akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int INF = 1 << 30;

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

    int n, m, x;
    cin >> n >> m >> x;

    vector<vector<int> > a(n, vector<int>(m, 0));
    vector<int> c(n, 0);
    REP(i, n) {
        cin >> c[i];
        REP(j, m) cin >> a[i][j];
    }

    int ans = INF;
    REP(mask, 1 << n) {
        vector<int> level(m, 0);
        int cost = 0;
        REP(i, n) {
            if ((mask >> i) & 1) {
                cost += c[i];
                REP(j, m) level[j] += a[i][j];
            }
        }
        bool ok = true;
        REP(j, m)
            if (level[j] < x) ok = false;
        if (ok) ans = min(ans, cost);
    }

    if (ans == INF) cout << -1 << endl;
    else cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;


int main()
{
    IOS
    string s,t;
    cin>>s>>t;
    ll cnt=0;
    for(ll i=0;i<3;i++)
    {
        cnt+=(s[i]==t[i]);
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())

ans = "No"
while k > 0 and b <= a:
    b *= 2
    k -= 1
while k > 0 and c <= b:
    c *= 2
    k -= 1
if b > a and c > b:
    ans = "Yes"
print(ans)


Measured memory_bytes: 9172
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  int max_a, max_index, max_sec_a;
  max_a = 0;
  max_sec_a = 0;
  for(int i= 0; i<n;++i){
    cin >> a[i];
    if(a[i] > max_a){
      max_a = a[i];
      max_index = i;
    }else if(a[i] >= max_sec_a){
      max_sec_a = a[i];
    }
  }
  for(int i= 0; i<n;++i){
    if(i!=max_index){
  	  printf("%d\n", max_a);
    }else{
      printf("%d\n", max_sec_a);
    }
  }
  return 0;
}


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

int main()
{
	int array[26] = {0};
	string s;
	cin >> s;
	int len = s.length();
	for(int i = 0; i < len; i++)
	{
		array[s[i]-'a']++;
	}
	for(int i = 0; i < 26; i++)
	{
		if(array[i] == 0)
		{
			printf("%c\n",i + 'a');
			return 0;
		}
	}
	puts("None");
	return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

type PairInt struct {
	first, second int
}

func NewPairInt(first, second int) PairInt {
	return PairInt{first, second}
}

type PairsInt []PairInt

func (p PairsInt) Less(i, j int) bool {
	if p[i].first == p[j].first {
		return p[i].second < p[j].second
	} else {
		return p[i].first < p[j].first
	}
}

func (p PairsInt) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p PairsInt) Len() int {
	return len(p)
}

type IntHeap []int

func (h IntHeap) Len() int {
	return len(h)
}

func (h IntHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h IntHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func solve() {
	var n, m int
	fmt.Scan(&n, &m)
	a := make([]int, n)
	b := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	for i := 0; sc.Scan(); i++ {
		args := strings.Split(sc.Text(), " ")
		a[i], _ = strconv.Atoi(args[0])
		b[i], _ = strconv.Atoi(args[1])
	}

	pairs := make(PairsInt, n)
	for i := 0; i < n; i++ {
		pairs[i] = NewPairInt(a[i], b[i])
	}
	sort.Sort(pairs)

	h := &IntHeap{}
	heap.Init(h)
	sum := 0
	j := 0
	for i := n; i > 0; i-- {
		for j < n && pairs[j].first+i <= m+1 {
			heap.Push(h, pairs[j].second)
			j++
		}
		if h.Len() != 0 {
			sum += heap.Pop(h).(int)
		}
	}

	fmt.Println(sum)
}

func main() {
	solve()
}


Measured memory_bytes: 9236
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

const int MAX=100005;
int value[MAX][3];
int dp[MAX][4];

int happy(int i,int l){
    if(dp[i][l]!=-1) return dp[i][l];
    if(l==0) dp[i][0]=max(happy(i+1,1),happy(i+1,2))+value[i][0];
    else if(l==1) dp[i][1]=max(happy(i+1,0),happy(i+1,2))+value[i][1];
    else if(l==2) dp[i][2]=max(happy(i+1,0),happy(i+1,1))+value[i][2];
    return dp[i][l];
}

int main() {
    #ifndef LOCAL
    fastIO;
    #endif
    memset(dp,-1,sizeof(dp));
    int n,rta;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> value[i][j];
        }
    }
    dp[n-1][0]=value[n-1][0];
    dp[n-1][1]=value[n-1][1];
    dp[n-1][2]=value[n-1][2];
    for(int i=0;i<3;i++){
        happy(0,i);
    }
    rta=max(dp[0][0],dp[0][1]);
    rta=max(rta,dp[0][2]);
    cout << rta << endl;
    return 0;
}



Measured memory_bytes: 10984
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let mut remain_zero : usize = 0;
    let mut remain_half : usize = 0;
    let ans;
    if k % 2 != 0 {
        //odd
        for i in 1..n+1 {
            if i%k == 0 {
                remain_zero += 1;
            }
        }
        ans = remain_zero.pow(3);
    } else {
        //even
        for i in 1..n+1 {
            if i%k == 0 {
                remain_zero += 1;
            } else if i%k == k/2 {
                remain_half += 1;
            }
        }
        ans = remain_zero.pow(3) + remain_half.pow(3);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a,s=0,ans=-1,i;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a;
        s+=a;
    }
    cout<<(s>n?ans:n-s)<<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    int n; cin >> n;
    int sum = 0;
    int inf = -1;

    rep(i,n) {
        int tmp; cin >> tmp;
        sum += tmp;
        inf = max(inf, tmp);
    }
    
    cout << sum - (inf/2) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N;
char c[202];

ll dp[202][202];

void add(ll &a,ll b){
    a=(a+b)%MOD;
}

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

  dp[0][0]=1;
  for(int i=0;i<N;i++){
      for(int j=0;j<=i;j++){
          if(c[i]=='-') add(dp[i+1][j],dp[i][j]);
          else if(c[i]=='D'){
              add(dp[i+1][j],dp[i][j]*j);
              if(j>=1) add(dp[i+1][j-1],dp[i][j]*j*j);
          }else{
              add(dp[i+1][j+1],dp[i][j]);
              if(j>=1) add(dp[i+1][j],dp[i][j]*j);
          }
      }
  }

  cout<<dp[N][0]<<endl;

  return 0;
}



Measured memory_bytes: 3412
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
	int x ,a, b;

	cin>>x;

	a = x/500;
	b = (x%500)/5;

	cout << (a*1000) + (b*5) <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,a[2000],s[1001],ans,A,B;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s[a[i]]++;
    }
    for(int i=0;i<1000;i++){
        s[i+1]+=s[i];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            A=min(1000LL,a[i]+a[j]-1);
            B=max(a[i],a[j])-min(a[i],a[j])+1;
            ans+=s[A]-s[B-1];
            if(B<=a[i]&&a[i]<=A)ans--;
            if(B<=a[j]&&a[j]<=A)ans--;
        }
    }
    cout<<ans/3<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 1e5+ 7;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;

ll a[N];
int main()
{
    ll n,i,x;
    scanf("%llu",&n);
    bool flag = 1;
    for(i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    ll sum;
    if(a[0]==0)
        sum=0;
    else
    {
        sum=1;
        for(i=0;i<n;i++){
            sum*=a[i];
            if(a[i+1]>(1000000000000000000/sum))
            {
                sum=-1;
                break;
            }


        }
    }
    printf("%lld\n",sum);
}


Measured memory_bytes: 2508
#include"iostream"
using namespace std;
int main()
{
	int a, b, c;
	for (a = 1; a < 10; a++)
	{
		for (b = 1; b < 10; b++)
		{
			c = a*b;
			cout << a << "x" << b << "=" << c << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2864
#include<bits/stdc++.h>
using namespace std;
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main() {
	int n=read(),k=read(); 
	--n; --k;
	if (n%k==0) printf("%d\n", n/k);
	else printf("%d\n", n/k+1);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <vector>

std::string sim(const std::string& t0, const std::string& s) {
  size_t n = s.length();
  std::string res = t0;
  for (size_t i = 1; i <= n; ++i) {
    size_t pi = i-1;
    size_t ci = (i<n? i:0);

    char cur;
    if (res[ci] == 'S') {
      if (s[ci] == 'o') {
        cur = res[pi];
      } else {
        cur = res[pi] ^ 'S' ^ 'W';
      }
    } else {
      if (s[ci] == 'o') {
        cur = res[pi] ^ 'S' ^ 'W';
      } else {
        cur = res[pi];
      }
    }
    res += cur;
  }

  if (res[1] != res[n+1]) return {};
  if (res[0] != res[n]) return {};
  res.pop_back();
  res.pop_back();
  return res;
}

int main() {
  size_t N;
  scanf("%zu", &N);

  char buf[131072];
  scanf("%s", buf);
  std::string s = buf;

  std::vector<std::string> t0 = {"SS", "SW", "WS", "WW"};
  for (auto t: t0) {
    std::string res = sim(t, s);
    if (!res.empty())
      return !printf("%s\n", res.c_str());
  }

  puts("-1");
}


Measured memory_bytes: 824
#include <bits/stdc++.h>
using namespace std;
#define int long long

main() {
    int a, b, c, d, l;
    cin >> a >> b >> c >> d;
    a--;
    l = c/__gcd(c,d)*d;
    cout << b - b/c - b/d + b/l - a + a/c + a/d - a/l;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

#define MAX_V 10010
struct edge {int to;long long cap;int rev;};
vector<edge> G[MAX_V];	// 最大フロー用の隣接リスト
bool used[MAX_V];
void add_edge(int from,int to,long long cap) {
	G[from].push_back((edge){to,cap,(int)G[to].size()});
	G[to].push_back((edge){from,0,(int)G[from].size()-1});
}
long long dfs(int v,int t,long long f) {
	if(v==t) return f;
	used[v]=true;
	for(int i=0; i<G[v].size(); ++i) {
		edge &e=G[v][i];
		if(!used[e.to]&&e.cap>0) {
			long long d=dfs(e.to,t,min(f,e.cap));
			if(d>0) {
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
long long FordFulkerson(int s,int t, vector<vector<P>>& adj) {
	// adj は通常の隣接リスト（first: to, second: cost）
	for(int i=0; i<(int)adj.size(); i++) {
		for(int j=0; j<(int)adj[i].size(); j++) {
			add_edge(i,adj[i][j].first,adj[i][j].second);
		}
	}
	long long flow=0;
	while(1) {
		for(int i=0; i<MAX_V; ++i) used[i]=false;
		long long f=dfs(s,t,INF*INF);
		if(f==0) return flow;
		flow+=f;
	}
}

int main() {
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	ll ans=0;
	REP(i,n) ans+=max(0ll,a[i]);
	vector<vector<P>> adj(n+2);
	REP(i,n) {
		if(a[i]>=0) adj[1+i].pb(P(n+1,a[i]));
		else adj[0].pb(P(1+i,-a[i]));
	}
	REP(i,n) {
		for(ll j=2; (i+1)*j<=n; j++) {
			adj[1+i].pb(P((i+1)*j,INF*INF/1000ll));
		}
	}
	cout<<ans-FordFulkerson(0,n+1,adj)<<endl;
}


Measured memory_bytes: 512
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e3 + 10;
int check(int a, int b)
{
	return (a + b - 1) / b;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	int pos = -1;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		if (x == 1) pos = i;
	}
	int ans = n;
	for (int i = k; i <= n; i++)
	{
		int l = i - k + 1;
		int r = i;
		if (pos < l || pos > r) continue;
		ans = min(ans, 1 + check(l - 1, k - 1) + check(n - r, k - 1));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define vpii vector<pair<int,int> >
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back   
#define PB pop_back
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;

void solve(){
    int n, q, sum = 0;
    cin>>n;
    int a[n+5], b[100010] = {0};
    f(i,n)cin>>a[i],sum += a[i],b[a[i]]++;
    cin>>q;
    while(q--){
        int x, y;
        cin>>x>>y;
        sum -= (x*b[x]);
        sum += (y*b[x]);
        b[y] += b[x];
        b[x] = 0;
        cout<<sum<<endl;
    }
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 5208
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int m;
pair < int , int > pp[N];

int main(){
    cin >> n >> m;
    int mn = 1e5;
    int mx = 0;
    for(int i = 1; i <= m; i++){
        int l , r;
        cin >> l >> r;
        pp[i] = {l , r};
        mx = max(mx , l);
        mn = min(mn , r);
    }
    if(mn < mx){
        cout << 0 << endl;
    } else {
        cout << mn - mx + 1 << endl;
    }
}


Measured memory_bytes: 1024
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let _ = Scanf.scanf "%d %d" @@ fun n k ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let v = Array.fold_left gcd a.(0) a in
  Array.fold_left (fun b x -> b || x >= k && (x - k) mod v = 0) false a
  |> fun b -> print_endline (if b then "POSSIBLE" else "IMPOSSIBLE")

Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class program{
    public static void Main(){
        var abC = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToList();
        var a = abC[0];
        var b = abC[1];
        var C = abC[2];

        var h = b * Sin(C * 2 * PI / 360);
        var S = a * h / 2;
        var c = Sqrt(a*a + b*b - 2*a*b*Cos(C * 2*PI / 360));
        var L = a + b + c;
        Console.WriteLine(S);
        Console.WriteLine(L);
        Console.WriteLine(h);
    }
}



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

using namespace std;

#define MAX 100005

vector<int> pen(MAX, 0), ac(MAX, 0);

int main(){

    int n, m, p;
    cin >> n >> m;
    string st;

    for(int i = 0; i < m; i++){
        cin >> p >> st;
        if( st == "AC" )
            ac[p] = 1;
        else if( ac[p] == 0 )
            pen[p]++;
    }

    int aa = 0, pn = 0;
    for(int i = 1; i < MAX; i++)
        if( ac[i] )
            aa++, pn += pen[i];

    cout << aa << " " << pn;

    return 0;
}

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

int main() {
  const int dx[] = {-1,1,0,0};
  const int dy[] = {0,0,-1,1};
  string s;
  while(cin>>s) {
	for(unsigned i=1;i<s.size();i++) {
	  int a = (s[i-1]-'A')/3, b = (s[i]-'A')/3;
	  int c = (s[i-1]-'A')%3, d = (s[i]-'A')%3;
	  bool ok = false;
	  for(int k=0;k<4;k++) {
		if(a+dy[k] == b && c+dx[k] == d) ok = true;
	  }
	  if(!ok) goto fin;
	}
	cout << s + '\n';
  fin:;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
//void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s)
{
	queue<int> q;
	q.push(s);
	REP(n) d[i] = INFTY;
	d[s] = 0;
	int u;
	while (!q.empty())
	{
		u = q.front(); q.pop();
		for (int v=0; v<n; v++)
		{
			if (M[u][v] == 0) continue;
			if (d[v] != INFTY) continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	REP(n)
	{
		cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
	}
}


int main()
{
	int u, k, v;
	
	cin >> n;
	rep(i, n) rep(j, n) M[i][j] = 0;
	
	rep(i, n)
	{
		cin >> u >> k;
		u--;
		rep(j, k)
		{
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	
	bfs(0);
	
	return 0;
}


/*
void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}
*/


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<vector<int>> vv(m);
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		vv[x % m].emplace_back(x);
	}
	for(int i = 0; i < m; i++) sort(vv[i].begin(), vv[i].end());
	int ans = 0;
	for(int i = 0; i < m; i++){
		int j = (m - i) % m;
		if(i > j) continue;
		if(i == j){
			ans +=vv[i].size() / 2;
			continue;
		}
		int p = 0;
		for(int k = 0; k + 1 < vv[i].size(); k++) if(vv[i][k] == vv[i][k + 1]){
			p++;
			k++;
		}
		int q = 0;
		for(int k = 0; k + 1 < vv[j].size(); k++) if(vv[j][k] == vv[j][k + 1]){
			q++;
			k++;
		}
		int is = vv[i].size(), js = vv[j].size();
		if(is > js){
			swap(is, js);
			swap(p, q);
		}
		int sel = min((js - is) / 2, q);
		ans += sel;
		js -= sel * 2;
		ans += min(is, js);
	}
	cout << ans << endl;
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;
long double pi = 3.141592653589793238462643383279;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, h, m;
    cin>>a>>b>>h>>m;

    long double ang1 = 2 * pi * h / 12;
    ang1 = ang1 + 2 * pi * m / (12 * 60);
    long double ang2 = m * 2 * pi / 60;
    long double ang;

    ang = ang2 - ang1;

    long double ans = a * a + b * b - 2 * a * b * cos(ang);
    ans = sqrt(ans);
    cout<<setprecision(10)<<fixed<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4104
#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(int n)
{
    if (n == 2) return true;

    double sqn = sqrt(n);
    for (int i = 3; i <= sqn; i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

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

    if (x != 2 && x % 2 == 0) ++x;
    while (!isPrime(x)) {
        x += 2;
    }

    cout << x << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
 
//define
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int 

//typedef
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long inf = 1000000000000000000;

using namespace std;

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

ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void update(int n, vi &v, int x, int ch)
{
    while(x<=n)
    {
        v[x]+=ch;
        x+=(x&(-x));
    }
}

int query(vi &v, int x)
{
    int ans=0;
    while(x>0)
    {
        ans+=v[x];
        x-=(x&(-x));
    }
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    ll mx=0, ans=0;
    rep(i,n)
    {
        ll x;
        cin>>x;
        ans+=max(0LL, mx-x);
        mx=max(mx,x);
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int f[100010];
	int a[100010];
	for(int i=1;i<=n+1;i++) cin>>f[i];
	for(int i=1;i<=n;i++) cin>>a[i];
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=f[i]) ans+=(long long)f[i],a[i]-=f[i],f[i]=0;
		else ans+=(long long)a[i],f[i]-=a[i],a[i]=0;
		if(a[i]>=f[i+1]) ans+=(long long)f[i+1],a[i]-=f[i+1],f[i+1]=0;
		else ans+=(long long)a[i],f[i+1]-=a[i],a[i]=0;
	}
	cout<<ans<<endl;
}

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

using pii = pair<int, int>;

template <typename T>
class fenwick_tree {
public:
    fenwick_tree(int n) : n(n), dat(n, 0) {}

    void add(int i, T value) {
        for(; i<n; i |= i + 1) {
            dat[i] += value;
        }
    }

    T sum(int i) const {
        T res = 0;
        for(; i>=0; i = (i & (i+1)) - 1) {
            res += dat[i];
        }
        return res;
    }
    // [l, r)
    T sum(int l, int r) const {
        return sum(r-1) - sum(l-1);
    }

private:
    const int n;
    std::vector<T> dat;
};


int main() {
    int N, M;
    cin >> N >> M;
    fenwick_tree<int> bit(M + 1);

    vector<vector<pii>> range(100001);
    for(int i = 0; i < N; ++i) {
        int l, r;
        cin >> l >> r;
        range[r - l + 1].emplace_back(l, r);
    }

    int sum = N;
    for(int d = 1; d <= M; ++d) {
        sum -= range[d - 1].size();
        int res = sum;
        for(auto& p : range[d - 1]) {
            bit.add(p.first, 1);
            bit.add(p.second + 1, -1);
        }
        for(int i = d; i <= M; i += d) {
            res += bit.sum(i);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int h, w;
int fld_cnt;
char fld[55][55];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int d[55][55];

int bfs(int sx, int sy) {
    queue<P> que;
    que.push(P(sx, sy));
    Fill(d, -1);
    d[sy][sx] = 1;

    while(que.size()) {
        P p = que.front();
        que.pop();
        if(p.first == w && p.second == h) break;
        rep(i, 4) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(fld[ny][nx] == '#' || d[ny][nx] != -1) continue;
            d[ny][nx] = d[p.second][p.first] + 1;
            que.push(P(nx, ny));
        }
    }
    return d[h][w];
}

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

    cin >> h >> w;
    Fill(fld, '#');
    rep(i, h) {
        rep(j, w) {
            cin >> fld[i+1][j+1];
            if(fld[i+1][j+1] == '#') fld_cnt++;
        }
    }
    int dist = bfs(1, 1);
    if(dist == -1) {
        puts("-1");
        return 0;
    }
    int ans = h * w - dist - fld_cnt;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
	int n, m,cnt=0;
	cin >> n >> m;
	if (n % 2 == 0) {
		for (int i = 1;i <= n / 4;i++) {
			cout << i << " " << n / 2 + 1 - i << endl;
			cnt++;
			if (cnt == m)return 0;
		}
		for (int i = 1;;i++) {
			cout << n / 2 + i +1<< " " << n + 1 - i << endl;
			cnt++;
			if (cnt == m)return 0;
		}
	}
	else {
		for (int i = 1;i <= n / 4;i++) {
			cout << i << " " << n / 2 + 1 - i << endl;
			cnt++;
			if (cnt == m)return 0;
		}
		for (int i = 1;;i++) {
			cout << n / 2 + i << " " << n + 1 - i << endl;
			cnt++;
			if (cnt == m)return 0;
		}
	}
	
}


Measured memory_bytes: 3168
from decimal import Decimal
N = int(input())

target = [list(input().split()) for i in range(N)]

result = 0

for t in target:
    if t[1] == 'JPY':
        result += int(t[0])
    else:
        #print(Decimal(t[0]) * Decimal(38000.0))
        result += Decimal(t[0]) * Decimal(380000.0)
print(result)

Measured memory_bytes: 5076
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int d[200010][4][4][4]={};
char w[200010][4][4][4]={};
int f[200010][4][4][4]={};
void g(int i,int j,int k,int l,int a,int b,int c,char s){
  d[i][j][k][l]=1;
  f[i][j][k][l]=a*16+b*4+c;
  w[i][j][k][l]=s;
}
int main(){
  int n,a,b,c,i,j,k,l;
  char s[1000010];
  scanf("%d %d %d %d",&n,&a,&b,&c);
  if(a>3)a=3;
  if(b>3)b=3;
  if(c>3)c=3;
  d[0][a][b][c]=1;
  for(i=0;i<n;i++){
    scanf("%s",s);
    for(j=0;j<4;j++){
      for(k=0;k<4;k++){
	for(l=0;l<4;l++){
	  if(d[i][j][k][l]==0)continue;
	  if(s[1]=='B'){
	    if(k){  
	      g(i+1,MIN(j+1,3),k-1,l,j,k,l,'A');
	      //if(k==3)g(i+1,MIN(j+1,3),k,l,j,k,l,'A');
	    }
	    if(j){
	      g(i+1,j-1,MIN(k+1,3),l,j,k,l,'B');
	      //if(j==3)g(i+1,j,MIN(k+1,3),l,j,k,l,'B');
	    }
	  }
	  if(s[0]=='A'&&s[1]=='C'){
	    if(l){
	      g(i+1,MIN(j+1,3),k,l-1,j,k,l,'A');
	      //if(l==3)g(i+1,MIN(j+1,3),k,l,j,k,l,'A');
	    }
	    if(j){
	      g(i+1,j-1,k,MIN(l+1,3),j,k,l,'C');
	      //if(j==3)g(i+1,j,k,MIN(l+1,3),j,k,l,'C');
	    }
	  }
	  if(s[0]=='B'){
	    if(l){
	      g(i+1,j,MIN(k+1,3),l-1,j,k,l,'B');
	      //if(l==3)g(i+1,j,MIN(k+1,3),l,j,k,l,'B');
	    }
	    if(k){
	      g(i+1,j,k-1,MIN(l+1,3),j,k,l,'C');
	      //if(k==3)g(i+1,j,k,MIN(l+1,3),j,k,l,'C');
	    }	 
	  }
	}
      }
    }
  }
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      for(k=0;k<4;k++){
	if(d[n][i][j][k]){//printf("%d %d %d",i,j,k);
	  printf("Yes\n");
	  for(l=n;l;l--){
	    a=f[l][i][j][k];
	    s[l]=w[l][i][j][k];
	    i=a/16;
	    j=(a%16)/4;
	    k=a%4;//printf("%d %d %d\n",i,j,k);
	  }
	  for(l=0;l<n;l++)printf("%c\n",s[l+1]);
	  return 0;
	}
      }
    }
  }
  printf("No\n");
  return 0;
}


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

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll ok = 1e9, ng = 0;
    while (ok > ng + 1) {
        ll mi = (ok + ng) / 2;
        int t = 0;
        rep(i, N) {
            t += (A[i] + mi - 1) / mi - 1;
        }
        if (t <= K) {
            ok = mi;
        } else {
            ng = mi;
        }
    }
    cout << ok << "\n";
}

Measured memory_bytes: 3992
n, l = [int(v) for v in input().split()]
a_s = [int(v) for v in input().split()]

piv = -1
b_s = []
for i in range(n - 1):
  a2 = a_s[i] + a_s[i + 1]
  b_s.append(a2)
  if a2 >= l:
    piv = i

if piv == -1:
  print("Impossible")
else:
  print("Possible")
  for i in range(piv):
    print(i + 1)
  for i in range(n-2, piv - 1, -1):
    print(i + 1)

Measured memory_bytes: 14052
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
if n % 2 == 1:
    if a[0] != 0:
        print(0)
        exit()
    for i in range(1, n, 2):
        if a[i] != a[i + 1] or a[i] != i + 1:
            print(0)
            exit()
else:
    for i in range(0, n, 2):
        if a[i] != a[i + 1] or a[i] != i + 1:
            print(0)
            exit()
print(2 ** (n // 2) % (10 ** 9 + 7))

Measured memory_bytes: 13880
#include<stdio.h>
int main(void)
{
	int x,y,z;
	
	
	scanf("%d",&x);
	scanf("%d",&y);
	z=x+y;
	
	if(z>0) {
		printf("1\n");
	}
	else if(z==0){
		printf("0\n");
	}
	else if(z<0) {
		printf("-1\n");
	}
	
	return 0;
}


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

using namespace std;

int INF = 1e9 + 5;

int main() {
    int n;
    cin >> n;
    int t = 0, x = 0, y = 0;
    for (int i = 0; i < n; i++) {
        int t1, x1, y1;
        cin >> t1 >> x1 >> y1;
        int difft = t1 - t, dist = abs(x1 - x) + abs(y1 - y);
        
        if (dist > difft) {
            cout << "No" << endl;
            return 0;
        } 
        else if ((difft - dist) % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
        
        t = t1;
        x = x1;
        y = y1;
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std; 

void printString(ll n) { 
  string str;
  int i = 0; // To store current index in str which is result 

  while (n > 0) { 
    // Find remainder 
    int rem = n % 26; 

    // If remainder is 0, then a 'Z' must be there in output 
    if (rem == 0) { 
      str.push_back('z'); 
      n = (n / 26) - 1; 
    } 
    else // If remainder is non-zero 
    {
      str.push_back((rem - 1) + 'a'); 
      n = n / 26; 
    } 
  } 

  // Reverse the string and print result 
  reverse(str.begin(), str.end()); 
  cout << str << endl; 

  return; 
} 

int main() {
  int TC = 1;
  // int cnt = 1;
  while (TC--) {
    ll N;
    // N = cnt++;
    cin >> N;
    printString(N);
  }
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<sstream>
#include<cstdio>
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
# define ull unsigned long long int
# define ll long long int
# define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define vull vector<unsigned long long>
# define vll vector<long long>
# define vl vector<long>
# define vi vector<int>
# define vs vector<string>
# define vvi vector<vector<int>>
# define vii vector<pair<int,int>>
# define rep(i,a,b) for(int i=a;i<=b;i++)
# define pb push_back
# define pop pop_back
# define MOD 1e9+7
# define mp make_pair
# define F first
# define S second
# define all(v) v.begin(),v.end()
# define _ <<" "
//typedef _int128 Bigint;
using namespace std;
ull size[50];
double gcd(double a,double b)
{
    return a < 0.01 ? b : gcd(fmod(b,a),a);
}
ll max(ll a,ll b)
{
        return (a>b)?a:b;
}
ll max(ll a,ll b,ll c)
{
        return max(a,max(b,c));
}
ll min(ll a,ll b)
{
        return (a<b)?a:b;
}
ll min(ll a,ll b,ll c)
{
        return min(a,min(b,c));
}
void swap(ll *x,ll *y)
{
        ll temp;
        temp=*y;
        *y=*x;
        *x=temp;
}
ull patty(int level,ull x)
{
        if(x<=level)
        return 0;
        if(level==0)
        return 1;
        //if(x>size[level])
        //return pow(2,level+1);
        if(x<=size[level-1]+1)
        {
                return patty(level-1,x-1);
        }
        else if(x==size[level-1]+2)
        return pow(2,level)-1+1;
        else if(x>size[level-1]+2)
        return pow(2,level)-1+1+patty(level-1,x-2-size[level-1]);
}
int main()
{
//clock_t t=clock();
fastio;
/*int t;cin>>t;
while(t--)
{
        
}*/
int n;ull x;cin>>n>>x;size[0]=1;
for(int i=1;i<n;i++)
{
        size[i]=2*size[i-1]+3;
}
cout<<patty(n,x)<<endl;
//t=clock()-t;
//cout<<"Time is "<<(float)((float)t/CLOCKS_PER_SEC)<<endl;
return 0;
}

Measured memory_bytes: 512
WHxyr = input().split()
W = int(WHxyr[0])
H = int(WHxyr[1])
x = int(WHxyr[2])
y = int(WHxyr[3])
r = int(WHxyr[4])


if x-r<0 or x+r>W or y-r<0 or y+r>H:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 7664
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

void dfs(vector<vector<int>> &graph, vector<int> &ok, int p){
    ok[p] = 1;
    for(auto&& c : graph[p]){
        if(ok[c] == 1) continue;
        dfs(graph, ok, c);
    }
}

int main(void)
{
    int N,M;
    cin >> N >> M;
    vector<pii> edge;
    REP(i, M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edge.pb(pii(a,b));
    }

    vector<int> ok(N, 0);

    int ans = 0;
    REP(i, M){
        vector<vector<int>> graph(N, vector<int>());
        REP(j, M){
            if(i == j) continue;
            int a = edge[j].fi;
            int b = edge[j].se;
            graph[b].pb(a);
            graph[a].pb(b);

        }
        
        REP(j, N) ok[j] = 0;

        dfs(graph, ok, 0);

        REP(j, N) if(ok[j] == 0){
            ans++;
            break;
        }
    }

    pr(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  int ans=0;
  while(a[0] != a[1] || a[0] != a[2] || a[1] != a[2]){
    VSORT(a);
    if((a[0] + 2) <= a[2]) a[0] += 2;
    else{
      a[0]+=1;
      a[1]+=1;
    }
    ans++;
  }
  cout << ans << endl;
}

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

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)
#define pb push_back
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double E=2.718281828459045;
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int MOD=1e3;
const int N=1e5+5;
const ll maxn=1e6+5;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};

ll n,a,b;
void solve()
{
    if(a+b>n+1||a*b<n)
    {
        cout<<-1;
        return ;
    }
    while(n>0)///每轮都是构造一个递增的子序列
    {
        ll x=min(a,n-b+1);///每一轮都取递增数和递减数中较小的那个
        //cout<<"x="<<x<<endl;
        for(ll i=n-x+1;i<=n;i++)
            cout<<i<<" ";
        n-=x;///x 为这一轮构造的递增子序列的个数
        b--;///递减的值 b 每一轮 -1
    }
}
int main()
{
    while(cin>>n>>a>>b)
    {
        solve();
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <iostream>

const int N = 100000;

int a[N], b[N];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("A.in", "r", stdin);
#endif
    int n;
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; ++ i) {
            scanf("%d%d", a + i, b + i);
        }
        long long result = 0;
        for (int i = n - 1; i >= 0; -- i) {
            int rem = (a[i] + result) % b[i];
            if (rem > 0) {
                result += b[i] - rem;
            }
        }
        std::cout << result << std::endl;
    }
}

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

int main() {
    char ch;
    int cnt[26]={};
    while(cin>>ch){
        ch=tolower(ch);
        if(isalpha(ch)){
            cnt[ch-'a']++;
        }
    }
    for(int i=0;i<26;i++){
        printf("%c : %d\n",i+'a',cnt[i]);
    }

}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn =2e3+5;
const double pi=acos(-1);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double jiao1=2*pi*m/60.0;
	double shi=h*60.0+m;
	double jiao2=2*pi*shi/720.0;
	/*if(jiao1>=pi)
    {
        jiao1=2.0*pi-jiao1;
    }
    if(jiao2>=pi)
    {
        jiao2=2.0*pi-jiao2;
    }*/
    //cout<<jiao1<<" "<<jiao2<<'\n';
    double jiao=abs(jiao1-jiao2);
    if(jiao>pi)
    {
        jiao=2*pi-jiao;
    }
    double ans=sqrt(a*a+b*b-2.0*a*b*cos(jiao));
    //double ans=sqrt(a*a+b*b-2.0*a*b*cos(jiao));
    cout<<fixed<<setprecision(15)<<ans<<'\n';



}


Measured memory_bytes: 4248
# 屈辱的ウンコードいつか綺麗に書けるように
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = a1 + a2 +a3
n = int(input())
b = [int(input()) for i in range(n)]

for i in b:
    if i in a:
        a[a.index(i)] = 0

if a[0] == a[1] == a[2] == 0:
    print('Yes')
elif a[3] == a[4] == a[5] == 0:
    print('Yes')
elif a[6] == a[7] == a[8] == 0:
    print('Yes')
elif a[0] == a[3] == a[6] == 0:
    print('Yes')
elif a[1] == a[4] == a[7] == 0:
    print('Yes')
elif a[2] == a[5] == a[8] == 0:
    print('Yes')
elif a[0] == a[4] == a[8] == 0:
    print('Yes')
elif a[2] == a[4] == a[6] == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;

constexpr int MAX = 1001;
long long fac[MAX], inv[MAX], finv[MAX];
void CombInit(){
    fac[0] = inv[0] = finv[0] = 1;
    fac[1] = inv[1] = finv[1] = 1;
    for(int i=2; i<MAX; ++i){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long Comb(int n,int k){
    if(n < 0 || k < 0 || n < k) return 0;
    return (fac[n] * finv[n-k] % MOD) * finv[k] % MOD;
}

ll mod_pow(ll x,int e){
    ll y = 1;
    while(e) {
        if(e & 1) y = y * x % MOD;
        x = x * x % MOD;
        e >>= 1;
    }
    return y;
}


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    CombInit();
    ll ans = 0;
    for(int i = 1; i < k; ++i) {
        ll num = Comb(k, i) * mod_pow(k - i, n);
        if(i&1) ans = (ans + num) % MOD;
        else ans = (ans - num + MOD) % MOD;
    }
    cout << (mod_pow(k, n) - ans + MOD) % MOD * finv[k] % MOD << endl;
    return 0;
}


Measured memory_bytes: 3196
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (w, h): (usize, usize) = util::get2();
    let p: Vec<usize> = (0..w).map(|_| util::get()).collect();
    let q: Vec<usize> = (0..h).map(|_| util::get()).collect();

    let mut v: Vec<(usize, bool)> = p.iter()
        .map(|&c| (c, true))
        .chain(q.iter().map(|&c| (c, false)))
        .collect();

    v.sort();

    let m = (w + 1) * (h + 1) - 1;
    let mut used = 0;
    let mut wc = 0;
    let mut hc = 0;
    let mut ans = 0;

    for &(c, t) in &v {
        if t {
            let u = min(h + 1 - hc, m - used);
            wc += 1;
            ans += u * c;
            used += u;
        } else {
            let u = min(w + 1 - wc, m - used);
            hc += 1;
            ans += u * c;
            used += u;
        }
        // debug!(used, wc, hc, ans);
        if used == m {
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540