akhauriyash/Code-Regression huggingface dataset:
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n;
vector<ll> a, b;
ll mpow(ll x, ll n)
{ //x^n(mod M)
    ll ans = 1;
    while (n != 0)
    {
        if (n & 1)
            ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n);
    b.resize(n);
    ll zz = 0; //ともに0
    ll zn = 0;
    ll nz = 0;
    rep(i, n) cin >> a[i] >> b[i];
    map<pair<ll, ll>, ll> m;
    rep(i, n)
    {
        if (a[i] == 0 && b[i] == 0)
            zz++;
        else if (a[i] == 0)
            zn++;
        else if (b[i] == 0)
            nz++;
        else
        {
            ll g = gcd(abs(a[i]), abs(b[i]));
            a[i] /= g;
            b[i] /= g;
            if (b[i] < 0)
            {
                a[i] *= -1;
                b[i] *= -1;
            }
            m[make_pair(a[i], b[i])]++;
        }
    }
    set<pair<ll, ll>> used;
    ll ans = 1;
    for (auto x : m)
    {
        if (used.count(x.first))
            continue;
        p fir = x.first;
        p sec = make_pair(x.first.second, x.first.first);
        if (x.first.first < 0)
        {
            sec.second *= -1;
        }
        else{
            sec.first *= -1;
        }
        if (m[sec])
        {
            ans *= (mpow(2, x.second) + mpow(2, m[sec]) - 1)%MOD; //全て選ばないダブルカウントを引く
            ans %= MOD;
        }
        else
        {
            ans *= mpow(2, x.second);
            ans %= MOD;
        }
        used.insert(sec);
        /*
        cout<<fir.first<<" "<<fir.second<<"\n";
        cout << sec.first << " " << sec.second << "\n";
        cout << ans << "\n";
        */
    }
    ans *= (mpow(2, zn) + mpow(2, nz) - 1) % MOD;
    ans %= MOD;
    ans+=zz;
    ans %= MOD;
    ans=(ans-1+MOD)%MOD;//全て選ばないを引く
    cout<<ans%MOD<<"\n";
}


Measured memory_bytes: 43788
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      t: usize,
   }
   for _ in 0..t {
      input! {
         n: usize,
         klr: [(Usize1, usize, usize); n]
      }
      if n == 1 {
         let (_, l, _) = klr[0];
         println!("{}", l);
         continue;
      }
      let mut ans = 0usize;
      let mut map1 = vec![vec![]; n];
      let mut map2 = vec![vec![]; n];
      for &(k, l, r) in klr.iter() {
         if l == r || k == n - 1 {
            ans += l;
         } else if l > r {
            ans += r;
            map1[k].push(l - r);
         } else {
            ans += l;
            map2[k].push(r - l);
         }
      }
      let mut q1 = BinaryHeap::new();
      let mut q2 = BinaryHeap::new();
      for i in 0..n {
         if map1[i].is_empty() {
            continue;
         }
         for &x in map1[i].iter() {
            q1.push(Reverse(x));
         }
         while q1.len() > i + 1 {
            q1.pop().unwrap();
         }
      }
      for i in (0..n - 1).rev() {
         if map2[i].is_empty() {
            continue;
         }
         for &x in map2[i].iter() {
            q2.push(Reverse(x));
         }
         while q2.len() > n - i - 1 {
            q2.pop().unwrap();
         }
      }
      for Reverse(x) in q1.iter() {
         ans += x;
      }
      for Reverse(x) in q2.iter() {
         ans += x;
      }
      println!("{}", ans);
   }
}


Measured memory_bytes: 25976
#include <bits/stdc++.h>
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define lop(i,s,t) for(int i=s;i<(t);++i)
using namespace std; 
const int N=2e5+40;
int n,a[N],b[N],aa[N],bb[N],ans;
int main(){ 
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",a+i);
	rep(i,1,n)scanf("%d",b+i);
	lop(k,0,29){
		int qwq=(1<<(k+1))-1,qaq=(1<<k),qAq=(1<<(k+1));
		rep(i,1,n)aa[i]=a[i]&qwq;
		rep(i,1,n)bb[i]=b[i]&qwq;
		sort(aa+1,aa+n+1);
		sort(bb+1,bb+n+1);
		int tot=0,l1=n+1,r1=n+1,l2=n;
		rep(i,1,n){
			while(l1-1>=1&&aa[i]+bb[l1-1]>=qaq)--l1;
			while(r1-1>=1&&aa[i]+bb[r1-1]>=qAq)--r1;
			while(l2>=1&&aa[i]+bb[l2]>=qAq+qaq)--l2;
			tot^=((r1-l1)&1)^((n-l2)&1);
		}
		if(tot)ans+=1<<k;
	}
	printf("%d\n",ans);
    return 0; 
}

Measured memory_bytes: 3328
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
enum MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    auto A = new long[](N);
    auto B = new long[](N);
    foreach (i; 0 .. N)
        scan(A[i], B[i]);

    // alias DIV = Tuple!(long, long);
    // DIV simple(DIV t)
    // {
    //     long g = gcd(t[0], t[1]);
    //     return DIV(t[0] / g, t[1] / g);
    // }

    // DIV[] solve(long[] tmp, long i)
    // {
    //     if (i == N)
    //     {
    //         // writeln(tmp);
    //         tmp.sort();
    //         if (N & 1)
    //         {
    //             return [DIV(tmp[(N + 1) / 2 - 1], 1)];
    //         }
    //         else
    //         {
    //             return [simple(DIV(tmp[N / 2 - 1] + tmp[N / 2], 2))];
    //         }
    //     }
    //     DIV[] ret;
    //     foreach (x; A[i] .. B[i] + 1)
    //     {
    //         ret ~= solve(tmp ~ x, i + 1);
    //     }
    //     return ret.sort.uniq.array;
    // }

    // auto ans = solve([], 0);
    // dprint(ans.length, ans);
    long med(long[] L)
    {
        L.sort();
        // writeln(L);
        if (L.length & 1)
        {
            return L[(L.length + 1) / 2 - 1];
        }
        else
        {
            return L[(L.length / 2 - 1)] + L[(L.length / 2)];
        }
    }

    long a = med(A.dup);
    long b = med(B.dup);
    // dprint(a, b);
    writeln(b - a + 1);
}

/// 素因数分解
long[long] factorize(long x)
{
    assert(0 < x, "x is negative");
    long[long] ps;
    while ((x & 1) == 0)
    {
        x /= 2;
        ps[2] = (2 in ps) ? ps[2] + 1 : 1;
    }
    for (long i = 3; i * i <= x; i += 2)
        while (x % i == 0)
        {
            x /= i;
            ps[i] = (i in ps) ? ps[i] + 1 : 1;
        }
    if (x != 1)
        ps[x] = (x in ps) ? ps[x] + 1 : 1;
    return ps;
}


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

using namespace std;

bool Memo[32] = {1,1,1};
int Trib[32] = {0,1,1};
int trib(int num){
	for(int i = 3;i <= num+1;i++){
		if(Memo[i])continue;
		Trib[i] = Trib[i-1] + Trib[i-2] + Trib[i-3];
		Memo[i] = 1;
	}
	return Trib[num+1];
}

int main(){
	int n;
	int ans; 
	while(cin >> n,n){
		ans = trib(n);
		if(ans  % 3650  == 0){
			ans = ans/3650;
		}else{
			ans = ans/3650+1;
		}
		cout << ans << endl;
	}	
	return 0;
}

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

static const int cMaxNumber = 500001;

void maxHeapify(int array[], int interRoNode, int array_size) {
	int left = 2 * interRoNode;
	int right = 2 * interRoNode + 1;

	//?????§??????????????????????????¶
	int largestNodeNumber;
	if (left <= array_size && array[left] > array[interRoNode])
		largestNodeNumber = left;
	else
		largestNodeNumber = interRoNode;
	if (right <= array_size && array[right] > array[largestNodeNumber])
		largestNodeNumber = right;

	//?????????????????§??????????????\????????????
	if (largestNodeNumber != interRoNode) {
		swap(array[largestNodeNumber], array[interRoNode]);
		maxHeapify(array, largestNodeNumber, array_size);
	}
}

void buildMaxHeap(int array[], int array_size) {
	for (int i = array_size / 2; i >= 1; i--)
		maxHeapify(array, i, array_size);
}

class PriorityQueue {
public:
	PriorityQueue() {
		cur_size_ = 0;
	}

	//add
	void insert(int key) {
		cur_size_++;
		array_[cur_size_] = -(1 << 30);
		increaseKey(cur_size_, key);
	}

	//remove
	int heapExtractMax() {
		if (cur_size_ < 1) return 0;
		int key = array_[1];

		array_[1] = array_[cur_size_];
		cur_size_--;
		maxHeapify(array_, 1, cur_size_);
		return key;
	}

private:
	void increaseKey(int i, int key) {
		if (key < array_[i]) return;
		array_[i] = key;

		while (i > 1 && array_[i / 2] < array_[i]) {
			swap(array_[i], array_[i / 2]);
			i = i / 2;
		}
	}

	int array_[2000001];
//	int max_size;
	int cur_size_;
};

int main() {
	PriorityQueue pq;

	while (1) {
		//string s;
		//cin >> s;
		char s[10];
		cin >> s;

		if (s[0] == 'i') {
			int key;
			cin >> key;
			pq.insert(key);
		}
		else if (s[0] == 'e') {
			if (s[1] == 'n')
				break;
			int key;
			key = pq.heapExtractMax();
			cout << key << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 6892
class SegmentTree:
    def __init__(self, initial_values, f=max, zero=0):
        self.__size = len(initial_values)
        self.__n = 1 << ((self.__size - 1).bit_length())
        self.__f = f
        self.__z = zero
        self.__dat = [zero] * (2 * self.__n)
        self.__get_leaf = lambda i: self.__n + i - 1
        self.__get_parent = lambda i: (i-1)//2
        self.__get_children = lambda i: (self.__dat[2*i+1], self.__dat[2*i+2])
        self.__is_left = lambda i: i&1 == 1
        self.__is_right = lambda i: i&1 == 0
        zi = self.__get_leaf(0)
        for i, v in enumerate(initial_values):
            self.__dat[zi + i] = v
        for i in range(zi-1, -1, -1):
            self.__dat[i] = self.__f(*self.__get_children(i))
    
    def update(self, index, value):
        i = self.__get_leaf(index)
        if self.__dat[i] == value: return
        self.__dat[i] = value
        while i > 0:
            i = self.__get_parent(i)
            self.__dat[i] = self.__f(*self.__get_children(i))
    
    def query(self, from_inclusive, to_exclusive):
        if to_exclusive <= from_inclusive: return self.__z
        a, b = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1
        ans = self.__z
        while b - a > 1:
            if self.__is_right(a): ans = self.__f(ans, self.__dat[a])
            if self.__is_left(b): ans, b = self.__f(ans, self.__dat[b]), b-1
            a, b = a//2, self.__get_parent(b)
        ans = self.__f(ans, self.__dat[a])
        if a != b: ans = self.__f(ans, self.__dat[b])
        return ans

N = int(input())
S = input()
g = lambda c: 1 << (ord(c)-ord('a'))
tree = SegmentTree([g(c) for c in S], lambda x,y:x|y)
Q = int(input())
for _ in range(Q):
    t, a, b = input().split()
    if t == '1': tree.update(int(a)-1, g(b))
    else: print(bin(tree.query(int(a)-1, int(b))).count('1'))

Measured memory_bytes: 89108
package main

import (
	"bufio"
	"fmt"
	"os"
)

type Range struct {
	L, R int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var N, M, Q int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d", &N, &M, &Q)

	dp := make(map[Range]int)
	for i := 0; i < M; i++ {
		var L, R int
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &L, &R)
		dp[Range{L, R}]++
	}

	for i := 1; i <= N; i++ {
		t := Range{1, i}
		for t.R <= N {
			dp[t] = dp[t] +
				dp[Range{t.L, t.R - 1}] +
				dp[Range{t.L + 1, t.R}] -
				dp[Range{t.L + 1, t.R - 1}]
			t.L++
			t.R++
		}
	}

	for Q > 0 {
		Q--
		var p, q int
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &p, &q)
		fmt.Println(dp[Range{p, q}])
	}

}


Measured memory_bytes: 18816
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

ll const MAX_C = 10005;

int main() {
    INIT;
    ll N;
    cin >> N;
    vector<ll> X(N), Y(N), P(N);
    rep(i, N) { cin >> X[i] >> Y[i] >> P[i]; }

    ll pow_N = 1 << N;
    vector<vector<ll>> cost_x(N, vector<ll>(pow_N));
    vector<vector<ll>> cost_y(N, vector<ll>(pow_N));

    for (ll bit = 0; bit < pow_N; bit++) {
        rep(i, N) {
            ll min_x = INF;
            ll min_y = INF;

            chmin(min_x, abs(X[i]) * P[i]);
            chmin(min_y, abs(Y[i]) * P[i]);

            for (ll j = 0; j < N; j++) {
                if (bit & (1 << j)) {
                    chmin(min_x, abs(X[i] - X[j]) * P[i]);
                    chmin(min_y, abs(Y[i] - Y[j]) * P[i]);
                }
            }

            cost_x[i][bit] = min_x;
            cost_y[i][bit] = min_y;
        }
    }

    vector<ll> min_sum(N + 1, INF);
    vector<ll> ids;
    vector<pair<ll, ll>> now_lines;

    // 3進数bit全探索
    for (ll bit = 0; bit < pow(3, N); bit++) {
        int tmp = bit;
        for (int pos = 1; pos <= N; pos++) {
            ids.pb(tmp % 3);
            tmp /= 3;
        }

        ll id_x = 0, id_y = 0;
        ll k_id = 0;
        rep(i, N) {
            if (ids[i] == 0) {
                id_x += 1 << i;
                k_id++;
            } else if (ids[i] == 1) {
                id_y += 1 << i;
                k_id++;
            }
        }

        ll sum = 0;
        rep(i, N) { sum += min(cost_x[i][id_x], cost_y[i][id_y]); }
        chmin(min_sum[k_id], sum);

        ids.clear();
        now_lines.clear();
    }

    rep(i, N + 1) { cout << min_sum[i] << endl; }

    return 0;
}

Measured memory_bytes: 11244
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

class CombMod:
	def __init__(self, N):
		facts = [1]
		rfacts = [1]
		for i in range(1, N+1):
			facts.append(facts[i-1]*i % mod)
			rfacts.append(pow(facts[i], mod-2, mod))
		self.facts = facts
		self.rfacts = rfacts

	def comb(self, n, k):
		return self.facts[n]*self.rfacts[k]*self.rfacts[n-k] % mod

	def perm(self, n, k):
		return self.facts[n]*self.rfacts[n-k] % mod

	def fact(self, k):
		return self.facts[k] % mod

	def rfact(self, k):
		if k == 0: return 1
		return self.rfacts[k] % mod

S = ri()

n = S // 3

cm = CombMod(S)

def f(i, m):
	a = i-1 + m
	ret = cm.fact(a) * cm.rfact(i-1) * cm.rfact(m)
	return ret % mod

ans = 0
for i in range(1, n+1):
	m = S - i*3
	ans += f(i, m)
	ans %= mod
print(ans)


Measured memory_bytes: 74116
private fun readAtOnce(): List<String> = readLine()!!.split(" ")
private fun readInts(): List<Int> = readAtOnce().map(String::toInt)
private fun readLongs(): List<Long> = readAtOnce().map(String::toLong)
private fun zeroArray(size: Int): IntArray = IntArray(size) { 0 }
private fun Int.repeat(predicate: (Int) -> Unit) = repeat(this, predicate)

fun main(array: Array<out String>) {
    val (N) = readInts()

    println(N / 2 + N % 2)
}

Measured memory_bytes: 37992
#include<iostream>

int main()
{	
	int num,i,j,x;
	int answer=0;
	int c[201];
	scanf("%d",&num);
	for(i=0;i<num;i++){
		scanf("%d",&c[i]);
	}

	while(1){
		for(i=0;i<num;i++){
			//printf("%d\n",c[i]);
			answer++;
			if(c[i]%2==0){
				c[i]=c[i]/2;
			}
			else{
				answer=answer/num;
				printf("%d\n",answer);
				return 0;			
			}
		}
	}
}

Measured memory_bytes: 256
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#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 bigmod 1000000007
#define INF 500000000


int main() {
    string a,b;
    cin>>a>>b;
    int n = stoi(a+b);
    if((double)sqrt(n)-(int)sqrt(n)==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
my $N= <STDIN>;
my $s= <STDIN>;
my @dat = split(/ /,$s);
my $sum =0;
for(my $i=0;$i<$N;$i++){
    $sum = $sum + $dat[$i];
}
if($N < $sum){
    print "-1";
}else{
    $ans = $N - $sum;
    print "$ans";
}

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

using namespace std;

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

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

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

    int ans = 0;

    for (int i = 0; i < N; i++) {
        if (V[i] > C[i]) {
            ans += V[i] - C[i];
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,W,ans;
int f[150][150][450],w[150],c[150];
int main()
{
	int n,W;
	cin>>n>>W;
	for (int i=0;i<n;i++) cin>>w[i]>>c[i];
	for (int i=0;i<n;i++) for (int j=0;j<=i;j++) for (int k=0;k<=3*j;k++)
	  {
		f[i+1][j][k]=max(f[i+1][j][k],f[i][j][k]);
		f[i+1][j+1][k+w[i]-w[0]]=max(f[i+1][j+1][k+w[i]-w[0]],f[i][j][k]+c[i]);
	  }
	for(int i=0; i<=n; i++) for(int j=0; j<=3*i; j++)
	  {
		long long nowW=(long long)w[0]*i+j;
		if(nowW<=W) ans=max(ans,f[n][i][j]);
	  }
	cout<<ans;
}

Measured memory_bytes: 24960
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
using namespace std;

int  dizi[50][50],dp[100005][10],n,k;
vector<int>v[100005];
int dpf(int crr,int last,int parent){
	// printf("%d %d \n",crr,last );
	if(dp[crr][last]!=-1){
		return dp[crr][last];
	}
	dp[crr][last]=0;
	ll a=1;
	if(last==0){
		ll b=1;
		for(int i=0;i<v[crr].size();i++){
			if(v[crr][i]!=parent){
				a*=dpf(v[crr][i],0,crr);
				a%=mod;
				b*=dpf(v[crr][i],1,crr);
				b%=mod;
			}
		}
		dp[crr][last]=a+b;
		dp[crr][last]%=mod;
	}
	else{
		for(int i=0;i<v[crr].size();i++){
			if(v[crr][i]!=parent){	
				a*=dpf(v[crr][i],0,crr);
				a%=mod;
			}
		}
		dp[crr][last]=a;
	}
	if(dp[crr][last]==0){
		if(last==0)
			dp[crr][last]=2;
		else
			dp[crr][last]=1;
	}
	return dp[crr][last];
}
int main(){
	// freopen("a.gir","r",stdin);
	// freopen("a.cik","w",stdout);
	for(int i=0;i<100005;i++){
		for(int j=0;j<5;j++){
			dp[i][j]=-1;
		}
	}
	int a,b;
	scanf("%d",&n);
	for(int i=0;i<(n-1);i++){
		scanf("%d %d",&a,&b);
		v[a].pb(b);
		v[b].pb(a);
	}
	printf("%d\n",dpf(1,0,-1) );
}

Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int sum = 0;
  for(int i=0; i<n; i++){
    int l,r;
    cin >> l >> r;
    sum += r-l+1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    rep(i, N) cin >> t[i];
    ll ans = 0;
    
    rep(i, N) {
        if (i < (N -1)) {
            ans += min(t[i + 1] - t[i], T);
        }
        else {
            ans += T;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

int selectionSort(int a[],int n){
    int c = 0;

    for(int i = 0;i<n;i++){
        int minj=i;
        for(int j=i+1;j<n;j++){
            if(a[minj]>a[j])minj=j;
        }
        if(minj!=i){
            swap(a[minj],a[i]);
            c++;
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i];
        if(i!=n-1)cout<<" ";
    }
    cout<<endl;

    return c;
}

int main(void){

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

    int c = selectionSort(a,n);

    cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 3104
a = []
for i in range(3):
    a += list((map(int, input().split())))
card = [False] * 9
n = int(input())
# b = []
for i in range(n):
    # b.append(int(input()))
    try:
        card[a.index(int(input()))] = True
    except ValueError:
        continue
if (sum(card[:3]) == 3 or sum(card[3:6]) == 3 or sum(card[6:]) == 3
        or sum(card[::3]) == 3 or sum(card[1::3]) == 3 or sum(card[2::3]) == 3
        or sum(card[::4]) == 3 or sum(card[2:7:2]) == 3):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    s = sorted(list(set(A)))
    mc = A.count(s[-1])

    for a in A:
        if len(s) == 1:
            print(s[-1])
        elif a == s[-1] and mc == 1:
            print(s[-2])
        else:
            print(s[-1])


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 17184
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    long long int n, m, k, a, b;
    cin >> n >> m >> k;
    vector<long long int> aa(n+1);
    vector<long long int> bb(m+1);
    rep(i,n){
        cin >> a;
        aa[i+1] = aa[i] + a;
    }
    rep(i,m){
        cin >> b;
        bb[i+1] = bb[i] + b;
        }
    int ans = 0;
    int j = m;
    rep(i,n+1){
        if(aa[i] > k) break;
        while(aa[i] + bb[j] > k){
            j--;
        }
        ans = max(ans,i + j);
    }
    cout << ans;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-10
#define int ll

struct vector2D {double x, y;};

double multiply(vector2D a, vector2D b) {
  return a.x*b.x + a.y*b.y;
}

signed main(void) {
  double x[4], y[4];
  while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]) {
    vector2D a, b;
    a.x = x[1] - x[0];
    a.y = y[1] - y[0];
    b.x = x[3] - x[2];
    b.y = y[3] - y[2];

    if(fabs(multiply(a, b)) < EPS) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var d = new Dictionary<int ,bool>();
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                d[i*j]=true;
            }
        }
        if(d.ContainsKey(N))WriteLine("Yes");
        else WriteLine("No");

    }
}



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

using namespace std;

int H, W, A, B;

int C[1005][10005];

int main(void) {

	cin >> H >> W >> A >> B;

	for (int i = 1; i <= H - B; i++) {
		for (int j = 1; j <= A; j++) {
			C[i][j] = 1;
		}
	}

	for (int i = H - B + 1; i <= H; i++) {
		for (int j = A + 1; j <= W; j++) {
			C[i][j] = 1;
		}
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cout << C[i][j];
		}cout << endl;
	}


	return 0;
}


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

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = inputArray[0];

			var numArray = retreiveLongArray();

			long min = int.MaxValue;
			int count = 0;

			for (int i = 0; i < N; i++) {
				if(numArray[i]< min) {
					min = numArray[i];
					count++;
				}
			}

			//答えの出力
			var ans = count;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


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

int main() {
	int n, q;
	cin >> n;
	int S[n];
	for (int i = 0; i < n; i++) cin >> S[i];
	cin >> q;
	int T[q];
	for (int i = 0; i < q; i++) cin >> T[i];
	int ans = 0;
	for (int i = 0; i < q; i++) {
		int key = T[i];
		int left = 0, right = n, mid;
		while (left < right) {
			mid = (left+right)/2;
			if (S[mid] == key) {
				ans++;
				break;
			} else if (S[mid] < key) {
				left = mid + 1;
			} else {
				right = mid;
			}
		}
	}
	cout << ans << endl;
	return 0;
}



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

int a()
{
    int n;
    std::cin >> n;
    int a, b;
    std::cin >> a >> b;
    
    int dis = 0;
    bool ans = false;
    while(1)
    {
        dis += n;
        if(a <= dis && dis <= b)
        {
            ans = true;
            break;
        }
        if(b < dis)
        {
            break;
        }
    }
    
    if(ans)
    {
        std::cout << "OK" << std::endl;
    }
    else
    {
        std::cout << "NG" << std::endl;
    }
    return 0;
}


int main(int argc, const char * argv[])
{
    a();
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    vector<int> a(n),b(n),c(n-1);
    rep(i,n) {
        cin >> a[i];
        a[i]--;
    }
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];
    int ans = b[a[0]];
    for (int i = 1; i < n; i++) {
        ans += b[a[i]];
        if (a[i-1] + 1 == a[i]) ans += c[a[i-1]];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# 値の取得
N, M, X, Y = map(int, input().split())
# X国の支配地を取得
xi = list(map(int, input().split()))
# Y国の支配地を取得
yi = list(map(int, input().split()))
# 各リストに国の首都をついか
xi.append(X)
yi.append(Y)
# 配列間同士で重複があるか確認
if max(xi) < min(yi):
    print('No War')
else:
    print('War')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin >> n >> k;
  cout << min(n%k, k - (n%k)) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
const int LEN = 100000;//??????????????§??????
struct pp
{
	char name[10];
	int time;
} ;
pp P[LEN];
int head, tail, n;
void enqueue(struct pp x)//??\????????°
{
	P[tail] = x;//?°?x?????\??°????°?
	tail = (tail + 1)%LEN;//??¨?????????????????????????????????head=(tail + 1) % LEN??¶??´???????????????
}
struct pp dequeue()//???????????°
{
	struct pp x = P[head];//?°?head??????????????´????´?????????\??????x
	head = (head + 1)%LEN;
	return x;//????????????????´?
}

int main()
{
	int alltime=0;//?´??????¶??´  ?±???¨????????????????§????
	int n, q;//n??¨???????????°???q??¨?????¶??´????????§?°?
	struct pp u;
	scanf("%d%d",&n,&q);
	//?°?????????????????????°?????????
	for (int i = 0; i < n; i++)
	{
		scanf("%s%d",& P[i].name,& P[i].time);//cin >> P[i].name >> P[i].time;
	}
	head = 0; tail = n;
	//?¨??????¶??´????????¬???
	while (head != tail)
	{
		u = dequeue();//?????´????´???????
		int c = min(q, u.time);//????????¶??´????????§?°??????\????????????????????¶??´
		u.time = u.time - q;//????????????????????????????????¶??´
		alltime = alltime + c;
		if (u.time > 0)
			enqueue(u);//??????????????¬????????\??°????°?
		else
		{
			printf("%s %d\n",u.name,alltime);
		}
	}
	return 0;
}

Measured memory_bytes: 4288
#include<stdio.h>
main(){
    int a,b,c;
    int tmp;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    if(b>c){
        tmp=b;
        b=c;
        c=tmp;
    }
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    printf("%d %d %d\n",a,b,c);

    return 0;
}


Measured memory_bytes: 2048
from collections import defaultdict

N = int(input())
*A,=map(int,input().split())

'''
方針:
- 各A_i,(i<h)ごとにf(h,j)=A_h+A_j-|h-j|の値がf(i,j)に比べてどれだけ変化するかを計算し、
リストに格納(①)
- 各要素A_k,(j<k)ごとにf(i,k)=A_i+A_k-|i-k|の値がf(i,j)に比べてどれだけ変化するかを
計算し、カウントをとる(②)
- 再度ループを回して①と②を照合し、値が一致する組数をansに加算
'''

ans=0
diff_list=[] #①照合用の差分リスト
count=defaultdict(int) #②各要素がどれだけはみ出ているかのカウント
#前処理として、最初のループで①と②を作成
for i in range(1,N):
  if i == A[0]+A[i]:
    ans += 1
  d1 = A[i]-A[0]
  d2 = i
  diff_list.append(d1+d2)
  
  count[A[0]+A[i]-i] += 1

for i in range(N-1):
  count[A[0]+A[i+1]-(i+1)] -= 1 #その要素自身を忘れずに引く
  d = diff_list[i]
  ans += count[-d]
  
print(ans)

Measured memory_bytes: 67880
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;

int N;
int H[100001];
int memo[100001];

int solve(int n) {
  if (n < 0) return (1 << 30);
  if (n == 0) return 0;
  if (memo[n] != -1) return memo[n];

  int res = solve(n-1) + abs(H[n] - H[n-1]);
  res = min(res, solve(n-2) + abs(H[n] - H[n-2]));

  return memo[n] = res;
}

int main(void) {
  int N; cin >> N;
  rep(i, N) cin >> H[i];
  memset(memo, -1, sizeof(memo));
  cout << solve(N-1) << endl;
  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

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


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int a, b, c,i,count=0;
	scanf("%d %d %d", &a, &b, &c);
	for (i = a; i <= b; i++) {
		if ((c % i) == 0) {
			count++;
		}
	}
	printf("%d\n", count);
}

Measured memory_bytes: 2704
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast")
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e6;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    fast_io;
    int as, bs, i, j, mx = 1e9, s;
    string a, b;
    cin >> a >> b;
    as = a.size(), bs = b.size();
    for (i = 0; i <= as - bs; i++)
    {
        s = 0;
        for (j = i; j < i + bs; j++)
            if (a[j] != b[j - i]) s++;
        mx = min(mx, s);
    }
    cout << mx;
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005;
const int MOD=1e9+7;
LL dist[N];
bool vis[N];
int head[N],tot=0,fa[N];

struct node
{
    int from,to;
    LL w;
    int next;
} edge[N*4];
bool operator<(node a,node b)
{
    return a.w<b.w;
}
void add(int u,int v,LL w)
{
    edge[tot].from=u;
    edge[tot].to=v;
    edge[tot].w=w;
    edge[tot].next=head[u];
    head[u]=tot++;
}
int n;

int get(int x)
{
    if(x==fa[x])
        return x;
    else
        return fa[x]=get(fa[x]);
}
struct Point
{
	int x,y; 
	int id;
}p[N];
bool cmp1(Point a,Point b)
{
	return a.x<b.x;
}
bool cmp2(Point a,Point b)
{
	return a.y<b.y;
}
int main()
{
    memset(head,-1,sizeof(head));
    tot=0;


    scanf("%d",&n);

    for(int i=1; i<=n; i++)
        fa[i]=i;


    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&p[i].x,&p[i].y);
        p[i].id=i;
    }
    sort(p+1,p+n+1,cmp1);
    for(int i=2;i<=n;i++)
	{
		add(p[i-1].id,p[i].id,p[i].x-p[i-1].x);
	}
    sort(p+1,p+n+1,cmp2);
	for(int i=2;i<=n;i++)
	{
		add(p[i-1].id,p[i].id,p[i].y-p[i-1].y);
	}
  
    
    sort(edge,edge+tot);
    int cnt=0;
    LL ans=0;
    for(int i=0; i<tot; i++)
    {

        int fu=get(edge[i].from);
        int fv=get(edge[i].to);
        if(fu!=fv)
        {


            fa[fu]=fv;
            cnt++;
            ans+=edge[i].w;
            if(cnt==n-1)
                break;

        }
    }
    cout<<ans<<endl;

    return 0;

}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string s;
ll k;

int main(void) {
  // Here your code !
  cin >> s;
  scanf("%lld", &k);

  int n = s.size();

  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == 'a') continue;
    int cur_remain = (int)('z' - s[i]);

    if ((ll)(cur_remain) + 1LL > k) {
      continue;
    }

    s[i] = 'a';
    k -= (cur_remain + 1);
  }

  int cur_pos = (int)(s.back() - 'a');

  k += (ll)(cur_pos);
  
  int mod = (int)('z' - 'a');
  
  mod += 1;

  int last_pos = k % mod;

  s[n - 1] = (char)('a' + last_pos);

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 512
import math

N, D = map(int, input().split())
point_list = []
for n in range(N):
  x_y = tuple(map(int, input().split()))
  point_list.append(x_y)

count = 0

for p in point_list:
  d = math.sqrt(p[0]**2+p[1]**2)
  if d <= D:
    count += 1
  else:
    pass

print(count)

Measured memory_bytes: 36072
n,m=map(int,input().split())
from collections import defaultdict 
d=defaultdict(list)
from collections import deque 
for i in range(m):
    a,b=map(int,input().split())
    a-=1 
    b-=1 
    d[a].append(b)
    d[b].append(a)
q=[0]
dist=[0]*n 
vis=[0]*n 
vis[0]=1 
q=deque() 
q.append(0)
while q:
    t=q.popleft()
    for i in d[t]:
        if not vis[i]:
            vis[i]=1 
            dist[i]=dist[t]+1 
            q.append(i)
print('POSSIBLE' if dist[n-1]==2 else 'IMPOSSIBLE')

Measured memory_bytes: 108632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(void){
    int n;cin>>n;
    vector<int>V(100002,0);int x;
    rep(i,n){
        cin>>x;V[x]++;
    }
    int ma=0;
    rep(i,100000){
        ma=max(ma,V[i]+V[i+1]+V[i+2]);
    }
    cout<<ma<<endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> r(N);
	for (int i = 0; i < N; i++)
		cin >> r[i];
	sort(r.begin(), r.end());
	double ma = 0;
	for (int n = 3; n <= N; n++) {
		vector<int> a(r.end() - n, r.end());
		do {
			vector<double> x(n), y(n);
			for (int i = 0; i < n; i++) {
				x[i] = a[i] * cos(M_PI*2 / n * i);
				y[i] = a[i] * sin(M_PI*2 / n * i);
			}
			for (int t = 0; t < 1; t++) {
				int i = rand() % n;
				int j = (i + n - 1) % n, k = (i + 1) % n;
				double dx = x[k] - x[j], dy = y[k] - y[j];
				double _dx = dy, _dy = -dx;
				double r = sqrt(_dx * _dx + _dy * _dy);
				x[i] = _dx / r * a[i];
				y[i] = _dy / r * a[i];
			}
			double sum = 0;
			for (int i = 0; i < n; i++) {
				int j = (i + 1) % n;
				sum += x[i] * y[j] - y[i] * x[j];
			}
			ma = max(ma, sum);
		} while (next_permutation(a.begin() + 1, a.end()));
	}
	printf("%.15f\n", ma / 2);
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x,y,ans=0;
	cin>>x;
	y=x;
	if(x&1)
	{
		cout<<0<<endl;
		return 0;
	}
	while(x)
	{
		ans+=x/2/5;
		x/=5;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N, s, f, sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s >> f;
    sum += (f - s) + 1;
  }
  cout << sum << endl;
}


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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	int m=max(a,max(b,c));
	int sum=a+b+c;
	if(sum==2*m)cout<<"Yes";
	else cout<<"No";
	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/
/*
int h,w;
char maze[10][10];
int dx[2]={1,0};
int dy[2]={0,1};

bool dfs(int x,int y){
  cout<<x<<" "<<y<<endl;
  bool ok=false;
  if(x==w-1&&y==h-1){
    return true;
  }else{
    rep(i,2){
      if(maze[y+dy[i]][x+dx[i]]=='#'){
	ok=dfs(x+dx[i],y+dy[i]);
      }
      if(ok)return ok;
    }
  }
  return ok;
}

int main(){
  cin>>h>>w;
  rep(i,h)rep(j,w)cin>>maze[i][j];
  if(dfs(0,0))cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  return 0;
}
*/

int main(){
  int h,w,cnt=0;
  cin>>h>>w;
  rep(i,h)rep(j,w){
    char c;
    cin>>c;
    if(c=='#')cnt++;
  }
  if(cnt==w+h-1)cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] seq = new int[n];
		long ret = 0;
		HashMap<String, Integer> subseq = new HashMap<String, Integer>();
		String N = "";
		StringBuilder sb = new StringBuilder(N);
		for (int i = 0; i < seq.length; i++) {
			sb.append(in.next());
		}
		N = sb.toString();
		//System.out.println(N);
		while(true) {
			String target =  String.valueOf(ret);//??\?????????????????????target???????????????long??????String??¨???
			int digit = target.length();
			int left = 0;
			int right = left + digit;
			while (right <= n) {
				String sub = N.substring(left, right);
				//System.out.println("sub : " + sub);
				if(!N.contains(target)){
					System.out.println(target);
					return;
				}
				left++;
				right++;
			}
			ret++;
		}
	}
}

Measured memory_bytes: 46912
using System;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            int sum = 0;
            int N = int.Parse(Console.ReadLine());
            int[] prices = new int[N];

            int max = prices[0];

            for(int i = 0; i < N; i++)
            {
                prices[i] = int.Parse(Console.ReadLine());
                if (max <= prices[i]) {
                    max = prices[i];
                }
                sum += prices[i];
            }


            sum = sum - max / 2;

            Console.Write(sum);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    int a;
    for(int i=0;i<n-1;i++){
        cin >> a ;
        x[a-1]++;
    }
    for(int i=0;i<n;i++){
        cout << x[i] << endl;
    }
}

Measured memory_bytes: 4060
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      // cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

bool solve() {
  int N;
  cin >> N;
  vi A(N), D(N), DD(N);
  cin >> A;
  int S = accumulate(all(A), 0LL);
  if (S % (N * (N + 1) / 2) != 0) return false;
  int k = S / (N * (N + 1) / 2);
  rep(i, 0, N) { D[i] = A[(i + 1) % N] - A[i] - k; }
  int cnt = 0;
  rep(i, 0, N) {
    if (D[i] % N != 0) {
      return false;
    }
    cnt += abs(D[i]) / N;
  }
  if (cnt != k) return false;
  return true;
}
signed main() {
  if (solve())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 2560
h,w = map(int,input().split())
arr=[]
arr.append(['.']*(w+2))

for _ in range(h):
    arr.append(list('.'+input()+'.'))
arr.append(['.']*(w+2))

ans = []

for i in range(h):
    ans.append([])
    for j in range(w):
        cnt=0
        if arr[i+1][j+1]=='#':
            cnt='#'
        else:
            for hh in range(3):
                for ww in range(3):
                    if not(hh==1 and ww==1) and arr[i+hh][j+ww]=='#':
                        cnt+=1
            cnt=str(cnt)
        ans[i].append(cnt)
for line in ans:
    print(''.join(line))
    

Measured memory_bytes: 3188