akhauriyash/Code-Regression huggingface dataset:
void main()
{
    long h, w;
    rdVals(h, w);
    string[] a = h.rdCol!string;

    long[][] dp = new long[][](h, w);
    dp[0][0] = 1;
    foreach (i, y; a)
    {
        foreach (j, x; y)
        {
            if (x == '#') continue;
            if (i) dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
            if (j) dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
        }
    }

    dp[h-1][w-1].writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 11132
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int N, K;
string s;
int a[200005], a2[200005];

int sgn(int n)
{
	if(n % 2) return -1;
	else return 1;
}

int main(void)
{
	cin >> N >> K;
	cin >> s;
	
	if(s.size() == 1){
		if(s[0] == 'B') K++;
		if(K%2) cout << "B" << endl;
		else cout << "A" << endl;
		return 0;
	}
	
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'A') a[i] = 1;
		else a[i] = -1;
		a2[i] = a[i];
	}
	
	int cnt = 0, pos = 0;
	while(K){
		if(a2[pos] * sgn(cnt) == 1) a2[pos] *= -1;
		else{
			pos++;
			cnt++;
		}
		K--;
		if(pos >= s.size() - 1) break;
	}
	
	string ans;
	if(K <= 0){
		string tmp;
		for(int i = 0; i < pos+1; i++){
			if(i%2) tmp += 'B';
			else tmp += 'A';
		}
		if(s[s.size()-1] == 'B'){
			if(tmp[pos] == 'A') tmp[pos] = 'B';
			else tmp[pos] = 'A';
		}
		reverse(tmp.begin(), tmp.end());
		for(int i = pos; i < s.size()-1; i++){
			if(a2[i] * sgn(cnt) == 1) ans += 'A';
			else ans += 'B';
		}
		ans += tmp;
		cout << ans << endl;
		return 0;
	}
	
	for(int i = 0; i < s.size(); i++){
		if(i%2) ans += 'B';
		else ans += 'A';
	}
	reverse(ans.begin(), ans.end());
	if(s.size() % 2){
		if(s[s.size()-1] == 'B' && K%2 == 0) ans[0] = 'B';
		if(s[s.size()-1] == 'A' && K%2) ans[0] = 'A';
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2696
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

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

    ll a;
    int cnt = 0;
    ll m = INF;
    ll ans = 0;
    REP(i, N) {
        cin >> a;
        if (a < 0) {
            ++cnt;
        }

        a = abs(a);
        m = min(a, m);
        ans += a;
    }

    if (cnt % 2 == 1) {
        ans -= 2 * m;
    }
    
    cout << fixed << setprecision(20);
    cout << ans << endl;

}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr <<"at line "<< __LINE__<<": [" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;

template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

void solve()
{
	int n;
	cin>>n;
	
	vector<int>vec(n);
	map<int,int>fre;
	
	for(int &x: vec)
	{
		cin>>x;
		fre[x]++;
	}
	
	ll sum=0;
	
	for(int x: vec) sum+=(ll)x;
	
	int q;
	cin>>q;
	
	while(q--)
	{
		int b,c;
		cin>>b>>c;
		
		sum-=(ll)b*fre[b];
		sum+=(ll)c*fre[b];
		
		fre[c]+=fre[b];
		fre[b]=0;
		
		cout<<sum<<"\n";
	}
}		

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


Measured memory_bytes: 8220
#include<iostream>
#include<algorithm>
using namespace std;
int N;
int A[1<<17],B[1<<17];
long ans;
main()
{
	cin>>N;
	for(int i=0;i<=N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	for(int i=0;i<N;i++)
	{
		int t=min(A[i],B[i]);
		ans+=t;
		B[i]-=t;
		t=min(A[i+1],B[i]);
		ans+=t;
		A[i+1]-=t;
	}
	cout<<ans<<endl;
}


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

int main() {
        int y;
        cin >> y;
        int x=y;
        int fx=0;
        for (int i=8; i>=0; i--) {
                fx += x/int(powl(10, i));
                x = x % int(powl(10, i));
        }
        if ((y%fx) == 0) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
        return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


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

const int N=1000005;
int cnt[N+1];


void pre()
{
    for(int i=1;i<=N;i++)
    {
        for(int j=i;j<=N;j+=i)
            cnt[j]++;
    }


}


void solve()
{
    pre();
    int n;
    cin>>n;
    int ans=0;
    for(int c=1;c<=n-1;c++)
    {
        ans=ans+cnt[n-c];
    }
    cout<<ans<<endl;
    
}

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



Measured memory_bytes: 11460
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
  int N, M; cin >> N;
  M = N;
  int x,y; cin>>x>>y;
  Graph G(N);
  for(int i=0; i<N-1; i++){
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  G[x-1].push_back(y-1);
  G[y-1].push_back(x-1);
  int ans[N]={0};
  for(int i=0;i<N;i++){
    vector<int> dist(N,-1);
    queue<int> que;
    dist[i]=0;
    que.push(i);
    while(!que.empty()){
      int v=que.front(); 
      que.pop();
      for(int nv : G[v]){
        if(dist[nv] != -1) continue; 
        dist[nv]=dist[v]+1;
        que.push(nv);
      }
    }
    for(int j=i+1;j<N;j++) ans[dist[j]]++;
  }
  for(int j=1;j<N;j++) cout<<ans[j]<<endl;
}

Measured memory_bytes: 384
use std::vec::Vec;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let n: usize = read();
    let mut ans: usize = 0;
    for i in 1..=n {
      if i % 3 != 0 && i % 5 != 0 {
        ans += i;
      }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2136
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define MAX_N (200005)
#define INF (1LL<<60)
#define EPS (1e-7)
#define DEBUG(x) cerr << #x <<":"<< x << endl;
#define DEBUGVC(x) cerr << #x <<": "; for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define DEBUGVCP(x) for(auto p:(x)) cerr << #x <<": "<< p.first <<", "<< p.second << endl;
#define DEBUG2(x, y) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y << endl;
#define DEBUG3(x, y, z) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y <<", "<< #z <<" : "<< z << endl;
const int MOD = (int)1e9+7;
#define P pair<int,int>

int N;
vector<int> c(N);
vector<int> G[MAX_N];
vector<int> F(MAX_N,false);
vector<int> V(MAX_N);

int ans=0;
int idx=0;

void bfs(int s){
    queue<int> que;
	que.push(s);
    int p = s;
    F[s]=true;

	while (!que.empty()) {
		int u = que.front(); que.pop();
        //DEBUG2(u, V[u]);

        vector<pair<int,int>> vc;
		for (int i = 0; i<G[u].size(); i++) {
            int v = G[u][i];
            if(F[v]) continue;
            F[v] = true;
			vc.push_back(make_pair(G[v].size(),v));
		}
        sort(vc.begin(),vc.end());
        for(int i=0; i<vc.size(); i++){
            V[vc[i].second] = c[idx++];
        }
        for(int i=0; i<vc.size(); i++){
            ans += min(V[u],V[vc[i].second]);
            que.push(vc[i].second);
        }

	}
}

signed main() {
    cin >> N;
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    c.resize(N);
    for(int i=0; i<N; i++) cin >> c[i];

    vector<pair<int,int>> L(N);
    for(int i=0; i<N; i++){
        int cnt=0;
        for(int j=0; j<G[i].size(); j++){
            int u = G[i][j];
            if(G[u].size()==1) cnt++;
        }
        L[i] = (make_pair(cnt,i));
    }
    sort(L.begin(),L.end());
    sort(c.rbegin(),c.rend());
    //DEBUGVCP(L);
    V[L[0].second] = c[0];
    idx++;
    bfs(L[0].second);

    cout << ans << endl;
    for(int i=0; i<N; i++) cout << V[i] <<" "; cout << endl;

}

Measured memory_bytes: 9088
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int n, p;
int stone[100];

int main() {
  while (scanf("%d %d", &n, &p), n|p) {
    MEMSET(stone, 0);
    int turn = 0;
    while (true) {
      if (p > 0) {
        stone[turn]++;
        p--;
        if (p == 0) {
          int have = 0;
          REP(i, n) {
            if (stone[i] > 0) { have++; }
          }
          if (have == 1) {
            printf("%d\n", turn);
            break;
          }
        }
      } else {
        p += stone[turn];
        stone[turn] = 0;
      }
      turn = (turn + 1) % n;
    }
  }
}

Measured memory_bytes: 872
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int count=0;
    int d=0,temp=N;
    while(temp>0){
        d++;
        temp/=10;
    }
    int mini=pow(10,d-1);
    if(d%2==1){
        count+=(N-mini+1);
    }
    for(int i=1;i<d;i+=2){
        count+=(9*pow(10,i-1));
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[input().split() for i in range (n)]
d=0

for k in range(n):
#行
    ab=0
    for j in range (m):
        #列
        ab+=int(a[k][j])*b[j]
    if ab+c>0:
        d+=1
print(d)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
signed main(){
  char a[105],b[105];
  int c,d;
  string e,f;
  cin>>a>>b;
  while(true){
    if(a[c]==NULL) break;
    c++;
  }
  while(true){
	if(b[d]==NULL) break;
    d++;
  }
  sort(a,a+c);
  sort(b,b+d,greater<int>());
 // cout<<a<<" "<<b<<"\n";
  e=a,f=b;
  if(e<f) cout<<"Yes";
  else cout<<"No";
  cout<<"\n";
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int DP[100001] = {};
int N, M;
vector <int> Graph[100001];

int Calc(int V){
  if (DP[V] != -1) return DP[V];
  int now = 0;
  for (int i = 0; i < Graph[V].size(); i++){
    int next = Graph[V][i];
    now = max(now, Calc(next) + 1);
  }
  return DP[V] = now;
}

int main(){
  cin >> N >> M;
  for (int i = 0; i < M; i++){
    int X, Y; cin >> X >> Y;
    X--; Y--;
    Graph[X].push_back(Y);
  }

  fill(DP, DP + N, -1);

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, Calc(i));
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    bool ans = true;
    rep(i, s.size()) if (s[i] != t[i]) ans = false;

    if (ans) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    ll a,b,c;
    cin>>a>>b>>c;
    ll step=0;
    ll res=0;
    while(a%2==0 and b%2==0 and c%2==0)
    {
        if(res==1e6)
        {
            cout<<"-1"<<endl;
            return 0;
        }
        ll aa=a/2;
        ll bb=b/2;
        ll cc=c/2;

        c=aa+bb;
        b=aa+cc;
        a=bb+cc;

        step++;
        res++;


    }
    cout<<step<<endl;

}



Measured memory_bytes: 3640
import Control.Applicative
import Data.List

main = do
    nums@[a,b,c] <- sort.map read.words <$> getLine :: IO [Int]
    if c == a && c == b then putStrLn "0" else putStrLn.show $ count 0 [a,b,c]

count n [a,b,x] = if a' == x && b' == x then (n+1) else count (n+1) nums where
    nums = sort [x,a',b']
    x' = foldl max 0 [x,a',b']
    (a',b') = if (x >= a+2) then (a+2,b) else  (a+1,b+1)

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

int main(){
	long long N, A, B;
	cin >> N >> A >> B;
	long long X[N], gap[N-1];
	for(int i=0; i<N; i++){
		cin >> X[i];
		if(i > 0) gap[i-1] = X[i] - X[i-1];
	}
	sort(gap, gap+N-1);
	long long ans = A*(X[N-1] - X[0]), min = ans;
	for(int i=1; i<N; i++){
		ans = ans - A*(gap[N-i-1]) + B;
		min = (min>ans?ans:min);
	}
	cout << min << endl;
	return 0;
}


Measured memory_bytes: 1792
n = int(input())
ns = list(map(int, input().split()))
rslt = [0] * n
r = n - 1 
while r >= 0:
    if sum(rslt[r:n:r+1]) % 2 != ns[r]:
        rslt[r] += 1
    r -= 1
print(sum(rslt))
if sum(rslt):
    print(*[i+1 for i, num in enumerate(rslt) if num == 1])



Measured memory_bytes: 13108
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include<string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
using namespace std;
const int MAX=1e5+10;
int fa[MAX];
bool vis[MAX];
vector<int> node[MAX];
queue<int> s;
int pre[MAX];
void bfs()
{
    while(!s.empty())
    {
    	for(auto i:node[s.front()])
    	{
    	     if(i!=s.front()&&vis[i]==0) 
			 {
			 	
				 //cout<<i<<" "<<s.front()<<endl;
				 s.push(i);
			 	vis[i]=1;
			 	pre[i]=s.front();
			 	//cout<<s.front()<<endl;
			 } 
		}
		s.pop();
	}
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n,m,x,y;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
    	scanf("%d %d",&x,&y);
    	node[x].push_back(y);
		node[y].push_back(x); 
	}
	s.push(1);
	vis[1]=1; 
	bfs();
	bool st=0;
    for(int i=1;i<=n;i++)
    {
    	if(vis[i]==0) st=1;
	}
	if(st==1) cout<<"No";
	else
	{
		cout<<"Yes"<<endl;
		for(int i=2;i<=n;i++)
		{
			printf("%d\n",pre[i]);
		}
	}
     
 } 

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

template <typename T, typename F> T binsearch(T a, T b, F f) {
	if (b - a == 0) return a;
	auto m = (a + b) / 2;
	return f(m) ? binsearch(a, m, f) : binsearch(m+1, b, f);
}

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto text = load<string>();
	auto n = (int)text.size();
	auto k = 1;
	auto last_multi = false;
	for (auto i=1; i<n; ++i) {
		if (last_multi) {
			++k;
			last_multi = false;
		} else {
			if (text[i-1] == text[i]) {
				if (i == n-1) {
					
				} else {
					++k;
					++i;
					last_multi = true;
				}
			} else {
				++k;
			}
		}
	}
	cout << k << '\n';
}


Measured memory_bytes: 720
n = int(input())
arr = list(map(int, input().split()))

arr.sort()

minus = [x for x in arr if x < 0]
plus = [x for x in arr if x >= 0]

if not minus:
    plus = arr[1:]
    minus = [arr[0]]
elif not plus:
    plus = [arr[-1]]
    minus = arr[:-1]

print(sum(plus) - sum(minus))

plus_max = plus[-1]
plus_rest = plus[:-1]
minus_min = minus[0]
minus_rest = minus[1:]

x = minus_min
while plus_rest:
    y = plus_rest.pop()
    print(x, y)
    x = x - y
minus_min = x

x = plus_max
while minus_rest:
    y = minus_rest.pop()
    print(x, y)
    x = x - y

print(x, minus_min)


Measured memory_bytes: 14144
using System;

namespace abc098a
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split();
            var a = int.Parse(inputs[0]);
            var b = int.Parse(inputs[1]);
            var max = a + b;
            var sub = a - b;
            if (sub > max) max = sub;
            var product = a * b;
            if (product > max) max = product;
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 11092
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;

public class Main {
    static boolean check(int a,int b,int mid){
        if(a <= mid && b <= mid || a > mid && b > mid)return true;
        return false;
    }
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int array[] = new int[2 * n + 1];
        StringTokenizer st = new StringTokenizer(br.readLine());
        for (int i = 1; i < 2 * n; i++)
            array[i] = Integer.parseInt(st.nextToken());
        array[0] = array[2 * n] = -1;
        int infinity = (int) 1E9 + 5;
        int low = 1;
        int high = 2 * n;
        TreeSet<Integer> zero;
        TreeSet<Integer> ones;
        while (low < high) {
            int mid = (low + high) / 2;
            int temp = -1;
            zero = new TreeSet<>();
            ones = new TreeSet<>();
            ones.add(infinity);
            ones.add(-infinity);
            zero.add(infinity);
            zero.add(-infinity);
            for (int i = 1; i < 2 * n; i++) {
                if (check(array[i],array[i - 1],mid) && i != 1) {
                    //System.out.println(array[i] + " " + mid + " " + i);
                    if (array[i] > mid) ones.add(i);
                    else zero.add(i);
                }
                if (check(array[i],array[i + 1],mid) && i != 2*n - 1) {
                    //System.out.println(array[i] + " " + mid + " " + i);
                    if (array[i] > mid) ones.add(i);
                    else zero.add(i);
                }
            }
                int beforezero = zero.floor(n);
                int afterzero = zero.ceiling(n);
                int beforeone = ones.floor(n);
                int afterone = ones.ceiling(n);
                int beforemax = Math.max(beforeone, beforezero);
                int aftermin = Math.min(afterone, afterzero);
                int min = Math.min(aftermin - n, n - beforemax);
                //System.out.println("1 " + aftermin + " " + beforemax + " " + min + " " + beforezero + " " + afterzero + " " + beforeone + " " + afterone);
                if (min == aftermin - n) {
                    if (afterone < afterzero) temp = 1;
                    else temp = 0;
                }
                if (min == n - beforemax) {
                    if (beforeone < beforezero) temp = 0;
                    else temp = 1;
            }
            if(min > n){
                if((n & 1) == 0)temp = (array[n] > mid) ? 0 : 1;
                else temp = (array[n] > mid) ? 1 : 0;
            }
            //System.out.println(mid + " " + low + " " + high + " " + zero + " " + ones + " " + temp);
            if (temp == 1) low = mid + 1;
            else high = mid;
        }
        System.out.println(low);
    }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N){
    cin >> a.at(i);
  }
  int cnt = 0;
  vector<bool> pushed(N, false);
  int light = 0;
  
  while(light != 1){
    if(pushed.at(light) == true){
      cnt = -1;
      break;
    }
    else{
      pushed.at(light) = true;
      light = a.at(light)-1;
      cnt++;
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 640
# coding: utf-8
# Your code here!

N,M,X,Y = [int(i) for i in input().split()]

x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
flag = False

if min(y) > max(x):

    for i in range(max(x)+1,min(y)+1):

        if Y >= i > X:
            flag = True

if flag:
    print('No War')
else:
    print('War')


Measured memory_bytes: 3060
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            final int N = fs.nextInt();
            final String S = fs.next();

            int now = 0;
            int mx = now;

            for (int i = 0; i < N; i++) {
                if (S.charAt(i) == 'I') now++;
                else now--;
                if (mx < now) mx = now;
            }

            System.out.println(mx);
        }
    }
}

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


Measured memory_bytes: 21076
#include<iostream>
using namespace std;
int n, m, i, j, st, dr, mid;
int a[305][305], viz[305], num[305], u[305];
int verif(int maxim){
    int i, nr, ok, j;
    nr = m;
    for(i = 1; i <= m; i++){
        viz[i] = 1;
        num[i] = 0;
    }
    for(i = 1; i <= n; i++){
        num[ a[i][1] ]++;
        u[i] = 1;
    }
    do{
        ok = 0;
        for(i = 1; i <= m; i++){
            if(num[i] > maxim){
                ok = 1;
                viz[i] = 0;
                nr--;
            }
            num[i] = 0;
        }
        for(i = 1; i <= n; i++){
            while(u[i] <= m && viz[ a[i][ u[i] ] ] == 0){
                u[i]++;
            }
            num[ a[i][ u[i] ] ]++;
        }
    }while(ok == 1 && nr != 0);

    if(nr > 0){
        return 1;
    }
    return 0;
}
int main(){
    cin>> n >> m;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cin>> a[i][j];
        }
    }
    st = 1;
    dr = n;
    while(st <= dr){
        mid = (st + dr) / 2;
        if( verif(mid) ){
            dr = mid - 1;
        }
        else{
            st = mid + 1;
        }
    }
    cout<< st;
}


Measured memory_bytes: 640
#include<iostream>
#include<cctype>
using namespace std;
int main() {
string str;
getline(cin, str);
bool f = 0, bad=0;
if(str.size()<6) bad=1;
for(int i=0;i<str.size();i++) if(isdigit(str[i])) f=1;
if(!f) bad=1;
f=0;
for(int i=0;i<str.size();i++) if('a'<=str[i]) f=1;
if(!f) bad=1;
f=0;
for(int i=0;i<str.size();i++) if('A'<=str[i]&&str[i]<='Z') f=1;
if(!f) bad=1;
cout << ( bad ? "INVALID" : "VALID" ) << endl;
return 0;
}

Measured memory_bytes: 1172
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<vector>
using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
	int a, b; cin >> a >> b;
	cout << a * b - a - b + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define maxn 100
#define mod 998244353
using namespace std;




int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll res = a * (n/(a+b));
    n %= (a+b);
    res += min(a, n);
    cout << res << endl;

    return 0;
}



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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;

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

  LL ans = 0;
  int N;
  cin >> N;
  vector<int> A(N + 2);
  FOR(i, 0, N) { cin >> A[i + 1]; }

  A[0] = 0;
  A[N + 1] = 0;

  LL sum = 0;
  FOR(i, 0, N + 1) { sum += abs(A[i] - A[i + 1]); }
  // cout << sum << '\n';

  int diff, sub;
  FOR(i, 1, N + 1) {
    diff = abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]);
    sub = abs(A[i - 1] - A[i + 1]);
    ans = sum - diff + sub;
    cout << ans << '\n';
  }

  return 0;
}

Measured memory_bytes: 1664
n,x = gets.chomp.split.map(&:to_i)
count = 0
min = 10000
n.times do |i|
  m = gets.to_i
  min = m if min > m
  x -= m
  count += 1
end

while x >= min
  x -= min
  count += 1
end

printf("%d\n",count)

Measured memory_bytes: 1788
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int weight[10] = {1, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7, 1<<8, 1<<9};

int main() {
	sort(weight, weight + 10);
#if 0
	rep(i,10) cout << weight[i] << endl;
#endif
	for(int W; cin >> W;) {
		vector<int> ans;
		while(W) {
			int add = *(upper_bound(weight, weight + 10, W) - 1);
			//cout << add << W << endl;
			ans.pb(add);
			W -= add;
		}
		sort(all(ans));
		cout << ans[0];
		for(int i = 1, n = ans.size(); i < n; i++) {
			cout << " " << ans[i];
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
    int a,b; cin >> a >> b;
    int count = 0;
    if (a != b) {
        count += max(a,b);
        count += max(a,b) - 1;
    } else {
        count += a * 2;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
class Lichaotree:
    #区間は1-indexed
    #min
    def __init__(self, X):
        self.N = len(X)
        self.N0 = 2**(self.N-1).bit_length()
        self.comp = {v : k for k, v in enumerate(X)}
        self.inf = 10**12
        self.X = X + [self.inf]*(self.N0 - self.N)
        self.data = [None]*(2*self.N0)
        self.size = [0]*self.N0 + [1]*self.N0
        for i in range(self.N0-1, 0, -1):
            self.size[i] = 2*self.size[2*i]
        self.start = [0]*(2*self.N0)
        for i in range(1, 2*self.N0):
            if i == i&(-i):
                continue
            self.start[i] = self.start[i-1] + self.size[i]
        
    def f(self, line, x):
        return line[0]*x + line[1]

    def _update(self, k, line):
        
        if self.data[k] is None:
            self.data[k] = line
            return
        
        l = self.start[k]
        r = l + self.size[k]        
        
        while True:
            if self.data[k] is None:
                self.data[k] = line
                return
            
            m = (l+r)//2
            lx = self.X[l]
            mx = self.X[m]
            rx = self.X[r-1]
            gl = (self.f(self.data[k], lx) > self.f(line, lx))
            gm = (self.f(self.data[k], mx) > self.f(line, mx))
            gr = (self.f(self.data[k], rx) > self.f(line, rx))
            if gl and gr:
                self.data[k] = line
                return
            
            if not gl and not gr:
                return
            
            if gm:
                self.data[k], line = line, self.data[k]
                gl = not gl
                
            if gl:
                r = m
                k = 2*k
            else:
                l = m
                k = 2*k+1
    
    def query(self, x):
        k = self.comp[x] + self.N0
        s = self.inf
        while k > 0:
            if self.data[k]:
                s = min(s, self.f(self.data[k], x))
            k = k >> 1
        return s
            
    def addline(self, line):
        self._update(1, line)
    
    def addlineseg(self, l, r, line):
        #区間[l, r)にlineを追加,l, rはXの元
        
        L = l+self.N0
        R = r+self.N0
        while L < R:
            if R & 1:
                R -= 1
                self._update(R, line)
            if L & 1:
                self._update(L, line)
                L += 1
            L >>= 1
            R >>= 1

N, C = map(int, input().split())
H = list(map(int, input().split()))

T = Lichaotree(H)
dp = [10**19]*N
dp[0] = 0
T.addline((-2*H[0], H[0]**2))
for i in range(1,N):
    mi = T.query(H[i])
    dp[i] = mi + C + H[i]**2
    T.addline((-2*H[i], H[i]**2+dp[i]))
print(dp[-1])


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

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A.at(i);
    ll even = 0;
    ll odd = 0;
    rep(i,N){
        if(A.at(i)%2 == 1) odd++;
        else even++;
    }
    if(odd%2 == 1) cout << "NO" <<endl;
    else cout << "YES" <<endl;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MOD = 1000000007;
const int B = 2010;

ll mod_pow(ll x, ll k)
{
	ll res = 1;
	for (; k; k /= 2, x = x * x % MOD) {
		if (k & 1) {
			res = res * x % MOD;
		}
	}
	return res;
}

ll fac[10010];
int N;
int a[200010], b[200010];
int dp[5010][5010];

int main() {
	fac[0] = 1;
	for (int i = 1; i < 10010; ++i) {
		fac[i] = fac[i-1] * i % MOD;
	}

	cin >> N;

	rep(i, N) {
		cin >> a[i] >> b[i];
		dp[B-a[i]][B-b[i]]++;
	}

	rep(i, 5010) rep(j, 5010) {
		if (i > 0 && j > 0) {
			dp[i][j] = ((ll)dp[i][j] + dp[i-1][j] + dp[i][j-1]) % MOD;
		}
	}

	int ret = 0;

	rep(i, N) {
		ret = (ret + dp[B+a[i]][B+b[i]]) % MOD;
	}

	rep(i, N) {
		ll t = fac[a[i]*2+b[i]*2] * mod_pow(fac[a[i]*2], MOD-2) % MOD * mod_pow(fac[b[i]*2], MOD-2) % MOD;
		ret = (ret - t + MOD) % MOD;
	}

	ret = (ll)ret * (MOD + 1) / 2 % MOD;
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 99968
#include "bits/stdc++.h"
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    bool flag = false;
    for(int i = 1; i < pow(100100, 0.5); i++){
        if(b >= 100){
            if((a * 1000 + b) == i * i) flag = true;
        }else if(b >= 10){
            if((a * 100 + b) == i * i) flag = true;
        }else{
            if((a * 10 + b) == i * i) flag =true;
        }
    }
    if(flag) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int K;
    cin>>K;
    
    int odd=K/2+K%2;
    int even=K/2;
    
        cout<<odd*even<<endl;
    
   
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int ans=0;
    for(int i=1;i<=40;i++){
        for(int j=2;j<=10;j++){
            if((pow(i,j)<=x)&&(ans<=pow(i,j))){
                ans=pow(i,j);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
const int N=130;
using namespace std;
char s[N];
int main()
{
   scanf("%s",&s);
   int len=strlen(s);
   
   if(len<4) 
   {
      printf("No\n");return 0;	
   }	
   else
   {
   	 if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
   	  printf("Yes\n");
   	 else printf("No\n");
   }
   return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    double a,b;
    double x;

    scanf("%lf %lf",&a,&b);

    x=(a+b)/2;

    if(x-(int)x>=0.5){
        x=(int)x+1;
    }
    else{
        x=x;
    }
    printf("%.0f\n",x);
    return 0;
}

Measured memory_bytes: 256
program main
	integer H, W, i, j, k, l, counter
	character(1), allocatable :: S(:, :), Sans(:, :)
	read(*, *) H, W
	allocate(S(0:H+1, 0:W+1))
	allocate(Sans(1:H, 1:W))
	S(0, 0:W+1) = '.'
	S(H+1, 0:W+1) = '.'
	S(1:H, 0) = '.'
	S(1:H, W+1) = '.'
	do i = 1, H
		do j = 1, W-1
			read(*, '(a1)', advance = 'No') S(i, j)
		end do
		j = W
		read(*, '(a1)') S(i, j)
	end do
	do i = 1, H
		do j = 1, W
			if(S(i, j) == '.') then
				counter = 0
				do k = -1, 1 
					do l = -1, 1
						if(S(i+k, j+l) == '#') then
							counter = counter + 1
						end if
					end do
				end do
				write(Sans(i, j), '(I1)') counter
			else 
				write(Sans(i, j), '(a1)') '#'
			end if
		end do
	end do
	do i = 1, H
		do j = 1, W-1
			write(*, '(a1)', advance = 'No') Sans(i, j)
		end do
		j = W
		write(*, '(a1)') Sans(i, j)
	end do		
end program main

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int S=0,T;
int N;
struct edge{
	int s,t,cap;long long v;int nxt;
}e[50005];
int e_cnt,last[405];
void addedge(int u,int v,int cap,long long l){
	e[e_cnt]=(edge){u,v,cap,l,last[u]};
	last[u]=e_cnt++;
	e[e_cnt]=(edge){v,u,0,-l,last[v]};
	last[v]=e_cnt++;
}
long long d[405];int fa[405];
bool vis[405];
#define LIM -(1000000000000001ll)
bool dij(){
	for(int i=0;i<=T;i++)d[i]=LIM;
	memset(vis,0,sizeof(vis));
	d[S]=0;
	for(int i=0;i<=T;i++){
		int x=-1;
		for(int j=0;j<=T;j++)if(!vis[j]&&(x==-1||d[j]>d[x]))x=j;
		if(x==-1||d[x]==LIM)break;
		vis[x]=1;
		for(int i=last[x];i!=-1;i=e[i].nxt)if(!vis[e[i].t]&&e[i].cap&&d[e[i].t]<d[x]+e[i].v){
			// assert(e[i].v<=0);
			d[e[i].t]=d[x]+e[i].v;
			fa[e[i].t]=i;
		}
	}
	return d[T]>LIM;
}
pair<int,long long> solve(){
	int flow=0;long long cost=0;long long r=0;
	while(dij()){
		flow++;
		int u=T;
		while(u!=S){
			e[fa[u]].cap=0;
			e[fa[u]^1].cap=1;
			u=e[fa[u]].s;
		}
		r+=d[T];
		cost+=r;
		for(int i=0;i<e_cnt;i++)e[i].v=d[e[i].s]+e[i].v-d[e[i].t];
	}
	return make_pair(flow,cost);
}
int x[85],y[85];long long v[85];
int t[325],a[325],b[325];
int L[85][2],R[85][2];
int main(){
	// freopen("e.in","r",stdin);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d%lld",&x[i],&y[i],&v[i]);
	}
	int m;
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		char c=getchar();
		while(c<'A'||c>'Z')c=getchar();
		if(c=='L')t[i]=0;
		if(c=='R')t[i]=1;
		if(c=='D')t[i]=2;
		if(c=='U')t[i]=3;
		scanf("%d%d",&a[i],&b[i]);
	}
	long long ans=0;
	for(int supy=1;supy<=n;supy++){
		memset(R,63,sizeof(R));
		for(int j=1;j<=m;j++)if(b[j]<supy){
			if(t[j]&1)R[supy-b[j]][t[j]>>1]=min(R[supy-b[j]][t[j]>>1],a[j]-1);
			else L[b[j]+1][t[j]>>1]=max(L[b[j]+1][t[j]>>1],a[j]+1);
		}
		for(int i=2;i<=supy;i++)for(int j=0;j<2;j++)L[i][j]=max(L[i][j],L[i-1][j]);
		for(int i=supy-1;i>0;i--)for(int j=0;j<2;j++)R[i][j]=min(R[i][j],R[i+1][j]);
		// for(int i=1;i<=supy;i++)printf("%d %d\n",L[i][0],R[i][0]);
		// for(int i=1;i<=supy;i++)printf("%d %d\n",L[i][1],R[i][1]);
		T=2*supy+2*n+1;
		e_cnt=0;
		memset(last,-1,sizeof(last));
		for(int i=1;i<=supy;i++)addedge(S,i,1,0),addedge(i+supy,T,1,0);
		for(int i=1;i<=n;i++)addedge(i+2*supy,i+n+2*supy,1,v[i]-1000000000000000ll);
		for(int i=1;i<=supy;i++)
			for(int j=1;j<=n;j++)if(x[j]>=L[i][0]&&x[j]<=R[i][0])addedge(i,j+2*supy,1,0);
		for(int i=1;i<=supy;i++)
			for(int j=1;j<=n;j++)if(y[j]>=L[i][1]&&y[j]<=R[i][1])addedge(j+n+2*supy,i+supy,1,0);
		pair<int,long long>res=solve();
		// printf("%d %d %lld\n",supy,res.first,res.second);
		res.second+=supy*1000000000000000ll;
		if(res.first==supy)ans=max(ans,res.second);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    ll cnt=0;
    rep(i,n){
        if(a[i]<b[i]) cnt+=(b[i]-a[i])/2;
        else cnt-=a[i]-b[i];
    }
    if(cnt<0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}
    




Measured memory_bytes: 384
#include<stdio.h>
#define N 8
int a[N],b[N],c[16],d[16];
char e[N][N];
int koukan1(int x,int y){
  return 7-x+y;
  }
int koukan2(int x,int y){
  return x+y;
}
int plbslv(int x){
  int y;
  if(x==N)return 1;
  if(a[x])return plbslv(x+1);
  for(y=0;y<N;++y){
    if(b[y])continue;
    if(c[koukan1(x,y)])continue;
    if(d[koukan2(x,y)])continue;
    a[x]=1; b[y]=1;
    c[koukan1(x,y)]=1;
    d[koukan2(x,y)]=1;
    e[x][y]='Q';
    if(plbslv(x+1))return 1;
    a[x]=0;b[y]=0;
    c[koukan1(x,y)]=0;
    d[koukan2(x,y)]=0;
    e[x][y]='.';
  }
  return 0;
}
int main(){
  int total,i,j,haga,seven;
  for(i=0;i<N;++i){
    for(j=0;j<N;++j){
      e[i][j]='.';
    }
  }
  scanf("%d",&total);
  for(i=0;i<total;++i){
    scanf("%d %d",&haga,&seven);
    a[haga]=1;b[seven]=1;
    c[koukan1(haga,seven)]=1;
    d[koukan2(haga,seven)]=1;
    e[haga][seven]='Q';
  }
  plbslv(0);
  for(i=0;i<N;++i){
    for(j=0;j<N;++j){
      printf("%c",e[i][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std; 
int arrCount[200005] = { 0 }; 
bool cmp(int iNum1, int iNum2)
{ 
    return iNum1 > iNum2;
}
int main()
{
    int n, m, i, t, iSum=0,maxn(1); 
    cin >> n >> m; 
    for (i = 1; i <= n; ++i)
    { 
        scanf("%d",&t);
        ++arrCount[t]; 
        maxn=(t>maxn?t:maxn);
    }
    sort(arrCount, arrCount + maxn+1,cmp); 
    for (i = m; arrCount[i]; ++i)
    { 
        iSum += arrCount[i]; 
    }
    cout << iSum << endl; 
    return 0; 
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;
int main(){
	int n,max=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.size()-1;i++){
		set<char> u,u2;
		string t1,t2;
		int count=0;
		for(int j=0;j<=i;j++){
			u.insert(s[j]);
		}
		for(int j=i+1;j<=s.size();j++){
			if(u.find(s[j])!=u.end()&&u2.find(s[j])==u2.end()){
				count++;
				u2.insert(s[j]);
			}
		}
		if(count>max){
			max=count;
		}
		DEB(count)END
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse.csgraph import dijkstra

N, X, Y = list(map(int, sys.stdin.buffer.readline().split()))
 
V = [X - 1]
U = [Y - 1]
for i in range(N - 1):
    V.append(i)
    U.append(i + 1)

graph = csr_matrix(([1] * N, (V, U)), shape=(N, N))
dist = dijkstra(graph, directed=False).astype(int)
ans = np.bincount(dist.ravel(), minlength=N) // 2
print(*ans[1:], sep='\n')

Measured memory_bytes: 76516
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;
typedef long long ll;

int main(){
   int n;
   cin >> n;
   int b[n-1];
   rep(i,n-1){
      cin >> b[i];
   }
   ll ans = 0;
   ans += b[0];
   ans += b[n-2];
   for(int i = 0; i<= n-3; i++){
      ans += min(b[i], b[i+1]);
   }
   if(n == 2) cout << b[0] * 2 << endl;
   else cout << ans << endl;
}

Measured memory_bytes: 256