akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
#define minimize(var, val) (var = min((val), var))
long long MOD = 1e9 + 7;

class Tree {
   public:
    struct Node {
        int index;
        vector<Node*> adjacent;
        Node* parent = nullptr;
        long long start_time = 0, end_time = 0;
        ll dp_subtree = 1, dp_supertree = 1;
    };

    vector<Node> list;
    Node* root = nullptr;

    explicit Tree(int n) {
        list = vector<Node>(n);
        for (int i = 0; i < n; i++)
            list[i].index = i;
        root = &list[0];
    }
    void add_edge(int x, int y) {
        assert(x < list.size() && y < list.size());
        list[x].adjacent.push_back(&list[y]);
        list[y].adjacent.push_back(&list[x]);
    }
    int __build(Node* root = nullptr, int time = 0) {
        if (root == nullptr)
            root = this->root;
        root->start_time = time;
        for (auto child : root->adjacent) {
            if (child == root->parent)
                continue;
            child->parent = root;
            time = __build(child, time + 1);
        }
        root->end_time = time;
        return time;
    }
};

// Return ways with black root in subtree
ll dp_sub(Tree::Node* root) {
    root->dp_subtree = 1;
    for (auto child : root->adjacent) {
        if (child == root->parent)
            continue;
        root->dp_subtree = (root->dp_subtree * (dp_sub(child) + 1)) % MOD;
    }
    return root->dp_subtree;
}

// Propagates number of ways to children
void dp_sup(Tree::Node* root) {
    ll ways_in_prefix = 1, ways_in_suffix = 1, n = root->adjacent.size();
    for (int i = 0; i < n; i++) {
        if (root->adjacent[i] == root->parent)
            continue;
        root->adjacent[i]->dp_supertree =
            (root->adjacent[i]->dp_supertree * ways_in_prefix) % MOD;
        ways_in_prefix =
            (ways_in_prefix * (root->adjacent[i]->dp_subtree + 1)) % MOD;
    }
    for (int j = n - 1; j >= 0; j--) {
        if (root->adjacent[j] == root->parent)
            continue;
        root->adjacent[j]->dp_supertree =
            (root->adjacent[j]->dp_supertree * ways_in_suffix) % MOD;
        ways_in_suffix =
            (ways_in_suffix * (root->adjacent[j]->dp_subtree + 1)) % MOD;
    }
    for (auto child : root->adjacent) {
        if (child == root->parent)
            continue;
        child->dp_supertree =
            (child->dp_supertree * root->dp_supertree + 1) % MOD;
        dp_sup(child);
    }
}

int main() {
    int n;
    cin >> n >> MOD;
    // Build a Tree from the input
    Tree tree(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        tree.add_edge(u - 1, v - 1);
    }
    tree.__build();
    // Call DP and output
    dp_sub(tree.root);
    dp_sup(tree.root);
    for (int i = 0; i < n; i++)
        cout << (tree.list[i].dp_subtree * tree.list[i].dp_supertree) % MOD
             << endl;
}

Measured memory_bytes: 14720
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2 == 0)
    cout << a - b << endl;
  else
    cout << b - a << endl;
  return 0;
}


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

const int N = 1e5 + 10;
vector<int> to[N];

int n , m , q;
int color[N] , deep[N];

struct Node{int v , d , c;};
Node op[N];

void BFS(Node x)
{
	queue<Node> q;
	q.push(x);
	while(!q.empty())
	{
		Node now = q.front();
		q.pop();
		int &x = now.v;
		if(now.d <= deep[x])	continue;
		deep[x] = now.d;
		if(color[x] == -1) color[x] = now.c;
		for(auto i:to[x])	q.push((Node) {i , now.d - 1 , now.c});
	}
}

int main()
{
	scanf("%d %d" , &n , &m);
	while(m--)
	{
		int u , v;
		scanf("%d %d" , &u , &v);
		to[u].push_back(v) , to[v].push_back(u);
	}
	scanf("%d" , &q);
	for(int i = 1 ; i <= q ; i ++)
		scanf("%d %d %d" , &op[i].v , &op[i].d , &op[i].c);
	memset(deep , 255 , sizeof(deep));
	memset(color , 255 , sizeof(color));
	for(int i = q ; i ; i --) BFS(op[i]);
	for(int i = 1 ; i <= n ; i ++)
		printf("%d\n" , max(color[i] , 0));
}

Measured memory_bytes: 9336
#include "bits/stdc++.h"
using namespace std;
typedef long long int Int;
int N;
char s[100001];
int ans[100010];
bool check(int t0,int t1) {
	ans[0]=t0;
	ans[1]=t1;
	for(int i=1;i<N;i++) {
		if(ans[i]) {
			if(s[i]=='o') ans[i+1]=ans[i-1];
			else ans[i+1]=!(ans[i-1]);
		}else {
			if(s[i]=='x') ans[i+1]=(ans[i-1]);
			else ans[i+1]=!(ans[i-1]);
		}
	}
	if(ans[N]!=ans[0]) return 0;
	if(ans[0]) {
		if(s[0]=='o'&&(ans[1]==ans[N-1])) return 1;
		if(s[0]=='x'&&(ans[1]!=ans[N-1])) return 1;
	}else {
		if(s[0]=='o'&&(ans[1]!=ans[N-1])) return 1;
		if(s[0]=='x'&&(ans[1]==ans[N-1])) return 1;
	}
	return 0;
}
int main() {
	scanf("%d",&N);
	scanf("%s",s);
	for(int i=0;i<=1;i++) {
		for(int j=0;j<=1;j++) {
			if(check(i,j)) {
				for(int k=0;k<N;k++) {
					if(ans[k]) putchar('S'); else putchar('W');
				}
				putchar('\n');
				return 0;
			}
		}
	}
	printf("-1\n");
}

Measured memory_bytes: 768
import collections
N = int(input())
if N < 2:
  print(0)
  exit()

def fact(n):  # O(√N)で素因数のリストを作成　n >= 2

  arr = []
  temp = n

  for i in range(2, int(n**(1/2))+1):
    if temp % i == 0:
      while temp % i == 0:
        temp //= i
        arr.append(i)

  if temp != 1:
    arr.append(temp)

  return collections.Counter(arr)

c = fact(N).most_common()

ans = 0
for i in range(len(c)):
  for j in range(1, 1000):
    if  j*(j-1)//2 <= c[i][1] < j*(j+1)//2:
      ans += j-1
      
print(ans)

Measured memory_bytes: 9720
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;
const int mod = 1000000007;

int main() {

  string N;
  cin>>N;
  //vector<int> A(N);
  //for(int i=0; i<N; i++){cin>>A[i];}
  //vector<vector<int>> A(N,vector<int>(M));
  //for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  if(N[3]==N[2] && N[4]==N[5])cout<<"Yes"<<endl; 
else cout << "No" << endl;
}


Measured memory_bytes: 256
import heapq
import math

n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
heapq.heapify(q)

for i in range(n):
    heapq.heappush(q, -a[i])

for _ in range(m):
    b = heapq.heappop(q) / 2
    heapq.heappush(q, math.ceil(b))

print(sum(q) * -1)


Measured memory_bytes: 14532
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll  = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<T> ReadVec1(int N) {
    vector<T> vec(N);
    for(int i = 0; i < N; i++)
        vec[i] = In<T>();
    return move(vec);
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(j, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}


int main() {
    int N = In<int>();
    auto A = ReadVec1<ll>(N);
    ll X = 0;
    for(int i = 0; i < N; i++) {
        X += A[i] * (i % 2 == 0 ? 1 : -1);
    }
    cout << X;
    for(int i = 0; i < N-1; i++) {
        X = 2 * A[i] - X;
        cout << " " << X ;
    }
    cout << endl;
}

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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n, q;
  string s;
  cin >> n >> s >> q;

  set<int> a[26];
  rep(i, n) { a[s[i] - 'a'].insert(i); }

  rep(qn, q) {
    int type;
    cin >> type;
    if (type == 1) {
      int i;
      char c;
      cin >> i >> c;
      --i;
      if (s[i] == c) continue;
      a[s[i] - 'a'].erase(i);
      a[c - 'a'].insert(i);
      s[i] = c;
    } else {
      int l, r;
      cin >> l >> r;
      --l, --r;
      int ans = 0;
      rep(i, 26) {
        auto it = a[i].lower_bound(l);
        if (it == a[i].end()) continue;
        if (l <= *it && *it <= r) ++ans;
      }
      cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 24196
#include<stdio.h>

int main(void){
    int N,L,ans,i;
    ans = 0;

    scanf("%d%d",&N,&L);


    if(L < 0 && L + N - 1 >= 0){
        for(i = 1; L + i - 1 < 0; i++){
            ans += L + i - 1;
        }
        for(i = 2 - L; i <= N; i++){
            ans += L + i - 1;
        }
    }else if(L < 0 && L + N - 1 < 0){
        for(i=1; i <= N - 1; i++){
            ans += L + i - 1;
        }
    }else{
        for(i=2; i <= N ; i++){
            ans += L + i - 1;
        }
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 







int dp[200][200];
int x[100][100],y[100][100];
int main()
{
     int n;
     cin>>n;
     vector<int> a(n),b(n),c(n);
     for(int i=0;i<n;i++)cin>>a[i];
     rep(i,n)cin>>b[i];
     rep(i,n)cin>>c[i];
     sort(a.begin(),a.end());sort(b.begin(),b.end());
     sort(c.begin(),c.end());
     ll res=0LL;
     for(int i=0;i<n;i++){
          int t=b[i]-1;
          int id1=upper_bound(a.begin(),a.end(),t)-a.begin();
          int id2=upper_bound(c.begin(),c.end(),b[i])-c.begin();
          if(id1==0){continue;
          }
          int ct1=id1;
          int ct2=n-id2;
          res+=1LL*ct1*ct2;
         
     }
     cout<<res;
}


























Measured memory_bytes: 4564
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep (i, N)
    cin >> A[i];
  vector<int> B(N);
  rep (i, N)
    cin >> B[i];
  vector<int> C(N);
  rep (i, N)
    cin >> C[i];

  sort(all(A));
  sort(all(B));
  sort(all(C));

  vector<ll> AB(N); /* B[i]を使うときの(A,B)の組み合わせ数 */
  rep (i, N)
    AB[i] = lower_bound(all(A), B[i]) - A.begin();

  vector<ll> AB_sum(N); /* B[i]までを使うときの(A,B)の組み合わせ数 */
  AB_sum[0] = AB[0];
  repp (i, 1, N - 1)
    AB_sum[i] = AB_sum[i - 1] + AB[i];

  ll ans = 0;
  rep (i, N) {
    auto itr = lower_bound(all(B), C[i]);
    if (itr == B.begin())
      continue;
    auto itr_B = itr - 1 - B.begin();
    ans += AB_sum[itr_B];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2944
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const int MAX = 3500;

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

	for (int i = 1; i <= MAX; i++) {
		for (int j = 1; j <= MAX; j++) {
			ll a = 4 * i * j - n * (i + j);
			ll b = n * i * j;

			if (a > 0 && b % a == 0) {
				//cout << a << " " << b << endl;
				ll c = b / a;
				cout << i << " " << j << " " <<c << endl;
				//cout << (4 * c * i * j) / (j * c + c * i+i * j) << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3508
#include <iostream>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if ( a >= b && a >= c)
		cout << a * 10 + b + c;
	else if ( b >= a && b >= c)
		cout << b * 10 + a + c;
	else 
		cout << c * 10 + b + a;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=4e18;
const ll MOD=1e9+7;
const double EPS=1e-7;

ll H,W,D;
ll a[305][305];
vector<ll> costInMod[305*300];
unordered_map<ll,P> posMap;
int main(){
    cin>>H>>W>>D;
    for(ll i=0;i<H;i++){
        for(ll j=0;j<W;j++){
            ll a;
            cin>>a;
            posMap[a]=P(i,j);
        }
    }
    for(ll i=1;i<=D;i++){
        ll pre=0;
        costInMod[i].push_back(0);
        for(ll j=1;j*D+i<=H*W;j++){
            ll tmp = pre + abs(posMap[j*D+i].first -posMap[j*D+i-D].first)
                         + abs(posMap[j*D+i].second-posMap[j*D+i-D].second);
            costInMod[i].push_back(tmp);
            pre=tmp;
        }
    }
    ll Q;
    cin>>Q;
    for(ll i=0;i<Q;i++){
        ll l,r;
        cin>>l>>r;
        ll mod=(r%D==0?D:r%D);
        cout<<costInMod[mod][(r-mod)/D]-costInMod[mod][(l-mod)/D]<<endl;
    }
    return 0;
}

Measured memory_bytes: 10660
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();
        int a=sc.nextInt();int b=sc.nextInt();
        pw.println(Math.min(n*a,b));
        pw.flush();
    }
    
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21204
#include <iostream>

using namespace std;

int main(void) {
	int antennas[5];
	for (int i = 0; i < 5; i++) {
		cin >> antennas[i];
	}
	int k;
	cin >> k;

	int diff;
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 4; j++) {
			diff = (antennas[i] > antennas[j]) ? antennas[i] - antennas[j] : antennas[j] - antennas[i];
			if (diff > k) break;
		}
		if (diff > k) break;
	}

	if (diff > k) {
		cout << ":(" << endl;
	} else {
		cout << "Yay!" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;
	cin>>n>>k;
	ll c0=0,c1=0;
	for(ll i=1;i<=n;i++)
	{
		if(i%k==0)
			c0++;
		if(i%k==k/2)
			c1++;
	}
	if(k%2)
		c1=0;
	ll res =(c0*c0*c0+c1*c1*c1);
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        tmp = min(A[i], B[i])
        ans += tmp
        A[i] -= tmp
        B[i] -= tmp
        if B[i]:
            tmp2 = min(A[i+1], B[i])
            ans += tmp2
            A[i+1] -= tmp2
    print(ans)


if __name__ == "__main__":
    main()


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

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

  int64_t ans = 0;

  if(n==1){
    ans = 0;
  }else{
    for(int64_t i=0;i<n-1;i++){
      ans += i+1;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0; i<n; i++){ 
    cin >> a[i];
  }
  
  sort(a.begin(),a.end());
  
  int mini,maxm;
  mini=a[0];
  maxm=a[n-1];
  
  int Ans=10e6;
  for(int i=a[0]; i<=a[n-1]; i++){
    int x=i;
    int ans=0;
    for(int j=0; j<n; j++){
      ans+=pow(x-a[j],2);
    }
    Ans=min(Ans,ans);
  }
  
  cout << Ans << endl;
  
}



Measured memory_bytes: 256
N, K = map(int, input().split())

def sum_(a, b):
    if (a-b)%2 == 1:
        return int((b+a) * (b-a+1) / 2)
    else:
        return int((b+a) * (b-a+1) / 2)

ret = 0
for i in range(K, N+2):
    ret += sum_(N-i+1, N) - sum_(0, i-1) + 1

print(int(ret % (10**9 + 7)))


Measured memory_bytes: 9188
from collections import defaultdict
n, m = map(int, input().split())
order = []
dd = defaultdict(int)

for i in range(m):
    p, y = map(int, input().split())
    order.append([i, p, y])

# 全体を年代順にソート
order.sort(key=lambda x: (x[2]))
# print(order)

ans = ['']*m
for ii, pp, yy in order:
    dd[pp] += 1
    ans[ii] = '{:0>6}{:0>6}'.format(pp, dd[pp])

print('\n'.join(ans))


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

int main() {
  int N, L;
  cin >> N >> L;
  int count = N*(2*L-1+N)/2;
  if(0 <= L) {
    count = count - L;
  }
  else if(L+N-1 <= 0) {
    count = count - (L+N-1);
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
int m;
bool vis[N];
int res[N];
bool flag;
vector < pair < int , int > > a[N];
void dfs(int s , int p , int w) {
    vis[s] = true;
    res[s] = res[p] + w;
    for(auto j : a[s]) {
        int l = s;
        int r = j.first;
        int w = j.second;
        if(vis[r] == false) {
            dfs(r , s , w);
        }
        else {
            if(res[r] - res[l] != w) {
                flag = true;
                return ;
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 1 ; i <= m ; i++) {
        int u , v , w;
        cin >> u >> v >> w;
        a[u].emplace_back(make_pair(v , w));
        a[v].emplace_back(make_pair(u , -w));
    }
    if(m == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = 1 ; i <= n ; i++) {
        if(vis[i] == false) {
            flag = false;
            dfs(i , 0 , 0);
            if(flag) {
                cout << "No" << endl;
                return 0;
            }
        }
        else continue;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 14464
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
string S;
vector<int> p[10];
signed main(){
	cin >> N >> S;
	rep(i, N){
		p[S[i]-'0'].pb(i);
	}
	int ans = 0;
	rep(i, 1000){
		int idx = -1;
		auto itr = upper_bound(all(p[i/100]), idx);
		if(itr == p[i/100].end()) continue;
		idx = *itr;
		itr = upper_bound(all(p[(i/10)%10]), idx);
		if(itr == p[(i/10)%10].end()) continue;
		idx = *itr;
		itr = upper_bound(all(p[i%10]), idx);
		if(itr == p[i%10].end()) continue;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
using namespace std;
int main(){
    string S;
    cin >> S;

    int size = S.size();

    string X = "keyence";

    int d=0;
    int i=0;
    if(S == X){
        cout << "YES" <<endl;
        return 0;
    }
    
    if(S[0]=='k'){
        if(S[i]==X[d]){
            while(S[i]==X[d]){
                i++;
                d++;
            }

            if(X.substr(d,7-d)==S.substr(size-(7-d),7-d)){
                cout << "YES" <<endl;
                return 0;
            }
        }
    }
    

    if(S[0]!='k'){
        if(S.substr(size-7,7)=="keyence"){
            cout << "YES"  <<endl;
            return 0;
        }
    }

    if(S.substr(0,7)=="keyence"){
        cout << endl;
        return 0;
    }

    cout << "NO" <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	int c;
	int car[100];
	int out[100];
	
	i = c = 0;
	
	while (scanf("%d", &car[i]) != EOF){
		if(car[i] == 0){
			out[c] = car[i - 1];
			c++;
			i--;
			if (car[i - 1] != 0){
				i--;
			}
		}
		i++;
	}
	
	for (i = 0; i < c; i++){
		printf("%d\n", out[i]);
	}
	
	return (0);
}

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

namespace InfiniteCoins
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');

            var a = new int[N];

            for(int i = 0; i < N; i++)
            {
                a[i] = int.Parse(str[i]);
            }

            for(int i = 0; i < N; i++)
            {
                for (int j = 0; j < N - i-1; j++)
                {
                    if (a[N -j-1] > a[N -j - 2])
                    {
                        int t = a[N - j - 2];
                        a[N - j - 2] = a[N - j-1];
                        a[N - j-1] = t;
                    }
                }
            }

            int Asum = 0;
            int Bsum = 0;
            for(int i = 0; i < N; i++)
            {
                if (i % 2 == 0)
                {
                    Asum += a[i];
                }
                else if (i % 2 == 1)
                {
                    Bsum += a[i];
                }
            }

            Console.WriteLine(Asum - Bsum);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
int visit[10][10][10];

signed main(){
	int h,w;
	cin>>h>>w;
	int c[10][10];
	rep(i,10)rep(j,10)cin>>c[i][j];
	vector<vi> a(h,vi(w));
	rep(i,h){
		rep(j,w){
			cin>>a[i][j];
		}
	}

	vector<vi> dp(10,vi(10,INF));
	rep(i,10)rep(j,10)dp[i][j]=c[i][j];

	rep(k,10)rep(i,10)rep(j,10){
		chmin(dp[i][j],dp[i][k]+dp[k][j]);
	}

	int ans=0;
	rep(i,h)rep(j,w){
		if(a[i][j]==-1)continue;
		ans+=dp[a[i][j]][1];
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

template<typename T>
vector<T> bellman_ford(const vector<vector<pair<int, T>>> &graph, int root) {
  int n = graph.size();
  vector<T> dists(n, numeric_limits<T>::max());
  dists[root] = 0;
  for (int i = 0; i < n-1; ++i) {
    for (int j = 0; j < n; ++j) {
      if (dists[j] == numeric_limits<T>::max()) continue;
      for (auto e : graph[j]) {
        int nx; T cost;
        tie(nx, cost) = e;
        if (dists[nx] > dists[j] + cost) dists[nx] = dists[j] + cost;
      }
    }
  }
  queue<int> q;
  for (int i = 0; i < n; ++i) if (dists[i] != numeric_limits<T>::max()) q.push(i);
  while (!q.empty()) {
    int i = q.front(); q.pop();
    for (auto e : graph[i]) {
      int nx; T cost;
      tie(nx, cost) = e;
      if (dists[nx] == numeric_limits<T>::min()) continue;
      if (dists[i] == numeric_limits<T>::min() or dists[nx] > dists[i] + cost) {
        dists[nx] = numeric_limits<T>::min();
        q.push(nx);
      }
    }
  }
  return dists;
}

int main() {
  int n, m; cin>>n>>m;
  vector<vector<pair<int, long long>>> g(n);
  rep(i, m) {
    int a, b;
    long long c;
    cin>>a>>b>>c;
    --a; --b;
    g[a].emplace_back(b, -c);
  }
  auto dists = bellman_ford(g, 0);
  if (dists[n-1] == numeric_limits<long long>::min()) puts("inf");
  else print(-dists[n-1]);
  return 0;
}


Measured memory_bytes: 384
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for k in range(D)]
t = [int(input()) for k in range(D)]


ret = 0
last = [0]*26
for k in range(D):
    last[t[k]-1] = k+1
    ret += s[k][t[k]-1]
    for i in range(26):
        ret -= c[i]*(k+1-last[i])
    print(ret)


Measured memory_bytes: 73888
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    cout << "a ";
    if (a == b) cout << "==";
    if (a < b) cout << "<";
    if (a > b) cout << ">";
    cout << " b" << endl;
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<algorithm>
class kuohao{
    public:
    int must_have=0;
    int this_num=0;
    int countl=0;
    bool operator<(const kuohao& a){
        if(this->must_have>0&&a.must_have>0){
            if(this->this_num<0&&a.this_num<0){
                return this->countl>a.countl;
            }
            return this->this_num>a.this_num;
        }
        return (this->must_have)<(a.must_have);
    }
};
int main(){
    int n;
    std::cin>>n;
    std::string strs[n];
    kuohao k[n];
    for(int i=0;i<n;++i){
        std::cin>>strs[i];
    }
    for(int i=0;i<n;++i){
        int temp=strs[i].size(); 
        int count=0;
        int countl=0;
        int countMH=0;
        for(int j=0;j<temp;++j){
            if(strs[i][j]=='('){
                ++count;
                ++countl;
            }
            if(strs[i][j]==')'){
                --count;
                --countl;
            }
            if(count<countMH){
                ++(k[i].must_have);
                countMH=count;
                countl=0;
            }
        }
        k[i].this_num=count;
        k[i].countl=countl;
    }
    std::sort(k,k+n);
    int count=0;
    for(int i=0;i<n;++i){
        if(count>=k[i].must_have){
            count+=(k[i].this_num);
        }
        else{
            int j;
            for(j=i+1;j<n;++j){
                if(count>=k[j].must_have&&k[j].must_have!=-1){
                    if(k[j].this_num<0){
                        std::cout<<"No"<<std::endl;
                        return 0;
                    }
                    count+=(k[j].this_num);
                    k[j].must_have=-1;
                    k[j].this_num=0;
                    --i;
                    break;
                }
            }
            if(j>=n){
                std::cout<<"No"<<std::endl;
                return 0;
            }
        }
    }
    if(count==0){
        std::cout<<"Yes"<<std::endl;
    }
    else{
        std::cout<<"No"<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 46544
#include<stdio.h>
int min(int a, int b)
{
	if(a<b) return a;
	else return b;
}
int main()
{
	int c1=0, c2=1, d, t, s;
	char c;
	scanf("%c", &c);
	if(c=='1')
		s = 1;
	else
		s = 0;
	while(~scanf("%c", &c))
	{
		if(c==(48+s))
			c1++;
		else c2++;
		s = (s+1)%2;
	}
	printf("%d\n", min(c1, c2));
	return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
#define pb push_back
#define ll long long
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int main() 
{
    fast_io();
    int count[3] = {0};
    int n; cin >> n;
    ll ans = 1, mod = 1e9 + 7;
    for (int i = 0; i < n; ++i)
    {
        int a; cin >> a;
        int possible = 0;
        for (int j = 0; j < 3; ++j)
        {
            if (count[j] == a)
                ++possible;
        }
        ans = (ans * possible)%mod;
        if (possible == 0) 
        {
            cout << 0 << endl;
            return 0;
        }
        for (int j = 0; j < 3; ++j)
        {
            if (count[j] == a)
            {
                ++count[j];
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string s;
  cin >> s;

  const regex re("A[A-Z]*Z");
  int answer = 0;
  for (sregex_iterator it(ALL(s), re), end; it != end; ++it) {
    auto &&m = *it;
    answer = max(answer, static_cast<int>(m.length()));
  }
  cout << answer << endl;
  return 0;
}


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

int main(void) {
  int n, k;
  cin >> n >> k;
  for(int i = 0;i < n;i++) {
    char s;
    cin >> s;
    if(i == k-1) {
      s = s + 32;
    }
    cout << s;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
const double INF = 1e18;

int main(){
	double h;
	double hmax=0, hmin=INF;
	while(cin >> h){
		hmax = max(hmax, h);
		hmin = min(hmin, h);
	}
	cout << fixed << setprecision(5);
	cout << hmax - hmin << endl;
	return 0;
}


Measured memory_bytes: 3208
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3])) 

Measured memory_bytes: 26228
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<List<Integer>> edge = new ArrayList<List<Integer>>();
		for (int i = 0; i < n; i++) {
			edge.add(new ArrayList<Integer>());
		}
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			edge.get(a).add(b);
			edge.get(b).add(a);
		}
		sc.close();
		int[] ans = new int[n];
		Queue<Integer> s = new ArrayDeque<Integer>();
		s.offer(0);
		ans[0] = 0;
		while (s.size() > 0) {
			int x = s.poll();
			for (int i : edge.get(x)) {
				if (ans[i] == 0) {
					ans[i] = x + 1;
					s.add(i);
				}
			}
		}
		System.out.println("Yes");
		for (int i = 1; i < n; i++) {
			System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 76572
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const double PI = 3.14159265358979323846264338327950;
const LL MOD = 1000000007;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int main(void)
{
	int N, L;
	cin >> N >> L;
	int A[100000];
	Rep(i, N){
		cin >> A[i];
	}
	bool f = false;
	int id = 0;
	Rep(i, N - 1){
		if(A[i] + A[i + 1] >= L){
			f = true;
			id = i;
			break;
		}
	}
	if(f){
		PrintLn("Possible");
		Rep(i, id){
			printf("%d\n", i + 1);
		}
		for(int i = N - 2; i >= id; i--){
			printf("%d\n", i + 1);
		}
	}else{
		PrintLn("Impossible");
	}
	return 0;
}


Measured memory_bytes: 1152
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) {
        par.assign(n, -1);
    }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool is_same(int x, int y) {
        return root(x) == root(y);
    }
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int n, m, k; cin >> n >> m >> k;
    vector<set<int>> sets(n);
    UnionFind uf(n);

    rep(i, m) {
        int a, b; cin >> a >> b;
        --a, --b;
        sets[a].insert(b);
        sets[b].insert(a);
        uf.merge(a, b);
    }

    rep(i, k) {
        int c, d; cin >> c >> d;
        --c, --d;
        if (!uf.is_same(c, d)) continue;
        sets[c].insert(d);
        sets[d].insert(c);
    }

    rep(i, n) {
        int num = uf.size(i) - 1 - sets[i].size();
        cout << num << " ";
    }
    cout << endl;
}


Measured memory_bytes: 22272
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define mk make_pair
using namespace std;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int main(){
  int h,w,n,sum=0,x1,y1;
  cin>>h>>w>>n;
  string s[h];
  for(int i=0;i<h;i++)cin>>s[i];
  r(i,h)r(j,w)if(s[i][j]=='S')y1=i,x1=j;
  for(int o=1;o<=n;o++){
    int used[h][w]={};
    queue<pair<pair<int,int>,int> >q;
    q.push(mk(mk(y1,x1),0));
    used[y1][x1]=1;
    while(!q.empty()){
      pair<pair<int,int>,int> p=q.front();q.pop();
      int x=p.first.second,y=p.first.first,sum2=p.second;
      if(s[y][x]-'0'==o){
        sum+=sum2;
        y1=y;
        x1=x;
        goto L;
      }
      r(j,4){
        int xx=x+dx[j],yy=y+dy[j];
        if(xx>=0&&yy>=0&&yy<h&&xx<w)
          if(!used[yy][xx])
            if(s[yy][xx]!='X'){
              q.push(mk(mk(yy,xx),sum2+1));
              used[yy][xx]++;
            }
      }
    }L:;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 7956
#include <cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int f(int a,int b)
{
    return a>b?a-b:b-a;
}
int main()
{
    int i,j,n,a[100005][5],ok=1,t,x;
    scanf("%d",&n);
    a[0][0]=a[0][1]=a[0][2]=0;
    for(i=1;i<=n;i++)
        scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
    for(i=1;i<=n;i++)
    {
        t=a[i][0]-a[i-1][0];
        x=f(a[i][1],a[i-1][1])+f(a[i][2],a[i-1][2]);
        if(!(t>=x&&(t-x)%2==0))
        {
            ok=0;break;
        }
    }
    if(ok) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


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

int h,w,k;
char s[310][310];
int co[310];
int ans[310][310];
int main(){
	cin>>h>>w>>k;
	REP(i,h){
		REP(j,w){
			cin>>s[i][j];
			if(s[i][j]=='#'){
				co[i]++;
			}
		}
	}
	int l=0;
	while(co[l]==0){
		l++;
	}
	//l++;
	int now=1;
	int tnow=1;
	int stc=0;
	//cout<<l<<endl;
	for(int i=0;i<l;i++){
		tnow=1;
		stc=0;
		for(int j=0;j<w;j++){
			int flag=0;
			if(s[l][j]=='#'){
				stc++;
				if(stc!=1)
					flag=1;
			}
			//cout<<tnow;
			if(stc==0||stc==1){
				ans[i][j]=1;
			}else{
				if(flag){
					tnow++;
					ans[i][j]=tnow;
				}else{
					ans[i][j]=tnow;
				}
			}
		}
		//cout<<endl;
	}
	tnow=1;
	for(int i=l;i<h;i++){
			if(co[i]==0){
				for(int j=0;j<w;j++)
				ans[i][j]=ans[i-1][j];
			}else{
				stc=0;
				for(int j=0;j<w;j++){
					int flag=0;
					if(s[i][j]=='#'){
						stc++;
						if(stc!=1)
							flag=1;
					}
					//cout<<tnow;
					if(stc==0||stc==1){
						ans[i][j]=tnow;
					}else{
						if(flag){
							tnow++;
							ans[i][j]=tnow;
						}else{
							ans[i][j]=tnow;
						}
					}
				}
				tnow++;
			}
		
	}
	
	REP(i,h){
		REP(j,w){
			cout<<ans[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

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


int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int res = min(b,d) -  max(a,c);
    if(res >= 0)cout << res << endl;
    else cout << 0 << endl;

    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int A, B;
    cin >> A >> B;
    
    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
        cout << "Possible\n";
    }
    else{
        cout << "Impossible\n";
    }
}


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

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

    int res = 0, mx = 0;
    for (int i = 0; i < n; ++i) {
        int l; cin >> l;
        mx = max(mx, l);
        res += l;
    }   
    
    res -= mx;
    if ( mx < res ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s, t string
	_, _ = fmt.Scan(&s, &t)
	
	answer := 0
	
	for i := 0; i < 3; i++ {
		if s[i] == t[i] {
			answer++
		}
	}
	
	fmt.Println(answer)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define vec vector
typedef int64_t intl;
#define fi first
#define se second
#define pushb push_back
#define popb pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
vec<int> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};



int main(){
  char a,b,c,d;
  int A,B,C,D;
  cin >> a >> b >> c >>d;
  A = a-'0';B=b-'0';C=c-'0';D=d-'0';
  bitset<3> ansbit;
  for (int tmp =0; tmp < (1 << 3);tmp++){
    bitset<3> s(tmp);
    int ans = A;
    if( s.test(0) ){ans += B;} else {ans -= B;}
    if( s.test(1) ){ans += C;} else {ans -= C;}
    if( s.test(2) ){ans += D;} else {ans -= D;}
    
    if(ans ==  7){ ansbit = s; break;}
  }
  cout << A;
  if( ansbit.test(0) ){cout <<'+';} else {cout <<'-';}
  cout << B;
  if( ansbit.test(1) ){cout <<'+';} else {cout <<'-';}
  cout << C;
  if( ansbit.test(2) ){cout <<'+';} else {cout <<'-';}
  cout << D <<"=7";
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
ll F[200001];
ll memo[3][200001];
int main()
{
int N;
	string X;
	cin >> N >> X;
	ll cnt1 = 1, cnt0 = 0, cnt_1 = -1;
	fx(N) {
		if (X[x]=='1') {
			cnt0++;
		}
	}
	cnt1 += cnt0;
	cnt_1 += cnt0;
	
	fx(cnt1+1) {
		int y = x;
		int sum = 0;
		while (y>0) {
			sum += (y & 1) == 1 ? 1 : 0;
			y >>= 1;
		}
		if (sum>0) {
			F[x] = F[x % sum] + 1;
		}
	}
	ll ans1 = 0, ans0 = 0, ans_1 = 0;
	memo[0][0] = cnt0==1?0:1;
	memo[1][0] = cnt1 == 1 ? 0 : 1;
	memo[2][0] = cnt_1 == 1 ? 0 : 1;

	fx(N) {
		ans1 *= 2;
		ans0 *= 2;
		ans_1 *= 2;
		if (X[x]=='1') {
			ans1++;
			ans0++;
			ans_1++;
		}
		if (cnt0!=0) {
			ans0 %= cnt0;
			ans1 %= cnt1;
			if (x>0) {
				memo[0][x] = (memo[0][x - 1] * 2) % cnt0;
				memo[1][x] = (memo[1][x - 1] * 2) % cnt1;
			}
			if (cnt_1>0) {
				ans_1 %= cnt_1;
				if (x>0) {
					memo[2][x] = (memo[2][x - 1] * 2) % cnt_1;
				}
			}
		}
	}

	fx(N) {
		if (X[x]=='1') {
			ll sum =  - memo[2][N - x - 1] + ans_1;
			sum += cnt_1;
			if (cnt_1==0) {
				ce(0)
			}
			else {
				ce(F[sum % cnt_1] + 1)
			}

		}
		else {
			ll sum = memo[1][N - x - 1] + ans1;
			ce(F[sum%cnt1]+1)
		}
	}
	
    return 0;
}



Measured memory_bytes: 9212
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

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

int H, W;
vector<string> board;
const int MAX_HW = 1010;
ll dp[MAX_HW][MAX_HW];
int main()
{
    cin >> H >> W;
    board.resize(H);
    for (int i = 0; i < H; i++)
    {
        cin >> board[i];
    }
    dp[0][0] = 1;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (dp[i][j] == 0)
            {
                continue;
            }
            //right
            if (j + 1 < W && board[i][j + 1] == '.')
            {
                dp[i][j + 1] += dp[i][j] % MOD;
            }
            //down
            if (i + 1 < H && board[i + 1][j] == '.')
            {
                dp[i + 1][j] += dp[i][j] % MOD;
            }
        }
    }
    cout << dp[H - 1][W - 1] % MOD << endl;
    return 0;
}


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

int t;
long long a, b, c, d;
bool ans = 0;

long long gcd(long long left, long long right);

int main() {
  int roop;
  cin >> t;
  for(roop = 0; roop < t; ++roop) {
    cin >> a >> b >> c >> d;
    // cout << a << " " << b << " " << c << " " << d << endl;
    ans = 0;
    if(a < b)
      ans = 1;
    else if(b > d)
      ans = 1;
    else if(c >= b)
      ans = 0;
    else {
      // solve();
      ans = (c < b - gcd(b, d) + a % gcd(b, d));
    }
    if(ans)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
  return 0;
}

long long gcd(long long left, long long right) {
  long long nextnum, ansgcd = -1;
  if(left < right) swap(left, right);
  while(ansgcd == -1) {
    nextnum = left % right;
    if(nextnum == 0) ansgcd = right;
    left = right;
    right = nextnum;
  }
  return ansgcd;
}

Measured memory_bytes: 256