akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	//1706
	Scanner sc = new Scanner(System.in);
	int INF = 1 << 24;
	int [] cake;
	int k;
	
	class Edge{
		int from, to, cost;
		public Edge(int from, int to, int cost) {
			this.from = from;
			this.to = to;
			this.cost = cost;
		}
	}
	
	class State implements Comparable<State>{
		int now;
		int cost, visited;
		public State(int now, int cost, int visited) {
			this.now = now;
			this.cost = cost;
			this.visited = visited;
		}
		@Override
		public int compareTo(State o) {
			return this.cost - o.cost;
		}
	}

	private void doit() {
		while (true) {
			int m = sc.nextInt();
			int n = sc.nextInt();
			k = sc.nextInt();
			int d = sc.nextInt();
			if((m|n|k|d) == 0) break;
			cake = new int[m];
			for(int i = 0; i < m; i++){
				cake[i] = sc.nextInt();
			}
			ArrayList<Edge> list = new ArrayList<Edge>();
			for(int i = 0; i < d; i++){
				String a = sc.next();
				String b = sc.next();
				int cost = sc.nextInt();
				int from = changeInd(a);
				int to = changeInd(b);
				list.add(new Edge(from, to, cost));
				list.add(new Edge(to, from, cost));
			}
			int [][] res = bellman(list, Math.max(1, Math.max(m, n)) * 10 + 1, m, 2);
			int ans = INF;
			for(int i = 0; i < res[3].length; i++){
				ans = Math.min(ans, res[3][i]);
			}
			System.out.println(ans);
		}
	}
	
	private int changeInd(String a) {
		if(a.equals("H")){
			return 2;
		}
		if(a.equals("D")){
			return 3;
		}
		char c = a.charAt(0);
		String sub = a.substring(1);
		int num = Integer.parseInt(sub) -1;
		if(c == 'C'){
			return num * 10 + 1;
		}
		else{
			return num * 10;
		}
	}

	private int [][] bellman(ArrayList<Edge> data, int arraysize, int bitsize, int s){
		int m = data.size();
		int [][] d = new int[arraysize][1 << bitsize];
		for(int i = 0; i < arraysize; i++){
			Arrays.fill(d[i], INF);
		}
		d[s][0] = 0;
		while(true){
			boolean update = false;
			for(int i = 0; i < m; i++){
				Edge e = data.get(i);
				for(int j = 0; j < (1 << bitsize); j++){
					if(d[e.from][j] == INF) continue;
					if(e.from % 10 == 1){
						int ind = e.from / 10;
						if((j & (1 << ind)) > 0) continue;
						int nextind = j | 1 << ind;
						int nextcost = d[e.from][j] + e.cost * k - cake[ind];
						if(d[e.to][nextind] > nextcost){
							d[e.to][nextind] = nextcost;
							update = true;
						}
					}
					else{
						int nextcost = d[e.from][j] + e.cost * k;
						if(d[e.to][j] > nextcost){
							d[e.to][j] = nextcost;
							update = true;
						}
					}
				}
				
			}
			if(! update){
				break;
			}
		}
		return d;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 56576
//https://atcoder.jp/contests/keyence2020/tasks/keyence2020_a

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

int run(istream& in, ostream& out) {
    ll H, W, N;
    in >> H >>  W >> N;
    ll ans = 0;
    auto larger = H < W ? W : H;
    ans = (N + larger - 1) / larger;
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <numeric>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> vs(n);
  for (auto& v : vs)
    cin >> v;
  int price = INT_MIN;
  for (int l = 0; l <= n; l++) {
    for (int r = 0; r <= min(n - l, k - l); r++) {
      vector<int> gems;
      for (int i = 0; i < l; i++)
        gems.push_back(vs[i]);
      for (int i = n - r; i < n; i++)
        gems.push_back(vs[i]);
      sort(begin(gems), end(gems));
      int remove = 0;
      for (int i = 0; i < min(k - l - r, l + r); i++) {
        if (gems[i] > 0) break;
        remove += gems[i];
      }
      price = max(accumulate(begin(gems), end(gems), 0) - remove, price);
    }
  }
  cout << price << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int[] ans = new int[4];
		while (true) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int[] a = new int[3];
			Arrays.fill(a, Integer.MAX_VALUE);
			for (int i = 0; i < 3; i++) {
				int tmp = Integer.parseInt(st.nextToken());
				if (tmp < a[0]) {
					a[2] = a[1]; a[1] = a[0]; a[0] = tmp;
				} else if (tmp < a[1]) {
					a[2] = a[1]; a[1] = tmp;
				} else if (tmp < a[2]) {
					a[2] = tmp;
				}
			}
			int ret = findTriangleType(a);
			if (ret == -1) break;
			ans[0]++;
			ans[ret]++;
		}
		reader.close();
		System.out.print(ans[0]);
		for (int i = 1; i < 4; i++) {
			System.out.print(" " + ans[i]);
		}
		System.out.println();
	}

	private static int findTriangleType(int[] a) {
		int ret = -1;
		int n1,n2,n3;
		n1 = a[0]; n2 = a[1]; n3 = a[2];
		if (n1 + n2 <= n3) {
			ret = -1;
		} else if (n1*n1 + n2*n2 == n3*n3) {
			ret = 1;
		} else if (n1*n1 + n2*n2 > n3*n3) {
			ret = 2;
		} else {
			ret = 3;
		}
		return ret;
	}
}



Measured memory_bytes: 24208
import           Control.Monad
import           Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Sequence as Seq
import Data.Foldable

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  as <- (Seq.unstableSortBy (flip compare) . Seq.fromList) <$> getIntList

  let bgst = Seq.index as 0
      th = (bgst + 1) `div` 2

      bigs = Seq.takeWhileL (>= th) as
      smalls = Seq.dropWhileL (>= th) as

      _ Seq.:> x = Seq.viewr bigs

      countSmallWinners x xs s res | s*2 < x   = res
                                   | otherwise = countSmallWinners x' xs' s' res'
        where x' Seq.:< xs' = Seq.viewl xs
              s' = s - x'
              res' = res + 1

      ans = Seq.length bigs + countSmallWinners x smalls (sum smalls) 0

  print ans

Measured memory_bytes: 24956
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
// ascending order
#define asort(array, N) sort(array, array + N)
// descending order
#define asort_r(array, N) sort(array, array + N, greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	ll d[N];
	ll total = 0;
	for(int i = 0; i < N; i++) d[i] = 0;
	for(int i = 0; i < N; i++) {
		int a;
		cin >> a;
		a--;
		d[a]++;
		if(d[a] == 1) total += 1;
	}

	asort(d, N);
	ll ans = 0;
	ll tmp = 0;
	for(int i = 0; i < N; i++) {
		if(total - tmp <= K) {
			cout << ans << endl;
			return 0;
		}
		if(d[i] != 0) {
			ans += d[i];
			tmp++;
			d[i] = 0;
		}
	}
	cout << ans << endl;



	
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=1e3+20;

vector<int>ed[maxn];

int n,m;
int f[maxn][maxn];
int rt,D;
int g[maxn][maxn];
int vis[maxn];
int A[maxn],B[maxn];
int graph[maxn][maxn];

void bfs(int S)
{
	f[rt][S]=1;
	queue<int>q;
	q.push(S);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int v:ed[u])
		{
			if(!f[rt][v])
			{
				f[rt][v]=1;
				q.push(v);
			}
		}
	}
}

struct Edge {
	int u,v;
};
Edge E[200020];

void dfs1(int u)
{
	vis[u]=D;
	for(int v:ed[u])
	{
		if(vis[v])continue;
		dfs1(v);
	}
}

inline void init()
{
	n=read(); m=read();
	REP(i,1,m)
	{
		int u=read(),v=read();
		E[i]=(Edge){u,v};
		ed[u].push_back(v);
		graph[u][v]=1;
	}
	REP(u,1,n)
	{
		rt=u;
		bfs(u);
	}
	cerr<<(double)clock()/CLOCKS_PER_SEC<<endl;
	REP(u,1,n)
	{
		static int st[maxn],top; top=0;
		for(int v:ed[u])st[++top]=v;
		memset(vis,0,sizeof(int)*(n+1));
		vis[u]=top+1;
		REP(j,1,top)
		{
			D=j;
			if(!vis[st[j]])dfs1(st[j]);
		}
		memcpy(A,vis,sizeof(int)*(n+1));
		memset(vis,0,sizeof(int)*(n+1));
		vis[u]=top+1;
		DREP(j,top,1)
		{
			D=j;
			if(!vis[st[j]])dfs1(st[j]);
		}
		memcpy(B,vis,sizeof(int)*(n+1));
		REP(j,1,top)if(A[st[j]]!=B[st[j]])g[u][st[j]]=1;
		
	}
}

inline void doing()
{
	REP(i,1,m)
	{
		int u=E[i].u,v=E[i].v;
		if(f[v][u]^(g[u][v]))puts("diff");
		else puts("same");
	}
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 16384
import java.util.*;
public class Main {
	static int[] list;
    public static void main(String[] args){
    	Scanner sc =new Scanner(System.in);
    	int n= sc.nextInt();//0<=n<=44
    	list=new int[n+1];
    	Arrays.fill(list,0);
    	System.out.println(calcfib(list,n));
    }
    static int calcfib(int[] list,int i){
    	if(i==1||i==0){
    		return 1;
    	}else if(list[i]==0){
    		return list[i]=calcfib(list,i-1)+calcfib(list,i-2); 
    	}else{
    		return list[i];
    	}
    	
    }
}


Measured memory_bytes: 26420
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s, t; cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end()); reverse(t.begin(), t.end());
  if(s < t) {
    cout << "Yes" << endl;
  } else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
int main(){
    ll n; cin >> n;
    if(n%2==1) cout << 0 << endl;
    else{
        ll ans=0;
        ll res=10;
        while(res<=n){
            ans+=n/res;
            res*=5;
        }
        cout << ans;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef long long llint;
typedef vector<long long int> vint;
typedef vector< vector<int> > vvint;
typedef vector<string> vstr;


int main(void) {
	int r, D, x;
	cin >> r >> D >> x;
	for (int i = 0; i < 10; i++) {
		x = r * x - D;
		cout << x << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int maxn=1e6+13;

set<int> d[maxn];
int a[maxn];
int p[maxn];//筛出每个数最小素因子
int cnt[maxn]; 
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	p[1]=0;
	for(int i=2;i<=maxn;i++)
	{
		if(p[i]) continue;
		for(int j=i;j<=maxn;j+=i)
		{
			p[j]=i;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=a[i];p[j];j/=p[j])
		{
			d[i].insert(p[j]);
		}
	}
	int type=0;
	for(int i=1;i<=n;i++)
	{
		for(int j:d[i])
		{
			if(++cnt[j]>=2)
			{
				type=1;
			}
		}
	}
	int gcd=a[1];
	for(int i=2;i<=n;i++)
	{
		gcd=__gcd(gcd,a[i]);
	}
	if(gcd!=1)
	{
		printf("not coprime");
	}
	else if(gcd==1)
	{
		if(type==1)
		{
			printf("setwise coprime");
		}
		else
		{
			printf("pairwise coprime");
		}
	}
 } 

Measured memory_bytes: 295392
#include<stdio.h>
using namespace std;

int main(){
  int n,c[20],v[20],ans=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d",&c[i]);
  for(int i=0;i<n;i++)scanf("%d",&v[i]);
  for(int i=0;i<n;i++)if(c[i]>v[i])ans+=c[i]-v[i];
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
ya = [0] * 100001
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x**2 + y**2 + z**2 + x*y + y*z + z*x
            ya[n] += 1
n = I()
for i in range(1,n+1):
    print(ya[i])


Measured memory_bytes: 80180
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

LL fact[100005], ifact[100005];

LL bigmod(LL a, LL b) {
	if (b == 0) return 1;
	LL x = bigmod(a, b / 2);
	x = (x * x) % MOD;
	if (b & 1)  x = (x * a) % MOD;
	return x;
}


LL ncr(LL n, LL r) {
	if (n < r) return 0;
	LL x = fact[n];
	x *= ifact[n - r];
	x %= MOD;
	x *= ifact[r];
	x %= MOD;
	return x;
}

int a[100100];
int C[100100];

int main() {
	fact[0] = ifact[0] = 1;
	for (int i = 1; i <= 100001; i++) {
		fact[i] = (i * fact[i - 1]) % MOD;
		ifact[i] = bigmod(fact[i], MOD - 2);
	}
	int n;
	cin >> n;
	for (int i = 0; i < n + 1; i++) {
		cin >> a[i];
		C[a[i]]++;
	}
	int pos1 = -1, pos2;
	for (int i = 0; i < n + 1; i++) {
		if (C[a[i]] == 2) {
			if (pos1 == -1)pos1 = i + 1;
			else pos2 = i + 1;
		}
	}
	if (n == 1) {
		for (int i = 1; i <= n + 1; i++) {
			cout << 1 << endl;
		}
		return 0;
	}
	LL ans = 0;
	for (int i = 1; i <= n + 1; i++) {
		ans = ncr(n + 1, i);
		ans -= ncr(pos1 - 1 + n + 1 - pos2, i - 1);
		ans += MOD;
		ans %= MOD;
		//LL ans = (ncr(n + 1, i) + MOD - ncr(pos1 - 1+ n+  1 - pos2, i - 1)) % MOD;
		cout << ans << endl;
	}
	//system("pause");
}

Measured memory_bytes: 3584
MOD = 10 ** 9 + 7

# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

N = int(input())
S = input()

DOT = [0] * (N+1)
SHARP = [0] * (N+1)

for i in range(0, N):
    if S[i] == "#":
        SHARP[i+1] = SHARP[i] + 1
        DOT[i+1] = DOT[i]
    else:
        SHARP[i+1] = SHARP[i]
        DOT[i+1] = DOT[i] + 1

ret = 999999999999999

for d in range(N+1):
    # 0～dの#を.にかえる
    cnt1 = SHARP[d]
    # d+1～N-1の.を#にかえる
    cnt2 = DOT[N] - DOT[d]
    cnt = cnt1 + cnt2
    # print("{} + {} : {}".format(cnt1,cnt2,cnt))
    ret = min(cnt, ret)

# print("---")
print(ret)


Measured memory_bytes: 12808
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,m,i,j,k;
	ll x[3],t,ans=0ll;
	vector<ll> a[8];
	cin >> n >> m;
	for(i=0; i<n; ++i){
		for(k=0; k<3; ++k){
			cin >> x[k];
		}
		for(j=0; j<8; ++j){
			t = 0ll;
			for(k=0; k<3; ++k){
				t += ((j&(1<<k))?1ll:-1ll)*x[k];
			}
			a[j].push_back(t);
		}
	}
	for(j=0; j<8; ++j){
		t = 0ll;
		sort(a[j].begin(),a[j].end(),greater<ll>());
		for(i=0; i<m; ++i){
			t += a[j][i];
		}
		ans = max(t,ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/ruby
h=Hash.new(0)
gets.to_i.times{a,b=gets.split;h[a]+=b.to_i}
h.keys.sort{|a,b|x=a.size<=>b.size;x!=0?x:a<=>b}.each{|k|puts "#{k} #{h[k]}"}

Measured memory_bytes: 2740
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))



/* alias */


template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = 10001000100;
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


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


/* main */


signed main(){


    cin.tie(0);
    ios::sync_with_stdio(false);


    int h, w;
    cin >> h >> w;


	char arr[1000][1000];

	rep(i,0,h){
		rep(j,0,w){
			char tmp; cin >> tmp;
			arr[i][j] = tmp;
		}
	}

	int dp[1000][1000];

	dp[0][0] = 1;

	rep(i,0,h){
		rep(j,0,w){
			if(i == 0 && j == 0) continue;

			if(arr[i][j] == '#'){
				dp[i][j] = 0;
				continue;
			}

			if(i == 0){
				dp[0][j] = dp[0][j - 1];
				continue;
			}

			if(j == 0){
				dp[i][0] = dp[i - 1][0];
				continue;
			}

			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;

		}
	}

	print(dp[h - 1][w - 1] % mod);


	



	
	


	




	




    



	








    



    





    


    

}



Measured memory_bytes: 9088
#include<stdio.h>
int min(int x, int y)
{
	if(x<y) return x;
	return y;
}
int max(int x, int y)
{
	if(x>y) return x;
	return y;
}
int main()
{
	int a,b,c,i,j,k;
	scanf("%d %d %d", &a, &b, &k);
	for(i=a; i<=min(b,a+k-1); i++)
		printf("%d\n", i);
	for(i=max(a+k, b-k+1); i<=b; i++)
		printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;

ll len[1000001];
vector<int> child[1000001];

void bfs(int v,vector<int> &order) {
    queue<int> q; q.push(v);
    while(!q.empty()) {
        int v = q.front(); q.pop();
        order.push_back(v);
        for (int i=0; i<child[v].size(); ++i)
            q.push(child[v][i]);
    }
}

int main() {
    int n, m;
    cin>>n;
    vector<int> root;
    for (int i=0; i<n; ++i) {
        cin>>len[i]>>m;
        if (m != -1) child[m].push_back(i);
        else root.push_back(i);
    }
    vector<int> order;
    ll ans = 0;
    for (int i=0; i<root.size(); ++i) bfs(root[i], order);
    reverse(order.begin(), order.end());
    for (int i=0; i<order.size(); ++i) {
        int v = order[i];
        const int n = child[v].size();
        vector<ll> l(n);
        for (int p=0; p<n; ++p) l[p] = len[child[v][p]];
        sort(l.begin(), l.end());
        for (int p=0; p<n; ++p) {
            ans += (n-p-1) * l[p];
            //cout<<v<<" "<<l[p]<<" "<<(n-p-1) * l[p]<<endl;
            len[v] += l[p];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 68704
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    long long int r = 0, g = 0, b = 0, ans = 1;
    for(int i=0; i<n; i++){
        if(a[i] == r && a[i] == g && a[i] == b){ ans *= 3; r += 1; }
        else if(a[i] == r && a[i] == g){ ans *= 2; r += 1; }
        else if(a[i] == g && a[i] == b){ ans *= 2; g += 1; }
        else if(a[i] == r) r += 1;
        else if(a[i] == g) g += 1;
        else if(a[i] == b) b += 1;
        else ans = 0;

        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4028
n, x, m = map(int, input().split())

mn = min(n, m)
P = [] # value of pre + cycle
sum_p = 0 # sum of pre + cycle
X = [False] * m

for i in range(mn):
    if X[x]: break
    X[x]  = True
    P.append(x)
    sum_p += x
    x = x*x % m

if len(P) >= mn:
    print(sum_p)
    exit()

pre_len = P.index(x)
cyc_len = len(P) - pre_len
nxt_len = (n - pre_len) % cyc_len

cyc_num = (n - pre_len) // cyc_len

pre = sum(P[:pre_len])
cyc = sum_p - pre
nxt = sum(P[pre_len: pre_len + nxt_len])

print(pre + cyc * cyc_num + nxt)


Measured memory_bytes: 11816
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second

main(){
    int n;
    cin>>n;
    set<string>st;
    string s,t;
    cin>>s;
    st.insert(s);
    r(i,n-1){
        cin>>t;
        if(st.count(t)){
            cout<<"No"<<endl;
            return 0;
        }
        st.insert(t);
        if(s[s.size()-1]!=t[0]){
            cout<<"No"<<endl;
            return 0;
        }
        swap(t,s);
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    int a, b;
    cin >> a >> b;

    string str_a = to_string(a), str_b = to_string(b);

    string ans0, ans1;
    rep(i, b) { ans0 += str_a; }
    rep(i, a) { ans1 += str_b; }

    string temp[2];
    temp[0] = ans0;
    temp[1] = ans1;

    sort(temp, temp + 2);

    cout << temp[0] << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, p;
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> p >> s;

  ll ret = 0;

  if(p == 2 || p == 5) {
    REP(i, n) {
      if((s[i] - '0') % p == 0) ret += (i+1);
    }
  } else {
    map<int, int> mp;
    mp[0] = 1;
    ll cur = 0, p10 = 1;
    RREP(i, n) {
      cur = (cur + (s[i] - '0')*p10) % p;
      ret += mp[cur];
      mp[cur]++;
      (p10*=10) %= p;
    }
  }

  cout << ret << endl;
}


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

using namespace std;

const double PI = acos(-1);

int main()
{
  while(1)
  {
    long long n;
    cin >> n;
    if(n == 0)
      exit(0);
    vector<long double> s(n);
    for(long long i = 0;i < n;i++)
    {
      cin >> s[i];
    }
    long double h = accumulate(s.begin(), s.end(), 0.) / s.size();
    for(long long i = 0;i < n;i++)
    {
      s[i] -= h;
      s[i] = s[i] * s[i];
    }
    cout << fixed << setprecision(20) << sqrtf(accumulate(s.begin(), s.end(), 0.) / s.size()) << endl;
  }
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 998244353
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

const int maxa = 3000;

void solve() {
	int n, s;
	cin >> n >> s;
	
	vi a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int ans = 0;
	vvi dp(n + 1, vi(maxa + 1, 0));
	dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= s; j++) {
			if(j + a[i] > s) continue;
			dp[i + 1][j + a[i]] += dp[i][j];
			assert(dp[i + 1][j + a[i]] >= 0);
			dp[i + 1][j + a[i]] %= P;
		}
		
		for(int j = 0; j <= s; j++) {
			dp[i + 1][j] += (dp[i][j] * 2) % P;
			assert(dp[i + 1][j] >= 0);
			dp[i + 1][j] %= P;
		}
	}	
	
	cout << dp[n][s] << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 38620
n, c, k = map(int, raw_input().split())
arr = [input() for i in xrange(n)]
arr.sort()

res = 1
start = arr[0]
cur = c

for pas in arr:
	if c == 0:
		c = cur
		start = pas
		res += 1

	if pas <= start + k:
		c -= 1
	else:
		res += 1
		c = cur -1
		start = pas

print res
		


Measured memory_bytes: 6336
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  vector<int> button(a);
  int i = 0;
  int aa = a;
  while(aa > 0){
    int b;
    cin >> b;
    button.at(i) = b;
    i++;
    aa--;
  }
  int now = button.at(0);
  int count = 1;
  while(true){
    if(now == 2){
      cout << count << endl;
      break;
    }
    else if(count > a){
      cout << -1 << endl;
      break;
    }
    count++;
    now = button.at(now-1);
  }
}
  

Measured memory_bytes: 640
import math
n, d = map(int,input().split())
list = []
counter = 0
pre_a = pre_b = 0

for i in range(n):
    a,b=map(int,input().split())
    if pre_a == a and pre_b == b:
        pass
    mile = math.sqrt(a**2 + b**2)
    if mile <= d:
        counter += 1
    a = pre_a
    b = pre_b
print(counter)



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

int main(int argc, const char * argv[]) {
    
    int N, M;
    cin >> N;
    string s;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> s;
        S[i] = s;
    }
    cin >> M;
    vector<string> T(M);
    for (int i = 0; i < M; i++) {
        cin >> s;
        T[i] = s;
    }
    int cnt, max = -1;
    //string max_s;
    for (int i = 0; i < N; i++) {
        cnt = 1;
        for (int j = i + 1; j < N; j++) {
            if (S[i] == S[j]) {
                cnt++;
            }
        }
        if (cnt > max) {
            for (int j = 0; j < M; j++) {
                if (S[i] == T[j]) {
                    cnt--;
                }
            }
            if (cnt > max) {
                //max_s = S[i];
                max = cnt;
            }
        }
    }
    if (max < 0) {
        max = 0;
    }
    cout << max << endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
dum = list(map(int, input().split()))

ans = [-1] * n

ans[0] = sum(dum[::2]) - sum(dum)//2

for i in range(1,n):
	ans[i] = dum[i-1] - ans[i-1]

for i in range(n):
	ans[i] *= 2
	ans[i] = str(ans[i])

print(" ".join(ans))


Measured memory_bytes: 17468
n,x=map(int,input().split())
if n==2and x==2:
    print('Yes',*[1,2,3],sep='\n')
    exit()
a=[[]for _ in range(2*n-1)]
a[n-1]=x
f=[0]*2*n
f[x]=1
try:
    if x>2*n-3:
        a[n-3]=x-2
        a[n-2]=x+1
        a[n]=x-1
        f[x-2]=f[x-1]=f[x+1]=1
    else:
        a[n-3]=x+2
        a[n-2]=x-1
        a[n]=x+1
        f[x-1]=f[x+1]=f[x+2]=1
    if f[0]:
        1/0
except:
    print('No')
    exit()
i=0
for j,v in enumerate(f[1:],1):
    if v:continue
    while a[i]:i+=1
    a[i]=j
print('Yes',*a,sep='\n')

Measured memory_bytes: 61936
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

struct Event {
        int t;
        int event;
        int x;
};

int sortfunc(struct Event &lhs, struct Event &rhs)
{
        if (lhs.t != rhs.t) {
                return lhs.t < rhs.t;
        }
        return lhs.event < rhs.event;
}

int main()
{
        int n, q;
        vector<Event> events;
        set<int> xset;

        cin >> n >> q;
        for (int i = 0; i < n; ++i) {
                int s, t, x;
                cin >> s >> t >> x;
                events.push_back({s - x, 1, x});
                events.push_back({t - x, -1, x});
        }

        for (int i = 0; i < q; ++i) {
                int d;
                cin >> d;
                events.push_back({d, 2, 0});
        }

        sort(events.begin(), events.end(), sortfunc);

        for (auto event = events.begin(); event != events.end(); ++event) {
                if (event->event == 1) {
                        xset.insert(event->x);
                }
                if (event->event == -1) {
                        xset.erase(event->x);
                }
                if (event->event == 2) {
                        if (xset.empty()) {
                                cout << -1 << endl;
                        }
                        else {
                                cout << *(xset.begin()) << endl;
                        }
                }
        }

        return 0;
}


Measured memory_bytes: 18152
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()

if s[-1] == 's':
    print(s+'es')
else:
    print(s+'s')

Measured memory_bytes: 9044
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)

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

const int MOD = 1e9 + 7;
const int maxn = 1;
const double EPS = 1e-8;

map<string, map<int, int>>mp;
class BGuidebook {
public:
	void solve(std::istream& in, std::ostream& out) {
		int N, P;
		string s;
		in >> N;
		mp.clear();
		for (int i = 0; i < N; ++i)
		{
			in >> s >> P;
			mp[s][P] = i+1;
		}
		for (auto it = mp.begin(); it != mp.end(); ++it)
		{
			vector<int>v;v.clear();
			for(auto tt = (it->second).begin(); tt != (it->second).end(); ++tt)v.push_back(tt->second);
			for (int i = v.size() - 1; i >= 0; --i) {
				out << v[i] << endl;
			}
		}
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	BGuidebook solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << "\n"; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


VV G;
V a, dp, ans;

int dfs(int u, int p=-1) {
  ans[u] = lower_bound(all(dp), INF-1) - dp.begin() - 1;
  for (auto &v : G[u]) {
    if (v == p) continue;
    int i = lower_bound(all(dp), a[v]) - dp.begin();
    int tmp = dp[i];
    dp[i] = a[v];
    dfs(v, u);
    dp[i] = tmp;
  }
  return 0;
}


int main() {
  ll n; cin >> n;
  G.assign(n, V());
  a.assign(n, 0);
  dp.assign(n+1, INF);
  ans.assign(n, INF);
  dp[0] = -INF;
  cin >> a;

  rep(i, n-1) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  int v = 0;
  int i = lower_bound(all(dp), a[v]) - dp.begin();
  dp[i] = a[v];
  dfs(v);

  cout << ans;
  return 0;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int n; cin >> n;
    ll count_p = 0;
    ll count_m = 0;
    vector<int> A(n), B(n);
    rp(i, 0, n){
        scanf("%d", &A[i]);
    }
    rp(i, 0, n){
        scanf("%d", &B[i]);
    }
    rp(i, 0, n){
        int a = A[i];
        int b = B[i];
        int c = a - b;
        if(c > 0) count_m += c;
        if(c < 0) {
            c = -c;
            count_p += c/2;
        }
    }
    if(count_p >= count_m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    unordered_map<string, ll> mp;
    for (ll i = 0; i < N; i++) {
        string s;
        cin >> s;
        ++mp[s];
    }
    ll M;
    cin >> M;
    for (ll i = 0; i < M; i++) {
        string s;
        cin >> s;
        --mp[s];
    }

    ll ans = 0;
    for (const auto& p : mp) {
        ans = max(ans, p.second);
    }
    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void debug() { std::cerr << '\n'; }
template <class H, class... T> void debug(H &&head, T &&... args) {
    std::cerr << head;
    sizeof...(args) == 0 ? std::cerr << "" : std::cerr << ' ';
    debug(std::forward<T>(args)...);
}
template <class T> void debug(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cerr << v[i];
        i == v.size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
    }
}
template <class T> void debug(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cerr << v[i][j];
            j == v[i].size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
        }
    }
}

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

    string s;
    cin >> s;
    auto yes = []() {
        print("Yes");
        exit(0);
    };
    auto no = []() {
        print("No");
        exit(0);
    };
    REP(i, s.size()) {
        if (i % 2 != 0) {
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D')
                no();
        } else {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D')
                no();
        }
    }
    yes();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <list>
#include <map>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define rep(i,n) for(register int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
//const int MOD=998244353;
const int N=2e5+10;

inline int read(){
	int ww=1,xx=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') ww=-ww;ch=getchar();}
	while(isdigit(ch)){xx=(xx<<1)+(xx<<3)+(ch^48);ch=getchar();}
	return ww*xx;
}

int n=read();
int head[N];
int cnt;
int dist1[N],dist2[N],ans;

struct Edge{
	int to,nxt;
}ed[N];

void add_edge(int a,int b){
	ed[++cnt].to=b;
	ed[cnt].nxt=head[a];
	head[a]=cnt;
}

void dfs1(int u,int p){
	for(int i=head[u];i!=-1;i=ed[i].nxt){
		int v=ed[i].to;
		if(v!=p){
			dist1[v]=dist1[u]+1;
			dfs1(v,u);
		}
	}
}

void dfs2(int u,int p){
	for(int i=head[u];i!=-1;i=ed[i].nxt){
		int v=ed[i].to;
		if(v!=p){
			dist2[v]=dist2[u]+1;
			dfs2(v,u);
		}
	}
}

signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	for(int i=1;i<=n;i++) head[i]=-1;
	for(int i=1;i<n;i++){
		int fr,to;
		fr=read();
		to=read();
		add_edge(fr,to);
		add_edge(to,fr);
	}
	dist1[1]=0;
	dist2[n]=0;
	dfs1(1,-1);
	dfs2(n,-1);
	for(int i=1;i<=n;i++)
		if(dist1[i]<=dist2[i])
			ans++;
	if(ans>n-ans) puts("Fennec");
	else puts("Snuke");
	return 0;
}
/*
7
3 6
1 2
3 1
7 4
5 7
1 4

4
1 4
4 2
2 3
*/

Measured memory_bytes: 7680
N,M=map(int,input().split())
x=sorted(list(map(int,input().split())))
y=[]
for i in range(M-1):
   y.append(x[i+1]-x[i])
y=sorted(y)
z=0
for i in range(M-N):
  z+=y[i]
print(z)  
  

Measured memory_bytes: 13960
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>

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

using namespace std;

typedef long long ll;

int N, C;
vector<vector<int>> vD;
vector<vector<int>> vC;
vector<int> a;
vector<int> b;
vector<int> c;

int main()
{
  cin >> N >> C;
  a = vector<int>(C, 0);
  b = vector<int>(C, 0);
  c = vector<int>(C, 0);
  vD = vector<vector<int>>(C, vector<int>(C));
  vC = vector<vector<int>>(N, vector<int>(N));
  for (int i = 0; i < C; i++)
  {
    for (int j = 0; j < C; j++)
    {
      cin >> vD[i][j];
    }
  }
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      cin >> vC[i][j];
      vC[i][j]--;
    }
  }
  for (int h = 0; h < C; h++)
  {
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      {
        if ((i + j) % 3 == 0)
        {
          a[h] += vD[vC[i][j]][h];
        }
        else if ((i + j) % 3 == 1)
        {
          b[h] += vD[vC[i][j]][h];
        }
        else
        {
          c[h] += vD[vC[i][j]][h];
        }
      }
    }
  }
  int res = 1e9;
  REP(i, C)
  {
    REP(j, C)
    {
      if (i != j)
      {
        REP(h, C)
        {
          if (i != h && j != h)
          {
            res = min(res, a[i] + b[j] + c[h]);
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1408
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

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

  int m; cin >> m;
  REP(t,m){
	int init; cin >> init;
	int year; cin >> year;
	int n; cin >> n;
	int ans = 0;
	REP(i,n){
	  int kind;
	  double a, b;
	  cin >> kind >> a >> b;
	  int now = init;
	  if(kind == 1){
		REP(y,year){
		  now = now + (int)(now*a) - b;
		}
	  }
	  else{
		int sum = 0;
		REP(y,year){
		  sum += (int)(now*a);
		  now -= b;
		}
		now = now + sum;
	  }
	  ans = max(ans, now);
	}
	cout << ans << endl;
  }

  return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  for(int i=1;i<=b;i++){
    if((a*i-c)%b==0){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b,c,k;
  int sum=0;
  
  scanf("%d %d %d %d", &a, &b, &c, &k);
  
  while(a>0&&k>0){
    sum++;
    a--;
    k--;
  }
  while(b>0&&k>0){
    b--;
    k--;
  }
  while(c>0&&k>0){
    sum--;
    k--;
  }
  
  printf("%d", sum);
  
  return 0;
}
  
  

Measured memory_bytes: 1732
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, K, Q, A[112345],C[112345];

int main() {

	scanf("%d%d%d", &N,&K,&Q);
	rep(i, Q) scanf("%d", &A[i]);

	rep(i, Q) {
		C[A[i] - 1]++;
	}

	rep(i, N) {
		if (K - Q + C[i] > 0) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}

	return 0;
}


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

int gen[1000000];
int used[1000001];
int main(){
	vector<int> p;
	for(int i = 0 ; i < 1000000 ; i++) gen[i] = 1;
	gen[0] = gen[1] = 0;
	for(int i = 0 ; i*i < 1000000 ; i++){
		if(gen[i]){
			for(int j = i*i ; j < 1000000 ; j+=i)
				gen[j] = 0;
		}
	}
	for(int i = 0 ; i < 1000000 ; i++) if(gen[i])p.push_back(i);
	
	long long A,B;
	cin >> A >> B;
	
	long long X = max(2ll,A-B) , Y = A+B;
	if(Y<2){ cout << 0 << endl; return 0; }
	
	for(int i = 0 ; i <= 1000000 ; i++) used[i] = 9999999;
	
	for(int i = 0 ; i < p.size() ; i++){
		for(long long j = X+(p[i]-X%p[i])%p[i] ; j <= Y ; j += p[i]){
			//if(used[j]==-1) continue;
			long long n_ = j , ok = 0;
			while(n_%p[i]==0) ok++ , n_ /= p[i];
			if(ok){
				if(used[j-X] >= ok){
					used[j-X] = ok;
				}else{
					used[j-X] = -1;
				}
			}
			//cout << p[i] << " " << ok << " " << used[j-X] << endl;
		}
	}
	int ans = 0;
	for(int i = 0 ; i <= Y-X ; i++){
		if(used[i] != -1) ans++;
	}
	cout << ans << endl;

}

Measured memory_bytes: 9128