akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		//キーボード入力メソッド
		Scanner sc = new Scanner(System.in);

		int x = 1;
		int i = 0;

		//xが0のとき、終了
		while(true) {
			x = sc.nextInt();
			i++;
			if(x == 0) {
				break;
			}
			System.out.println("Case " + i + ": " + x);
		}
	}

}



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

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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
string x[3]={"Sunny","Cloudy","Rainy"};
string s;cin>>s;
if(s=="Sunny"||s=="Cloudy"||s=="Rainy"){
for(int i=0;i<3;i++){
    if(s==x[i]&&i!=2)
        {cout<<x[i+1]<<endl;break;}
    else if(i==2)
    {cout<<"Sunny"<<endl;}

}
}
return 0;}


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  vector<int> card(3);
  for(int i = 0; i < 3; i++) cin >> card[i];
  sort(card.begin(), card.end());
  cout << card[0] + card[1] + card[2] * 10 <<endl;
}


Measured memory_bytes: 3616
A=list(input())
cnt = 0
if A[0] == "A":
    A[0]="a"
    if A[2:-1].count("C")==1:
        A[A.index("C")]="c"
        a="".join(A)
        if a.islower():
            cnt+=1
if cnt==1:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vvl G;
ll dfs(int v){
  ll res=1;
  for(auto nv:G[v]){
    res+=dfs(nv);
  }
  return res;
}
    
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  ll n,p;
  cin >> n >> p;
  int odd=0,even=0;
  rep(i,n){
    ll a;
    cin >> a;
    if(a&1)odd++;
    else even++;
  }
  if(odd==0 && p==1){
    cout << 0 << endl;
  }
  else if(even==0 && p==0 && n==1){
    cout << 0 << endl;
  }
  else if(odd==0 && p==0){
    cout << (ll)pow(2,n) << endl;
  }
  else cout << (ll)pow(2,n-1) << endl;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);


  int q;
  cin>>q;

  rep(i,0,q){
    int c,a,n;
    cin>>c>>a>>n;
    int k,ans = 0;
    k = min({c,a,n});
    ans += k;
    c -= k;
    a -= k;
    k = min({c/2,a});
    ans += k;
    c -= k*2;
    ans += c/3;
    cout<<ans<<'\n';
  }

  return 0;
}


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

int main(){
  int N,Q;
  int l,r;
  string S;
  cin >> N >> Q;
  cin >> S;
  vector<int> pos;
  pos.push_back(0);
  int sum=0;
  for (int i=1;i<S.size();i++){
    if( (*(S.begin()+i-1)=='A') && (*(S.begin()+i)=='C') ){
      sum++;
    }
    pos.push_back(sum);
  }
  vector<int> ans;
  for (int i=0;i<Q;i++){
    cin >> l >> r;
    ans.push_back(pos[r-1]-pos[l-1]);
  }
//  for(auto itr=pos.begin();itr!=pos.end();itr++) cout << *itr << endl;
  for(auto itr=ans.begin();itr!=ans.end();itr++) cout << *itr << endl;
}
    
    

Measured memory_bytes: 1976
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    boolean found = false;
		Scanner input = new Scanner(System.in);
		String s = input.next();
		for(int i=0;i<s.length();i++){
		    if(s.charAt(i)=='7'){
		        System.out.println("Yes");
		        found = true;
		    }
		    if(found){
		        break;
		    }
		}
		if(!found){
		    System.out.println("No");
		}
	}
}


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a, b;
	cin>>a>>b;
	if (a == b)
	{
		cout<<"Yes"<<endl;
	}
	else if (a > b)
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n+1, 0);
    rep(i,n) cin >> a[i+1];
    vector<bool> in(n+1, false);
    vector<int> ans;
    for(int i = n; i > 0; i--){
        int cnt = 0;
        for(int j = i; j <= n; j += i){
            if(in[j]) cnt++;
        }
        if(cnt%2 != a[i]){
            in[i] = true;
            ans.push_back(i);
        }
    }
    cout << ans.size() << endl;
    for(auto p : ans){
        cout << p << " ";
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  double a,b,x;
  cin>>a>>b>>x;
  cout.precision(17);
  if(a*b/2*a>x)
  {
    cout<<fixed<<atan((a*b*b)/(2*x))*180/M_PI;
    return 0;
  }
  else
  {
    cout<<fixed<<atan(2*(a*a*b-x)/(a*a*a))*180/M_PI;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }

  int main(){
      lint n,k;
      cin>>n>>k;
      lint ans=0;
      lint x=n/k;
      ans=x*x*x;
       lint t=0;
    if(k%2==0){
        lint f;
        f=k/2;
        while(f<=n){
                t++;
           f+=k;
        }
    }
      ans+=(t*t*t);
      cout<<ans;
  }

  
     
  

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	x, y, a, b, c := scanInt(), scanInt(), scanInt(), scanInt(), scanInt()
	p := make([]int, a)
	for i := range p {
		p[i] = scanInt()
	}
	q := make([]int, b)
	for i := range q {
		q[i] = scanInt()
	}
	r := make([]int, c)
	for i := range r {
		r[i] = scanInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(p)))
	sort.Sort(sort.Reverse(sort.IntSlice(q)))
	sort.Sort(sort.Reverse(sort.IntSlice(r)))
	ans := 0
	pi, qi, ri := 0, 0, 0
	for cnt := 0; cnt < x+y; cnt++ {
		pv := 0
		if pi < x {
			pv = p[pi]
		}
		qv := 0
		if qi < y {
			qv = q[qi]
		}
		rv := 0
		if ri < c {
			rv = r[ri]
		}

		if pv >= qv && pv >= rv {
			ans += pv
			pi++
		} else if qv >= pv && qv >= rv {
			ans += qv
			qi++
		} else {
			ans += rv
			ri++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  string s;
  cin >> s;
  int N = sz(s);

  rep(i, N) {
    if (i + 1 < N && s[i] == s[i + 1]) {
      cout << i + 1 << ' ' << i + 2 << endl;
      return 0;
    }
    if (i + 2 < N && s[i] == s[i + 2]) {
      cout << i + 1 << ' ' << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
	ll n,W;
  	cin>>n>>W;
  	ll val[n];
  	ll w[n];
  	ll max1=0;
  	for(int i=0;i<n;i++){
      cin>>w[i]>>val[i];
      max1=max(max1,val[i]);
    }
  	
  	ll dp[n+1][max1*n+1];
  	ll ans=0,i,j;
  	for( i=0;i<=n;i++){
      for( j=0;j<= max1*n ;j++){
        dp[i][j]= INT_MAX;
        if(j==0)
          dp[i][j]=0;
        else if(i==0 || j==0)
          dp[i][j]= INT_MAX;
        else if(j>=val[i-1]){
          dp[i][j] = min(w[i-1] + dp[i-1][j-val[i-1]], dp[i-1][j]);
          if (dp[i][j] <= W)
        	ans = max(ans, j);
        }
        else{
        	dp[i][j] = dp[i-1][j];
          if (dp[i][j] <= W)
        	ans = max(ans, j);
        }
        
      }
    }
  	cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=998244353;
const int siz=2e5;
const int inf=1e9;
int main(){
	int N; cin>>N;
	long cnt[100001] = {}; int a; long sum = 0;
	rep(i,0,N){ cin>>a; cnt[a]++; }
    rep(i,0,100001) sum += i * cnt[i];
	int Q; cin>>Q;
	int b,c;
	rep(i,0,Q){
		cin>>b>>c;
        sum += (c - b) * cnt[b];
		cnt[c] += cnt[b];
		cnt[b] = 0;
        cout<<sum<<endl;
	}
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
using namespace std;
int power(int a,int b)
{   int m=2019;
    int res=1;
    while(b>0)
    {
      if(b&1)
      res=(res*a)%m;
      b/=2;
      a=(a*a)%m;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    string s; cin>>s;
    int n=s.length();
    map<int,int>g; set<int>r;
    int p=s[n-1]-48; g[p]++;
    r.insert(p); int prev=p; 
    repr(i,n-2,0)
    {
        p=((power(10,n-i-1)*(s[i]-48))%2019+prev)%2019;
        r.insert(p);
        g[p]++;
        prev=p;
    }
    ll count=0;
    for(auto i:r)
    {
        int m=g[i];
        if(m&1)
        {
            ll k=(m-1)/2; k*=m;
            count+=k;
        }
        else
        {
            ll k=m/2; k*=(m-1);
            count+=k;
        }
    }
    count+=g[0];
    cout<<count<<"\n";
    return 0;
}

Measured memory_bytes: 3784
program main
integer :: n,k,q
integer,allocatable :: a(:),b(:)
read(*,*)n,k,q
allocate(a(q),b(n))
b = k - q
do i = 1,q
read(*,*)a(i)
end do
do i = 1,q
b(a(i)) = b(a(i)) + 1
end do
do i = 1,n
if(b(i) <= 0)then
write(*,*)'No'
else
write(*,*)'Yes'
end if
end do
end program

Measured memory_bytes: 1536
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from collections import deque

MOD = 10**9 + 7
N = int(input())
tree = dict(zip(range(N), [[] for i in range(N)]))
edge_id = {}
c = 0
for i in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  tree[a].append(b)
  tree[b].append(a)
  edge_id[(a, b)] = c
  edge_id[(b, a)] = c + 1
  c += 2

# 部分木のサイズ
# 頂点v1 -> v2の向きを考えたときに、頂点v2を根とする部分木のサイズを計算する
size = [0] * 2*(N-1)
def calc_size(v1, v2):
  global size
  idx = edge_id[(v1, v2)]
  if size[idx]:
    return size[idx]
  children = tree[v2]
  s = 1
  for child in children:
    if child == v1:
      continue
    s += calc_size(v2, child)
  size[idx] = s
  idx_inv = edge_id[(v2, v1)]
  size[idx_inv] = N - s
  return s

# 階乗、組合せの計算
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10**9+7
for i in range(2, 2*10**5+1):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

def comb(n, r, mod=MOD):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod

# 頂点iに1を書くときの場合の数
ans = [0] * N
dp = [0] * 2*(N-1)
def calc_dp(v1, v2):
  global dp
  idx = edge_id[(v1, v2)]
  if dp[idx]:
    return dp[idx]
  children = tree[v2]
  s = calc_size(v1, v2)
  res = g1[s-1]
  for child in children:
    if child == v1:
      continue
    res *= calc_dp(v2, child)
    res %= MOD
    _s = calc_size(v2, child)
    res *= g2[_s]
    res %= MOD
  dp[idx] = res
  return res

def calc_ans(i):
  global ans
  global dp
  if ans[i]:
    return ans[i]
  children = tree[i]
  res = g1[N-1]
  for child in children:
    res *= calc_dp(i, child)
    res %= MOD
    _s = calc_size(i, child)
    res *= g2[_s]
    res %= MOD
  ans[i] = res
  return res

# 頂点0に1と記入する場合の数を求める
calc_ans(0)
# そこからはbfsで子に伝搬させていく
# 伝搬の漸化式はnode -> childのとき
# ans[child] = ans[node] * size[(node, child)]/size[(child, node)]
d = deque([[0, -1]])
c = 0
while d:
  node, par = d.popleft()
  c += 1
  children = tree[node]
  for child in children:
    if child == par:
      continue
    s1 = calc_size(node, child)
    s2 = N - s1
    r = (g1[s1] * g1[s2-1] % MOD) * (g2[s1-1] * g2[s2] % MOD) % MOD
    ans[child] = ans[node] * r % MOD
    d.append([child, node])

print(*ans, sep='\n')

Measured memory_bytes: 186912
#include <stdio.h>

int main(){
  int X,N,p[103];
  int tmp;
  
  scanf("%d %d",&X,&N);
  for(int i=1;i<=N;i++){
    scanf("%d",&tmp);
    p[tmp+1]=1;
  }
  
  int c=0,d=0;
  while(c==0){
    if(p[X+d+1]!=1) c=1;
    if(p[X-d+1]!=1) c=-1;

    if(c==0) d++;
  }
  
  printf("%d\n",X+c*d);
  
  return 0;
}


Measured memory_bytes: 1736
//
// Created by Hideaki Imamura on 2019-07-12.
//

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
    ll n, a;
    vector<ll> s;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        s.push_back(a - (i+1));
    }

    sort(s.begin(), s.end());

    ll median = s[n / 2];

    ll res = 0;
    for(int i = 0; i < n; ++i) {
        res += abs(s[i] - median);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    int ans = (N - 1) / (K - 1);
    if((N - 1) % (K - 1) != 0) {
        ans++;
    }
    cout << ans << endl;
}

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

int main(void)
{
	int k, s;
	cin >> k >> s;
	
	int count = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			if (x + y <= s && x + y + k >= s) {
				count++;
			}
		}
	}


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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000009
# define pi acos(-1)
# define fi first
# define se second
using namespace std;


signed main()
{
    gok
    int n;
    cin>>n;
    int p=15;
    int su=0;
    int ss = n*(n+1);
    ss/=2;
    for(int i=3;i<=n;i++)
    {
        if(i%3==0 || i%5==0)
            su+=i;
    }

cout<<ss-su;









      return 0;
    }


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

#define maxv 1000*(1000-1)/2+1

int dp[maxv];
vector<vector<int>>graph;
vector<int>visited,cal;
int dfs(int v){//最長経路
    if(visited[v]){
        if(!cal[v])return -1;
        return dp[v];
    }
    visited[v]=true;
    dp[v]=1;
    for(auto x:graph[v]){
        int res=dfs(x);
        if(res==-1)return -1;
        dp[v]=max(dp[v],res+1);
    }
    cal[v]=1;
    return dp[v];//トポロジカルソートはメモ化再帰と相性がよい
}
signed main(){
    int n;
    cin>>n;
    vector<vector<int>>a(n,vector<int>(n-1));
    rep(i,n)rep(j,n-1){
        cin>>a[i][j];
        a[i][j]--;
    }
    int v=0;
    vector<vector<int>>id(n,vector<int>(n));
    graph.resize(maxv);
    rep(i,n)rep(j,n){
        if(i<j)id[i][j]=v++;
    }
    rep(i,n)
    {
        rep(j,n-1){
        if(i<a[i][j])a[i][j]=id[i][a[i][j]];
        else a[i][j]=id[a[i][j]][i];
        }
        rep(j,n-2)graph[a[i][j+1]].pb(a[i][j]);//前後関係は同じ選手のスケジュールに依存
    }
    int ans=0;
    visited.resize(maxv,0);
    cal.resize(maxv,0);
    rep(i,v){
        int res=dfs(i);
        if(res==-1){//resが-1のとき、ループがあり実現不可
            cout<<-1<<endl;
            return 0;
        }
        ans=max(ans,res);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 41344
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		while(true){

			StringBuilder str = new StringBuilder(in.next());

			if(str.substring(0).equals("-")){

				break;

			}else{

			int shuffle_num = in.nextInt();

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

					int card_num = in.nextInt();

					String shuffle_word = str.substring(0, card_num);

					str.delete(0, card_num);

					str.append(shuffle_word);

				}
			}

			System.out.println(str.toString());



		}





	}

}

Measured memory_bytes: 26440
#include <stdio.h>
#include <queue>

using namespace std;

int n,inputed_order[41] = {0};
queue<int> Queue;

struct Node{
	Node(){
		left_child = right_child = -1;
	};
	int left_child,right_child;
};

void postORDER(Node order[],int id){
	if(order[id].left_child != -1) postORDER(order,order[id].left_child );
	if(order[id].right_child != -1) postORDER(order,order[id].right_child );
	Queue.push(id+1);
}

int findRoot(int inorder[],int left,int right){
	int root = inorder[left];
	for(int i = left+1; i <= right; i++){
		if(inputed_order[root] > inputed_order[inorder[i]]){
			root = inorder[i];
		}
	}
	return root;
}

void reconstruct(int inorder[],Node order[],int root,int left,int right){
	int root_index;
	for(root_index = left; inorder[root_index] != root; root_index++);
	if(left < root_index){
		int new_root = findRoot(inorder,left,root_index-1);
		order[root-1].left_child = new_root-1;
		if(left < root_index-1)	reconstruct(inorder,order,new_root,left,root_index-1);
	}
	if(root_index < right){
		int new_root = findRoot(inorder,root_index+1,right);
		order[root-1].right_child = new_root-1;
		if(root_index+1 < right) reconstruct(inorder,order,new_root,root_index+1,right);
	}
}

int main(){
	scanf("%d",&n);
	int preorder[n],inorder[n];
	Node order[n];

	for(int i = 0; i < n; i++){
		scanf("%d",&preorder[i]);
		inputed_order[preorder[i]] = i;
	}
	for(int i = 0; i < n; i++){
		scanf("%d",&inorder[i]);
	}

	if(n == 1){
		printf("%d\n",preorder[0]);
	}else{
		reconstruct(inorder,order,preorder[0],0,n-1);
		postORDER(order,preorder[0]-1);
		while(!Queue.empty()){
			if(Queue.size() != 1){
				printf("%d ",Queue.front());
				Queue.pop();
			}else{
				printf("%d\n",Queue.front());
				Queue.pop();
			}
		}
	}

}

Measured memory_bytes: 1036
room = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

def enter_room(building_index, floor_index, room_index, num):
    room[building_index][floor_index][room_index] += num

N = int(input())

for i in range(N):
    building_num, floor_num, room_num, num = list(map(int, input().split()))
    enter_room(building_num - 1, floor_num - 1, room_num - 1, num)

for b in range(len(room)):
    for f in range(len(room[b])):
        line = ''
        for r in range(len(room[b][f])):
            line += ' ' + str(room[b][f][r])
        print(line)
    if b < len(room) - 1:
        print('####################')


Measured memory_bytes: 5604
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
     int n, k; cin >> n >> k;
     vector<int> A(n); rep(i, n) cin >> A[i];

     rep(i, min(1000, k)){
         
         vector<int> plus(n), minus(n);
      rep(j, n){
        int s = max(0, j-A[j]), t = min(n-1, j+A[j]);
        plus[s]++; minus[t]++;
      }
      int cnt = 0;
      rep(j, n){
        cnt += plus[j];
        A[j] = cnt;
        cnt -= minus[j];
     }
     }
     rep(i, n)cout << A[i] << " ";
     cout << ln;
}
    

 


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
const int NMAX = 2000;



int main(){
    int n;
    cin >> n;
    ll x,y;
    
    multiset<ll> a,b;
    
    rep(i,n){
        cin >> x >> y;
        a.insert(x+y);
        b.insert(x-y);
    }
    
    ll da = *a.rbegin() - *a.begin();
    ll db = *b.rbegin() - *b.begin();
    ll ans = max(da,db);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 22376
#include <stdio.h>

int main()
{
  int a, b, c, d, e, k;

  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  scanf("%d", &d);
  scanf("%d", &e);
  scanf("%d", &k);

  if (e - a > k) {
    printf(":\(\n");
  } else {
    printf("Yay!\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 300005;
const int mod = 998244353;
ll d[63];
ll a[205];
string s;
bool add(ll x) {
    for (int i = 62 ; i >= 0 ; i--) {
        if (x & (1LL<<i)) {
            if (d[i] == -1) {
                d[i] = x;
                return true;
            }
            x ^= d[i];
        }
    }
    return 0;
}
void solve() {
    memset(d, -1, sizeof(d));
    int n;
    cin >> n;
    f (n) {
        cin >> a[i];
    }
    cin >> s;
    int f = 0;
    for (int i = n - 1 ; i >= 0 ; i--) {
        if (add(a[i]) && s[i] == '1') {
            f = 1;
            break;
        }
    }
    cout << f << '\n';
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}


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

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

const double eps = 1e-10;

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

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	int ch[26] = {};
	cin >> H >> W;
	REP(i, H){
		REP(j, W){
			char a;
			cin >> a;
			ch[a-'a']++;
		}
	}
	int num1 = 0, num2 = 0, num4 = 0;
	REP(i, 26){
		if(ch[i] == 0) continue;
		num4 += ch[i]/4;
		ch[i]%=4;
		num2 += ch[i]/2;
		ch[i] %= 2;
		num1 += ch[i];;
	}
	int a = (H%2)*(W%2), b = (H/2)*(W/2);
	if(num1 != a || num4 < b){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}


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

int main () {
  vector<int> banana;
  banana = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  int A,B;
  cin>>A>>B;
  if(banana[A]==banana[B]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
let n = stdin.ReadLine() |> int
let mutable a = stdin.ReadLine().Split(' ') |> Array.map int64
let mutable ans = 1000000000000000005L 

let X = Array.sum(a) |> int64
let mutable x = 0 |>int64

let mini(c,b)=
    if c > b then
        b
     else
        c

let abns(e)=
    if e > 0 then
        e|>int64
    else
        -e|>int64

for i in[0..n-1]do
x<-x+a.[i]
let tw = 2|>int64
let dd = tw*x
let dx = X-dd
if i+1<n then ans <- mini(ans,abs(dx));;

printfn "%d" ans

Measured memory_bytes: 47328
n,i;
ea[2<<17],eb[2<<17],next[2<<17],first[1<<17];
long M,dp1[1<<17],dp2[1<<17],R[2<<17];
/*dfs1(u,p,i)
{
	dp1[u]=1;
	for(i=first[u];i;i=next[i])eb[i]-p?dfs1(eb[i],u),dp1[u]=dp1[u]*-~dp1[eb[i]]%M:0;
}*/
dfs1(u,p,i,I)
{
	dp1[u]=1;
	for(i=first[u];I=eb[i];i=next[i])I-p?dfs1(I,u),dp1[u]=dp1[u]*-~dp1[I]%M:0;
}
/*dfs2(u,p,x,i)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p,x);
	for(;i;i=next[i])
	{
		if(eb[i]!=p)dfs2(eb[i],u,L[i]*R[next[i]]%M+1);
	}
}
make(i,p,x,t)
{
	if(i)
	{
		L[i]=x;
		t=eb[i]-p?-~dp1[eb[i]]:1;
		make(x=next[i],p,t%M*x%M);
		R[i]=R[x]*t%M;
	}
}*/
/*
dfs2(u,p,x,i)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p);
	for(;i;i=next[i])eb[i]-p?dfs2(eb[i],u,R[next[i]]*x%M+1),x=x%M*-~dp1[eb[i]]%M:0;
}
*/
/**/
dfs2(u,p,x,i,I)
{
	dp2[u]=dp1[u]*x%M;
	for(make(i=first[u],p);I=eb[i];i=next[i])I-p?dfs2(I,u,R[next[i]]*x%M+1,0,0),x=x%M*-~dp1[I]%M:0;
	//dp2[u]=x;
}
/**/
make(i,p)
{
	if(i)make(next[i],p),R[i]=R[next[i]]*(eb[i]-p?-~dp1[eb[i]]:1)%M;
}
main(u,v)
{
	/*for(scanf("%d%d",&n,&M);~scanf("%d%d",&u,&v);)
	{
		i++;
		ea[i]=u;
		eb[i]=v;
		i++;
		ea[i]=v;
		eb[i]=u;
	}*/
	//for(;~scanf("%d%d",&u,&v);)i++?ea[i]=eb[i+1]=u,ea[i+1]=eb[i]=v,i++:(n=u,M=v);
	for(;~scanf("%d%d",&u,&v);i++)i++?ea[i-1]=eb[i]=u,ea[i]=eb[i-1]=v:(n=u,M=v);
	//for(;~scanf("%d%d",&u,&v);)i++?ea[i-1]=eb[i]=u,eb[i-1]=ea[i++]=v:(n=u,M=v);
	for(;--i;first[ea[i]]=i)next[i]=first[ea[i]];
	dfs1(*R=1,0);
	dfs2(1,0,1);
	for(;i++<n;)printf("%d\n",dp2[i]);
}

Measured memory_bytes: 11520
from bisect import bisect_left


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]

    def is_root(self, x):
        return self.parent[x] < 0

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]


def check(i, j):
    global friends
    global blocks
    a = bisect_left(friends, [i, j])
    b = bisect_left(friends, [j, i])
    c = bisect_left(blocks, [i, j])
    d = bisect_left(blocks, [j, i])



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

blocks = [[] for _ in range(n)]
friend_num = [0] * n
uf = UnionFind(n)

for _ in range(m):
    array = list(map(int, input().split()))
    uf.unite(array[0]-1, array[1]-1)
    friend_num[array[0]-1] += 1
    friend_num[array[1]-1] += 1

for _ in range(k):
    array = list(map(int, input().split()))
    blocks[array[0]-1].append(array[1]-1)
    blocks[array[1]-1].append(array[0]-1)

for i in range(n):
    uf.find(i)

for i in range(n):
    num = uf.size(i)
    personal_block_list = blocks[i]
    personal_block_num = 0
    for j in personal_block_list:
        if uf.same(i, j):
            personal_block_num += 1

    print(num-friend_num[i]-personal_block_num-1, end=' ')




Measured memory_bytes: 29368
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))

# 最も大きい数と、その1/2との差が最も小さい数を選ぶ
A = sorted(A, reverse = True)
one = A[0]
diff = one
ans = -1
for i in range(1,len(A)):
  if abs(one / 2 - A[i]) < diff:
    diff = abs(one / 2 - A[i])
    ans = A[i]
    
print(one, ans)

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

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

int main()
{
  int N, Q; cin >> N >> Q;
  string S; cin >> S;
  vector<int> l(Q), r(Q); rep(i, Q) cin >> l[i] >> r[i];

  vector<int> cumsum(N, 0);
  for (int i = 1; i < N; ++i) {
    cumsum[i] += cumsum[i-1];
    if (S[i-1] == 'A' and S[i] == 'C') cumsum[i]++;
  }

  for (int i = 0; i < Q; ++i) {
    cout << cumsum[r[i]-1] - cumsum[l[i]-1] << endl;
  }
}

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

int D;
const int N = 26;

int calc(const vector<int> &C, const vector<vector<int>> &S, vector<int> &T, vector<int> &L) {
    int res = 0;
    for(int d = 0; d < D; ++d) {
        res += S[d][T[d]];
        L[T[d]] = d;
        for(int i = 0; i < N; ++i) {
            res -= C[i] * (d - L[i]);
        }
        cout << res << '\n';
    }
    return res;
}

int main() {
    cin >> D;
    vector<int> C(N);
    for(int i = 0; i < N; ++i) cin >> C[i];
    vector<vector<int>> S(D, vector<int>(N));
    for(int i = 0; i < D; ++i) {
        for(int j = 0; j < N; ++j) cin >> S[i][j];
    }
    vector<int> T(D);
    for(int i = 0; i < D; ++i) {
        cin >> T[i];
        T[i]--;
    }

    vector<int> L(N, -1);

    calc(C, S, T, L);
    return 0;
}


Measured memory_bytes: 3672
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int main(){
	int N,X;
	cin >> N >> X;
	int now = 0;
	int ans = 1;
	for(int i=0; i<N; i++){
		int tmp;
		cin >> tmp;
		now += tmp;
		if(now <= X) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// youngjinp20
// 2020 07

#include <bits/stdc++.h>
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define byr(x) [](const auto& a, const auto& b) { return a.x > b.x; }
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pa;

const int MAX = 1e5;
const int MOD = 1e9+7;
int N;
vector<int> G[MAX+1];

pa dfs(int v, int from) {
	queue<pa> values;
	for (auto e : G[v]) {
		if (e == from) continue;
		values.push(dfs(e, v));
	}

	ll b=1, w=1;
	while (!values.empty()) {
		auto x = values.front();
		values.pop();
		b *= x.second;
		b %= MOD;
		w *= x.first + x.second;
		w %= MOD;
	}

	return {b, w};
};

int main() {
	cin >> N;

	for (int i=1; i<N; i++) {
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	pa ret = dfs(1, 0);
	cout << (ret.first + ret.second) % MOD << endl;

	return 0;
}


Measured memory_bytes: 78456
#include<iostream>
#include<algorithm>
#include<numeric>
#include<iterator>
#include<vector>

using namespace std;
typedef unsigned int val;

int main() {
	val n, kari;
	while(cin >> n && n) {
		val p = 0;
		for(val i = 0; i < n; ++i) {
			cin >> kari;
			p = p + kari;
		}

		vector<val> j(n-1);
		for(vector<val>::iterator ite = j.begin(); ite != j.end(); ++ite) cin >> *ite;
		sort(j.rbegin(), j.rend());
		partial_sum(j.begin(), j.end(), j.begin());

		val s = p * n;
		for(vector<val>::iterator ite = j.begin(); ite !=j.end(); ++ite) {
			if(s < (p + *ite) * distance(ite, j.end())) s = (p + *ite) * distance(ite, j.end());
			else break;
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1444
n = int(input())
lst = []
b = 0
for i in range(n):
    s = str(raw_input())
    lst.append(s)
    if s == "Un":
        if ("A" in lst) == True:
            lst.remove("A")
            lst.remove("Un")
        else:
            b = 1
if b != 0:
    print "NO"
else:
    if len(lst) != 0:
        print "NO"
    else:
        print "YES"

Measured memory_bytes: 6452
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using Graph=vector<vector<ll>>;
int main(){
  ll n,t;cin>>n>>t;
  vector<ll> ti(n);
  rep(i,n)cin>>ti[i];
  ll c=t;
  for(int i=n-1;i>0;--i){
    c+=min(t,ti[i]-ti[i-1]);
  }
  cout<<c;
}

Measured memory_bytes: 1792
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

uint8_t buf[100][100];

int32_t main(void)
{
  int32_t H, W;
  scanf("%d %d", &H, &W);
  for (uint8_t i = 0; i < H; i++) {
    scanf("%s", buf[i]);
  }

  for (int32_t i = 0; i < (W + 2); i++) {
    printf("#");
  }
  printf("\n");

  for (int32_t i = 0; i < H; i++) {
    printf("#");
    for (int32_t j = 0; j < W; j++) {
      printf("%c", buf[i][j]);
    }
    printf("#\n");
  }

  for (int32_t i = 0; i < (W + 2); i++) {
    printf("#");
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 128
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        h, w = map(int, input().split())
        a = []
        for i in range(h):
            a.append(list(input()))
        # print(h)
        # print(w)
        # print(a)

        hash = []
        for i in range(h):
            for j in range(w):
                if a[i][j] == '#':
                    hash.append((i, j))
        # print(hash)
                
        queue = [(0, 0, [(0, 0)])]
        flag = False
        while queue:
            # print(queue)
            i, j, hist = queue.pop(0)
            if (i, j) == (h - 1, w - 1) and a[i][j] == '#' and hist == hash:
                flag = True
                break
            else:
                if i + 1 < h and a[i+1][j] == '#':
                    queue.append((i + 1, j, hist + [(i + 1, j)]))
                if j + 1 < w and a[i][j+1] == '#':
                    queue.append((i, j + 1, hist + [(i, j + 1)]))
        if flag:
            print('Possible')
        else:
            print('Impossible')
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()


Measured memory_bytes: 5232
def split_ii(h, w):
    if w==2:
        return h*w
    elif w%3==0:
        return 0
    else:
        return h

def split_t(h, w):
    ans = h*w
    for i in range(h//5, (h+1)//2+1):
        head = i*w
        left = (h-i)*(w//2)
        right = (h-i)*(w - w//2)
        ans = min(ans, max(head, left, right)-min(head, left, right))
    return ans

h, w = map(int, input().split())
print(min(split_ii(h, w), split_ii(w, h), split_t(h, w), split_t(w, h)))

Measured memory_bytes: 3064
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n').map(a => a.split(' '))
  let ary = [0, 0, 0, 0]
  for (let i = 0; i < input.length; i++) {
    ary[input[i][0] - 1]++
    ary[input[i][1] - 1]++
  }
  ary.sort((a, b) => a - b)
  if (ary[0] == 1 && ary[1] == 1 && ary[2] == 2 && ary[3] == 2) {
    console.log('YES')
  } else {
    console.log('NO')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
N, A, *x = map(int, open(0).read().split())

NX = N * max(x + [A])
y = [0] + [v - A for v in x]
dp = [[0] * (2 * NX + 1) for _ in range(N + 1)]

dp[0][NX] = 1  
for j in range(1, N + 1):
    for t in range(2 * NX + 1):
        if t - y[j] < 0 or t - y[j] > 2 * NX:
            dp[j][t] = dp[j - 1][t]
        elif 0 <= t - y[j] <= 2 * NX:
            dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y[j]]
                
print(dp[N][NX] - 1)


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

int main(){
	int n;
	std::cin >> n;
	std::vector<int> h(n);
	int hmax=0;
	int count = 0;
	for(int i=0; i<n; i++){
		std::cin >> h[i];
		if(hmax<=h[i]){
			count++;
			hmax = h[i];
		}
	}
	std::cout << count <<std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
using namespace std;

// LongestCommonSubsequence; 最長共通部分列
// ：文字列sと文字列tの最長共通部分列長及び部分列（1例）の組を返す
pair<long long, string> LongestCommonSubsequence(const string s, const string t){
    vector<vector<long long>> dp(s.size()+1, vector<ll>(t.size()+1, 0));
    for(long long i=1; i<=s.size(); i++){
        for(long long j=1; j<=t.size(); j++){
            if(s[i-1] == t[j-1]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
            dp[i][j] = max(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
        }
    }
    long long i=s.size(), j=t.size(); string subsequence = "";
    while(i>0 && j>0){
        if(dp[i][j] == dp[i-1][j]) i--;
        else if(dp[i][j] == dp[i][j-1]) j--;
        else{ subsequence = s[i-1] + subsequence; i--; j--; }
    }
    return make_pair(dp[s.size()][t.size()], subsequence);
}

int main(){
    Init();
    string s, t; cin >> s >> t;
    auto lcs = LongestCommonSubsequence(s, t);
    cout << lcs.second << endl;
}

Measured memory_bytes: 70784
#include<iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000
using namespace std;
int main()
{
    vector<int> a(5);
    rep(i,5) cin>>a[i];
    int final_ans=INF;
    do
    {
        int ans=0;
        rep(i,a.size())
        {
            ans+=a[i];
            if(i!=a.size()-1)
            {
                int offset=10-(a[i]%10);
                if(offset==10)offset=0;
                ans+=offset;
            }
        }
        final_ans=min(ans,final_ans);
    }while (next_permutation(a.begin(),a.end()));
    cout<<final_ans<<endl;

   return 0;
}

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

int main() {
	int H, W, i, k;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0) {
			break;
		}

		for (k = 1; k <= H; k++) {
			if (k % 2 == 1) {
				for (i = 1; i <= W; i++) {
					if (i % 2 == 1) {
						cout << "#";
					} else {
						cout << ".";
					}
					if (i == W) {
						cout << endl;
					}
				}
			}else{
				for (i = 1; i <= W; i++) {
					if (i % 2 == 0) {
						cout << "#";
					} else {
						cout << ".";
					}
					if (i == W) {
						cout << endl;
					}
				}
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3096
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var l = Sarray();
            if (l.Sum() - l.Max() <= l.Max())
                WriteLine("No");
            else
                WriteLine("Yes");
        }


        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 28232
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
V g[ohara];
ll dat[400][400];
bool vi[400];
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------

void dfs(ll moto,ll now){
    if(vi[now])return;
    vi[now]=true;
    dat[moto][now]=1;
    rep(i,Size(g[now])){
        dfs(moto,g[now][i]);
    }
}
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>m;
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        g[a[i]].p_b(b[i]);
    }
    rep(i,n){
        rep(j,n+1)vi[j]=false;
        dfs(i,i);
    }
    rep(i,n){
        V ans;
        rep(j,n){
            if(dat[i][j]&&dat[j][i])ans.p_b(j);
        }
        sort(all(ans));
        rep(j,Size(ans)){
            cout<<ans[j]+1;
            if(j==Size(ans)-1)cout<<"\n";
            else cout<<" ";
        }
    }
    return 0;
}


Measured memory_bytes: 30092