akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n, k;
int b[4005][4005], w[4005][4005];
int bsum[4005][4005], wsum[4005][4005];
int Sum(int cnt[4005][4005], int x1, int y1, int x2, int y2) {
	int ans = cnt[x2][y2] - cnt[x1][y2] - cnt[x2][y1] + cnt[x1][y1];
	return ans;
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; ++ i) {
		int x, y; scanf("%d%d", &x, &y);
		x %= k * 2; y %= k * 2;
		char c[5]; scanf("%s", c);
		if (c[0] == 'B') b[x][y] ++;
		else w[x][y] ++;
	}
	for (int i = 0; i < k * 2; ++ i) {
		for (int j = 0; j < k * 2; ++ j) {
			b[i + k * 2][j] = b[i + k * 2][j + k * 2] = b[i][j + k * 2] = b[i][j];
			w[i + k * 2][j] = w[i + k * 2][j + k * 2] = w[i][j + k * 2] = w[i][j];
		}
	}
	for (int i = 1; i <= k * 4; ++ i) {
		for (int j = 1; j <= k * 4; ++ j) {
			bsum[i][j] = bsum[i - 1][j] + bsum[i][j - 1] - bsum[i - 1][j - 1] + b[i - 1][j - 1];
			wsum[i][j] = wsum[i - 1][j] + wsum[i][j - 1] - wsum[i - 1][j - 1] + w[i - 1][j - 1];
		}
	}
	int ans = 0;
	for (int x = 0; x < k * 2; ++ x) {
		for (int y = 0; y < k * 2; ++ y) {
			int B = Sum(bsum, x, y, x + k, y + k) + Sum(bsum, x + k, y + k, x + k + k, y + k + k);
			int W = Sum(wsum, x + k, y, x + k + k, y + k) + Sum(wsum, x, y + k, x + k, y + k + k);
			int sum = B + W;
			ans = max(ans, sum);
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main()
{
	int N,M;

	cin >> N >> M;

	vector<int> vec(N);
	int a, b;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		vec.at(a - 1) = vec.at(a - 1) + 1;
		vec.at(b - 1) = vec.at(b - 1) + 1;
	}
	for (int i = 0; i < N;i++) {
		cout << vec.at(i) << endl;
	}
}


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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL)
const int N=200002,M=11;
int a[N],b[N],c[N],h[N];
string s[N];
int r[3];
int main()
{
	ll n,A,B,C;
	cin>>n>>A>>B>>C;
	r[0]=A;r[1]=B;r[2]=C;
	if(A==0&&B==0&&C==0)
	{
		if(n) cout<<"No";
		else cout<<"Yes";
		return 0;
	}
	for(int i=1;i<=n;i++)
	cin>>s[i];
	// a[n+1]=n+1;
	// b[n+1]=n+1;
	// c[n+1]=n+1;
	// for(int i=n;i>=1;i--)
	// {
	// 	a[i]=a[i+1];
	// 	b[i]=b[i+1];
	// 	c[i]=c[i+1];
	// 	if(s[i][0]=='A'||s[i][1]=='A')
	// 		a[i]=i;
	// 	if(s[i][0]=='B'||s[i][1]=='B')
	// 		b[i]=i;
	// 	if(s[i][0]=='C'||s[i][1]=='C')
	// 		c[i]=i;
	// }
	vector<char> v;
	for(int i=1;i<=n;i++)
	{
		int x=s[i][0]-'A';
		int y=s[i][1]-'A';
		if(r[x]+r[y]==0)
		{
			return cout<<"No",0;
		}
		if(r[x]<r[y])
		{
			v.pb(x+'A');r[x]++;r[y]--;
		}
		else if(r[y]<r[x])
		{
			v.pb(y+'A');r[y]++;r[x]--;
		}
		else
		{
			if(i==n)
			{
				v.pb(x+'A');
				break;
			}
			if(s[i+1][0]==s[i][0]||s[i+1][1]==s[i][0])
			{
				v.pb(x+'A');
				r[x]++;
				r[y]--;
			}
			else
			{
				v.pb(y+'A');r[y]++;r[x]--;
			}
		}
	}
	cout<<"Yes\n";
	for(char c:v) cout<<c<<"\n";

	
	return 0;
}

Measured memory_bytes: 9960
//! Framework <https://github.com/vain0x/procon>

#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

fn main() {
    let mut scan = Scan::new();

    let A = scan.word::<i64>();
    let B = scan.word::<i64>();

    println!("{}", A * B);
}


Measured memory_bytes: 2116
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in.map(_.split(' ').map(_.toInt))
  val V = ls(1)
  val C = ls(2)
  val ret = V.indices.map( i => V(i)-C(i) ).filter(_ > 0).sum
  println(ret)
}


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

using namespace std;

const int maxn = 100 + 5;

int n;
int h[maxn];
int hst, ans;

void inline Init()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", h + i);
}

void inline Solve()
{
	for(int i = 1; i <= n; ++i) {
		if(h[i] >= hst) {
			++ans;
			hst = h[i];
		}
	}
	printf("%d\n", ans);
}

int main()
{
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (B % A == 0) {
          System.out.println(A + B);
        } else {
          System.out.println(B - A);
        }
    }
}

Measured memory_bytes: 35856
#include <cstdio>
#include <algorithm>
int I()
{
	int r = 0, c;
	do c = getchar(); while (c < 48 || c > 57);
	do r = (r << 3) + r + r + (c - 48), c = getchar(); while (c > 47 && c < 58);
	return r;
}
inline long long abs(long long x)
{
	return x < 0 ? -x : x;
}
int N;
long long H[500001], a[500001], T[500002];
int main()
{
	N = I(), H[0] = I();
	for (int i = 1; i <= N; i++)
	{
		a[i] = I();
		H[i] = std::min(H[i - 1], abs(H[i - 1] - a[i]));
	}
	T[N + 1] = 1;
	for (int i = N; i; i--)
		T[i] = T[i + 1] << 1 <= a[i] ? T[i + 1] : T[i + 1] + a[i];
	for (int Q = I(); Q--; )
	{
		int x = I();
		puts(H[x - 1] >= T[x + 1] ? "YES" : "NO");
	}
	return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <ctime>


#ifndef M_PI
#define M_PI 3.141592653589
#endif
#define int long long
#define double long double
#define f(variable, start, end) for (int variable = start; variable < end; ++variable)
#define be(a) a.begin(), a.end()
#define no cout << "NO\n"
#define yes cout << "YES\n"
#define nor cout << "NO\n"; return
#define yesr cout << "YES\n"; return
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>


using namespace std;


template<typename T, typename E>
vector<T> &operator>>(vector<T> &v, E a) {
    v.push_back(a);
    return v;
}

//pair output
template<typename E>
ostream &operator<<(ostream &os, pair<E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//"map" pair output
template<typename E>
ostream &operator<<(ostream &os, pair<const E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//vector output
template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (T i : vec) {
        os << i << ' ';
    }
    return os;
}

//2 dimensional vector output
template<typename T>
ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
    for (vector<T> i : vec) {
        os << i << '\n';
    }
    return os;
}

//vector<pair<T, E>> output
template<typename T, typename E>
ostream &operator<<(ostream &os, vector<pair<T, E>> &vec) {
    for (pair<T, E> i : vec) {
        os << i.first << ' ' << i.second << '\n';
    }
    return os;
}


int32_t main() {
    cin.tie(NULL);
    cout.tie(NULL);
    cout.setf(ios::fixed);
    cout.precision(10);
    ios_base::sync_with_stdio(false);
#ifdef TIME
    int32_t start = clock();
#endif

    int n;
    cin >> n;
    vi a(n);
    int sum = 0;
    map<int, int> m;
    f(i, 0, n) {
        cin >> a[i];
        m[a[i]]++;
        sum += a[i];
    }

    int q, b, c;
    cin >> q;
    f (i, 0, q) {
        cin >> b >> c;
        sum += (c - b) * m[b];
        cout << sum << '\n';
        m[c] += m[b];
        m[b] = 0;
    }


#ifdef TIME
    cout << "\ntime: " << (clock() - start) / (CLOCKS_PER_SEC * 1.0);
#endif

    return 0;
}

Measured memory_bytes: 9928
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a>> b;
    if (a==b)
        cout << "Draw" ;
    if (a>b || a==1){
          if(b!=1)
            cout<<"Alice" ;
    }
    if(b>a || b==1) {
            if (a!=1)
                cout << "Bob" ;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REP_S(i, n, s) for(int i = s; i < (int)(n); i++)
int main()
{
   	ios::sync_with_stdio(false);
	cin.tie(0);

	int num;
	cin >> num;

    int a[100010];
    vector<int> colorList;
    REP(i, num)   
    {
        cin >> a[i];
        a[i] = -a[i];
        if(i == 0)
        {
            colorList.push_back(a[0]);
            continue;
        }

        if(colorList[colorList.size() - 1] <= a[i])
        {
            colorList.push_back(a[i]);
            continue;
        }        
        *upper_bound(colorList.begin(), colorList.end(), a[i]) = a[i];
    }
    cout << colorList.size() << endl;
	return 0;
}

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

using namespace std;

#define ll long long
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cmax(a,b)		a = max (a, b)
#define cmin(a,b)		a = min (a, b)

const int MAXN = 5005;
const int oo = 0x3f3f3f3f;

int N, K, a[MAXN], num[MAXN], top = 0, ans = 0;
bitset<MAXN> F;

bool vaild(int o){
	bool ok = 1;
	F.reset();
	F[0] = 1;
	up (i, 1, N) {
		if (a[i] == num[o] && ok) {
			ok = 0;
			continue;
		}
		F |= F << a[i];
	}
	up (i, K - num[o], K - 1) if (F[i]) return 1;
	return 0;
}

int main(){
	scanf("%d%d", &N, &K);
	up (i, 1, N) scanf("%d", &a[i]);
	up (i, 1, N) if (a[i] < K) num[++top] = a[i];
	if (!top) {
		puts("0");
		return 0;
	}
	N = top;
	up (i, 1, N) a[i] = num[i];
	sort(num + 1, num + top + 1);
	top = unique(num + 1, num + top + 1) - (num + 1);
	num[top + 1] = oo;
	int le = 1, ri = top, mi;
	while (le + 1 < ri) {
		mi = (le + ri) >> 1;
		if (vaild(mi)) 	ri = mi;
		else 			le = mi;
	}
	int o = top + 1;
	if (vaild(le)) o = le;
	else if (vaild(ri)) o = ri;
	up (i, 1, N) if (a[i] < num[o]) ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
    int N,M;
    cin >> N >> M;
    cout << ((N == M) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int getDigitSum(int n){
   int res = 0;
   while(n){
       res += n % 10;
       n /= 10;
   }
   return res;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = INF;
    rep(i, 1, n){
        int a = i;
        int b = n - i;
        int tmp = getDigitSum(a) + getDigitSum(b);
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back
#define MAX 1e16
#define SIZE 1e8
#define mod 1000000007
#include<regex>


using namespace std;




int main()
{
	string str;
	cin>>str;
	regex r(".*AC.*");
	if(regex_match(str,r)){
	    cout<<"Yes"<<endl;
	}else{
	    cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> idx(n);
  rep(i, n) {
    int p;
    cin >> p;
    idx[--p] = i;
  }
  int ans = 0, cnt = 1;
  rep(i, n-1) {
    if (idx[i] < idx[i+1])
      cnt++;
    else {
      chmax(ans, cnt);
      cnt = 1;
    }
  }
  chmax(ans, cnt);
  ans = n-ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int A, B; cin >> A >> B;
	B--;
	if (B % (A - 1) == 0) cout << B / (A - 1) << endl;
	else cout << B / (A - 1) + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


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

    ll w[n],v[n];
    rep(i,0,n)cin >> w[i] >> v[i];

    ll dp[n+1][W+1] = {};

    rep(i,1,n+1){
	rep(j,1,W+1){
	    if(j-w[i-1] >= 0){
		dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]]+ v[i-1]);
	    }else{
		dp[i][j] = dp[i-1][j];
	    }
	}
    }

    P(dp[n][W]);
    return  0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<bool> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// g++ -o a a.cpp -Wall -lm -std=c++17
int main(){
    ll n,h;cin>>n>>h;
    VI a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    ll amax=0;
    ll ans=0;
    rep(i,n)chmax(amax,a[i]);
    sort(ALL(b),greater<ll>());
    ll i=0;
    while(h>0 && b[i]>=amax){
        h-=b[i];
        ans++;
        i++;
    }
    if(h>0)ans+=(h+amax-1)/amax;
    cout<<ans<<endl;

}

Measured memory_bytes: 4848
//code by 27.
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<cassert>
#include<climits>
#include<cmath>
#include<memory.h>
using namespace std;
vector<int>a[1000001];
int f[1000001];
queue<int>que;
int main()
{
	int g=0,g1=0,g2=0;
	int n,m;
	cin>>n;
	int x,y;
	for(int i=1;i<=n-1;i++)
	{
		cin>>x>>y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	que.push(1);
	que.push(n);
	f[1]=1;
	f[n]=-1;
	while(g<n)
	{
		for(int i=0;i<a[que.front()].size();i++)
		{
			//cout<<"*"<<a[que.front()][i]<<" "<<f[a[que.front()][i]]<<endl;
			if(f[a[que.front()][i]]==0&&f[que.front()]==-1)
			{
				f[a[que.front()][i]]=-1;
				que.push(a[que.front()][i]);
			}
			else if(f[a[que.front()][i]]==0&&f[que.front()]==1)
			{
				f[a[que.front()][i]]=1;
				que.push(a[que.front()][i]);
			}
		}
		if(f[que.front()]==1)g1++;
		else if(f[que.front()]==-1)g2++;
		que.pop();
		g++;
	}
	if(g2>=g1)cout<<"Snuke";
	else cout<<"Fennec";
	return 0;
}
//

Measured memory_bytes: 29184
#include <bits/stdc++.h>
#define rep(i,j,n) for(int i = j; i < n; i++)
using namespace std;
int main(){
  int n, res = 0;
  cin >> n;
  rep (i, 1, n+1) {
    if (i % 2 == 0) continue;
    int cnt = 0;
    rep (j, 1, i+1) if (i % j == 0) cnt++;
    if(cnt == 8) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
from itertools import combinations

H, W, K = [int(x) for x in input().split()]

field = []

for i in range(H):
    width = []
    for j, x in enumerate(input()):
        if x == '.':
            width.append(0)
        else:
            width.append(1)
    field.append(width)

result = 0

for h in range(2**H):
    for w in range(2**W):
        count = 0
        for y in range(H):
            for x in range(W):
                if ((h >> y) & 1):
                    if ((w >> x) & 1):
                        count += field[y][x]
        if count == K:
            result += 1
        #print("{} -> count : {}".format((h, w), count))

print(result)


Measured memory_bytes: 9120
#include<stdio.h>
int gcd(int x,int y){
  int r,tmp;
  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }
  r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  return y;
}
int main(void){
  int x,y,r;
  scanf("%d",&x);
  scanf("%d",&y);
  r=gcd(x,y);
  printf("%d\n",r);
  return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
int solve(int i, int n, vector<int>& A){
    if(n==0)return 1;
    else if(i==A.size() || n<0) return 0;
    return max(solve(i+1, n-A[i], A), solve(i+1, n, A) );
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,m_i;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) cin >> A[i];
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> m_i;
        if(solve(0,m_i,A)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3156
import sys
import queue


def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())

    edges = {i : [] for i in range(1, N+1)}
    for i in range(N-1):
        a, b = map(int, input().split())
        edges[a].append(b)
        edges[b].append(a)
    
    values = {i : 0 for i in range(1, N+1)}
    for i in range(Q):
        p, x = map(int, input().split())
        values[p] += x
    
    has_noparent = {i : True for i in range(1, N+1)}
    has_noparent[1] = False
    
    q = queue.Queue()
    q.put(1)
    
    children = {i : [] for i in range(1, N+1)}
    while not q.empty():
        parent = q.get()
        value_parent = values[parent]
        for child in edges[parent]:
            if has_noparent[child]:
                values[child] += value_parent
                q.put(child)
                has_noparent[child] = False

    ret = [str(i) for i in values.values()]
    ret = ' '.join(ret)
    print(ret)
    
if __name__=="__main__":
    main()

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

const int mod = 1e9+7;

const int N = 200200;
vector<int> adj[N];
int visited[N];


int dfs(int u){
    visited[u] = 1;
    int here = 1;
    for (auto e:adj[u]){
        if (visited[e]) continue;
        here += dfs(e);
    }
    return here;
}


signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n, m;
    cin>>n>>m;
    while(m--){
        int a, b;
        cin>>a>>b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int ans = 0;

    for (int i=0; i<n; i++){
        if (visited[i]) continue;
        ans = max(ans, dfs(i));
    }

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


Measured memory_bytes: 25536
n=int(input())
A=list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
C=[0]+list(map(int,input().split()))
s=B[A[0]]
for i in range(1,n):
  s+=B[A[i]]
  if A[i]==A[i-1]+1:
    s+=C[A[i]-1]
print(s)

Measured memory_bytes: 3064
N,T = map(int, input().split())
C = []
Time = []
A = []
for i in range(N):
  c,t = map(int, input().split())
  C.append(c)
  Time.append(t)
for j in range(N):
  if Time[j]<=T:
    A.append(C[j])
if len(A)>=1:
  print(min(A))
else:
  print("TLE")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	unsigned long long a, b, x;
	cin >> a >> b >> x;
	unsigned long long counta, countb, ans;
	counta = (a - 1) / x;
	if (a == 0) {
		counta = -1;
	}
	countb = b/ x;
	ans = countb - counta;
	cout << ans;
	return 0;
}

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



int main(){
    int a,b,ans;
    cin >> a >> b;
    //vector<vector<int>> x(n, vector<int>(d));
    cout << max({a*b,a+b,a-b}) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////	
	string s;
	cin >> s;
	bool bb=1;
	int a[26]={};
	SREP(i,s) a[s[i]-'a']++;
	REP(i,26) if(a[i]%2==1) bb=0;
	cout << (bb ? "Yes" : "No") << endl;
//////////////////////////////////////////////
}


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

int main()
{
    ll n, m = 0;
    cin >> n;
    vector<ll> a(n + 1), b(n + 1, 0);
    rep1(i, n) cin >> a[i];

    for (ll i = n; i > 0; i--)
    {
        ll sum = 0;
        for (ll j = i; j <= n; j += i)
        {
            sum += b[j];
        }
        if (sum % 2 != a[i])
            b[i] = 1;
    }
    cout << accumulate(b.begin(), b.end(), 0) << endl;
    rep1(i, n)
    {
        if (b[i])
            cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 6432
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, m, s = 0, t = 0;
    cin >> n >> m;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e, t += e;
    for (ll e : a)
        s += (e >= double(t) / (4 * m));
    cout << (s < m ? "No" : "Yes") << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 200000;
vector<vector<int>> g(maxn);
ll score[maxn];
int N,Q;

void dfs(int s,ll ns){
    ns = score[s];
    if(g[s].size()>0){
        rep(i,g[s].size()){
            score[g[s][i]]+=ns;
            dfs(g[s][i],ns);
        }
    }else{
        return;
    }
    return;
}

int main(){
    
    cin >> N>>Q;
    fill(score,score+N,0);
    rep(i,N-1){
        int a,b;
        cin >> a>>b;
        a--;b--;
        g[a].push_back(b);
    }
    rep(i,Q){
        int v;
        ll s;
        cin >> v>>s;
        v--;
        score[v]+=s;
    }
    
    dfs(0,0);
    
    rep(i,N){
        cout << score[i]<<' ';
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 21120
N=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)
a.append(0)
ans=0
num_count=0
prev=0
for ai in a:
    # print(prev,ai,num_count,ans)
    if ai!=prev:
        if num_count>=prev:
            ans+=num_count-prev
        else:
            ans+=num_count
        num_count=1
    else:
        num_count+=1
    prev=ai

print(ans)


Measured memory_bytes: 14268
import math
n,m = map(int,input().split())
a = []
c = []
for i in range(n):
    a.append(input().split())
for i in range(m):
    c.append(input().split())
for i in range(n):
    d = float('inf')
    for j in range(m):
        b = abs(int(a[i][0]) - int(c[j][0])) + abs(int(a[i][1]) - int(c[j][1]))
        if d > b:
            d = b
            ans = j+1
    print(ans)


Measured memory_bytes: 3064
using System;

namespace AtcoderABC042A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            string s = "YES";

            if(a == 5 && b == 7 && c == 5)
            {
                Console.WriteLine(s);
            }else if(a == 5 && b == 5 && c == 7)
            {
                Console.WriteLine(s);
            }else if(a == 7 && b == 5 && c == 5)
            {
                Console.WriteLine(s);
            }
            else
            {
                Console.WriteLine("NO");
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
pair<int,int> ab[110];
bool abc[110];
pair<int,int> cd[110];
bool cdc[110];
int ans;
	
int main(){
	cin>>n;
	REP(i,n){
		int t,s;
		cin>>t>>s;
		ab[i]=pair<int,int>(t,s);
	}
	REP(i,n){
		int t,s;
		cin>>t>>s;
		cd[i]=pair<int,int>(t,s);
	}
	sort(cd,cd+n);
	REP(i,n){
		int t=-1;
		REP(j,n){
			if(!abc[j]){
				if(t==-1){
					if(cd[i].first>ab[j].first&&ab[j].second<cd[i].second){
						t=j;
					}
				}else{
					if(cd[i].first>ab[j].first&&ab[j].second>ab[t].second&&ab[j].second<cd[i].second){
						t=j;
					}
				}
			}
			
		}
		if(t!=-1){
			ans++;
			abc[t]=true;
			//cout<<i<<" "<<t<<endl;	
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> fruit;
    rep(i,n){
        int v;
        cin>>v;
        fruit.push_back(v);
    }
    sort(fruit.begin(),fruit.end());
    int sum=0;
    rep(i,k){
        sum+=fruit[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    output(h2 * 60 + m2 - h1 * 60 - m1 - k);
    
    
    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main(){
    char s[200005];
    scanf("%s",s);
    int x = 0;
    int i = 0;
    while(s[i]){
        x += s[i] - '0';
        x %= 9;
        i++;
    }
    if(x == 0) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 1812
#include <iostream>

using namespace std;

int main(void){
  int n, i, c = 0, sum = 0;
  char a;
  cin >> n;
  for(i = 0; i < n; i++){
    cin >> a;
    if(a == 'A'){
      c = 1;
    }else if(a == 'B' && c == 1){
      c = 2;
    }else if(a == 'C' && c == 2){
      sum++;
      c = 0;
    }else{
      c = 0;
    }
  }
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
num = input()
L = []
house = []
for i in range(int(num)):
    k = input().split()
    k[0] = int(k[0])
    k[1] = int(k[1])
    k[2] = int(k[2])
    k[3] = int(k[3])
    L.append(k)

for i in range(3):
    a = ["","0","0","0","0","0","0","0","0","0","0"]
    b = ["","0","0","0","0","0","0","0","0","0","0"]
    c = ["","0","0","0","0","0","0","0","0","0","0"]
    d = ["#"*20]
    house.append([a,b,c,d])

a = ["","0","0","0","0","0","0","0","0","0","0"]
b = ["","0","0","0","0","0","0","0","0","0","0"]
c = ["","0","0","0","0","0","0","0","0","0","0"]
house.append([a,b,c])

for i in L:
    house[i[0]-1][i[1]-1][i[2]] = str(int(house[i[0]-1][i[1]-1][i[2]])+i[3])

for i in house:
    for j in i:
        k = " ".join(j)
        print(k)



Measured memory_bytes: 5620
stri = [input() for _ in range(3)]
str_now = [0 for _ in range(3)]
now = 0
while True:
  if str_now[now] == len(stri[now]):
    print(chr(ord('A')+now))
    exit()
  else:
    str_now[now] += 1
    now = ord(stri[now][str_now[now]-1]) - ord('a')


Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
q=int(input())
mx=max(a)
num=[]
for i in range(100002):
  num.append(0)
bc=[]
for i in range(q):
  b,c=map(int,input().split())
  bc.append([b,c])
sm=0
for i in a:
  num[i]+=1
  sm+=i
for i in bc:
  b=i[0]
  c=i[1]
  sm-=b*num[b]
  sm+=c*num[b]
  num[c]=num[b]+num[c]
  num[b]=0
  print(sm)

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

int main() {
	int N,Ai,min,count,amari;
  	min = 1000;
  	cin >> N;
	for (int i = 0; i < N; i++){
  	cin >> Ai;
    amari = 0; 
    count = 0;
    	while (amari == 0){
          	amari = Ai % 2;
          	if (amari != 0){
            break;
            }
          	Ai /= 2;
            count++;
		}
    if (min >= count){
    min = count;
    }
    }
  	cout << min << endl;
}

Measured memory_bytes: 384
import sys


def main():
    N = int(input())
    statement = [[] for i in range(N)]
    for i in range(N):
        message = int(input())
        for j in range(message):
            num, tmp = map(int, input().split())
            if tmp == 1:
                TF = True
            else:
                TF = False
            statement[i].append((num, TF))
    ans = 0
    for i in range(1 << N):
        status = [False] * 15
        tmp_ans = 0
        for j, c in enumerate(format(i, '015b')[::-1]):
            if c == '1':
                status[j] = True
                tmp_ans += 1
        if tmp_ans <= ans:
            continue
        flag = True
        for j, person in enumerate(statement):
            if not status[j]:
                continue
            for state in person:
                if status[state[0]-1] != state[1]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            ans = max(ans, tmp_ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 48988
//ABC123-D

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>
#include <string>
#include <map>
using namespace std;
map<tuple<long long int, long long int, long long int> , bool> Accepted;

int main(){
  
  vector<long long int> Cakes[3];
  long long int X,Y,Z,K;
  cin >> X >> Y >> Z >>K;
  Cakes[0].resize(X);
  Cakes[1].resize(Y);
  Cakes[2].resize(Z);
   
  for(int i=0; i<3; i++){
    for(int j=0; j<Cakes[i].size(); j++){
      cin>>Cakes[i][j];
    }
    sort(Cakes[i].begin(), Cakes[i].end(), greater<long long int>());
  }
  //All the cake's data is sorted in Cake[i][j]//
 
  priority_queue<pair<long long int, tuple<long long int, long long int, long long int> > > Q;
  
  long long int a=0,b=0,c=0;
  long long int sum_a,sum_b,sum_c;
  Q.push(make_pair(Cakes[0][0]+Cakes[1][0]+Cakes[2][0], make_tuple(0,0,0)));

  for(long long int loop=0; loop<K; loop++){
    pair<long long int, tuple<long long int, long long int, long long int>>topPair = Q.top();
    tuple <long long int, long long int, long long int> topCombination = topPair.second;
    
    a = get<0>(topCombination);
    b = get<1>(topCombination);
    c = get<2>(topCombination);
    //cout << "debug "<<a << " "<<b <<" "<<c<<endl;
    Q.pop();
    if(Accepted[topPair.second] == false){
      cout<<topPair.first<<endl;
      Accepted[topPair.second] = true;
      if(a+1<X) sum_a = Cakes[0][a+1]+Cakes[1][b]+Cakes[2][c];
      else sum_a = -999;
      if(b+1<Y) sum_b = Cakes[0][a]+Cakes[1][b+1]+Cakes[2][c];
      else sum_b = -999;
      if(c+1<Z) sum_c = Cakes[0][a]+Cakes[1][b]+Cakes[2][c+1];
      else sum_c = -999;
      if(sum_a > 0) Q.push(make_pair(sum_a,make_tuple(a+1,b,c)));
      if(sum_b > 0) Q.push(make_pair(sum_b,make_tuple(a,b+1,c)));
      if(sum_c > 0) Q.push(make_pair(sum_c,make_tuple(a,b,c+1)));
    }else{
      loop--;
    }
  }
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

bool seen[55];

void dfs(vector<int> g[55], int v){
    seen[v] = true;
    for(auto to : g[v]){
        if (seen[to]) continue;
        dfs(g, to);
    }
}

int main(){
    int n, m, ans = 0;
    cin >> n >> m;
    int a[m], b[m];
    rep(i, m) cin >> a[i] >> b[i];
    rep(i, m){
        vector<int> g[55];
        rep(j, m){
            if (j != i) {
                g[a[j]-1].push_back(b[j]-1);
                g[b[j]-1].push_back(a[j]-1);
            }
        }
        memset(seen, 0, sizeof(seen));
        dfs(g, 0);
        bool flag = true;
        rep(i, n) if (!seen[i]) flag = false;
        if (!flag) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=200001 ;
int main()
{
   fast ;
   ll a,b,n ; cin>>a>>b>>n ;
   ll x=min(n,b-1) ;
   ll ans=(a*x)/b ;

   ans-=a*(x/b) ;
   cout<<ans<<endl ;

}



Measured memory_bytes: 3604
#include <iostream>
using namespace std;
#define MAX 100
#define INFTY 1<<22
#define WHITE 0
#define GRAY 1
#define BLACK 2

int gMatrix[MAX][MAX];

void dijkstra(int n){
    // 最小の重みを記録する
    int minV;
    int weight[MAX];
    int color[MAX];
    
    for(int i = 0;i < n;++i){
        weight[i] = INFTY;
        color[i] = WHITE;
    }
    // 始点
    weight[0] = 0;
    color[0] = GRAY;
    
    while(1){
        minV = INFTY;
        // 頂点
        int u = -1;
        for(int i = 0;i < n;++i){
            if(minV > weight[i] && color[i] != BLACK){
                u = i;
                minV = weight[i];
            }
        }
        if(u == -1)break;
        color[u] = BLACK;
        
        for(int v = 0;v < n;++v){
            if(color[v] != BLACK && gMatrix[u][v] != INFTY){
                if(weight[v] > weight[u] + gMatrix[u][v]){
                    weight[v] = weight[u] + gMatrix[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    // 出力
    for(int i = 0;i < n;++i){
        cout << i << " " << ( weight[i] == INFTY ? -1 : weight[i] ) << endl;
    }
}

int main(){
    int n;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            gMatrix[i][j] = INFTY;
        }
    }
    
    int k,c,u,v;
    for(int i = 0;i < n;++i){
        cin >> u >> k;
        for(int j = 0;j < k;++j){
            cin >> v >> c;
            gMatrix[u][v] = c;
        }
    }
    dijkstra(n);
    return 0;
}


Measured memory_bytes: 3116
while True:
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss = [s]
    for i in range(k,n):
        s = s +a[i] -a[i-k]
        ss.append(s)
    print(max(ss))


Measured memory_bytes: 11700
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a; string s; cin >> n >> a >> s;
	for (int h = 0; h < n; h++) {
		if (h == a - 1 && s[h] == 'A') { cout << 'a'; }
		else if (h == a - 1 && s[h] == 'B') { cout << 'b'; }
		else if (h == a - 1 && s[h] == 'C') { cout << 'c'; }
		else {
			cout << s[h];
		}
	}
	cout << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

const int MaxN = 100000, MaxS = 511;
const int Mod = 998244353, base = ((long long) 1e18) % Mod;

int N;
int Pw[MaxN + 5];
int Sg[3][MaxN + 5];
std::vector<int> Gr[3][MaxN + 5];
int Buc[3][MaxS + 5];

inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % Mod; }
inline void inc(int &x, int y = 1) { x = add(x, y); }

void init() {
  scanf("%d", &N);
  Pw[0] = 1;
  for (int i = 1; i <= N; ++i) Pw[i] = mul(Pw[i - 1], base);
  for (int k = 0; k < 3; ++k) {
    int m;
    scanf("%d", &m);
    for (int i = 1; i <= m; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      if (u > v) std::swap(u, v);
      Gr[k][u].push_back(v);
    }
  }
}

void getSg(int k) {
  static bool buc[MaxN + 5];
  memset(buc, false, sizeof buc);
  int mx = 0;
  for (int u = N; u >= 1; --u) {
    for (int i = 0; i <= mx; ++i) buc[i] = false;
    mx = 0;
    for (int v : Gr[k][u]) {
      buc[Sg[k][v]] = true;
      mx = std::max(mx, Sg[k][v]);
    }
    for (int i = 0; i <= mx + 1; ++i)
      if (buc[i] == false) {
        Sg[k][u] = i;
        break;
      }
  }
}

void solve() {
  for (int k = 0; k < 3; ++k) getSg(k);
  for (int k = 0; k < 3; ++k)
    for (int i = 1; i <= N; ++i)
      inc(Buc[k][Sg[k][i]], Pw[i]);
  int ans = 0;
  for (int i = 0; i <= MaxS; ++i)
    for (int j = 0; j <= MaxS; ++j) {
      int k = i ^ j;
      if (k > MaxS) continue;
      inc(ans, mul(mul(Buc[0][i], Buc[1][j]), Buc[2][k]));
    }
  printf("%d\n", ans);
}

int main() {
  init();
  solve();
  return 0;
}

Measured memory_bytes: 14336
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int [] h1 = new int[2];
		int [] h2 = new int [2];
		
		h1[0] = Integer.parseInt(sc.next())*60;
		h1[1] = Integer.parseInt(sc.next());
		h2[0] = Integer.parseInt(sc.next())*60;
		h2[1] = Integer.parseInt(sc.next());
		
		int k = Integer.parseInt(sc.next());
		
		int get = h1[0] + h1[1];
		int sle = h2[0] + h2[1];
		
		sle -= k;
		System.out.println(sle -get);
	}

}


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

int main(){
  vector<int> num(5);
  scanf("%d %d %d %d %d", &num[0], &num[1], &num[2], &num[3], &num[4]);

  sort(num.begin(),num.end(),greater<int>());

  printf("%d %d %d %d %d\n", num[0], num[1], num[2], num[3], num[4]);
  return EXIT_SUCCESS;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<ll> v(N);
  ll sumA = 0, sumB = 0;
  rep(i,N){
    cin >> v[i];
    sumA+=v[i];
  }
  rep(i,N){
    ll x;cin >> x;
    sumB+=x;
    v[i]-=x;
  }
  if(sumA<sumB){
    cout << -1 << endl;
    return 0;
  }
  sort(all(v));
  int count = 0;
  ll sum = 0;
  rep(i,N){
    if(v[i]>=0)break;
    ++count;
    sum += v[i];
  }
  per(i,N){
    if(sum>=0)break;
    sum += v[i];
    ++count;
  }
  cout << count << endl;
  return 0;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<pair<i64, i64>> C(N);
    for (i32 i = 0; i < N; i++) {
        i64 A, B;
        cin >> A >> B;
        C[i] = make_pair(B, A);
    }
    sort(ALL(C));
    i64 sum = 0;
    bool ans = true;
    for (i32 i = 0; i < N; i++) {
        sum += C[i].second;
        if (sum > C[i].first) ans = false;
    }
    cout << YN("Yes", "No", ans) << endl;

}


Measured memory_bytes: 6348
#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;
   int a,b;
   cin >> a >> b;
   string u;
   cin >> u;
   if(s == u){
   	--a; 
   }else{
   	  --b;
   }
   cout << a << " " << b << endl;
 }

Measured memory_bytes: 256
from sys import stdin

def main():
    A=stdin.readline().replace('B', '0').replace('W', '1')
    #A=list(map(int,bw))
    #A = list(map(int,stdin.readline().replace('B', '0').replace('W', '1')))

    wc = A.count('1')
    indices = [i for i, x in enumerate(A) if x == '1']
    if wc > 0:
      print(sum(indices) - 1*wc*(wc-1) //2 )
    else:
      print(sum(indices))

input = lambda: stdin.readline()
main()


Measured memory_bytes: 11364