akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    vector <ll> xs;
    REP(i, n){
        ll x; cin >> x;
        xs.push_back(x);
    }
    ll ans = 1e9;
    REP(i, 100){
        ll cand = 0;
        ll j = i+1;
        for(auto x: xs){
            cand += pow((x-j), 2);
        }
        ans = min(cand, ans);
    }
    cout << ans << endl;
    return 0;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, m;
  deque<pair<LL, LL>> v;
  Solver2(LL n, LL m) : n(n), m(m){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      LL a, b;
      cin >> a >> b;
      v.emplace_back(a, b);
    }
    sort(v.begin(), v.end());
    priority_queue<LL> pq;
    LL ans = 0;
    for (int i = 1; i <= m; ++i) {
      while (!v.empty() && v[0].first <= i) {
        pq.push(v[0].second);
        v.pop_front();
      }
      if (!pq.empty()) {
        ans += pq.top();
        pq.pop();
      }
    }
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


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

int main(void) {
	int n, m;
	int ans = 0;

	std::map<int, int> dict;

	cin >> n >> m;
	
	for (int i = 0; i < n; ++i) {
		int k, tmp;
		cin >> k;
		for (int j = 0; j < k; ++j) {
			cin >> tmp;
			++dict[tmp];
		}
	}

	for (const auto &d : dict) {
		if (d.second == n) {
			++ans;
		}
	}

	cout << ans;
	
	return 0;
}


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

int main(){
    using namespace std;
    unsigned long N, A1, A2, A{0};
    cin >> N >> A1 >> A2;
    unsigned long S{A1 + A2};
    for(unsigned long i{2}, a; i < N; ++i){
        cin >> a;
        A ^= a;
    }
    if((A ^ S) & 1 || A > S)return 0 & puts("-1");
    unsigned long ans{(S - A) >> 1};
    if(ans & A)return 0 & puts("-1");
    for(unsigned long i{1UL << 63}; i; i >>= 1)if((A & i) && ans + i <= A1)ans += i;
    if(!ans || ans > A1)return 0 & puts("-1");
    cout << A1 - ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

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

    int result = 0;
    for (int i=0; i<N; i++) {
        if (h[i] < h[i+1] and h[i+1] >= h[i+2]) result += h[i+1];
        if (h[i] >= h[i+1] and h[i+1] < h[i+2]) result -= h[i+1];
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
int n,m;
map<pii,int>used;
bool vis[200005]={0};
ll ans=-1;
ll cnt=0;
vi v[200005];
void dfs(int pos){
	vis[pos]=1;cnt++;
	REP(i,v[pos].size()){
		if(!vis[v[pos][i]]){
			dfs(v[pos][i]);
		}
	}
}
int main(void){
	cin>>n>>m;
	REP(i,m){
		int a,b;
		cin>>a>>b;
		if(!used[mp(a,b)]){
			used[mp(a,b)]=used[mp(b,a)]=1;
			v[a].pb(b);
			v[b].pb(a);
		}
	}
	FORN(i,1,n+1){
		if(!vis[i]){
			cnt=0;
			dfs(i);
			ans=max(ans,cnt);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 46016
h, w = map(int, input().split())
if not h%3 or not w%3:
  print(0)
else:
  ans = min([h, w])
  for i in range(h):
    sub = max([abs(w*i-w//2*(h-i)), abs(w*i-(w-w//2)*(h-i))])
    if ans > sub:
      ans = sub
  for i in range(w):
    sub = max([abs(h*i-h//2*(w-i)), abs(h*i-(h-h//2)*(w-i))])
    if ans > sub:
      ans = sub
  print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int dp[26] = {};
	int dp1[26] = {};
	int check1[26] = {};
	int check2[26] = {};
	string s1, t1;
	cin >> s1 >> t1;
	for (int i = 0; i < s1.size(); i++) {
		char a = s1[i];
		char b = t1[i];
		int anumber = s1[i] - 'a';
		int bnumber = t1[i] - 'a';
		if (check2[anumber] == 0) {
			dp1[anumber] =  bnumber;
			check2[anumber] = 1;
		}
		else {
			if (dp1[anumber] != bnumber) {
				cout << "No";
				return 0;
			}
		}
		if (check1[bnumber] == 0) {
			dp[bnumber] = anumber;
			check1[bnumber] = 1;
		}
		else {
			if (dp[bnumber] != anumber) {
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 776
#include <stdio.h>
int abs(int n){
		if(n<0){
		return -1*n;}else
		return n;}
int main(void)
{int A,B,C,x,i,a,b,l,r,g,m,tmp;
	long long int N,K,sum;
	scanf("%lld%lld",&N,&K);
	sum=0;
	if(K==0){
		printf("%lld",N*N);}
		else if(N==1)
		printf("0");
		else
			{
		for(b=K+1;b<=N;b++){
			if(N%b<=K-1)
			sum+=(b-K)*(N/b);
			else
			sum+=(b-K)*(N/b)+(N%b)-K+1;}
			printf("%lld",sum);}
			

	return 0;
}


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




typedef long long ll;
#define INF 1LL<<40
#define def INF
template<class V, int NV> struct SegTree {
    V comp(V l, V r) { return min(l, r); };
    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int l, int r) { //[l,r]
        if (l > r) return def;
        l += NV; r += NV + 1; V ret = def;
        while (l < r) { if (l & 1) ret = comp(ret, val[l++]); if (r & 1) ret = comp(ret, val[--r]); l /= 2; r /= 2; }
        return ret;
    }
    void update(int i, V v) { i += NV; val[i] = v; while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]); }
    void add(int i, V v) { update(i, val[i + NV] + v); }
};
int N, Q, A, B, X[201010];
//-----------------------------------------------------------------------------------
/*ll dp[201010][201010][201010];
ll orderN3() {
    rep(i, 0, Q + 1) rep(a, 0, N + 1) rep(b, 0, N + 1) dp[i][a][b] = INF;
    dp[0][0][0] = 0;
    rep(i, 0, Q) rep(a, 0, N + 1) rep(b, 0, N + 1) if (dp[i][a][b] != INF) {
        dp[i + 1][X[i]][b] = min(dp[i + 1][X[i]][b], dp[i][a][b] + abs(a - X[i]));
        dp[i + 1][a][X[i]] = min(dp[i + 1][a][X[i]], dp[i][a][b] + abs(b - X[i]));
    }

    ll ans = INF;
    rep(a, 0, N + 1) rep(b, 0, N + 1) ans = min(ans, dp[Q][a][b]);
    return ans;
}*/
//-----------------------------------------------------------------------------------
/*ll dp2[2][201010];
ll orderN2() {
    rep(i, 0, N + 1) dp2[0][i] = INF;
    dp2[0][A] = 0;

    rep(i, 0, Q) {
        int b;
        if (i == 0) b = B;
        else b = X[i - 1];

        // reset
        rep(a, 0, N + 1) dp2[(i + 1) % 2][a] = INF;

        // 1. b -> X[i]
        rep(a, 0, N + 1) dp2[(i + 1) % 2][a] = min(dp2[(i + 1) % 2][a], dp2[i % 2][a] + abs(b - X[i]));
        // 2. a -> X[i]
        rep(a, 0, N + 1) dp2[(i + 1) % 2][b] = min(dp2[(i + 1) % 2][b], dp2[i % 2][a] + abs(a - X[i]));
    }

    ll ans = INF;
    rep(a, 0, N + 1) ans = min(ans, dp2[Q % 2][a]);
    return ans;
}*/
//-----------------------------------------------------------------------------------
SegTree<ll, 1 << 18> dp3, dpplus, dpminus;
ll offset = 0;
ll orderNlogN() {
    dp3.update(A, 0);
    dpplus.update(A, 0+A);
    dpminus.update(A, 0-A);

    rep(i, 0, Q) {
        int b;
        if (i == 0) b = B;
        else b = X[i - 1];

        // 1. b -> X[i]
        offset += abs(X[i] - b);

        // 2. a -> X[i]
        ll mi = INF;
        mi = min(mi, dpminus.get(0, X[i]) + X[i]);
        mi = min(mi, dpplus.get(X[i], N) - X[i]);
        mi -= abs(X[i] - b);

        dp3.update(b, mi);
        dpplus.update(b, mi + b);
        dpminus.update(b, mi - b);
    }

    ll ans = dp3.get(0, N) + offset;
    return ans;
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N >> Q >> A >> B;
    rep(i, 0, Q) scanf("%d", &X[i]);

    cout << orderNlogN() << endl;
}

Measured memory_bytes: 15360
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll x,y; cin >> x >> y;
  
  if(gcd(x,y) == y) cout << -1 << endl;
  else{
    for(ll i=1; i < 100000000; i++){
      if((x*i) % y != 0){
        cout << x*i << endl;
        return 0;
      }
    }
    
  }
  
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
ll l[200005],r[200005];
int main()
{
    ll n,k,c,cntl=-INF,cntr=-INF,ans=0;
    string s;
    cin>>n>>k>>c>>s;
    l[0]=0,r[0]=0;
    rep1(i,n)
    {
        if(s[i-1]=='o'&&cntl+c<i)
        {
            cntl=i;
            l[i]=l[i-1]+1;
        }
        else l[i]=l[i-1];
        //cout<<l[i]<<" ";
    }
    //cout<<"\n";
    rep1(i,n)
    {
        if(s[n-i]=='o'&&cntr+c<i)
        {
            cntr=i;
            r[i]=r[i-1]+1;
        }
        else r[i]=r[i-1];
        //cout<<r[i]<<" ";
    }
    rep1(i,n)
    {
        if(l[i-1]+r[n-i]<k) cout<<i<<"\n";
    }
}


Measured memory_bytes: 4996
#include <cstdio>
#include <iostream>
using namespace std;
const int Q=1<<17;
int s[Q],n,maxn;
int Ch(int x,int l,int r)
{return max(l,min(r,x));}
int main()
{
	scanf("%d%d",&maxn,&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&s[i]);
	int p=1,l=0,r=maxn;
	int qaq,t,a,ty=-1,del=0;
	for(scanf("%d",&qaq);qaq;--qaq){
		scanf("%d%d",&t,&a);
		while(p<=n&&s[p]<=t){
			int val=ty*(s[p]-s[p-1]);
			l=Ch(l+val,0,maxn);
			r=Ch(r+val,0,maxn);
			del+=val;
			ty=-ty;
			++p;
		}
		printf("%d\n",Ch(Ch(a+del,l,r)+ty*(t-s[p-1]),0,maxn));
	}
	return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<string> s(n);
    for (int i=0; i<n; i++) {
        cin >> s.at(i);
    }
    ll m = 0, a = 0, r = 0, c = 0, h = 0;
    for (string name : s) {
        char start = name.at(0);
        if (start == 'M') {
            m++;
        }
        else if (start == 'A') {
            a++;
        }
        else if (start == 'R') {
            r++;
        }
        else if (start == 'C') {
            c++;
        }
        else if (start == 'H') {
            h++;
        }
    }
    cout << m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h << endl;
    return 0;
}


Measured memory_bytes: 6144
#include <cstdio>
#include <unordered_map>
#define N 100
#define INF 0x7FFFFFFF

void solve(std::unordered_map<int, int> a[N], const int n){
    std::unordered_map<int, int> result;
    result.insert(std::make_pair(0, 0));
    while(result.size() != n){
        std::pair<int, int> newV;
        newV.first = INF;
        newV.second = INF;
        for(auto &x: result){
            for(auto &y: a[x.first]){
                int w = y.second + x.second;
                if(result.find(y.first) == result.end() && newV.second > w){
                    newV.first = y.first;
                    newV.second = w;
                }
            }
        }
        result.insert(newV);
    }
    for(int i = 0; i < n; ++i){
        std::printf("%d %d\n", i, result.find(i)->second);
    }
}

int main(){
    int n;
    std::scanf("%d", &n);
    std::unordered_map<int, int> a[N];
    for(int i = 0; i < n; ++i){
        int id;
        std::scanf("%d", &id);
        int num;
        std::scanf("%d", &num);
        for(int j = 0; j < num; ++j){
            std::pair<int, int> v;
            std::scanf("%d", &v.first);
            std::scanf("%d", &v.second);
            a[i].insert(v);
        }
    }
    solve(a, n);
    return 0;
}



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

int main()
{
 	string str;
  cin >> str;
  rep(i, str.length()) {
    if(i % 2 == 0 && str[i] == 'L') {
      cout << "No" << endl;
      return 0;
    }
    if(i % 2 == 1 && str[i] == 'R') {
      cout << "No" << endl;
      return 0;
    }    
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
num = [-1 for _ in range(n + 1)]
for _ in range(m):
    s, c = map(int, input().split())
    if num[s] == -1 or num[s] == c:
        num[s] = c
    else:
        print('-1')
        exit()
if num[1] == -1 and n > 1:
    num [1] = 1
ans = ''
for i in num:
    if i == -1:
        ans += '0'
    else:
        ans += str(i)
print(int(ans) if len(str(int(ans))) == n else '-1')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)
// #define int long long
#define debug(var) cout << "[" << #var << "] " << var << endl
//using ll = long long;

const int INF = 1<<29;
const double EPS=1e-9;
const int MOD=998244353;

signed main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int min = (h2 - h1) * 60 + (m2 - m1);
    cout << min - k << endl;
}



Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
int main(){
	int n,i,j,f[105][105],w,h,x,y,gf;
	char m[105][105];
	while(1){
		scanf("%d%d",&h,&w);
		if(w==0 && h==0)break;
		x=y=gf=0;memset(f,0,sizeof(f));
		for(i=0;i<h;i++)scanf("%s",m[i]);
		while(gf==0){
			f[y][x]=1;
			if(m[y][x]=='>'){
				x++;
				if(f[y][x]==1)gf=1;
			}else if(m[y][x]=='v'){
				y++;
				if(f[y][x]==1)gf=1;
			}else if(m[y][x]=='<'){
				x--;
				if(f[y][x]==1)gf=1;
			}else if(m[y][x]=='^'){
				y--;
				if(f[y][x]==1)gf=1;
			}else if(m[y][x]=='.')gf=2;
		}
		if(gf==1)printf("LOOP\n");
		else printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

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

int main(void) {

    ios::sync_with_stdio(false); cin.tie(0);

   int h, w;
   cin >> h >> w;
   VV<char> grid(h, V<char>(w));
   rep (i, h) rep (j, w) cin >> grid[i][j];

   rep (i, h) rep (j, w) {
       if (grid[i][j] == '.') continue;
       bool ok = false;
       rep (k, 4) {
           int x = j + dx[k];
           int y = i + dy[k];
           
           if (x < 0 || x >= w || y < 0 || y >= h) continue;
           if (grid[y][x] == '#') ok = true;
        }
        if (!ok) {
            cout << "No" << endl;
            return 0;
        }
   }
    cout << "Yes" << endl;
    return 0;
}


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

int main(){
    int N;
    string S;
    cin>>N>>S;
    int ans = 0;
    for(int i=0;i<S.size()-2;i++){
        if(S[i]!='A') continue;
        if(S[i+1]!='B') continue;
        if(S[i+2]!='C') continue;
        ans++;
    }
    cout<<ans<<endl;
}


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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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




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


const int MOD = 1000000007;

//////////////////////////////////////////


int n;
void Input() {

    cin >> n;

}



void Solve() {

    vector<int> arr(n);
    vector<int> com_sum(n);

    cin >> arr[0];

    com_sum[0] = arr[0];

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

        cin >> arr[i];
        com_sum[i] = com_sum[i-1] + arr[i];
    }

    int ans = INF;
    int lim = com_sum[n-1];
    for(int i = 0; i < n; i++) {

        int left = com_sum[i];
        int right = abs(left - lim);

        ans = min(ans, abs(left-right));
    }

    cout << ans << endl;


}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



Measured memory_bytes: 256
#include<stdio.h>
int main() {
	char S[] = "aaa";
	int i, k = 0;

	scanf("%s", &S);

	for (i = 0; i < 3; i++) {
		if (S[i] == 'o') {
			k++;
		}
	}

	i = 700 + k * 100;
	printf("%d\n", i);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef long long ll;

int const N=1e6+5, M=1e3+5, MOD=1e9+7;
ll const OO=0x3f3f3f3f3f3f3f3f;

ll n,m,k,sx,sy,ex,ey;
string grid[N];
vector<vector<ll>>dis;
vector<vector<bool>>vis;

int dr[]={0,0,-1,1};
int dc[]={-1,1,0,0};

bool valid(int r, int c)
{
    return r>=0 && r<n && c>=0 && c<m && grid[r][c]=='.';
}

void BFS()
{
    ll ur,uc,vr,vc,c;
    queue<pair<int,int>>q;
    dis[sx-1][sy-1]=0;
    q.push({sx-1,sy-1});
    vis[sx-1][sy-1]=1;
    while(!q.empty())
    {
        ur=q.front().first;
        uc=q.front().second;
        q.pop();
        if(ur==ex-1 && uc==ey-1)
            break;
        for(int i=0; i<4; i++)
        {
            vr=ur;
            vc=uc;
            for(int j=0; j<k; j++)
            {
                vr+=dr[i];
                vc+=dc[i];
                if(valid(vr,vc))
                {
                    if(!vis[vr][vc])
                    {
                        vis[vr][vc]=1;
                        dis[vr][vc]=dis[ur][uc]+1;
                        q.push({vr,vc});
                    }
                    else if(dis[vr][vc]>=dis[ur][uc]+1)
                        dis[vr][vc]=dis[ur][uc]+1;
                    else
                        break;
                }
                else
                    break;

            }
        }
    }
}

int main()
{
    FIO
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);
    cin>>n>>m>>k>>sx>>sy>>ex>>ey;
    for(int i=0; i<n; i++)
        cin>>grid[i];
    dis=vector<vector<ll>>(n+5,vector<ll>(m+5,OO));
    vis=vector<vector<bool>>(n+5,vector<bool>(m+5,0));
    BFS();
    if(dis[ex-1][ey-1]==OO)
        cout<<"-1\n";
    else
        cout<<dis[ex-1][ey-1]<<"\n";
    return 0;
}


Measured memory_bytes: 90404
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

typedef long long llong;
using namespace std;

int main() {
	int x, y;

	cin >> x >> y;
	cout << x + y / 2 << endl;
	

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
  ll a,b;
  cin >> a >> b;
  if(a+b<10){
    cout << a+b << endl;
  }else{
    cout << "error" << endl;
  }
}

Measured memory_bytes: 3596
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n := io.NextInt()
	for k := 1; k <= n; k++ {
		maxIter := int(math.Sqrt(float64(k)))
		count := 0
		for x := 1; x <= maxIter; x++ {
			for y := 1; y <= maxIter; y++ {
				z := sort.Search(maxIter, func(z int) bool { return g(x, y, z) >= k })
				if z != 0 && g(x, y, z) == k {
					count++
				}
			}
		}
		io.Println(count)
	}
}

func g(x, y, z int) int {
	return (x+y+z)*(x+y+z) - x*y - y*z - z*x
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

int main(void) {
    int64_t n,a,mina;
    int64_t times;
    cin >> n;

    mina = LONG_MAX;
    for(int i=0;i<5;i++) {
        cin >> a;
        if(mina > a) {
            mina = a;
        }
    }

    if(n%mina) {
        times = (n/mina) + 1;
    } else {
        times = n/mina;
    }

    times += 4;
    cout << times << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  long a,b;
  scanf("%ld %ld",&a,&b);
  if((a+b)%2 == 0){
    printf("%ld\n",(a+b)/2);
  }else{
    printf("IMPOSSIBLE\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string str;

int main() {
    while (cin >> str) {
        bool aru[30];
        memset(aru, 0, sizeof(aru));
        for (int i = 0; i < str.size(); ++i) aru[ (int)(str[i] - 'a') ] = true;
        int res = 0;
        for (res = 0; res < 26; ++res) if (!aru[res]) break;
        if (res < 26) cout << (char)('a' + res) << endl;
        else cout << "None" << endl;
    }
}





Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 1e5+10;

struct edge
{
    int to;
    ll len;
} ng1,ng2;

using namespace std;

vector<edge> Graph[N];
ll depth[N];

void dfs (int v, int p, ll d)
{
    depth[v]=d;
    for (auto e: Graph[v])
    {
        if (e.to==p)
            continue;
        dfs(e.to,v,d+e.len);
    }
}

main()
{
    fast;
    int n,a,b,q,k,i;
    ll c;
    cin>>n;
    for (i=0;i<n-1;i++)
    {
        cin>>a>>b>>c;
        //struct edge ng1,ng2;
        ng1.to=b;
        ng2.to=a;
        ng1.len=c;
        ng2.len=c;
        Graph[a].pb(ng1);
        Graph[b].pb(ng2);
    }
    cin>>q>>k;
    dfs(k,-1,0);
    int x,y;
    while (q--)
    {
        cin>>x>>y;
        cout<<depth[x]+depth[y]<<endl;
    }
}

Measured memory_bytes: 14336
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    int ans = 0;
    rep(i, (N + 1) / 2) if (S[i] != S[N - 1 - i]) ans++;
    write(ans);
}

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

int main(){
	int h, w, n;
	while(scanf("%d%d%d", &h, &w, &n), h){
		vector<vector<int> > a(h, vector<int>(w));
		vector<vector<int> > c(h + 1, vector<int>(w + 1));
		for(int i = 0; i < h; ++i)
		for(int j = 0; j < w; ++j){
			scanf("%d", &a[i][j]);
		}
		c[0][0] = n - 1;
		for(int i = 0; i < h; ++i)
		for(int j = 0; j < w; ++j){
			int s = c[i][j];
			int ch = s >> 1;
			if(s & 1){
				if(!a[i][j]){
					ch = (s + 1) >> 1;
				}
				a[i][j] = !a[i][j];
			}
			c[i + 1][j] += ch;
			c[i][j + 1] += s - ch;
		}

		int y = 0, x = 0;
		while(y < h && x < w){
			if(a[y][x]){ ++x; }
			else{ ++y; }
		}
		printf("%d %d\n", y + 1, x + 1);
	}
}

Measured memory_bytes: 8824
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

const int N = 100100;
struct Node{
	int id, num;
}a[N], b[N];
bool cmp(Node x, Node y){
	return x.num > y.num;
}
int n, x;
int main(){
	read(n);
	n /= 2;
	for (int i = 1; i <= n; i++){
		read(x); a[x].num++;
		read(x); b[x].num++;
	}
	for (int i = 1; i < N; i++)
		a[i].id = b[i].id = i;
	sort(a + 1, a + N, cmp);
	sort(b + 1, b + N, cmp);
	int tmp = 0;
	if (a[1].id == b[1].id)
		tmp = max(a[1].num + b[2].num, a[2].num + b[1].num);
		else tmp = a[1].num + b[1].num;
	printf("%d\n", n * 2 - tmp);
	return 0;
}



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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K & 1) {
    ll nA = B + C;
    ll nB = A + C;
    if (abs(nA - nB) > 1e18) {
      cout << "Unfair" << endl;
      return;
    }
    cout << nA - nB << endl;
  } else {
    cout << A - B << endl;
  }
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

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

typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int>d(n);
    vector<vector<int> > p(n,vector<int>(20,-1));
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int m;
            cin >> m;
            p[m][0] = i;
            d[m] = d[i]+1;
        }
    }
    for(int i=1;i<20;i++){
        for(int j=0;j<n;j++){
            if(p[j][i-1]!=-1)p[j][i] = p[p[j][i-1]][i-1];
        }
    }
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int u,v;
        cin >> u >> v;
        if(d[u]<d[v]){
            swap(u,v);
        }
        int k = d[u]-d[v];
        int cnt = 0;
        while(k>0){
            if(k%2!=0){
                u = p[u][cnt];
            }
            cnt++;
            k/=2;
        }
        if(u==v){
            cout << u << "\n";
        }else{
            for(int s = 19;s>=0;s--){
                if(p[u][s]!=p[v][s]){
                    u = p[u][s];
                    v = p[v][s];
                }
            }
            cout << p[u][0] << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 15032
#include <bits/stdc++.h>
using namespace std;
char a1,b1,c1,d1;
int ans,a,b,c,d;
int main()
{
	cin>>a1>>b1>>c1>>d1;
	a=a1-'0';b=b1-'0';c=c1-'0';d=d1-'0';
	for(char i='+';i<='-';i++)
	    for(char j='+';j<='-';j++)
	        for(char k='+';k<='-';k++)
	        {
	            ans=a;
	            if(i=='+') ans+=b;
	            else if(i=='-') ans-=b;
	            if(j=='+') ans+=c;
	            else if(j=='-') ans-=c;
	            if(k=='+') ans+=d;
	            else if(k=='-') ans-=d;
	            if(ans==7)
	            {
	                cout<<a<<i<<b<<j<<c<<k<<d<<"="<<ans<<"\n";
	                return 0;
	            }
	        }
}

Measured memory_bytes: 256
S = list(input())
S_uniq = list(set(S))

a_z_list = list('abcdefghijklmnopqrstuvwxyz')
not_holding_sorted = sorted(list(set(a_z_list) - set(S)))

if len(not_holding_sorted) == 0:
    ans = 'None'
else:
    ans = not_holding_sorted[0]
    
print(ans)

Measured memory_bytes: 3956
N = int(input())
A = [int(s) for s in input().split()]
inc_flag = 0
dec_flag = 0
ans = 1
for i in range(N-1):
    if  A[i] < A[i+1]:
        if dec_flag == 1:
            ans += 1
            inc_flag = 0
            dec_flag = 0
        else:
            inc_flag = 1
    elif A[i] > A[i+1]:
        if inc_flag == 1:
            ans += 1
            inc_flag = 0
            dec_flag = 0
        else:
            dec_flag = 1
print(ans)

Measured memory_bytes: 14252
# -*- coding: utf-8 -*-
N = int(input())
p = list(map(int, str(input()).split()))

# 昇順のリストと比較し、２箇所以上異なっていたらソート不可能
# ２箇所ないし０箇所であればYESを出力する

target_list = [i for i in range(1,N+1)]

count = 0
for i in range(N):
    if target_list[i] != p[i]:
        count += 1

if count == 2 or count == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<stdio.h>
int min(int a, int b)
{
	if (a < b)
		return a;
	else
		return b;
}
int main()
{
	int h, w;
	scanf("%d %d", &h, &w);
	int i, j;
	char a[1003][1003];
	for (i = 0; i < h; i++)
		scanf("%s", a[i]);
	int v[1003][1003];
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			v[i][j] = 100000000;
	int b;
	for (i = 0; i < h; i++)
	{
		b = -1;
		for (j = 0; j < w; j++)
		{
			if (a[i][j] == '#')
			{
				b = j;
				v[i][j] = 0;
			}
			else
			{
				if (b >= 0)
					v[i][j] = min(v[i][j], j - b);
			}
		}
		b = -1;
		for (j = w - 1; j >= 0; j--)
		{
			if (a[i][j] == '#')
			{
				b = j;
				v[i][j] = 0;
			}
			else
			{
				if (b >= 0)
					v[i][j] = min(v[i][j], b - j);
			}
		}
	}
	for (j = 0; j < w; j++)
	{
		b = -1;
		for (i = 0; i < h; i++)
		{
			if (a[i][j] == '#')
			{
				b = i;
				v[i][j] = 0;
			}
			else
			{
				if (b >= 0)
					v[i][j] = min(v[i][j], i - b);
			}
		}
		b = -1;
		for (i = h - 1; i >= 0; i--)
		{
			if (a[i][j] == '#')
			{
				b = i;
				v[i][j] = 0;
			}
			else
			{
				if (b >= 0)
					v[i][j] = min(v[i][j], b - i);
			}
		}
	}
	for (i = 0; i < h; i++)
	{
		for (j = 1; j < w; j++)
			v[i][j] = min(v[i][j], v[i][j - 1] + 1);
		for (j = w - 2; j >= 0; j--)
			v[i][j] = min(v[i][j], v[i][j + 1] + 1);
	}
	for (j = 0; j < w; j++)
	{
		for (i = 1; i < h; i++)
			v[i][j] = min(v[i][j], v[i - 1][j] + 1);
		for (i = h - 2; i >= 0; i--)
			v[i][j] = min(v[i][j], v[i + 1][j] + 1);
	}
	int ans = 0;
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			if (ans < v[i][j])
				ans = v[i][j];
	printf("%d\n", ans);
	return 0;
}

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

int main(){
  long long yc[10000]={};
  int n;
  cin>>n;

  for(int i=2; i<=n; i++){
    int j=i;
    while(j!=1){
      int cnt=2;
      while(j>=cnt){
	//cout<<j<<" "<<cnt<<endl;
	if(j%cnt==0){
	  yc[cnt]++;
	  j /= cnt;
	  break;
	}
	cnt++;
      }
      //cout<<j<<" "<<cnt<<endl;
    }
  }
  unsigned long long  yakuko=1;
  for(int i=1; i<=n; i++){
    //cout<<i<<" "<<yc[i]<<endl;
    if(yc[i])yakuko*=yc[i]+1;
    yakuko %= 1000000007;
  }
  cout<<yakuko<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 2005
#define INF 1000000005
#define INFLL 4000000000000000003
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<int>>s(h,vector<int>(w));
    REP(i,h){
        REP(j,w){
            char c;
            cin>>c;
            s[i][j]=c-'0';
        }
    }
    int ans=INF;
    for(int bits=0;bits<(1<<h-1);bits++){
        vector<int> S;
        REP(i,h-1){
            if(bits & (1<<i)){
                S.push_back(i);
            }
        }
        vector<int>T(SZ(S)+1);
        int cnt=SZ(S);
        bool f=true;
        REP(j,w){
            
            vector<int>tmp(SZ(S)+1);
            int p=0;
            REP(i,h){
                if(s[i][j]==1)tmp[p]++;
                if(SZ(S)!=0&&SZ(S)!=p&&i==S[p])p++;
            }
            bool r=true;
            REP(i,SZ(tmp)){
                if(tmp[i]>k){
                    f=false;
                    break;
                }
                if(!r)continue;
                    if(tmp[i]+T[i]>k){
                    cnt++;
                    r=false;
                }else{
                    T[i]+=tmp[i];
                }
            }
            if(!r)REP(i,SZ(tmp))T[i]=tmp[i];
            if(!f){
                cnt=INF;
                break;
            }
        }
        ans=min(ans,cnt);
    }
    OUT(ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a[100][100],b[100][100];
    int i, j, k, n, m, l;
    long int c[100][100]={0};
    scanf("%d %d %d", &n, &m, &l);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(j=0;j<m;j++){
        for(k=0;k<l;k++){
            scanf("%d",&b[j][k]);
        }
    }
    for(i=0;i<n;i++){
        for(k=0;k<l;k++){
            for(j=0;j<m;j++){
                c[i][k]+=a[i][j]*b[j][k];
            }
        }
    }
    for(i=0;i<n;i++){
        for(k=0;k<l;k++){
            printf("%ld",c[i][k]);
            if(k!=l-1){
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 768
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use std::collections::HashSet;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let a: usize = read!();
    let b: usize = read!();
    let k: usize = read!();

    let mut hs = HashSet::new();

    for i in a..(a + k).min(b+1) {
        hs.insert(i);
    }

    for i in (b.wrapping_sub(k) + 1).max(a)..=b {
        hs.insert(i);
    }

    let hs = hs.iter().sorted().collect_vec();

    for v in hs {
        println!("{}", v);
    }
}


Measured memory_bytes: 2160
#include <iostream>

using namespace std;

int main()
{
    int n = 5;
    int * nums = (int*)malloc(n*sizeof(int));
    for (int i = 0; i < n; i ++)
    {
        cin >> nums[i];
        if (nums[i] == 0) cout << i + 1;
    }
}

Measured memory_bytes: 3524
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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;
}

const long long INF = 1LL << 60;

int N;
long long W, w[110], v[110];
long long dp[110][100100] = {0};

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

    // DP loop
    for (int i = 0; i < N; i++){
        for(int sum_w = 0; sum_w <= W; sum_w++){

            // i番目の品物を選ぶ場合
            // i番目のwがsum_wよりも大きくなければ選べます
            if (sum_w - w[i] >= 0){
                chmax (dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i]);
            }

            // i番目の品物を選ばない場合
            // 初期値0なので，大きいものには更新されるよ
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
            // さっきの総利得と同じ
        }
    }
    cout << dp[N][W] << endl;
}








Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N, M,suma=0,a;
cin>> N >> M;
for (int i = 0; i<M;) {
    cin >> a;
    suma = suma+a;
    ++i;
}
if (N- suma>=0){cout << N- suma;}
else {cout << -1;}

}


Measured memory_bytes: 3632
s_dash = gets.chomp.chars
t = gets.chomp.chars

n = s_dash.length
m = t.length

# ずらしていって一致する部分を見つける
# 一致したらそれ+?を0埋めの文字をansに入れる
# ansを昇順にして一番最初のもの
ans = []

(n - m + 1).times do |i|
  tmp = s_dash[i,m]

  flag = true
  m.times do |j|
    next if tmp[j] == '?'
    flag = false if tmp[j] != t[j]
  end

  if flag
    char = ''
    char += s_dash[0..i-1].join.gsub('?', 'a') if i > 0
    char += t.join
    char += s_dash[i+m..n-1].join.gsub('?', 'a') if i+m < n
    ans << char
  end
end

puts ans.empty? ? 'UNRESTORABLE' : ans.sort[0]


Measured memory_bytes: 1788
temp = input().rstrip().split(" ")
N = int(temp[0])
M = int(temp[1])
list = [0] * N
for i in range(M):
    temp = input().rstrip().split(" ")
    a = int(temp[0])
    b = int(temp[1])
    list[a-1] += 1
    list[b-1] += 1
for answer in list:
    print(answer)

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

using namespace std;

int trains[501][501];

int main() {
  int n, m, q;
  scanf("%d %d %d", &n, &m, &q);

  int l, r;
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &l, &r);
    trains[--l][--r]++;
  }

  for (int i = 0; i < n; ++i) {
    for (int j = n - 1; 0 < j; --j) {
      trains[j - 1][i] += trains[j][i];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= n; ++j) {
      trains[i][j] += trains[i][j - 1];
    }
  }

  int p, t;
  for (int i = 0; i < q; ++i) {
    scanf("%d %d", &p, &t);
    printf("%d\n", trains[--p][--t]);
  }
}


Measured memory_bytes: 1920
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <bits/stdc++.h>

#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define mod 1000000007
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define FOR(i, x, y) for (int i = x; i <= y; i++)
//#define tr(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

//using namespace __gnu_pbds;

using namespace std;

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

int n, j, ans;

int v[100005];
int Q[100005];

int main()
{
	scanf("%d", &n);
	
	FOR (i, 1, n)
		scanf("%d", &v[i]), Q[v[i]]++;
	
	FOR (i, 1, 100000) {
		while (Q[i] > 3)
			Q[i] -= 2;
		
		ans+=Q[i]!=0;
	}
	
	FOR (i, 1, 100000)
		if (Q[i] == 2)
			j++;
	
	if (j&1)
		printf("%d", ans-1);
	else
		printf("%d", ans);
}


Measured memory_bytes: 1024
#import <Foundation/Foundation.h>
typedef struct Pair {
	int index;
	int value;
} Pair;
int compare(const void *a, const void *b){
	return (int)(((Pair*)a)->value-((Pair*)b)->value);
}

int main() {
	int n;
	scanf("%d",&n);
	Pair *A = (Pair*)malloc(sizeof(Pair)*n);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		Pair x = {.index = i+1, .value = a};
		A[i] = x;
	}
	qsort(A, n, sizeof(Pair), compare);
	for(int i=0;i<n;i++){
		printf("%d",A[i].index);
		if(i<n-1) printf(" ");
	}
}

Measured memory_bytes: 7508
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        double[] exp = new double[1001];
        double sum = 0;
        for (int i = 1; i <= 1000; i++) {
            sum += i;
            exp[i] = sum / i;
        }
        double ans = 0;
        for (int i = 0; i < k; i++) {
            ans += exp[p[i]];
        }
        double expsum = ans;
        for (int i = 1; i < n - k + 1; i++) {
            expsum -= exp[p[i - 1]];
            expsum += exp[p[i + k - 1]];
            ans = Math.max(expsum, ans);
        }
        System.out.println(ans);
    }

}


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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define fWrite          freopen ("out.txt","w",stdout);
#define TC              int t;cin >> t;FOR(tc,1,t)
#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

#define Make(x,p)       (x  (1<<p))
#define DeMake(x,p)     (x & ~(1<<p))
#define Check(x,p)      (x & (1<<p))
#define popcount(x)     __builtin_popcount(x)

vector<int>V[2005];
bool vis[2005];
int dis[2005];

void bfs(int s)
{
    MEM(vis,0);
    MEM(dis,0);
    vis[s]=1;
    queue<int>Q;
    Q.push(s);
    while(!Q.empty())
    {
        int x=Q.front();
        Q.pop();
        REP(i,V[x].size())
        {
            if(!vis[V[x][i]])
            {
                vis[V[x][i]]=1;
                dis[V[x][i]]=dis[x]+1;
                Q.push(V[x][i]);
            }
        }
    }
    return;
}

int main()
{
    Fast
    int n,x,y;
    cin >> n >> x >> y;
    FOR(i,1,n-1)
    {
        V[i].pb(i+1);
        V[i+1].pb(i);
    }
    V[x].pb(y);
    V[y].pb(x);
    int arr[n+5]= {0};
    FOR(i,1,n)
    {
        bfs(i);
        FOR(i,1,n) arr[dis[i]]++;
    }
    FOR(i,1,n-1) cout << arr[i]/2 << '\n';
}


Measured memory_bytes: 384