akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 100005
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int a[MN];
int n,l,cur;
bool mk;
int main()
{
	n=in();l=in();
	for (int i=1;i<=n;++i) a[i]=in();
	for (int i=1;i<n;++i) if (a[i]+a[i+1]>=l){cur=i;mk=1;break;}
	if (!mk) {printf("Impossible");return 0;}
	else puts("Possible");
	for (int i=1;i<cur;++i) printf("%d\n",i);
	for (int i=n-1;i>cur;--i) printf("%d\n",i); 
	printf("%d",cur);return 0;
}

Measured memory_bytes: 1152
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:64000000")
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <cctype>
#include <numeric>
#include <memory>
#if __cplusplus >= 201103L
#include <cwchar>
#include <cwctype>
#include <array>
#include <forward_list>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
inline bool check(string s){
	if(s.size()&1) return false;
	string a=s.substr(0,s.size()/2),b=s.substr(s.size()/2);
	return a==b;
}
int main(){
	string s;
	cin>>s;
	s.pop_back(); 
	while(!check(s)){
		s.pop_back();
	}
	cout<<s.size()<<endl;
	#ifdef home
	eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
	#endif
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e6+5;
ll cnt[N][5];
map<char ,int> mp;
char ch[5] = {'F','R','G','B'};
void solve(){
	mp['R'] = 1;
	mp['G'] = 2;
	mp['B'] = 3;
	
	int n; 
	cin>>n; 
	string s; 
	cin>>s; 
	ll ans = 0;
	cnt[0][mp[s[0]]]++;
	for(int j=1;j<n;j++){
		for(int k=j+1;k<n;k++){
			if(s[j]==s[k])continue;
			ans+=cnt[j-1][6-mp[s[j]]-mp[s[k]]];
			int dis = k-j;
			if(j-dis>=0 and s[j-dis]==ch[6-mp[s[j]]-mp[s[k]]]){
				ans--;
			}
		}
		cnt[j][1] = cnt[j-1][1];
		cnt[j][2] = cnt[j-1][2];
		cnt[j][3] = cnt[j-1][3];
		
		cnt[j][mp[s[j]]]++;
	}
	for(int i=0;i<n;i++){
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3760
#include <cstdio>
#include <algorithm>
#define INT long long
using namespace std;
int n, q, l, h[100010], dt[20][100010];

int main()
{
    scanf("%d", &n);
    for(int i = 1 ; i <= n ; i++ ) scanf("%d", h+i);
    scanf("%d%d", &l, &q);
    for(int i = 1 ; i <= n ; i++ )
        dt[0][i] = (int)(upper_bound(h+1, h+n+1, h[i]+l) - h) - 1;
    for(int j = 1 ; j < 20 ; j++ )
        for(int i = 1 ; i <= n ; i++ )
            dt[j][i] = dt[j-1][dt[j-1][i]];
    while( q-- )
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if( a > b ) swap(a,b);
        int cnt = 0, d;
        for(int i = 19 ; i >= 0 ; i-- )
        {
            if( dt[i][a] < b )
            {
                d = 0;
                a = dt[i][a];
                cnt += (1<<i);
            }
            else d = i;
        }
        printf("%d\n", cnt+(1<<d));
    }
}


Measured memory_bytes: 8960
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
 
using namespace std;

struct Point {
  double x;
  double y;
  double z;
  Point() {;}
  Point(double x, double y, double z) : x(x), y(y), z(z) {;}
};
 
int n;
Point point[100];

template <class T>
T square(T x) { return x * x; }

inline double len(const Point &a, const Point &b) {
  return sqrt(square(a.x - b.x) + square(a.y - b.y) + square(a.z - b.z));
}
 
double calc() {
  Point p(50.0, 50.0, 50.0);
  double ratio = 0.5;
  double ans = 100000000;
  while (ratio > 1e-10) {
    for (int iter = 0; iter < 100; iter++) {
      int index = 0;
      double length = 0;
      for (int i = 0; i < n; i++) {
        if (length < len(point[i], p)) {
          length = len(point[i], p);
          index = i;
        }
      }
      ans = min(ans, length);
      p.x += (point[index].x - p.x) * ratio;
      p.y += (point[index].y - p.y) * ratio;
      p.z += (point[index].z - p.z) * ratio;
    }
    ratio /= 2.0;
  }
  return ans;
}
 
int main() {
  while (scanf("%d", &n), n) {
    for (int i = 0; i < n; i++) {
      double x, y, z;
      scanf("%lf %lf %lf", &x, &y, &z);
      point[i] = Point(x, y, z);
    }
    printf("%.5lf\n", calc());
  }
}

Measured memory_bytes: 0
# n : 全日数　k：働く日数　c：働いた日からその後働かない日数
n, k, c = map(int, input().split())
s = input()

## 前から貪欲的に働く日を求める l
l = []
i = 0
num = 0
while num < k:
    if s[i] == 'o':
        l.append(i)
        num += 1
        i += c + 1
    else:
        i += 1

## 後ろから貪欲的に働く日を求める r
r = []
num = 0
i = n - 1
while num < k:
    if s[i] == 'o':
        r.append(i)
        num += 1
        i -= c + 1
    else:
        i -= 1
r.reverse()

for i in range(k):
    if l[i] == r[i]:
        print(l[i] + 1)

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

int main(void){
    int i=0;
    int cnt = 0;
    char l, a[20];
    while(cin>>l){
        a[i] = l;
        i++;
    }
    for( int j = 0; j < i; j++){
        if(a[j] == 'o') cnt++;
    }
    if((15-(i-cnt)) > 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;


int main()
{
	string S,T;
	cin>>S;
	cin>>T;
	vector<int> RS(26,-1);
	vector<int> RT(26,-1);
	bool ans = true;
	for(int i = 0; i < S.length(); i++){
		int s = S[i] - 'a';
		int t = T[i] - 'a';
		if( RS[s] < 0){
			RS[s] = t;
		}else{
			if( RS[s] != t){
				ans = false;
				break;
			}
		}
		if( RT[t] < 0){
			RT[t] = s;
		}else{
			if(RT[t] != s){
				ans = false;
				break;
			}
		}

	}
	if(ans == true){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3448
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ic pair <int, char>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;

/*int intConvert(string s){
    int n;
    stringstream geek(s);
    geek >> n;
    return n;
}*/

/*string strConvert(int n){
    string s;
    stringstream ss;
    ss << n;
    s=ss.str();
    return s;
}*/


int main(){
    int a,b,c,d,e;
    scanf("%d %d %d %d %d",&a, &b, &c, &d, &e);

    if(a<=0){
        int ans = (c*abs(a)+d);
        int ans1 = b*e;
        pf("%d\n",(ans1+ans));
    }
    else{
        int ans = (b-a)*e;
        pf("%d\n",ans);
    }

    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int A, B, C;
	cin >> A >> B >> C;

	bool b = false;
	if ((C >= A) && (C <= B)) {
		b = true;
	}

	cout << (b ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define fin freopen("E:/in.txt", "r", stdin)
#define fout freopen("E:/out.txt", "w", stdout)
#define ms(a, x) memset(a, x, sizeof(a))
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, b) for(int i = n; i >= a; i--)
typedef long long ll;
typedef long double ld;
const int maxn = 1e5+5;
const int mod = 1e9+7;
using namespace std;
typedef pair<int, int> pii;

int main(){
    int n;
    string s = "Hello World";
    cin >> n;
    if(n == 1){
        cout << s << endl;
    }
    else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t n;
  ll k;
  cin >> n >> k;
  vector <ll> height (n);
  rep (i, n) cin >> height [i];

  auto ans = count_if (ALL (height), [&] (auto && x) {
    return x >= k;
  });
  cout << ans << endl;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N,M; cin >> N >> M;
    VI A(M); REP(i,M) cin >> A[i];
    int sum = 0; REP(i,M) sum += A[i];
    cout << (sum<=N ? N-sum : -1) << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.io.*;
import java.util.*;

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

	public Main() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int x = fs.nextInt(), y = fs.nextInt();
		if(x <= y) out.println("unsafe");
		else out.println("safe");
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

Measured memory_bytes: 32500
#include<bits/stdc++.h>
using namespace std;int main(){long n,a,b,c,d;cin>>n>>a>>b>>c>>d;for(long k=0;k<n;k++)if(c*k-d*(n-1-k)<=b-a&&b-a<=d*k-c*(n-1-k)){cout<<"YES";return 0;}cout<<"NO"; }

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

int main() {
    std::string s;

    std::cin >> s;

    for (int i = s.length() - 7; i >=  0; i--) {
        std::string s7 = s.substr(i, 7),
            s6 = s.substr(i + 1, 6),
            s5 = s.substr(i + 2, 5);
        //std::cout << s7 << " " << s6 << " " << s5 << std::endl;
        if (s7 == "dreamer") i -= 6;
        else if (s6 == "eraser") i -= 5;
        else if (s5 == "dream" || s5 == "erase") i -= 4;
        else {
            std::cout << "NO" << std::endl;
            return 0;
        }
    }

    std::cout << "YES" << std::endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,K;
    cin>>n>>K;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int dp[n+1];
    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);
    for(int i=2;i<n;i++)
    {
        dp[i] = INT_MAX;
        for(int j=i-1;j>=max(0,i-K);j--)
            dp[i] = min(dp[i],dp[j] + abs(a[i] - a[j]));
    }
     cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
constexpr int MOD = 1000000007;
using ll = long long;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  
  vector<int> x(n + 1, 0), y(n + 1, 0), z(n + 1, 0);
  vector<int> t(n);
  for (int i = 0; i < n; i++) {
    x[i + 1] = x[i];
    y[i + 1] = y[i];
    z[i + 1] = z[i];
    if (x[i] == a[i])
      x[i + 1]++;
    else if (y[i] == a[i])
      y[i + 1]++;
    else if (z[i] == a[i])
      z[i + 1]++;
    
    int ti = 0;
    if (x[i] == a[i])
      ti++;
    if (y[i] == a[i])
      ti++;
    if (z[i] == a[i])
      ti++;
    t[i] = ti;
  }
  
  ll total = 1;
  for (int i = 0; i < t.size(); i++) {
    total *= t[i];
  	total %= MOD;
  }
  cout << total << endl;
  
  return 0;
}

Measured memory_bytes: 2304
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int a[M+4];

 main()

{
    fast
    int n,l;
    cin>>n>>l;
    f(i,1,n)
    {
        cin>>a[i];
    }
    int yo=-1;
    for(int i=1;i<n;i++)
    {
        int len=a[i]+a[i+1];
        if(len>=l)
        {
            yo=i;
            break;
        }
    }
    if(yo==(-1))
    {
        cout<<"Impossible"<<endl;
        return 0;
    }
    cout<<"Possible"<<endl;
    f(i,1,yo-1)
    {
        cout<<i<<" ";
    }
    rf(i,n-1,yo+1)
    {
        cout<<i<<" ";
    }
    cout<<yo<<endl;
    return 0;

}













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

namespace _0227
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] vs = RArInt();
                if (vs.Sum() == 0) break;
                Console.WriteLine(RArInt().OrderByDescending(x => x).Where((x, i) => i % vs[1] != vs[1] - 1).Sum());
            }
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



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

int main() {
    double r, g;
    cin >> r;
    cin >> g;

    // R: 現在のレーティング
    // G: 次のコンテストで設定したいレーティング

    g *= 2.0;
    cout << g - r;

}


Measured memory_bytes: 256
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
int n;
int b=0,r=0;
string s;
cin>>n;
cin>>s;
forn(i,n)
{
  if(s[i]=='R')
  r++;
  else
  b++;
}
if(r>b)
cout<<"Yes";
else
cout<<"No";

    return 0;
  }


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

using namespace std;

int main() {

    int n, r, t;
    int p[100];
    int pos[100];
    int empty[1000], filled[1000];
    int ans = 0;

    cin >> n >> r >> t;

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

    fill(pos, pos + 100, 0);
    fill(empty, empty + 1000, 0);
    fill(filled, filled + 1000, 0);

    for(int i = 0; i < t; ++i) {

        for(int j = 0; j < n; ++j) {

            pos[j] = (pos[j] + p[j]) % r;

            if(i) {
                ++empty[pos[j]];
            }

            if(filled[pos[j]] > 0) {
                --filled[pos[j]];
            } else {
                ++ans;
            }

        }

        for(int j = 0; j < r; ++j) {
            if(empty[j]) {
                filled[j] += empty[j];
                empty[j] = 0;
            }
        }

    }

    cout << ans << endl;

}

Measured memory_bytes: 3084
lines = $stdin.read
array = lines.split("\n")
N,M,D = array[0].split(" ").map(&:to_i)

ans = if D.zero?
        1.quo(N)
      else
        (2*(N - D)).quo(N**2)
      end

puts "%.10f" % ((M-1)*ans).to_f

Measured memory_bytes: 1916
N, M = list(map(int, input().split()))
dest_list_1 = list()
dest_list_2 = list()

for _ in range(M):
    a, b = list(map(int, input().split()))

    if a == 1:
        dest_list_1.append(b)
    elif b == 1:
        dest_list_1.append(a)
    elif a == N:
        dest_list_2.append(b)
    elif b == N:
        dest_list_2.append(a)

len_dest_1 = len(dest_list_1)
len_dest_2 = len(dest_list_2)

if len(set(dest_list_1 + dest_list_2)) == len_dest_1 + len_dest_2:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')


Measured memory_bytes: 24908
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String S = scanner.next();
    
    int N = S.length();
    String S1 = S.substring(0,(N - 1) / 2);
    String S2 = S.substring((N + 3) / 2 - 1,N);
    
    String answer = "No";
    if(k(S,N) && k(S1,S1.length()) && k(S2,S2.length())){
      answer = "Yes";
    }
    
    System.out.println(answer);
  }
  
  public static boolean k(String str,int length){
    for(int i = 0;i < (length + 1) / 2;i++){
         /*System.out.println(
          i + "," + 
          str.charAt(i) + "," + str.charAt(length - i - 1));
      */
      if(str.charAt(i) != str.charAt(length - i - 1)){
        return false;
      }
    }
    return true;
  }
}

Measured memory_bytes: 23124
// I - Coins
#include <bits/stdc++.h>
using namespace std;
using dl = double;

int main(){
	int N; scanf("%d",&N);
	vector<dl> dp(N+1);
	for(int i=(N+1)/2; i<=N; i++) dp[i] = 1.;
	for(int i=1; i<=N; i++){
		dl p,q; scanf("%lf",&p); q = 1.-p;
		for(int j=0; j<=N-i; j++) dp[j] = q*dp[j] + p*dp[j+1];
	}
	printf("%.10g\n",dp[0]);
}

Measured memory_bytes: 256
// finish date: 2018/02/11

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N, A, B;
    cin >> N >> A >> B;
    vi h(N);
    rep(i, N) cin >> h[i];
    int l = 1, r = 1e9;
    int m;
    ll c;
    ll life;
    int ans = 0;
    while (l <= r) {
        c = 0;
        m = (l + r) / 2;
        rep(i, N) {
            life = (ll)h[i] - (ll)m * B;
            if (life > 0) {
                c += (life + (A - B) - 1) / (A - B);
            }
        }
        if (c <= m) {
            ans = m;
            r = m - 1;
        } else {
            l = m + 1;
        }
    }
    cout << ans << endl;

    return 0;
}




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

int main() {
  ll A,B,K;
  cin>>A>>B>>K;
  if(A<=K){
    K-=A;
    A=0;
    if(B<=K){
      B=0;
    }else B-=K;
  }else A-=K;
  cout<<A<<" "<<B<<endl;
}	


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int a,p;
    Scd2(a,p);

    printf ("%d\n", (a*3+p)/2 );

    return 0;
}



Measured memory_bytes: 256
import java.lang.Math.*
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val N = scn.nextInt()

    var list = arrayOfNulls<Int>(N+1)
    for(i in 1..N){
        list[i] = scn.nextInt()
    }

    var dp = arrayOfNulls<Int>(N+1)
    for(i in 1..N){
        dp[i] = 0
    }

    dp[2] = abs(list[2]!! - list[1]!!)
    for(i in 3..N){
        var j1 = abs(list[i]!! - list[i-1]!!) + dp[i-1]!!
        var j2 = abs(list[i]!! - list[i-2]!!) + dp[i-2]!!
        dp[i] = min(j1,j2)
    }

    println(dp[N])
}

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

using namespace std;

int main() {
  int A, B, C, K;
  
  cin >> A >> B >> C >> K;
  
  for (int i = K; i > 0; i--) {
    if (A >= B) {
      B *= 2;
    } else if (B >= C){ 
      C *= 2;
    }
  }
  
  if (A < B && B < C) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <vector>
#include <cstdlib>

using namespace std;

int main(int argc, const char * argv[]) {
	int N ;

	cin >> N;

	for (int i = 1; i < 10; i++){
		for (int j = 1; j < 10; j++)
		{
			if ((i * j) == N){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	ll n, k;
	cin >> n >> k;
	//~ while (n < k) {
		//~ n += n;
	//~ }
	cout << min(n % k, k - n % k) << '\n';
 	return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;

int main() {
	int N;
	int i;
	int flag = 0;
	int ngFlag = 0;
	int A[200] = {};
	cin >> N;
	for (i = 0; i < N; ++i) {
		cin >> A[i];
	}

	for (i = 0; i < N; ++i) {
		flag = 0;
		if (A[i] % 2 == 0) {
			if (A[i] % 3 == 0) {
				++flag;
			}
			if (A[i] % 5 == 0) {
				++flag;
			}
			if (flag == 0) {
				++ngFlag;
				break;
			}
		}



	}

	if (ngFlag >0) {
		cout << "DENIED" << endl;
	}
	else {
		cout << "APPROVED" << endl;
	}




}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String []args)
    {
        Scanner sc=new Scanner(System.in);
        int  n=sc.nextInt();
        int K=sc.nextInt();
        String S=sc.next();
        int p=S.charAt(K-1);
        char x=(char)(p+32);
System.out.print(S.substring(0,(K-1))+x+S.substring(K));
}
}


Measured memory_bytes: 22096
#include<stdio.h>
int main(void)
{
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(w>=x+r&&0<=x-r&&h>=y+r&&0<=y-r)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, from, to) for (int i = from; i < (to); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int, int>> vii;

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

    int n, k;
    cin >> n >> k;

    vi as(n+1);

    rep(i,0,n) {
        int a;
        cin >> a;
        as[a]++;
    }

    vi b;
    rep(i,0,n+1) {
        if (as[i] != 0) {
            b.push_back(as[i]);
        }
    }
    sort(b.begin(), b.end());

    int re = 0;

    int in = 0;
    while (b.size() - in > k) {
        re += b[in];
        in++;
    }

    cout << re << endl;

    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(void){
  long long A,B,C,K;
  cin >> A >> B >> C >> K;
 
  if(A < K){
    if(A+B<K){
      cout << A-abs(K-(A+B)) << endl;
    }
    else{
      cout << A << endl;
    }
  }
  else{
    if(A > K){
      cout << K << endl;
    }
    else{
      cout << A << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3644
/* Author rumoisen */
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
 
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
 
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ans;
    for(int i=1;;i++){
        if(i*i>n){
            ans=(i-1)*(i-1);
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


void solve(long long N){
    for(int i = 0;i <= N;i++){
        if(int(1.08 * i) == N){
            cout<<i<<endl;
            return;
        }
    }
    cout<<":("<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int num,a,b,t;
int main()
{
	scanf("%d",&num);
	for(int i=0;i<num;i++)
	{
		scanf("%d%d",&a,&b);
		if(a==b) t++;
		else t=0;
		if(t==3) 
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
 } 

Measured memory_bytes: 3820
from sys import stdin, stdout
from time import perf_counter

import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7


l = [int(item) for item in input().split()]

if (l[0]==5 and l[1] == 5 and l[2]==7) or (l[0]==5 and l[1] == 7 and l[2]==5) or (l[0]==7 and l[1] == 5 and l[2]==5):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9196
import math
N,A,B=map(int,input().split())
v = input().split()
for i in range(N):
    v[i] = int(v[i])

v.sort(reverse=True)

ans1=0
for i in range(A):
    ans1 += v[i]
ans1 /= A
print(ans1)

p = v[A-1]
q = v.count(p)
r = v.index(p)
ans2=0
if not v[0] == v[A-1]:
    #q P A-r
    ans2 = math.factorial(q) // math.factorial(q+r-A) // math.factorial(A-r)
else: # N==q
    for i in range(A,min(q,B)+1):
        # q P i
        ans2 += math.factorial(q) // math.factorial(q-i) // math.factorial(i)
print(ans2)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

int main() {
    int N; cin >> N;
    int ac=0, wa=0, tle=0, re=0;
    REP(i, N) {
        string S; cin >> S;
        if (S == "AC") ac++;
        if (S == "WA") wa++;
        if (S == "TLE") tle++;
        if (S == "RE") re++;
    }
    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, a, b; cin >> n >> a >> b;
  auto rec = [&](const auto& rec, int mask, int a, int b) -> V<> {
    if (__builtin_popcount(mask) == 1) {
      return a == b ? V<>{} : V<>{a, b};
    }
    for (int i = 0; i < n; ++i) if (mask & 1 << i and (a ^ b) & 1 << i) {
      mask ^= 1 << i;
      for (int bit = mask; ; bit = bit - 1 & mask) {
        if (__builtin_popcount(a & mask ^ bit) & 1 and __builtin_popcount(b & mask ^ bit) & 1) {
          auto va = rec(rec, mask, a & mask, bit);
          if (a & 1 << i) for (auto&& e : va) {
            e |= 1 << i;
          }
          auto vb = rec(rec, mask, bit, b & mask);
          if (b & 1 << i) for (auto&& e : vb) {
            e |= 1 << i;
          }
          move(begin(vb), end(vb), back_inserter(va));
          return va;
        }
        if (!bit) break;
      }
      return {};
    }
  };
  auto res = rec(rec, (1 << n) - 1, a, b);
  if (res.empty()) {
    cout << "NO" << '\n';
  } else {
    cout << "YES" << '\n';
    for (int i = 0; i < 1 << n; ++i) {
      cout << res[i] << " \n"[i == (1 << n) - 1];
    }
  }
}

Measured memory_bytes: 1648
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int N;

long long Euclid(long long A, long long B) {  // A>B
  if (B == 0)
    return A;
  else {
    return Euclid(B, A % B);
  }
}

long long Euclid(vector<long long> A) {
  long long ans = A[0];
  for (int i = 1; i < A.size(); i++) {
    ans = Euclid(ans, A[i]);
  }

  return ans;
}

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

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

  cout << Euclid(A) << '\n';
}

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

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

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

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

int main() {
	ll n, m, h, w; cin >> n >> m >> h >> w;
	ll ans = (n - h) * (m - w);
	cout << ans << endl;
}

Measured memory_bytes: 256
n;float x[21],y[21],S;main(){for(;~scanf("%f,%f",x+n,y+n);n++);x[n]=*x,y[n]=*y;for(;n--;)S+=(x[n]-x[n+1])*(y[n]+y[n+1]);exit(!printf("%f\n",S/2));}

Measured memory_bytes: 0
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,p;
    cin >> n >> m >> p;
    vector<pair<pair<ll,ll>,ll > > ed(m);
    vvll rbl(n);
    REP(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        c -= p;
        ed[i].fi.fi = a;
        ed[i].fi.se = b;
        ed[i].se = c;
        rbl[b].pb(a);
    }
    vint re(n,0);
    queue<ll> q;
    re[n-1] = 1;
    q.push(n-1);
    while(!q.empty()){
        ll now = q.front();
        q.pop();
        for(ll i : rbl[now]){
            if(re[i]==0){
                q.push(i);
                re[i]=1;
            }
        }
    }
    vll sc(n,-LLINF);
    sc[0] = 0;
    REP(i,n){
        REP(j,m){
            ll fr = ed[j].fi.fi;
            ll to = ed[j].fi.se;
            if(re[to]==1&&sc[fr]>-LLINF){
                if(sc[fr]+ed[j].se>sc[to]){
                    sc[to] = sc[fr]+ed[j].se;
                    if(i==n-1){
                        cout << -1 << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << max(0LL, sc[n-1]) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

vector<vector<ll>> cnt;
vector<vector<bool>> seen;
int H, W;

void dfs(Graph &G, int h, int w, int fh, int fw){
    if(G[h][w] == 1 && G[fh][fw] == 0){
        cnt[h][w] = min(cnt[h][w], cnt[fh][fw] + 1);
    }else{
        cnt[h][w] = min(cnt[h][w], cnt[fh][fw]);
    }
    if(h == H - 1 && w == W - 1) return;
    if(h + 1 < H){
        dfs(G, h + 1, w, h, w);
    }
    if(w + 1 < W){
        dfs(G, h, w + 1, h, w);
    }
}

int main(){
    cin >> H >> W;
    Graph g(H, vector<int>(W));
    rep(i, H)rep(j, W){
        char c;
        cin >> c;
        if(c == '#')g[i][j] = 1;
        else g[i][j] = 0;
    }
    cnt.assign(H, vector<ll>(W, INF));
    seen.assign(H, vector<bool>(W, false));
    cnt[0][0] = g[0][0];
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            if(h - 1 >= 0){
                if(g[h][w] == 1 && g[h - 1][w] == 0) cnt[h][w] = min(cnt[h][w], cnt[h - 1][w] + 1);
                else cnt[h][w] = min(cnt[h][w], cnt[h - 1][w]);
            }
            if(w - 1 >= 0){
                if(g[h][w] == 1 && g[h][w - 1] == 0) cnt[h][w] = min(cnt[h][w], cnt[h][w - 1] + 1);
                else cnt[h][w] = min(cnt[h][w], cnt[h][w - 1]);
            }
        }
    }
    // rep(i, H){
    //     rep(j, W)cout << cnt[i][j] << " " ;
    //     cout << endl;
    // }
    int ans = cnt[H - 1][W - 1];
    cout << ans << endl;
}

Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let d = 998244353;
    let s: usize = v.iter().cloned().sum();
    let mut tab = vec![0; s + 1];
    let mut tab2 = vec![0; s + 1];
    tab[0] = 1;
    tab2[0] = 1;
    let mut psum = 0;
    for i in 0..n {
        let mut next: Vec<usize> = tab.iter().clone().map(|x| x * 2 % d).collect();
        let mut next2 = tab2.clone();
        for j in 0..psum + 1 {
            next[j + v[i]] = (next[j + v[i]] + tab[j]) % d;
            next2[j + v[i]] = (next2[j + v[i]] + tab2[j]) % d;
        }
        psum += v[i];
        tab = next;
        tab2 = next2;
    }
    let mut ans = (pow_m(3, n, d) + 3 * (d - tab.iter().skip((s + 1) / 2).fold(0, |ac, x| (ac + x) % d))) % d;
    if s % 2 == 0 {
        ans = (ans + 3 * tab2[s / 2]) % d;
    }
    println!("{}", ans);
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut ret = 1;
    let mut r = n;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}


Measured memory_bytes: 8444
// AUTHOR - RUTVIK KOTHARI
// DAIICT , GANDHINAGAR

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long
#define pll pair<ll,ll>
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define INFL LLONG_MAX
#define pb push_back
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll N = 1e5 + 5;
const ll M = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll m1 = 1e9 + 7;
const ll m2 = 1e9 + 9;
const ll p1 = 402653189;
const ll p2 = 1610612741;
const int LN = 32;

ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll dx[4]={-1,  1,  0,  0};
ll dy[4]={ 0,  0,  1, -1};

ll pw[LN],fact[N],invfact[N];

void pre()
{
    fact[0]=1;
    for(int i=0;i<LN;i++)pw[i]=power(2,i);
    for(int i=1;i<N;i++)fact[i]=(i*fact[i-1])%mod;
    for(int i=0;i<N;i++)invfact[i]=powermodm(fact[i],mod-2,mod);
}



int main()
{
    FIO;
    //pre();

    ll i,j;
    
    ll n;
    cin>>n;
    
    ll h[n+1];
    for(i=1;i<=n;i++)
        cin>>h[i];
    
    h[1]--;
    
    for(i=2;i<=n;i++)
    {
        if(h[i]-1 >= h[i-1])
            h[i]--;
    }
    
    for(i=2;i<=n;i++)
    {
        if(h[i] < h[i-1])
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    
    return 0;
}

Measured memory_bytes: 1024
def DFS(num):
    global ans,color
    color[num]="black"
    if "white" not in color:
        ans +=1
    for i in M[num]:
        if color[i]=="white":
            DFS(i)
    color[num]="white"


n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

M=[[] for _ in range(n)]
color=["white" for _ in range(n)]
for a,b in AB:
    M[a-1].append(b-1)
    M[b-1].append(a-1)

ans=0
DFS(0)
print(ans)

Measured memory_bytes: 41820
#include <stdio.h>

int main()
{
	int N;
	int ans, sum, start, end;
	while (scanf("%d", &N) && N) {
		ans = 0, start = 1, end = 2, sum = 3;
		do {
			if (sum == N) ans += 1, sum -= start++;
			else if (sum < N) sum += ++end;
			else sum -= start++;
		} while (start != end);
		printf("%d\n", ans);
	}

	return 0;
}



Measured memory_bytes: 2104
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in range(26):
    alphabet[i] = alphabet[i].upper()

def ctoi(c):
    res = 0
    for x in alphabet:
        if x == c:
            return res
        res += 1
    return res

while True:
    n = int(input())
    if n == 0:
        break
    
    c = list(input().split())

    maxi = [n for _ in range(26)]
    cnt = [0 for _ in range(26)]

    for j in range(n):
        x = c[j]
        idx = ctoi(x)

        for i in range(26):
            if i == idx:
                cnt[i] += 1
            else:
                maxi[i] -= 1
        
        shouri = False        
        for alpha in alphabet:
            idx = ctoi(alpha)
            mx = -1
            for i in range(26):
                if i != idx:
                    mx = max(mx, maxi[i])
            
            if cnt[idx] > mx:
                print(alpha, j + 1)
                shouri = True
                break
        
        if shouri:
            break
    else:
        print('TIE')



Measured memory_bytes: 5632
using System;
class AtCoder
{
    static void Main(string[] args)
    {
      	var str = Console.ReadLine().Split(' ');
      	var a = int.Parse(str[0]);
      	var b = int.Parse(str[1]);
      
        for( var x = 1; x <= (int)(100 / 0.08) ; x++ )
        {
        	if(
              ((int)(x * 0.08) == a) &&
              ((int)(x * 0.1) == b) )
            {
              Console.WriteLine(x.ToString());
             	return;
            }
        }
      	Console.WriteLine("-1");
    }
}

Measured memory_bytes: 13140