akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <cctype>
#include <cstdlib>
#include <string.h>
#include <utility>
#include <cstdio>
#include <set>
#include <map>
#include <assert.h>
using namespace std;

#define INF (1 << 20)
#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

#define ll long long
#define LL long long

int flg[10];

int dfs(int n, int s) {
	int ret = 0;
	if (n == 0) return s == 0;
	for (int i = 0; i < 10; ++i) {
		if (flg[i]) continue;
		flg[i]++;
		ret += dfs(n-1, s-i);
		flg[i]--;
	}
	return ret;
}

int main() {
	int n, s;
	while (cin >> n >> s) {
		if (n == 0) break;
		int res = dfs(n, s);
		while (n != 0) res /= n--;
		cout << res << endl;
	}
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll d, g;
  cin >> d >> g;
  
  vector<ll> p(d), c(d);
  REP(i, d)
    cin >> p[i] >> c[i];
  
  ll min_count = 114514191;
  //bit search for patterns to prove all pi
  for(ll bit = 0; bit < (1 << d); bit++){
    ll sum = 0;
    ll count = 0;
    //match bit
    for(ll i = 0; i < d; i++){
      if((bit >> i) & 1){
        sum += (i+1) * 100 * p[i] + c[i];
        count += p[i];
      }
    }
    //cout << sum << endl;
    if(sum >= g)
      min_count = min(count, min_count);
    else{
      //pick pi until not all pi
      for(ll i = d-1; i >= 0; i--){
        if(bit & (1 << i))
           continue;
        
        //cout << i << endl;
        REP(j, p[i]){
          sum += (i+1)*100;
          count++;
          if(sum >= g){
            min_count = min(count, min_count);
            break;
          }
        }
        break;
      }
    }
    
  }
  
  cout << min_count << "\n";
}

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

int main() {
  
  int s; cin >> s; vector<int> vec; int count = 1;
  
  vec.push_back(s);
  
  while (true) {
    
    int tmp = vec.at(count - 1);
    
    if (tmp % 2 == 0) tmp /= 2;
    else tmp = tmp * 3 + 1;
    
    auto result = find(vec.begin(), vec.end(), tmp);
    
    if (result == vec.end()) vec.push_back(tmp);
    else {
      cout << count + 1 << endl;
      break;
    }
    
    count++;
    
  }
  
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

void main()
{
	foreach (line; stdin.byLine) {
		auto x = line.split(",").map!(to!int).array.sort.array;
		auto u = x.uniq.array.length;
		if (u == 2) {
			auto n = x.count(x[0]);
			if (n == 2 || n == 3) {
				writeln("full house");
			} else {
				writeln("four card");
			}
		} else if (u == 3) {
			foreach (e; x) {
				if (x.count(e) == 3) {
					writeln("three card");
					break;
				} else if (x.count(e) == 2) {
					writeln("two pair");
					break;
				}
			}
		} else if (u == 4) {
			writeln("one pair");
		} else {
			auto arr = iota(x[0], x[0]+5).array;
			auto aarr = 1 ~ iota(10, 14).array;
			if (x == arr || x == aarr) {
				writeln("straight");
			} else {
				writeln("null");
			}
		}
	}
}

Measured memory_bytes: 1216
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/multi_array.hpp>

using namespace std;

#if 0
// memo
abs()

start_with(str, "hoge");
ends_with(str, "hoge");

std::sort(d.begin(), d.end());
d.erase(std::unique(d.begin(), d.end()), d.end());
#endif

using namespace boost;
using namespace boost::algorithm;

/**

   @retuen msb pos + 1,
   @retval 0 not found
 */
template<size_t SZ>
size_t msb(const std::bitset<SZ>& s) {
    for (size_t i = SZ; i != 0; --i) {
        if (s[i-1]) {
            return i;
        }
    }
    return 0;
}


static inline bool isOdd(int v)
{
    return v & 0x01;
}

int main()
{
    uint64_t X, Y;

    std::cin >> X >> Y;

    uint64_t v = X;
    uint64_t count = 1;
    for (;;) {
        auto vv = v*2;
        if (vv > Y) {
            break;
        }
        count++;
        v = vv;
    }

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


Measured memory_bytes: 256
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout << setprecision(12)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cin4(x, y, z, _) cin >> x >> y >> z >> _
#define cin5(x, y, z, p, q) cin >> x >> y >> z >> p >> q
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define Test ll _t; cin1(_t); rep(w, 0, _t)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cntv(v,a) count(v.begin(),v.end(),a)
#define fans(x) \
    if ( x  ) coul("YES"); \
    else coul("NO")

struct point{    int x, y, ind;   char ch;  };
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod = 1000000007;
const ll mx =131080;
//ll rnd(ll x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
bool cmp(point A, point B){   if(A.x != B.x) ret(A.x < B.x);  ret(A.y < B.y);   }
//void segPre(ll l, ll h, ll in) {  ll segTree[3*mx];   if ( l == h ){  segTree[ in ] = arr[ l ];   return;  }   ll m = (l + h) / 2; pre(l, m, 2*in);  pre(m+1, h, 2*in+1);    segTree[ in ] = segTree[ in*2 ] | segTree[ in*2+1 ];   segTree[ in ] = segTree[ in*2 ] ^ segTree[ in*2+1 ];    }
// head collected
// Don't use variable name as --> prev, time, _t, w, y1


ll n, m, ara[200007], _, da;


start;
// op = 0 when n = even
    cin1(n);

    rep(i, 0, n-1){
        cin1(_);
        ara[ _ ]++;
    }


    rep(i, 1, n+1)
        coul(ara[ i ]);

finish


Measured memory_bytes: 5184
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

struct UnionFind {
    vector<int> par;
    
    //要素nで初期化
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    //xが属する集合の根を返す
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    //xとyが同じ集合に属しているかを判定
    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    //xが属する集合とyが属する集合をマージ
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // 計算量が減るよ
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    //xが属する集合のサイズ
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
	int n,m,k;cin>>n>>m>>k;
	vector<int> friend_count(n + 1,0);
	UnionFind fri(n + 1);

	for(int i = 0; i < m; i++) {
		int a,b;cin>>a>>b;
		fri.merge(a,b);
		friend_count[a]++;
		friend_count[b]++;
	}
	vector<int> ans(n + 1,0);
	for(int i = 0; i < k; i++) {
		int a,b;cin>>a>>b;
		if (fri.issame(a,b)){
			ans[a]--;
			ans[b]--;
		}
	}
	for(int i = 1; i <= n; i++) {
		ans[i] += fri.size(i) - 1 - friend_count[i];
	}
	for(int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359
int T[100000];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N,C,K;
	cin >> N >> C >> K;
	for(int i=0; i<N; i++) cin >> T[i];
	sort(T, T+N);
	int ans = 0;
	int l = INT_MIN;
	int people = 0;
	for(int i=0; i<N; i++){
		//cout << ans << " " << l << " " << people << endl;
		if(T[i] > l){
			ans++;
			l = T[i]+K;
			people = 1;
			if(people == C) l = INT_MIN;
		}
		else{
			people++;
			if(people == C) l = INT_MIN;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>

using namespace std;

int main(void) {
	
	int n, m, a[50], b[50], num[50] = {};

	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		cin >> a[i] >> b[i];
	}
	
	for (int i = 0; i < m; i++)
	{
		num[a[i] - 1]++;
		num[b[i] - 1]++;
	}

	for (int i = 0; i < n; i++)
	{
		cout << num[i] << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
x,k,d = map(int,input().split())

x = abs(x)

if k%2 == 0:
    if x >= k*d:
        print(x - k*d)
    else:
        print(min(x%(2*d),abs(x%(2*d)-2*d)))

else:
    if x >= k*d:
        print(x - k*d)
    else:
        #print(min(x%d,abs(x%d-d)))
        print(abs(x%(2*d)-d))

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 100009;

lli n,k;
lli ans;

int main(){
	cin >> n >> k;
	if(k%2){
		ans = n/k;
		cout << ans*ans*ans << endl;
	}else{
		ans = 0;
		for(lli a = 1;a <= n;a++){
			if(a%k == 0){
				ans += (n/k)*(n/k);
			}else if(a%(k/2) == 0){
				ans += ((n-k/2)/k+1)*((n-k/2)/k+1);
			}
		}
		cout << ans << endl;
	}
}


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

int main(void) {
	int n, k, x[110000];

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

	int min = 1000000000;
	for (int i = 0; i < n - (k - 1); i++) {
		int plus = 0, minus = 0, length = 1000000000;
		if (x[i] < 0) {
			minus = abs(x[i]);
			length = abs(x[i]);
		}
		if (x[i + (k - 1)] > 0) {
			plus = x[i + (k - 1)];
			if (x[i + (k - 1)] <= length) length = x[i + (k - 1)];
		}

		if (plus > 0 && minus > 0) {
			if (plus + minus + length <= min) {
				min = plus + minus + length;
			}
		}
		else if (plus + minus <= min) {
			min = plus + minus;
		}
	}

	cout << min << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
  fastIO;
  vector<int> time(5);
  rep(i, 5) cin >> time.at(i);

  int diff = 0;
  for(auto t: time) {
    if(t % 10 != 0)
      diff = max(diff, (10 - t % 10));
  }

  int sum = 0;
  for(auto t: time) {
    sum += t;
    if(t % 10 != 0)
      sum += (10 - t % 10);
  }

  cout << sum - diff << endl;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
  int n,count,number,p[20];
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  count=0;
  for(int i=1;i<n-1;i++){
    if((p[i]>p[i-1]&&p[i]<p[i+1])||(p[i]>p[i+1]&&p[i]<p[i-1])){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}

    


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
	string str;
	cin >> str;
	int flag = 0;
	for(int i = 0; i < str.length(); i++) {
		if(str[i] == 'C') flag = 1;
		if((str[i] == 'F')&&(flag == 1)) flag = 2;
	}

	if(flag == 2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> sum(N);
    int s = 0;
    for (int i = 0; i < N; i++) {
        int w;
        cin >> w;
        sum[i] = sum[i - 1] + w;
        s += w;
    }

    int res = 1000000000;
    for (int i = 0; i < N; i++) {
        res = min(res, abs((s - sum[i]) - sum[i]));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=100005;
int n,m;
int par[max_n];
int findpar(int x)
{
    return x==par[x]?x:par[x]=findpar(par[x]);
}
void unite(int x,int y)
{
    x=findpar(x);y=findpar(y);
    if(x!=y)par[x]=y;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)par[i]=i;
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        unite(x,y);
    }
    int ans=0;
    for(int i=1;i<=n;i++)if(findpar(i)==i)ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1152
#include<cstdio>
#include<cstring>
char s[1010][1010];
int qx[1001000],qy[1001000],d[1001000],l=0,r=0;
int X[4]={-1,0,0,1};
int Y[4]={0,-1,1,0};
int main()
{
  	int n,m;
  	scanf("%d%d",&n,&m);
  	for(int i=1;i<=n;++i)
      	scanf("%s",s[i]+1);
  	for(int i=1;i<=n;++i)
      	for(int j=1;j<=m;++j)
          	if(s[i][j]=='#')
            {
            	qx[++r]=i;
              	qy[r]=j;
              	d[r]=0;
            }
 	while(l<r)
    {
      	int x=qx[++l];
      	int y=qy[l];
      	for(int i=0;i<4;++i)
          	if(s[x+X[i]][y+Y[i]]=='.'&&x+X[i]>0&&x+X[i]<=n&&y+Y[i]>0&&y+Y[i]<=m)
            {
              	qx[++r]=x+X[i];
              	qy[r]=y+Y[i];
              	s[qx[r]][qy[r]]='#';
              	d[r]=d[l]+1;
            }
    }
  	printf("%d\n",d[r]);
  	return 0;
}

Measured memory_bytes: 12928
<?php 
fscanf(STDIN,"%d",$n);
$a_li = explode(" ",trim(fgets(STDIN)));
$key_count = array();
for($i=0;$i<$n;$i++){
  $key_count[$a_li[$i]]++;
}

$diff = 0;
//print_r($key_count);

foreach($key_count as $key => $count){
	if($key==$count){
      continue;
    }elseif($key<$count){
      $diff += $count-$key;
    }else{
      $diff += $count;
    }
}


echo $diff;

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

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    int ans = 1;
    while(2*ans <= n) ans *= 2;

    cout << ans << endl;
}

Measured memory_bytes: 380
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  cin>>n;
  int h[n];
  REP(i, n)cin>>h[i];
  if(n==1){
    cout<<h[0]<<endl;
    return 0;
  }

  int ans=h[0];

  REP(i, n-1){
    ans += max(0, h[i+1]-h[i]);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
from numba import jit
@jit
def main():
    n,k = map(int,input().split())
    p = list(map(int,input().split()))
    c = list(map(int,input().split()))

    ans=-10**18
    for i in range(n):
        start,count=i,1
        val=c[start]
        while p[start]-1 != i:
            start = p[start]-1
            count += 1
            val += c[start]
        start = i
        if val > 0:
            a = (k//count-1)*val
            ans=max(a,ans)
            num=count+k%count
        else:
            a=0
            num=min(k,count)
        for _ in range(num):
            a += c[start]
            start=p[start]-1
            ans=max(a,ans)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 119976
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

int64_t mod = 998244353 ;

vector<int> getprime(int n){
    vector<int> p(0) ;
    vector<bool> table(n+1,0) ;
    for (int i = 2; i <= n; i++)
    {
        if (table.at(i) == 0)
        {
            p.push_back(i) ;
            for (size_t j = 2; j < n/i ; j++)
            {
                table.at(i*j) = 1 ;
            }
            
        }
        
    }
    return p ;
}

int d(int64_t n){
    int re = 1 ;
    while (1)
    {
        n /= 10 ;
        if (n > 0)
        {
            re ++ ;
        }else
        {
            return re ;
        }
        
        
    }
    
}

int main(){
    vector<int> t(5) ;
    for (int i = 0; i < 5; i++)
    {
        cin >> t.at(i) ;
    }
    int ans = 0 ;
    for (int i = 0; i < 5; i++)
    {
        ans += (t.at(i)/10 ) *10 ;
        t.at(i) %= 10 ;
    }
    sort(t.begin(),t.end()) ;
    bool flag = 1 ;
    for (int i = 0; i < 5; i++)
    {
        if (t.at(i) > 0)
        {
            if (flag)
            {
                ans += t.at(i) ;
                flag = 0 ;
            }else
            {
                ans += 10 ;
            }
            
            
        }
        
    }
    
    cout << ans << endl ;

}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)(n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (int)(n); i++)
#define INF 100000000

template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}

int main()
{
    ll H, N;
    cin >> H >> N;
    vector<ll> A(N), B(N);

    REP(i, N)
    cin >> A[i] >> B[i];

    ll dp[H + 1];
    REP(i, H + 1)
    {
        dp[i] = INF;
    }

    dp[0] = 0;

    REP(i, N)
    {
        REP(j, H)
        {
            chmin(dp[min(j + A[i], H)], dp[j] + B[i]);
        }
    }

    cout << dp[H] << endl;
}

Measured memory_bytes: 3692
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    if(a + b == 15){
        cout << "+" << endl;
        return 0;
    }

    if(a * b == 15){
        cout << "*" << endl;
        return 0;
    }

    cout << "x" << endl;

    return 0;
}


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

using namespace std;
 
int main(){
    int n;
    cin >> n;
    if(n >= 195)
        cout << "5" << endl;
    else if(n >= 189)
        cout << "4" << endl;
    else if(n >= 165)
        cout << "3" << endl;
    else if(n >= 135)
        cout << "2" << endl;
    else if(n >= 105)
        cout << "1" << endl;
    else
        cout << "0" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	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 k;
	cin>>k;
	cout<<a[k];
	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; cin >> N;
    vector<int> H(N);
    for(int i=0; i<N; i++) cin >> H[i];

    vector<int> ans(N);
    for(int i=N-2; i>=0; i--) {
        if(H[i] >= H[i+1]) ans[i] = ans[i+1] + 1;
        else ans[i] = 0;
    }

    cout << *max_element(ans.begin(), ans.end()) << endl;
    return 0;
}


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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}

int main(){
    string S;
    cin >> S;
    int N = S.size();

    static int64_t dp[4001][4020];
    dp[0][0] = 1;
    int rest = 0;
    for(int i=0; i<2*N; i++){
        int plus = i<N ? (S[i] - '0') : 0;
        if(i<N) rest += 2;
        rest--;
        for(int j=0; j<=2*N; j++){
            if(j+plus <= rest) add(dp[i+1][j+plus], dp[i][j]);
            if(j+plus-1 <= rest && j+plus-1 >= 0) add(dp[i+1][j+plus-1], dp[i][j]);
        }
    }
    cout << dp[2*N][0] << endl;
    return 0;
}

Measured memory_bytes: 123520
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

int my_gcd(int n , int m){
  if(n < m){
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}



int main(){
ll N,M; cin >> N >> M;
ll ans;
if(2*N >= M){
  ans = M / 2;
}
else{
  ans = N;
  M -=2 * N;
  ans += M / 4;
}
cout << ans << endl;
}

Measured memory_bytes: 256
from collections import*
import sys
input=sys.stdin.readline


class UNION_FIND(object):
    def __init__(self,n):
        #親の番号を格納する。親だった場合は-(その集合のサイズ)
        #作るときはParentの値を全て-1にする
        #こうすると全てバラバラになる
        self.parent=[-1 for i in range(n)]
        
    def root(self,x):
        #Aがどのグループに属しているか調べる
        if self.parent[x]<0:
            return x
        else:
            self.parent[x]=self.root(self.parent[x])  #親を再帰で探知 再帰は最後に上のifにひっかかる
            return self.parent[x]
 
    def size(self,x):
        #自分のいるグループの頂点数を調べる
        return -self.parent[self.root(x)]   #親をとってきたい
        
    def union(self,x,y):
        #AとBをくっ付ける
        #AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        #print(self.parent)
        x=self.root(x)
        y=self.root(y)
        #print(x,y)
        if x==y:   #すでにくっついてるからくっ付けない
            return False
            
        #大きい方(A)に小さいほう(B)をくっ付けたい
        #大小が逆だったらひっくり返しちゃう。
        if self.size(x)<self.size(y):
            x,y=y,x
        self.parent[x]+=self.parent[y]  #Aのサイズを更新する
        self.parent[y]=x   #Bの親をAに変更する
        return True
        
n,k,l=map(int,input().split())
u1=UNION_FIND(n)
u2=UNION_FIND(n)
d=defaultdict(int)
for i in range(k):
    p,q=map(int,input().split())
    u1.union(p-1,q-1)
for i in range(l):
    p,q=map(int,input().split())
    u2.union(p-1,q-1)
for i in range(n):
    d[(u1.root(i),u2.root(i))]+=1
print(*[d[(u1.root(i),u2.root(i))]for i in range(n)])

Measured memory_bytes: 41468
#include<bits/stdc++.h>
using namespace std;
int n,k,a[50],num;
bool cmp(int x,int y)
{
	return x>y;
}
int main() {
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=k;i++) num+=a[i];
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N;
vector<int> v;

int dp[15][100050]; //v[i]までで金額iを作るための最小コスト
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;

    v.push_back(1);
    int t1 = 6;
    while(t1 < 100000){
        v.push_back(t1);
        t1 *= 6;
    }
    int t2 = 9;
    while(t2 < 100000){
        v.push_back(t2);
        t2 *= 9;
    }
    sort(v.begin(), v.end());

    REP(i,0,v.size()+1){
        REP(j,0,100010){
            if(j == 0) dp[i][j] = 0;
            else dp[i][j] = INF;
        }
    }

    REP(i,1,v.size()+1){
        REP(j,1,100010){
            dp[i][j] = dp[i-1][j];
            if(j - v[i-1] >= 0){
                dp[i][j] = min(dp[i][j], dp[i][j - v[i-1]] + 1); //v[i]を使用する場合
            }
        }
    }

    cout<<dp[v.size()][N]<<endl;

    return 0;
}


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

typedef vector<double> vec;
typedef vector<vec> mat;

const double EPS = 1e-8;

vec gauss_jordan(const mat &A, const vec &b,int k){
  int n = A.size();
  mat B(n, vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      B[i][j] = A[i][j];
  for(int i=0;i<n;i++) B[i][n] = b[i];

  for(int i=0;i<k;i++){
    int pivot = i;
    for(int j=i+1;j<n;j++) if(fabs(B[j][i]) > fabs(B[pivot][i])) pivot = j;
    swap(B[i],B[pivot]);

    //ティツァツ」テ」ツ?古」ツ?ェテ」ツ??」ツ?凝」ツ??」ツ?づ」ツ?」テ」ツ?ヲテ」ツつづ、ツクツ?ヲツ?湘」ツ?ァテ」ツ?ッテ」ツ?ェテ」ツ??」ツ??
    if(fabs(B[i][i]) < EPS) return vec();
    
    for(int j=i+1;j<=n;j++) B[i][j] /= B[i][i];
    for(int j=0;j<n;j++)
      if(i != j)
	for(int k=i+1;k<=n;k++)
	  B[j][k] -= B[j][i] * B[i][k];
  }
  vec x(n);
  for(int i=0;i<n;i++) x[i] = B[i][n];
  return x;
}


int X[111][111];
int C[111][111];
int P,S;

bool check(const vec &v){  
  for(int i=0;i<=P;i++)
    for(int j=0;j<=S;j++)
      if( C[i][j] != -1 )
        X[i][j] = (int)round(v[C[i][j]]);  
  for(int i=0;i<=P;i++){
    int sum = 0;
    for(int j=0;j<S;j++) sum += X[i][j];
    if( sum != X[i][S] ) return false;
  }
  for(int j=0;j<=S;j++){    
    int sum = 0;
    for(int i=0;i<P;i++) sum += X[i][j];
    if( sum != X[P][j] ) return false;
  }  
  return true;
}

void view(vec& v){
  for( auto a : v )
    cout << a << " ";
  cout << endl;
}

const int INF = (1<<29);
int main(){

  while( cin >> P && P ){
    cin >> S;
    memset( C,-1,sizeof(C) );
    memset( X,0,sizeof(X));
    int cnt = 0;
    for(int i=0;i<=P;i++){
      for(int j=0;j<=S;j++){
        string s; cin >> s;
        if( s == "?" ) C[i][j] = cnt++;
        else X[i][j] = stoi(s);
      }
    }
    
    static int ttt=0;
    if( ttt++ ) cout << endl;

    int n = P+S+1;

    if( cnt >  n ) {
      cout <<"NO" << endl;
      continue;
    }
    
    mat M = mat(n,vec(n));
    vec V = vec(n);
    set<vec> F;
    int k = 0;
    for(int i=0;i<P;i++){
      V[k] = 0;
      for(int j=0;j<S;j++){
        if( C[i][j] != -1 ) M[k][C[i][j]] = 1;
        else V[k] -= X[i][j];
      }
      V[k] += X[i][S];
      k++;
    }

    for(int j=0;j<S;j++){
      V[k] = 0;
      for(int i=0;i<P;i++){
        if( C[i][j] != -1 ) M[k][C[i][j]] = 1;
        else V[k] -= X[i][j];
      }
      V[k] += X[P][j];
      k++;
    }

    for(int i=0;i<P;i++)
      for(int j=0;j<S;j++){
        if( C[i][j] != -1 ) M[k][C[i][j]] = 1;
        else V[k] -= X[i][j];
      }
    V[k] += X[P][S];
    k++;
    
    
    vec res = gauss_jordan(M,V,cnt);
    if( res.empty() ) cout << "NO" << endl;
    else {
      if( check(res) ){
        for(int i=0;i<cnt;i++)
          cout << (int)round(res[i]) << endl;
      } else
        cout << "NO" << endl;
    }
  }
}

Measured memory_bytes: 3236
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<cassert>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(a, max(b, c)) - min(a, min(b, c)) << endl;
}

Measured memory_bytes: 256
a,b = input().split()
a = int(a)
b = int(b)

def gcd(x,y):
  r = 1
  while r!=0:
    #x = max(x,y)
    #y = min(x,y)
    r = x % y
    x=y
    y=r
  return (x)

print (int(a*b/gcd(max(a,b),min(a,b))))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define dF2(i,a,b) for(int i=a;i>(b);--i)
#define eF(i,u) for(int i=h[u];i;i=nxt[i])
#define ll long long
#define ld double
typedef pair<int,int> pii;
inline int Gcd(int X,int Y){return Y?Gcd(Y,X%Y):X;}
inline ll Gcd(ll X,ll Y){return Y?Gcd(Y,X%Y):X;}
inline int Pow(int base,ll exp,int _mod){if(!(base%=_mod))return 0;int _ans=1;for(;exp;exp>>=1,base=(ll)base*base%_mod)exp&1?_ans=(ll)_ans*base%_mod:0;return _ans;}
inline ll Pow(ll base,ll exp,ll _mod){if(!(base%=_mod))return 0;ll _ans=1;for(;exp;exp>>=1,base=base*base%_mod)exp&1?_ans=_ans*base%_mod:0;return _ans;}
const int INF=0x3f3f3f3f;

int n,k;
int a[100001],b[100001];

int h[100001],nxt[200001],to[200001],tot;
inline void ins(int x,int y){nxt[++tot]=h[x];to[tot]=y;h[x]=tot;}

int main(){
	scanf("%d%d",&n,&k);
	printf("%d",(n-2)/(k-1)+1);
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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 EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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


	bool f = true;

	for (int i = 0; i < 3; i++) {
		int x = a[i] % 2;
		int y = a[0] % 2;

		if (x != y) {
			f = false;
		}
	}

	if (f) {
		sort(a.begin(), a.end());
		int tmp = 0;
		for (int i = 0; i < 3; i++) {
			tmp += (a[2] - a[i]) / 2;
		}

		cout << tmp << endl;
		return 0;
	}

	int ans = INF;
	for (int i = 0; i < 3; i++) {
		for (int j = i+1; j < 3; j++) {
			int tmp = 1;
			vector<int> b;
			b = a;

			b[i]++;
			b[j]++;

			sort(b.begin(), b.end());
			bool f = true;
			for (int i = 0; i < 3; i++) {
				
				if ((b[2] % 2) != b[i] % 2) {
					f = false;
				}
				tmp += (b[2] - b[i]) / 2;

			}

			if (f) {
				ans = min(ans, tmp);
			}
			
		}
	}

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

Measured memory_bytes: 256
n, a, b = list(map(int, input().split()))

def ketawa(x):
  temp = x
  res = 0
  while temp != 0:
    res += temp % 10
    temp = temp // 10
  return res

sum = 0

for i in range(1, n+1):
  res = ketawa(i)
  if a <= res <= b:
    sum = sum + i

print(sum)

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

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

  int H, W;
  cin >> H >> W;

  auto isin = [&](PII p){
    return 0 <= p.FF && p.FF < H && 0 <= p.SS && p.SS < W;
  };

  VS vs(H);
  cin >> vs;

  LL ans = 0;
  vector<vector<bool>> vis(H, vector<bool>(W));
  REP(y,H) REP(x,W){
    if(vis[y][x]) continue;
    LL n = 0, m = 0;
    queue<PII> q;
    q.push(MP(y,x));
    while(!q.empty()){
      auto p = q.front();
      q.pop();
      
      REP(d,4){
        PII np(p.FF + dy[d], p.SS + dx[d]);
        if(!isin(np) || vis[np.FF][np.SS]) continue;
        if(vs[p.FF][p.SS] == vs[np.FF][np.SS]) continue;
        vis[np.FF][np.SS] = true;
        q.push(np);
        (vs[p.FF][p.SS] == '.' ? n : m)++;
      }
    }

    ans += n * m;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	long long int n;
	cin>>n;
	
	while(n)
	{
		if(n%10 == 7)
		{
			cout<<"Yes";
			return 0;
		}
		n=n/10;
			}
			cout<<"No";
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) {};
    void init(int n) {
        par.assign(n, -1);
    }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    int sum(int x) {
        return -par[root(x)];
    }

};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    using pint = pair<int, int>;
    using Edge = pair<ll, pint>;
    vector<Edge> edges;

    vector<int> ids(n);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) {return x[i] < x[j];});
    for (int i = 0; i + 1 < ids.size(); ++i) {
        int u = ids[i], v = ids[i + 1];
        edges.push_back(Edge(x[v] - x[u], pint(u, v)));
    }

    sort(ids.begin(), ids.end(), [&](int i, int j) {return y[i] < y[j];});
    for (int i = 0; i + 1 < ids.size(); ++i) {
        int u = ids[i], v = ids[i + 1];
        edges.push_back(Edge(y[v] - y[u], pint(u, v)));
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(n);
    ll res = 0;
    for (auto e : edges) {
        int u = e.second.first, v = e.second.second;
        ll cost = e.first;
        if (uf.issame(u, v)) continue;
        uf.unite(u, v);
        res += cost;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 8432
/*SorooshH*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
const int MAX = 1e6;
const int MV = 1e5;
const int INF = 2e9;
const int MOD = 1e9 + 7;
int MA = -INF , MI = INF , ANS;

int n;
char x;
set<char> st;

int32_t main()
{
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n;

    for(int i=0 ; i<n ; i++)
        cin >> x , st.insert(x);

    if(st.size() == 3)
        cout << "Three\n";
    else
        cout << "Four\n";
    return 0;
}


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

int main()
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  if(a[0] == 5 && a[1] == 5 && a[2] == 7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int h;
  int top[4] = {};
  int i;
  int N = 10;
  int tmp;
  while (N--) {
    scanf("%d", &top[3]);
    for (i = 2; i >= 0; i--) {
      if (top[i] > top[i+1]) {
        break;
      }
      tmp = top[i];
      top[i] = top[i+1];
      top[i+1] = tmp;
    }
  }
  for (i = 0; i < 3; i++) {
    printf("%d\n", top[i]);
  }
  return 0;
}



Measured memory_bytes: 2044
#include<stdio.h>
#include<stdlib.h>
typedef long long int ll;

int int_sort(const void* a, const void* b) {
	if (*(int*)a < *(int*)b) {
		return -1;
	}
	else
		if (*(int*)a == *(int*)b) {
			return 0;
		}
	return 1;
}
int main(void)
{
	int n;
	static ll a[300000];
	static ll teem[100000][3];
	ll sum = 0;
	int teemi = 0;

	scanf("%d", &n);
	for (int i = 0; i < 3 * n; i++) {
		scanf("%lld", &a[i]);
	}

	qsort((void*)a, 3*n, sizeof(a[0]), int_sort);

	for (int i = 0; i < n; i++) {
		teem[i][0] = a[i];
		a[i] = -1;
	}
	for (int i = n; i < 3 * n; i += 2) {
		//teem[teemi][1] = a[i];
		//teem[teemi++][2] = a[i + n];
		sum += a[i];
	}
	/*
	for (int i = 0; i < n; i++) {
		sum += teem[i][1];
	}*/
	printf("%lld\n", sum);
	/*
	for (int i = 0; i < 3 * n; i++) {
		printf("%d\n", a[i]);
	}*/
	return 0;
}

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

using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	int n;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
	cin >> n;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
      cin >> vec.at(i);
    }
    for(int i=0; i<n; i++){
      if(vec.at(i)=="AC"){
        a++;
      }
      if(vec.at(i)=="WA"){
        b++;
      }
      if(vec.at(i)=="TLE"){
        c++;
      }
      if(vec.at(i)=="RE"){
        d++;
      }
    }
  
    cout << "AC x " << a << "\n";
    cout << "WA x " << b << "\n";
    cout << "TLE x " << c << "\n";
    cout << "RE x " << d;
    
  
}

Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define nl '\n'
typedef long long ll;
//////////////////////////////////////////////////////////////////////

string s;
vector<int> pos[26];

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

  cin>>s;

  for(int i=0;i<s.length();i++){
    pos[s[i]-'a'].emplace_back(i);
  }
  
  ll reps = 0;
  for(int i=0;i<26;i++){
    reps += (pos[i].size()*1ll*pos[i].size() - pos[i].size())/2;
  }
  
  ll n = s.length();
  cout << 1+(n*n-n)/2 - reps << endl;

  return 0;
};


Measured memory_bytes: 1936
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
int main(void){
    ll h, n;
    cin >> h >> n;
    vector<vector<ll>> dp(n+1, vector<ll>(h+1, 1e+11));
    vector<p> check;
    for(ll i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        check.push_back(p(a,b));
    }
    dp[0][0] = 0;
    for(ll i = 1; i <= n; i++){
        ll f = check[i-1].first; ll s = check[i-1].second;
        for(ll j = 1; j <= h; j++){
            if(j <= f)
                dp[i][j] = min(dp[i-1][j], s);
            else
                dp[i][j] = min(dp[i-1][j], dp[i][j-f]+s);
           // cout << dp[i][j] << endl;
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007
#define rev(v) reverse(v.begin(), v.end());

bool comp(int a, int b){
    return (a<b);
}

int main(){
    int a, b, c, k;
    int sum = 0;
    cin >> a >> b >> c >> k;

    REP(i,0,k){
        if(a>0){
            sum+=1;
            a--;
        }else if(b>0){
            b--;
        }else{
            sum-=1;
            c--;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3576
//http://drken1215.hatenablog.com/entry/2019/04/27/224100_1

#include "bits/stdc++.h"
using namespace std;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

signed main() {
  	cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

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

    // 累積 GCD (左と右両方)
    vector<int> left(N+1, 0), right(N+1, 0);
    for (int i = 0; i < N; ++i) left[i+1] = GCD(left[i], a[i]);
    for (int i = N-1; i >= 0; --i) right[i] = GCD(right[i+1], a[i]);
    
    // 集計
    int res = 0;
    for (int i = 0; i < N; ++i) {
        // 左側
        int l = left[i];

        // 右側
        int r = right[i+1];

        // 更新
        chmax(res, GCD(l, r));
    }
    cout << res << endl;
}

Measured memory_bytes: 1408