akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

ll dp[2][5001];
int n;
string s;

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	return res;
}

int main() {
	cin >> n >> s;
	
	int size = s.size();
	
	dp[0][0] = 1;
	REP(i, n) {
		memset(dp[(i + 1) & 1], 0, sizeof(dp[0]));
		
		REP(j, i + 1) {
			(dp[(i + 1) & 1][max(j - 1, 0)] += dp[i & 1][j]) %= MOD;
			(dp[(i + 1) & 1][j + 1] += dp[i & 1][j] * 2) %= MOD;
		}
	}
	
	ll ans = dp[n & 1][size];
	ans = ans * mod_pow(mod_pow(2, size, MOD), MOD - 2, MOD) % MOD;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
/*  "A quote? by me? hell no!"  */
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <set>
#include <string>
#include <fstream>
#define F first
#define S second
#define ll long long
#define int ll
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per() cout<<fixed<<setprecision(12)
#define pb push_back
#define FOR(i,a,b) for(int i=a;((a<b)?(i<=b):(i>=b));((a<b)?(i++):(i--)))
//#define endl '\n'
//#define cin in
//#define cout out

using namespace std;
const int MAX_N = 1e2+10;
const int INF = 1e12+10;
const ll mod = 1e18;
ofstream out("output.txt");
ifstream in("intput.txt");
typedef pair<int,int> pii;
int bpow(int t,int n){int ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}

int from[MAX_N*100],to[MAX_N*100],w[MAX_N*100];
int n,m;
int d[MAX_N][MAX_N];
bool relax(int e,int s){
    if(d[s][to[e]]>d[s][from[e]]+w[e]&&d[s][from[e]]!=INF){
        d[s][to[e]]=d[s][from[e]]+w[e];
        return true;
    }
    return false;
}
bool ok=true;
void bellman(int s){
    fill(d[s],d[s]+MAX_N,INF);
    d[s][s]=0;
    for(int i=0;i<n-1;i++)
        for(int e=0;e<m;e++)
            relax(e,s);
    for(int e=0;e<m;e++)
        if(relax(e,s))
            ok=false;
}
int32_t main(){
    fast();per();
    cin>>n>>m;
    for(int i=0;i<m;i++)
        cin>>from[i]>>to[i]>>w[i];
    for(int i=0;i<n;i++)
        bellman(i);
    if(!ok)
        return cout<<"NEGATIVE CYCLE\n",0;
    for(int v=0;v<n;v++,cout<<'\n')
        for(int u=0;u<n;u++){
            if(d[v][u]!=INF)
                cout<<d[v][u];
            else
                cout<<"INF";
            if(u!=n-1)
                cout<<" ";
        }
}

Measured memory_bytes: 3492
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    string s,t;
    cin>>s>>t;
    
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    return 0;
}









Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
	int n,W;cin>>n>>W;
	vector<int> v(n),w(n);
	rep(i,n)cin>>w[i]>>v[i];
  
  constexpr int maxH = 1e5;
  vector<vector<ll>> dp(n+1,vector<ll>(maxH+1,INF));
  dp[0][0] = 0;

  for(int i = 1;i <= n;++i){
    rep(j,maxH+1){
      dp[i][j] = dp[i-1][j];
      if(j-v[i-1] >= 0)chmin(dp[i][j],dp[i-1][j-v[i-1]]+w[i-1]);
    }
  }

  for(int i = maxH;i >= 0;--i){
    if(dp[n][i] <= W){
      print(i);
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 83172
import java.util.Scanner;
/**
 * Write a description of class Circumfrence here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Main
{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int num = sc.nextInt();
        
        System.out.println(3.14 * 2 * num);
    }
}


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

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

    int int_n;
    double n;
    cin >> int_n;
    n = int_n;

    double x = (int_n % 2 == 0 ? n / 2 : (n + 1) / 2);
    cout << fixed << setprecision(10) << x / n << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define Point pair <int, int>
#define x first
#define y second
#define MAXN 205
#define mod 998244353
using namespace std;

int n, pw2[MAXN];
bool checked[MAXN][MAXN];
Point p[MAXN];

inline int fmod (int x) {
    return (x % mod + mod) % mod;
}

inline int f (int x) {
    return fmod (pw2[x] - x - 1 - x * (x - 1) / 2);
}

bool collinear (Point A, Point B, Point C) {
    B.x -= A.x, B.y -= A.y;
    C.x -= A.x, C.y -= A.y;

    return B.x * C.y == B.y * C.x;
}

int main () {
    ios::sync_with_stdio (0);

    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> p[i].x >> p[i].y;

    if (n <= 2) {
        cout << "0\n";
        return 0;
    }

    pw2[0] = 1;
    for (int i = 1; i <= n; ++i)
        pw2[i] = pw2[i - 1] * 2 % mod;

    int sol = f (n);
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if (checked[i][j])
                continue;

            vector <int> v {i, j};

            for (int k = j + 1; k <= n; ++k) {
                if (collinear (p[i], p[j], p[k]))
                    v.push_back (k);
            }

            sol = fmod (sol - f (v.size ()));

            for (int i = 0; i < (int) v.size (); ++i) {
                for (int j = i + 1; j < (int) v.size (); ++j) {
                    checked[v[i]][v[j]] = checked[v[j]][v[i]] = 1;
                }
            }
        }
    }

    cout << sol << "\n";

    return 0;
}

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

int main(){
	int a,b,c;
	int ans;
	bool flg;
	int cnt=0;
	
	while(cin>>a>>b){
		cnt++;flg=false;
		//-----test-----
		if(cnt==200) break;
		//--------------
		c=a+b;
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

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

using namespace std;

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

	int n, k;
	cin >> n >> k;
	int a;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		cin >> a;
		if(a >= k) ans++;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int gcd(int x,int y){
	while( x*y > 0 ){
		if( x > y ) x = x%y;
		else y = y%x;
	}
	return x+y;
}
signed main(){
	int n;
	cin>>n;
	vector<int> a;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
	}
	vector<int> rg,lg;
	lg.pb(0);
	rg.pb(0);
	for(int i=0;i<n;i++){
		lg.pb(gcd(a[i],lg[lg.size()-1]));
		rg.pb(gcd(a[n-1-i],rg[rg.size()-1]));
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		int tmp = gcd( lg[i-1], rg[n-i] );
		//cout<<i<<" "<<lg[i-1]<<" "<<rg[n-i]<<endl;
		if( tmp > ans ) ans = tmp;
	}
	cout<<ans<<endl;
	return 0;
}

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

// ABC127C - Prison 
// https://atcoder.jp/contests/abc127/tasks/abc127_c

void ABC127C() {
	int N, M;
	cin >> N >> M;

	vector<int> L(M), R(M);
	for (int i = 0; i < M; i++)
	{
		cin >> L[i] >> R[i];
	}

	//各IDカードで開けられる区間の重複する区間の左端・右端を探す
	int L_max = 0;
	int R_min = INT_MAX;
	for (int i = 0; i < M; i++)
	{
		L_max = max(L_max, L[i]);
		R_min = min(R_min, R[i]);
	}
	//cout << "L_max : " << L_max << endl;
	//cout << "R_min : " << R_min << endl;

	int tmp = R_min - L_max;
	if (tmp < 0) { //0未満のときは区間の重複なし
		cout << 0 << endl;
	}
	else {
		cout << tmp + 1 << endl; //区間の数は"右端 - 左端 + 1」
	}
}

int main() {
	ABC127C();

	return 0;
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanText() string {
	sc.Scan()
	return sc.Text()
}

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

	a, b := scanText(), scanText()
	ab, _ := strconv.Atoi(a + b)

	r := math.Floor(math.Sqrt(float64(ab)))

	if int(r)*int(r) == ab {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 1776
#include<iostream>
using namespace std;
int main(){
    int n,i,max,min;
    long long sum=0;
    int a[100000];
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
        sum=sum+a[i];
        if(i==1){
            max=a[i];
            min=a[i];
        }
        else{
            if(max<a[i]){
                max=a[i];
            }
            if(min>a[i]){
                min=a[i];
            }
        }
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int N;
    cin >> N;
    vector<LL> L(N);
    REP(i,N)cin>>L[i];

    LL count = 0;
    for(int i=0; i<N; i++){
        LL L1 = L[i];
        for(int j=i+1; j<N; j++){
            LL L2 = L[j];
            for(int k=j+1; k<N; k++){
                LL L3 = L[k];
                if(L1 < L2+L3 && L2 < L1+L3 && L3 < L1+L2 && L1!=L2 && L2!=L3 && L3 != L1){
                    count++;
                }
            }
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
use std::fmt::{Display, Formatter, Error};

struct NumVec(Vec<i32>);

impl Display for NumVec {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        let mut str = String::new();
		let k = self.0.len() - 1;
        for num in &self.0[0..k] {
            str.push_str(&num.to_string());
            str.push_str(" ");
        }

        str.push_str(&self.0[k].to_string());
        write!(f, "{}", str)
    }
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
	let line = read_vec::<usize>();
	let (r, c) = (line[0], line[1]);
	let mut sum_row: Vec<i32> = vec![0; c + 1];
	for i in 0..r {
		let row = read_vec::<i32>();
		for (i, v) in row.iter().enumerate() {
			print!("{} ", v);
			sum_row[i] += *v;
		}
		let sum = row.iter().sum::<i32>();
		println!("{}", sum);
		sum_row[c] += sum;
	}
	println!("{}", NumVec(sum_row));
}


Measured memory_bytes: 5040
# Left-child right-sibling representation
class Node:
    def __init__(self, id):
        self.id = id
        self.chi_list = []
        self.depth = None
        self.parent = None
    
    def create_out(self, node_map):  
        
        if self.parent is None:
            self.parent = -1

        self.depth = self.get_depth(node_map)
        self.type = self.get_type()

    def get_depth(self, node_map):

        if self.depth is not None:
            return self.depth
        
        if self.parent is None or self.parent == -1:
            return 0

        return node_map.get(self.parent).get_depth(node_map) + 1
    
    def get_type(self):
        if self.parent == -1:
            return 'root'

        return 'internal node' if self.chi_list else 'leaf'

node_num = int(input())
node_map = {}
for id in range(0, node_num):
            node_map[id] = Node(id)

for _ in range(node_num):
    temp = list(map(int, input().split()))
    id = temp[0]
    chi_list = []
    for i in range(2, len(temp)):
        chi_id = temp[i]
        chi_list.append(temp[i])

        chi_node = node_map.get(chi_id)
        chi_node.parent = id
        node_map[chi_id] = chi_node
    
    node = node_map.get(id)
    node.chi_list = chi_list
    node_map[id] = node

for node in list(node_map.values()):
    node.create_out(node_map)
    print('node '+ str(node.id) + ': parent = ' + str(node.parent)\
         + ', depth = ' + str(node.depth) + ', ' + str(node.type) + ', ' + str(node.chi_list))


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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.1415926535897932;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

int solve(v_int &a)
{
    int rtn = 0;

    irep(i, a.size()) {
        irep2(j, i+1, a.size()-1) {
            if(a[i] > a[j]) {
                rtn++;
            }
        }
    }
    return rtn;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) { 
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}

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

    v_int a(n);
    v_int kaidan(4);

    irep(i, n) {
        cin >> a[i];
    }
    
    irep2(i, 1, 3) { 
        v_int b; 
        irep(j, i) {
            irep(k, n) {
                b.push_back(a[k]);
            }        
        }
        kaidan[i] = solve(b);
        //cout << kaidan[i] << endl;
    }

    ll start = kaidan[2] - kaidan[1];
    ll diff = kaidan[3]-2*kaidan[2]+kaidan[1];
    ll ans = 2*start;
    ans += (((k-2) % IMOD) * diff) % IMOD; 
    ans *= (k-1) % IMOD;
    ans %= IMOD;
    ans *= modinv(2, IMOD);
    ans += kaidan[1];
    ans %= IMOD;
    cout << ans << endl;

    return 0;
}
/** atcoder **/



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a.at(i);
  int sum = 0;
  rep(i, m) sum += a.at(i);
  int day = n - sum;
  if(day >= 0) cout << day << endl;
  else cout << -1 << endl;
} 

Measured memory_bytes: 3672
x, y, z, k = map(int, input().split())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))

aabb = [a + b for a in aaa for b in bbb]
aabb.sort(reverse=True)
aabb = aabb[:k]

aabbcc = [ab + c for ab in aabb for c in ccc]
aabbcc.sort(reverse=True)
aabbcc = aabbcc[:k]

print('\n'.join(map(str, aabbcc)))


Measured memory_bytes: 137868
#include<bits/stdc++.h>
#define IMAX 1000000000000

#define ll long long

using namespace std;
int main()
{
  ll n,k;
  cin>>n>>k;
  ll a[n];
  for(ll i=0;i<n;i++)
    cin>>a[i];
 
  ll b[n];
  for(ll i=0;i<n;i++)
    b[i]=IMAX;
  
  b[0]=0;
  
  for(ll i=0;i<n;i++)
  {
      for(int j=1;j<=k;j++)
      {
        ll x=i+j;
        // ll y=i+2;
        if(x<n)
          b[x]=min(abs(a[i]-a[x])+b[i],b[x]);
        // if(y<n)
        //   b[y]=min(abs(a[i]-a[y])+b[i],b[y]);
      }
  }
 
  //for(ll i=0;i<n;i++)
    //cout<<b[i]<<"\n";
  
  
  cout<<b[n-1];
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>
using namespace std;

int main(){
    long long N,M,ac=0,wa=0;
    cin >> N >> M;
    vector<pair<long long, string>> S(M);
    vector<long long> A(N,0);
    vector<long long> W(N,0);

    for(long long i=0; i<M; i++){
        cin >> S[i].first >> S[i].second;
    }
    for(long long i=0; i<M; i++){
        if(S[i].second != "AC" && A[S[i].first-1] == 0)
            W[S[i].first-1]++;
        if(S[i].second == "AC" && A[S[i].first-1] == 0){
            wa+=W[S[i].first-1];
            ac++;
            A[S[i].first-1]=1;
        }
    }
    cout << ac << " " << wa << endl;
}

Measured memory_bytes: 8064
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static int n;
	public static int m;
	public static long k;
	public static long[] a;
	public static long[] b;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		n = parseInt(sc.next());
		m = parseInt(sc.next());
		k = parseLong(sc.next());
		a = new long[n];
		for (i = 0; i < n; i++) {
			a[i] = parseLong(sc.next());
		}
		b = new long[m];
		for (i = 0; i < m; i++) {
			b[i] = parseLong(sc.next());
		}
		sc.close();
//		out.println(Arrays.toString(a));
		long ans=0;
		long cnt=0;
		long tot=0;
		i=0;
		j=0;
		while(tot<=k&&i<n) {
			tot+=a[i];
			i++;
			cnt++;
		}
		if(tot>k) {
			cnt--;
			i--;
			tot-=a[i];
		}
		ans=cnt;
		j=0;
		for ( i--;  ; i--) {
			while(tot<=k&&j<m) {
				tot+=b[j];
				j++;
				cnt++;
			}
			if(tot>k) {
				cnt--;
				j--;
				tot-=b[j];
			}
			ans=Math.max(ans, cnt);
			if(i<0) break;
			cnt--;
			tot-=a[i];
		}
		out.println(ans);
			
//			if(a[i]<b[j]) {
//				tot+=a[i];
//				i++;
//			} else if(a[i]>b[j]){
//				tot+=b[j];
//				j++;
//			} else {
//				tot+=a[i];
//				i++;
//				if(tot<=k) {
//					tot+=b[j];
//					j++;
//					ans++;
//				}
//			}
//			ans++;
//		}
//		if(tot<=k) {
//			if(i>=n) {
//				while(tot<=k&&j<m) {
//					tot+=b[j];
//					j++;
//					ans++;
//				}
//			} else if(j>=m) {
//				while(tot<=k&&i<n) {
//					tot+=a[i];
//					i++;
//					ans++;
//				}
//			}
//		}
//		if(tot>k) {
//			ans--;
//		}
//		out.println(ans);
//		out.println(b2(0, 0, 0, 0));
//	}
//	public static int b2(long tot, int i, int j, int cnt) {
////		out.printf("%d,%d,%d,%d%n", tot, i , j , cnt);
//		if(tot>k) return cnt-1;
//		if(i==n&&j==m) return cnt;
//		int aa=0;
//		int bb=0;
//		if(i<n) {
//			aa = b2(tot+a[i], i+1, j, cnt+1);
//		}
//		if(j<m) {
//			bb = b2(tot+b[j], i, j + 1, cnt+1);
//		}
////		out.println(aa);
////		out.println(bb);
//		return Math.max(aa, bb);
	}
}


Measured memory_bytes: 63444
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<string>
using namespace std;
#define ll long long int
#define maxn 100005

void _init() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}



int main() {
	_init();

	string s, t;
	cin >> s >> t;
	int n = s.length(), m = t.length();
	int dp[n + 1][m + 1];
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}

	//cout << "maxLength" << dp[n][m] << endl;
	string res = "";
	while (n > 0 && m > 0) {
		if (s[n - 1] == t[m - 1]) {
			res += s[n - 1];
			n--, m--;
		}
		else {
			if (dp[n][m] == dp[n - 1][m])n--;
			else m--;
		}
	}

	reverse(res.begin(), res.end());

	cout << res << endl;

	return 0;
}









Measured memory_bytes: 38804
#include <bits/stdc++.h>
using namespace std;
#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)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#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

int main(){
	int n; scanf("%d", &n);
	ll sx = LLONG_MIN,
		 si = LLONG_MAX,
		 dx = LLONG_MIN,
		 di = LLONG_MAX;
	REP(i, n){
		ll x, y; scanf("%lld%lld", &x, &y);
		LAR(sx, x+y);
		SML(si, x+y);
		LAR(dx, x-y);
		SML(di, x-y);
	}
	printf("%lld\n", max(sx-si, dx-di));
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    double ans = 0;
    REP(i,N){
        double a; cin >> a;
        ans += 1.0 / a;
    }
    ans = 1 / ans;
    printf("%.12lf\n",ans);
}


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

using namespace std;

int main(){
	int a,b,c,d,e,f;
	float x , y , delta;

	while(cin >> a >> b >> c >> d >> e >> f){
			delta = (a * e) - (b * d);

			x = ((c * e) - (b * f)) / delta;
			y = ((a * f) - (c * d)) / delta;

			if(x == 0) x = 0;
			if(y == 0) y = 0;

		printf("%.3f %.3f\n", x , y);
	}

	return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    cout << (800 * N - (N / 15) * 200) << endl;
    return 0;
};

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main implements Runnable{

	public static void main(String[] args) {
		new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start();
	}
	
	boolean same(char[] a,char[] b) {
		if(a.length!=b.length)return false;
		boolean ret=true;
		for(int i=0;i<a.length;++i)ret&=a[i]==b[i];
		return ret;
	}
	
	int n(char c) {
		return (int)(c-'0');
	}
	
	public void run() {
		FastScanner sc=new FastScanner();
		long a=sc.nextLong();//1e18
		long b=sc.nextLong();//1e18,0<=a<=b
		long x=sc.nextLong();//1e18
		System.out.println((1+b/x)-(a==0?0:(1+(a-1)/x)));
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

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

Measured memory_bytes: 25044
/*
Author: CNYALI_LK
LANG: C++
PROG: C.cpp
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define all(x) x.begin(),x.end()
#define end(...) {printf(__VA_ARGS__);exit(0);}
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
typedef long long ll;
template<class T>void chkmin(T &a,T b){a=a<b?a:b;}
template<class T>void chkmax(T &a,T b){a=a>b?a:b;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
ll to[233333],lst[233333],beg[122222],e,tot[122222];
void add(ll u,ll v){
	to[++e]=v;
	lst[e]=beg[u];
	beg[u]=e;
	++tot[u];
}
ll vis[233333],a[233333][2],as[2][233333],alls[233333];
ll top[2],allt,bsum,ans;
void dfs(ll x,ll col){
	if(a[x][col])return;
	a[x][col]=1;
	++top[col];
	if(!vis[x]){
		vis[x]=1;
		++allt;
		bsum+=tot[x];
	}
	for(ll i=beg[x];i;i=lst[i])dfs(to[i],col^1);
}
void calc(ll x){
	top[0]=top[1]=0;
	allt=0;
	bsum=0;
	dfs(x,0);
	bsum>>=1;
	ll as1=top[0]+top[1]-allt;
	ll as0=top[0]*top[1]-as1*top[0]-as1*top[1]+as1*as1+((as1*(as1-1))>>1);
	ans+=as0-bsum;
}
int main(){
#ifdef cnyali_lk
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	ll n,m,u,v;
	scanf("%lld%lld",&n,&m);
	for(ll i=1;i<=m;++i){
		scanf("%lld%lld",&u,&v);
		add(u,v);
		add(v,u);
	}
	for(ll i=1;i<=n;++i)if(!vis[i])calc(i);
	printf("%lld\n",ans);
	return 0;
}



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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) if((x)>(y))(x)=(y)
#define chmax(x,y) if((x)<(y))(x)=(y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b, c, x, y, r;

signed main() {
	cin >> a >> b >> c >> x >> y;
	c *= 2;
	if (a+b>c) {
		int m = min(x,y);
		r += m*c;
		x -= m, y -= m;
		r += (x+y) * min(c, (x ? a : b));
	} else r = a*x + b*y;
	cout << r << ln;
}

Measured memory_bytes: 256
n = int(input())
s = list(str(input()))

# (
x = 0
y = 0
for i in range(n):
    if s[i] == '(':
        x += 1

    if s[i] == ')':
        if x >= 1:
            x -= 1
        else:
            y += 1

for _ in range(x):
    s.append(')')

for _ in range(y):
    s.insert(0,'(')
ans = ''.join(s)
print(ans)


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

using namespace std;

long long a[10000001];
long long res;

int main() {
	
	int i, j, n;
	
	scanf("%d", &n);
	
	for (i = 1; i <= n; i++)
		for (j = i; j <= n; j += i)
			a[j]++;
	
	for (i = 1; i <= n; i++)
		res += i * a[i];
	
	printf("%lld", res);
	
	return 0;
}

Measured memory_bytes: 81980
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


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

    // 入力
    int H, W;
    cin >> H >> W;
    string S[51];
    for(int i = 0; i < H; i++) {
        cin >> S[i];
    }
    

    // 処理
    int output[51][51] = {};
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if (S[i][j] == '#') continue;
            for(int k = 0; k < 9; k++) {
                int dx = i + k % 3 - 1;
                int dy = j + k / 3 - 1;
                if (dx < 0 || dx >= H) continue;
                if (dy < 0 || dy >= W) continue;
                if (S[dx][dy] == '#') output[i][j]++;
            }
        }
    }

    // 出力
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if (S[i][j] == '#') 
                cout << S[i][j];
            else 
                cout << output[i][j];
        }
        cout << endl;
    }


    return 0;
}


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

  
int main(){
  int n;
  cin >> n;
  VI p(n);
  rep(i,n){
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  int sum=0;
  rep(i,n){
    sum+=p.at(i);
  }
  int summ=sum-p.at(n-1)/2;
  cout << summ << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
ll dpx[2019],dpy[2019];
int main(){
	ll n,z,w;
	cin>>n>>z>>w;
	vector<ll> a;
	a.pb(w);
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	dpx[1] = abs( a[n]-a[n-1]);
	dpy[1] = abs( a[n]-a[n-1]);
	for(int i=2;i<=n;i++){
		ll ma = abs(a[n-i]-a[n]);
		for(int j=1;j<=i-1;j++){
			if(ma<dpy[j])ma=dpy[j];
		}
		dpx[i]=ma;
		ll mi = abs(a[n-i]-a[n]);
		for(int j=1;j<=i-1;j++){
			if(dpx[j]<mi)mi=dpx[j];
		}
		dpy[i]=mi;
	}
	cout<<dpx[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
	long int price;
	long int max;
}hm;

int cmp( const void *p, const void *q ) {
    return ((hm*)p)->price - ((hm*)q)->price;
}

int main(void){
    // Your code here!
    long int n,m;
    hm lst[100000];
    scanf("%d %d",&n,&m);
    for(long int i=0;i<n;i++){
        scanf("%ld %ld",&lst[i].price,&lst[i].max);
    }
    
    
    qsort( lst,n, sizeof(hm), cmp );
    
    /*for(int i=0;i<n;i++){
        printf("%d:%d %d\n",i,lst[i].price,lst[i].max);
    }*/
    
    long long int cost=0;
    long int shop=0;
    while(m>0){
        if(lst[shop].max>=m){
            //printf("%d a\n",shop);
            lst[shop].max-=m;
            cost+=m*lst[shop].price;
            m=0;
        }else if(lst[shop].max<m){
            //printf("%d b\n",shop);
            m-=lst[shop].max;
            cost+=lst[shop].price*lst[shop].max;
            lst[shop].max=0;
            shop++;
        }
        //printf("m=%d cost=%d\n",m,cost);
    }
    
    printf("%lld\n",cost);
    return 0;
}

Measured memory_bytes: 3324
import java.util.Scanner;
import java.util.ArrayList;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list=new ArrayList<>();
		for(int i = 0; i<n; i++){
			list.add(sc.nextInt());
		}
		int[] ans=new int[n];
		for(int i = 0; i<n; i++){
			int ch=-1;
			for(int j=0; j<list.size(); j++){
				if(list.get(j)==j+1){
					ch=j;
				}
			}
			if(ch!=-1){
				ans[i]=list.remove(ch);
			}
			
		}
		if(list.size()>0){
			System.out.println(-1);
			return;
		}
		for(int i=n-1; i>=0; i--){
			System.out.println(ans[i]);
		}
	}
}


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

using namespace std;

typedef long long ll;
#define PI 3.14159265




int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> h(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    vector<vector<int> > arr(n + 1);
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        arr[v].push_back(u);
        arr[u].push_back(v);
    }
    int ans = 0;
    for(int i = 1; i < arr.size(); i++){
        bool yap = true;
        for(int j = 0; j < arr[i].size(); j++){
            if(h[arr[i][j]] >= h[i]){
                yap = false;
            }
        }
        if(yap){
            ans++;
        }
    }
    cout << ans << endl;
    
}

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

using namespace std;

typedef long long int llint;

int r, g, b;

inline bool solve() {
  return (100 * r + 10 * g + b) % 4 == 0;
}

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

  cin >> r >> g >> b;

  if (solve()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

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

using namespace std;

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

    cout << fixed << setprecision(10);
    if (d == 0) {
        cout << (m - 1.0) / n << endl;
    } else {
        cout << 2.0 * (n - d) / n / n * (m - 1) << endl;
    }
    return 0;
}

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

int main(){
  int n;
  long long int sum = 0;
  cin >> n;
  vector<int> a(n+1), b(n);
  for(int i = 0; i < n+1; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }

  for(int i = 0; i < n; i++){
    if(a[i] > b[i]){
      sum += b[i];
      a[i] -= b[i];
      b[i] = 0;
    }else{
      sum += a[i];
      b[i] -= a[i];
      a[i] = 0;
    }

    if(a[i+1] > b[i]){
      sum += b[i];
      a[i+1] -= b[i];
      b[i] = 0;
    }else{
      sum += a[i+1];
      b[i] -= a[i+1];
      a[i+1] = 0;
    }
  }

  cout << sum << endl;

}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long a = in.nextLong();
        long b = in.nextLong();

        long total = (n / (a + b)) * a;
        total += Math.min((n % (a + b)), a);
        System.out.println(total);
    }
}


Measured memory_bytes: 21844
N,M = map(int,input().split())
a = [0]*M
b = [0]*M
c = [[] for _ in range(M)]
for i in range(M):
    a[i],b[i] = map(int,input().split())
    c[i] = list(map(int,input().split()))
    
inf = 2**30 - 1
dp = [[inf]*(2**N+1) for _ in range(M+1)]
dp[0][0] = 0

c_bit = [0] * M
for i in range(M):
    for t in c[i]:
        c_bit[i] += 1<<(t-1)

for i in range(M):
    for j in range(1<<N):
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])
        dp[i+1][j|c_bit[i]] = min(dp[i+1][j|c_bit[i]],dp[i][j]+a[i])

ans = dp[M][(1<<N)-1]
if ans==inf:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 77672
#include<stdio.h>

//昇順に並べる
void sort(int* a) {
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2-i; j++) {
      if (a[j] > a[j+1]) {
        int tmp = a[j];
        a[j] = a[j+1];
        a[j+1] = tmp;
      }
    }
  }
}


int main(void) {
  
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);
  int a[3] = {A, B, C};
  sort(a);
  int small = a[0];
  int mid = a[1];
  int big = a[2];
  
  int dif1 = big - small;
  int dif2 = big - mid;
  
  int ans = 0;
  if (dif2%2 == 0 && dif1%2 == 0) {
    ans = dif1/2 + dif2/2 + 0;
  } else if ((dif1%2 + dif2%2)%2 == 1) {
    ans = dif1/2 + dif2/2 + 2;
  } else {
    ans = dif1/2 + dif2/2 + 1;
  }
  
  printf("%d\n", ans);
 
  return 0;
}

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

int main() {
       int N;
       cin >> N;
       for (int i = 0; i < 2; i++)
       {
           if(N % 10 == 9) {
               cout << "Yes" << endl;
               return 0;
           }
           N /= 10;
       }
       cout << "No" << endl;
       return 0;
}

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n,m,a[maxn],b[maxn],cnt,vis[maxn];
char s[maxn];
set<int > e[maxn];

int main() {
    read(n),read(m);scanf("%s",s+1);
    for(int i=1,x,y;i<=m;i++) {
        read(x),read(y);
        if(e[x].find(y)!=e[x].end()) continue;
        e[x].insert(y),e[y].insert(x);
        if(s[y]=='A') a[x]++;else b[x]++;
        if(s[x]=='A') a[y]++;else b[y]++;
    }
    queue<int > q;
    for(int i=1;i<=n;i++) if(!min(a[i],b[i])) q.push(i);
    while(!q.empty()) {
        int x=q.front();q.pop();
        if(vis[x]) continue;
        // printf("? : %d %d %d\n",x,a[x],b[x]);
        vis[x]=1;cnt++;
        for(auto v:e[x]) {
            if(v!=x) e[v].erase(x);
            if(s[x]=='A') a[v]--;
            else b[v]--;
            if(!min(a[v],b[v])) q.push(v);
        }
        e[x].clear();
    }
    puts(cnt!=n?"Yes":"No");
    return 0;
}


Measured memory_bytes: 71936
import java.util.Scanner;


public class Main{
    public  static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
        	while(sc.hasNext()) {
        		int[] dp=new int[51];
        		int n = sc.nextInt();
        		for(int i=0; i<=9; i++) {
        			for(int j=0; j<=9; j++) {
        				for(int k=0; k<=9; k++) {
        					for(int s=0; s<=9; s++) {
        						dp[i+j+k+s]++;
        					}
        				}
        			}
        		}
        		System.out.println(dp[n]);
        	}
        }
    }
}


Measured memory_bytes: 26956
#include<iostream>
#include<string>

using namespace std;

 int main(){
  int N;
  string S;
  int K;
 
  cin >> N >> S >> K;

  char a = S.at(K-1);
  

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

   if ((S.at(i)) != a) {
     S.at(i) = '*';
    }
  }
  cout << S << endl;  

 return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H, i;
        int MAX = 100000;
        int[] A = new int[MAX+1];
        H = sc.nextInt();

        for(i = 1; i <= H; i++) A[i] = sc.nextInt();

        for(i = 1; i <= H; i++) {
            System.out.print("node " + i + ": key = " + A[i] + ", ");
            if(parent(i) >= 1) System.out.print("parent key = " + A[parent(i)] + ", ");
            if(left(i) <= H) System.out.print("left key = " + A[left(i)] + ", ");
            if(right(i) <= H) System.out.print("right key = " + A[right(i)] + ", ");
            System.out.println();
        }
    }
}



Measured memory_bytes: 27628
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 100000
using namespace std;
typedef long long ll;
int map[255][255];
int f[255],d[255],tt=0;
bool vis[255];
void dfs(int n,int u)
{
	if(vis[u]) return;
	vis[u]=true;
	tt++;
	d[u]=tt;
	for(int i=1;i<=n;i++)
	{
		if(map[u][i]) dfs(n,i);
	}
	tt++;
	f[u]=tt;
	return; 
}
int main()
{	
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			map[i][j]=0;
		}
	for(int i=0;i<n;i++)
	{
		int cur,k,u;
		cin>>cur>>k;
		while(k--)
		{
			cin>>u;
			map[cur][u]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		vis[i]=false;
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i]) dfs(n,i);
	}
	for(int i=1;i<=n;i++)
	{
		cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==c){
    cout<<b<<endl;
  }
  else if(a==b){
    cout<<c<<endl;
  }
  else{
    cout<<a<<endl;
  }
}

    

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pii         pair<int,int> 
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
using namespace std;
 
void solve(){
    int n;
    cin>>n;
    int h[n];
    rep(i,0,n)cin>>h[i];
    int dp[n];

    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);

    rep(i,2,n){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout<<dp[n-1]<<endl;
}
 
 
 
int main(){
  //  #ifndef ONLINE_JUDGE
    // for getting input from input.txt
 //   freopen("input.txt", "r", stdin);
    // for writing output to output.txt
   // freopen("output.txt", "w", stdout);
  //  #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
   
 
    int t=1,i=1;
   // cin>>t;
    
 
    while(t--){
       // cout<<"Case #"<<i++<<": ";
        solve();
    
    }
 
    return 0;
}

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

int main(void){
    char s[201]; 

    scanf("%s", s);

    for(int i = strlen(s) - 1; i > 0; i--){
        if(i % 2 == 0){
            for(int j = 0; j < i / 2; j++){
                if(s[j] != s[i/2 + j]){
                    break;
                }else{
                    if(j == i/2 - 1){
                        printf("%d\n", i);
                        return 0;
                    }
                }
            }
        }
    }

    return 0;

} 


Measured memory_bytes: 256
from operator import itemgetter

n = int(input())
a = sorted(list(map(int, input().split())))
max_n = a.pop(-1)
x = max_n / 2
a_ = sorted([(x, abs(max_n/2-x)) for x in a], key=itemgetter(1))

print(max_n, a_[0][0])

Measured memory_bytes: 19416