akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n,m,t;

vector<PP> G;
vector<P> bfsG[100001];
int edge[200001];
int s[200001],e[200001];
int par[200001];
int rank[200001];
int nowG[200001];
int dist[100001];
int cnt[200001];
ll dp[200001];

int find(int x){
	if(x==par[x])return x;
	return (par[x]=find(par[x]));
}

bool same(int x,int y){
	return find(x)==find(y);
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	if(rank[x]<rank[y]){
		par[y]=x;
	}else{
		par[x]=y;
		if(rank[x]==rank[y]){
			rank[x]++;
		}
	}
}

void bfs(){
	queue<int> que;
	memset(dist,-1,sizeof(dist));
	dist[0]=0;
	que.push(0);
	while(que.size()){
		int v=que.front();
		que.pop();
		//printf("%d %d\n",v,dist[v]);
		for(int i=0;i<bfsG[v].size();i++){
			if(dist[v]<bfsG[v][i].sc && dist[bfsG[v][i].fi]==-1){
				dist[bfsG[v][i].fi]=dist[v]+1;
				que.push(bfsG[v][i].fi);
			}
		}
	}
}

ll func(int v){
	if(dp[v]!=-1)return dp[v];
	ll res=0;
	if(edge[v]!=-1){
		res+=func(edge[v]);
	}
	ll get=(ll)cnt[v]*(s[v]-e[v]);
	//printf("%d %lld %lld\n",v,res,get);
	return dp[v]=(res+get);
}

int main(void){
	scanf("%d%d%d",&n,&m,&t);
	for(int i=0;i<m;i++){
		int a,b,T;
		scanf("%d%d%d",&a,&b,&T);
		a--;
		b--;
		G.push_back(PP(T,P(a,b)));
		bfsG[a].push_back(P(b,T));
		bfsG[b].push_back(P(a,T));
	}
	bfs();
	sort(G.begin(),G.end());
	reverse(G.begin(),G.end());
	for(int i=0;i<n;i++){
		par[i]=i;
		rank[i]=0;
		nowG[i]=i;
		s[i]=t;
		cnt[i]=1;
	}
	int all=n;
	memset(edge,-1,sizeof(edge));
	for(int i=0;i<G.size();i++){
		if(!same(G[i].sc.fi,G[i].sc.sc)){
			int x=find(G[i].sc.fi);
			int y=find(G[i].sc.sc);
			unite(x,y);
			//printf("par %d %d\n",x,y);
			edge[nowG[x]]=all;
			edge[nowG[y]]=all;
			cnt[all]=cnt[nowG[x]]+cnt[nowG[y]];
			e[nowG[x]]=G[i].fi;
			e[nowG[y]]=G[i].fi;
			s[all]=G[i].fi;
			//printf("now %d %d\n",nowG[x],nowG[y]);
			nowG[x]=all;
			nowG[y]=all;
			all++;
			//printf("%d %d %d %d\n",all-1,cnt[all-1],G[i].sc.fi,G[i].sc.sc);
		}
	}
	memset(dp,-1,sizeof(dp));
	ll res=0;
	for(int i=0;i<n;i++){
		if(dist[i]!=-1){
			res=max(res,func(i));
		}
	}
	printf("%lld\n",res);
	return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long n, a, b; cin >> n >> a >> b;
    long long ans = n / (a + b) * a + min(a, n % (a + b));
    cout << ans << "\n";
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int cnt = 0;
  for(int i = a; i <= b; i++){
    for(int j = c; j <= d; j++ ){
      if(i == j) cnt++;
    }
  }
  if(cnt >= 2){
  cout << cnt - 1 << endl;
  } else cout << 0 << endl;
 }


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
const int N=2e5+5;
const int P=998244353;
pii robs[N];
int n,cop[N],ner[N];
ll dp[N],sum[N],bb[N];
struct eff{
    int l,r,id;
    bool operator < (const eff a)const{
        return id<a.id;
    }
};
priority_queue<eff>q;
int findd(int x){return upper_bound(cop+1,cop+n+2,x)-cop;}
int main()
{
    sc(n);
    rep(i,1,n)sc2(robs[i].fi,robs[i].se);
    sort(robs+1,robs+n+1);
    rep(i,1,n)cop[i]=robs[i].fi;
    cop[n+1]=inf;
    rep(i,1,n){
        while(!q.empty()){
            auto u=q.top();
            if(i>u.r)q.pop();
            else if(i>=u.l&&i<=u.r&&!ner[i]){
                ner[i]=u.id;
                break;
            }else break;
        }
        int nx=robs[i].fi+robs[i].se-1,pos=findd(nx);
        q.push({i+1,pos-1,i});
    }
    bb[1]++;sum[0]=1;
    rep(i,1,n){
        bb[i]=(bb[i]+bb[i-1])%P;
        dp[i]=(dp[i]+bb[i])%P;
        if(ner[i]>0)dp[i]=((dp[i]-sum[ner[i]-1])%P+P)%P;
        bb[i+1]=(bb[i+1]+dp[i])%P;
        sum[i]=(dp[i]+sum[i-1])%P;
        //cout<<dp[i]<<" "<<sum[i]<<endl;
    }
    cout<<sum[n]<<endl;
    return 0;
}


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

int main(){
    string S;
    cin >> S;
    int s=S.size();
    int cnt=0;
    for(int i=0;i<s;i++){if(S[i]=='o')cnt++;}
    if(cnt+15-s>=8)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    A = []
    ans = []
    for h in range(H):
        a = list(map(int, input().split()))
        A.append(a)
    for y in range(H):
        for x in range(W):
            if A[y][x] % 2 == 1:
                if x <= W-2:
                    A[y][x] -= 1
                    A[y][x+1] += 1
                    ans.append((y+1, x+1, y+1, x+2))
                elif y <= H-2:
                    A[y][x] -= 1
                    A[y+1][x] += 1
                    ans.append((y+1, x+1, y+2, x+1))
    print(len(ans))
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main()


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

int enzan(int num1,int num2,int clc){
  int numa[4];
  int numb[4];
  int ans[4];
  lp(i,4){
    numa[i]=0;
    numb[i]=0;
  }
  if(num1>=8){
    numa[0]=1;
    num1-=8;
  }
  if(num1>=4){
    numa[1]=1;
    num1-=4;
  }
  if(num1>=2){
    numa[2]=1;
    num1-=2;
  }
  if(num1>=1){
    numa[3]=1;
    num1-=1;
  }
  if(num2>=8){
    numb[0]=1;
    num2-=8;
  }
  if(num2>=4){
    numb[1]=1;
    num2-=4;
  }
  if(num2>=2){
    numb[2]=1;
    num2-=2;
  }
  if(num2>=1){
    numb[3]=1;
    num2-=1;
  }
  //  lp(i,4){
  //  cout<<numa[i];
  //}
  //cout<<endl;
  //lp(i,4){
  //  cout<<numb[i];
  //}
  //cout<<endl;

  lp(i,4){
    if(clc==1){
      if(numa[i]==1&&numb[i]==1) ans[i]=1;
      else ans[i]=0;
    }
    if(clc==2){
      if(numa[i]==numb[i]) ans[i]=0;
      else ans[i]=1;
    }
    if(clc==3){
      if(numa[i]==0&&numb[i]==0) ans[i]=0;
      else ans[i]=1;
    }
  }
  return ans[0]*8+ans[1]*4+ans[2]*2+ans[3]*1;
}


int change(string calc){
  while(1){
    int num=0,ca=0;
    int memo[2];
    //int hoge;
    //cout<<calc<<endl;
    //cin>>hoge;
    if(calc.size()==1) break;
    for(int i=0;i<calc.size();i++){
      if(calc[i]=='['){
	num=0;
	ca=0;
      }
      if(calc[i]=='*') ca=1;
      if(calc[i]=='^') ca=2;
      if(calc[i]=='+') ca=3;
      if('0'<=calc[i]&&calc[i]<='9'){
	memo[num]=calc[i]-'0';
	num++;
      }
      if('a'<=calc[i]&&calc[i]<='z'){
	memo[num]=calc[i]-'a'+10;
	num++;
      }
      if(calc[i]==']'){
	if(num==1){
	  calc.erase(i,1);
	  calc.erase(i-2,1);
	  break;
	}
	else if(num==2){
	  int memori=enzan(memo[0],memo[1],ca);
	  if(memori<=9){
	    calc[i-1]=memori+'0';
	    calc.erase(i-2,1);
	    calc.erase(i-3,1);
	  }
	  else{
	    calc[i-1]=memori-10+'a';
	    calc.erase(i-2,1);
	    calc.erase(i-3,1);
	  }
	  break;
	}
      }
    }
  }
  if('a'<=calc[0]&&calc[0]<='z') return calc[0]-'a'+10;
  return calc[0]-'0';
}


int main(){
  while(1){
    string cast;
    cin>>cast;
    if(cast==".") break;
    int mez;
    cin>>mez;
    int xx[20];
    lp(i,20) xx[i]=0;
    int ansmemo;
    for(int i=0;i<10000;i++){
      string calc=cast;
      char a,b,c,d;
      a='0'+i/1000;
      b='0'+i%1000/100;
      c='0'+i%100/10;
      d='0'+i%10;
      lp(j,calc.size()){
	if(calc[j]=='a'){
	  calc[j]=a;
	}
	if(calc[j]=='b'){
	  calc[j]=b;
	}
	if(calc[j]=='c'){
	  calc[j]=c;
	}
	if(calc[j]=='d'){
	  calc[j]=d;
	}
      }
      int mems=change(calc);
      if(mez==i) ansmemo=mems;
      xx[mems]++;
    }
    cout<<ansmemo<<" "<<xx[ansmemo]<<endl;
  }
  return 0;
}
	 


Measured memory_bytes: 3100
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

const int N = 200000 + 7, C = 31;

int n;
char s[N];
int nxt[N][C], dp[N], frm[N];

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for (int j = 0; j < 26; ++j)
		nxt[n + 1][j] = n + 1;
		
	dp[n + 1] = 1;
	for (int i = n; i; --i) {
		dp[i] = 1 << 29;
		for (int j = 25; j >= 0; --j) {
			nxt[i][j] = s[i] == 'a' + j ? i : nxt[i + 1][j];
			if (dp[nxt[i][j] + 1] < dp[i])
				dp[i] = dp[nxt[i][j] + 1],
				frm[i] = j;
		}
		++dp[i];
	}
	
	for (int i = 1, j; i <= n; i = nxt[i][j] + 1)
		for (j = 0; j < 26; ++j)
			if (dp[i] == dp[nxt[i][j] + 1] + 1) {
				printf("%c", 'a' + j);
				break;
			}

	return 0;
}


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

int i=0,j=0;
string buffer="";
vector<string> vec;

void p(void){
	if(i > 0){
		i--;
	}
	j = 0;
}

void n(void){
	if(i < vec.size() - 1){
		i++;
	}
	j = 0;
}

void f(void){
	if(j < vec.at(i).length()){
		j++;
	}
	else if(j == vec.at(i).length() && i < vec.size() - 1){
		i++;
		j = 0;
	}
}

void b(void){
	if(j > 0){
		j--;
	}
	else if(j == 0 && i > 0){
		i--;
		j = vec.at(i).length();
	}
}

void d(void){
	string s = vec.at(i);

	if(j < vec.at(i).length()){
		s.erase(s.begin() + j);
	}
	else if(j == vec.at(i).length() && i < vec.size() - 1){
		s += vec.at(i + 1);
		vec.erase(vec.begin() + i);
	}
	vec.erase(vec.begin() + i);
	vec.insert(vec.begin() + i, s);
}

void k(void){
	if(j == vec.at(i).length() && i < vec.size() - 1){
		d();
		buffer = "\n";
	}
	else if(j < vec.at(i).length()){
		string s = vec.at(i);

		buffer = s.substr(j);
		s.erase(s.begin()+j,s.end());
		vec.erase(vec.begin() + i);
		vec.insert(vec.begin() + i, s);
	}
}

void y(void){
	string s = vec.at(i);

	if(buffer == "\n"){
		vec.insert(vec.begin()+i+1,s.substr(j));
		s.erase(s.begin()+j,s.end());
		vec.erase(vec.begin()+i);
		vec.insert(vec.begin()+i,s);
		i++;
		j = 0;
	}
	else if(buffer != ""){
		s.insert(j,buffer);
		j += buffer.length();
		vec.erase(vec.begin()+i);
		vec.insert(vec.begin()+i,s);
	}
}

int main(void){
	string s;

	while(getline(cin,s) && s!="END_OF_TEXT"){
		vec.push_back(s);
	}
	while(cin>>s && s!="-"){
		switch(s.at(0)){
		case 'a': j=0; break;
		case 'e': j=vec.at(i).length(); break;
		case 'p': p(); break;
		case 'n': n(); break;
		case 'f': f(); break;
		case 'b': b(); break;
		case 'd': d(); break;
		case 'k': k(); break;
		case 'y': y(); break;
		}
	}
	for(int i=0;i<vec.size();i++){
		cout<<vec.at(i)<<endl;
	}

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define N 100005
int n,a[N*2],b[N*2],l=1e9,r,g;
int chk(int x)
{
    for(int i=1;i<=n*2-1;i++) b[i]=(a[i]>=x)?1:0;b[0]=b[n*2]=2;
    for(int i=0;i<n;i++)
    {
        if((b[n-i]==b[n-i-1]&&b[n-i]==0)||(b[n+i]==b[n+i+1]&&b[n+i]==0)) return 0;
        if((b[n-i]==b[n-i-1]&&b[n-i]==1)||(b[n+i]==b[n+i+1]&&b[n+i]==1)) return 1;
    }
    return b[1];
}
int main()
{
    scanf("%d",&n);for(int i=1;i<=2*n-1;i++) scanf("%d",&a[i]),l=min(l,a[i]),r=max(r,a[i]);
    for(int mid=(l+r)>>1;l<=r;mid=(l+r)>>1) if(chk(mid)) l=mid+1,g=mid;else r=mid-1;
    printf("%d\n",g);
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	s = "0" + s;
	const int n = s.size() - 1;
	if(s[n] != '0' || s[1] != '1'){
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < n; ++i){
		if(s[i] != s[n - i]){
			cout << -1 << endl;
			return 0;
		}
	}
	vector<int> parents(n, -1);
	vector<int> pending;
	for(int i = 0; i < n; ++i){
		if(s[i + 1] != '0' || i + 1 == n){
			for(const auto v : pending){ parents[v] = i; }
			pending.clear();
		}
		pending.push_back(i);
	}
	for(int i = 0; i + 1 < n; ++i){
		cout << i + 1 << " " << parents[i] + 1 << endl;
	}
	return 0;
}



Measured memory_bytes: 2408
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll h; cin>>h;
	ll n; cin>>n;
	vector<ll> a(n);
	vector<ll> b(n);
	REP(i,n) {
		cin>>a[i];
		cin>>b[i];
	}
	vector<ll> m(h+1,INF);
	m[0]=0;
	REP(j,n){
		FOR(k,1,a[j]+1){
			if(k>h)break;
			m[k]=min(m[k],b[j]);
		}
	}
	//cout << "m: "; REP(i,(signed)m.size()) cout<<m[i]<<" "; cout << endl; //----------cout----------//
	REP(i,h){
		FOR(j,1,h){
			if(j+i>h)break;
			m[j+i]=min(m[j+i],m[i]+m[j]);
		}
		//cout << "m: "; REP(i,(signed)m.size()) cout<<m[i]<<" "; cout << endl; //----------cout----------//
	}
	cout<<m[h]<<endl;
	return 0;
}

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

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<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



string S;

int main() {
    while (cin >> S) {
        istringstream sin(S);
        int num;
        sin >> num;

        int zen = num / 100;
        int kou = num % 100;

        bool YYMM = (kou >= 1 && kou <= 12);
        bool MMYY = (zen >= 1 && zen <= 12);
        if (YYMM && MMYY) puts("AMBIGUOUS");
        else if (YYMM) puts("YYMM");
        else if (MMYY) puts("MMYY");
        else puts("NA");
    }
}













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

using namespace std;
typedef  long long ll;

#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
const int maxn=1e6+5;
const int mod=1e9+7;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a*500>=b)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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


#define mx 100005
#define ll long long 

void IO()
{
  #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  #endif
}


int ar[mx];
char ch[mx];
int m,n,k,ii;

void solve()
{
   string s;
   cin>>s;
   
   	  if(s.back()=='s')cout<<s<<"es\n";
   
   else
   {
     cout<<s<<"s\n";
   }
}

int main()
{
   IO();
  int t=1;
  //scanf("%d",&t);
  while(t--)
  {
    solve();
  }
  return 0;
}

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}

//--------------------------------------------------//

int main() {
  use_cio();
  int n, x;
  ll sum = 0;
  cin >> n >> x;
  rep(i, n) {
    int l;
    cin >> l;
    sum += l;
    if (sum > x) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << n + 1 << endl;
}


Measured memory_bytes: 256
#define N 100
#define INF 10000000
#define WHITE 0
#define BLACK 1

typedef struct {
  int v[N]; //neibor u
  int c[N]; //both u and vi connect and weight
  int k,d,pi,color;
}G;

int n; //vertex

G g[N];

void dijkstra();

  int main()
{
  int i,j,u,vertex,cost;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    
    scanf("%d%d",&u,&g[i].k);

    for(j=0;j<g[i].k; j++) {

      scanf("%d%d",&vertex,&cost);
      g[u].v[j]=vertex; g[u].c[j] = cost;
    }
  }

  dijkstra();

  for(i=0;i<n;i++){
    printf("%d %d\n",i,g[i].d);
  }
  return 0;
}
 
void dijkstra()
{
  int i,j,u,mincost;

  for(i=0; i<n; i++){
    g[i].d = INF;
    g[i].pi = -1;
    g[i].color = WHITE;
  }

  g[0].d = 0;

  while(1) {

    mincost = INF;

    for(i=0;i<n;i++) {

      if(g[i].color != BLACK && g[i].d < mincost) {

	  mincost = g[i].d;
	  u = i;
      }
    }

    if(mincost == INF) break;

    g[u].color = BLACK;

    for(i=0; i<g[u].k;i++) {

      j = g[u].v[i];
      if(g[j].color != BLACK && g[u].c[i] + g[u].d < g[j].d) {
	g[j].pi = u;
	g[j].d = g[u].c[i] + g[u].d;

      }
    }
  }
}

Measured memory_bytes: 680
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ms(a,x) memset(a,x,sizeof(a))
const int Max=1000000+10;
int main()
{
    int n,m;
    cin>>n>>m;
    int sum=min(n,m);
    cin>>n>>m;
    sum+=min(n,m);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
struct mint{
	ull v;
	mint(ll vv=0){s(vv%mod+mod);}
	mint& s(ull vv){
		v=vv<mod?vv:vv-mod;
		return *this;
	}
	mint operator-()const{return mint()-*this;}
	mint& operator+=(const mint&rhs){return s(v+rhs.v);}
	mint&operator-=(const mint&rhs){return s(v+mod-rhs.v);}
	mint&operator*=(const mint&rhs){
		v=ull(v)*rhs.v%mod;
		return *this;
	}
	mint&operator/=(const mint&rhs){return *this*=rhs.inv();}
	mint operator+(const mint&rhs)const{return mint(*this)+=rhs;}
	mint operator-(const mint&rhs)const{return mint(*this)-=rhs;}
	mint operator*(const mint&rhs)const{return mint(*this)*=rhs;}
	mint operator/(const mint&rhs)const{return mint(*this)/=rhs;}
	mint pow(int n)const{
		mint res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	mint inv()const{return pow(mod-2);}
	/* mint inv()const{
		int x,y;
		int g=extgcd(v,mod,x,y);
		assert(g==1);
		if(x<0)x+=mod;
		return mint(x);
    }*/
	friend ostream& operator<<(ostream&os,const mint&m){
		return os<<m.v;
	}
	bool operator<(const mint&r)const{return v<r.v;}
	bool operator==(const mint&r)const{return v==r.v;}
};
mint dp[1000005][2];//1:Lと一致, 2:L未満
int main(){
    dp[0][0]=1;
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++){
       // {a+b==0
        if(s[i]=='0'){
            dp[i+1][0]+=dp[i][0];
            dp[i+1][1]+=dp[i][1];
        }
        else{
            dp[i+1][1]+=(dp[i][0]+dp[i][1]);
        }
        //}
        //{a+b==1
          if(s[i]=='0'){
            dp[i+1][1]+=dp[i][1]*2;
        }
        else{
            dp[i+1][0]+=dp[i][0]*2;
            dp[i+1][1]+=dp[i][1]*2;
        }
       //}
    }
    mint ans=dp[n][0]+dp[n][1];
    cout<<ans<<endl;
}

Measured memory_bytes: 16128
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 3e5;
int a[maxn], b[maxn];
signed main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
    	cin >> a[i];
    	b[i] = a[i];
    }
    sort(b, b + n);
    for(int i = 0; i < n; ++i) {
    	if(a[i] == b[n - 1]) {
    		cout << b[n - 2] << endl;
    	} else {
    		cout << b[n - 1] << endl;
    	}
    }
    return 0;
}


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

#define MAX 200000 

bool prime_table[MAX];
int head;

int main(){
	int n, i, j;
	int result;
	// make table
	for (i = 0; i < MAX; i++) {
		if(i==0||i==1){
			prime_table[i] = false;
		}else{
			prime_table[i] = true;
		}
	}
	// find prime
	for (i = 2; i < MAX; i++) {
		if(prime_table[i]){
			for (j = i+i; j < MAX; j+=i) {
				prime_table[j] = false;
			}
		}
	}
	
	while(cin >> n){
		if (n == 0) {
			break;
		}
		result = 0;
		j = 0;
		for (i = 0; i <= MAX; i++) {
			if(prime_table[i]){
				result += i;
				j++;
				if (j == n) {
					break;
				}
			}
		}
		cout << result << endl;
	}
	return 0;
}

Measured memory_bytes: 0
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   A : Integer;
   B : Integer;
   C : Integer;
   Ans : Integer;
begin
   Get (A);
   Get (B);
   Get (C);
   Ans := B/A;
   if Ans > C then
      Ans := C;
   end if;
   Put_Line (Integer'Image (Ans));
end Solve;

Measured memory_bytes: 3672
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int a = array[0];
			int b = array[1];
			for (var i = 1; i <= 3; ++i) {
				if ((a * b * i) % 2 == 1) {
					Console.WriteLine("Yes");

					Console.ReadKey();
					return;
				}
			}

			Console.WriteLine("No");

			//Console.WriteLine($"{answer}");
			Console.ReadKey();
		}
	}
}

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)(n); i++)
#define Loop1(i, n) for(int i = 1; i <= (int)(n); i++)
#define Loopr(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; }
bool inrange(int x, int t) { return x >= 0 && x < t; }
bool inrange(vi xs, int t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

/*******************************************************/

int main() {
	ll a, b; cin >> a >> b;
	if (a <= 0 && 0 <= b) {
		cout << "Zero" << endl;
	}
	else if (0 < a) {
		cout << "Positive" << endl;
	}
	else {
		if ((b - a + 1) % 2 == 0) {
			cout << "Positive" << endl;
		}
		else {
			cout << "Negative" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int x, a;
	cin >> x >> a;
	if (x < a) cout << 0 << endl;
	else cout << 10 << endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {

  val n = scala.io.StdIn.readInt()
  val s = scala.io.StdIn.readLine()

  def solve(): Long = {
    var cnt = 0
    (0 to 999).foreach { i =>
      val numSeq: Seq[Int] = Seq(i / 100, (i / 10) % 10, i % 10)
      val lastIndex = numSeq.length - 1
      var numIndex = 0

      val sLength = s.length
      var j = 0
      while(j < sLength) {
        if(s(j).toString == numSeq(numIndex).toString) {
          numIndex += 1
          if(numIndex == lastIndex + 1)  j = sLength // break loop
        }
        j += 1
      }
      if(numIndex == lastIndex + 1) cnt += 1
    }
    cnt
  }
  println(solve)

}


Measured memory_bytes: 114272
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )

int A[3];
int main() {
    cin >> A[0] >> A[1] >> A[2];
    std::sort(A, A+3);
    int c = (A[1] - A[0]) / 2;
    if ((A[1] - A[0]) % 2) {
        c++;
        A[2] += 1;
    }
    cout << c + (A[2] - A[1]) << endl;
}

Measured memory_bytes: 888
#include<stdio.h>
#include<math.h>

typedef struct{ double x, y; }point;

void koch(int n, point a, point b)
{
    if( n == 0 ) return;
    point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}

int main()
{
    point a, b;
    int n;

    scanf("%d", &n);

    a.x = a.y = b.y = 0;
    b.x = 100;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);

    return 0;
}

Measured memory_bytes: 1848
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 60


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N, M = lmi()
ABC = llmi(M)


class BellmanFord:
    def __init__(self, n, start=0):
        self.n = n
        self.cost = [INF] * n
        self.cost[start] = 0
        self.edge = dict()

    def add_edge(self, _from, _to, _cost):
        self.edge[(_from, _to)] = _cost

    def fill_cost(self, check=False):
        negative_loops = set()
        for i in range(self.n):
            for (_from, _to), _cost in self.edge.items():
                if self.cost[_from] != INF and self.cost[_to] > self.cost[_from] + _cost:
                    self.cost[_to] = self.cost[_from] + _cost
                    if check:
                        negative_loops.add(_to)
        return negative_loops


bf = BellmanFord(N)
for a, b, c in ABC:
    bf.add_edge(a - 1, b - 1, -c)
bf.fill_cost()
negative_loops = bf.fill_cost(check=True)
# print(negative_loops, bf.cost)
if N - 1 in negative_loops:
    print('inf')
else:
    print(-bf.cost[-1])


Measured memory_bytes: 4340
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
a = sorted(list(a))
ma = max(a)

div = defaultdict(bool)
count = 0
for i in range(n):
    b = a[i]
    if div[b]:
        count += 1
    else:
        for j in range(1,ma//b+1):
            div[j*b] = True
        if(i+1<n and a[i] == a[i+1]):
            count += 1

print(n-count)

Measured memory_bytes: 170204
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define clr(x,y) memset(x,y,sizeof(x))
#define in(a) a=read()
#define out(a) printf("%d\n",a)
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return x*f;
}
#define mod 1000000007
void MOD(int &x){if(x>=mod)x-=mod;}
#define inf (1<<30)
#define maxn 200010
ll a[maxn],b[maxn];
int n;
ll check(ll x){
	ll sum=0;
	FOR(i,1,n){
		ll c=x/b[i];
		if(c<=a[i])sum+=a[i]-c;
	}
	return sum;
}
int main(){
	ll k;
	in(n);in(k);
	FOR(i,1,n)in(a[i]);
	sort(a+1,a+n+1);
	FOR(i,1,n)in(b[i]);
	sort(b+1,b+n+1);reverse(b+1,b+n+1);
	ll l=-1,r=1e12;
	while(l+1<r){
		ll mid=(l+r)/2;
		ll x=check(mid);
		if(x<=k)r=mid;
		else l=mid;
	}
	cout<<r<<endl;
	
}

Measured memory_bytes: 3328
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

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

int main(){
  ll n;
  cin >> n;
  vector<ll> A(n);
  rep(i,n)cin >> A[i];
  sort(A.begin(),A.end());
  ll cnt = 0;
  rep(i,n-1)if(A[i] == A[i+1])cnt++;
  if(cnt==0)cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 4836
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

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

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

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

int d(long long int N)
{
    int count = 0;

    while (N > 0)
    {
        N /= 10;
        count++;
    }

    return count;
}

double rad2(double x)
{
    return x * (M_PI / 180);
}

int kaibun(char S[], int n)
{
    for (int i = 0; i < n / 2; i++)
    {
        if (S[i] != S[n - i - 1])
            return 0;
    }
    return 1;
}

int main()
{
    int A, B;

    scanf("%d%d", &A,&B);

    printf("%d", A * B);
}

Measured memory_bytes: 3800
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

int arr[2010];
long long dp[2010][2010];

long long tabs(int a, int b) {
    if (a > b) return a - b;
    return b - a;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<pair<int, int>> positions;
    for (int i = 0; i < N; ++i) {
        cin >> arr[i];
        positions.emplace_back(arr[i], i);
    }
    sort(positions.begin(), positions.end());
    reverse(positions.begin(), positions.end());

    for (int i = 0; i < N; ++i) {
        pair<int, int>& p = positions[i];
        int A = p.first;
        int pos = p.second;
        for (int j = 0; j <= i; ++j) {
            dp[j + 1][N - i - 1] = max(dp[j][N - i] + A * tabs(pos, j), dp[j + 1][N - i - 1]);
            dp[j][N - i - 1] = max(dp[j][N - i] + A * tabs(pos, j + N - i - 1), dp[j][N - i - 1]);
            // cerr << "dp[" << j + 1 << "][" << N - i - 1 << "] = " << dp[j + 1][N - i - 1] << endl;
            // cerr << "dp[" << j << "][" << N - i - 1 << "] = " << dp[j][N - i - 1] << endl;
        }
    }
    long long res = 0;
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            if (res < dp[i][j]) res = dp[i][j];
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 26316
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll modinv(ll n)    { ll ans=powm(n,mod-2); return ans; }
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

int main()
{
	fast
	ll n,k;
	cin>>n>>k;

	ll a[n+1];
	forn(i,1,n+1)
	{
		cin>>a[i];
	}

	ll dp[n+1][k+1];
	ll pref[n+1][k+1];
	reset(dp,0);
	reset(pref,0);

	forn(i,0,a[1]+1)
	{
		dp[1][i]=1;
	}

	forn(i,0,k+1)
	{
		if(i==0)
			pref[1][i]=1;
		else
			pref[1][i]=add(pref[1][i-1],dp[1][i]);
	}

	forn(i,2,n+1)
	{
		forn(j,0,k+1)
		{
			if(j-a[i]-1>=0)
			{
				dp[i][j]=add(dp[i][j],sub(pref[i-1][j],pref[i-1][j-a[i]-1]));
			}
			else
				dp[i][j]=add(dp[i][j],pref[i-1][j]);
		}

		forn(j,0,k+1)
		{
			if(j==0)
				pref[i][j]=dp[i][j];
			else
				pref[i][j]=add(pref[i][j-1],dp[i][j]);	
		}
	}

	cout<<dp[n][k];
    
	return 0;
}

Measured memory_bytes: 158080
#include<stdio.h>
#include<string.h>
#include<math.h>

int main(void){
  int x[5],cou;
  for(int i=0;i<5;i++){
    scanf("%d",&x[i]);
    if(x[i]==0){
      cou=i;
    }
  }
  printf("%d",cou+1);

   return 0;
}


Measured memory_bytes: 1684
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)

int n,ma,mb;
int a[50], b[50], c[50];
int dp[50][400][400];

const int inf = 10000000;
const int W = 410;
const int nmax=40, abmax=10;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin>>n>>ma>>mb;
  FOR(i,0,n) {
    cin>>a[i]>>b[i]>>c[i];
  }
  FOR(i,0,n+1) {
    FOR(ca,0,nmax*abmax+1) {
      FOR(cb,0,nmax*abmax+1) {
        dp[i][ca][cb] = inf;
      }
    }
  }

  dp[0][0][0] = 0;
  FOR(i,0,n) {
    FOR(ca,0,nmax*abmax+1) {
      FOR(cb,0,nmax*abmax+1) {
        if (dp[i][ca][cb]==inf) continue;
        dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb]);
        dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]],
                                        dp[i][ca][cb]+c[i]);
      }
    }
  }

  int ans=inf;
  FOR(ca,1,nmax*abmax+1) {
    FOR(cb,1,nmax*abmax+1) {
      if (ca*mb == cb*ma) {
        ans = min(ans, dp[n][ca][cb]);
      }
    }
  }

  cout << (ans==inf?-1:ans) << endl;
}


Measured memory_bytes: 26880
class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]


def main():
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for i in range(m):
        a, b = map(int, input().split())
        uf.unite(a, b)
        
    ans = 0
    
    for i in range(1, n+1):
        ans = max(ans, uf.size(i))
    
    print(ans)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 13612
import java.util.*;
public class Main{
	private static int h, w, cnt;
	private int[] ColumnCheck(char c[]){
		int a[] = new int[w];
		for(int i = 0;i < w;i++){
			if(c[i] == 'c') cnt = 0;
			else if(cnt >= 0) cnt++;
			a[i] = cnt;
		}
		return a;
	}
	private void print(int a[][]){
		for(int i = 0;i < h;i++){
			for(int k = 0;k < w;k++){
				if(k != w - 1) System.out.print(a[i][k] + " ");
				else System.out.println(a[i][k]);
			}
		}
	}
	private void doIt(){
		Main main = new Main();
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		int a[][] = new int[h][w];
		char c[][] = new char[h][w];
		for(int i = 0;i < h;i++){
			cnt = -1;
			c[i] = sc.next().toCharArray();
			a[i] = ColumnCheck(c[i]);
		}
		print(a);
	}
	public static void main(String args[]){
		new Main().doIt();
	}
}

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

using namespace std;

const int Nmax = 1e5 + 5;

int n, m, dif[Nmax];
bool special[Nmax];
char S[Nmax];

vector<int> v[Nmax];
bool used[Nmax];

void add_edge(int x, int y)
{
    if(x == y) return;
    v[x].push_back(y);
    v[y].push_back(x);
}

void dfs(int node, bool &ok, int &sum)
{
    used[node] = 1;
    ok |= special[node];
    sum += dif[node];

    for(auto it : v[node])
        if(!used[it])
            dfs(it, ok, sum);

}

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> (S+1);
    n = strlen(S+1);
    cin >> m;

    int i;

    for(i=1; i<n; ++i)
        if(i <= n/2) dif[i] += (int)S[i] - (int)S[i+1];
            else dif[n - i] += (int)S[i] - (int)S[i+1];

    for(i=1; i<=m; ++i)
    {
        int x, y;
        cin >> x >> y;
        --x;

        if(x > n/2) x = n - x;
        if(y > n/2) y = n - y;

        if(x && y) add_edge(x, y);
            else if(y) special[y] = 1;
                else if(x) special[x] = 1;
    }

    for(i=1; i<=n/2; ++i)
        if(!used[i])
        {
            bool ok = 0;
            int sum = 0;
            dfs(i, ok, sum);

            if(!ok && sum%26!=0)
            {
                cout << "NO\n";
                return 0;
            }
        }

    cout << "YES\n";

    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int main(){
  int n, h[100000];cin>>n;rep(i,n)cin>>h[i];
  int dp[100000];dp[0] = 0;dp[1] = abs(h[0] - h[1]);dp[2] = abs(h[0] - h[2]);
  repd(i,3,n){
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n-1] << endl;
}



Measured memory_bytes: 1024
using System;

namespace abc166
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var k = int.Parse(nm[1]);
            var sunukes = new bool[n];
            for (var i = 0; i < k; ++i)
            {
                Console.ReadLine();
                var nStrList = Console.ReadLine().Split(' ');
                foreach (var nStr in nStrList)
                {
                    sunukes[int.Parse(nStr) - 1] = true;
                }
            }
            var itazura = 0;
            for (var i = 0; i < n; ++i)
            {
                if (!sunukes[i])
                {
                    ++itazura;
                }
            }
            Console.WriteLine(itazura);
        }
    }
}


Measured memory_bytes: 27720
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

ll n,ans;

ll f(ll x) {
	return (x+1)*x>>1;
}

int main() {
	qr(n); 
	ans=f(n)+15*f(n/15)-3*f(n/3)-5*f(n/5);
	pr2(ans);
	return 0;
}



Measured memory_bytes: 3624