akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define MAX 100005
ll INF = (1LL<<40);

struct edge{
  ll to,cost;
};

struct state{
  ll pos,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};

vector<edge> G[MAX];
ll d[MAX];
vector<ll> A,B,C;
ll N,M,K,sum=0;

int main(){
  cin>>N>>M>>K;
  for(int i=0;i<M;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    G[a].push_back((edge){b,c});
    G[b].push_back((edge){a,c});
    A.push_back(a);
    B.push_back(b);
    C.push_back(c);
    sum+=c;
  }
  fill(d,d+MAX,INF);
  d[0]=0;
  priority_queue< state > Q;
  Q.push((state){0,0});
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost > d[s.pos])continue;
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(e.cost + s.cost < d[e.to]){
        d[e.to]=e.cost+s.cost;
        Q.push((state){e.to,d[e.to]});
      }
    }
  }
  
  vector<P> vec;
  for(int i=0;i<M;i++){
    ll maxm=max(d[A[i]],d[B[i]]);
    vec.push_back(P(maxm,C[i]));
  }

  sort(vec.begin(),vec.end());
  ll ans=sum;
  for(int i=0;i<(int)vec.size();i++){
    sum-=vec[i].second;
    ans=min(ans, vec[i].first*K+sum);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 27888
// AOJ ALDS1_9_C Priority Queue
// 2018.4.27 bal4u

#include <stdio.h>

#define QSIZE 2000002

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

typedef struct { int t; } QUE;
QUE que[QSIZE+5];
int qsize;

void max_heapify(int i)
{
	int l, r, max;
	QUE qt;
	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t > que[i].t) max = l; else max = i;
	if (r < qsize && que[r].t > que[max].t) max = r;
	if (max != i) {
		qt = que[i], que[i] = que[max], que[max] = qt;
		max_heapify(max);
	}
}

void deq()
{
	que[0] = que[--qsize];
	max_heapify(0);
}

void enq(long long t)
{
	int i, max;
	QUE qt;

	i = qsize++;
	que[i].t = t;
	while (i > 0 && que[max = PARENT(i)].t < que[i].t) {
		qt = que[i]; que[i] = que[max], que[max] = qt;
		i = max;
	}
}


// バッファを経ずstdinから数値を得る
#define gc() getchar_unlocked()
//#define gc() getchar()
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int main()
{
	int k;

	qsize = 0;
	while (1) {
		if (gc() == 'e') {
			if (gc() == 'n') break;
			k = 6; while (k--) gc();
			printf("%d\n", que[0].t);
			deq();
		} else {
			k = 6; while (k--) gc();
			enq(in());
		}
	}
	return 0;
}



Measured memory_bytes: 5672
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr clear()
#define ins insert
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define cusmem(x,val) for(auto &i:x) i=val;
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);\
            cin.tie(NULL);\
            cout.tie(NULL);
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int>pli;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
string impossible;

mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());

// const int N=6;
const int N=5e2+5;
const int M=1e4+5;
const int L=41;
int MOD=1e9+7;
// ll n,m,k,i,j,d;
bool f0,f1,f2;
const int MAXN=2e3;

ll dp[3005][3005][4];

int main(){
    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin); 
            freopen("output.txt","w",stdout);
    #endif
    fastio
    cout<<fixed<<setprecision(11);
    int tests=1;    
    // cin>>tests;
    for(int te=1;te<=tests;te++){
        ll r,c,items;  cin>>r>>c>>items;
        int v[r][c]; mem(v,0);
        for(int i=0;i<items;i++){
            int x,y,val;    cin>>x>>y>>val;
            v[x-1][y-1]=val;
        }
        
        mem(dp,0LL);
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                for(int k=0;k<4;k++){
                    if(i-1>=0)  dp[i][j][k]=max(dp[i-1][j][3],dp[i][j][k]);
                    if(j-1>=0)  dp[i][j][k]=max(dp[i][j-1][k],dp[i][j][k]);
                    if(k>0){
                        if(i-1>=0)  dp[i][j][k]=max(v[i][j]+dp[i-1][j][3],dp[i][j][k]);
                        if(j-1>=0)  dp[i][j][k]=max(v[i][j]+dp[i][j-1][k-1],dp[i][j][k]);
                        dp[i][j][k]=max(dp[i][j][k],v[i][j]*1LL);
                    }
                    // cout<<dp[i][j][k]<<" ";
                }
                // cout<<"|\t|";
            }
            // cout<<"\n";
        }
        cout<<dp[r-1][c-1][3];
    }
    return 0;
}





Measured memory_bytes: 320900
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=1e9+7;

lint pow_mod(lint b, lint n,lint p){
  lint ans=1;
  lint i=b;
  while(n>0){
    if(n%2==1){
      ans*=i;
      ans%=p;
    }
    i*=i;
    i%=p;
    n/=2;
  }
  return ans;
}

lint inv_mod(lint a,lint p){
  return pow_mod(a,p-2,p);
}

lint nCk(lint n,lint k){
  lint nu=1,de=1;
  REP(i,k){
    nu*=n;
    nu%=p;
    n--;
  }
  REP(i,k){
    de*=i+1;
    de%=p;
  }
  return (nu*inv_mod(de,p))%p;
}

int main(){
  lint n,a,b;
  cin>>n>>a>>b;
  cout<<(2*p+pow_mod(2,n,p)-nCk(n,a)-nCk(n,b)-1)%p<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
      int a = in.nextInt(), b = in.nextInt();
      if (a < b) 
        System.out.println("a < b");
      else if (a > b)
        System.out.println("a > b");
      else
        System.out.println("a == b");
    }
}

Measured memory_bytes: 26224
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

typedef long long ll;

const int ALP = 26;
const int INF = 1e9 + 239;
const int N = 2e5 + 7;

namespace Fenw {
	int f[N];

	void add(int pos, int val) {
		for (int i = pos; i < N; i = (i | (i + 1))) {
			f[i] += val;
		}
	}

	int get(int pos) {
		int ans = 0;
		for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {
			ans += f[i];
		}
		return ans;
	}

	void init() {
		for (int i = 0; i < N; i++) {
			add(i, 1);
		}
	}
}

ll ans = 0;

int n;
string s;
vector<int> ps[ALP];
int pl[ALP];
int pr[ALP];

void init() {
	Fenw::init();
	for (int i = 0; i < n; i++) {
		ps[s[i] - 'a'].push_back(i);
	}
	for (int i = 0; i < ALP; i++) {
		pl[i] = 0;
		pr[i] = (int)ps[i].size() - 1;
	}
}

void doit(int &cs) {
	int best = INF;
	int to = -1;
	for (int i = 0; i < ALP; i++) {
		if (pl[i] >= pr[i]) continue;
		if (best > (Fenw::get(ps[i][pl[i]])) + (cs - 1 - Fenw::get(ps[i][pr[i]]))) {
			best = (Fenw::get(ps[i][pl[i]])) + (cs - 1 - Fenw::get(ps[i][pr[i]]));
			to = i;
		}
	}
	if (to == -1) {
		cout << -1 << endl;
		exit(0);
	}
	int l = ps[to][pl[to]];
	int r = ps[to][pr[to]];
	Fenw::add(l, -1);
	Fenw::add(r, -1);
	ans += (ll)best;
	cs -= 2;
	pl[to]++;
	pr[to]--;
}

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

	cin >> s;
	n = (int)s.size();
	init();
	int cs = n;
	while (cs >= 2) {
		doit(cs);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2680
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define pb push_back
#define mp make_pair
#define err(x) cout<<#x<<"= "<<x<<endl;
#define rep(i,n) for(int i =0; i< n; i++)
#define ff first
#define ss second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 2009
#define eps 1e-13
//const ll infi =

int nxt[SIZE],n,q,k,reserv[SIZE];

ll A[SIZE],idx[SIZE];

int cmp(int a, int b){
	return A[a] < A[b];
}
int solve(ll sta, int id1){                              // A[idx[id]] = sta
	rep(i,n+1){
		nxt[i] = n;reserv[i] = 0;
	}
	
	vector<int> impos;int prev = -1;
	impos.pb(n);

	for(int i = n-1; i>=0; i--){
		if( A[i]  < sta){
			reserv[impos.back()] = max(0, impos.back()- i-k);
			for(int j = i; j< impos.back(); j++)
				nxt[j] = impos.back();
			impos.pb(i);
		}			
	}//-1
	reserv[impos.back()] = max(0, impos.back()-k+1);
	for(int i =0; i< impos.back(); i++)
		nxt[i] = impos.back();
//	cout<<"for sta = "<<sta<<' '<<reserv[n]<<endl;
//	rep(i,n){
//		cout<<reserv[i]<<' ';
//	}
//	cout<<endl;
//	rep(i,n)cout<<nxt[i]<<' ';
//	cout<<endl<<endl;;
	int cnt = 1;
	//cerr<<reserv[nxt[idx[id1]]]<<endl;
	if(reserv[nxt[idx[id1]]] <=0 ) return INF;
	if(q==1) return 0;
	reserv[nxt[idx[id1]]]--;
	for(int i = id1+1; i< n; i++){
	//	if(cnt>=q) break;
		if(reserv[nxt[idx[i]]]){
			reserv[nxt[idx[i]]]--;
			cnt++;
		//	cout<<cnt<<endl;
			if(cnt == q)return A[idx[i]]-sta;
		}
	}

	return INF;
}	
	
int main(){
//	#ifdef ONLINE_JUDGE
//	freopen("little.in", "r" , stdin);
//	freopen("little.out", "w", stdout);
// cin.tie(false); cout.tie(false);	
//	#endif
	ios::sync_with_stdio(false);
	cin>>n>>k>>q;
	rep(i,n){
		cin>>A[i];
		idx[i] = i;
	}
	sort(idx, idx+n,cmp);
//	rep(i,n){
//		cout<<A[idx[i]] <<' ';
//	}
//	cout<<endl;
	int ans = INF;
	rep(i,n){
		ans = min(ans,solve(A[idx[i]] , i));
	//	cout<<ans<<endl;
	}
	
	cout<<ans<<endl;

	return 0;
};


Measured memory_bytes: 384
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void sot (lld B[], lld C[], lld m)
{
	pair <lld, lld> P[m];
	for(lld i = 0; i < m; i+=1){
		P[i].first = C[i];
		P[i].second= B[i];
	}
	sort(P, P+m);
	for(lld i = 0; i < m; i+=1){
		C[i] = P[i].first;
		B[i] = P[i].second;
	}
}
int main ()
{
      FastIO
      lld n, m;
      cin >> n;
      cin >> m;
      lld A[n];
      for(lld i = 0; i < n; i += 1){
      	cin >> A[i];
      }
      lld B[m], C[m];
      for(lld i = 0; i < m; i += 1){
      	cin >> B[i] >> C[i];
      }
      sot(B , C , m);
      sort(A, A + n);
      lld j = m - 1 ;
      for(lld i = 0; i < n; i += 1){
      	if (A[i] < C[j]&& j>=0){
      		A[i]=C[j];
      		B[j] -= 1;
      		if (B[j] == 0){
      			j--;
      		}
      	}
      }
      lld sum = 0;
      for(lld i = 0; i < n; i += 1){
      	sum+= A[i];
      }
      cout << sum;
      return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	vector<long long> a(n);
	cin >> a;

	long long cur = 0;
	long long ans1 = 0, ans2 = 0;
	rep(i,n){
		cur += a[i];
		if(i % 2){
			if(cur <= 0){
				ans1 += abs(cur) + 1;
				cur = 1;
			}
		}else{
			if(cur >= 0){
				ans1 += abs(cur) + 1;
				cur = -1;
			}
		}
	}

	cur = 0;
	rep(i,n){
		cur += a[i];
		if(i % 2){
			if(cur >= 0){
				ans2 += abs(cur) + 1;
				cur = -1;
			}
		}else{
			if(cur <= 0){
				ans2 += abs(cur) + 1;
				cur = 1;
			}
		}
	}
	cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 1024
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back


using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 2000001;
const ll mod = 1000000007;
/*
ll fac[MAXN];
ll inv[MAXN];

ll modPower(ll x,ll y){
    x%=mod;
    ll res = 1;
    while(y){
        if(y&1)res= (res*x)%mod;
        x = (x*x)%mod;
        y>>=1;
    }
    return res;
}

void pre(){
    fac[0] = 1;
    for(ll i = 1; i < MAXN; i++)fac[i] = (i * fac[i-1])%mod;
    inv[MAXN-1] = modPower(fac[MAXN-1] , mod-2);
    for(ll i = MAXN-2; i >= 0; i--)inv[i] = (inv[i+1] * (i+1))%mod;
}*/

int main(){
    ll n, t;
    cin>>n>>t;
    ll a[n], b[n];
    fr(i,n)cin>>a[i] >> b[i];
    ll dp[n+1][t+1];

    fr(i,n+1)fr(j,t+1)dp[i][j] = 0;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= t; j++){
            dp[i][j] = dp[i-1][j];
            if(j >= a[i-1])dp[i][j] = max(dp[i][j], b[i-1] + dp[i-1][j-a[i-1]]);
        }
    }

    /*fr(i,n+1){
        fr(j,t+1)cout<<dp[i][j]<<' ';
        cout<<endl;
    }*/

    ll ans = dp[n][t-1];

    bool inc[n];
    fill(inc, inc+n , 0);

    int ptr = n, tt = t-1;

    while(ptr > 0){
        if(tt >= a[ptr-1] && dp[ptr][tt] == b[ptr-1] + dp[ptr-1][tt - a[ptr-1]])inc[ptr-1] = 1 , tt -= a[ptr-1];
        ptr--;
    }

//cout<<"Inc: "; fr(i,n)cout<<inc[i]<<' '; cout<<endl;

    ll extra = 0;
    fr(i,n)if(!inc[i])extra = max(extra, b[i]);
    ans += extra;

    ans = max(ans, dp[n][t]);

    cout<< ans << endl;
}


Measured memory_bytes: 70656
//##MohK..
//09/05/2020 .... 3,07..
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,b;
    cin>>a>>b;
    if(b>=a)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;


    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

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

ll n,m;

int main(){
	cin >> n >> m;
	vector<P> vp(m);
	vector<vector<ll>> cnt(2,vector<ll>(n,1));
	rep(i,m)cin >> vp[i].first >> vp[i].second;
	sort(ALL(vp));
	rep(i,m){
		ll num = vp[i].second;
		cnt[0][num] = max(cnt[0][num],cnt[0][num-1]+1);
		cnt[1][num-1] = max(cnt[1][num]+1,cnt[1][num-1]);
		// rep(j,n){
		// 	cout << cnt[0][j] << " " << cnt[1][j] << endl;
		// }
		// cout << endl;
	}
	rep(i,n){
		// cout << cnt[0][i] << " " << cnt[1][i] << endl;
		cout << cnt[0][i] + cnt[1][i] - 1;
		if(i != n-1)cout << " ";
		else cout << endl;
	}
}



Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,W;cin>>N>>W;vector<pair<int,int>>A(N);
  int a=0,b=0,c=0,d=0;
  vector<int>B(N);
  vector<int>C(N);
  vector<int>D(N);
  vector<int>E(N);
  int Z=0;
  for(int i=0;i<N;i++){
    cin>>A[i].first>>A[i].second;
    Z=A[0].first;
    if(A[i].first-A[0].first==0){B[a]=A[i].second;a++;}
    if(A[i].first-A[0].first==1){C[b]=A[i].second;b++;}
    if(A[i].first-A[0].first==2){D[c]=A[i].second;c++;}
    if(A[i].first-A[0].first==3){E[d]=A[i].second;d++;}
  }
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  sort(D.begin(),D.end());
  sort(E.begin(),E.end());
  reverse(B.begin(),B.end());
  reverse(C.begin(),C.end());
  reverse(D.begin(),D.end());
  reverse(E.begin(),E.end());
  long long ans=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(W-Z*i-(Z+1)*j-(Z+2)*k<0)break;
        long long count=0;
        for(int l=0;l<i;l++)count+=B[l];
        for(int l=0;l<j;l++)count+=C[l];
        for(int l=0;l<k;l++)count+=D[l];
        for(int l=0;l<(W-Z*i-(Z+1)*j-(Z+2)*k)/(Z+3);l++)count+=E[l];
        ans=max(ans,count);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3616
S = input()
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] == "1":
        n += 1
    else:
        break

if S[0] == "1" and K <= n:
    print(1)
elif S[0] == "1" and K > 1:
    print(S[n])
elif S[0] != "1":
    print(S[0])


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		final int H=sc.nextInt(),W=sc.nextInt();
		sc.nextLine();
		final String[][] s=new String[H+2][W+2];
		boolean f=true;
		for(int i=0;i<W+2;i++){
			s[0][i]=".";
			s[H+1][i]=".";
		}
		for(int i=1;i<H+1;i++){
			s[i]=("."+sc.nextLine()+".").split("");
		}
		/*		
		for(int i=0;i<H+2;i++){
			for(int k=0;k<W+2;k++){
				System.out.print(s[i][k]);
			}
			System.out.println("");
		}
		*/
		
		for(int i=1;i<H+1;i++){
			for(int k=1;k<W+1;k++){
				if(s[i][k].equals("#")){
					if(s[i-1][k].equals("#"))continue;
					if(s[i+1][k].equals("#"))continue;
					if(s[i][k-1].equals("#"))continue;
					if(s[i][k+1].equals("#"))continue;
					f=false;
					break;
				}
			}
			if(! f)break;
		}
		
		String ans;
		if(f){
			ans="Yes";
		}else{
			ans="No";
		}
		System.out.println(ans);
	}
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    int p[5001];
    int c[5001];
    long long ans[5001] = {0};
    
    cin >> n >> k;
    for(int i=0; i<n; i++)
        cin >> p[i];
    for(int i=0; i<n; i++)
        cin >> c[i];  
        
    for(int i=0; i<n; i++){
        // find out length, cycle_length, cycle_sum, whole_sum, max_val, s_pos
        int length=0, cycle_length=0, s_pos=0;
        long long cycle_sum=0, whole_sum=0, max_val = -1e18;
        int s = i;
        
        unordered_map<int, vector<long long>> dict;
        while(dict[s].empty()){
            // cout<< " s is : " << s <<'\n';
            dict[s] = {length, whole_sum};
            // cout << "dict[s] is : " << length << " " << whole_sum << '\n';
            length++;
            whole_sum += c[p[s]-1];
            s = p[s]-1;
            if(length <= k)
                max_val = max(whole_sum, max_val);
        }
        
        
        cycle_length = length - dict[s][0];
        cycle_sum = whole_sum - dict[s][1];
        s_pos = s;
        // cout << "cycle_length is : " << cycle_length << " cycle_sum is : " << cycle_sum <<
        // " s_pos is : " << s_pos <<'\n' << '\n';
        if(k <= length){
            ans[i] = max_val;
        }
        else{ // k > length
            if(cycle_sum <= 0)
                ans[i] = max_val;
            else{
                int pos_cycle = (k - length)/cycle_length;
                if(pos_cycle >= 1){
                    int left_k = (k-length) - (pos_cycle-1)*cycle_length;
                    whole_sum += (pos_cycle-1)*cycle_sum;
                    max_val = max(whole_sum, max_val);
                    for(int j=0; j<left_k; j++){
                        whole_sum += c[p[s_pos]-1];
                        s_pos = p[s_pos]-1;
                        max_val = max(whole_sum, max_val);
                    }
                    ans[i] = max_val;
                }
                else{
                    int left_k = k - length;
                    for(int j=0; j<left_k; j++){
                        whole_sum += c[p[s_pos]-1];
                        s_pos = p[s_pos]-1;
                        max_val = max(whole_sum, max_val);
                    }
                    ans[i] = max_val;
                }
            }
        }
    }
    //for(int i=0; i<n; i++)
    //        cout << ans[i] <<' ';
    //    cout << '\n';
    cout << *max_element(ans, ans+n);
    return 0;
}

Measured memory_bytes: 4168
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

int N;
map<long long, int> M;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i=0; i<N; i++){
		long long a;
		cin >> a;
		if(M.count(a) == 0){
			M[a] = 1;
		}
		else{
			M[a]++;
		}
	}

	int c1 = 0, c2 = 0;
	for(auto itr = M.begin(); itr != M.end(); itr++){
		long long k = itr->first;
		int v = itr->second;
		if(v >= 3){
			if((v % 2) == 0){
				M[k] = 2;
			}
			else{
				M[k] = 1;
			}
		}
		if(M[k] == 1){
			c1++;
		}
		else if(M[k] == 2){
			c2++;
		}
	}
	int ans = 0;
	if((c2 % 2) == 0){
		ans = c1 + c2;
	}
	else{
		ans = c1 - 1 + c2;
	}

	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 9892
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#define N 102
using namespace std;
int n, m;
int dis[N][N];
int main() {
	vector<pair<pair<int, int>, int>> edges;
	edges.clear();
	cin>>n>>m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			dis[i][j] = (i == j ? 0 : 1000000000);
		}
	}
	for (int i = 1; i <= m; ++i) {
		int a,b,c;
		cin>>a>>b>>c;
		edges.push_back(make_pair(make_pair(a,b), c));
		dis[a][b] = dis[b][a] = c;
	}
	for (int k = 1; k <= n; ++k) {
		for (int i = 1; i <= n; ++i) {
			for (int j =1 ; j <= n; ++j) {
				dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j]);
			}
		}
	}
	int cnt=0;
	for (int i = 0; i < edges.size(); ++i) {
		int a = edges[i].first.first;
		int b = edges[i].first.second;
		int c = edges[i].second;
		bool found = false;
		for (int i = 1; i <= n; ++i) {
			if (dis[i][a]+c == dis[i][b] || dis[i][b]+c == dis[i][a]) {
				found=true;
				break;
			}
		}
		if (!found) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>
#include <array>
#include <cstdio>

using namespace std;

using ll = long long;
using ull = unsigned long long;

static const int INF = 100000;

int main()
{
    int H, W, K;
    cin >> H >> W >> K;

    vector<string> S(H);
    for (int i = 0; i < H; ++i) {
        cin >> S[i];
    }

    int ans = INF;

    for (int i = 0; i < 1024; ++i) {
        int c = 0;
        vector<int> index(H);

        for (int j = 0; j < H; ++j) {
            index[j] = c;

            if (i & (1 << j)) {
                ++c;
            }
        }

        int ans_c = c;
        vector<int> counts(c+1, 0);

        for (int k = 0; k < W; ++k) {
            for (int j = 0; j < H; ++j) {
                if (S[j][k] == '1') {
                    counts[index[j]]++;
                }
            }

            bool any = any_of(begin(counts), end(counts), [K](int c){
                return c > K;
            });

            if (any) {
                ++ans_c;

                fill(begin(counts), end(counts), 0);
                for (int j = 0; j < H; ++j) {
                    if (S[j][k] == '1') {
                        counts[index[j]]++;
                    }
                }
            }
        }

        bool any = any_of(begin(counts), end(counts), [K](int c){
            return c > K;
        });

        if (any) {
            ans_c = INF;
        }

        ans = min(ans, ans_c);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>


int main()
{
	int R[200000];
	int maxv, minv;
	int i, j, n;
	
	scanf("%d",&n);
	
	for (i = 0; i < n; i++) {
		scanf("%d",&R[i]);
	}
	
	minv = R[0];
	maxv = R[1] - R[0];
	
	
	
	for (j = 1; j <= n - 1; j++) {
		if (maxv < R[j] - minv) {
			maxv = R[j] - minv;
		}
		if (R[j] < minv) {
			minv = R[j];
		}
	}
		
	printf("%d\n",maxv);
return 0;
}


Measured memory_bytes: 2648
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    while (true) {
      int N = ReadInt();
      if (N == 0) return;
      int[] A = ReadIntArray();
      double avg = A.Average();
      int count = A.Count(x => x <= avg);
      Console.WriteLine(count);
    }
  }

  private static List<int> _var;
  public static int cin() { if (_var == null || _var.Count() == 0) { _var = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>(); } int ans = _var[0]; _var.RemoveAt(0); return ans; }
  public static void Swap<T>(ref T a, ref T b) {T temp = a;a = b;b = temp;}
  public static string ReadStr() { return Console.ReadLine(); }
  public static int ReadInt() { return int.Parse(Console.ReadLine()); }
  public static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  public static long ReadLong() { return long.Parse(Console.ReadLine()); }
  public static char ReadChar() { return Console.ReadLine()[0]; }
  public static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  public static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  public static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  public static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  public static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  public static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}



Measured memory_bytes: 17516
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n;cin >> n;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    map<LL,LL> ma;
    LL ans = 0;
    for (int i = n-1; i >= 0; i--) {
        ma[i - a[i]]++;
        ans += ma[a[i] + i];
    }
    cout << ans << endl;
    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

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

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL a(n);
	LL max_a = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		max_a = max(max_a,a[i]);
	}
	LL hmax = INT32_MAX;
	for (int i = 0; i < n; i++) {
		if(abs(LL(double(max_a/2) - hmax))> abs(LL(double(max_a/2) - a[i])) and a[i] != max_a) hmax = a[i];
	}
	cout << max_a << ' ' << hmax << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<stdio.h>
#include<cmath>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<string.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<string.h>
#include<stack>
#include<queue>
#include<deque>
 
#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
//#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 100000007
 
using namespace std;

char a[7][7],b[7][7];
ll n,m,k;

void copy()
{
    for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++)
    {
        b[i][j] = a[i][j];
    }
}
void colouring(ll i,ll j)
{
    for(ll x=0;x<n;x++)
    {
        if(i&(1<<x))
        {
            for(ll y=0;y<m;y++)
            {
                b[x][y]='@';
            }
        }
    }
    for(ll x=0;x<m;x++)
    {
        if(j&(1<<x))
        {
            for(ll y=0;y<n;y++)
            {
                b[y][x] = '@';
            }
        }
    }
}

bool check()
{
    ll count=0;
    for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++)
    {
         if(b[i][j]=='#')
         {
             count++;
         }
    }
    if(count==k) return true;
    else return false;
}

int main()
{
    //fastio
    
    sfffl(n,m,k);
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    for(ll i=0;i<(1<<n);i++)
    for(ll j=0;j<(1<<m);j++)
    {
        copy();
        colouring(i,j);
        if(check()) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
    int N;
    cin>>N;
    int M=N/2;
    double O=N-M;
    double ans=O/(double)N;
    cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=2019;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
int main()
{
	int n,m,q,k;
	string s;
	cin>>s;
	reverse(all(s));
	map<int,int>mp;
	int len=s.length();
	int ans=0;
	int now=0,f=1;
	mp[0]++;
	for(int i=0;i<len;i++){
		now=(now+f*(s[i]-'0'))%2019;
		(f*=10)%=2019;
		ans+=mp[now];
		mp[now]++;
	}
	cout<<ans;
}


Measured memory_bytes: 3372
import sys


def main():
    x, y = map(int, input().split())

    if y > 4 * x:
        print('No')
        sys.exit()

    if y < 2 * x:
        print('No')
        sys.exit()

    if not (y % 2 == 0):
        print('No')
        sys.exit()
    
    if (y - 2 * x) % 2 == 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef set <int> S;

int skip(string str,int i){
  int cnt=str[i++]=='(';
  while(cnt) cnt+=(str[i]=='(')-(str[i++]==')');
  return i-1;
}

void calc(char ch,S a,S b, S &res){
  S::iterator i,j;
  for(i=a.begin();i!=a.end();i++)
    for(j=b.begin();j!=b.end();j++){
      int I=*i,J=*j;
      if(ch=='+') I+=J;
      else if(ch=='-') I-=J;
      else if(ch=='*') I*=J;
      else if(ch=='/'&&J)I/=J;
      else continue;
      res.insert(I);
    }
}

int num[1<<8];
S solve(string str){
  S res;
  int len=str.size();
  if(len==1){res.insert(num[str[0]]);return res;}
  if(skip(str,0)==len-1)res=solve(str.substr(1,len-2));

  for(int i=0;(i=skip(str,i))<len-1;i+=2)
    calc(str[i+1],solve(str.substr(0,i+1)),solve(str.substr(i+2,len-i-2)),res);

  return res;
}

int main(){
  while(1){
    string str;
    cin>>str;
    if(str=="#")break;
    string siki;
    char ch='A';
    for(int i=0;i<str.size();){
      int b=0;
      while('0'<=str[i]&&str[i]<='9') b=b*10+str[i++]-'0';
      if(b)num[ch]=b,siki+=ch++;
      else siki+=str[i++];
    }
    cout <<solve(siki).size()<<endl;
  }
  return 0;
}

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

const int INF = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];

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

    int ans = INF;
    for (int i = 0; i <= N - K; i++) {
        int tmp = h[i] - h[i + K - 1];
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

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

int main() {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    int y_len = y2 - y1;
    int x_len = x2 - x1;

    int x3, y3, x4, y4;
    y3 = y2 + x_len;
    x3 = x2 - y_len;
    x4 = x1 - y_len;
    y4 = y1 + x_len;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(3 * n);
  for (int i = 0; i < a.size(); i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  int64_t ans = 0;
  for (int i = 1; i <= 2 * n; i += 2) {
    ans += (int64_t)a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b=input().split()
    l=['A','B','C','D','E','F']
    if l.index(a)<l.index(b):
        print('<')
    elif l.index(a)>l.index(b):
        print('>')
    else:
        print('=')
resolve()

Measured memory_bytes: 3060
fn read_str() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).expect("Fail to read input.");
    s
}

fn read_num() -> i32 {
    read_str().trim().parse().expect("Could not parse.")
}

fn read_nums() -> Vec<i32> {
    let s = read_str();
    let a: Vec<&str> = s.split(' ').collect();
    let mut v: Vec<i32> = Vec::new();
    for x in a {
        v.push(x.trim().parse().expect("Could not parse."));
    }
    v
}

fn main() {
    let v = read_nums();
    if v[0] < v[1] && v[1] < v[2] {
        println!("Yes");
    } else {
        println!("No");
    }
}



Measured memory_bytes: 5024
import qualified Data.ByteString.Char8 as BC
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed ((!))
import Data.Maybe
import Control.Applicative

findBinary :: V.Vector Int -> Int -> Bool
findBinary v n = fB (0, V.length v)
    where
        fB (lower,upper)
            | upper - lower <= 1 = lower == n || upper == n
            | otherwise = let mid = (upper + lower) `div` 2
                              x = v ! mid
                              in
                               case n `compare` x of
                                    LT -> fB (lower,mid)
                                    GT -> fB (mid,upper)
                                    EQ -> True
-- |
-- >>> let v = V.fromList [1,3,4,5,8,12,13]
-- >>> findBinary v 1
-- True
-- >>> findBinary v 11
-- False
-- >>> findBinary v 13
-- True

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

main = do
    _ <- getLine
    s <- V.fromList <$> readInts
    _ <- getLine
    t <- V.fromList <$> readInts
    print . V.length . V.filter (findBinary s) $ t

Measured memory_bytes: 8512
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;


signed main(){
    int N,K;cin>>N>>K;
    vector<int>G(N);
    REP(i,N){
        int a;cin>>a;a--;
        G[i]=a;
    }
    int now=0;
    if(K<=N){
        REP(i,K){
            now=G[now];
        }
    }
    else{
        vector<int>visited(N);
        REP(i,N)visited[i]=INF;
        REP(i,2*N){
            if(visited[now]==INF)visited[now]=i;
            else{
                int a=i-visited[now];
                if((K-visited[now])%a==0){
                    break;
                }
            }
            now=G[now];
        }
    }
    cout<<now+1<<endl;
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int B[N];
    for(int i=1;i<N;i++)cin >> B[i];
    int Ans = B[1]+B[N-1];
    for(int i=2;i<=N-1;i++){
        if(B[i-1]<=B[i]){
            Ans+=B[i-1];
        }else{
            Ans+=B[i];
        }
    }
    cout << Ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using Int = long long;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    int l = 0;
    int ans[N] = {};
    while (l < N){
        int r = l + 1;
        if (S[l] == 'R'){
            while (r < N && S[r] == 'R') r += 1;
                ans[r-1] = r-l;
        }else{
            while (r < N && S[r] == 'L') r += 1;
            ans[l] = r-l;
        }
        l = r;
    }
    int i=0;
    while (i<N-1){
        if (ans[i]){
            int tmp = (ans[i]+ans[i+1])/2;
            if((ans[i] + ans[i+1])%2 == 0){
                ans[i] = tmp;
                ans[i+1] = tmp;
            }else{
                if (ans[i] > ans[i+1]){
                    if(ans[i] % 2){
                        ans[i] = tmp+1;
                        ans[i+1] = tmp;
                    }else{
                        ans[i] = tmp;
                        ans[i+1] = tmp+1;
                    }
                }else{
                    if(ans[i+1] % 2){
                        ans[i+1] = tmp+1;
                        ans[i] = tmp;
                    }else{
                        ans[i+1] = tmp;
                        ans[i] = tmp+1;
                    }
                }
            }
            i += 2;
            continue;
        }
        i += 1;
    }
    for(int i=0;i<N;i++) cout << ans[i] << " ";
    cout << endl;

}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    int t[100005][3];
    for(int i=0;i<n;i++)cin>>t[i][0]>>t[i][1]>>t[i][2];
    int d[100005][3];
    rep(i,n+2)rep(j,3)d[i][j]=0;
    d[0][0]=d[0][1]=d[0][2]=0;
    for(int i=0;i<n;i++)for(int j=0;j<3;j++)for(int k=0;k<3;k++)if(j!=k)d[i+1][k]=max(d[i+1][k],d[i][j]+t[i][k]);
    int res=0;
    for(int i=0;i<3;i++) res=max(res,d[n][i]);
    cout<<res<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	int n;
	cin >> n;

	int cnt = 0;
	int mx = 0;

	rep(i, n){
		int d1, d2;
		cin >> d1 >> d2;
		if(d1 == d2){
			cnt++;
			chmax(mx, cnt);
		}else{
			cnt = 0;
		}
	}

	if(mx >= 3){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define jl long long

int main() {
    int N; // 行
    int M; // 列
    int K; // 黒の個数
    cin >> N >> M >> K;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= M; j++) {
            int ans = (i*(M-j)+(N-i)*j);
            if ( ans == K ) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N;
    cin >> N;
    //N*N-2*N-4
    if(N%2==1)GOODBYE;
    int Ans=0;
    int k=N/10;
    while(k>0){
        Ans+=k;
        k/=5;
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int cnt=0;
        int a,b,c;
        cin>>a>>b>>c;
        while(a>0&&b>0&&c>0){
            a--;b--;c--;cnt++;
        }
        while(a>1&&b>0){
            a-=2;b--;cnt++;
        }
        while(a>2){
            a-=3;cnt++;
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define LL long long
using namespace std;
typedef struct node
{
    int i;
    int rank1;
    bool friend operator <(const struct node &a,const struct node &b)
    {
        return a.rank1 < b.rank1;   //降序排序
    }
}node;
int main()
{
   int n;
   scanf("%d",&n);
   node newnode;
   set<node>  s;
   s.clear();
   for(int i=1;i<=n;i++)
   {
       newnode.i=i;
       scanf("%d",&newnode.rank1);
       s.insert(newnode);
   }
   set<node>  ::iterator it;
   it=s.begin();
   while(it!=s.end())
   {
       printf("%d ",(*it).i);
       it++;
   }
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll)1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    rep(a, 1, n) {
        ll con = n / a;
        if(n % a == 0)
            con--;
        ans += con;
    }
    cout << ans << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 3656
def d_cake_123_priority_queue(X, Y, Z, K, A, B, C):
    # editionalの解法3
    import heapq
    # 数列A, B, Cを降順ソート
    a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)

    def evaluation(x, y, z):
        # heapqは最小値を取り出す方式なので、符号を反転させないといけない
        return (-(a[x] + b[y] + c[z]), x, y, z)

    # priority queue を定義し、(A_1 + B_1 + C_1, 1, 1, 1) を追加
    q = []
    heapq.heappush(q, evaluation(0, 0, 0))
    ans = []
    memo = {(0, 0, 0): True}

    # priority queueに対するK回の操作の部分
    for _ in range(K):
        e, x, y, z = heapq.heappop(q)
        ans.append(-e)
        if x + 1 < X and (x + 1, y, z) not in memo:
            heapq.heappush(q, evaluation(x + 1, y, z))
            memo[(x + 1, y, z)] = True
        if y + 1 < Y and (x, y + 1, z) not in memo:
            heapq.heappush(q, evaluation(x, y + 1, z))
            memo[(x, y + 1, z)] = True
        if z + 1 < Z and (x, y, z + 1) not in memo:
            heapq.heappush(q, evaluation(x, y, z + 1))
            memo[(x, y, z + 1)] = True
    return '\n'.join(map(str, ans[:K]))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_priority_queue(X, Y, Z, K, A, B, C))

Measured memory_bytes: 5016