akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    long long int a, b, c; cin >> a >> b >> c;
    if (c - (a + b) <= 0) {
        cout << "No" << endl;
    }
    else {
        if (c* c + a * a + b * b -2 * a * c - 2 * b * c -2*a * b > 0) {
            cout << "Yes" << endl;
        } 
        else {
            cout << "No" << endl;
        }
    }
     
           

}

















Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[]
dif=0
ans=0
if sum(a)<sum(b):
    print(-1)
else:
    for i in range(n):
        x,y=a[i],b[i]
        if x<y:
            dif+=y-x
            ans+=1
        else:
            c.append(x-y)
    c.sort()
    while c and dif>0:
        ans+=1
        dif-=c.pop()
    print(ans)

Measured memory_bytes: 81584
import sys
import fractions
import functools

N = int(sys.stdin.readline().rstrip())
T = []
for _ in range(N):
    T.append(int(sys.stdin.readline().rstrip()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

if N == 1:
    print(T[0])
else:
    print(lcm_list(T))

Measured memory_bytes: 5048
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

void build(deque<int> &a, deque<int> &b, ll n) {
  stack<ll> s;
  while(n != 1) {
    if(n % 2) {
      s.push(1);
      n--;
    } else {
      s.push(0);
      n /= 2;
    }
  }
  int c = 1;
  while(!s.empty()) {
    int x = s.top();
    s.pop();
    if(x) {
      a.push_back(c);
      b.push_front(c);
    } else {
      a.push_back(c);
      b.push_back(c);
    }
    c++;
  }
}

int main() {
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  deque<int> a, b;
  build(a, b, N+1);
  cout << a.size() + b.size() << endl;
  FOR(x,a) {
    cout << x << " ";
  }
  FOR(x,b) {
    cout << x << " ";
  }
  cout << endl;
  return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[],int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}
int main(){

int p[1001]={};
int k=0;
int n=0;
int ans=0;
scanf("%d %d",&n,&k);

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

scanf("%d",&p[i]);

}
quick_sort(p,0,n-1);
for(int i=0;i<k;i++){

ans=ans+p[i];

}


    printf("%d\n",ans);



return 0;

}


Measured memory_bytes: 1732
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>
#define mp make_pair
#define pb push_back

using namespace std;

const int MAX = 100;

int pr[MAX];
bool used[MAX];
vector<int> e[MAX];

bool dfs(int v)
{
    used[v] = true;
    for (auto u : e[v])
    {
        if (pr[u] == -1 || !used[pr[u]] && dfs(pr[u]))
        {
            pr[u] = v;
            return true;
        }
    }
    return false;
}

int main() 
{
	int n;
	scanf("%d", &n);
	vector<pair<int, int>> r, b;
	for (int i = 0; i<n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		r.pb(mp(x,y));
	}
	for (int i = 0; i<n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		b.pb(mp(x,y));
	}
	for (int i = 0; i<MAX; ++i) {
		pr[i] = -1;
		used[i] = 0;		
	}
	for (int i = 0; i<n; ++i) {
		for (int j = 0; j<n; ++j) {
			if (r[i].first < b[j].first && r[i].second < b[j].second) {
				e[i].pb(j);
			}
		}
	}
	for (int i = 0; i<n; ++i) {
		for (int j = 0; j<n; ++j) {
			used[j] = 0;
		}
		dfs(i);
	}
	int sum = 0;
	for (int i = 0; i<n; ++i) {
		if (pr[i] >= 0)
			++sum;
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#define PB push_back
#define in scanf
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using	namespace std;
void solve(){
	int e;
	while(cin >> e ,e!=0) {
	int m =1000000000;
	int x;
	for(int z=0;z*z*z<=e;z++){
		for(int y=0;y*y+z*z*z<=e;y++){
			x = e-y*y-z*z*z;
			m = min(x + y + z,m);
			
				
		}
	}
	cout << m  << endl;
	
}
}



	
int main(){
	solve();

}

Measured memory_bytes: 1160
#include<cstdio>  
#include<cmath>  
using namespace std;
long long n,ans;
int s;
int main(){
    scanf("%lld",&n);  
    for(int i=sqrt(n);i>0;--i)   
        if(n%i==0){
            ans=n/i;
            break;
        }
    while(ans>0){  
        ++s;
        ans/=10;
    }
    printf("%d\n",s);
    return 0;
}

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

int main()
{
    int n, y, m, a, b, c;
    cin >> n >> y;
    if(y > 10000 *n || y < 1000 * n){
        cout << "-1 -1 -1" << endl;
        return 0;
    }
    m = y/1000-n;
    for(int a = 0; a <= m/9; a++){      // solve a+b+c = n && 9a+4b = m
        if((m-9*a)%4 != 0)
            continue;
        b = (m-9*a)/4;
        if(a+b > n)
            continue;
        c = n - a - b;
        cout << a << " " << b << " " << c << endl;
        return 0;
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define testing 1
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = 2e5+5;
#if !testing
#define cerr if(0)cout
#endif
int A[MAXN], B[MAXN], C[MAXN];
ll ans;
int n;
int32_t main() 
{
	IAMSPEED
	cin >> n;
	FOR(i,1,n)cin>>C[i];
	FOR(i,1,n) {
		A[i] = C[i] - (i-1);
		B[i] = C[i] + (i-1);
	}
	map<int,int>mp1,mp2;
	FOR(i,1,n) {
		mp1[A[i]]++;
		mp2[B[i]]++;
	}
	FOR(i,1,n) {
		ans += mp2[-A[i]];
	}
	cout<<ans;
	
}



Measured memory_bytes: 31640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD = 1000000007;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


int main() {
	int n;
	ll ans = 1;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		ans *= i;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

template<class I>
inline I max(I a, I b) {
	return a > b ? a : b;
}

int n, len[110], ans;

int main(void) {
	scanf("%d", & n);
	for (register int i = 1; i <= n; ++i)
		scanf("%d", len + i);
	for (register int i = 1; i <= n - 2; ++i)
		for (register int j = i + 1; j <= n - 1; ++j)
			for (register int l = j + 1; l <= n; ++l)
				if (len[i] + len[j] + len[l] - max(len[i], max(len[j], len[l])) > max(len[i], max(len[j], len[l])) && !(len[i] == len[j] || len[i] == len[l] || len[j] == len[l]))
					++ans;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1724
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

int main() {
  size_t n, k;
  scanf("%zu %zu", &n, &k);

  std::vector<intmax_t> a(n);
  for (auto& ai: a) scanf("%jd", &ai);

  std::vector<intmax_t> cand;
  cand.reserve(n*(n+1)/2);

  for (size_t i = 0; i < n; ++i) {
    intmax_t acc = a[i];
    cand.push_back(acc);
    for (size_t j = i+1; j < n; ++j) {
      acc += a[j];
      cand.push_back(acc);
    }
  }

  intmax_t res = 0;
  for (int j = 62; j >= 0; --j) {

    std::vector<intmax_t> set, unset;
    for (auto ai: cand) {
      ((ai >> j & 1)? set: unset).push_back(ai & (~(1_ju << j)));
    }
    if (set.size() >= k) {
      res |= 1_jd << j;
    } else {
      set.insert(set.end(), unset.begin(), unset.end());
    }

    std::sort(set.begin(), set.end());
    cand = std::move(set);
  }

  printf("%jd\n", res);
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<pair<int, int>> a(26);
    for(int i=0; i<26; i++) a[i] = make_pair(0, i);
    for(int i=0; i<n; i++){
        if(i%2 == 0){
            a[s[i]-'a'].first++;
        }
    }
    sort(a.begin(), a.end(), greater<pair<int, int>>());

    int ans = 0;
    int tmp = 0, now = a[0].first;
    for(int i=0; i<=26; i++){
        if(i < 26 && now == a[i].first){
            tmp++;
        }else{
            if(now > 0) ans += 2*tmp;
            if(now > 1) ans += 2;
            if(now > 1 && tmp > 1) ans += 2;
            tmp = 1;
            if(i < 26) now = a[i].first;
        }
    }
    cout << ans-1 << endl;
}



Measured memory_bytes: 3224
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int M;
int P;
char S[4];
int res1;
int res2;
int ok[100000];
int ng[100000];
int main(){
  int Lj4PdHRW, i;
  rd(N);
  rd(M);
  for(Lj4PdHRW=(0);Lj4PdHRW<(M);Lj4PdHRW++){
    rd(P);P += (-1);
    rd(S);
    if(ok[P]){
      continue;
    }
    if(S[0]=='A'){
      ok[P]++;
    }
    else{
      ng[P]++;
    }
  }
  for(i=(0);i<(N);i++){
    if(ok[i]){
      res1++;
      res2 += ng[i];
    }
  }
  wt_L(res1);
  wt_L(' ');
  wt_L(res2);
  wt_L('\n');
  return 0;
}
// C

Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#include <iterator>
#include <chrono>
#include <stack>
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
#define PI 3.1415926535

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

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

	i64 ans = 0;

	int a = 0;
	for (int i = 0; i < s.size() - 1; i++)
	{
		if (s[i] == 'A')
		{
			a++;
		}
		else if (s.substr(i, 2) == "BC")
		{
			ans += a;
			i++;
		}
		else
		{
			a = 0;
		}
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNext()){
            int n = in.nextInt();
            int k = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }
            Arrays.sort(h);
            int min = h[n - 1] - h[0];
            if(min == 0){
                System.out.println(0);
            }else{
                for (int i = 0; i <= n - k; i++) {
                    int sub = h[i + k - 1] - h[i];
                    if(sub < min){
                        min = sub;
                    }
                }
            }
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 50224
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a;
    string s;
    cin >> a >> s;

    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define llint long long

using namespace std;

llint n, m, mod;
llint dp[5005][5005];
llint dpsum[5005][5005];
llint dp2[5005][5005];
llint num[5005][5005];

int main(void)
{
	cin >> n >> mod;
	if(n == 2){
		cout << 3 << endl;
		return 0;
	}
	m = (n+1)/2-1;
	
	dp[0][0] = 1;
	for(int i = 0; i <= n; i++){
		for(int j = 1; j <= n; j++){
			dp[i][j] = dp[i][j-1];
			if(i-j >= 0) dp[i][j] += dp[i-j][j], dp[i][j] %= mod;
		}
	}
	for(int j = 0; j <= n; j++){
		llint sum = 0;
		for(int i = 0; i <= n; i++){
			sum += dp[i][j];
			if(sum >= mod) sum -= mod;
			dpsum[i][j] = sum;
		}
	}
	
	for(int i = 0; i <= n; i++) dp2[0][i] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			llint ret = dp[i][j];
			if(i-m >= 0 && j-1 >= 0) ret += mod - dp2[i-m][j-1];
			if(i-2*m >= 0 && j-2 >= 0) ret += mod - dp2[i-2*m][j-2];
			if(i-3*m >= 0 && j-3 >= 0) ret += mod - dp2[i-3*m][j-3];
			if(i-(m+1) >= 0 && j-1 >= 0) ret += mod - dp[i-(m+1)][j-1];
			if(i-(m+2) >= 0 && j-1 >= 0) ret += mod - dpsum[i-(m+2)][j-1];
			dp2[i][j] = ret % mod;
		}
	}
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			if(i+j > n) break;
			llint tmp = 0;
			for(int k = 0; k <= 3; k++){
				if(i-k*m < 0 || j-k < 0) break;
				if(n % 2 == 0) tmp += dp2[i-k*m][j-k] * (k+1);
				else tmp += dp2[i-k*m][j-k];
			}
			num[i][j] = tmp % mod;
		}
	}
	for(int j = 0; j <= n; j++){
		llint sum = 0;
		for(int i = 0; i <= n; i++){
			if(i+j > n) break;
			sum += num[i][j];
			if(sum >= mod) sum -= mod;
			num[i][j] = sum;
		}
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= i; j++){
			ans += dp[i-j][m] * num[j-1][n-i] % mod;
		}
	}
	cout << ans % mod << endl;
	
	return 0;
}

Measured memory_bytes: 719872
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010



int main(){
  int N,W;
  int w[110], v[110];
  int w0;
  scanf("%d%d",&N,&W);

  for(int i=0;i<N;i++){
    scanf("%d%d",w+i, v+i);
  }

  w0 = w[0];
  for(int i=0;i<N;i++){
    w[i] -= w0;
  }

  int dp[110][310] = {};

  for(int i=0;i<N;i++){
    for(int j=i;j>=0;j--){
      for(int k=0;k<=i*3;k++){
        dp[j+1][k+w[i]] = max(dp[j+1][k+w[i]],dp[j][k] + v[i]);
      }
    }
  }
    
  int ans = 0;

  for(int i=0;i<=N;i++){
    for(int j=0;j<=3*i;j++){
      if(j + (ll)w0*i <= W)
        ans = max(ans, dp[i][j]);
    }
  }
  
  printf("%d\n",ans);
  
  return 0;
}


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

int main(){

    string a,b;

    cin >> a >> b;
    bool f=true;
    rep(i,3){
        if(a[i]!=b[2-i]){
            f=false;
        }
    }
    if(f){
        cout << "YES" <<endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N, K; cin >> N >> K;
    string s; cin >> s;

    int op = 0, val = 1;
    while(val < N) op++, val *= 2;
    op = min(op, K);

    while(op--) {
        string t = s;
        reverse(t.begin(), t.end());
        string v = s + t;

        string min_s = string(1, 'z'+ 1);
        for(int i=0; i<N; i++) {
            chmin(min_s, v.substr(i, N));
        }

        reverse(min_s.begin(), min_s.end());
        s = min_s;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int c = 0;
    vector <int> v;
    int total = 0;
    for(int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        v.push_back(temp);
    }
    for(int i = 0; i < n; i++)
    {
        total += v[i];
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    if(v[m-1] >= total/(4.0*m))
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << '\n'

typedef int64_t Int;
const double pi = M_PI;

using namespace std;

int main() {
    int W, a, b;
    cin >> W >> a >> b;

    if (a <= b && b <= a + W || b <= a && a <= b + W) {
        cout << 0 << endl;
    } else if (a + W < b) {
        cout << b - (a + W) << endl;
    } else if (b + W < a) {
        cout << a - (b + W) << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int hight[10];
	int i;
	int j;
	
	for (i = 0; i < 10; i++){
		scanf("%d", &hight[i]);
	}
	
	for (i = 0; i < 10; i++){
		for (j = i + 1; j < 10; j++){
			if (hight[i] < hight[j]){
				int temp;
				temp = hight[i];
				hight[i] = hight[j];
				hight[j] = temp;
			}
		}
	}
	
	printf("%d\n%d\n%d\n", hight[0], hight[1], hight[2]);
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
struct O
{
	int l,r,x;
}b[200005];
int x,y,t,n,m,e[100005],a[100005]; 
char S[100005];
void add(int &u,int v)
{
	if (!v) return;
	if (!u) {u=v; return;}
	if (b[u].x<b[v].x)
	{
		add(b[u].r,v);
		swap(b[u].l,b[u].r);
	}
	else
	{
		add(b[v].r,u);
		swap(b[v].l,b[v].r);
		u=v;
	}
}
int main()
{
	scanf("%s",S+1); n=strlen(S+1);
	for (int i=1;i<=n;++i) a[i]+=S[i]-'a',a[i+1]-=S[i]-'a';
	scanf("%d",&m);
	for (int i=1;i<=m;++i)
	{
		scanf("%d%d",&x,&y);
		b[++t].x=y;
		add(e[x],t);
	}
	for (int i=1;i<=n+1>>1;++i)
	{
		b[++t].x=n-i+1;
		add(e[i],t);
	}
	for (int i=1;i<=n;++i)
	{
		a[i]%=26;
		while (e[i]&&b[e[i]].x<i) add(b[e[i]].l,b[e[i]].r),e[i]=b[e[i]].l;
		if (!e[i]){
			if (a[i]) {puts("NO"); return 0;}
			continue;
		}
		t=b[e[i]].x;
		a[t+1]+=a[i]; a[i]=0;
		add(e[t+1],b[e[i]].l);
		add(e[t+1],b[e[i]].r);
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

vector<vector<int>> graph(1010, vector<int>());
vector<int> deg(1010);
vector<int> x(1010);
bool ans = true;

P dfs(int n) {
	int d = deg[n];
	vector<vector<bool>> dp(d + 1, vector<bool>(5010));
	vector<P> ch;
	for (int i : graph[n]) {
		ch.pb(dfs(i));
	}
	int sum = 0;
	dp[0][0] = true;
	rep(i, d) {
		int ch1 = ch[i].first;
		int ch2 = ch[i].second;
		sum += ch1 + ch2;
		rep(j, 5010) {
			if (j >= ch1 && dp[i][j - ch1]) dp[i + 1][j] = true;
			if (j >= ch2 && dp[i][j - ch2]) dp[i + 1][j] = true;
		}
	}
	int check = -1;
	for (int i = 0; i <= x[n]; i++) {
		if (dp[d][i]) check = i;
	}
	if (check == -1) {
		ans = false;
	}
	else {
		return P(sum - check, x[n]);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 1; i < n; i++) {
		cin >> p[i];
		p[i]--;
		graph[p[i]].pb(i);
		deg[p[i]]++;
	}
	rep(i, n) cin >> x[i];
	P tmp = dfs(0);
	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

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

int main(){
  string word, checker = "ACTG";
  cin >> word;
  int A = 0;
  for (int i = 0; i < (int)word.length(); i++){
    int j;
    for (j = i; j < (int)word.length() && checker.find(word[j]) != string::npos; j++);
    A = max(A, j - i);
  }
  cout << A << '\n';
  return 0;
}

Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
#include<queue>
using namespace std;
const int MAXN=(int)1e5;
const int INF=(int)1e9;
int n_pnt,n_edg,cnt;
map<int,int> ID[MAXN+5];
int input[2*MAXN+5][3];
vector<pair<int,int> > lnk[5*MAXN+5];
int dist[5*MAXN+5];
bool vis[5*MAXN+5];
int main()
{
	scanf("%d%d",&n_pnt,&n_edg);
	cnt=n_pnt+1;
	for(int i=0;i<n_edg;i++)
	{
		int u,v,c;scanf("%d%d%d",&u,&v,&c);
		input[i][0]=u;input[i][1]=v;input[i][2]=c;
		if(!ID[u].count(c)) ID[u][c]=cnt++;
		if(!ID[v].count(c)) ID[v][c]=cnt++;
		lnk[ID[u][c]].push_back(make_pair(ID[v][c],0));
		lnk[ID[v][c]].push_back(make_pair(ID[u][c],0));
	}
	for(int i=1;i<=n_pnt;i++)
		for(map<int,int>::iterator it=ID[i].begin();it!=ID[i].end();it++)
		{
			int id=it->second;
			lnk[i].push_back(make_pair(id,1));
			lnk[id].push_back(make_pair(i,1));
		}
	fill(dist,dist+5*MAXN+5,INF);
	dist[1]=0;vis[1]=true;
	queue<int> que;que.push(1);
	while(!que.empty())
	{
		int u=que.front();que.pop();
		for(int i=0;i<lnk[u].size();i++)
		{
			int v=lnk[u][i].first,l=lnk[u][i].second;
			if(dist[v]>dist[u]+l)
			{
				dist[v]=dist[u]+l;
				if(!vis[v])
					vis[v]=true,que.push(v);
			}
		}
		vis[u]=false;
	}
	if(dist[n_pnt]==INF) printf("%d\n",-1);
	else printf("%d\n",dist[n_pnt]/2);
	return 0;
}


Measured memory_bytes: 58752
#include <bits/stdc++.h>
using namespace std;
const int IINF = -1e+8;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> p(m);
    vector<string> s(m);
    for(int i=0;i<m;i++){
        cin >> p[i] >> s[i];
    }
    vector<int> vl(n, 0);
    int ac = 0, wa = 0;
    for(int i=0;i<m;i++){
        if(s[i] == "AC"){
            if(vl[p[i]] >= 0)
                ac ++;
            wa += max(0, vl[p[i]]);
            vl[p[i]] = IINF;
        }else{
            vl[p[i]] ++;
        }
    }
    cout << ac << " " << wa << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

vector<int> to[200005];
ll ans[200005];
ll a[200005];
vector<ll> vec(200005);

pair<int, ll> dfs(int x, int i, int p = -1) {
    pair<int, ll> res;
    if (a[x]>vec[i])  {
        res.first = i+1;
        res.second = vec[i+1];
        vec[i+1] = a[x];
        i++;
    }
    else {
        auto it = lower_bound(vec.begin(), vec.begin()+i+1, a[x]); 
        int y = it - vec.begin();
        res.first = y;
        res.second = vec[y];
        vec[y] = a[x];
        
    }
    ans[x] = i+1;
    for (int e: to[x]) {
        if (e==p) continue;
        pair<int, ll> temp = dfs(e, i, x);
        //vec[temp.first] = temp.second;
    }
    vec[res.first] = res.second;
    return res;
}

int main(){
    int n;
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n-1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        to[u].emplace_back(v);
        to[v].emplace_back(u);
    }
    
    vec[0] = 1E+18;
    pair<int, ll> p = dfs(0, 0);

    
    
    
    
    rep(i, n) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 33260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int vx[4] = {1, 0, -1, 0};
int vy[4] = {0, 1, 0, -1};

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i, 0, H) cin >> S[i];
  vector<vector<int>> visited(H, vector<int>(W));
  queue<P> Q;
  ll ans = 0;
  rep(i, 0, H) rep(j, 0, W) {
    if (!visited[i][j]) {
      ll h = 0, b = 0;
      visited[i][j] = 1;
      Q.push({i, j});
      while (!Q.empty()) {
        P cur = Q.front(); Q.pop();
        int y = cur.first;
        int x = cur.second;
        if (S[y][x] == '.') h++;
        else b++;
        rep(k, 0, 4) {
          int nx = x + vx[k];
          int ny = y + vy[k];
          if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
          if (S[y][x] == S[ny][nx] || visited[ny][nx]) continue;
          visited[ny][nx] = 1;
          Q.push({ny, nx});
        }
      }
      ans += h * b;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main ()
{   int x , y;

	while(1)
	{
		cin >> x >> y;
		if(x == 0 && y == 0) break;
	
		if (x < y)
		{
			cout << x << " " << y <<endl;
		}
		else 
		{
			cout << y << " "<< x <<endl;
		}

	}
	return 0;
}


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

int main()
{
    int S, h, m, s;
    cin >> S;
    h = S / 3600;
    S = S % 3600;
    m = S / 60;
    s = S % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}



Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
    int side1,side2,diagonal,box1=0,box2=0,pow1,pow2,pow3;
    while(scanf("%d,%d,%d",&side1,&side2,&diagonal)!=EOF)
    {
        pow1=side1*side1;
        pow2=side2*side2;
        pow3=diagonal*diagonal;
        if(pow3==pow1+pow2)
            box1++;
        if(side1==side2)
            box2++;
    }
    printf("%d\n%d\n",box1,box2);
    return 0;
}

Measured memory_bytes: 596
# 入力
M, K = map(int, input().split())

# K 0 1 2 ... (2**M - 1) K (2**M - 1) ... 2 1 0 が解
ans = (
    '-1' if K >= 2**M or M == K == 1 else
    '0 0' if M == 0 else
    '0 0 1 1' if M == 1 else
    '{} {} {} {}'.format(
        K,
        ' '.join(
            str(i)
            for i in range(2**M)
            if i != K
        ),
        K,
        ' '.join(
            str(i)
            for i in range(2**M - 1, -1, -1)
            if i != K
        ),
    )
)

# 出力
print(ans)


Measured memory_bytes: 12912
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 10, INF = 1e9 * 1e9 + 10;

string s;

void find(int n, int st, int gr = 0) {
    if (n == 0) {
        cout << s << "\n";
        return;
    } else {
        for (int i = 1; i <= st; i++) {
            if (i > gr + 1) {
                continue;
            }
            
            s.push_back('a' + i - 1);
            find(n - 1, st, max(gr, i));
            s.pop_back();
        }
    }
}

int main()
{
    fastInp;

    ll n;
    cin >> n;

    find(n, n + 4);
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int n,a,ans=0;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
	{
        cin>>a;
        ans+=a;
    }
    if(ans%2==0)cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int N=2005;
char tmp[N];
int a[N][N],sh[N][N],ss[N][N],s[N][N];
int get(int a[N][N],int x1,int y1,int x2,int y2){
    int sum=a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1];
    return sum;
}
int main(){
    int n,m,q,i,j,x1,y1,x2,y2;
    scanf("%d %d %d",&n,&m,&q);
    for(i=1;i<=n;i++){
        scanf("%s",tmp+1);
        for(j=1;j<=m;j++) a[i][j]=tmp[j]-'0';
    }
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++){
            sh[i][j]=sh[i][j-1]+sh[i-1][j]-sh[i-1][j-1];
            if(i<n&&a[i][j]&&a[i+1][j]) sh[i][j]++;
        }
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++){
            ss[i][j]=ss[i][j-1]+ss[i-1][j]-ss[i-1][j-1];
            if(j<m&&a[i][j]&&a[i][j+1]) ss[i][j]++;
        }
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
    for(i=1;i<=q;i++){
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        //printf("sum=%d %d %d\n",get(s,x1,y1,x2,y2),get(ss,x1,y1,x2,y2-1),get(sh,x1,y1,x2-1,y2));
        printf("%d\n",get(s,x1,y1,x2,y2)-get(ss,x1,y1,x2,y2-1)-get(sh,x1,y1,x2-1,y2));
    }
    return 0;
}


Measured memory_bytes: 64640
#include<iostream>
using namespace std;
int main()
{

bool t=true;
int n,k;
int s[11];
cin>>n>>k;
for(int i=0;i<k;i++)
    cin>>s[i];

for(int i=n;i<100000;i++)     
    {for(int j=0;j<k;j++)
         {if(i>=0 and i%10==s[j]) {t=false;
                                          break;}
          if(i>=10 and i/10%10==s[j]) {t=false;
                                          break;}
          if(i>=100 and i/100%10==s[j]) {t=false;
                                          break;}
          if(i>=1000 and i/1000%10==s[j]) {t=false;
                                          break;}
          if(i>=10000 and i/10000%10==s[j]) {t=false;
                                          break;}
         }
     if(t==true) {cout<<i;
                  system("pause");
                  return 0;}
     t=true;}
      
system("pause");
return 0;
}

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

int main(){
  int n,ans=0;
  cin >> n;
  int judge[n][n];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) judge[i][j] = -1;
  }
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    for(int j=0;j<a;j++){
      int b,c;
      cin >> b >> c;
      judge[i][b-1]=c;
    }
  }
  for(int i=0;i<(1<<n);i++){
    int honlist[n]={};
    bool flag = 1;
    for(int j=0;j<n;j++){
  		if(i>>j&1) honlist[j]=1;
    }
    for(int k=0;k<n;k++){
      if(honlist[k]){
        for(int l=0;l<n;l++){
          if(judge[k][l] == -1) continue;
          if(judge[k][l] != honlist[l]) flag = 0;
        }
      }
    }
    if(flag) ans = max(ans,__builtin_popcount(i));
  }
  cout << ans << endl;
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ret = 0;
    for(int i = 0; i+2 < n; i++){
        if(s.substr(i,3)=="ABC")    ret++;
    }
    cout << ret << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){ 
    cin >> A[i];
  }
  int sum = 0;
  sum += abs(A[0]);
  for(int i = 0; i < N - 1; i++){
    sum += abs(A[i] - A[i + 1]);
  }
  sum += abs(A[N - 1]);
  int sum1 = sum;
  sum1 -= abs(A[0]);
  sum1 -= abs(A[1] - A[0]);
  sum1 += abs(A[1]);
  cout << sum1 << endl;
 
  for(int i = 1; i < N - 1; i++){
    sum1 = sum;
    sum1 -= abs(A[i] - A[i + 1]);
    sum1 -= abs(A[i] - A[i - 1]);
    sum1 += abs(A[i - 1] - A[i + 1]);
    cout << sum1 << endl;
  }
  sum1 = sum;
  sum1 -= abs(A[N - 1]);
  sum1 -= abs(A[N - 1] - A[N - 2]);
  sum1 += abs(A[N - 2]);

  cout << sum1 << endl;
  return 0;
}

Measured memory_bytes: 1664
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line = br.readLine();
        char[] arr = line.toCharArray();

        // 以下でもACだが、元文字列にpea-chが含まれている場合は正しく機能しない
        /*
        line = line.replaceAll("apple", "pea-ch");
        line = line.replaceAll("peach", "apple");
        line = line.replaceAll("pea-ch", "peach");
        */

        for (int i = 0; i < arr.length - 4; i++) {
            if (line.substring(i, i + 5).equals("apple")) {
                arr[i] = 'p';
                arr[i+1] = 'e';
                arr[i+2] = 'a';
                arr[i+3] = 'c';
                arr[i+4] = 'h';
                i += 4;
            }else if(line.substring(i, i + 5).equals("peach")) {
                arr[i] = 'a';
                arr[i+1] = 'p';
                arr[i+2] = 'p';
                arr[i+3] = 'l';
                arr[i+4] = 'e';
                i += 4;
            }
        }
        System.out.println(arr);
    }
}


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

int main(){
 long long a,b,c,d;
cin>>a>>b;
  c=0;
  for(int i=1;i<=a;i++){
    for(int j=10;j<=b;j++){
      if(i==(j/10)*(j%10)&&j/10>=2&&j%10>=2){
        c++;
      }
    }
  }
    cout<<c<<endl;
}



Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
  int N;
  cin >>N;
int x=0;
  if(N<105){ 
    cout<<x;
  }

  else if(N<135){ 
    cout<<1;
  }
  else if(N<165){
    cout<<2;
  }
  else if(N<189){
    cout<<3;
  }
  else if(N<195){
    cout<<4;
  }
  else{
    cout <<5;
  }
  return 0;
}


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

int main() {
  long long l = 1000000000+7;
  int n,m;
  cin >> n >> m;
  vector<bool>data(n,false);
  long long dp[n+1];
  for(int i = 0;i <= n;i++) dp[i] = l;
  dp[0] = 1;
  dp[1] = 1;
  for(int i = 0;i < m;i++){
    int a;
    cin >> a;
    data[a] = true;
  }
  if(data[0]) dp[0] = 0;
  if(data[1]) dp[1] = 0;
  for(int i = 2;i <= n;i++){
    dp[i] = dp[i-1]+dp[i-2];
    dp[i] %= l;
    if(data[i]) dp[i] = 0;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 1024
H,W = map(int,input().split())

A = []
for i in range(H):
    a = input()
    if "#" in a: A.append(a)
        
A = list(zip(*A))

B = []
for a in A:
    if "#" in a: B.append(a)
        
B = list(zip(*B))

for b in B:
    print("".join(b))

Measured memory_bytes: 3188
h, w = map(int, input().split())
S = [list(str(input())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if S[i][j] == '#':
            flag = False
            for di, dj in (-1, 0), (1, 0), (0, 1), (0, -1):
                ni, nj = i+di, j+dj
                if 0 <= ni < h and 0 <= nj < w:
                    if S[ni][nj] == '#':
                        flag = True
                        break
            if not flag:
                print('No')
                exit()
else:
    print('Yes')


Measured memory_bytes: 66584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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;
    map<int, int> M;
    for(int i = 0; i < n; ++i) {
        int a; cin >> a; M[a]++;
    }
    int ans = 1;
    for(int i = n - 1; i >= 0; i -= 2) ans = (ans * M[i]) % MOD;
    for(int i = n - 1; i >= 2; i -= 2) ans = (ans * (M[i] - 1)) % MOD;
    COUT(ans);
}

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

int N, W;
int w[110], v[110];

long long dp[110][100010];

int main() {
    cin >> N >> W;
    for(int i = 0; i < N; i++)
        cin >> w[i] >> v[i];

    for(int j = 0; j <= W; j++)
        dp[0][j] = 0;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= W; j++) {
            if(j >= w[i])
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;

int main(){
  using P = complex<double>;
  const double pi = acos(-1);
  int X;
  cin >> X;
  P dir(1,0);
  P r = polar(1.0,X*pi/180);
  P p(1,0);
  int ans = 1;
  while(abs(p) > 1e-9){
    dir *= r;
    p += dir;
    ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3972
q, h, s, d = map(int, input().split())
n = int(input())
m = min(4 * q, 2 * h, s)
if d / 2 < m:  # d を優先的に使う
    print((n // 2) * d + (n % 2) * m)
else:
    print(n * m)


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

#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 2e5+5;
const int MOD= 998244353;
int n,b[MAXN];
struct node{
    int x,y;
}a[MAXN];
bool cmp(node a,node b){
    return a.x<b.x;
}
ll dp[MAXN];
int st[MAXN];
int main()
{
    scanf("%d",&n);
    rep(i,1,n){
        scanf("%d%d",&a[i].x,&a[i].y);
        a[i].y+=a[i].x-1;
    }
    sort(a+1,a+n+1,cmp);
    rep(i,1,n)b[i]=a[i].x;
    dp[n+1]=1;
    int p=0;
    per(i,n,1){
        int y=a[i].y;
        while(p&&y>=a[st[p]].x){
            y=max(y,a[st[p]].y);
            p--;
        }
        a[i].y=y;
        if(!p)dp[i]=(dp[i+1]+dp[n+1])%MOD;
        else dp[i]=(dp[i+1]+dp[st[p]])%MOD;
        st[++p]=i;

    }
    printf("%lld\n",dp[1]);
}


Measured memory_bytes: 4480
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

public class Program{
    public static void Main(){
        var N = int.Parse(ReadLine());
        for(int i=0;i<N;i++){
            var line = ReadLine().Split(' ').Select(x=>ulong.Parse(x)).ToArray();
            WriteLine(Judge(line));
        }
    }
    static string Judge(ulong[] array){
        var A = array[0];
        var B = array[1];
        var C = array[2];
        var D = array[3];
        if(B>A||B>D) return "No";
        if(B <= C) return "Yes";
        var g = GetGcd(B,D);
        if(B-g+(A%g) > C) return "No";
        else return "Yes";
    }
    public static ulong GetGcd(ulong a, ulong b)
    {
        return b != 0 ? GetGcd(b, a % b) : a;
    }

}
//var N = long.Parse(ReadLine());


Measured memory_bytes: 13396
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int dfs(int from, const vector<vector<int>> &graph, vector<bool> &visited, vector<int>& max_depth) {
    if (max_depth[from] != -inf) return max_depth[from];
    int depth = 0;
    visited[from] = true;
    for (int to : graph[from]) {
        if (visited[to]) {
            visited[from] = false;
            return max_depth[from] = -1;
        } else {
            int d = dfs(to, graph, visited, max_depth);
            if (d == -1) {
                visited[from] = false;
                return max_depth[from] = -1;
            }
            depth = max(d + 1, depth);
        }
    }
    visited[from] = false;
    return max_depth[from] = depth;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> graph(n * n);
    for (int i = 0; i < n; ++i) {
        int prev_game = graph.size() - 1;
        for (int j = 0; j < n - 1; ++j) {
            int opp;
            cin >> opp;
            --opp;
            int next = opp > i ? i * n + opp : opp * n + i;
            graph[prev_game].push_back(next);
            prev_game = next;
        }
    }
    vector<bool> visited(graph.size());
    vector<int> max_depth(graph.size(), -inf);
    int depth = dfs(graph.size() - 1, graph, visited, max_depth);
    if (depth != -1)
        cout << depth << endl;
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 43520
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true){
			int H = stdIn.nextInt();
			int W = stdIn.nextInt();
			if(H == 0 && W == 0)
				break;
			for (int i=0; i<H; i++) {
				for (int j=0; j<W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26836
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){ T x; cin >> x; return (x); }
template<typename T=int,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return move(x); }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){ return graph.size(); }
};

class WarshallFloyd{
	vector<vector<ll>> dist;
public:
	void CalcShortestPath(ConnectNodeInfo& connect){
		int V = connect.size();
		dist.resize(V,vector<ll>(V,1LL<<60));

		REP(i,V){
			dist[i][i]=0;
			int U = connect[i].size();
			REP(j,U){
				dist[i][connect[i][j].first] = connect[i][j].second;
			}
		}

		REP(k,V){
			REP(i,V){
				REP(j,V){
					if(dist[i][k]!=(1LL<<60) && dist[k][j]!=(1LL<<60)){
						dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
					}
				}
			}
		}
	}
	bool HasNegativeLoop(){
		bool flag = false;
		for(int i=0,ei=dist.size();i<ei;i++){
			if(dist[i][i]<0){
				flag = true;
				break;
			}
		}
		return flag;
	}
	ll CalcDiameter(){
		ll diameter = -(1LL<<60);
		int V = dist.size();
		REP(i,V){
			REP(j,V){
				if(dist[i][j]<1LL<<60){
					diameter = max(diameter,dist[i][j]);
				}
			}
		}
		return diameter;
	}
	ll GetDistance(int i,int j){
		return dist[i][j];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in(),M=in(),R=in();
	vector<int> T=vecin(R);
	sort(ALL(T));
	ConnectNodeInfo connect(N);
	REP(i,M){
		int u=in()-1,v=in()-1,c=in();
		connect.AddNonDirectionalConnection(u,v,c);
	}
	WarshallFloyd WF;
	WF.CalcShortestPath(connect);
	ll minD=1LL<<60;
	do{
		ll D=0;
		REP(i,R-1){
			D += WF.GetDistance(T[i]-1,T[i+1]-1);
		}
		minD = min(minD,D);
	}while(next_permutation(ALL(T)));
	
	out(minD);
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,t7=0;
    scanf("%d%d%d",&a,&b,&c);
    if(a==7) t7++;
    if(b==7) t7++;
    if(c==7) t7++;
    if(t7==1) printf("YES");
    else printf("NO");
}

Measured memory_bytes: 256