akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main(){
	int N,K;
	string S;
	cin>>N>>K>>S;
	vector<int> c;
	c.push_back(0);
	for(int i=1;i<N;i++){
		if(S[i-1]!=S[i]) c.push_back(i);
	}
	int R=c.size();
	int ans=0;
	for(int i=0;i<R;i++){
		if(S[c[i]]=='1')
			if(i+2*K+1<R){
				ans=max(ans,c[i+2*K+1]-c[i]);
			}
			else ans=max(ans,N-c[i]);
		if(S[c[i]]=='0'){
			if(i+2*K<R){
				ans=max(ans,c[i+2*K]-c[i]);
			}
			else ans=max(ans,N-c[i]);
		}
	}
	cout<<ans;
}

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

// #define int         long long 
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(v)      v.begin(),v.end()
#define ff          first
#define ss          second
#define endl        "\n"
#define mod         1000000007
#define PI          3.14159265 
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define print(x)    for(auto el: x) cout<<el<<" ";cout<<endl;





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

    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];

    int dp[n] = {0};

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

    for(int i=2; i<n; i++)
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));

    cout<<dp[n-1]<<endl;

    return;    
}




int32_t main() 
{
    
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    FIO;
    int test;

    // cin>>test;
    test = 1;
    
    while(test--)
        solve();

    return 0;
}

Measured memory_bytes: 4428
#include <stdio.h>

int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  
  if((a+b)>=c){
	printf("%d",b+c);
  }
  else
    printf("%d",a+(2*b)+1);
  
  return 0;
}

Measured memory_bytes: 128
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end

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

    ll n, q;
    in >> n >> q;
    string s;
    in >> s;

    ll db[n] = {};
    REP_AB(i, 1, n-1){
        db[i] = db[i-1];
        if(s[i-1] == 'A' && s[i] == 'C'){
            db[i]++;
        }
    }
    ll l, r;
    REP(i, q){
        in >> l >> r;
        out << db[r-1] - db[l-1] << endl;
    }
}


Measured memory_bytes: 1872
n=int(input())
s=[str(input()) for _ in range(n)]

from collections import Counter
results = Counter(s)

max_num = results.most_common()[0][1]
max_key_list = [kv[0] for kv in results.items() if kv[1] == max_num]
for i in sorted(max_key_list):
  print(i)


Measured memory_bytes: 49508
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
const int N = 1e+5;
int dp[N][3];
int a[N];
int b[N];
int c[N];

int n;

void helper(int i)
{
	if(i==n)
	{
		return;
	}

	dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
	dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
	dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
	helper(i+1);

}
int32_t main()
{
	cin>>n;

	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}

	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	
	helper(1);
	
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	return 0;

}

Measured memory_bytes: 4992
#[allow(unused_imports)]
use std::io::Write;

#[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)*}
    };
}

#[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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

#[allow(non_snake_case)]
fn main() {
    input![N: usize, X: usize, L: [usize; N]];
    let mut ans = 1;
    let mut sum = 0;
    for l in L {
        sum += l;
        if sum <= X {
            ans += 1;
        } else {
            break;
        }
    }
    println!("{}", ans);
}


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())
#define din(x) int x; cin >> x

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 450555;
const int M = 1155;

void solve() {
    ll a,b;
    cin >> a >> b;
    
    cout << a*b;


}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

const int MOD = 1e9 + 7;

int n, m;
int s, t;
long long dist[2][500000];
long long ways[2][500000];
vector<pair<int, int> > graph[500000];
long long ans = 0;

void djkstra(int v, int slot)
{
    set<pair<long long, int> > s;
    s.insert({0, v});
    for (int i = 1; i <= n; i++) dist[slot][i] = 1e18;
    dist[slot][v] = 0;
    ways[slot][v] = 1;
    while (s.size())
    {
        auto it = s.begin();
        s.erase(s.begin());
        int u = (*it).second;
        for (auto e : graph[u])
        {
            int weight = e.second;
            int ver = e.first;
            if (dist[slot][ver] < dist[slot][u] + weight) continue;
            if (dist[slot][ver] > dist[slot][u] + weight)
            {
                s.erase({dist[slot][ver], ver});
                dist[slot][ver] = dist[slot][u] + weight;
                ways[slot][ver] = 0;
                s.insert({dist[slot][ver], ver});
            }
            if (dist[slot][ver] == dist[slot][u] + weight) ways[slot][ver] = (ways[slot][ver] + ways[slot][u]) % MOD;
        }
    }
    return;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> s >> t;
    for (int i = 0; i < m; i++)
    {
        int v, u, w;
        cin >> v >> u >> w;
        graph[v].push_back({u, w});
        graph[u].push_back({v, w});
    }
    djkstra(s, 0);
    djkstra(t, 1);
    ans = ways[0][t] * ways[0][t] % MOD;
    long long len = dist[0][t];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < graph[i].size(); j++)
        {
            int v = graph[i][j].first;
            if (dist[0][i] + dist[1][v] + graph[i][j].second == len && dist[0][i] * 2 < len && dist[0][v] * 2 > len && dist[1][v] * 2 < len && dist[1][i] * 2 > len)
            {
                ans = (ans + MOD - ways[0][i] * ways[0][i] % MOD * ways[1][v] % MOD * ways[1][v] % MOD) % MOD;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (dist[0][i] * 2 == len && dist[1][i] * 2 == len)
        {
            long long up = 0;
            long long down = 0;
            for (int j = 0; j < graph[i].size(); j++)
            {
                int v = graph[i][j].first;
                if ((dist[1][v] + graph[i][j].second) * 2 == len) up = (up + ways[1][v]) % MOD;
                if ((dist[0][v] + graph[i][j].second) * 2 == len) down = (down + ways[0][v]) % MOD;
            }
            ans = (ans + MOD - up * up % MOD * down % MOD * down % MOD) % MOD;
        }
    }
    cout << ans;
}


Measured memory_bytes: 34804
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int solve(const int n, int a[100])
{
  sort(a, a + n, greater<int>());
  int score1 = 0, score2 = 0;
  REP(i, n) {
    if (i % 2 == 0)
      score1 += a[i];
    else
      score2 += a[i];
  }
  return score1 - score2;
}

int main()
{
  int n;
  int a[100];
  cin >> n;
  REP(i, n) cin >> a[i];
  cout << solve(n, a) << endl;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll a, b;

    cin >> a >> b;

    if(a<10 && b<10){
        cout << a*b << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll x,ans=0;
            cin>>x;
            ans=ans+1000*(x/500);
            x=x%500;
            ans=ans+5*(x/5);
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout << a*b/2 << endl;
  return 0;
}


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

int main(){
    double f;
    int a,b,e,g;
    cin>>a>>b;
    e=a/b;
    g=a%b;
    f=double(a)/double(b);
    cout<<e<<" "<<g<<" ";
    printf("%.8lf\n", f);
    
    
}


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

ll powll(ll x,ll t)
{
    if(!t) return 1;
    ll a = powll(x,t>>1);
    a*=a;
    if(t&1) a*= x;
    return a;
}

int main(){
    ll n;
    ll a[200000];
    ll max,maxll;
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    ll ans = 1;
    maxll = numeric_limits<ll>::max();
    max = powll(10,18);
    rep(i,n){
        ll b = maxll / ans;
        ans *= a[i];
        //cout << b << ":" << ans << endl;
        if(b < a[i]){ans=-1;break;}
        if(ans > max){ans = -1;break;}
    }
    rep(i,n){
        if(a[i] == 0){ ans=0;}
    }
    cout << ans << endl;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
*/

int main(){
cout<<fixed<<setprecision(10);

string S;cin>>S;
  int ans=700;
  for(int i=0;i<3;i++){
    if(S[i]=='o'){
      ans+=100;
    }
  }
    cout<<ans<<endl;
}




Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> a(N);
  for(auto& val: a)
    std::cin >> val;
  int x = 0;
  for(auto val: a)
    x ^= val;
  for(auto val: a)
    std::cout << (x ^ val) << " ";
  std::cout << std::endl;
  return 0;
}



Measured memory_bytes: 3932
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def main():
    N, M = LI()
    jobsavailable = [[] for _ in range(10**5+1)]
    for _ in range(N):
        a, b = LI()
        if a > M:
            continue
        jobsavailable[M-a].append(b)
    cur_jobs = []
    cnt = 0
    for i in range(1, M+1):
        jobs = jobsavailable[M-i]
        for j in jobs:
            heapq.heappush(cur_jobs, -j)
        if cur_jobs != []:
            j = -heapq.heappop(cur_jobs)
            cnt += j
    print(cnt)

main()



Measured memory_bytes: 20968
n= int(input())

i = 0
base = 1
digits = ''

while n!= 0:
  if n % (base*2) == 0:
    digits += '0'
  else:
    digits += '1'
    n -= base 
  
  i += 1
  base *= -2

if digits=='':
  digits='0'
  
print(digits[::-1])  

Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      ans += Integer.numberOfTrailingZeros(a);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 48560
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	long long N;
	cin >> N;

	string march = "MARCH";

	vector<vector<string>> S(march.length(), vector<string>());

	string str;
	size_t pos = 0;
	for (long long i = 0; i < N; i++) {
		cin >> str;
		pos = march.find(str.substr(0, 1));
		if (pos != string::npos) {
			S[pos].push_back(str);
		}
	}

	long long ans = 0;
	for (size_t i = 0; i < S.size() - 2; i++) {
		for (size_t j = i + 1; j < S.size() - 1; j++) {
			for (size_t k = j + 1; k < S.size(); k++) {
				ans += (long long)S[i].size() * (long long)S[j].size() * (long long)S[k].size();
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7308
#include <stdio.h>

int main (void)
{
        int n,c,i;

        scanf("%d",&n);

        char s[n];

        scanf("%s",s);

        if(n%2==1) printf("No");
        else{
        c=0;
        for(i=0;i<n/2;i++)
                if(s[i]==s[i+(n/2)]) c++;

        if(c==n/2) printf("Yes");
        else  printf("No");
        }
        return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Arrays;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int[] b = new int[a];
    for(int i = 0;i < b.length;i++){
      b[i] = sc.nextInt();
    }
    Arrays.sort(b);
    double c = (double)(b[0] + b[1]) / 2;
    for(int j = 2; j < b.length; j++){
      c = (double)(c + b[j]) / 2;
    }
    System.out.println(c);
  }
}

Measured memory_bytes: 21716
import java.util.*;

public class Main {
    static String[] s;
    static int[] a;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        a = new int[4];
        s = new String[4];
        s = sc.next().split("");

        for (int i = 0; i < s.length; i++) {
            a[i] = Integer.parseInt(s[i]);
        }
        //bit全探索 2**3
        for (int i = 0; i < (1 << 3); i++) {

            int tmp = a[0];
            for (int j = 0; j < 3; j++) {
                if ((1 & i >> j) == 1) {
                    tmp += a[j + 1];
                } else {
                    tmp -= a[j + 1];
                }
            }
            if (tmp == 7) {
                System.out.print(s[0]);
                for (int j = 0; j < 3; j++) {
                    if ((1 & i >> j) == 1) {
                        System.out.print("+");
                    } else {
                        System.out.print("-");
                    }
                    System.out.print(a[j + 1]);
                }
                System.out.println("=7");
                return;
            }
        }
    }
}



Measured memory_bytes: 21716
from collections import deque

H, W = map(int, input().split())
S = [['#'] * (W + 2) for _ in range(H + 2)]
c = 0
for i in range(1, H+1):
    s = list(input())
    S[i] = ['#'] + s + ['#']
    c += s.count('.')

step = [(1, 0), (-1, 0), (0, 1), (0, -1)]
que = deque([(1, 1)])
S[1][1] = 1
while que:
    h, w = que.popleft()
    if (h, w) == (H, W):
        break
    for dh, dw in step:
        nh = h + dh
        nw = w + dw
        if S[nh][nw] != '.':
            continue
        que.append((nh, nw))
        S[nh][nw] = S[h][w] + 1
print(-1 if S[H][W] == '.' else c - S[H][W])

Measured memory_bytes: 3316
n = int(input())
*h, = map(int, input().split())
INF = float('inf')
costs = [INF for _ in range(n)]
costs[0] = 0
costs[1] = abs(h[1] - h[0])
for i in range(2, n):
  costs[i] = min([costs[i], 
                  costs[i - 2] + abs(h[i] - h[i - 2]),
                  costs[i - 1] + abs(h[i] - h[i - 1])])
ans = int(costs[-1])
print(ans)

Measured memory_bytes: 13980
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
const lint INF = 1001001001001001LL;
const lint MOD = 1000000007LL;
int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
void possible(){ cout << "possible" << endl; }
void Possible(){ cout << "Possible" << endl; }
void POSSIBLE(){ cout << "POSSIBLE" << endl; }
void impossible(){ cout << "impossible" << endl; }
void Impossible(){ cout << "Impossible" << endl; }
void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()

int main(){
  
  string s; cin >> s;
  string t; cin >> t;
  lint n = s.size();
  lint m = t.size();
  vector<lint> cnt1(n + 1, 0);
  vector<lint> cnt2(m + 1, 0);
  rep(i, n){
    if(s[i] == 'A') cnt1[i + 1] = 1;
    else cnt1[i + 1] = 2;
    cnt1[i + 1] += cnt1[i];
  }

  rep(i, m){
    if(t[i] == 'A') cnt2[i + 1] = 1;
    else cnt2[i + 1] = 2;
    cnt2[i + 1] += cnt2[i];
  }


  lint q; cin >> q;
  rep(i, q){
    lint a, b, c, d; cin >> a >> b >> c >> d;
    lint val1 = cnt1[b] - cnt1[a - 1];
    lint val2 = cnt2[d] - cnt2[c - 1];
    if((lint)abs(val1 - val2) % 3 == 0) YES();
    else NO();
  }
  return 0;
}


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

    using namespace std;

    const int MOD=1e9+7;
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        string s,t;
        cin>>s>>t;
        int n=s.size();
        int m=t.size();
        vector<vector<int>>a(n+1,vector<int>(m+1));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(s[i-1]==t[j-1])
                    a[i][j]=a[i-1][j-1]+1;
                else
                    a[i][j]=max(a[i-1][j],a[i][j-1]);
            }
        }
//        for(int i=0;i<=n;i++){
//            for(int j=0;j<=m;j++)
//                cout<<a[i][j]<<" ";
//            cout<<"\n";
//        }
        string ans="";
        int x=n,y=m;
        while(y!=0 && x!=0){
            if(a[x-1][y]==a[x][y])
                --x;
            else if(a[x][y-1]==a[x][y])
                --y;
            else{
                ans=t[y-1]+ans;
                --y;
                --x;
            }
        }
        cout<<ans;
        return 0;
    }


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, ans;
ll W[MAXN];
int par[MAXN];
bool mark[MAXN], good[MAXN];
pair<int, pii> E[MAXN];
vector<pii> G[MAXN];

int getpar(int x){ return (par[x]==x?x:par[x]=getpar(par[x]));}

void dfs(int node, int val){
	for (pii p:G[node]) if (p.second<=val && !mark[p.second]){
		mark[p.second]=1;
		dfs(p.first, val);
		ans++;
//		cerr<<"add edge "<<p.second<<"\n";
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<=n; i++) cin>>W[i], par[i]=i;
	for (int i=0; i<m; i++) cin>>E[i].second.first>>E[i].second.second>>E[i].first;
	sort(E, E+m);
	for (int i=0; i<m; i++){
		int u=E[i].second.first, v=E[i].second.second;
		G[u].pb({v, i});
		G[v].pb({u, i});
	}
	for (int i=0; i<m; i++){
		int u=getpar(E[i].second.first), v=getpar(E[i].second.second);
		if (u!=v){
			par[u]=v;
			W[v]+=W[u];	
		}
//		debug2(i, W[v])
		good[i]=(W[v]>=E[i].first);
	}
	for (int i=m-1; ~i; i--) if (good[i]) dfs(E[i].second.first, i);//, debug(i);
	cout<<m-ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 16272
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  auto digit_sum = [](int n) {
    int sum = 0;
    while (n) {
      sum += n%10;
      n /= 10;
    }
    return sum;
  };
  int ans = INF;
  for (int i = 1; i < n; i++) {
    int j = n-i;
    int num = digit_sum(i)+digit_sum(j);
    chmin(ans, num);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int E) {
    int m = INF;
    for (int y = 0; (y * y) <= E; y++) for(int z = 0; (y * y) + (z * z * z) <= E; z++) {
        int x = E - (y * y) - (z * z * z);
        m = min(m, x + y + z);
    }
    cout << m << endl;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    while (cin >> n, n) {
        solve(n);
        //return 0;
    }
}

Measured memory_bytes: 3056
n  = int(input())
h =  list(map(int, input().split()))
h.reverse()
for i in range(n - 1):
    if h[i] < h[i + 1] - 1:
        print("No")
        exit()
    if h[i] == h[i + 1] - 1:
        h[i + 1] -= 1
print("Yes")

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;

int main(){
  int n, m;cin>>n>>m;
  vector<pair<int, int>> student(n), point(m);
  for(int i=0;i<n;i++){
    int a, b;cin>>a>>b;
    student[i]=make_pair(a, b);
  }
  for(int i=0;i<m;i++){
    int a, b;cin>>a>>b;
    point[i]=make_pair(a, b);
  }
  for(int i=0;i<n;i++){
    int min_dis=INF, point_index;
    for(int j=0;j<m;j++){
      int dis=abs(student[i].first-point[j].first)+abs(student[i].second-point[j].second);
      if(min_dis>dis){
        point_index=j;min_dis=dis;
      }
    }
    cout << point_index+1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int w;
bool ok(string s){
    int dist[128]={};
    int num = (1<<w)*(2<<w);
    for(int i=0;i<num;i++) dist[i] = INF;
    dist[0] = 0;
    for(int r=0;r<=num+5;r++){
        bool upd = false;
        for(int i=0;i<num/2;i++){
            int mn = min(dist[2*i],dist[2*i+1]);
            if(dist[2*i] != dist[2*i+1]) upd = 1;
            dist[2*i] = mn; dist[2*i+1] = mn;
            int go = 0; if(s[i] == '1') go = -1;
            int from = 1; if(s[i] == '0') from = 0;
            if(dist[i]+go < dist[2*i]) dist[2*i]=dist[i]+go,upd=1;
            if(dist[i]+go < dist[2*i+1]) dist[2*i+1]=dist[i]+go,upd=1;
            if(dist[i] > dist[2*i]+from) dist[i]=dist[2*i]+from,upd=1;
            if(dist[i] > dist[2*i+1]+from) dist[i]=dist[2*i+1]+from,upd=1;
            go = 1; if(s[i+num/2] == '1') go = 0;
            from = 0; if(s[i+num/2] == '0') from = -1;
            if(dist[i+num/2]+go < dist[2*i]) dist[2*i]=dist[i+num/2]+go,upd=1;
            if(dist[i+num/2]+go < dist[2*i+1]) dist[2*i+1]=dist[i+num/2]+go,upd=1;
            if(dist[i+num/2] > dist[2*i]+from) dist[i+num/2]=dist[2*i]+from,upd=1;
            if(dist[i+num/2] > dist[2*i+1]+from) dist[i+num/2]=dist[2*i+1]+from,upd=1;
        }
        if(r == num+5){
            return !upd;
        }
    }
}
string s;
int main(){
    cin>>w>>s;
    if(ok(s)){
        cout << s << endl;
        return 0;
    }
    for(int i=s.size()-1;i>=0;i--){
        if(s[i] == '1'){
            s[i] = '?'; continue;
        }
        else{
            s[i] = '1';
            if(ok(s)){
                for(int j=i+1;j<s.size();j++){
                    s[j] = '0';
                    if(ok(s)) continue;
                    else s[j] = '1';
                }
                assert(ok(s));
                cout << s << endl;
                return 0;
            }
            else{
                s[i] = '?';
            }
        }
    }
    cout << "no" << endl;
}



Measured memory_bytes: 3240
import sys
r = [0]*(100000+1)
n,k = [int(x) for x in sys.stdin.readline().split()]
for i in range(n):
	a, b = [int(x) for x in sys.stdin.readline().split()]
	r[a] += b
c = 0
for i,j in enumerate(r):
	c += j
	if c >= k:
		print(i)
		break

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

using namespace std;

struct Treap{
    int val;
    char name;
};

Treap Bubble[100],Select[100],t[100];

void BubbleSort(Treap a[],int n){
    for(int i = 0;i<n;i++){
        for(int j=0;j<n-1;j++){
            if(a[j].val > a[j+1].val) swap(a[j],a[j+1]);
        }
    }
}

void SelectSort(Treap a[],int n){
    for(int i = 0;i<n;i++){
        int min = i;
        for(int j=i+1;j<n;j++){
            if(a[j].val<a[min].val) min = j;
        }
        if(min!=i) swap(a[min],a[i]);
    }
}



int main()
{
    int n;
    char s[10];
    cin >> n;
    for(int i = 0;i<n;i++){
        scanf("%s",s);
        Bubble[i].name = s[0];
        Bubble[i].val = s[1]-'0';
        Select[i] = Bubble[i];
        t[i] = Bubble[i];
    }
    BubbleSort(Bubble,n);
    SelectSort(Select,n);
    bool ok = true;
    for(int i = 0;i<n;i++){
        if(Bubble[i].name!=Select[i].name || Bubble[i].val !=Select[i].val) ok = false;
    }
    for(int i = 0;i<n-1;i++){
        printf("%c%d ",Bubble[i].name,Bubble[i].val);
    }
    printf("%c%d",Bubble[n-1].name,Bubble[n-1].val);
    cout << endl;
    cout << "Stable" << endl;
    for(int i = 0;i<n-1;i++){
        printf("%c%d ",Select[i].name,Select[i].val);
    }
    printf("%c%d",Select[n-1].name,Select[n-1].val);
    cout << endl;
    if(ok==true){
        cout << "Stable"<<endl;
    }else{
        cout << "Not stable" << endl;
    }
    
    return 0;
}


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

int main(){
  ll N,A,B;
  
  cin >> N >> A >> B;
  
  if((B-A)%2==0){
    cout << (B-A)/2 << endl;
  }else{
    if(A-1<N-B){
     cout << A+(B-A-1)/2 << endl;
    }else{
      cout << (N-B)+1+(B-A-1)/2 << endl;
    }
  }
  
}

Measured memory_bytes: 256
n = int(input())

def dividable3(x):
    if x % 3 == 0:
        return True
    return False

def include3(x):
    while x > 0:
        if x % 10 == 3:
            return True
        x = x // 10
    return False

def call(x):
    return dividable3(x) or include3(x)

line = ""
for i in range(1, n+1):
    if call(i):
        line += " " + str(i)
print(line)


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

int n, A[200005], S[200005], X[200005];

int getS(int l, int r){
  int res = S[r];
  if( l != 0 ) res -= S[l-1];
  return res;
}

int getX(int l, int r){
  int res = X[r];
  if( l != 0 ) res ^= X[l-1];
  return res;
}

bool check(int l, int r){
  return getS( l, r ) == getX( l, r );
}

int cal(int x){
  
  int l = x, r = n;
  
  while( l + 1 < r ){
    
    int m = ( l + r ) / 2;
    
    if( check( x, m ) == true ) l = m;
    else r = m;
    
  }
  
  return l - x + 1;
}

signed main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++){
    cin>>A[i];
    S[i] = A[i];
    if(i) S[i] += S[i-1];
    X[i] = A[i];
    if(i) X[i] ^= X[i-1];
  }
  
  int ans = 0;
  
  for(int i=0;i<n;i++) ans += cal( i );
  
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include<cstdio>
 
using namespace std;
 
typedef long long int ll;
 
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; }
 
typedef pair<int,int> pair;

double e(int num){
    double sum=0.5*num*(num+1);
    return sum/num;
}
 
int main(){
    int n,k; cin >> n >>k;
    vector<double> a(n); for(int i=0;i<n;i++) cin >> a[i];

    double max=0;

    for(int i=0;i<n;i++){
        a[i]=e(a[i]);
    }

    double num=0;

    for(int i=0;i<k-1;i++){
        num+=a[i];
    }

    for(int i=k-1;i<n;i++){
        num+=a[i];
        if(max<num){
            max=num;
        }
        num-=a[i-k+1];
    }

    //for(auto v : a) cout << v << endl;

    printf("%.7lf\n",max);
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<fstream>
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = 1e5+7;
static const int INF = 0x3f3f3f3f;
static const int MOD = 1e9+7;



int main() {

  int n,a,b;
  cin >> n >> a >>b;


  cout << min(a,b) << " " << max(0,a+b-n);
    return 0;


}

Measured memory_bytes: 256
<?php
while($input_line = fgets(STDIN)){
    $tmp[] = trim($input_line);
}

$k = array_shift($tmp);

$a = explode(" " ,$tmp[0]);

$b = $a[0];
$c = $a[1];

$i=1;
while($i<=$c){
    if($i%$k == 0){
        if($i>=$b){
           $result[] = $i; 
        }
    }
    $i++;
}
if(isset($result)){
    echo "OK";
}else{
    echo "NG";
}
?>

Measured memory_bytes: 16176
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<KeySort> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			long a = sc.nextLong();
			int b = sc.nextInt();
			list.add(new KeySort(b, a));
		}
		Collections.sort(list, new KeySortComparator());
		long money = 0;
		for (int i = 0; i < n; i++) {
			if (list.get(i).key <= m) {
				money += list.get(i).key * list.get(i).sort;
				m -= list.get(i).key;
			} else {
				money += m * list.get(i).sort;
				break;
			}
		}
		System.out.println(money);
	}
}
class KeySort {
	public int key;
	public long sort;
	public KeySort(int key, long sort) {
		this.key = key;
		this.sort = sort;
	}
}

class KeySortComparator implements Comparator<KeySort> {
	@Override
	public int compare(KeySort sort1, KeySort sort2) {
		if (sort1.sort == sort2.sort) {
			return 0;
		} else if (sort1.sort > sort2.sort) {
			return 1;
		} else {
			return -1;
		}
	}
}

Measured memory_bytes: 92172
class uf_tree:
    def __init__(self, n):
        self._size = n
        self.sizes = [1] * n
        self.par = list(range(n))

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

    def unite(self, x, y):
        self._size -= 1
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.par[y] = x
        self.sizes[x] += self.sizes[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.sizes[self.find(x)]


def com(x):
    return x*(x-1)//2

n, m = map(int, input().split())
AB = [ list(map(int, input().split())) for _ in range(m) ]

ans = []
benri = 0

uf = uf_tree(n+1)

benri = 0

for a, b in AB[::-1]:
    ans += [ com(n) - benri ]    
    if uf.same(a, b):
        continue

    a_benri = com(uf.size(a) )
    b_benri = com(uf.size(b) )

    uf.unite(a, b)
    sum_benri = com( uf.size(a) )
    benri += sum_benri - a_benri - b_benri

print (*ans[::-1], sep="\n")



Measured memory_bytes: 36380
#include <iostream>

using namespace std;

int main(){
  int N;
  int A[200010];
  bool flg=false;
  cin >> N;
  A[0] = -1;
  for(int i=1;i<=N;i++){
    cin >> A[i];
    if(A[i] - A[i-1] > 1){
      flg = true;
    }
  }
  if(flg){
    cout << -1 << endl;
    return 0;
  }
  A[N+1] = A[N];
  long long counter = 0;
  for(int i=N;1<=i;i--){
    if(A[i] >= A[i+1]){
      counter += A[i];
    }
  }

  cout << counter << endl;

  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc127C
{
    class Program
    {
        static void Main(string[] args)
        {
            string N_M = Console.ReadLine();
            string[] c = N_M.Split(' ');
            int N = Convert.ToInt32(c[0]);
            int M = Convert.ToInt32(c[1]);
            int count = 0;
            int otpt = 0;

            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++)
            {
                string L_R = Console.ReadLine();
                string[] a = L_R.Split(' ');
                L[i] = Convert.ToInt32(a[0]);
                R[i] = Convert.ToInt32(a[1]);
            }
            if (R.Min() >= L.Max())
            {
                otpt = R.Min() - L.Max() + 1;
            }
            else
            {
                otpt = 0;
            }
            Console.WriteLine(Convert.ToString(otpt));
            Console.ReadKey();
        }
    }
}


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

int main(){

  int num,leg;
  cin >> num >> leg;

  for(int kame=0;kame<=num;kame++){
    if(leg==kame*4+(num-kame)*2){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}

Measured memory_bytes: 3572
const mod = 10 ** 9 +7;
function pow (x,y){
    var r = 1;
    for (var i = 0;i < y;  i++) {
        r = r * x % mod;
    }    
    return r;
}
function Main(input) {
    var num = parseInt(input);
    var r = pow(10, num) - (pow(9, num) * 2) + pow(8, num)
    r = r %  mod;
    r = (r + mod ) %  mod;
    console.log(r)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

	if (a > b) 
		cout << "a > b" << endl;
	else if (a == b)
		cout << "a == b" << endl;
	else
		cout << "a < b" << endl;

	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
typedef long long int ll;
const ll N = 1e6 +9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
const ll mod = 1e9+7;
#define w first
#define v second
#define pb push_back
#define mp make_pair

const int MAX_N = 105, MAX_K = 1e5 + 5, MOD = 1e9 + 7;
ll dp[10005],a[10005],b[10005];
ll n;

ll rec(ll v){
     if(v<=0){
          return 0;
     }
     if(dp[v]!=-1){
          return dp[v];
     }
     ll ans = inf;
     for(int i = 0;i<n;i++){
          ans = min(ans,rec(v-a[i])+b[i]);
     }
     return dp[v] = ans;
}

int main() {   

     ll q = 1;
     // cin>>q;
     while(q--){
          ll h;
          cin>>h>>n;
          memset(dp,-1,sizeof(dp));
          for(int i = 0;i<n;i++){
               ll e,r;cin>>e>>r;
               a[i] = e;b[i] = r;
          }
          ll as = rec(h);
          cout<<as<<'\n';
     }
}         

Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    res = [0] * n
    for i in range(m):
        a, b = map(int, input().split())
        res[a - 1] += 1
        res[b - 1] += 1

    for i in res:
        print(i)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> s(N);
  rep(i,N) cin >> s[i];
  int sum = 0;
  sort(ALL(s));
  rep(i,N)
  {
    sum += s[i];
  }
  if(sum%10==0)
  {
    rep(i,N)
    {
      if(s[i]%10==0&&i==N-1)
      {
        cout << 0 << endl;
        return 0;
      }
      else if(s[i]%10!=0)
      {
        cout << sum - s[i] << endl;
        return 0;
      } 
    }
  }
  else
  {
    cout << sum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        
        int ans = (T / A) * B; 

        System.out.println(ans);
    }
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long A, long long B, long long N){
    cout << (A * min(B - 1, N)) / B << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long N;
    scanf("%lld",&N);
    solve(A, B, N);
    return 0;
}


Measured memory_bytes: 3684
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	int D, G, p[15], c[15];
	cin >> D >> G;
	for (int i = 0; i < D; i++)cin >> p[i] >> c[i];
	int ans = 1e9;
	for (int i = 0; i < (1<<D); i++) {
		int s = 0, num=0, rest_max = -1;
		for (int j = 0; j < D; j++) {
			if (i&(1 << j)) {
				s += 100 * (j + 1)*p[j] + c[j];
				num += p[j];
			}
			else {
				rest_max = j;
			}
		}

		if (s < G) {
			int s1 = 100 * (rest_max + 1);
			int need = (G - s + s1 - 1) / s1;
			if (need >= p[rest_max])continue;
			num += need;
		}
		ans = min(ans, num);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int x,y,n,m;
int main(){
	scanf("%d %d %d %d",&n,&m,&x,&y);
	int tmp;
	for(int i=0;i<n;i++){
		scanf("%d",&tmp);
		x=max(x,tmp);
	}
	for(int i=0;i<m;i++){
		scanf("%d",&tmp);
		y=min(y,tmp);
	}
	printf(x<y?"No War\n":"War\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		if(N%((D*2)+1) == 0) {
			System.out.println((N/((D*2)+1)));
		}else {
			System.out.println((N/((D*2)+1)) + 1);
		}
	}
}

Measured memory_bytes: 20948