akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
 
int main()
{
  int N, A, B, count = 0;
  std::cin >> N >> A >> B;
  
  for(int i = 1; i <= N; i++)
  {
    int sum = 0;
    for(int k = i; k > 0; k = k / 10)
    {
      sum += k % 10;
    }
    
    if(sum >= A && sum <= B)
    {
      count += i;
    }
  }
  
  std::cout << count;
  return 0;
}

Measured memory_bytes: 3160
AC = 0
WA = 0
TLE = 0
RE = 0

N = int(input())
for _ in range(N):
    s = input()
    if s == 'AC':
        AC += 1
    elif s == 'WA':
        WA += 1
    elif s == 'TLE':
        TLE += 1
    elif s == 'RE':
        RE += 1

print('AC', 'x', AC)
print('WA', 'x', WA)
print('TLE', 'x', TLE)
print('RE', 'x', RE)


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

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

    cout << n*(n-1)/2 << endl;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S[1010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(y,N) {
		FOR(x,N) S[y]+="#."[(x+y)&1];
	}
	
	int ret=0;
	FOR(y,N) if(S[y][0]=='.') S[y][0]='*', ret++;
	FOR(x,N) if(S[N-1][x]=='.') S[N-1][x]='*', ret++;
	for(y=1;y<N;y+=3) {
		for(x=1;x<N;x++) if(S[y][x]=='.') S[y][x]='*', ret++;
	}
	
	_P("%d\n",ret);
	FOR(y,N) FOR(x,N) if(S[y][x]=='*') _P("%d %d\n",x,y);
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

const int N = 310;

int n, m;
int mat[N][N], sit[N], cnt[N];
bool vis[N];

bool check(int mid){
	memset(sit, 0, sizeof(sit));
	for (int i = 1; i <= m; ++ i){
		vis[i] = true;
	}
	int num = m;
	while (num){
		memset(cnt, 0, sizeof(cnt));
		for (int i = 0; i < n; ++ i){
			++ cnt[mat[i][sit[i]]];
		}
		bool flag = true;
		for (int i = 1; i <= m; ++ i){
			if (cnt[i] > mid){
				flag = false;
				vis[i] = false;
			}
		}
		if (flag){
			return true;
		}
		for (int i = 0; i < n; ++ i){
			while (sit[i] < m && !vis[mat[i][sit[i]]]){
				++ sit[i];
			}
			if (sit[i] == m){
				return false;
			}
		}
	}
	return false;
}

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++ i){
		for (int j = 0; j < m; ++ j){
			scanf("%d", &mat[i][j]);
		}
	}
	int left = 0, right = n;
	while (left < right){
		int mid = left + right >> 1;
		if (check(mid)){
			right = mid;
		}
		else{
			left = mid + 1;
		}
	}
	return printf("%d\n", left), 0;
}

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

using namespace std;

#define N 55

const int INF = (int)1e9;

bool adj[N][N][N][N];
int f[N][N][N][N];
char mat[N][N];
int n, m;
vector<pair<int, int> > vec[26];

bool ok(int x, int y) {
	return x >= 0 && x < n && y >= 0 && y < m && mat[x][y] != '#';
}

int dfs(int lx, int ly, int rx, int ry) {
	if (f[lx][ly][rx][ry] != -1) return f[lx][ly][rx][ry];
	if (lx > rx || ly > ry) {
		return f[lx][ly][rx][ry] = 0;
	}
	if (!adj[lx][ly][rx][ry]) {
		return f[lx][ly][rx][ry] = -INF;
	}		

	int res = 0;

	if (mat[lx][ly] >= 'a' && mat[lx][ly] <= 'z') {
		int id = mat[lx][ly] - 'a';
		
		for (int i = 0; i < vec[id].size(); i++) {
			int x = vec[id][i].first, y = vec[id][i].second;

			if (!adj[lx][ly][x][y]) continue;

			if (x >= lx && x <= rx && y >= ly && y <= ry) {
				if (ok(lx + 1, ly)) {
					if (ok(x - 1, y)) {
						res = max(res, dfs(lx + 1, ly, x - 1, y) + 1 + dfs(x, y, rx, ry));
					}
					if (ok(x, y - 1)) {
						res = max(res, dfs(lx + 1, ly, x, y - 1) + 1 + dfs(x, y, rx, ry));
					}
				}

				if (ok(lx, ly + 1)) {
					if (ok(x - 1, y)) {
						res = max(res, dfs(lx, ly + 1, x - 1, y) + 1 + dfs(x, y, rx, ry));
					}
					if (ok(x, y - 1)) {
						res = max(res, dfs(lx, ly + 1, x, y - 1) + 1 + dfs(x, y, rx, ry));
					}
				}			
			}			

			/*
			if (lx == 1 && ly == 1 && rx == 4 && ry == 4) {
				cout << "here" << endl;
				cout << res << endl;
				cout << id << endl;
				cout << x << ' ' << y << endl;
			}*/
		}		


	}


	if (ok(lx + 1, ly)) {
		res = max(res, dfs(lx + 1, ly, rx, ry));		
	}	
	if (ok(lx, ly + 1)) {
		res = max(res, dfs(lx, ly + 1, rx, ry));
	}

	return f[lx][ly][rx][ry] = res;
}

int main() {
	while (~scanf("%d%d", &n, &m)) {
		if (n + m == 0) break;

		for (int i = 0; i < 26; i++) {
			vec[i].clear();
		}

		for (int i = 0; i < n; i++) {
			scanf("%s", mat[i]);
			for (int j = 0; j < m; j++) {
				if (mat[i][j] >= 'A' && mat[i][j] <= 'Z') {
					int id = mat[i][j] - 'A';
					vec[id].push_back(make_pair(i, j));
				}
			}
		}

		memset(adj, 0, sizeof(adj));
		memset(f, -1, sizeof(f));

		for (int i = n - 1; i >= 0; i--) {
			for (int j = m - 1; j >= 0; j--) {

				if (mat[i][j] == '#') continue;

				for (int x = i; x < n; x++) {
					for (int y = j; y < m; y++) {
						if (ok(i + 1, j)) {
							adj[i][j][x][y] |= adj[i + 1][j][x][y];
						}
						if (ok(i, j + 1)) {
							adj[i][j][x][y] |= adj[i][j + 1][x][y];
						}
					}
				}
				
				adj[i][j][i][j] = 1;		
			}
		}	

		int res = dfs(0, 0, n - 1, m - 1);

		/*

		for (int x = 0; x < n; x++) {
			for (int y = 0; y < m; y++) {
				for (int i = x; i < n; i++) {
					for (int j = y; j < m; j++) {
						if (f[x][y][i][j] == 1) {
							cout << "yes" << endl;
							cout << x << ' ' << y << endl;
							cout << i << ' ' << j << endl;
						}
					}
				}
			}
		}*/

		if (res == -INF)
			puts("-1");
		else
			printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 45892
h1,m1,h2,m2,k = gets.chomp.split(" ").map(&:to_i)

hsa = h2 - h1
hsa = hsa<0 ? hsa + 24 : hsa
msa = m2 - m1
if msa < 0
  hsa -= 1
  msa = 60 + msa
end
wt = hsa*60 + msa
puts wt - k

Measured memory_bytes: 14296
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector <int> C(N), S(N), F(N);
  for (int i = 1; i < N; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }

  for (int stpos = 1; stpos < N; stpos++) {
    int now = 0;
    for (int i = stpos; i < N; i++) {
      if (now < S[i]) now = S[i];
      if ((now % F[i]) != 0) {
        now = (now+F[i])/F[i] * F[i];
      }
      now += C[i];
    }
    cout << now << endl;
  }
  // 最後の駅
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
/**
  * @brief atcoder
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

char ss[4][64] = {"AC","WA","TLE","RE"};
int cnt[4];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;++i)
    {
        char s[64];
        scanf("%s", s);
        int j = 0;
        while(j<4 && strcmp(s,ss[j]))++j;
        assert(j<4);
        ++cnt[j];
    }
    for(int i=0;i<4;++i)
        printf("%s x %d\n", ss[i], cnt[i]);
    return 0;
}


Measured memory_bytes: 1732
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.Delayed;
import java.util.logging.Logger;


public class Main {
	static final long MOD=998244353;
	public static void main(String[] args){
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		int N=sc.nextInt();
		int a=N%10;
		if (a==3) {
			System.out.println("bon");
		}else if (a==0||a==1||a==6||a==8) {
			System.out.println("pon");
		}else {
			System.out.println("hon");
		}
	}
	static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 32624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  string s;
  cin >> s;
  for(int i=0;i<s.size();++i){
    if (s[i] == 'C') {
      for (int j = i + 1; j < s.size(); ++j) {
        if (s[j] == 'F') {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
REPLACE_CHAR = "*"

n = int(input())
s = list(input())
k = int(input())

keep_char = s[k - 1]
replaced_str = ""

for char in s:
    if char != keep_char:
        replaced_str += REPLACE_CHAR
    else:
        replaced_str += char

print(replaced_str)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5;
int n;
int a[N];
int gcd(int x, int y) {
    if (!y) return x;
    return gcd(y, x % y);
}
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int p = a[0];
    for (int i = 1; i < n; ++i) {
        p = gcd(p, a[i]);
    }
    cout << p << endl;

    return 0;
}

// 4 7 49

Measured memory_bytes: 3988
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

int n,m,k;

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			if(i*(m-j)+j*(n-i)==k)
			{
				puts("Yes");
				exit(0);
			}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] data = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long sum = 0;
        
        Array.Sort(data);
        int min = data[0];
        int max = data[n - 1];
        for(int i = 0; i < n;i++)
        {
            sum += data[i];
        }
        Console.WriteLine(min + " " + max + " " + sum);
        
        
    }
}


Measured memory_bytes: 18504
def main():
    n = int(input())
    *a, = map(int, input().split())

    # [l,r)
    r = 1
    xor, tot = a[0], a[0]

    ret = 0
    for l in range(n):
        while (r < n) and (xor ^ a[r]) == (tot + a[r]):
            xor ^= a[r]
            tot += a[r]
            r += 1

        ret += r - l

        xor ^= a[l]
        tot -= a[l]

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23560
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();

        for (int i = 0; i < 3; i++)
        {
            if (s[i] != t[2 - i])
            {
                Console.WriteLine("NO");
                return;
            }
        }

        Console.WriteLine("YES");
    }
}


Measured memory_bytes: 13140
class Dice(object):
    def __init__(self):
        self.number = [0 for _ in range(6)]
        self.before = [0 for _ in range(6)]
        self.init = [0 for _ in range(6)]

    def set_number(self, l):
        for i in range(6):
            self.number[i] = l[i]

    def roll(self, loc):
        d = {
            'N': (1, 5, 2, 3, 0, 4),
            'S': (4, 0, 2, 3, 5, 1),
            'E': (3, 1, 0, 5, 4, 2),
            'W': (2, 1, 5, 0, 4, 3)
        }
        for i in range(6):
            self.before[i] = self.number[i]

        for i, j in enumerate(d[loc]):
            self.number[i] = self.before[j]

    def roll_clockwise(self):
        for i in range(6):
            self.before[i] = self.number[i]
        self.number = [self.before[i] for i in (0, 2, 4, 1, 3, 5)]

    def set_Top_and_Front(self, top, front):
        top_index = self.number.index(top)
        if top_index == 5:
            self.roll('E')
            self.roll('E')
        elif top_index == 4:
            self.roll('S')
        elif top_index == 3:
            self.roll('E')
        elif top_index == 2:
            self.roll('W')
        elif top_index == 1:
            self.roll('N')
        front_index = self.number.index(front)
        if front_index == 1:
            pass
        elif front_index == 2:
            self.roll_clockwise()
        elif front_index == 3:
            self.roll_clockwise()
            self.roll_clockwise()
            self.roll_clockwise()
        elif front_index == 4:
            self.roll_clockwise()
            self.roll_clockwise()

    def set_Top(self, idx):
        if idx == 5:
            self.roll('E')
            self.roll('E')
        elif idx == 4:
            self.roll('S')
        elif idx == 3:
            self.roll('E')
        elif idx == 2:
            self.roll('W')
        elif idx == 1:
            self.roll('N')
        elif idx == 0:
            pass

    def check_identity(self, another_dice):
        res = False

        for i in range(6):
            self.init[i] = self.number[i]

        for i in range(6):
            self.set_Top(i)
            for j in range(4):
                if j == 0:
                    pass
                else:
                    self.roll_clockwise()
                if self.number == another_dice:
                    res = True
                    break
            if res:
                break
            for i in range(6):
                self.number[i] = self.init[i]
        return res


if __name__ == '__main__':
    l = list(map(int, input().split()))
    dice_a = Dice()
    dice_a.set_number(l)
    m = list(map(int, input().split()))
    print('Yes' if dice_a.check_identity(m) else 'No')



Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define endl '\n'
#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp  make_pair
#define pb  push_back
#define  sz(x)   (int)x.size()
#define  all(x)  x.begin(), x.end()
#define	 allr(x)  x.rbegin(), x.rend()
#define  bit(x)  __builtin_popcountll(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
const int inf = (int) 1e9+99999, mod = (int)1e9+7;
const ll linf = (ll) 2e18+99999;
int mul (int x, int y) { return ((ll)x * y) % mod; } 
int sub (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int add (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
 
const int maxn = (int) 3e5;
 
void solve () {
	long long n, p;
	cin >> n >> p;
	if (n == 1) {
		cout << p;
		exit (0);
	} else {
		ll d = 2;
		vector <pair <int, ll>> v;
		while (d*d <= p) {
			if (p % d == 0) {
				int cnt = 0;
				while (p % d == 0) {
					cnt ++;
					p /= d;
				}
				v.pb (mp (cnt, d));
			}
			d ++;
		}

		sort (all (v));
		
		ll res = 1;
		for (auto to: v) {
			if (to.first >= n) {
				res *= powl (to.second, to.first/n); 
			}
		}

		cout << res;
	}	
}

main () { fast_in;
    int t = 1; //cin >> t;
    while (t --) {
    	solve ();    
    }
	return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n; cin >> n;
    vector<string> ans;
    ans.push_back("a");
    rep(i,n-1) {
        vector<string> tmp;
        for (auto s: ans) {
            char mx = 'a';
            rep(k,s.size()) {
                if (mx < s[k]) mx = s[k];
            }
            char add = 'a';
            while(add<=mx+1) {
                tmp.push_back(s+add);
                //cout << s+add << endl;
                ++add;
            }
        }
        ans = tmp;
    
    }
    sort(all(ans));
    for (auto s: ans) {
        cout << s << endl;
    }
    
    return 0;
}


Measured memory_bytes: 10908
import java.util.Scanner;

public class Main{
  static int N;
  static int K;
  static int A[];
  static int DP[];
  static int DPK[];
  static int ans;
  public static void main(String args[]){
    int ans = 1000000000;
   Scanner sc = new Scanner(System.in);
   N = sc.nextInt();
   K = sc.nextInt();
   A = new int[N];
   DP = new int[N];
   DPK = new int[N];
   for(int i=0;i<N;i++){
     A[i]=sc.nextInt();
   }
   DP[0]=0;
   DP[1]=Math.abs(A[0]-A[1]);
   if(N==2){
     System.out.println(DP[1]);
   }
   else{
   for(int i=2;i<N;i++){
     for(int j=i-1;j>i-K-1;j--){
       if(j<0){}
         else{
           DPK[j]=DP[j]+Math.abs(A[j]-A[i]);
           if(ans>=DPK[j]){
             ans=DPK[j];
           }
         }
     }
     DP[i]=ans;
     ans = 1000000000;
   }
   System.out.println(DP[N-1]);
 }
}

}


Measured memory_bytes: 59120
#include <stdio.h>
#include <stdlib.h>

int n,m,*A;

int possible(int sum,int i){
    if(sum>m){
        return 0;
    }else if(sum==m){
        return 1;
    }else if(i==n){
        return 0;
    }else{
        if(possible(sum+A[i],i+1)){
            return 1;
        }else if(possible(sum,i+1)){
            return 1;
        }else{
            return 0;
        }
    }
}

int main(){
    int q;
    int i;
    scanf("%d",&n);
    A = (int *)calloc(n,sizeof(int));
    for(i=0;i<n;i++)scanf("%d",A+i);
    scanf("%d",&q);
    while(q){
        scanf("%d",&m);
        printf(possible(0,0) ? "yes\n" : "no\n");
        q--;
    }
}

Measured memory_bytes: 1020
#include <iostream>
using namespace std;
typedef struct{
	int x;
	int y;
}POS;
POS pos[201];
int maxx,minx,miny,maxy;
int a,n,d;
int main(){
	while(1){
		cin >>n;
		if(n==0)break;
		minx=miny=maxx=maxy=0;
		pos[0].x=pos[0].y=0;
		for(int i=1;i<n;i++){
			cin >> a>>d;
			if(d==0){
				pos[i].x=pos[a].x-1;
				pos[i].y=pos[a].y;
			}else if(d==1){
				pos[i].x=pos[a].x;
				pos[i].y=pos[a].y-1;
			}else if(d==2){
				pos[i].x=pos[a].x+1;
				pos[i].y=pos[a].y;
			}else if(d==3){
				pos[i].x=pos[a].x;
				pos[i].y=pos[a].y+1;
			}
			if(maxx<pos[i].x)maxx=pos[i].x;
			if(minx>pos[i].x)minx=pos[i].x;
			if(maxy<pos[i].y)maxy=pos[i].y;
			if(miny>pos[i].y)miny=pos[i].y;
		}
		cout <<maxx-minx+1 << " "<<maxy-miny+1 <<endl;
	}
}

Measured memory_bytes: 3092
H,W = map(int,input().split())
a = []
for h in range(H):
    row = list(input())
    if '#' in row:
        a.append(row)
H = len(a)
for w in range(W):
    T = 1
    for h in range(H):
        if a[h][w] == '#':
            T = 0
            break
    if T == 1:
        for h in range(H):
            a[h][w] = 0
for h in range(H):
    a[h] = [w for w in a[h] if w != 0]
for h in range(H):
    print(''.join(a[h]))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
bool N,S,E,W;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{	
		if (s[i]=='N')
			N=1;
		if (s[i]=='S')
			S=1;
		if (s[i]=='E')
			E=1;
		if (s[i]=='W')
			W=1;
	}
	if ((N^S)||(E^W))//^Á½±ßÊÇ²¼¶ûÖµ£¬²»Í¬ÎªÕæ£¬ÏàÍ¬Îª¼Ù 
		cout<<"No";
	else
		cout<<"Yes";
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;


int main(){
  int n, k;
  cin >> n >> k;
  int v[50];
  rep(i, n) cin >> v[i];
  ll ans = -INF;
    
  for(int i = 1; i <= k; i++){
    for(int j = 0; j <= i && j <= n; j++){
      //左からj個、右からi-j個とって、k-i個まで捨てる
      vector<int> jewelry;
      for(int l = 0; l < j; l++){
        jewelry.push_back(v[l]);
      }
      for(int l = 0; l < i-j && l < n - j; l++){
        jewelry.push_back(v[n-l-1]);
      }
      sort(all(jewelry));
      ll tmp = 0;
      for(int x: jewelry) tmp += x;
      for(int l = 0; l < k-i; l++){
        tmp = max(tmp, tmp - jewelry[l]);
        }
      ans = max(tmp, ans);
    }
    //cout << ans << endl;
  }
  cout << max(ll(0), ans) <<endl;
}
    
    
    

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

int main(){
  int h,n;
  cin >> h >> n;
  vector<int> a(n);
  int sum = 0;
  rep(i,n){
   cin >> a[i]; 
    sum += a[i];
  }
  if(sum >= h) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


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

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
vector<int> edge[200000];

int depth[200000];
int depth2[200000];
int ans;

void bfs(int now_e, int dep){
    REP(i,edge[now_e].size()){
        int next_e = edge[now_e][i];
        if(depth[next_e] > 0) continue;
        depth[next_e] = dep+1;
        //ans = max(ans,dep+1);
        bfs(next_e, dep+1);
    }
}

void bfs2(int now_e, int dep){
    REP(i,edge[now_e].size()){
        int next_e = edge[now_e][i];
        if(depth2[next_e] > 0) continue;
        depth2[next_e] = dep+1;
        //ans = max(ans,dep+1);
        bfs2(next_e, dep+1);
    }
}


signed main(){
    ans = -100;
    int n,u,v;
    cin >> n >> u >> v;
    u--;
    v--;
    REP(i,n-1){
        int a1,b1;
        cin >> a1 >> b1;
        edge[a1-1].pb(b1-1);
        edge[b1-1].pb(a1-1);
    }
    depth[v] = 1;
    bfs(v,1);
    depth2[u] = 1;
    bfs2(u,1);
    ans = 0;
    REP(i,n){
        if(depth[i]>depth2[i]){
            ans = max(ans,depth[i]);
        }
    }
    cout << ans-2 << endl;
    return 0;
}

Measured memory_bytes: 14464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
struct UnionFind{
public:
	vector<int> par;
	vector<int> rank;
	vector<int> s;
	int cnt;
 
	UnionFind(int n){
		rep(i,n){
			par.push_back(i);
			rank.push_back(0);
			s.push_back(1);
		}
		cnt=n;
	}
 
	int find(int x){
		if(par[x]==x) return x;
		else return par[x]=find(par[x]);
	}
 
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			par[x]=y;
			s[y]+=s[x];
		}else{
			par[y]=x;
			s[x]+=s[y];
			if(rank[x]==rank[y]) rank[x]++;
		}
		cnt--;
	}

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

	int size(int x){
		return s[find(x)];
	}
};

struct state{
	ll x,y,id;
};

struct edge{
	ll from,to,cost;
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<state> g;
	rep(i,n){
		ll x,y;
		cin>>x>>y;
		g.push_back({x,y,i});
	}
	vector<edge> tree;
	sort(begin(g),end(g),[](const state &a,const state &b){
		return a.x<b.x;
	});
	rep(i,n-1){
		state &now=g[i];
		state &ne=g[i+1];
		tree.push_back({now.id,ne.id,abs(now.x-ne.x)});
	}
	sort(begin(g),end(g),[](const state &a,const state &b){
		return a.y<b.y;
	});
	rep(i,n-1){
		state &now=g[i];
		state &ne=g[i+1];
		tree.push_back({now.id,ne.id,abs(now.y-ne.y)});
	}
	sort(begin(tree),end(tree),[](const edge &a,const edge &b){
		return a.cost<b.cost;
	});
	ll ans=0;
	UnionFind uf(n);
	for(auto &e:tree){
		if(!uf.same(e.from,e.to)){
			ans+=e.cost;
			uf.unite(e.from,e.to);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 10988
#include<iostream>

int main(){
  std::string s;
  std::string p;
  std::cin >> s;
  std::cin >> p;

  s += s.substr(0, p.size());
  if((int)s.find(p) == -1){
    std::cout << "No" << std::endl;
  }else{
    std::cout << "Yes" << std::endl;
  }
  
  return 0;
}



Measured memory_bytes: 3180
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# W行H列, x[W][H]
def create_grid(W, H, value = 0):
    return [[ value for _ in range(H)] for _ in range(W)]

########
N, M, Q = l_inpl()

l, r = [], []
for _ in range(M):
    li, ri = l_inpl()
    l.append(li)
    r.append(ri)

p, q = [], []
for _ in range(Q):
    pi, qi = l_inpl()
    p.append(pi)
    q.append(qi)

s = create_grid(N+1, N+1)

for i in range(M):
    s[l[i]][r[i]] += 1

for hi in range(1, N+1):
    for wi in range(1, N+1):
        s[hi][wi] += s[hi-1][wi]
        s[hi][wi] += s[hi][wi-1]
        s[hi][wi] -= s[hi-1][wi-1]

for i in range(Q):
    pi, qi = p[i], q[i]
    print(s[qi][qi] - s[qi][pi-1] - s[pi-1][qi] + s[pi-1][pi-1])

Measured memory_bytes: 28572
N=int(input())
l=[input() for _ in range(N)]
if(N!=len(set(l))):
    print("No")
    exit()
for i in range(0,N-1):
    if(l[i][len(l[i])-1]!=l[i+1][0]):
        print("No")
        exit()
print("Yes")

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

int main(){
  ll N,K;
  cin >> N >> K;
  ll ans=K;
  for(int i=0;i<N-1;i++){
    ans *= (K-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List

main :: IO ()
main = do  
  x <- sort <$> getInts
  let showStr = intersperse " " (map toString x) 
  let forPrint  = foldl (++) "" showStr 
  putStrLn forPrint 
  
getInts = do 
  x <- getLine 
  let y = (map$toInt)$words x
  return y

toInt :: (String -> Int)
toInt x = read x :: Int

toString :: (Int -> String)
toString x = show x :: String  


Measured memory_bytes: 3628
import sys
from math import factorial

input = sys.stdin.readline

Mod = 10**9 + 7


def Cmb(n, k):
    return factorial(n) // (factorial(n - k) * factorial(k)) % Mod


n, m, k = list(map(int, input().split()))

ans = 0

for i in range(1, n + 1):
    ans += i * (n - i) * m**2 % Mod

for i in range(1, m + 1):
    ans += i * (m - i) * n**2 % Mod

ans *= Cmb(n * m - 2, k - 2)
ans %= Mod

print(ans)


Measured memory_bytes: 74588
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int N = 2e6 + 6;
int A[N];
int n;

void solve()
{
	int n;
	cin >> n;

	map<string,int> m;

	loop(i,0,n)
	{
		string s;
		cin >>s;
		m[s]++;
	}

	cout << m.size();
}
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);

ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	

 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 19244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define FOR(i, r, n) for (int i=(int)(r); i<=(int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 2147483647
#define INF64 9223372036854775807
#define MOD 1000000007

int main(){

    int n;
    cin>>n;
    vector<int> a(n+1);
    rep(i, n) cin>>a[i+1];
    a[0]=a[1];

    int64_t dp[n+1][2];
    dp[0][0]=1000;
    dp[0][1]=1000;

    FOR(i, 1, n){
        dp[i][1]=(dp[i-1][0]/a[i-1])*a[i]+(dp[i-1][0]%a[i-1]);
        dp[i][0]=max(dp[i-1][0], dp[i][1]);
    }

    cout<<dp[n][0]<<endl;

}

Measured memory_bytes: 3612
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	long long N;
	scanf("%lld", &N);
	long long tmp = N;
	int L = 0, n;
	int count = 0;
	while (tmp > 0) {
		if (tmp % 10 == 9 && tmp >= 10) count++;
		L++;
		n = tmp;
		tmp /= 10;
	}
	long long an = 0;
	if (count == L - 1) {
		an = (L - 1) * 9 + n;
	}
	else {
		an = (L - 1) * 9 + n - 1;
	}
	printf("%lld", an);
	return 0;
}

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

int main(){
    long int N, K, temp, min;
    cin >> N >> K;
    if(K == 1 || N%K == 0){
        cout << "0" << endl;
        return 0;
    }

    if(N > K){
        N = N % K;
    }
    
    temp = K - N;
    if(temp >= N){
        min = N;
    } else {
        min = temp;
    }

    cout << min << endl;

}

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

int main(){
 long long N;
 std::cin>>N;

 std::vector<int> num;
 while(N>0){
  num.emplace_back(N%26);
  N=N/26;
 }

 std::string ans="";
/*
 for(int i=0;i<num.size();i++){
  std::cout<<num[i]<<" ";
 }
 std::cout<<std::endl;
//*/
 for(int i=0;i<num.size();i++){
  if(num[i]<=0){
   if(i!=num.size()-1){
    num[i]+=26;
    num[i+1]--;
   }
  }
 }

 for(int i=num.size()-1;i>=0;i--){
  if(num[i]!=0){
   ans=ans+(char)(num[i]+96);
  }
 }

 std::cout<<ans<<std::endl;

 return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
signed main() {

	int n;
	scnaf("%d", &n);
	map<char, int> cou;
	REP(i, 1) {
		char s[51];
		scanf("%s", s);
		int len = strlen(s);
		map<char, int> cur;
		REP(i, len) {
			cou[s[i]]++;
		}
	}
	REP(i, n-1) {
		char s[51];
		scanf("%s", s);
		int len = strlen(s);
		map<char, int> cur;
		REP(i, len) {
			cur[s[i]]++;
		}

		REP(i,'z'-'a'+1) {
			cou[i + 'a'] = min(cou[i+'a'], cur[i + 'a']);
		}
	}

	for (auto itr : cou) {
		REP(i,itr.second)
			printf("%c", itr.first);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;

// ---
const int AnLim = POW_10_5;
int N, M, A[AnLim], B[AnLim];
vector<int> P[AnLim];
int root, dist[AnLim];

void Sub(int i) {
  if (dist[i] != INF) { return; }
  if (P[i].size() == 1) {
    Sub(P[i][0]);
    dist[i] = dist[P[i][0]] + 1;
    return;
  }
  REP(j, P[i].size()) { Sub(P[i][j]); }
  int aj = 0;
  FOR(j, 1, P[i].size() - 1) {
    if (dist[P[i][j]] > dist[P[i][aj]]) { aj = j; }
  }
  dist[i] = dist[P[i][aj]] + 1;
  P[i] = {P[i][aj]};
  return;
}

void Ans() {
  REP(i, N-1+M) {
    P[B[i]].push_back(A[i]);
  }

  REP(i, N) {
    if (P[i].size() == 0) {
      P[i].push_back(-1);
      root = i;
      break;
    }
  }

  REP(i, N) { dist[i] = INF; }
  dist[root] = 0;
  REP(i, N) { Sub(i); }

  REP(i, N) {
    P[i][0]++;
  }

  return;
}

signed main() {
  cin >> N >> M;
  REP(i, N-1+M) { cin >> A[i] >> B[i]; }
  REP(i, N-1+M) { A[i]--; B[i]--; }

  Ans();

  REP(i, N) {
    cout << P[i][0] << endl;
  }
  return 0;
}


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

int main(){
  int n; cin>>n;
  set<string>st;
  vector<string>W(n);
  rep(i,n) cin>>W[i];
  st.insert(W[0]);
  bool jud = true;
  for (int i=1; i<n; i++){
    st.insert(W[i]);
    if (W[i][0]==W[i-1][W[i-1].size()-1]) continue;
    else jud = false;
  }
  if (st.size()!=n) jud = false;
  if (jud) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define MP make_pair
#define PB push_back

using namespace std;
typedef pair<int,int> Pair;
typedef long double ld;
typedef long long ll;

const int mod = 998244353, MAX = 1e5, N = 50005;
//template{{{
const long double Pi = 3.14159265358979323846l;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; };
inline void inc(int &x, int y) { x += y; x -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		x = mul(x, x), y >>= 1;
	} return ans;
}

/*char buf[1<<23],obuf[1<<23],*p1=buf,*p2=buf, *O = obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
void print(int x) {
    if(x > 9) print(x / 10);
    *O++=x%10+'0';
} */

template <class T> inline T	input() {
	T x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}

template <class T> inline bool chkmin(T &x, T y) { x = x < y ? x : y; return x == y; }
template <class T> inline bool chkmax(T &x, T y) { x = x > y ? x : y; return x == y; }
template <class T> inline T gcd(T x, T y) { return !y ? x : gcd(y, x % y); }
template <class T> inline T sqrm(T x) { return (ll) x * x % mod; }
template <class T> inline T sqr(T x) { return x * x; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read; //}}}

int n, m, Q;
int A[N], a[N], b[N], c[N], d[N];
long long ans = 0;

void dfs(int p) {
	if (p > n) {
		long long res = 0;
		for (int i = 1; i <= Q; ++i)
			if (A[b[i]] - A[a[i]] == c[i])
				res += d[i];
		chkmax(ans, res);
		return void();
	}

	for (int i = A[p - 1]; i <= m; ++i)
		A[p] = i, dfs(p + 1);
}

int main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	freopen("log", "w", stderr);
#endif

	read(n, m, Q);
	for (int i = 1; i <= Q; ++i) read(a[i], b[i], c[i], d[i]);

	A[0] = 1;
	dfs(1);

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


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000007;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll gcd(ll a2,ll b2){
	ll t;
	if(a2<b2){
		t=a2;
		a2=b2;
		b2=t;
	}
	while(b2!=0){
		t=a2%b2;
		a2=b2;
		b2=t;
	}
	return a2;
}

int main() {

	ll a,b;
	cin>>a>>b;

	ll total=1;
	ll t2=gcd(a,b);
	for(ll i=2; i*i<=t2; i++){
		if(t2%i==0){
			total++;
			while(t2%i==0){
				t2/=i;
			}
		}
	}
	if(t2!=1)total++;

	cout<<total<<endl;

	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
 
x = [0] * n
y = [0] * n
h = [0] * n
 
n.times do |i|
  (x[i], y[i], h[i]) = gets.chomp.split(' ').map(&:to_i)
end
 
(0..100).each do |cy|
  (0..100).each do |cx|
    a = []
    
    n.times do |i|  
      if h[i] > 0 then
        a.push( h[i] + (cx - x[i]).abs + (cy - y[i]).abs )
      end
    end
    
    if ((a.uniq.size == 1) and (a[0] > 0)) then
      flag = true
      
      n.times do |i|
        if [0, (a[0] - (cx - x[i]).abs - (cy - y[i]).abs)].max != h[i] then
          flag = false
          break
        end
      end
      
      if flag then
        puts [cx, cy, a[0]].map(&:to_s).join(' ')
        exit
      end
    end
  end
end

Measured memory_bytes: 4220
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;
using ll = long long;

ll sat_calc(vector<vector<ll>>& s, vector<ll>& c, vector<ll>& last, ll day, ll contest);

int main()
{
    ll d;
    cin >> d;
    vector<ll> c;
    vector<vector<ll>> s;
    vector<ll> last(26, 0);

    for (ll i = 0; i < 26; i++) {
        ll tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    for (ll i = 0; i < d; i++) {
        vector<ll> tmp_v;
        for (ll j = 0; j < 26; j++) {
            ll tmp;
            cin >> tmp;
            tmp_v.push_back(tmp);

        }
        s.push_back(tmp_v);
    }


    ll sat = 0;
    vector<ll> index_vec;
    for (ll i = 0; i < d; i++) {
        vector<ll> contest_sat;
        for (ll contest = 0; contest < 26; contest++) {
            ll tmp = sat_calc(s, c, last, i, contest);
            contest_sat.push_back(tmp);
        }
        std::vector<ll>::iterator iter = std::max_element(contest_sat.begin(), contest_sat.end());
        size_t index = std::distance(contest_sat.begin(), iter);
        sat += contest_sat[index];
        last[index] = i + 1;
        index_vec.push_back(index + 1);
        //cout << sat << endl;
    }
    for (auto a : index_vec) {
        cout << a << endl;
    }
    return 0;

}

ll sat_calc(vector<vector<ll>>& s, vector<ll>& c, vector<ll> &last, ll day,ll contest) {
    ll sat = s[day][contest];
    ll last_tmp = last[contest];
    last[contest] = day + 1;
    for (ll j = 0; j < 26; j++) {
        sat -= (day + 1 - last[j]) * c[j];
    }
    last[contest] = last_tmp;
    return sat;
}

Measured memory_bytes: 3728
A,B,C,D = map(int,input().split())

ans=0

if A<C:
    if B<=D:
        ans=B-C
    else:
        ans=D-C
else:
    if B<=D:
        ans=B-A
    else:
        ans=D-A

if ans>=0:
    print(ans)
else:
    print(0)

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    int64_t m = 100;
    int64_t ans = 0;
    while (m < n) {
        m = m * 1.01;
        ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> d(n);
    
    REP(i,n) cin>>a[i];
  REP(i,n) d[i]=a[i];
    int m;
    cin>>m;
    int b=0;
    int p,x;
    vector<int> c(m);
    for(int i=0;i<m;i++){
    cin>>p>>x;
    a[p-1]=x;
    
    REP(i,n){
        b+=a[i];
    }
    c[i]=b;
    b=0;
    a[p-1]=d[p-1];
    }
    REP(i,m){
        cout<<c[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256