akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
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 SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve(long long K){
    cout<<(K/2) * (K-(K/2))<<endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


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

if m == 0:
    print(0)
    exit()

ans = 0
for i in range(1<<3):
    x = [w[0] if i&1 > 0 else -w[0] for w in xyz]
    y = [w[1] if i&2 > 0 else -w[1] for w in xyz]
    z = [w[2] if i&4 > 0 else -w[2] for w in xyz]
    sums = [xx+yy+zz for xx, yy, zz in zip(x, y, z)]
    sums = sorted(sums, reverse = True)
    ans = max(ans, sum(sums[:m]))
print(ans)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    int ans = inf;
    for(int i = -100; i <= 100; i++) {
        int nans = 0;
        rep(j,n) {
            nans += (a[j]-i)*(a[j]-i);
        }
        chmin(ans,nans);
    }
    cout << ans << endl;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" ";
#define LOGE if(DEBUG)cout<<endl;

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


lli ans[200][200];

void func(long long H, long long W, long long N, std::vector<long long> a){

    lli now=0;
    for(lli i=0;i<H;i++){
        for(lli j=(i%2==0?0:W-1); j>=0 && j<W; j+=(i%2==0?1:-1)){
            if(a[now]==0)now++;
            ans[i][j]=now+1;
            a[now]--;
        }
    }
    REP(i,0,H){
        REP(j,0,W){
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }

}

int main(){
    // cout << fixed << setprecision(5);

    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    func(H, W, N, std::move(a));
    return 0;
}


Measured memory_bytes: 512
a = int(input())
b = int(input())
c = int(input())
x = int(input())


count = 0
for i in range(a+1):
	for j in range(b+1):
		for k in range(c+1):
			#if (str(i) + " " + str(j) + " " + str(k)) == x:
			if 500*(i) + 100*(j) + 50*(k) == x:
				count += 1
				
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=998244353, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
   
    // [1, n]
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    // a is 1-indexed]
    inline void add(int a, Abel x) {a++;
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    // [1, a], a is 1-indexed
    inline Abel sum(int a) {a++;
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
};

ll calc(ll a,ll b,ll c,ll d,ll n){
	a = modpow(2LL,a);
	d = modpow(2LL,d);
	a += d - 1;
	b = modpow(2LL,b);
	c = modpow(2LL,c);
	b += c - 1;
	a %= mod;
	b %= mod;
	a *= b;
	a %= mod;
	ll ret = modpow(2LL,n) - a;
	ret %= mod;
	ret += mod;
	ret %= mod;
	return ret;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<pair<ll,ll> > v(n);
    for(int i=0;i<n;i++){
    	cin >> v[i].first >> v[i].second;
    }
    {
    	map<ll,ll> mp;
    	for(int i=0;i<n;i++){
    		mp[v[i].first] = 0;
    	}
    	int idx = 0;
    	for(auto& i:mp){
    		i.second = idx++; 
    	}
    	for(int i=0;i<n;i++){
    		v[i].first = mp[v[i].first];
    	}
    }
    {
    	map<ll,ll> mp;
    	for(int i=0;i<n;i++){
    		mp[v[i].second] = 0;
    	}
    	int idx = 0;
    	for(auto& i:mp){
    		i.second = idx++; 
    	}
    	for(int i=0;i<n;i++){
    		v[i].second = mp[v[i].second];
    	}
    }
    sort(be(v));
    vector<ll> a(n),b(n),c(n),d(n);
    {
    	BIT<ll> bit(n);
    	for(int i=0;i<n;i++){
    		a[i] = bit.sum(v[i].second);
    		b[i] = i - a[i];
    		bit.add(v[i].second,1);
    	}
    }
    {
    	BIT<ll> bit(n);
    	for(int i=n-1;i>=0;i--){
    		c[i] = bit.sum(v[i].second);
    		d[i] = n - 1 - i - c[i];
    		bit.add(v[i].second,1);
    	}
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
    	(ans += calc(a[i],b[i],c[i],d[i],n))%=mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int power(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 1e5 + 10;
pair<int, int> tosort[maxn];

int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    tosort[i] = mp(x, y);
  }
  return 1;
}

void solve() {
  if (tosort[0].first || tosort[1].second) {
    printf("-1\n");
    return;
  }
  map<pair<int, int>, int> cnt;
  for (int i = 0; i < n; ++i) {
    int x = tosort[i].first;
    int y = tosort[i].second;
    if (i != 0 && !x) {
      printf("-1\n");
      return;
    }
    if (i != 1 && !y) {
      printf("-1\n");
      return;
    }
    cnt[{x, y}] += 1;
    tosort[i] = {x + y, y};
  }
  sort(tosort, tosort + n);

  int res = 2 * n - 2;
  for (int i = 0; i < n;) {
    int i0 = i;
    while (i < n && tosort[i].first == tosort[i0].first) {
      int x = tosort[i].first, y = tosort[i].second;
      x -= y;

      for (int iter = 0; iter < 2; ++iter) {
        auto &cur = (!iter ? x : y);
        if (!cur) {
          continue;
        }
        auto &cury = (iter ? x : y);
        --cur;
        bool ok = 0;
        for (int dx = -1; dx <= 1; ++dx) {
          cury += dx;
          if (cnt.count({x, y})) {
            ok = 1;
          }
          cury -= dx;
        }
        ++cur;
        if (!ok) {
          printf("-1\n");
          return;
        }
      }
      ++i;
    }

    int last = 0, left = 0;
    for (int j = i0; j < i;) {
      int j0 = j;
      while (j < i && tosort[j].second == tosort[j0].second) {
        ++j;
      }
      int now = j - j0;

      int del = 0;
      if (last + 1 == tosort[j0].second) {
        del = min(now, left);
        res -= del;
      }
      if (cnt.count({tosort[j0].first - tosort[j0].second - 1, tosort[j0].second - 1})) {
        res -= now - del;
        now = del;
      }
      left = now;
      last = tosort[j0].second;
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int M = 1000000007;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < k; ++i)
  {
    ans += a[i];
  }
  cout << ans;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	ll h;
	cin >> h;
	ll m = 1, res = 0;
	while (h > 0) {
	  res += m;
	  m *= 2;
	  h /= 2;
	}
	cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
static const int INF = 1e9;

void solve()
{
	int d;
	while (cin >> d, d)
	{
		int n, m;
		cin >> n >> m;
		vector<int> dist(n);
		dist[0] = 0;
		for (int i = 1; i < n; ++i)
		{
			cin >> dist[i];
		}
		dist.push_back(d);
		vector<int> k(m);
		for (int i = 0; i < m; ++i)
		{
			cin >> k[i];
		}
		sort(dist.begin(), dist.end());
		int sum = 0;
		for (int i = 0; i < m; ++i)
		{
			int l = 0;
			int r = dist.size();
			int minv = INF;
			while (l < r)
			{
				int mid = (l + r) / 2;
				if (dist[mid] < k[i])
				{
					minv = min(minv, k[i] - dist[mid]);
					l = mid + 1;
				}
				else
				{
					minv = min(minv, dist[mid] - k[i]);
					r = mid;
				}
			}
			sum += minv;
		}
		cout << sum << endl;
	}
}

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

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+7;
typedef long long LL;
typedef pair< LL , LL >PLL;

vector< PLL >preOptions[MAXN];
vector< PLL >sufOptions[MAXN];
LL a[MAXN];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    LL total = a[1];
    LL bam = a[1];
    for (int i = 2, j = 1; i <= n; i++) {
        total += a[i];
        while (j+1 < i && bam+a[j+1] <= total-(bam+a[j+1])) {
            j++;
            bam += a[j];
        }
        preOptions[i].emplace_back(bam, total-bam);
        if (j+1 < i) {
            preOptions[i].emplace_back(bam+a[j+1], total-bam-a[j+1]);
        }
    }

    total = a[n];
    LL dan = a[n];
    for (int i = n-1, j = n; i > 0; i--) {
        total += a[i];
        while (j-1 > i && dan+a[j-1] <= total-(dan+a[j-1])) {
            j--;
            dan += a[j];
        }
        sufOptions[i].emplace_back(dan, total-dan);
        if (j-1 > i) {
            sufOptions[i].emplace_back(dan+a[j-1], total-dan-a[j-1]);
        }
    }

    LL ans = 1e18;
    for (int i = 2; i+2 <= n; i++) {
        for (PLL p : preOptions[i]) {
            LL mn = min(p.first, p.second);
            LL mx = max(p.first, p.second);
            for (PLL q : sufOptions[i+1]) {
                LL _mn = min(q.first, q.second);
                LL _mx = max(q.first, q.second);
                ans = min(ans, max(mx, _mx)-min(mn, _mn));
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 33276
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int n, x, y;

int main(int argc, char *argv[]){
        scanf("%d%d%d", &n, &x, &y);
        int *result = (int *)calloc(n, sizeof(int));
        for (int i = 1; i <= n; i++){
                for (int j = i + 1; j <= n; j++){
                        int d = abs(x - i) + 1 + abs(y - j);
                        if (j - i < d){
                                d = j - i;
                        }
                        result[d] += 1;
                }
        }
        for (int i = 1; i < n; i++){
                printf("%d\n", result[i]);
        }
        return 0;
}

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

using namespace std;

class Solution {
public:
	void solve() {
		int k, n;
		cin >> k >> n;
		vector<int> a(n + 1, 0);
		for (int i = 0; i < n; i++) cin >> a[i];
		a[n] = a[0] + k;
		int ans = k;
		for (int i = 0; i < n; i++) {
			ans = min(ans, k - (a[i + 1] - a[i]));
		}
		cout << ans << "\n";

		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,M;
    scanf("%d %d", &N, &M);
    
    int nc2 = N*(N-1)/2;
    int mc2 = M*(M-1)/2;
    
    printf("%d\n", nc2+mc2);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

    int n, m;
    cin >> n >> m;

    bool a[n], b[n];
    for (int i = 0; i < n; i++) {
        a[i] = false;
        b[i] = false;
    }

    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        
        if (x == 0) {
            a[y] = true;
        }
        if (y == n - 1) {
            b[x] = true;
        }
    }

    bool possible = false;
    for (int i = 0; i < n; i++) {
        if (a[i] && b[i]) {
            possible = true;
            break;
        }
    }
    cout << ((possible)? "POSSIBLE" : "IMPOSSIBLE") << endl;

    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef tuple<string, int, int> sii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 105;
int n, p;
string s;
sii a[N];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> s >> p;
        a[i] = {s, p, i};
    }
    sort(a + 1, a + n + 1, [](sii &a, sii &b) {
        string s1 = get<0>(a);
        string s2 = get<0>(b);
        int i1 = get<1>(a);
        int i2 = get<1>(b);
        if (s1 == s2)
            return i1 > i2;
        return s1 < s2;
    });
    for (int i = 1; i <= n; ++i) {
        cout << get<2>(a[i]) << endl;
    }

    return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    string s, t;
    cin >> s >> t;
    int N = s.size(), M = t.size();
    vector<vector<int>> dp(N + 1, vector<int>(M + 1));
    // dp[i][j]:=i-1番目、j-1番目まで見たときのLCSの長さ
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            if(s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    int sc = N, tc = M;
    string res = "";
    while(sc > 0 && tc > 0) {
        if(dp[sc - 1][tc] == dp[sc][tc]) {
            sc--;
        } else if(dp[sc][tc - 1] == dp[sc][tc]) {
            tc--;
        } else {
            sc--;
            tc--;
            res += s[sc];
        }
    }
    reverse(All(res));
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 38504
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long 

map<string,int> m;
vector<string> arr{"AC","WA","TLE","RE"};


void print(){
    for(auto i:arr){
        cout<<i<<" "<<"x"<<" "<<m[i]<<"\n";
    }
    cout<<"\n";
    return;
}

signed main(){
    fast
    // system("clear");
    int n;
    cin>>n;

    while(n--){
        string s;
        cin>>s;
        m[s]++;
    }
    
    print();
    return 0;
}





Measured memory_bytes: 3664
import itertools
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

d = 0
c = 0
for x in itertools.permutations(xy):
  c += 1
  D = 0
  for i in range(N-1):
    D += ((x[i][0]-x[i+1][0]) ** 2 + (x[i][1]-x[i+1][1]) ** 2) ** 0.5
  d += D
ans = d / c
print(ans)

Measured memory_bytes: 3064
//#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
const int maxn = 2e4 + 55;
string a, b;
int n, l[maxn], r[maxn], mm[maxn];
vector<pi> t;
int ans = INT_MAX;
int eq(int x) {
	x %= n;
	if(x < 0) x += n;
	return x;
}
void upd(int l, int r, int s, int m) {
	ans = min(ans, m + 2*l + (r<s?s:(2*r-s)));
	s = eq(n-s), swap(l, r);
	ans = min(ans, m + 2*l + (r<s?s:(2*r-s)));
}
void go(int s) {
	memset(mm, 0, sizeof mm);
	int rsh = 0, m = 0;
	for(int i = 0; i < n; i++) {
		if(a[eq(i+s)]!=b[i]) mm[i] = 1, m++;
	}
	for(auto i : t) {
		if(!mm[i.second]) continue;
		upd(i.first, rsh, s, m);
		//cout << i.first << " " << rsh << "\n";
		rsh = max(rsh, r[i.second]);
	}
	upd(0, rsh, s, m);
//	cout << s << " - " << ans << '\n';
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> a >> b;
	n = a.size();
	if(count(all(b), '1')==0) return cout << (count(all(a), '1')==0?0:-1), 0;
	for(int i = 0; i < n; i++) {
		while(b[eq(i-l[i])]=='0') l[i]++;
		while(b[eq(i+r[i])]=='0') r[i]++;
		
		t.pb({l[i], i});
	}
	sort(rall(t));
	for(int i = 0; i < n; i++) go(i);
	cout << ans;
}


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

const int mod = 998244353;

int main()
{
    int n ,s;
    scanf("%d%d",&n,&s);
    vector <int> a(n);
    for(int&i : a)
        scanf("%d",&i);

    vector <int> dp(s+1);
    dp[0] = 1;
    for(int&x : a){
        for(int j=s; ~j; j--){
            dp[j] = (dp[j]+dp[j])%mod;
            if(j >= x)
                dp[j] = (dp[j]+dp[j-x])%mod;
        }
    }

    printf("%d\n",dp[s]);
}


Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main(){
  ll m,x,y,z,w,b,j;
  cin>>m>>x>>y;
  for(j=1;j<m;j++){
    cin>>z>>w;
    b=max((x+z-1)/z,(y+w-1)/w);
    x=z*b;
    y=w*b;
  }
  cout<<x+y<<endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using Grid = vector<string>;

constexpr char kBomb = '#';
constexpr char kEmpty = '.';

bool InBounds(const Grid &g, int x, int y)
{
    return 0 <= x && x < (int)g.size() && 0 <= y && y < (int)g[0].size();
}

int CountBombs(const Grid &g, int x, int y)
{
    static const vector<pair<int, int>> kMods = {
        {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}
    };

    int bombs = 0;
    for (const auto &mod : kMods) {
        int mx = x + mod.first;
        int my = y + mod.second;
        if (InBounds(g, mx, my) && g[mx][my] == kBomb) {
            bombs += 1;
        }
    }
    return bombs;
}

int main()
{
    int rows, cols;
    cin >> rows >> cols;
    cin.get();

    Grid grid(rows);
    for (auto &row : grid) {
        getline(cin, row);
    }

    for (int i = 0; i < rows; i += 1) {
        for (int j = 0; j < cols; j += 1) {
            if (grid[i][j] == kEmpty) {
                grid[i][j] = CountBombs(grid, i, j) + '0';
            }
        }
    }

    for (const auto &row : grid) {
        cout << row << "\n";
    }

    return 0;
}


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

int S[1000];
int top = 0;

void push(int x)
{
	S[top++] = x;
}

int pop()
{
	top--;
	return S[top];
}

int main()
{
	int a, b;
	char s[100];
	while(scanf("%s",s)!=EOF)
	{
		if (s[0] == '+')
		{
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-')
		{
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (s[0] == '*')
		{
			a = pop();
			b = pop();
			push(a * b);
		}
		else
			push(atoi(s));
	}
	printf("%d\n",pop());
}


Measured memory_bytes: 2132
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN= (int)1e5+10;
const ll MOD = (ll)1e9+7;
int main()
{	
	int a,b,c;
	cin>>a>>b>>c;
	int ma=max(a,b);
	ma=max(ma,c);
	cout<<a+b+c-ma<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] t = new String[]{"dream", "dreamer", "erase", "eraser"};
        
        boolean[] dp = new boolean[s.length() + 1];
        dp[0] = true;
        
        for(int i = 1; i < dp.length; i++) {
            if(!dp[i - 1]) continue;
            for(int j = 0; j < t.length; j++) {
                if(i - 1 + t[j].length() <= s.length()
                    && s.substring(i-1, i - 1 + t[j].length()).equals(t[j]))
                    dp[i + t[j].length() - 1] = true;
            }
        }
        
        System.out.println(dp[dp.length - 1] ? "YES" : "NO");
    }
}


Measured memory_bytes: 31756
#include <stdio.h>

int f(int n, int m) {
    if (!m) return n;
    else {
        int x = (int)(1.05 * n);
        if (x % 1000 > 0)
            return f((x / 1000 + 1) * 1000, m - 1);
        else
            return f(x / 1000 * 1000, m - 1);
    }
}

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", f(100000, n));
}



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

int main() {
  int N;
  int A;
  cin >> N ;
  cin >> A ;
  int M;
  M = N%500 ;
  if(M<=A){
      cout << "Yes" << endl;
  }
  else{
      cout << "No" << endl;
  }
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    int sum = 0;
    rep(i, n) {
        int row = ((ll)a[i] * sum) % MOD;
        ans += row;
        ans %= MOD;
        sum += a[i];
        sum %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4820
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    A = list(map(int, input().split()))
    ssum = sum([A[i] * B[i] for i in range(M)]) + C
    if ssum > 0:
        ans += 1
print(ans)


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;

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

int const MAX = 4141;

int n;
char s[MAX];
int a[MAX];

void solve() {
	int q = 0;
	fi(2, n) {
		if (s[i - 1] < s[i]) q++;
	}
	if (n == 26 && !q) {
		printf("-1\n");
		return;
	}
	fi(1, n) {
		a[s[i]]++;
	}
	fi('a', 'z') {
		if (!a[i]) {
			s[n + 1] = i;
			printf("%s\n", s + 1);
			return;		
		}
	}
	fdi(n, 1) {
		int x = -1;
		fj(i + 1, n) {
			if (s[i] < s[j]) {
				if (x == -1 || s[x] > s[j]) {
					x = j;
				}
			}
		}
		if (x != -1) {
			swap(s[x], s[i]);
			fj(i + 1, n) {
				s[j] = 0;
			}
			printf("%s\n", s + 1);
			return;
		}
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf(" %s", s + 1);
	n = strlen(s + 1);
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 256
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    d_arr = []
    for i in range(N):
        _ = int(_in[i+1])  # type:int
        d_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = len(set(d_arr))
    ### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 38256
#include <iostream>

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		int a=0, b=0;
		int aa, bb;
		for (int i = 0; i < n; i++) {
			cin >> aa >> bb;
			if (aa > bb) a += aa+bb;
			else if (bb > aa) b += aa+bb;
			else a += aa, b += bb;
		}
		cout << a << " " << b << endl;
	}
	return 0;
}

Measured memory_bytes: 0
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.Array.Unboxed
import Data.Bits
import Data.Char
import Data.Coerce
import Data.Function
import Data.Int 
import Data.IORef
import Data.List
import Data.Maybe
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  (n, m) <- getIntPair
  print $ solve n m

solve :: Int -> Int -> N
solve n m = sum [((-1) ^ k) * (cmb n k) * (perm m k) * ((perm (m - k) (n - k)) ^ 2) | k <- [0..n]]
  where
    cmb :: Int -> Int -> N
    cmb n k = (fact ! n) * (finv ! k) * (finv ! (n - k))
    perm :: Int -> Int -> N
    perm n k = fact ! n * finv ! (n - k)
    fact :: Array Int N
    fact = listArray (0, m) . scanl (*) 1 $ map fromIntegral [1..m]
    finv :: Array Int N
    finv = listArray (0, m) . map (f . fromIntegral) $ [0..m]
    f i
      | i == m = recip (fact ! m)
      | otherwise = let i' = i + 1 in (finv ! i') * (fromIntegral i')

-- Input

getInt :: IO Int
getInt = readLn

second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)

-- Search

bisearch :: (Int -> Bool) -> (Int, Int) -> (Int, Int)
bisearch check = bis
  where
    bis (l, r)
      | l + 1 == r = (l, r)
      | check mid  = bis (mid, r)
      | otherwise  = bis (l, mid)
      where
        mid = l + (r - l) `div` 2

-- Modular Arithmetic
--
 
modulo :: Int64
modulo = 10^9+7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined
---
 
exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r
 
recipM :: Int64 -> Int64
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM :: Int64 -> Int64 -> Int64
divM !x !y = x `mulMod` recipM y
 
instance Fractional N where
  (/) = coerce divM
  recip = coerce recipM
  fromRational = undefined

Measured memory_bytes: 96532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll inf = (1LL<<60);

int N,M;
vector<ll> a(5005), b(5005), c(5005);
vector<ll> dist(1005, inf);

int main(){
    cin >> N >> M;
    for(int i=0; i<M; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--; c[i] = -c[i];
    }

    dist[0] = 0;

    for(int loop=0; loop<N; loop++){
        for(int i=0; i<M; i++){
            if(dist[a[i]] == inf) continue;

            if(dist[b[i]] > dist[a[i]]+c[i]){
                dist[b[i]] = dist[a[i]]+c[i];
            }

        }
    }

    ll ans = -dist[N-1];
    vector<bool> negative(N+1, false);

    for(int loop=0; loop<N; loop++){
        for(int i=0; i<M; i++){
            if(dist[a[i]] == inf) continue;
            if(dist[b[i]] > dist[a[i]]+c[i]){
                dist[b[i]] = dist[a[i]]+c[i];
                negative[b[i]] = true;
            }

            if(negative[a[i]]) negative[b[i]] = true;
        }
    }

    if(negative[N-1]) cout << "inf" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int selectionSort(int A[],int N) {
	int i, j, t, sw=0, minj;
	for(i=0; i<N; i++) {
		minj = i;
		for(j=i; j<N; j++) {
			if(A[j] < A[minj]) minj = j;
		}
		t = A[minj]; A[minj] = A[i]; A[i] = t;
		if(i != minj) sw++;
	}
	return sw;
}

int main() {
	int A[100],N,i,sw;
	
	scanf("%d", &N);
	for(i=0; i<N; i++) scanf("%d", &A[i]);
	
	sw = selectionSort(A, N);
	
	for(i=0; i<N; i++) {
		if(i!=0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
	printf("%d\n", sw);
	
	return 0;	
}

Measured memory_bytes: 2740
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl; 
}

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

using namespace std;

const int INF = 1001001001;

int main()
{
    int n;
    
    while (scanf("%d", &n) && n){
        int xl = -INF, xr = INF;
        bool px = false;
        int pval = 1000000001;
        bool ok = true;
        for (int i = 0; i < n; i++){
            char s[16];
            scanf("%s", s);
            if (s[0] == 'x'){
                if (px) ok = false;
                else {
                    if (i & 1) xl = max(xl, pval + 1);
                    else xr = min(xr, pval - 1);
                }
                px = true;
            }
            else {
                int tmp;
                sscanf(s, "%d", &tmp);
                if (px){
                    if (i & 1) xr = min(xr, tmp - 1);
                    else xl = max(xl, tmp + 1);
                }
                else {
                    if (i & 1) ok &= (pval < tmp);
                    else ok &= (tmp < pval);
                }
                pval = tmp;
                px = false;
            }
        }
        if (!ok || xl > xr) printf("none\n");
        else if (xr != xl) printf("ambiguous\n");
        else printf("%d\n", xr);
    }
    
    return (0);
}

Measured memory_bytes: 1204
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<list>
using namespace std;
int main() {
	list<int> ls;
	vector<int> p;
	int n,a;
	string str;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> str;
		if (str == "insert") {
			cin >> a;
			ls.push_front(a);
		}
		else if (str == "delete") {
			cin >> a;
			for (list<int>::iterator itr = ls.begin(); itr != ls.end(); ++itr) {
				if (*itr == a) {
					ls.erase(itr);
					break;
				}
			}
		}
		else if (str == "deleteFirst") {
			ls.pop_front();
		}
		else if (str == "deleteLast") {
			ls.pop_back();
		}
	}
	for (list<int>::iterator itr = ls.begin(); itr != ls.end(); ++itr) {
		cout << (itr == ls.begin() ? "" : " ") << *itr;
	}
	cout << endl;
	return 0;
}


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

int main(){
  int a[1000000] = {};
  int s;
  cin >> s;
  a[s - 1]++;
  int count = 1;
  while(true){
    count++;
    if(s % 2 == 0) s /= 2;
    else s = 3 * s + 1;
    if(a[s - 1] > 0){
      cout << count << endl;
      return 0;
    }else a[s - 1]++;
  }
}

Measured memory_bytes: 7492
#include<iostream>
#include<vector>
#include<queue>
#define rep(i,n) for(ll i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main()
{
    ll v, e, r;
    cin >> v >> e >> r;
    vector<vector<pair<ll, ll>>> edges(v);
    rep(i,e){
        ll s, t, d;
        cin >> s >> t >> d;
        edges[s].push_back(make_pair(d, t));
    }
    const ll inf = 1e9;
    vector<ll> dist(v, inf);
    priority_queue<
        pair<ll, ll>,
        vector<pair<ll, ll>>,
        greater<pair<ll, ll>>
    >q;    
    q.push(make_pair(0, r));

    while(!q.empty()) {
        pair<ll, ll> hoge = q.top();
        ll d = hoge.first;
        ll t = hoge.second;
        q.pop();
        if(d < dist[t]) {
            dist[t] = d;
            for(auto huga : edges[t]) {
                ll l = huga.first;
                ll u = huga.second;
                if(dist[u] > d + 1) {
                    q.push(make_pair(d + l, u));
                }
            }
        }
    }
    for(ll d : dist) {
        if(d == inf) cout << "INF" << endl;
        else cout << d << endl;
    }
    return 0;
}


Measured memory_bytes: 21484
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String cou = br.readLine();
        int count = Integer.parseInt(cou);
        int[][] t1 = new int[3][10];
        int[][] t2 = new int[3][10];
        int[][] t3 = new int[3][10];
        int[][] t4 = new int[3][10];
        int i=0;
        init(t1);
        init(t2);
        init(t3);
        init(t4);
        while(i<count) {
            String line = br.readLine();
            String[] line2 = line.split(" ");
            switch(Integer.parseInt(line2[0])) {
                case 1:
                    add(t1,Integer.parseInt(line2[1]),Integer.parseInt(line2[2]),Integer.parseInt(line2[3]));
                    break;
                case 2:
                    add(t2,Integer.parseInt(line2[1]),Integer.parseInt(line2[2]),Integer.parseInt(line2[3]));
                    break;
                case 3:
                    add(t3,Integer.parseInt(line2[1]),Integer.parseInt(line2[2]),Integer.parseInt(line2[3]));
                    break;
                case 4:
                    add(t4,Integer.parseInt(line2[1]),Integer.parseInt(line2[2]),Integer.parseInt(line2[3]));
                    break;
                default:
                    break;
            }
            i++;
        }
        print(t1);
        punc();
        print(t2);
        punc();
        print(t3);
        punc();
        print(t4);
    }
    static void init(int[][] ary) {
        for(int i=0;i<ary.length;i++) {
            for(int j=0;j<ary[i].length;j++) {
                ary[i][j]=0;
            }
        }
    }
    static void print(int[][] tag) {
        for(int i=0;i<tag.length;i++) {
            for(int j=0;j<tag[i].length;j++) {
                System.out.print(" " + tag[i][j]);
            }
            System.out.println();
        }
    }
    static void punc() {
        System.out.println("####################");
    }
    //1 1 3 8 1棟1階3番目の部屋に+8人
    static void add(int[][] ren,int floor,int room,int num) {
            ren[floor-1][room-1] += num;
    }
  
}

Measured memory_bytes: 19328
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define var(n) int n; scn(n)
#define F first
#define S second 
#define pb push_back
const int N=1e6+5;
// const ll M = 998244353;
const ll M=1e9+7;
const ll inf=1e18;



int main()
{
	var(n);
	int a[n],dp[n];
	rep(i,0,n)
	{		
		scn(a[i]);
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min( dp[i-1]+abs(a[i]-a[i-1]) , dp[i-2]+abs(a[i]-a[i-2]));
	}
	pri(dp[n-1]);
}

Measured memory_bytes: 1024
import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		long[][] cells = new long[r+1][c+1]; //+1は総和セル
		
		for(int tate = 0;tate < r;tate++) {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		}
		
		for(int tate = 0;tate < r;tate++) {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		}
		
		for(int yoko = 0;yoko <= c;yoko++) {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		}
		
		for(int tate = 0;tate <= r;tate++) {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		}
		
		System.out.println("");
		

	}
	

}


Measured memory_bytes: 42088
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

class Combination {
    int powmod(int a, int p) {
        int ans = 1;
        int mul = a;

        for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }

        return ans;
    }
public:
    int N;
    int mod;
    vector<int> fact;
    vector<int> revFact;

    Combination(int n, int m) : N(n), mod(m), fact(n+1), revFact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= N; i++) {
            fact[i] = fact[i-1] * i;
            fact[i] %= mod;
        }

        // Fermat's little theorem
        revFact[N] = powmod(fact[N], mod - 2);

        for (int i = N-1; i >= 0; i--) {
            revFact[i] = revFact[i+1] * (i+1);
            revFact[i] %= mod;
        }
    }

    int get(int a, int b) {
        if (a < 0 || b < 0) return 0;
        if (b > a) return 0;
        return (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod;
    }
};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int X, Y;
    cin >> X >> Y;
    if ((X + Y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int K = (X + Y) / 3;
    int diff = abs(X - Y);

    if ((K + diff) % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    int A = (K + diff) / 2;
    int B = K - A;
    if (A < 0 || B < 0) {
        cout << 0 << endl;
        return 0;
    }

    Combination comb = Combination(K + 1, MOD);
    cout << comb.get(K, A) << endl;

    return 0;
}

Measured memory_bytes: 10624
/*Bismillahir Rahmanir Raheem*/

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

//code start

int main()
{
    // freopen("/root/Programming/input.txt", "r", stdin);
    // freopen("/root/Programming/output.txt", "w", stdout);
    string str, sb;
    cin >> str;
    int q;
    scanf("%d", &q);
    int ti, fi;
    bool flag = true;
    vector<string> vstart, vend;
    while (q--)
    {
        scanf("%d", &ti);
        if (ti == 1)
        {
            flag = !flag;
        }
        else
        {
            scanf("%d", &fi);
            getchar();
            cin >> sb;
            if (fi == 1)
            {
                if (flag)
                    vstart.push_back(sb);
                else
                    vend.push_back(sb);
            }
            else
            {
                if (flag)
                    vend.push_back(sb);
                else
                    vstart.push_back(sb);
            }
        }
    }
    if (flag)
    {
        int x = vstart.size();
        for (int i = x - 1; i > -1; i--)
        {
            cout << vstart[i];
        }
        cout << str;
        for (int i = 0; i < vend.size(); i++)
        {
            cout << vend[i];
        }
        printf("\n");
    }
    else
    {
        // cout<<"wojfoej";
        int x = vend.size();
        for (int i = x - 1; i > -1; i--)
        {
            reverse(vend[i].begin(), vend[i].end());
            cout << vend[i];
        }
        reverse(str.begin(), str.end());
        cout<<str;
        for (int i = 0; i < vstart.size(); i++)
        {
            reverse(vstart[i].begin(), vstart[i].end());
            cout << vstart[i];
            
        }
        printf("\n");
    }
    // cout << str << endl;
    return 0;
}

Measured memory_bytes: 11760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <cstdio>
using namespace std;

int main()
{
	while(true)
	{
		int a, b;
		cin >> a >> b;
		if(cin.eof())
			break;

		char len[10];
		sprintf(len, "%d", a + b);
		string sum(len);
		cout << sum.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
while True:
    n,x = map(int,input().split())
    if n==0 and x==0:
        break
    cnt=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                sum = i+j+k
                if sum==x:
                    cnt+=1

    print(cnt)
            
    
    




Measured memory_bytes: 5596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n % 111 == 0) {
		cout << n;
	}
	else {
		cout << (n / 111 + 1) * 111;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import deque

h, w = list(map(int, input().split()))
grid = [input() for _ in range(h)]

q = deque([(0, 0)])
dists = [[10000] * w for _ in range(h)]
dists[0][0] = 0
prev = [[-1] * w for _ in range(h)]

while q:
    x, y = q.popleft()

    nei = [(0, 1), (0, -1), (1, 0), (-1, 0)]

    for xo, yo in nei:
        nextx, nexty = x+xo, y+yo

        if nextx < 0 or nextx >= w or nexty < 0 or nexty >= h:
            continue
        if grid[nexty][nextx] == "#":
            continue

        dist = dists[y][x]+1

        if dist < dists[nexty][nextx]:
            dists[nexty][nextx] = dist
            prev[nexty][nextx] = (x, y)
            q.append((nextx, nexty))

if prev[h-1][w-1] != -1:
    path = []
    cur = (w-1, h-1)

    while cur != -1:
        path.append(cur)
        cur = prev[cur[1]][cur[0]]

    cnt = 0
    for i in range(w):
        for j in range(h):
            if grid[j][i] == "." and (i, j) not in path:
                cnt += 1

    print(cnt)
else:
    print(-1)

Measured memory_bytes: 9644
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,X,K,Q;
ll A[200010],B,C;
set<ll> S;
ll ans;
int main(){

    cin>>N>>K>>Q;
    REP(i,Q){
        ll a;
        cin>>a;
        A[a-1]++;
    }
    REP(i,N){
        cout<<((Q-K+1)<=A[i]?"Yes":"No")<<endl;

    }
}


Measured memory_bytes: 1408