akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int H, W, K;
    cin >> H >> W >> K;

    char SW[H][W];
    vector<vector<int>> ans(H, vector<int>(W, 0));
    rep(i, H) {
        rep(j, W) {
            cin >> SW[i][j];
        }
    }

    int cnt = 1;
    rep(i, H) {
        int num = 0;
        rep(j, W) {
            if (SW[i][j] == '#') num++;
        }
        if (num == 0) continue;
        rep(j, W) {
            if (num == 0) {
                ans[i][j] = cnt;
            }
            else {
                ans[i][j] = cnt;
                if (SW[i][j] == '#') {
                    num--;
                    if (num != 0) cnt++;
                }
            }
        }
        cnt++;
    }

    rep(i, H - 1) {
        rep(j, W) {
            if (ans[i][j] == 0) continue;
            if (ans[i + 1][j] == 0) {
                ans[i + 1][j] = ans[i][j];
            }
        }
    }

    for (int i = H - 1; i > 0; i--) {
        rep(j, W) {
            if (ans[i][j] == 0) continue;
            if (ans[i - 1][j] == 0) {
                ans[i - 1][j] = ans[i][j];
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            cout << ans[i][j];
            if (j != W - 1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		//????????¨?¨???????????????????
		Scanner sc = new Scanner(System.in);
		while(true){
			int intH = sc.nextInt();
			int intW = sc.nextInt();
			int h = intH - 1;
			int w = intW - 1;

			//??????H???W???0?????£???????????????????????????
			if((intH == 0) && (intW == 0)){
				break;
			}
			//??????

			for (int i = 0; i < intH; i++) {
				String A = "";
				for (int j = 0; j < intW; j++) {
					if (i == 0 || i == h || j == 0 || j == w ) {
						A += "#";
					}else {
						A += ".";
					}
				}
				System.out.println(A);
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 50400
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	ll N, H;
	
	cin >> N >> H;

	ll a[N], b[N];

	ll a_max = 0;
	rep(i, N)
	{
		cin >> a[i] >> b[i];
		a_max = a[i] > a_max ? a[i] : a_max;
	}

	sort(b, b+N, greater<ll>());

	ll count = 0;
	ll h = H;

	rep(i, N)
	{
		if (h <= 0 )
		{
			break;
		}

		if (b[i] < a_max)
		{
			break;
		}

		h -= b[i];
		count++;
	}

	if (h > 0)
	{
		count += (h + a_max - 1) / a_max;
	}
	


	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF = 1e12+1;
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;}

ll N, T;

int main() {
    cin >> N >> T;
    vector<ll> t(N);
    for (int i = 0; i < N; i++) cin >> t[i];
    ll res = 0;
    for (int i = 0; i < N-1; i++) {
        res += min(t[i+1]-t[i],T);
    }
    res += T;
    cout << res << endl;
}

Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():

    return

#C
def C():
    def bfs(s,g,n):
        bfs_map = [-1 for i in range(n)]
        bfs_map[s] = 0
        q = deque()
        q.append(s)
        fin = False
        while q:
            x = q.popleft()
            for y in v[x]:
                if c[x][y] > 0 and bfs_map[y] < 0:
                    bfs_map[y] = bfs_map[x]+1
                    if y == g:
                        fin = True
                        break
                    q.append(y)
            if fin:
                break

        if bfs_map[g] == -1:
            return None,0
        path = [None]*(bfs_map[g]+1)
        m = float("inf")
        path[bfs_map[g]] = g
        y = g
        for i in range(bfs_map[g])[::-1]:
            for x in v[y]:
                if c[x][y] > 0 and bfs_map[x] == bfs_map[y]-1:
                    path[i] = x
                    if c[x][y] < m:
                        m = c[x][y]
                    y = x
                    break
        return path,m

    def ford_fulkerson(s,g,c,n):
        f = 0
        while 1:
            p,m = bfs(s,g,n)
            if not m:break
            f += m
            for i in range(len(p)-1):
                c[p[i]][p[i+1]] -= m
                c[p[i+1]][p[i]] += m
        return f

    n = I()
    a = LI()
    e = n+2
    ma = 10**9
    c = [[0]*e for i in range(e)]
    v = [[] for i in range(e)]
    for i in range(n):
        d = i+1
        j = 2*d
        c[0][d] = ma
        v[0].append(d)
        v[d].append(0)
        c[d][n+1] = ma-a[i]
        v[d].append(n+1)
        v[n+1].append(d)
        while j <= n:
            c[j][d] = float("inf")
            v[j].append(d)
            v[d].append(j)
            j += d
    print(ma*n-ford_fulkerson(0,n+1,c,e))
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    int cnt = 0;
    int nb = 0;
    rep(i, n)
    {
        cnt++;
        if (a[nb] == 2)
        {
            OP(cnt);
            return 0;
        }
        nb = a[nb] - 1;
    }
    OP(-1);
    return 0;
}

Measured memory_bytes: 640
//ABC132A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	string s;
	cin >> s;
	if(s.at(0) == s.at(1) && s.at(1) == s.at(2) && s.at(2) == s.at(3)){
		cout << "No" << endl;
		return 0;
	}
	if(s.at(0) == s.at(1) && s.at(2) == s.at(3)){
		cout << "Yes" << endl;
		return 0;
	}else if(s.at(0) == s.at(2) && s.at(1) == s.at(3)){
		cout << "Yes" << endl;
		return 0;
	}else if(s.at(0) == s.at(3) && s.at(1) == s.at(2)){
		cout << "Yes" << endl;
		return 0;
	}else{
		cout << "No" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
int main() {
    int n,x,maxi,ans=1;
    cin>>n;
    cin>>maxi;
    for(int i=1;i<n;i++){
        cin>>x;
        if(x>=maxi){
            ans++;
            maxi=x;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
s = list(set(input()))
l = [["N","S"], ["W","E"], ["N", "S", "W", "E"]]
if len(s) != 2 and len(s) != 4:
    print("No")
    exit()
for i in l:
    x = 0
    for j in s:
        if j in i:
            x += 1
    if x == len(i):
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
    int a,b,c;
    cin >> a >> b >> c;
    int d = c-a-b;
    if(4*a*b<d*d && d>0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
	int a=0,b=0,k=0;	
	cin >> a >> b >> k;
	if (k>a+b)
	{
		cout << 0 << ' ' << 0;
	}
	else if (k>a)
	{
		cout << 0 << ' ' << b-(k-a);
	}
	else 
	{
		cout << a-k << ' ' << b;
	}
	return 0;
}


Measured memory_bytes: 256
var n,t,min:int64;
i:longword;
begin
        read(n);
        for i:=1 to round(sqrt(n)) do
        begin
                if n mod i=0 then
                begin
                        t:=n div i;
                        min:=i-1+t-1;
                end;
        end;
        write(min);
end.

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
		char a[100];int gg=0;int l;
	scanf("%s",a);
	char b[100];
	scanf("%s",b);
  int l1=strlen(a);
  int l2=strlen(b);
  if(l1>l2)
    l=l2;
  else
    l=l1;
  for(int i=0;i<l;i++)
  {
    if(a[i]!=b[i])
    {
      gg=9;break;}}
  if(gg==0)
    printf("Yes");
  else
    printf("No");// your code goes here
	return 0;
}



Measured memory_bytes: 1716
#include <stdio.h>
#include <math.h>
int main(){

  double x1,y1,x2,y2,xx,yy,result;

  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);

  xx=pow(x1-x2, 2);
  yy=pow(y1-y2, 2);

  printf("%lf\n",sqrt(xx+yy));

  return 0;

}

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

int main() {
	int n;
	
	cin >> n;
	vector<int> a(3*n);
	long long int ans = 0;
	for (int i = 0; i <3* n; i++) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		ans += a.at(3*n - 2 - (2 * i));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4240
#include<iostream>

using namespace std;

int main() {
	int n;
	int Min;
	int Max;
	long long Sum = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (i == 0) {
			Min = Max = a;
		}
		else {
			if (Min > a)Min = a;
			if (Max < a)Max = a;
		}
		Sum += a;
	}

	cout << Min << " " << Max << " " << Sum << endl;

	return 0;
}

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

long long int dp[100001][2];
const long long int INF = 1e18;

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

	int n;
	long long int x,a,b;
	vector <long long int> v;

	cin >> n >> a >> b;

	for(int i=0;i<n;i++)
	{
		cin >> x;
		v.push_back(x);
	}

	for(int i=0;i<=100000;i++)
	{
		for(int j=0;j<2;j++)
		{
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;
	dp[0][1] = 0;

	for(int i=1;i<n;i++)
	{
		long long int t1 = (v[i] - v[i-1])*a;
		dp[i][0] = min(dp[i][0],min(dp[i-1][0],dp[i-1][1])+t1);
		dp[i][1] = min(dp[i][1],min(dp[i-1][0],dp[i-1][1])+b);
	}

	cout << min(dp[n-1][0],dp[n-1][1]) << '\n';

	return 0;
}


Measured memory_bytes: 2676
y, m, d=map(int, input().split("/"))
if 2020<y:
  print("TBD")
else:
  if y<2019:
    print("Heisei")
    
  else:                   #y==2019
    if 5<=m:
      print("TBD")
    else:
      if m<=4:
        print("Heisei")

Measured memory_bytes: 9056
#include <stdio.h>

int main(void)
{
    int a_0, b_0, c_0;
    int a_1, b_1, c_1;
    int a_2, b_2, c_2;
    int a_3, b_3, c_3;

    scanf("%d %d %d", &a_0, &b_0, &c_0);
    if (a_0 <= b_0){
        a_1 = a_0;
        b_1 = b_0;
        c_1 = c_0;
    }else{
        a_1 = b_0;
        b_1 = a_0;
        c_1 = c_0;
    }

    if (b_1 <= c_1){
        a_2 = a_1;
        b_2 = b_1;
        c_2 = c_1;
    }else{
        a_2 = a_1;
        b_2 = c_1;
        c_2 = b_1;
    }

    if (a_2 <= b_2){
        a_3 = a_2;
        b_3 = b_2;
        c_3 = c_2;
    }else{
        a_3 = b_2;
        b_3 = a_2;
        c_3 = c_2;
    }

    printf("%d %d %d\n", a_3, b_3, c_3);

    return 0;
}

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

using namespace std;

int main()
{
	set<int> s;
	int x;
	for(int i=0;i<3;i++)
	{
		scanf("%d",&x);
		s.insert(x);
	}    
    if(s.size()==2)
    	printf("Yes\n");
    else
    	printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pi acos(-1)

using namespace std;

int main() {
    nl // Bazzi - Paradise

    int n; cin >> n;
    cout << (1000-n%1000)%1000;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    if(s[0] == s[1]){
        if(s[2] == s[3] && s[2] != s[1]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        vector<char> a(2);
        vector<char> b(2);
        a[0] = s[0];
        a[1] = s[1];
        b[0] = s[2];
        b[1] = s[3];
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        if(a == b){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
	int i,cnt;
	char now,str[100001];
	
	scanf("%s",str);

	now = str[0];
	cnt = 0;
	for (i = 1;i < strlen(str);i++) {
		if (now != str[i]) {
			now = str[i];
			cnt++;
		}
	}
	
	printf("%d\n",cnt);
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  if (N % 2 == 0) {
    cout << (double) (N / 2) / N << endl;
  }
  else {
    cout << (double) ((N + 1) / 2) / N << endl;
  }
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<pair<long long,long long>> a(n);
	for(int i=0;i<n;i++){
		long long x,l;
		cin >> x >> l;
		a[i].first=x-l;
		a[i].second=x+l;
	}
	
	sort(a.begin(),a.end(),
		[&](pair<long long,long long> &p0,pair<long long,long long> &p1){
			if(p0.second==p1.second){
				return p0.first<p1.first;
			}
			return p0.second<p1.second;
		}
	);
	
	int res=0;
	long long last=-(1LL<<50);
	for(int i=0;i<n;i++){
		if(last<=a[i].first){
			res++;
			last=a[i].second;
		}
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int A, B, C;

int main()
{
	in >> A >> B >> C;
	out << (A + B >= C ? "Yes" : "No") << std::endl;
	return 0;
}

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

typedef long long ll;
typedef long double lg;

using namespace std;

int main(){

 int a,b;
 cin>>a>>b;

 if(a == b)
    cout<<"Yes"<<endl;
 else
    cout<<"No"<<endl;

return 0;
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	n := 0
	x := 0
	c := make(map[int]int)
	for scanner.Scan() {
		arr := strings.Split(scanner.Text(), " ")
		if x == 0 {
			n, _ = strconv.Atoi(arr[0])
			x++
			continue
		}
		a, _ := strconv.Atoi(arr[0])
		b, _ := strconv.Atoi(arr[1])
		c[a]++
		c[b]++
	}

	for i := 1; i <= n; i++ {
		fmt.Println(c[i])
	}
}


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

using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

bool checked[1010][1010]={};
vector<queue<int>>q(2020);
int h,w;
cin>>h>>w;
rep2(i,h){
    rep2(k,w){
        char c;
        cin>>c;
        if(c=='#'){
            checked[i][k]=true;
            q[0].push(k);
            q[0].push(i);
        }
    }
}

int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int p=0;
while(1){
    bool finish=true;
    while(!q[p].empty()){
        int x=q[p].front();q[p].pop();
        int y=q[p].front();q[p].pop();
        rep(i,4){
            int nowx=x+dx[i];
            int nowy=y+dy[i];
            if(nowx>=1 && nowx<=w && nowy>=1 && nowy<=h){
                if(checked[nowy][nowx])continue;
                checked[nowy][nowx]=true;
                q[p+1].push(nowx);
                q[p+1].push(nowy);
                finish=false;
            }
        }
    }
    if(finish)break;
    p++;

}
cout<<p<<endl;

 return 0;
}
/*

by my self
first  23m 43s
second 17m 44s

3 3
...
.#.
...

2


6 6
..#..#
......
#..#..
......
.#....
....#.

3
*/

Measured memory_bytes: 10768
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s, t[4] = {"dream", "dreamer", "erase", "eraser"};
int n;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> s;
    n = s.size();
    int last = n;
    eper(i, n - 1, 0) {
        string sub = s.substr(i, last - i);
        rep(j, 0, 4) {
            if (sub == t[j]) {
                last = i;
            }
        }
    }
    if (last == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    if ((n / 100 == 7) || ((n / 10) % 10 == 7) || (n % 10 == 7)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1005;
const int mod=1e9+7;
struct node{int u,v,w;}e[N<<1];
struct _node{int to,next,w;}num[N<<1];
int cnt,head[N],n,m,fa[N][13],dep[N],Max[N][13],f[N],tag[N<<1],t1,t2;
ll sum,x;
bool operator < (const node &A,const node &B) {return A.w<B.w;}
int find(int x) {return x==f[x]?x:f[x]=find(f[x]);}
void add(int x,int y,int w)
{num[++cnt].to=y;num[cnt].next=head[x];num[cnt].w=w;head[x]=cnt;}
void mst()
{
  sort(e+1,e+m+1);
  for (int i=1;i<=n;i++) f[i]=i;
  for (int i=1;i<=m;i++) 
    if (find(e[i].u)!=find(e[i].v)) 
      sum+=e[i].w,f[find(e[i].u)]=find(e[i].v),tag[i]=1,add(e[i].u,e[i].v,e[i].w),add(e[i].v,e[i].u,e[i].w);
}
void dfs(int x)
{
  for (int i=head[x];i;i=num[i].next)
    if (num[i].to!=fa[x][0])
    {
      dep[num[i].to]=dep[x]+1;
      fa[num[i].to][0]=x;
      Max[num[i].to][0]=num[i].w;
      dfs(num[i].to);
    }
}
void init()
{
  for (int j=1;j<=12;j++)
    for (int i=1;i<=n;i++)
      fa[i][j]=fa[fa[i][j-1]][j-1],Max[i][j]=max(Max[i][j-1],Max[fa[i][j-1]][j-1]);
}
int jump(int x,int y)
{
  if (dep[x]<dep[y]) swap(x,y);
  int del=dep[x]-dep[y],ans=0;
  for (int i=0;i<=12;i++)
    if (del&(1<<i)) ans=max(ans,Max[x][i]),x=fa[x][i];
  if (x==y) return ans;
  for (int i=12;i>=0;i--)
    if (fa[x][i]!=fa[y][i]) ans=max(ans,Max[x][i]),ans=max(ans,Max[y][i]),x=fa[x][i],y=fa[y][i];
  return max(max(ans,Max[x][0]),Max[y][0]);//一不小心把Max写成fa了！
}
int ksm(int x,int y)
{
  int res=1;
  for (;y;x=(ll)x*x%mod,y>>=1)
    if (y&1) res=(ll)res*x%mod;
  return res;
}
int main()
{
  scanf("%d%d",&n,&m);
  scanf("%lld",&x);
  for (int i=1;i<=m;i++) scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
  mst();
  if (sum>x) return puts("0"),0;
  else{
    dfs(1);init();
    for (int i=1;i<=m;i++) 
      if (!tag[i])
      {
        int t=jump(e[i].u,e[i].v);
        if (e[i].w-t==x-sum) t1++;
        else if (e[i].w-t>x-sum) t2++;
      }
    if (x==sum) printf("%lld\n",((ll)ksm(2,t2)*(ksm(2,t1+n-1)-2+mod)%mod)%mod);
    else printf("%lld\n",(ll)ksm(2,t2)*(ksm(2,t1)-1+mod)%mod*2%mod);
  }
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int N, K;
vector<PLL> bk, wh;
vector<PLL> xn[1010], Yn[1010];
int sat[1010] = {};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> K;
	ll res = 0;
	REP(i, N){
		int x, y; char c;
		cin >> x >> y >> c;
		if(c == 'W'){
			wh.push_back({x, y});
			if((x/K+y/K)%2){
				sat[x%K]++;
				Yn[y%K].push_back({x, -1});
			}else{
				Yn[y%K].push_back({x, 1});
			}
			xn[x%K].push_back({y, 1});
		}else{
			bk.push_back({x, y});
			if((x/K+y/K)%2==0){
				sat[x%K]++;
				Yn[y%K].push_back({x, -1});
			}else{
				Yn[y%K].push_back({x, 1});
			}
			xn[x%K].push_back({y, 0});
		}
	}
	REP(i, K){
		ll sum = 0;
		REP(j, K){
			sum += sat[j];
		}
		REP(j, K){
			res = max(res, max(N-sum, sum));
			sum += xn[j].size()-2*sat[j];
		}
		REP(j, Yn[i].size()){
			sat[Yn[i][j].fs%K] += Yn[i][j].sc;
		}
	}
	cout << max(res, N-res) << endl;
}


Measured memory_bytes: 6888
#include <cstdio>
const int maxn = 5005;
int N, M, m;
int c[maxn][maxn];
int main() {
    scanf("%d %d %d", &N, &M, &m);
    int x = 1, y = 1;
    for(int i = 1; i <= m; i++) {
	int a;
	scanf("%d", &a);
	while(a--) {
	    c[x][y] = i;
	    if(x & 1) {
		if(y < M) y++;
		else x++;
	    }
	    else {
		if(y > 1) y--;
		else x++;
	    }
	}
    }
    for(int i = 1; i <= N; i++) {
	for(int j = 1;j <= M; j++) printf("%d ", c[i][j]); 
	printf("\n");
    }
    return 0;
}


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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {

  int n,k;
  cin >> n >> k;
  
  vector<int> a(n);
  REP(i,n){
    cin >> a[i];
  }
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  int mx = 0;
  
  REP(i,k){
    mx += a[i];
  }
  
  cout << mx << endl;
  
}

Measured memory_bytes: 256
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
typedef long long int ll ;
using namespace std;
#define MAX 100009	
int main()
{
    ll n; cin>>n;
    ll a= n/2;
    if(n%2==1) a++;
    cout<<a<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


i64 a,b;

i64 gcd(i64 x, i64 y){
	if(y == 0) return x;
	return gcd(y, x%y);
}
i64 lcm(i64 x, i64 y){
	return x*y / gcd(x,y);
}

int main(){
	cin >> a >> b;
	
	cout << lcm(a,b) << endl;
	
	return 0;
}

Measured memory_bytes: 256
using static System.Console;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ');
        var ans = int.MaxValue;

        for (var i = 0; i < N; i++)
        {
            var cnt = 0;
            var j = int.Parse(A[i]);
            while (j % 2 == 0)
            {
                cnt++;
                j /= 2;
            }
            ans = cnt < ans ? cnt : ans;
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const vector<int> dh = {1, 0};
const vector<int> dw = {0, 1};

vector<vector<bool>> seen;
// 深さ優先探索
//色が、color と同じ場所を最初に探索する。
void dfs(vector<string>& graph, int h, int w, char color) {
  int H = graph.size(); int W = graph.at(0).size();
  
  seen.at(h).at(w) = true;  //訪問済みにする。
    rep(i, 2){
      int next_h = h + dh.at(i);
      int next_w = w + dw.at(i);
      if(next_h>= graph.size() || next_w>=graph.at(0).size()) continue;  //場外
      if(seen.at(next_h).at(next_w)) continue;  //探索済みはスルー
      if(graph.at(next_h).at(next_w) != color) continue;  //色が違う箇所はスルー
      dfs(graph, next_h, next_w, color);
    } 
  
}


int main(){
  int H, W;
  cin >> H >> W;
  vector<string> graph(H);
  rep(i, H) cin >> graph.at(i);
  
  seen.assign(H, vector<bool>(W, false)); // seen初期化
  int res = 0;
  
  if(graph.at(0).at(0) == '.'){
    dfs(graph, 0, 0, '.');
    while(!seen.at(H-1).at(W-1)){
      rep(i, H){
        rep(j, W){
          if(seen.at(i).at(j)) dfs(graph, i, j, '#');
        }
      }
      res++;
      if(seen.at(H-1).at(W-1)) break;
      rep(i, H){
        rep(j, W){
          if(seen.at(i).at(j)) dfs(graph, i, j, '.');
        }
      }
      if(seen.at(H-1).at(W-1)) break;
    }
  }else{
    res++;
    dfs(graph, 0, 0, '#');
    while(!seen.at(H-1).at(W-1)){
      rep(i, H){
        rep(j, W){
          if(seen.at(i).at(j)) dfs(graph, i, j, '.');
        }
      }
      if(seen.at(H-1).at(W-1)) break;
      rep(i, H){
        rep(j, W){
          if(seen.at(i).at(j)) dfs(graph, i, j, '#');
        }
      }
      res++;
      if(seen.at(H-1).at(W-1)) break;
    }
      
  }
  
  
  cout << res;
  
  
}

Measured memory_bytes: 256
N = int(input())
s = input()
w = 0
e = 0
for i in s[1:]:
  if i == "E":
    e += 1
ans = e
tmp = e
for i in range(1,N):
    if s[i-1] == "E" and s[i] == "E":
        tmp -= 1
    elif s[i-1] == "W" and s[i] == "E":
        pass
    elif s[i-1] == "E" and s[i] == "W":
        pass
    elif s[i-1] == "W" and s[i] == "W":
        tmp += 1
    if ans > tmp:
        ans = tmp
print(ans)


Measured memory_bytes: 3828
#include <iostream>
#include <sstream>

using namespace std;

int main(){
	int i;
	string month;
	long int cost,sum,income,outcome;
	while(cin >> cost && cost != 0){
//		cout << cost;
		int sum = 0;
		bool flag = 1;
		for(i=0;i<12;i++){
			cin >> income >> outcome;
			sum += income - outcome;
			if(sum >= cost && flag){
				stringstream tuki;
				tuki << i+1;
				month = tuki.str();
				flag = !flag; 
			}
		}
		if(flag) month = "NA";
		cout << month << endl;
	}


}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();

		long r = n % k;

		System.out.println(Math.min(r, k - r));
	}

}


Measured memory_bytes: 35532
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long A = long.Parse(Console.ReadLine());
		if(A==1){
			Console.WriteLine("Hello World");
		} else {
			long B = long.Parse(Console.ReadLine());
			long C = long.Parse(Console.ReadLine());
			Console.WriteLine(B+C);
		}
	}
}

Measured memory_bytes: 11092
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, w[3][N], f[N], h[2];
int main()
{
    n = read();
    for(int i = 0; i < 3; ++i)
        for(int j = 1; j <= n; ++j) 
            w[i][j] = read();
    for(int i = 1; i <= n; ++i)
    {
        int a = w[0][i], b = w[1][i], c = w[2][i];
        if(abs(a-b) > 1||abs(b-c) > 1||b%3 != 2||(b%6&i&1)) return puts("No"), 0;
        f[i] = b/3+1, h[i&1] ^= a > c;
    }
    for(int i = 1; i <= n; ++i)
        while(f[i] != i) h[i&1^1] ^= 1, swap(f[i], f[f[i]]);
    puts(h[0]||h[1]?"No":"Yes");
    return 0;
}

Measured memory_bytes: 1664
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int data[] = new int[n];
		int group[] = new int[n+1];
		int alter = 0;
		for(int i = 0; i < n; i++) {
			data[i] = sc.nextInt();
			group[data[i]]++;
		}
		Arrays.sort(group);
		for(int i = 0; i < n+1-k; i++) {
			alter = alter + group[i];
		}
		System.out.println(alter);
	}
}

Measured memory_bytes: 86840
#include <cctype>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

typedef set<pair<int,int> > S;

struct E {
  int l, r;
  ll c;
};
bool cmpL(const E& e1, const E& e2) {
  return e1.l < e2.l;
}

struct K {
  int l, r;
  ll c;
};
bool operator>(const K& e1, const K& e2) {
  return e1.c > e2.c;
}
ostream& operator<<(ostream& out, const K& k) {
  return out << k.l << " " << k.r << " " << k.c << endl;
}

E es[100000+10];
ll dist[100000+10];
const ll INF = 1e18;

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  REP(i, m) {
    scanf("%d%d%lld", &es[i].l, &es[i].r, &es[i].c);
    es[i].l--;
    es[i].r--;
  }
  REP(i, n) {
    dist[i] = INF;
  }
  sort(es, es + m, cmpL);
  priority_queue<K, vector<K>, greater<K> > q;
  int ii = 0;
  for(; ii < m && es[ii].l == 0; ++ii) {
    q.push((K){es[ii].l, es[ii].r, 0+es[ii].c});
  }
  dist[0] = 0;
  int iii = 1;
  while(!q.empty()) {
    K cur = q.top(); q.pop();
    if(cur.r < iii) {
      continue;
    }
    while(iii <= cur.r) {
      dist[iii] = cur.c;
      ++iii;
    }
    for(; ii < m && es[ii].l < iii; ++ii) {
      q.push((K){es[ii].l, es[ii].r, dist[es[ii].l] + es[ii].c});
    }
  }
  cout << (dist[n-1] == INF ? -1 : dist[n-1]) << endl;
  return 0;
}


Measured memory_bytes: 4596
#include<iostream>

using namespace std;

int main(){

int data[1000000];


 for(int i = 0; i < 1000000; i++) data[i] = 1;

 for(int i = 2; i*i < 1000000; i++){
   if(data[i] == 1){
     for(int j = i*2; j < 1000000; j+=i) data[j] = 0;
   }
 }
 int in;
 
 while(cin >> in){
   
   int sum = 0;
   for(int i = 2; i <= in; i++){
     if(data[i] == 1) sum++;
   }
   
   cout << sum <<endl;
 }
 return 0;
}

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

struct edge{
  int to, cap, rev;
};

//fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(vector<vector<edge> > &g, int from,int to,int cap){
  g[from].push_back((edge){to, cap, (int)g[to].size()});
  g[to].push_back((edge){from, 0, (int)g[from].size() - 1});
}

class FordFulkerson{
public:
  FordFulkerson(){};
  FordFulkerson(vector<vector<edge> >& _g):g(_g), flow_val(-1e9){};
  int MaxFlow(int s,int t){
    if(flow_val != -1e9)return flow_val;
    int flow=0;
    while(1){
      bool used[g.size()];
      memset(used, false, sizeof(used));
      int f = Dfs(s, t ,1e9, used);
      if(f==0)return flow_val = flow;
      flow+=f;
    }
  }
  int flow_val;
private:
  //増加パスをDFSで探す
  int Dfs(int v,int t,int f, bool* used){
    if(v==t)return f;
    used[v] = true;
    for(int i=0;i < g[v].size();i++){
      edge &e = g[v][i];
      if(!used[e.to] && e.cap > 0){
        int d = Dfs(e.to, t, min(f, e.cap), used);
        if(d > 0){
          e.cap -= d;
          g[e.to][e.rev].cap +=d;
          return d;
        }
      }
    }
    return 0;
  }
  //sからtへの最大流を求める
  vector<vector<edge> > g;
};

int main(){
  int n, m;
  std::cin >> n >> m;
  vector<vector<edge> > g(n);
  for (int i = 0; i < m; i++) {
    int to, from, cost;
    std::cin >> from >> to >> cost;
    add_edge(g, from, to, cost);
  }
 FordFulkerson fd(g);
 std::cout << fd.MaxFlow(0, n - 1)<< std::endl;
  return 0;
}



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

int main(){
  int n,count=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    if(i<10) count++;
    else if(i==10) i+=88;
    else if(99<i&&i<1000) count++;
    else if(i==1000) i+=8998;
    else if(9999<i&&i<100000) count++;
  }
  cout<<count<<endl;
}

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

int main() {
	// your code goes here
	string s;
	char a;
	cin>>s;
	int l=s.size();
	char p[l];
	int i,k;
	for(i=0,k=0;i<s.size();i++)
	{
	    if(s[i]=='B')
	    {
	        if(k>0)
	        k--;
	    }
	    else
	    p[k++]=s[i];
	}
	for(i=0;i<k;i++)
	cout<<p[i];
	cout<<endl;
	return 0;
}


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

int GCD(int x, int y) {
    int temp;

    temp = y;
    y = x;
    x = temp;
    if (x % y == 0) {
        return y;
    }
    return GCD(x % y, y);
}

int main() {
    int x, y;
    cin >> x;
    cin >> y;
    cout << GCD(x, y) << "\n";
}

Measured memory_bytes: 3076
import Control.Monad
import Control.Applicative
import Data.List

main = do
  xs <- (map read . lines) <$> getContents :: IO [Int]
  mapM_ print $ map (length . comb) xs

comb :: Int -> [(Int,Int,Int,Int)]
comb n = do
  a <- [0..9]
  b <- [0..9]
  c <- [0..9]
  d <- [0..9]
  guard $ a + b + c + d == n
  return (a,b,c,d)

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

string s;

long long cal(long long n){
    return (1 + n) * n /2;
}

int main(){
    cin >> s;
    int n = s.size();
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    vector<long long> count;
    long long temp = 1;
    for(int i = 1; i < n; i ++){
        if(s[i] == s[i-1]) temp ++;
        else{
            count.push_back(temp);
            temp = 1;
        }
    }
    count.push_back(temp);
    long long res = 0;
    if(s[0] == '<'){
        for(int i = 0; i < count.size()-1; i += 2){
            res += cal(max(count[i], count[i+1]));
            res += cal(min(count[i], count[i+1])-1);
        }
        if(count.size() % 2 == 0){
            cout << res << endl;
            return 0;
        } else {
            res += cal(count.back());
            cout << res << endl;
            return 0;
        }
    } else {
        for(int i = 1; i < count.size() - 1; i += 2){
            res += cal(max(count[i], count[i+1]));
            res += cal(min(count[i], count[i+1])-1);
        }
        res += cal(count[0]);
        if(count.size() % 2 == 1){
            cout << res << endl;
            return 0;
        } else {
            res += cal(count.back());
            cout << res << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    ll a[n * 3];
    rep(i, 0, n * 3){
        cin >> a[i];
    }

    sort(a, a +  3 * n);

    ll sum = 0;
    rep(i, 0, 2 * n){
        if(i % 2 == 1){
            sum += a[3 * n - i - 1];
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <complex>

using namespace std;

typedef complex<double> P;

double EPS = 0;

typedef struct {
	P s,e;
	double h;
}RECT;

void P_cin(P& p){
	double x,y;
	cin >> p.real() >> p.imag();
}
double dot(P a,P b){ return a.real() * b.real() + a.imag() * b.imag(); }
double cross(P a,P b){ return a.real() * b.imag() - a.imag() * b.real(); } 

double distance_lp(P& s,P& e,P &p){
	if(dot(e-s,p-s) < EPS) return abs(p-s); //_sÆÌ£
	if(dot(s-e,p-e) < EPS) return abs(p-e); //_eÆÌ£
	return abs(cross(e-s,p-s)) / abs(e-s); //_Æ¼üÆÌ£
}

bool is_intersected_ls(P& a1, P& a2, P& b1, P& b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

bool is_contained(P& a,P& b,P& p){
	return (a.real() <= p.real() && p.real() <= b.real()) &&
		(a.imag() <= p.imag() && p.imag() <= b.imag());
}

double distance_rl(P& a,P& b,P& s,P& e){
	if(is_contained(a,b,s) || is_contained(a,b,e))
		return 0.0; //R[X©Ìª ÉüÁÄé

	double len = 1e10;
	P rectP[] = {a,P(a.real(),b.imag()),b,P(b.real(),a.imag())};
	for(int i = 0; i < 4; i++){
		if(is_intersected_ls(s,e,rectP[i],rectP[(i+1)%4])) return 0.0; //üªªdÈÁ½I
		len = min(len,distance_lp(rectP[i],rectP[(i+1)%4],s));
		len = min(len,distance_lp(rectP[i],rectP[(i+1)%4],e));
		len = min(len,distance_lp(e,s,rectP[i]));
	}

	return len;
}

double distance(RECT &r,P& s,P& e){
	double len = distance_rl(r.s,r.e,s,e);
	if(len <= r.h) return len; //cÉ¢
	return (r.h + len * len / r.h) / 2; //cÌûªá¢ÌÅvZ·é
}

int N;

void solve(){

	P s,e;
	P_cin(s);
	P_cin(e);

	vector<RECT> rects(N);
	for(int i = 0; i < N; i++){
		RECT &r = rects[i];
		P_cin(r.s);
		P_cin(r.e);
		cin >> r.h;
	}
	
	double ans = 1e10;
	for(int i = 0; i < N; i++){
		ans = min(ans,distance(rects[i],s,e));
	}

	cout << ans << endl;
}

int main()
{
	while(cin >> N,N){
		solve();
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

const int MAX_N = 50;

int main() {
    int N, M;
    cin >> N >> M;
    long num[MAX_N];
    for (int i = 0; i < N; ++i) {
        num[i] = 0;
    }
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        num[a - 1] += 1;
        num[b - 1] += 1;
    }
    for (int i = 0; i < N; ++i) {
        cout << num[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}


signed main() {
	int n,a,ans,t=0;
	cin >> n;
	a = n / 15;
	ans = a * (a - 1) / 2 * 120 + a * 60;
	for (int i = n / 15 * 15 + 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) {
			continue;
		}
		t += i;
	}
	cout << ans + t << endl;
}





Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int dp[100000];
int h[100000];
    
int cost(int n)
{if(dp[n]!=-1)return dp[n];else
    {dp[n]=min((abs(h[n]-h[n-1])+cost(n-1)),(abs(h[n]-h[n-2])+cost(n-2)));
return dp[n];}}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
{cin>>h[i];dp[i]=-1;}

  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
    int c=cost(n-1);
    cout<<c;
}

Measured memory_bytes: 3328
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
li = [111,222,333,444,555,666,777,888,999]
ind = bisect.bisect_left(li,N)
print(li[ind])


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

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 dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  while(1){
    int h, w;
    cin >> h >> w;
    if(h == 0 && w == 0) return 0;
    rep(i,h){
      rep(j, w){
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
}






Measured memory_bytes: 3080
#include <iostream>
#include <vector>

using std::cout;
using std::cin;
using std::endl;
using std::vector;

vector<int> make_table(vector<int> v) {
    vector<int> dp(1000000, 0);
    dp[1] = 1;
    int j;
    int min;
    for (int i = 2; i < dp.size(); i++) {
        j = 0;
        min = 1e09;
        while (i >= v[j]) {
            if (min > dp[i - v[j]]) {
                min = dp[i - v[j]];
            }
            j++; 
        }
        dp[i] = min + 1;
    }
    return dp; 
}

int main(void) {
    vector<int> all;
    vector<int> odd;

    int tetra = 0;
    int times = 1;
    while (1) {
        tetra = times * (times + 1) * (times + 2) / 6;
        all.push_back(tetra);
        if (tetra % 2 == 1) {
            odd.push_back(tetra);
        }
        times++;
        if (tetra > 1000000) {
            break;
        }
    }
    vector<int> dp_all = make_table(all);
    vector<int> dp_odd = make_table(odd);
    int input;
    while (1) {
        cin >> input;
        if (input == 0) {
            break;
        }
        cout << dp_all[input] << " " << dp_odd[input] << endl;
    }
    return 0;
}

Measured memory_bytes: 10532
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] head = br.readLine().split(" ");
    int n = Integer.parseInt(head[0]);
    int m = Integer.parseInt(head[1]);
    DSU uf = new DSU(n);
    for(int i = 0; i < m; i++){
      String[] data = br.readLine().split(" ");
      int ai = Integer.parseInt(data[0]) - 1;
      int bi = Integer.parseInt(data[1]) - 1;
      uf.merge(ai, bi);
    }
    br.close();
    int ans = 0;
    ArrayList<ArrayList<Integer>> l = uf.groups();
    for(int i = 0; i < l.size(); i++){
      ArrayList ll = l.get(i);
      if(ll != null && ll.size() != 0){
        ans++;
      }
    }
    System.out.println(ans -1);

  }
}
class DSU {
  private int n;
  private int[] parentOrSize;

  public DSU(int n) {
    this.n = n;
    this.parentOrSize = new int[n];
    Arrays.fill(parentOrSize, -1);
  }

  int merge(int a, int b) {
    if (!(0 <= a && a < n) || !(0 <= b && b < n)) {
      // この式が成立しない物は動作しません。
      return -1;
    }
    int x = leader(a);
    int y = leader(b);
    if (x == y) return x;
    if (-parentOrSize[x] < -parentOrSize[y]) {
      int tmp = x;
      x = y;
      y = tmp;
    }
    parentOrSize[x] += parentOrSize[y];
    parentOrSize[y] = x;
    return x;
  }

  boolean same(int a, int b) {
    if (!(0 <= a && a < n) || !(0 <= b && b < n)) {
      // この式が成立しない物は動作しません。
      return false;
    }
    return leader(a) == leader(b);
  }

  int leader(int a) {
    if (parentOrSize[a] < 0) {
      return a;
    } else {
      parentOrSize[a] = leader(parentOrSize[a]);
      return parentOrSize[a];
    }
  }

  int size(int a) {
    if (!(0 <= a && a < n)) {
      // この式が成立しない物は動作しません。
      return -1;
    }
    return -parentOrSize[leader(a)];
  }

  ArrayList<ArrayList<Integer>> groups() {
    int[] leaderBuf = new int[n];
    int[] groupSize = new int[n];
    for (int i = 0; i < n; i++) {
      leaderBuf[i] = leader(i);
      groupSize[leaderBuf[i]]++;
    }
    ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
    for (int i = 0; i < n; i++) {
      result.add(new ArrayList<>());
    }
    for (int i = 0; i < n; i++) {
      result.get(leaderBuf[i]).add(i);
    }
    return result;
  }
}

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

int main () {
    int N;
    int A[21];
    int B[51];
    int C[51];
    cin >> N;
    for (int i = 1; i <= N; ++i){
        cin >> A[i];
    }
    for (int i = 1; i <= N; ++i){
        cin >> B[i];
    }
    for (int i = 1; i < N; ++i){
        cin >> C[i];
    }
    
    int ans = 0;
    for (int i = 1; i <= N; ++i ){
        ans += B[A[i]];
        
        if ( i < N && A[i+1] - A[i] == 1){
            ans += C[A[i]];
        }
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
a = []
m = []
ans = []
for _ in range(h):
    a.append(list(map(int, input().split())))
for j in range(h):
    f = 0
    for i in range(w):
        if not f:
            if a[j][i] % 2:
                f = a[j][i]
        else:
            ans.append([j+1, i, j+1, i+1])
            if a[j][i] % 2:
                f = 0
    m.append(f)

f = 0
for j in range(h):
    if not f:
        if m[j] % 2:
            f = m[j]
    else:
        ans.append([j, w, j+1, w])
        if m[j] % 2:
            f = 0

print(len(ans))
for ansi in ans:
    print(" ".join([str(x) for x in ansi]))


Measured memory_bytes: 29792