akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new AOJ1148().doIt();
	}
	class AOJ1148{
		void doIt(){
			while(true) {
				int PC[][] = new int[10001][1500];
				int N = sc.nextInt();
				int M = sc.nextInt();
				if(N + M == 0)break;
				int r = sc.nextInt();
				for(int i = 0;i < r;i++) {
					int t = sc.nextInt();
					int n = sc.nextInt();
					int m = sc.nextInt();
					int s = sc.nextInt();
					if(s == 1)PC[m][t]++;
					else PC[m][t]--;
				}
				for(int i = 1;i <= M;i++) {
					for(int j = 500;j < 1500;j++) {
						PC[i][j] = PC[i][j] + PC[i][j-1];
					}
				}
				int q = sc.nextInt();
				for(int i = 0;i < q;i++) {
					int ts = sc.nextInt();
					int te = sc.nextInt();
					int m = sc.nextInt();
					int cnt = 0;
					for(int pos = ts;pos < te;pos++) {
						if(PC[m][pos] > 0) {
							cnt++;
						}
					}
					System.out.println(cnt);
				}
			}
		}
	}
}



Measured memory_bytes: 430748
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sim         template < class c
#define ris         return * this
#define dor         > debug & operator <<
#define eni(x)      sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

using namespace std;

sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug 
{
	~debug() 
	{ 
		cerr<<endl; 
	}
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int a;
		cin >> a;
		ll int ans = a + a * a + a * a * a;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 1000000007
using namespace std;
typedef long long ll;

int main(){
  map<char, int>  mp;
  string s; cin >> s;
  for(char c : s){
    mp[c]++;
  }
  for(auto itr=mp.begin(); itr!=mp.end(); itr++){
    if(itr->second%2!=0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a*(b/gcd(a,b));}
long long 
int main(){
  long long n,m,a,b,i;
  char s[100010],t[100010];
  scanf("%lld %lld",&n,&m);
  scanf("%s %s",s,t);
  a=lcm(n,m);
  b=gcd(n,m);
  for(i=0;i<b;i++){
    if(s[i*n/b]-t[i*m/b])a=-1;
  }
  printf("%lld\n",a);
  return 0;
}


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

#define P(s) cout<<(s)<<"\n"
#define R(v) v.begin(),v.end()

int main() {
    string s;
    cin >> s;
    auto o = count(R(s), 'o');
    P((700 + 100 * o));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define sqr(x) (x)*(x)
#define mod 1000000007
#define pi acos(-1.0)

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    double r;
    cin>>r;
    cout<<2*pi*r<<endl;
    return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;



int main() {
    int n,m; cin >> n >> m;
    vector<vector<int> > v(n,vector<int>());
    for (int i = 0; i < m; i++) {
      int a,b; cin >> a >> b;
      a--;
      b--;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    string ans = "IMPOSSIBLE";
    for(int i = 0;i < v[0].size();i++){
        int z = v[0][i];
        for(int j = 0;j < v[z].size();j++){
            if(n-1 == v[z][j]){
                ans = "POSSIBLE";
                break;
            }
        }
    }
    cout << ans;
}



Measured memory_bytes: 12016
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

int main()
{
  int n;
  cin >> n;
  int check = 1;
  int a[200100];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    if (a[i] == check)
    {
      check++;
    }
  }
  if (check == 1)
  {
    cout << -1 << "\n";
  }
  else
  {
    cout << n + 1 - check << "\n";
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  ll input(n);
  ll diff = ('z' - 'a') + 1;

  auto to_char = [&](int x){
    return (char)('a' + (x - 1 + diff) % diff);
  };

  vector<char> result;
  while (n > 0) {
    ll m = n % diff;
    if (m == 0) {
      m += diff;
      n -= diff;
    }
    n /= diff;
    result.push_back(to_char(m));
  }

  REP(i, result.size()) {
    cout << (char)result[result.size() - i - 1];
  }
}


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

const int MAXN = 1e5 + 10;
const int INF = 2*1e9;

int dp[MAXN],N,K,h[MAXN];

int main(){

	cin>>N;
	K = 2;
	for(int i = 1;i<=N;i++){
		cin>>h[i];
	}

	for(int i = 2;i<=N;i++){
		dp[i] = INF;
		for(int j = i-1;j>=max(i - K,1);j--){
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]) );
		}
	}

	cout<<dp[N];

	return 0;

}

Measured memory_bytes: 1024
import java.io.PrintWriter
import kotlin.math.pow

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun Int.pow(n: Int) = toDouble().pow(n).toLong()

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (A, B) = nextLongList()
    if (A % 2 == 0L) {
        val one = (B - A + 1) / 2
        val c = one % 2
        println(c xor if ((B - A + 1) % 2 == 0L) 0L else B)
    } else {
        val one = (B - A) / 2
        val c = one % 2
        println(A xor c xor if ((B - A) % 2 == 0L) 0L else B)
    }
}

Measured memory_bytes: 36560
# coding: utf-8

import sys 

sys.setrecursionlimit(1000000)
class DFSSolver:

    def __init__(self, table, h, w):
        self.table = table
        self.count = 0
        self.h = h
        self.w = w

    def delta(self, i, j):
        candididate = [(i-1, j-1), (i-1, j), (i-1, j+1),
                       (i, j-1), (i, j+1),
                       (i+1, j-1), (i+1, j), (i+1, j+1)]
        return candididate

    def dfs(self, i, j):
        self.table[i][j] = 0
        for i, j in self.delta(i, j):
            if i < 0 or j < 0 or i >= self.h or j >= self.w:
                pass
            elif self.table[i][j] == 1:
                self.dfs(i, j)

    def solve(self):
        for i in range(self.h):
            for j in range(self.w):
                if self.table[i][j] == 1:
                    self.dfs(i, j)
                    self.count += 1
        print(self.count)


W, H = list(map(int, input().split(" ")))
while W != 0 and H != 0:
    t = []
    for _ in range(H):
        t.append(list(map(int, input().split(" "))))
    d = DFSSolver(t, H, W)
    d.solve()
    W, H = list(map(int, input().split(" ")))




Measured memory_bytes: 9300
import numpy as np

n, s = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353

dp = np.zeros((s + 1, 3), dtype=np.int64)
dp[0][0] = 1

for i, e in enumerate(a):
    cp = dp.copy()

    dp[:, 1] += cp[:, 0]
    dp[:, 2] += cp[:, 0] + cp[:, 1]

    dp[e:, 1] += cp[:-e, 0] + cp[:-e, 1]
    dp[e:, 2] += cp[:-e, 0] + cp[:-e, 1]

    dp %= mod

ans = dp[s][2]
print(ans)


Measured memory_bytes: 20856
def gcd(a, b) :
    if a % b == 0 :
        return b
    else :
        return gcd(b, a % b)

while True :
    try :
        a, b = map(int, input().split())
    except EOFError :
        break
    
    a, b = max(a, b), min(a, b)
    x = gcd(a, b)
    print(x, a * b // x)


Measured memory_bytes: 5600
import java.util.*;

public class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int sum = 0;
		for(int i = 0; i < M; i++) {
			sum += sc.nextInt();
		}
		if(N - sum >= 0) {
			System.out.println(N - sum);
		} else {
			System.out.println(-1);
		}

	}
	
}

Measured memory_bytes: 46316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll>(m, 0));
    REP(i, n){
        REP(j, m){
            cin >> a.at(i).at(j);
        }
    }
    vector<ll> b(m);
    REP(i, m){
        cin >> b.at(i);
    }

    REP(i, n){
        ll ans = 0;
        REP(j, m){
            ans += a.at(i).at(j) * b.at(j);
        }
        cout << ans << endl;
    }
    return 0;
}



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

#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define mod 998244353
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
const int N=2e6+7;
ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
    if(b&1)
    r=(r*a)%m;
    b=b/2;
    a=(a*a)%m;
    }
    return r%m;
}

int main()
{
 ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;

string s;
cin>>s;
vi r(n,0),g(n,0),b(n,0);
if(s[0]=='R')r[0]++;
else if(s[0]=='G')g[0]++;
else b[0]++;
rep(i,1,n)
{
    r[i]=r[i-1];
    g[i]=g[i-1];
    b[i]=b[i-1];
    if(s[i]=='R')r[i]++;
else if(s[i]=='G')g[i]++;
else b[i]++;
}
ll ans=0;
rep(i,0,s.length()-2)
{
    rep(k,i+2,n)
    {
        if(s[i]==s[k])continue;
        ll arr;
        char ch;
        if(s[i]!='R'&&s[k]!='R')arr=0,ch='R';
        else if(s[i]!='G'&&s[k]!='G')arr=1,ch='G';
        else arr=2,ch='B';
        if(arr==0)ans+=r[k-1]-r[i];
        else if(arr==1)ans+=g[k-1]-g[i];
        else ans+=b[k-1]-b[i];
        if((i+k)%2==0&&s[(i+k)/2]==ch)ans--;


    }
}
cout<<ans;

}



Measured memory_bytes: 3672
n = int(input())
for l in range(1, 10**3):
  if l*(l-1)//2 == n:
    print("Yes")
    print(l)
    S = [[] for _ in range(l)]
    now = 0
    count = 1
    for j in range(l-1):
      for k in range(l-1-j):
        S[now].append(count)
        S[now+1+k].append(count)
        count += 1
      now += 1
    for s in S:
      print(l-1, *s)
    break
else:
  print("No")


Measured memory_bytes: 9384
n, m = map(int, input().split())
lrs = [list(map(int, input().split()))
       for _ in range(m)]

ls = []
rs = []
for l, r in lrs:
    ls.append(l)
    rs.append(r)
l = max(ls)
r = min(rs)
if l <= r:
    print(r - l + 1)
else:
    print(0)

Measured memory_bytes: 29088
n = gets.chomp.to_i
as = gets.chomp.split.map(&:to_i)

ms = []
ms[0] = 0

(1..n).each do |i|
    ms[i] = 2 * as[i-1] - ms[i-1]
end

diff = (ms[n] - ms[0]) / 2

puts ms.take(n).each_with_index.map { |m, i| i.even? ? m + diff : m - diff }.join(' ')


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

ll knapsack(ll wt[], ll val[], ll n, ll W)
{
    ll dp[n+1][W+1];

    for(ll i=0; i<=n; i++)
    {
        for(ll j=0; j<=W; j++)
        {
            if(i==0 || j==0)
                dp[i][j] = 0;
            else if(wt[i-1]>j)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = max(dp[i-1][j], val[i-1] + dp[i-1][j-wt[i-1]]);
        }
    }

    return dp[n][W];
}

int main() 
{
    ll n,W;
    cin>>n>>W;

    ll wt[n+1], val[n+1];

    for(ll i=0; i<n; i++)
        cin>>wt[i]>>val[i];

    cout<<knapsack(wt,val,n,W)<<endl;

    return 0;
}


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

using namespace std;
using ll = long long;

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

ll gcd(ll a, ll b) {
    if (a < b) return gcd(b, a);
    ll r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n, k; cin >> n >> k;
    ll ans = 0;
    if (n % k == 0) ans = 0;
    else {
        ll g = n % k;
        ans = min(g, abs(k - g));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
   int a,b;
   while(cin>>a>>b,a||b){
        int d=b-a;
        int x=d/1000;d%=1000;
        int y=d/500;d%=500;
        int z=d/100;
        cout<<z<<" "<<y<<" "<<x<<endl;
   }
}

Measured memory_bytes: 1160
N, M, *SC = map(int, open(0).read().split())

for i in range(10 ** N):
    S = str(i)
    if len(S) == N:
        if all(S[s - 1] == str(c) for s, c in zip(*[iter(SC)] * 2)):
            print(S)
            quit()

print(-1)

Measured memory_bytes: 3060
#include<stdio.h>
#define N 10000
int main(){
  int i,j,count = 0,count1 = 0,count2 = 0,n,q,S[N],T[N],h,k;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(i = 0;i < q;i++){
    scanf("%d",&T[i]);
  }

  for(i = 0;i < q;i++){
    for(j = 0;j < n;j++){
      if(T[i] == S[j]){
	count1 = 1;
	count++;
      }
      if(count1 == 1){break;}
    }
    count1 = 0;
  }
	  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

class UnionFind {
public:
    // 親の番号を格納、自分が親なら-1
    vector<int> Parent;

    // 初めはバラバラな状態
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }

    // Aがどのグループに属しているか調べる
    int root(int A) {
        if(Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }

    // Aが属するグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];
    }

    bool connect(int A, int B) {
        // root(A)とroot(B)をくっつける
        A = root(A);
        B = root(B);
        if(A == B) { // すでにくっついてたら
            return false;
        }

        //大きいほう(A)に小さいほう(B)をくっつける
        if(size(A) < size(B)) swap(A, B);

        //Aのサイズを更新
        Parent[A] += Parent[B];
        //Bの親をAにする
        Parent[B] = A;

        return true;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    for(int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    vector<long long> ans(M);
    ans[M - 1] = (long long)N * (N - 1) / 2;

    UnionFind Uni(N);

    for(int i = M - 1; i >= 1; i--) {
        ans[i - 1] = ans[i];

        //つながったとき
        if(Uni.root(A[i]) != Uni.root(B[i])) {
            ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
            Uni.connect(A[i], B[i]);
        }
    }

    for(int i = 0; i < M; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3328
/**
 * Created by hiramekun at 20:44 on 2019-12-08.
 */
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w)), b(h, vector<ll>(w));
//    int a[h][w], b[h][w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];

    ll max_diff = 2 * 80 * 160;
    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(max_diff)));
//    bool dp[h][w][max_diff];
    rep(i, h) rep(j, w) rep(l, max_diff) dp[i][j][l] = false;

    ll mid = max_diff / 2;
    dp[0][0][b[0][0] - a[0][0] + mid] = true;
    dp[0][0][-b[0][0] + a[0][0] + mid] = true;

    rep(i, h) {
        rep(j, w) {
            rep(l, max_diff) {
                if (!dp[i][j][l]) continue;
                if (i + 1 <= h - 1) {
                    dp[i + 1][j][l + b[i + 1][j] - a[i + 1][j]] = true;
                    dp[i + 1][j][l - b[i + 1][j] + a[i + 1][j]] = true;
                }
                if (j + 1 <= w - 1) {
                    dp[i][j + 1][l + b[i][j + 1] - a[i][j + 1]] = true;
                    dp[i][j + 1][l - b[i][j + 1] + a[i][j + 1]] = true;
                }
            }
        }
    }
    ll ans = 1e18;
    rep(i, max_diff) {
        if (dp[h - 1][w - 1][i]) ans = min(ans, abs(i - mid));
    }
    cout << ans << '\n';
}

Measured memory_bytes: 20992
#include <iostream>
#include <set>
#include <cstring>

using namespace std;


int main() {

int n;
cin >> n;

set<string> ans;


for(int i = 0; i < n; i++) {
  string s;
  cin >> s;
  ans.insert(s);
}

cout << ans.size() << endl;

}


Measured memory_bytes: 19120
#include<iostream>
#include<numeric>
#include<algorithm>
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
int main(){
    int N,C;
    int ma,mi;
    while(cin>>N&&N>0){
        C=0;
        int a[N];
        for (int i = 0;i < N;++i) {
            cin >> a[i];
        }
        ma = *max_element(a, a + SIZE_OF_ARRAY(a));
        mi = *min_element(a, a + SIZE_OF_ARRAY(a));
        C = accumulate(a, a + SIZE_OF_ARRAY(a), 0);
        C -= mi;
        C -= ma;
        cout << C /(N-2)<< endl;
    }
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;


void solve(std::string S, std::string T){
    int ans = 0;
    rep(i,S.length()){
        if(S[i] == T[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
// #define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<int>a(n);
  std::cin>>a;
  int sum = std::accumulate(all(a), 0);

  std::vector<int> dp(sum+1,false);
  dp.at(0) = true;
  for (int x : a) {
    for (int i = sum - x; i >= 0; i--) {
      int j = i + x;
      dp.at(j) |= dp.at(i);
    }
  }
  // debug(dp);

  int ans = 0;
  rep(i,0,sum+1) {
    if (i%10 != 0 && dp.at(i)) cmx(ans,i);
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define f(i,a,b) for(register int i=a;i<=b;++i)
using namespace std;
int a,b,cnt,sockets;
int main() {
    cin>>a>>b;
  	sockets=1;
    while(sockets<b) {
      ++cnt;
      sockets=sockets+a-1;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
n,w = map(int,input().split())
c,t = [],[]
for i in range(n):
    C,T = map(int,input().split())
    c.append(C)
    t.append(T)
cand = []
for i in range(n):
    if t[i] <= w:
        cand.append(c[i])
if cand !=[]:
    print(min(cand))
else:
    print("TLE")
   

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  ll N, A, B; cin >> N >> A >> B;
  ll retval;
  if (A>B) retval = 0;
  else if (N==1 && A==B) retval = 1;
  else if (N==1 && A!=B) retval = 0;
  else {
    retval = B*(N-2) - A*(N-2) +1;
  } 
  cout << retval << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 256
def takahashi(a, b, k):
	if k >= a:
		k = k - a
		a = 0
		if k <= b:
			b = b - k
		else:
			b = 0
		if a < 0 and b < 0:
			a = 0
			b = 0
	else:
		a = a - k
		k = 0
		if a < 0 and b < 0:
			a = 0
			b = 0

	print(a, b)

a, b, k = map(int, input().split())
takahashi(a, b, k)

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

int main() {
	int c1[3], c2[3], c3[3];
	int c1min, c2min, c3min;
	for (int i = 0;i < 3;i++)
		cin >> c1[i];
	for (int i = 0;i < 3;i++)
		cin >> c2[i];
	for (int i = 0;i < 3;i++)
		cin >> c3[i];

	if (c1[0] < c1[1])
	{
		if (c1[0] < c1[2])
			c1min = c1[0];
		else c1min = c1[2];
	}
	else if (c1[1] < c1[2])
		c1min = c1[1];
	else c1min = c1[2];

	if (c2[0] < c2[1])
	{
		if (c2[0] < c2[2])
			c2min = c2[0];
		else c2min = c2[2];
	}
	else if (c2[1] < c2[2])
		c2min = c2[1];
	else c2min = c2[2];

	if (c3[0] < c3[1])
	{
		if (c3[0] < c3[2])
			c3min = c3[0];
		else c3min = c3[2];
	}
	else if (c3[1] < c3[2])
		c3min = c3[1];
	else c3min = c3[2];


	if ((c1[0] - c1min == c2[0] - c2min) &&(c1[0]-c1min== c3[0] - c3min))
		if ((c1[1] - c1min == c2[1] - c2min ) && (c1[1] - c1min == c3[1] - c3min))
			if ((c1[2] - c1min == c2[2] - c2min) && (c1[2] - c1min == c3[2] - c3min))
			{
				cout << "Yes" << '\n'; 
				return 0;
			}
	cout << "No"<<'\n';
	return 0;
}

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

namespace mp = boost::multiprecision;

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  for (ll i = 0; i < n; ++i) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  
  mp::cpp_int ans = 1;
  for (ll i = 0; i < n; ++i) {
    ans *= a[i];
    if (ans > mp::cpp_int(1000000000000000000)) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4036
#include <iostream>
using namespace std;
 
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a>=b&&b>=c){
		cout<<10*a+b+c<<endl;
	}
	else if(a>=c&&c>=b){
		cout<<10*a+b+c<<endl;
	}
	else if(b>=c&&c>=a){
		cout<<10*b+a+c<<endl;
	}
	else if(b>=a&&a>=c){
		cout<<10*b+a+c<<endl;
	}
	else if(c>=a&&a>=b){
		cout<<10*c+b+a<<endl;
	}
	else if(c>=b&&b>=a){
		cout<<10*c+b+a<<endl;
	}
}


Measured memory_bytes: 256
#include<string>
#include<list>
#include<iostream>
using namespace std;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
 
  string str;
  list<int> data;
  list<int>::iterator it,l;
  int n,x;
  cin >> n;
  while(n--){
    cin >> str;
    if(str == "insert"){
      cin >> x;
      data.push_front(x);
    }else if(str == "delete"){
      cin >> x;
      for(it=data.begin(),l=data.end();it!=l;++it){
    if(*it == x){
      data.erase(it);
      break;
    }
      }
    }else if(str == "deleteFirst") data.pop_front();
    else data.pop_back();
  }
  for(it=data.begin(),l=--data.end();it!=l;++it) cout << *it << " ";
  cout << *it << endl;
}


Measured memory_bytes: 34264
import sys

cnt = {}

for line in sys.stdin:
    for letter in line:
        if letter.isalpha():
            c = letter.lower()
            cnt[c] = cnt.get(c, 0)+1
            
for i in range(26):
    c = chr(ord("a")+i)
    print(c, ":", cnt.get(c, 0), sep=" ")


Measured memory_bytes: 5572
import sys
input = sys.stdin.readline

def idx(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

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

cnt = 0
for abc in range(1000):
    abc = list(str(abc).zfill(3))
    i = 0
    for dig in s:
        if dig == abc[i]:
            i += 1
            if i == 3:
                break
    if i == 3:
        cnt += 1

print(cnt)

Measured memory_bytes: 42732
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int N;
	cin >> N;
	map<string, int> Votes;
	int MaxVote = 0;
	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		Votes[S]++;
		MaxVote = max(MaxVote, Votes[S]);
	}
	for (auto itr : Votes) if (itr.second == MaxVote) cout << itr.first << endl;
}

Measured memory_bytes: 25216
s=input()
n=len(s)
if all(s[i]==s[n-i-1] for i in range(n)):
    if all(s[i]==s[(n-1)//2-i-1] for i in range((n-1)//2)):
        if all(s[(n+3)//2-1+i]==s[n-i-1] for i in range(n-(n+3)//2)):
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vector<int> x(3);
  x[0] = a+b;
  x[1] = a*b;
  x[2] = a-b;
  sort(x.begin(), x.end());
  cout << x[2] << endl;
}

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

int main() {
	string s;
	int q;
	cin >> s >> q;
	vector<int> t(q), f(q, 0);
	vector<string> c(q, "");
	for (int i = 0; i < q; i++) {
		cin >> t.at(i);
		if (t.at(i) == 2) {
			cin >> f.at(i) >> c.at(i);
		}
	}

	bool normal = true;
	for (int i = 0; i < q; i++) {
		if (t.at(i) == 1) {
			normal = !normal;
		}
		else if (t.at(i) == 2) {
			if (!normal) {
				if (f.at(i) == 1) f.at(i) = 2;
				else if (f.at(i) == 2) f.at(i) = 1;
			}
			if (f.at(i) == 1) {
				s.insert(0, c.at(i));
			}
			else if (f.at(i) == 2) {
				s.append(c.at(i));
			}
		}
		//cout << s << " process " << i << endl;
	}
	if (!normal) reverse(s.begin(), s.end());
	cout << s << endl;
}


Measured memory_bytes: 15232
X, K, D = list(map(int, input().split()))
k = abs(X) // D
if K <= k:
	print(abs(abs(X) - (D * K)))
else:
	K -= k
	if K % 2 == 0:
		print(abs(abs(X) - (D * k)))
	else:
		print(abs(abs(X) - (D * (k + 1))))


Measured memory_bytes: 9176
(let ((a (read))
    (b (read))
    (c (read))
    (x (read))
    (y (read))
    (ans 0))

    (loop for i from 0 to (max x y) do
        (let ((ab_count (* 2 i))
            (a_count (- x i))
            (b_count (- y i))
            (tmp 0))
            (if (< a_count 0) (setq a_count 0))
            (if (< b_count 0) (setq b_count 0))
            (setq tmp (+ (* a a_count) (* b b_count) (* c ab_count)))
            (if (or (= ans 0) (> ans tmp))
                (setq ans tmp)
            )
        )
    )
    (princ ans)
)

Measured memory_bytes: 24224
#include <iostream>
using namespace std;
int m[50][50],a,b,c,d,e,cou;

void dfs(int i,int j){
  if(i==b&&j==a)cou++;
  if(m[i+1][j]==0&&i+1<=b)dfs(i+1,j);
  if(m[i][j+1]==0&&j+1<=a)dfs(i,j+1);
}

int main(){
  while(1){
    cin >>a>>b;
    if(a==0&&b==0)break;
    for(int i=1;i<=b;i++){
      for(int j=1;j<=a;j++){
	m[i][j]=0;
      }
    }
    cin >>c;
    for(int i=0;i<c;i++){
      cin >>d>>e;
      m[e][d]=1;
    }

    cou=0;
    dfs(1,1);
    cout << cou <<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m, j int
	arr := make([]int, 0)
	total := 0
	fmt.Scanf("%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &j)
		arr = append(arr, j)
		total += j
	}
	popular := float64(total) / float64(4*m)
	sort.Sort(sort.Reverse(sort.IntSlice(arr)))
	// flag := true
	// for i := 0; i < m; i++ {
	// 	if arr[i] < popular {
	// 		flag = false
	// 		break
	// 	}
	// }
	if float64(arr[m-1]) >= popular {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
def partition(ary, p, r)
  x = ary[r]
  i = p-1
  (p...r).each{ |j|
    if ary[j] <= x
      i = i+1
      tmp = ary[i]
      ary[i] = ary[j]
      ary[j] = tmp
    end
  }
  tmp = ary[i+1]
  ary[i+1] = ary[r]
  ary[r] = tmp
  i+1
end

# main
n = gets.to_i
ary = gets.split(' ').map(&:to_i)
i = partition(ary, 0, ary.size-1)

ary[i] = "[#{ary[i]}]"
puts ary.join(' ')

Measured memory_bytes: 17116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const ll mod = 1000 * 1000 * 1000 * (ll) 1000 * 939+ 7;
const int N = 500005;
int val[N];
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	ll ans = 0;
	ll mx = 0;
	for(int i = 0; i < sz(s); i++)
		if(s[i] == '<')
			val[i + 1] = val[i] + 1;
	for(int i = sz(s) - 1; i >= 0; i--)
	{
		if(s[i] == '>')
			val[i] = max(val[i + 1] + 1 , val[i]);
		ans += val[i];
	}
	cout << ans + val[sz(s)];
}


Measured memory_bytes: 2844
import java.util.*;
 
public class Main{
 
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        int D = sc.nextInt();
      
        int d = D / 10;
        
        int count = 0; 
        for(int i = 2; i < d; i++){
          for(int j = 2; j <= 9; j++){
            if((i*j <= M)&&(i*j>=4)){
              count++;
           }
          }  
        }
        int d1 = D%10;
        if( d1 != 0){
          for(int k = 2; k <= d1 ; k++){
            if((d*k <= M)&&(d*k>=4)){
              count++;
            }
          }  
        }
      
         System.out.println(count);
      
    }
}

Measured memory_bytes: 35700
int main(){
int i,a,n,x,y;
long t;
t=0;
x=-1000001;
y=1000001;
scanf("%d",&n);
for (i=0;i<n;i++){
scanf("%d",&a);
t=t+a;
if(x<a) x=a;
if(y>a)y=a;
}
printf("%d %d %li\n",y,x,t);
return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>

using namespace std;

char Upper(char c) {
  return c - 32;
}

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

  string a, b, c;
  cin >> a >> b >> c;

  cout << Upper(a[0]) << Upper(b[0]) << Upper(c[0]) << endl;

  return 0;
}


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

	UnionFind(int n) : par(n), rank(n),size(n){
		rep(i, n)
		{
			par[i] = i;
      size[i] = 1;
			rank[i] = 0;
		}
	}

  int find(int x){
    if(par[x]==x){
      return x;
    }else{
      return par[x]=find(par[x]);
    }
  }

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

  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(rank[x]<rank[y]){
      par[x]=y;
    }else{
      par[y]=x;
      if(rank[x]==rank[y]) rank[x]++;
    }
		size[x] += size[y];
		size[y] = size[x];
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }
	void body()
	{
		rep(i, par.size()){
			cout << par[i] << " " << rank[i] << endl;
		}
	}
};

int main()
{
    int n, m,ma = 0;
    cin >> n >> m;
    UnionFind uni(n);
    vector<P> p(m);
    rep(i, m){
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    rep(i, m){
        uni.unite(p[i].first - 1, p[i].second - 1);
    }
    rep(i,n){
      ma = max(ma,uni.si(i));
    }
    cout << ma << endl;
}

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


void solve(string &s){
    
    int n = s.size();
    vector<int>result(n);
    
    int current_l = -1;
    int final_l = -1; 
    int start_r = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'L' && current_l == -1){
            current_l = i;
        }
        if((s[i] == 'L' && s[i+1] == 'R') || i == n-1){
            final_l = i;
        }
        
        if(current_l != -1 && final_l != -1){
            int border_idx_1 = current_l;
            int border_idx_2 = current_l - 1;
            
            //cout << start_r << " " << current_l << " " << final_l << endl;
            // Now the odd idxs will go in the border_idx that is odd and vice versa
            int total_values = final_l - start_r + 1;
            
            if((border_idx_1 - start_r)%2){
                result[border_idx_2] = (final_l - start_r + 1)/2;
                result[border_idx_1] = (final_l - start_r + 1)/2;
                if(total_values%2){
                    result[border_idx_2] += 1;
                }
            }else{
                result[border_idx_2] = (final_l - start_r + 1)/2;
                result[border_idx_1] = (final_l - start_r + 1)/2 ;
                if(total_values%2){
                    result[border_idx_1] += 1;
                }
            }
            
            start_r = final_l + 1;
            current_l = -1;
            final_l = -1;
        }
    }
    
    for(int i = 0; i < n; i++){
        cout << result[i] << " ";
    }cout << endl;
    
    
    
}





int main(){
    
    string s;
    cin >> s;
    
    solve(s);
    
    
} 


Measured memory_bytes: 3820
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

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

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here

	int a, b, w; cin >> w>>a >> b;

	if (abs(a - b) <= w) Print(0);
	else Print(abs(a - b) - w);
	return 0;

}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc006/tasks/abc006_4

class Array
  def lis
    b_ary = [self[0]]
    self[1..-1].each do |v|
      # 広義単調増加 { |x| x > v }
      # index = b_ary.bsearch_index { |x| x > v }
      # 狭義単調増加 { |x| x >= v }
      # index = b_ary.bsearch_index { |x| x >= v }
      # 広義単調減少 { |x| x < v }
      index = b_ary.bsearch_index  { |x| x < v }
      # 狭義単調減少 { |x| x <= v }
      # index = b_ary.bsearch_index { |x| x <= v }
      if index
        b_ary[index] = v
      else
        b_ary << v
      end
    end
    return b_ary.size
  end
end

n = gets.to_i
puts n.times.with_object([]) { |i,obj| obj << gets.to_i }.map { |i| i.to_i }.lis

Measured memory_bytes: 5684
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0;i < n;i++)
const long long INF = 1LL << 60;

int MOD = 1000000007;

int main(){
    std::ios_base::sync_with_stdio(false);

    int h,w; cin>>h>>w;
    char s[51][51];
    rep(i,h) rep(j,w) cin >> s[i][j];

    bool ok = true;

    rep(i,h) rep(j,w){
        if(s[i][j]=='.') continue;
        if(i-1>=0 && s[i-1][j]=='#' && s[i][j]=='#') continue;
        if(j-1>=0 && s[i][j-1]=='#' && s[i][j]=='#') continue;
        if(i+1<h && s[i+1][j]=='#' && s[i][j]=='#') continue;
        if(j+1<w && s[i][j+1]=='#' && s[i][j]=='#') continue;

        ok = false;
    }

    if(ok) cout << "Yes\n";
    else cout << "No\n";


    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

#define dbg(x) cerr << (#x) << " --> " << (x) << nl;
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

#define Toktama ""

using namespace std;

#ifdef superset
  #include <ext/pb_ds/assoc_container.hpp>
  #include <ext/pb_ds/tree_policy.hpp>
  #include <ext/pb_ds/detail/standard_policies.hpp>

  using namespace __gnu_pbds;
  typedef tree < pair <int, int>, null_type, less < pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 2e5 + 7, inf = 1e9 + 7, mod = 1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int get_int() {
  char x = getchar();
  bool mns = 0;
  while (!isdigit(x)) mns |= x == '-', x = getchar();
  int res = 0;
  while (isdigit(x)) res = res * 10 + x - '0', x = getchar();
  if (mns) res = -res;
  return res;
}
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}
int mult(int x, int y) {
  return x * 1ll * y % mod;
}
int sum(int x, int y) {
  add(x, y);
  return x;
}

int n, k;
int a[N];
void solve() {
  n = get_int(), k = get_int();
  rep(i, 1, n)
    a[i] = get_int();
  sort (a + 1, a + 1 + n, greater <int> ());
  map <int, bool> dp;
  rep(i, 1, n) {
    map <int, bool> nxt;
    for (auto it : dp)
      nxt[__gcd(it.f, a[i])] = 1;
    if (a[i] >= k) nxt[a[i]] = 1;
    dp.swap(nxt);
  }
  for (auto it : dp)
    if (k % it.f == 0) cout << "POSSIBLE", ioi
  cout << "IMPOSSIBLE";
}
int main() {
  #ifndef Toktama
    freopen (Toktama".in", "r", stdin);
    freopen (Toktama".out", "w", stdout);
  #endif
  int t = 1;
  while (t--)
    solve();
  ioi
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int N,A,B,C,X,Y[100];
    while(cin>>N>>A>>B>>C>>X){
        if(N==0 && A==0 && B==0 && C==0 && X==0) break;
        for(int i=0; i<N; i++)
            cin>>Y[i];
        int Cn=0;
        for(int i=0; i<=10000; i++){
            if(Y[Cn]==X) Cn++;
            if(Cn>=N){
                cout<<i<<endl;
                break;
            }
            X=(A*X+B)%C;
        }
        if(Cn<N) cout<<-1<<endl;
    }
}



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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int K,X;
    cin >> K >> X;
    if(K*500 < X) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <random>
#include <string>
#include <vector>
using namespace std;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m, x, y; cin >> n >> m >> x >> y;
  vector<int> x_point(n), y_point(m);
  REP(i, n) cin >> x_point[i];
  REP(i, m) cin >> y_point[i];
  sort(ALL(x_point));
  sort(ALL(y_point));
  if (max(x, x_point[n-1]) + 1 <= min(y, y_point[0])) cout << "No War" << "\n";
  else cout << "War" << "\n";
  return 0;
}


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

int main(){
    int  n;

    cin >>n;
    if(n<=111){
        cout << 111<<endl;
    }else if(n<=222){
        cout<<222<<endl;
    }else if(n<=333){
        cout<<333<<endl;
    }else if(n<=444){
        cout<<444<<endl;
    }else if(n<=555){
        cout<<555<<endl;
    }else if(n<=666){
        cout<<666<<endl;
    }else if(n<=777){
        cout<<777<<endl;
    }else if(n<=888){
        cout<<888<<endl;
    }else if(n<=999){
        cout<<999<<endl;
    }
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N= 1e6;
int n,k;
vector<string> lunlun(N);
 
 
int32_t main()
{
	IOS;
	cin>>k;
	int i=0, ptr=1;
	char check='9', check2= '0';
 
	while(i<=1e5){
		
			
		if(i + 1 <= 9){
			++i;
			lunlun[i]=to_string(i);
			
			continue;
		}
 
		if(lunlun[ptr].back()!=check && lunlun[ptr].back()!=(check2)){
 
			lunlun[++i]=  (lunlun[ptr])+ (char)(lunlun[ptr].back() - 1);
			lunlun[++i]=  (lunlun[ptr])+ (char)(lunlun[ptr].back());
			lunlun[++i]=  (lunlun[ptr])+ (char)(lunlun[ptr].back() + 1);
 
		}
		else if(lunlun[ptr].back()==(check)){
			lunlun[++i]=  (lunlun[ptr])+ (char)(lunlun[ptr].back() - 1);
			lunlun[++i]=  (lunlun[ptr])+ (char)(lunlun[ptr].back());
			
 
		}
		else if(lunlun[ptr].back()==(check2)){
			
			lunlun[++i]=  (lunlun[ptr])+ (char)(lunlun[ptr].back());
			lunlun[++i]=  (lunlun[ptr])+ (char)(lunlun[ptr].back() + 1);
		}
	
		ptr++;
	}
	cout<<lunlun[k]<<endl;
	return 0;
}

Measured memory_bytes: 13952
//2018年  3月 26日 月曜日 02:33:37 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
int A[MAX_N], B[MAX_N];

void solve() {
	cin >> N >> M;
	ll x = 0, y = 0;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, M) cin >> B[i];
	rep(i, 0, N - 1) {
		ADD(x, 1LL * (A[i + 1] - A[i]) * (i + 1) % mod * (N - 1 - i) % mod);
	}
	rep(i, 0, M - 1) {
		ADD(y, 1LL * (B[i + 1] - B[i]) * (i + 1) % mod * (M - 1 - i) % mod);
	}
	cout << x * y % mod << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1024