akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

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

    int y, m, d;

    y = (s.at(0)-'0')*1000+(s.at(1)-'0')*100+(s.at(2)-'0')*10+(s.at(3)-'0');
    m = (s.at(5)-'0')*10 + (s.at(6)-'0');
    d = (s.at(8)-'0')*10 + (s.at(9)-'0');

    if(y>=2020||(y==2019&&m>=5)) cout << "TBD" << endl;
    else cout << "Heisei" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;

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


int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,k;
    cin>>n>>k;
    vector<int> vi(n);
    for(int i=0; i<n; i++){
        cin>>vi[i];
    }
    
    
    int step=vi[0];
    for(int i=1; i<n; i++){
        step=gcd(step,vi[i]);
    }
    for(int i:vi){
        if(i>=k && !((i-k)%step)){
            cout<<"POSSIBLE";
            return 0;
        }
    }
    cout<<"IMPOSSIBLE";
    
    
    
    
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N=100000;
int a,b,c,n,i,j,m;
string s[N];
int main()
{
	cin >> n>>m;
	for(i=1;i<=n;i++)
	cin >>s[i];
	sort(s+1,s+n+1);
	for(i=1;i<=n;i++)
	{
		cout << s[i];
	}
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int cnt[MAXN];
int mod(ll x){
	return (x%INF);
}
int C(int x){
	return mod((x*1LL*(x-1)));
}
int main(){
	//~ #ifndef ONLINE_JUDGE
    //~ freopen("file.in", "r", stdin);
	//~ #endif	
	int n,ans=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	for(int i=1+(n&1);i<n;i+=2)
		ans=mod(ans*1LL*C(cnt[i]));
	printf("%d\n",ans);	
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d", &a, &b, &c);
	if (b-a==c-b)
	{
		printf ("YES\n");
	}
	else 
	{
		printf("NO\n");
	}
	system("pause");
}


Measured memory_bytes: 504
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

char a[15], b[15], c[15];
char A, B, C;
int main()
{
	scanf(" %s %s %s", a, b, c);
	A = a[0] + 'A' - 'a';
	B = b[0] + 'A' - 'a';
	C = c[0] + 'A' - 'a';
	printf("%c%c%c\n", A, B, C);
	return 0;
}

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

ll nC2(ll n){return n*(n-1)/2;}//組み合わせ

int A[200000], C[200000];

int main(){
	int N; cin>>N;
	rep(i, N){scanf("%d",A+i); A[i]--;}//値補正
	rep(i, N) C[A[i]]++;//値の種類毎の計数
	ll all = 0; rep(a, N) all += nC2(C[a]);//組み合わせの総計
	rep(k, N) printf("%lld\n",all - nC2(C[A[k]]) + nC2(C[A[k]]-1));
}

Measured memory_bytes: 3712
n = int(input())
m = 0
d = -1000000000
for i in range(n):
    v = int(input())
    if n == i + 1 and d == 0: d = v - m
    if m == 0:
        m = v
        continue
    d = d if d > v - m else v - m
    m = m if m < v else v
print(d)


Measured memory_bytes: 5608
#include <algorithm>
#include <cassert>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
int main() {

  int n;
  cin >> n;
  vector<int> p(n);
  for (auto &e : p) {
    cin >> e;
    e--;
  }
  vector<int> q(n);
  for (auto &e : q) {
    cin >> e;
    e--;
  }
  vector<int> v(n);
  iota(v.begin(), v.end(), 0);
  int a = -1, b = -1;
  int o = 0;
  do {
    o += 1;
    bool is_p = true, is_q = true;
    rep(i, n) {
      if (p[i] != v[i]) is_p = false;
      if (q[i] != v[i]) is_q = false;
    }
    if (is_p) a = o;
    if (is_q) b = o;
  } while (next_permutation(v.begin(), v.end()));
  assert(a >= 1 and b >= 1);
  cout << abs(a - b) << endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;

const int INF = 100000000;
const int MAX_N = 100;
const int MAX_M = 1000;
const int MAX_W = 100000;
const int MAX_V = 100;
const int MAX_K = 100000;

typedef pair<int, int> P;

int n, K;
int a[MAX_N], m[MAX_N];
int dp[MAX_K+1];




int main(int argc, char *args[]) {
	int A, B, C;
	cin >> A >> B >> C;
	if (B / A > C) {
		cout << C << endl;
	}
	else {
		cout << B / A << endl;
	}
}

Measured memory_bytes: 256
o = list(str(input()))
e = list(str(input()))

o.reverse()
e.reverse()

n = len(o)+len(e)

ans = []
for i in range(n):
    if i%2 == 0:
        ans.append(o.pop())
    else:
        ans.append(e.pop())
print(''.join(ans))


Measured memory_bytes: 61820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    vector<int> ans;
    int m=0,a=0,r=0,c=0,h=0;
    rep(i,n){
        string s; cin >> s;
        if(s[0]=='M') m++;
        if(s[0]=='A') a++;
        if(s[0]=='R') r++;
        if(s[0]=='C') c++;
        if(s[0]=='H') h++;
    }
    if(m!=0) ans.push_back(m);
    if(a!=0) ans.push_back(a);
    if(r!=0) ans.push_back(r);
    if(c!=0) ans.push_back(c);
    if(h!=0) ans.push_back(h);

    ll ansnum = 0;
    if(ans.size()>=3){
        for(int i = 0; i < ans.size()-2; i++){
            for(int j = i+1; j < ans.size()-1; j++){
                for(int k = j+1; k < ans.size(); k++){
                    ansnum += (ll)ans[i]*ans[j]*ans[k];
                }
            }
        }
        cout << ansnum << endl;
    }
    else cout << 0 << endl;

    return 0;
}

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

int main(void) {
  int A, B;
  int ans = 0;
  cin >> A >> B;

  for (int i = 0; i < 2; i++) {
    if (A > B) {
      ans += A;
      A--;
    } else {
      ans += B;
      B--;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n, i, x;
	long long int m, y, a;
	scanf("%d", &n);
	m = 0;
	x = 0;
	y = 0;
	for (i = 0; i < n; i++) {
		scanf("%lld", &a);
		if (a < 0) {
			x++;
			a = -a;
		}
		if (i == 0 || y > a) y = a;
		m += a;
	}
	if (x % 2 == 1) m -= y * 2;
	printf("%lld", m);
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, C;
    cin >> N >> M >> C;
    ll B[M];
    REP(i, 0, M) {
        cin >> B[i];
    }
    ll A[N][M];
    REP(i, 0, N) {
        REP(j, 0, M) {
            cin >> A[i][j];
        }
    }
    ll ans = 0;
    REP(i, 0, N) {
        ll tmp = C;
        REP(j, 0, M) {
            tmp += A[i][j] * B[j];
        }
        if (tmp > 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    int a, b; cin >> a >> b;
    if ((a+b) >= 10) cout << "error" << endl;
    else cout << a+b << endl;
}

Measured memory_bytes: 256
#include<iostream>

char service[3][101];
int point[2];

void solve(int n){
	point[0]=0;
	point[1]=0;
	for(int i=1; service[n][i]!='\0'; i++){
		if(service[n][i]=='A')
			point[0]++;
		else
			point[1]++;
	}
	if(point[0]>point[1])
		point[0]++;
	else
		point[1]++;
}

int main(){
	while(true){
		for(int i=0; i<3; i++){
			std::cin >> service[i];
			if(service[0][0] == '0')
				return 0;
		}
		for(int i=0; i<3; i++){
			solve(i);
			std::cout << point[0] << ' ' << point[1] << std::endl;
		}
	}
}

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

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;

int main(){
  //  freopen("in.txt", "r", stdin);
    double n;
    int k;
    scanf("%lf%ds", &n, &k);
    double ans = 0;
    double base = 1.0/n;
    for(int i = 1; i <= n; ++i){
        int cnt = 0;
        LL now = i;
        while(now < k){
            ++cnt;
            now *= 2LL;
        }
        ans += base * pow(0.5, cnt);
    }
    printf("%.9lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();

    let mut ans_01 = 0;
    let mut ans_10 = 0;
    for (i, c) in buf.trim().chars().enumerate() {
        ans_01 += match (i%2, c) {
            (0, '0') | (1, '1') => 0,
            _ => 1,
        };

        ans_10 += match (i%2, c) {
            (0, '1') | (1, '0') => 0,
            _ => 1,
        };
    }

    println!("{}", std::cmp::min(ans_01, ans_10));
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

class cl{
public:
  int a, b;
  bool operator<(const cl &another) const{
    return b < another.b;
  }
};

void solve(){
  int n; cin >> n;
  vector<cl> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i].a >> v[i].b;
  }
  sort(v.begin(), v.end());
  long long sum = 0;
  for(int i = 0; i < n; i++){
    sum += v[i].a;
    if(sum > v[i].b){
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1792
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Serialization;

namespace AtCoder
{
    class Program
    {

        const int BiggestMod = 1000000007;

        public static void Main()
        {

            var num = int.Parse(Console.ReadLine());
            var ans = 0;
            var buf = 0;
            var buff = 360;

            while (true)
            {
                ans++;
                buf += num;
                if (buf < buff) continue;
                else if (buf > buff) buff += 360;
                else break;

            }

            Console.WriteLine(ans);

        }

    }

}

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

using namespace std;

vector<int> edge[5050];

int dp[5050][5050];
int fuck[5050];
int sz[5050];
const int mod = 1000000007;

void dfs(int pos,int lst)
{
	sz[pos] = 1;
	dp[pos][1] = 1;
	for(auto v : edge[pos])
	{
		if(v != lst)
		{
			dfs(v,pos);
			static int tmp[5050];
			for(int i = 0;i <= sz[pos] + sz[v]; ++ i)
				tmp[i] = 0;
			for(int i = 0;i <= sz[pos]; ++ i)
				for(int j = 0;j <= sz[v]; ++ j)
					tmp[i + j] = (tmp[i + j] + dp[pos][i] * 1ll * dp[v][j] % mod) % mod;
			for(int i = 0;i <= sz[pos] + sz[v]; ++ i)
				dp[pos][i] = tmp[i];
			sz[pos] += sz[v];
		}
	}
	for(int i = 1;i <= sz[pos]; ++ i)
		dp[pos][0] = (dp[pos][0] + dp[pos][i] * 1ll * (mod - 1) % mod * fuck[i] % mod) % mod;
}

int main()
{
	fuck[0] = 1;
	for(int i = 2;i <= 5000; ++ i)
		fuck[i] = fuck[i - 2] * 1ll * (i - 1) % mod;
	int n; scanf("%d",&n);
	for(int i = 1;i < n; ++ i)
	{
		int u,v; scanf("%d%d",&u,&v);
		edge[u].push_back(v); edge[v].push_back(u);
	}
	dfs(1,0);
	printf("%d\n",mod - dp[1][0]);
}

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


namespace solver{
  void solve(){
    int N; std::cin >> N;
    std::vector<int64_t> A(N);
    for(int i = 0; i < N; ++i) std::cin >> A[i];

    int64_t ans = 0;

    for(int i = 1; i < N; ++i){
      if(A[i - 1] > A[i]){
        ans += A[i - 1] - A[i];
        A[i] = A[i - 1];
      }
    }



    std::cout << ans << "\n";
  }
}

int main(){
  solver::solve();
  return 0;
}


Measured memory_bytes: 4848
n = int(input())
a = []
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
    a.append(int(input()))
    for j in range(a[i]):
        xx, yy = (int(i) for i in input().split())
        x[i].append(xx)
        y[i].append(yy)

hoge = [[2]*n for i in range(n)]

for i in range(n):
    for j in range(a[i]):
        if(y[i][j] == 1):
            hoge[i][x[i][j]-1] = 1
        elif(y[i][j] == 0):
            hoge[i][x[i][j]-1] = 0

ans = 0
for i in range(2**n):
    bit_list = []
    for j in range(n):
        if ((i >> j) & 1):
            bit_list.append(1)
        else:
            bit_list.append(0)
    flag = 1
    for k in range(n):
        if(bit_list[k] == 1):
            tmp = 0
            for l in range(n):
                if(hoge[k][l] != 2):
                    if(hoge[k][l] != bit_list[l]):
                        flag = 0
                        break
    if(flag == 1):
        tmp = 0
        for l in range(n):
            if(bit_list[l] == 1):
                tmp += 1
        if(tmp > ans):
            ans = tmp
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>

using ll = long long;

int main() {
    int N, M;
    std::cin >> N >> M;

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

    std::map<int, int> a;
    std::vector<int> sum(N + 1);
    sum[0] = 0;
    for (int i = 1; i < N + 1; i++) {
        sum[i] = (sum[i - 1] + A[i - 1]) % M;
    }

    ll ans = 0;
    for (int i = 0; i < N + 1; i++) {
        ans += a[sum[i]];
        a[sum[i]]++;
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 3968
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.regex;

void main() {
	auto N = readln.chomp.to!int, K = readln.chomp.to!int;
	int res = 1;

	foreach(i; 0..N) res = (res * 2 < res + K ? res * 2 : res + K);
	writeln(res);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<functional>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

int main(){
    int n,m;
    cin >> n>>m;
    cout<<(n-1)*(m-1);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
t = 0
h = 0
for n in range(N):
    w = input().split()
    if w[0] == w[1]:
        t += 1
        h += 1
    elif w[0] > w[1]:
        t += 3
    else:
        h += 3
print(t,h)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
ll f(ll a,ll b,ll x){
	ll k=(a*x)/b;
	ll l=a*(x/b);
	return k-l;
}


signed main(){
	ll a,b,x; cin>>a>>b>>x;
	cout<<f(a,b,min(b-1,x))<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
int main()
{
          int n;
          cin >> n;
          long double ans;
          for(int i=0;i<n;i++)
          {
                    int temp;
                    cin >> temp;
                    ans+=(long double)((long double)1.0/(long double)temp);
          }
          ans=(long double)((long double)1.0/(long double)ans);
          //cout << ans << endl;
          cout << setprecision(60)<< ans << "\n";
          return 0;
}

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

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String inp[]= br.readLine().split(" ");
        int a= Integer.parseInt(inp[0]);
        int b= Integer.parseInt(inp[1]);
        if(a<=12 && a>=6)
        	b/=2;
        else
        	if(a<=5)
        		b=0;
        System.out.print(b);
	}
}

Measured memory_bytes: 19540
S = [int(c) for c in input()]
pairs = (len(S)+1) // 2

zeroone = 0
onezero = 0

for _ in range(pairs):

    last = S.pop()

    if last == 1:
        zeroone += 1
    else:
        onezero += 1

    if S:
        last = S.pop()
        if last == 0:
            zeroone += 1
        else:
            onezero += 1

print(min(zeroone, onezero))



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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d.at(i);
  sort(d.begin(),d.end());
  int ans=0;
  int pre=0;
  rep(i,n){
    if(pre<d.at(i)) ans++;
    pre=d.at(i);
  }
  cout << ans << "\n";
}  

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

using namespace std;

int main()
{
    int H,W;
    char s[52][52];
    bool flag = true;
    scanf("%d%d",&H,&W);

    for(int i=0;i<H;i++)
    {
        scanf("%s",s[i+1]+1);
    }
    
    for(int i=1;i<=H;i++)
    {
        for(int j=1;j<=W;j++)
        {
            if(s[i][j]=='#')
                if(s[i-1][j]!='#')                    
                    if(s[i+1][j]!='#')
                        if(s[i][j-1]!='#')                    
                            if(s[i][j+1]!='#')
                                flag = false;
        }
    }

    if(flag)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
int a[33]={0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
int main()
{
	int n;
	scanf("%d",&n);
	printf("%d",a[n]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    for(int i =0;i<n;i++){
        int z;
        cin >> z;
        x[i]=z;
        y[i]=z;
    }
    sort(y.begin(),y.end());
    for(int i=0;i<n;i++){
       if(x[i]<=y[n/2-1]){
           cout << y[n/2] << endl;
       }else{
           cout << y[n/2-1]<< endl;
       }
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
struct Node
{
    string ss;
    int b,pos;
}s[1002];
bool cmp(Node a,Node b)
{
    if(a.ss==b.ss)
        return a.b>b.b;
    return a.ss<b.ss;
}
int main()
{
    int a,b;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s[i].ss>>s[i].b;
        s[i].pos=i+1;
    }
sort(s,s+n,cmp);
for(int i=0;i<n;i++)
    cout<<s[i].pos<<endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
typedef vector<Pii> Vp;
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define All(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define debug(x) cerr << #x << ':' << x << endl;

#define FAST cin.tie(0), ios::sync_with_stdio(false)
inline bool chmin(int &a, int b){return b<a? a=b,1 : 0;}
const ll LINF = (1LL << 62);
const int INF = 1 << 29;
int n;
Vp node[100010];
Vi min_cost(100010,LINF);

void dijkstra(int k);

main(){
	FAST;
	int q,k;
	cin >> n;

	q = n;
	while(--q){
		int from,to,cst;
		cin >> from >> to >> cst;
		node[from].pb(mkp(cst,to));
		node[to].pb(mkp(cst,from));
	}
	cin >> q >> k;
	dijkstra(k);
	rep(i,q){
		int a,b;
		cin >> a >> b;
		cout << min_cost[a] + min_cost[b] << endl;
	}
}

void dijkstra(int k){
	priority_queue< Pii, Vp, greater<Pii> > pq;
	pq.push(mkp(0,k));

	while(!pq.empty()){
		Pii now = pq.top();pq.pop();
		int cost = now.fi;
		int pos = now.se;
		rep(i,node[pos].size()){
			int ncost = node[pos][i].fi;
			int nxt = node[pos][i].se;
			if(chmin(min_cost[nxt], cost+ncost))
				pq.push(mkp(cost+ncost, nxt));
		}
	}
	return;
}


Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b;
  cin >> a;
  b = a % 10;
  
  if(b == 3){
    cout << "bon" << endl;
  }
  else if(b == 0 || b == 1 || b == 6 || b ==8){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
#define max1 1000001



int main(){	
	vector<int> k;
	long long int n;
	cin>>n;
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			int ct=0;
			//cout<<i<<endl;
			while((n%i)==0){
				n=n/i;
				ct++;
			}
			k.push_back(ct);
			//cout<<n<<" "<<ct<<endl;
		}
	}
	if(n>1){
		k.push_back(1);
	}
	int op=0;
	for (int i = 0; i < k.size(); ++i)
	{
		int x=k[i];
		//cout<<x<<endl;
		int ctr=1;
		while(x>=ctr){
			x-=ctr;
			ctr++;
			op++;
		}
		//cout<<x<<" "<<ctr<<" "<<op<<endl;
	}
	cout<<op<<endl;

}
	
	
	
	





Measured memory_bytes: 3720
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define D 11 
#define MAXN (1 << 18)
#define MAXW (100010)

int dp[(1 << D)][MAXW];
int v[MAXN];
int w[MAXN];

int n, q;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i = 1; i < (1 << D); i++) {
		int (& prevdp)[MAXW] = dp[i / 2];
		for (int j = 0; j + w[i] < MAXW; j++) {
			dp[i][j + w[i]] = prevdp[j] + v[i];
		}
		for (int j = 0; j < MAXW; j++) {
			dp[i][j] = max(prevdp[j], dp[i][j]);
		}
		for (int j = 1; j < MAXW; j++) {
			dp[i][j] = max(dp[i][j], dp[i][j - 1]);
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		int cur, cap;
		cin >> cur >> cap;
		vector<int> items;
		while (cur >= (1 << D)) {
			items.push_back(cur);
			cur >>= 1;
		}
		int m = items.size();
		int bestval = 0;
		for (int mask = 0; mask < (1 << m); mask++) {
			int curv = 0;
			int curw = 0;
			for (int j = 0; j < m; j++) {
				if (mask & (1 << j)) {
					curv += v[items[j]];
					curw += w[items[j]];
				}
			}
			if (curw > cap) {
				continue;
			}
			curv += dp[cur][cap - curw]; 
			bestval = max(curv, bestval);
		}
		cout << bestval << endl;
	}
	return 0;
}


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

/*高速化*/
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* define */
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)

/* 最大値と最小値に置き換える */
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}


/* 型定義 */
typedef vector<long long> vi;
typedef long long ll;
using Graph = vector<vi>;


/* 定数 */
const double PI = 3.141592;
const double e = 2.6;
const long long Inf = 1LL << 60;
const long long mInf = -Inf;


int N,M;
string A[55];
string B[55];

bool match(int x,int y)
{
    for(int i = 0;i < M;i++)
    {
        for(int j = 0;j < M;j++)
        {
            if(A[x + i][y + j] != B[i][j]) return false;
        }
    }
    return true;
}

void calc()
{
    cin >> N >> M;
    int i,j;
    for(i = 0;i < N;i++) cin >> A[i];
    for(j = 0;j < M;j++) cin >> B[j];
    for(i = 0; i<= N - M;i++)
    {
        for(j = 0;j <= N - M;j++)
        {
            if(match(i,j))
            {
                cout << "Yes\n";
                return;
            }
        }
    }
    cout << "No\n";
    return;
}


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


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

INF = 10**9
WHITE = -100
GRAY = -1000
BLACK = -10000

def main():
	m = int(input().strip())
	s = [[-1] * m for _ in range(m)]
	for i in range(m):
		l = list(map(int, input().strip().split()))
		for j in range(l[1]):
			s[i][l[2 + 2 * j]] = l[3 + 2 * j]
	color = [WHITE] * m
	d = [INF] * m
	p = [-1] * m

	d[0] = 0
	# for i in range(m):
	# 	print(s[i])
	color[0] = BLACK
	u = 0
	while True:
		for i in range(m):
			if color[i] != BLACK and s[u][i] != -1:
				if d[u] + s[u][i] < d[i]:
					d[i] = d[u] + s[u][i]
					p[i] = u
		mincost = INF
		for i in range(m):
			if color[i] != BLACK and d[i] < mincost:
				mincost = d[i]
				u = i
		if mincost == INF:
			break
		color[u] = BLACK
	for i in range(m):
		print("{} {}".format(i, d[i]))


if __name__ == '__main__':
	main()



Measured memory_bytes: 5816
import java.util.*;

public class Main {
    static long[] bit;
    static int n;

    static void add(int x, int y) {
        for (int i=x;i<=n;i+=i&(-i)) {
            bit[i]+=y;
        }
    }

    static long sum(int x) {
        long tmp = 0L;
        for (int i=x;i>0;i-=i&(-i)) {
            tmp+=bit[i];
        }
        return tmp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int q = sc.nextInt();
        bit = new long[n+1];
        for (int i=0;i<q;i++) {
            int com = sc.nextInt();
            if (com==0) {
                int x = sc.nextInt();
                int y = sc.nextInt();
                add(x, y);
            } else { // com==1
                int x = sc.nextInt();
                int y = sc.nextInt();
                System.out.println(sum(y)-sum(x-1));
            }
        }
    }
}


Measured memory_bytes: 104468
S=input()
if S=="SUN":
  print("7")
elif S=="MON":
  print("6")
elif S=="TUE":
  print("5")
elif S=="WED":
  print("4")
elif S=="THU":
  print("3")
elif S=="FRI":
  print("2")
elif S=="SAT":
  print("1")

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef map<string,int> MP;
typedef vector<int> V;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define inf (int)(1e9)
#define INF 1.1529215e+18
#define MAXX 999999
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
/*--------------------------------------------*/

int main(){
    int n;cin>>n;
    map<string,int> mp;
    string s[n+1];
    rep(i,n){cin>>s[i];mp[s[i]]++;}
    int flag=1;
    rep(i,n-1){//１じゃなければアウト　
        char last=s[i][s[i].size()-1];
        //printf("last=%c\n",last);
        //printf("mp=%d\n",mp[s[i]]);
        if(mp[s[i]]>1||last!=s[i+1][0])flag=0;
    }
    cout<<(flag?"Yes":"No");
}


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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int H;
	cin >> H;

	while ( H != 0 ) {
		std::vector< std::vector<int> > puzz(H+2, std::vector<int>(5+2));
		std::vector<int> count(10,0);
		for (int i = 0; i < H+2; i++) {
			for (int j = 0; j < 5+2; j++) {
				if (i==0||i==H+1||j==0||j==5+1) {
					puzz[i][j] = -1;
				}
				else {
					cin >> puzz[H-i+1][j];
					count[puzz[H-i+1][j]]++;
				}
			}
		}

		bool chain = true;
		bool same = true;
		bool find = false;
		int n,l;
		int point = 0;
		while (chain) {
			chain = false;
			for (int i = 1; i < H+1; i++) {
				for (int j = 1; j < 5+1; j++) {
					if (count[puzz[i][j]] > 2) {
						n = puzz[i][j];
						l = 1;
						same = true;
						while (same) {
							if (n == puzz[i][j+l]) {
								l++;
							}
							else {
								same = false;
							}
						}
						if (l > 2) {
							for (int k = 0; k < l; k++) {
								puzz[i][j+k] = 0;
							}
							point += n * l;
							count[n] -= l;
							chain = true;
						}
					}
				}
			}

			for (int i = 1; i < H+1; i++) {
				for (int j = 1; j < 5+1; j++) {
					if (puzz[i][j] == 0) {
						find = false;
						for (int k = i+1; k < H+1 && !(find); k++) {
							if (puzz[k][j] != 0) {
								std::swap(puzz[i][j], puzz[k][j]);
								find = true;
							}
						}
					}
				}
			}
		}
		cout << point << endl;
		cin >> H;
	}

	return 0;
}

Measured memory_bytes: 3144
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;wahile(t--) 
const int maxx  = 3*1e5 , limit = 1e17 , MOD=1e9+7;
string binary(int n){bitset<32>b(n) ;string p =b.to_string();return p;}
int decimal(string s){int res = 0; for(int i = 0; i < s.size() ; i++ ){if(s[i] == '1')res = res + pow(2,s.size() - i -1);}    return res;}
bool isPrime(int n){if (n <= 1) return false; if (n <= 3) return true;if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
int pow (int x, int n,int mod) {if (n == 0) return 1; int res = pow (x, n / 2,mod);res = (res * res) % mod;if (n % 2) res = (res * x ) % mod;return res;}
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int32_t main(){
    boost;
    int n;cin>>n;
    
    map< string,int >cn;
    int res=0;
    for(int i = 0; i < n; i++ ){
        string s;cin>>s;
        cn[s]++;
        if(cn[s]==1)res++;
    }
    cout<<res<<endl;
   
}

Measured memory_bytes: 19224
n, Y = gets.chomp.split.map(&:to_i)
def total(x, y, z)
    10000*x + 5000*y + 1000*z
end
0.upto(n) do |x|
    0.upto(n-x) do |y|
        z = n - x - y
        if total(x, y, z) == Y
            puts "#{x} #{y} #{z}"
            exit
        end
    end
end
puts '-1 -1 -1'

Measured memory_bytes: 1788
S = list(input())
T = list(input())

lst_of_values = []
for i in range(len(S)):
    current = 0
    if i + len(T) > len(S):
        break

    k = 0
    for j in range(i, i+len(T)):
        if S[j] != T[k]:
            current += 1
        k+=1
    lst_of_values.append(current)
    k=0

print(min(lst_of_values))



Measured memory_bytes: 9064
#include <random>    //ランダム
#include <algorithm> //アルゴリズム
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#include <cassert>
#include <cfloat>
#include <numeric>
#include <climits>
#include <stdint.h>
using namespace std;
// vector<int> temple(7,0);
    // for(int i=0; i<temple.size(); i++){
    
    // }
    // int maxtemp=*max_element(temple.begin(), temple.end());;
    // int mintemp=*min_element(temple.begin(), temple.end());;
    // int answer=0;
    // for(int i=0; i<temple.size(); i++){
    //     if(temple[i]==maxtemp||temple[i]==mintemp){
            
    //     }else{
    //         answer+=temple[i];
    //     }
    // }
    // answer/=5;
    // cout << answer << std::endl;
int main()
{
    int ondo;
    cin >> ondo;
    if(ondo>=30){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    } 
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    int bg[3][3];
    int flag[3][3] = {0};
    REP(i, 3)
    REP(j, 3) {
        cin >> bg[i][j];
    }
    cin >> N;
    vi b(N);
    cin >> b;
    REP(n, N)
    REP(i, 3)
    REP(j, 3) {
        if (bg[i][j] == b[n]) {
            flag[i][j] = 1;
        }
    }
    bool ok = false;
    REP(i, 3) {
        if (flag[i][0] == 1 && flag[i][1] == 1 && flag[i][2] == 1) {
            ok = true;
        } else if (flag[0][i] == 1 && flag[1][i] == 1 && flag[2][i] == 1) {
            ok = true;
        }
    }
    if (flag[0][0] && flag[1][1] && flag[2][2]) {
        ok = true;
    } else if (flag[0][2] && flag[1][1] && flag[2][0]) {
        ok = true;
    }
    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <tuple>

int main()
{
	std::string N;
	std::cin >> N;
	int val = 0;
	for (size_t i = 0; i < N.size(); ++i) {
		val = (val + N[i] - '0') % 9;
	}
	if (val == 0) {
		std::cout << "Yes" << std::endl;
	}
	else
	{
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;

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

	int m = a+b;
	m = max(a - b, m);
	m = max(a*b,m);

	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

vi g[N];
bool vis[N];

void dfs(int v) {
	vis[v] = 1;
	for(auto it : g[v]) {
		if(!vis[it]) {
			dfs(it);
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(!vis[i]) {
			dfs(i);
			cnt++;
		}
	}
	cnt--;
	cout << cnt;

	return 0;
}

Measured memory_bytes: 10424
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc147/tasks/abc147_e
//bitset<100> bなどと定義すると、長さ100の0 or 1の列を確保できる
//これに対してbit演算も可能
//ちなみにbitset<n>のnはコンパイル時に決まっている必要あり
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

int H,W;
int A[80][80];

int ans = 2147483647;

void solve(){
	const int standard = 80*80*2;
	const int bitset_size = standard*2+1;
	vector<vector<bitset<bitset_size>>> dp(80,vector<bitset<bitset_size>>(80,0));//x,yまできたときに和がjであることが可能かどうかをdp[x][y][j]とおく
	//jのとりうる値は-80*80*2 ~ 80*80*2;
	dp[0][0][standard-A[0][0]] = 1;
	dp[0][0][standard+A[0][0]] = 1;
	for(int h=0;h<H;h++){
		for(int w=0;w<W;w++){
			//上から下への遷移
			if(h){
				//例えばdp[i-1][j] = 01011000
				//左から順に(i-1,j)で計算した後に0,1,2,3,4,5,6,7になることが可能かどうかを表している
				//としたとき
				//例えばa[i][j]=2であれば
				//dp[i][j] = dp[i-1][j] >> 2を計算し
				//dp[i][j] = 00010110
				//左から順に(i,j)で計算した後に0,1,2,3,4,5,6,7になることが可能かどうかを表している
				// << 2についても計算しOR(|)をとって保管
				dp[h][w] |= dp[h-1][w] << A[h][w];
				dp[h][w] |= dp[h-1][w] >> A[h][w];
			}
			//左から右への遷移
			if(w){
				dp[h][w] |= dp[h][w-1] << A[h][w];
				dp[h][w] |= dp[h][w-1] >> A[h][w];
			}
		}
	}
	for(int i=0;i<bitset_size;i++){
		if(dp[H-1][W-1][i]) ans = min(ans,abs(i-standard));
	}
}
 
int main(){
	cin >> H >> W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++) cin >> A[i][j];
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int x;
			cin >> x;
			A[i][j] = abs(A[i][j]-x);
		}
	}
 
	solve();

	cout << ans << endl;
	return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int N;
  long long a[100010];
  int i;
  long long s=1;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%lld",&a[i]);
  }
  int zero=0;
  for(i=0;i<N;i++){
    if(a[i]==0){
      zero=zero+1;
    }
    if(zero>0){
      printf("0\n");
      return 0;
    }
  }
  for(i=0;i<N;i++){
    if(a[i]<=1000000000000000000/s){
      s=s*a[i];
    }
    else{
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld",s);
  return 0;
}


Measured memory_bytes: 2496
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int n, r; cin >> n >> r;
	if (n >= 10) cout << r;
	//r=inner-100*(10-n)
	else cout << r + 100 * (10 - n);

	return 0;
}

Measured memory_bytes: 3144
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

LL cnt[5];
int idx[255];
char name[255];
LL dp[6][4];
int main() {
	memset(idx, -1, sizeof(idx));
	idx['M'] = 0;
	idx['A'] = 1;
	idx['R'] = 2;
	idx['C'] = 3;
	idx['H'] = 4;
	int n;
	cin >> n;
	REP(i, n) {
		scanf("%s", name);
		if (idx[name[0]] != -1) cnt[idx[name[0]]]++;
	}
	LL ret = 0;
	dp[0][0] = 1;
	REP(i, 5) {
		REP(j, 4) {
			dp[i + 1][j + 1] += cnt[i] * dp[i][j];
			dp[i + 1][j] += dp[i][j];
		}
	}
	cout << dp[5][3] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e18+7
#define lim (lld)1e9+7
#define MAX2 (lld)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

lld power(lld x, lld y, lld p)  
{   lld res = 1;     x = x % p; if (x == 0) return 0;  
  
    while (y > 0)  
    { if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;   }  
    return res;  } 


lld extend_gcd(lld a, lld b, lld& x, lld& y) {
    if (b == 0) { x = 1;y = 0;return a;}
    lld x1, y1;
    lld d = extend_gcd(b, a % b, x1, y1);
    x = y1; y = x1 - y1 * (a / b);return d;	}

lld rowNum[]={-1,0,0,1};
lld colNum[]={0,-1,1,0};

int main()
{
	fastio
	lld x,k,d;
	cin>>x>>k>>d;

	x=abs(x);

	lld req = x/d,ans;

	if(k<=req)
		ans = x-k*d;

	else
	{
		lld reqans = abs(x-req*d);
		k-=abs(req);

		if(abs(reqans-d)<reqans)
		{
			reqans-=d;
			k--;
		}

		if(k%2==0)
			ans=reqans;
		else
			ans=min(abs(reqans)-d,abs(reqans+d));
	}

	cout<<abs(ans)<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

int main() {
  set<string> st;
  int n;
  cin>>n;
  while (n--) {
    char cmd[8], str[20];
    scanf("%s %s",cmd,str);
    if (!strcmp(cmd,"insert")) {
      st.insert(str);
    } else {
      cout<<(st.find(str)!=st.end()?"yes":"no")<<endl;
    }
  }
  return 0;
}



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

typedef long long ll;
#define endl '\n'

int main()
{
    int n;cin>>n;
    n%=10;
    if(n==3)cout<<"bon\n";
    else if(n==0||n==1||n==6||n==8)cout<<"pon\n";
    else cout<<"hon\n";
    return 0;
}

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

typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back

template<class T>
inline bool read(T &ret) {
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF) return 0;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

LL a[N * 5], k, n;
LL ans = 0, sum[N * 5] = {0};
map<unsigned int, LL> num;

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        read(a[i]);
        sum[i] = sum[i - 1] + a[i];
    }
    num[0] = 1;
    for (int i = 1; i <= n; ++i) {
        if (i - k >= 0) {
            num[(sum[i - k] - (i - k)) % k]--;
        }
        if (num.count((sum[i] - i) % k)) {
            ans += num[(sum[i] - i) % k];
        }
        num[(sum[i] - i) % k]++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 18432