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

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

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    rep(i,N) cin>>A[i];
    map<int,int> m;
    m[0]=3;
    ll ans = 1;
    rep(i,N){
        ans = (ans*m[A[i]])%mod;
        m[A[i]]--;
        m[A[i]+1]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8120
import sys


H,W,K = [int(_) for _ in input().split()]
l = []
c = 0
if W == 1:
    print(1)
    sys.exit()
#0本
l.append([0 for _ in range(W-1)])
#1本
for i in range(0, W-1):
    a = [0 for _ in range(W-1)]
    for j in range(0, W-1):
        if j == i:
            a[j] = 1
        else:
            a[j] = 0
    l.append(a)
#2本
if W >= 4:
    for i in range(0, W-3):
        for j in range(i+2, W-1):
            a = [0 for _ in range(W-1)]
            for k in range(0, W-1):
                if k == i or k == j:
                    a[k] = 1
                else:
                    a[k] = 0
            l.append(a)
#3本
if W >= 6:
    for i in range(0, W-5):
        for j in range(i+2, W-3):
            for k in range(j+2, W-1):
                a = [0 for _ in range(W-1)]
                for p in range(W-1):
                    if p == i or p == j or p == k:
                        a[p] = 1
                    else:
                        a[p] = 0
                l.append(a)
#4本
if W == 8:
    l.append([1,0,1,0,1,0,1])


HW = [[0 for _ in range(W)] for _ in range(H+1)]
HW[0][0] = 1

for i in range(0, H):
    for j in range(0,W):
        for k in range(len(l)):
            q = HW[i][j]
            if j == 0:
                if l[k][j] == 1:
                    HW[i+1][j+1] += q
                else:
                    HW[i+1][j] += q
            elif j == W-1:
                if l[k][j-1] == 1:
                    HW[i+1][j-1] += q
                else:
                    HW[i+1][j] += q
            else:
                if l[k][j] == 0 and l[k][j-1] == 0:
                    HW[i+1][j] += q
                elif l[k][j] == 1:
                    HW[i+1][j+1] += q
                else:
                    HW[i+1][j-1] += q
        for x in range(0, W):
            HW[i+1][x] = HW[i+1][x] % 1000000007
  
ans = HW[H][K-1]

print(ans)


Measured memory_bytes: 3192
S=[l for l in raw_input()]
T=[l for l in raw_input()]
import copy
result = []
for i in range(len(S)-len(T)+1):
	S_ = copy.copy(S)
	flg = True
	for j in range(len(T)):
		if S[i+j]==T[j]:
			S_[i+j]=T[j]
		elif S[i+j]=='?':
			S_[i+j]=T[j]
		elif S[i+j] != T[j]:
			flg = False
			break
	if flg:
		S_=('').join(S_)
		while '?' in S_:
			S_=S_.replace('?','a')
		result.append(S_)

if result == []:
	print 'UNRESTORABLE'
else:
	print sorted(result)[0]	

Measured memory_bytes: 2696
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	/*string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, 3)if (s[i] == t[i])ans++;
	cout << ans;*/


	int a, b;
	cin >> a >> b;
	int ans = 0;
	while (ans * a - (ans - 1) < b) {
		ans++;
	}
	cout << ans;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

string itos5 (int n )
{
	stringstream ss;
	ss << n;
	string res = ss.str();
	int len = res.length();
	int i;

	if (len < 5){
		for (i = 0; i < 5 - len; ++i){
			res = '0' + res;
		} // end for
	} // end if

	return res;
}

int main()
{
	const string pos[8] = {
	"*****     ",
	"     *****",
	"==========",
	" **** ****",
	"* **** ***",
	"** **** **",
	"*** **** *",
	"**** **** "
};
	int i,j,k;

//	cut here before submit 
//	freopen ("testcase.abacus", "r", stdin );
	string str = "";

	vector <vector <string> > R;

	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		vector <string> res (8, string ( 5, ' ') );
//		vector <string> res (10, string (5, ' ') );
		int n;
		string t = "";
		stringstream ss(str);
		ss >> n;

		t = itos5 (n );

		for (i = 0; i < 5; ++i){
			int m = t[i] - '0';
			for (j = 0; j < 8; ++j){
				res[j][i] = pos[j][m];
			} // end for
		} // end for
		
		R.push_back(res );
		res.clear();

	} // end loop
	int size = R.size();

	for (k = 0; k < size; ++k){
		vector<string>::iterator it = R[k].begin();
		for (; it != R[k].end(); ++it ){
			string str = (*it);
			int len = str.length();

			for (i = 0; i < len; ++i){
				cout << str[i];
			} // end for
			cout << endl;
		} // end for
		if (k != size - 1 ) {
			cout << endl;
		} // end if
	} // end for
	
	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,i,j,k,l,m,n,ans,tmp,hoge,fuga,piyo;
ll x[10010],y[10010];
string s,str;
int main(){
  cin>>s>>str;
  if(str.length()-s.length()==1){
    for(int i=0;i<s.length();i++){
      if(s[i]!=str[i])ans++;
    }
    if(ans==0)cout<<"Yes";
    else cout<<"No";
    return 0;
  }
  cout<<"No";
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
typedef tuple<int, int, int> T;

//区間更新、区間Min。更新は新しい方ではなく、値の小さい方を優先。
const int DEPTH = 17;
const int INF = 1e+16;
struct RUQ {
	int d[1 << (DEPTH + 1)];
	RUQ() {
		int i;
		rep(i, (1 << (DEPTH + 1))) d[i] = INF;
	}
	
	//[l, r)
	void update(int l, int r, int x, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return;
		if (l <= a && b <= r) {
			d[id] = min(d[id], x);
			return;
		}
		update(l, r, x, a, (a + b) / 2, id * 2 + 1);
		update(l, r, x, (a + b) / 2, b, id * 2 + 2);
	}
	
	int query(int pos) {
		int ret = INF;
		
		pos += (1 << DEPTH) - 1;
		ret = min(ret, d[pos]);
		while (pos > 0) {
			pos = (pos - 1) / 2;
			ret = min(ret, d[pos]);
		}
		return ret;
	}
};

int n, m;
T tupl[100002];	//(l, r, c)
int l[100002], r[100002], c[100002];
RUQ ruq;

signed main() {
	int i;
	
	cin >> n >> m;
	
	rep(i, m) {
		cin >> l[i] >> r[i] >> c[i];
		l[i]--; r[i]--;
		tupl[i] = T(l[i], r[i], c[i]);
	}
	tupl[m] = T(0, 0, 0);
	tupl[m + 1] = T(n - 1, n - 1, 0);
	m += 2;
	
	sort(tupl, tupl + m);
	
	rep(i, m) {
		l[i] = get<0>(tupl[i]);
		r[i] = get<1>(tupl[i]);
		c[i] = get<2>(tupl[i]);
	}
	
	//rep(i, m) { cout << l[i] << ", " << r[i] << ", " << c[i] << endl; }
	
	ruq.update(0, 1, 0);	//dp[0] = 0
	rep(i, m - 1) {
		int val = ruq.query(i);
		val += c[i];
		
		//r[i] > l[j]なる最小のjを探す
		int iter = upper_bound(l, l + m, r[i]) - l;
		
		//[i + 1, iter)を更新
		//cout << "val = " << val << ", [" << i + 1 << ", " << iter << ")" << endl;
		ruq.update(i + 1, iter, val);
	}
	
	int res = ruq.query(m - 1);
	if (res >= INF / 2) cout << -1 << endl;
	else cout << res << endl;
	return 0;
}

Measured memory_bytes: 7040
/*
3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000
*/
#include <bits/stdc++.h>
using namespace std;
void print() { cout << '\n'; } template<class T, class ...U> void print(T x, U ...y) { cout << x << ' '; print(y...); }
typedef long long ll; const ll N = 2e5 + 5, M = 1e9 + 7; typedef vector<int> vi; typedef vector<vi> vii; void Main();
int main(int argc, char **argv) {
  ios::sync_with_stdio(0), cin.tie(0); cout << setprecision(10) << fixed;
  #ifdef Zmm
  freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x;
  #endif
  Main();
}
struct pp {
  ll x, h;
  bool operator<(const pp &b) const {
    // if (h == b.h) return id < b.id;
    return h < b.h;
  }
} a[N], mini = {0, -0x3f3f3f3f};
bool cmp(const pp &a, const pp &b) { return a.x < b.x; }
struct node {
  ll tag;
  pp mx;
} t[N << 2];

#define lt (o << 1)
#define rt ((o << 1) | 1)

void build(ll o, ll l, ll r) {
  if (l == r) {
    t[o].tag = 0;
    t[o].mx = a[l];
    return;
  }
  ll mid = (l + r) >> 1;
  build(lt, l, mid);
  build(rt, mid + 1, r);
  t[o].mx = max(t[lt].mx, t[rt].mx);
}

void update(ll o, ll L, ll R, ll l, ll r, ll x) {
  // cout << l << ' ' << r << ' ' << L << ' ' << R << endl;
  if (L <= l && R >= r) {
    t[o].mx.h += x;
    t[o].tag += x;
    return;
  }
  ll mid = (l + r) >> 1;
  if (L <= mid) update(lt, L, R, l, mid, x);
  if (R > mid) update(rt, L, R, mid + 1, r, x);
  t[o].mx = max(t[lt].mx, t[rt].mx);
}
void pushdown(ll o) {
  if (t[o].tag) {
    t[lt].mx.h += t[o].tag;
    t[rt].mx.h += t[o].tag;
    t[lt].tag += t[o].tag;
    t[rt].tag += t[o].tag;
    t[o].tag = 0;
  }
}
pp query(ll o, ll L, ll R, ll l, ll r) {
  if (L <= l & R >= r) return t[o].mx;
  ll mid = (l + r) >> 1;
  pushdown(o);
  pp ans = mini;
  if (L <= mid) ans = max(ans, query(lt, L, R, l, mid));
  if (R > mid) ans = max(ans, query(rt, L, R, mid + 1, r));
  return ans;
}


ll nxt[N];
void Main() {
  ll n, D, A;
  cin >> n >> D >> A;
  for (ll i = 1; i <= n; i++) cin >> a[i].x >> a[i].h;
  sort(a + 1, a + n + 1, cmp);
  // for (ll i = 1; i <= n; i++) a[i].id = i;
  nxt[0] = 1;
  for (ll i = 1; i <= n; i++) {
    ll j = nxt[i - 1] + 1;
    for (; j <= n; j++) if (a[j].x - a[i].x > D) break;
    nxt[i] = j - 1;
  }
  build(1, 1, n);
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll h = query(1, i, i, 1, n).h;
    if (h >= 0) {
      ll p = lower_bound(a + 1, a + n + 1, (pp){a[i].x + D * 2, 0}, cmp) - a;
      if (p == n + 1 || a[p].x > a[i].x + D * 2) p--;
      update(1, i, p, 1, n, -(h + A - 1) / A * A);
      ans += (h + A - 1) / A;
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s; 
  int count;
  int i;
  
  cin >> s;
  for(i=0; i<3; i++){ 
  if (s[i]=='1'){
    count++;
  }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

#define PI 3.14159265358979323846
const int size = 1001;
double X[size];
double Y[size];

double getDistance( double x1, double y1, double x2, double y2 ) {
    double x = x2 - x1;
    double y = y2 - y1;
    return sqrt( x * x + y * y );
}

double getDistance( double x, double y ) {
    return getDistance( 0, 0, x, y );
}

double zero( double d ) {
    return fabs( d ) < 1e-9 ? 0.0 : d;
}

int main() {
    X[0] = 1.0;
    Y[0] = 0.0;
    for ( int i = 1; i < size; i++ ) {
        double x = X[i-1] * cos( PI / 2.0 ) - Y[i-1] * sin( PI / 2.0 );
        double y = X[i-1] * sin( PI / 2.0 ) + Y[i-1] * cos( PI / 2.0 );
        double d = zero( getDistance( x, y ) );
        X[i] = X[i-1] + zero( x ) / d;
        Y[i] = Y[i-1] + zero( y ) / d;
        // cout << X[i-1] << ", " << Y[i-1] << " => " << X[i] << ", " << Y[i] << endl;
    }
    
    int n;
    while ( cin >> n && n > 1 ) {
        printf( "%.2f\n", X[n-1] );
        printf( "%.2f\n", Y[n-1] );
    }
    return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>
  
using namespace std;
  
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


int main(){
	while(1){
		string str;
		getline(cin,str);
		
		if(cin.eof())break;
		
		vector<bool> isnum;
		rep(i,str.size()){
			if(i==str.size()-1 || str[i+1]==' '){
				char c = str[i];
				if(c>='0' && c<='9')isnum.push_back(true);
				else isnum.push_back(false);
			}
		}
		
		
		
		stringstream sst;
		sst<<str;
		
		stack<double> t;
		rep(i,isnum.size()){
			if(isnum[i]){
				int a;
				sst>>a;
				t.push((double)a);
				
			}else{
				char c;
				sst>>c;
				
				double b = t.top();t.pop();
				double a = t.top();t.pop();
				
				if(c=='*'){
					t.push(a*b);	
				}
				if(c=='+'){
					
					t.push(a+b);
				}
				if(c=='-'){
					
					t.push(a-b);
				}
				if(c=='/'){
					
					t.push(a/b);
				}
			}
		}
		
		printf("%.8lf\n",t.top());
	}
	
}

Measured memory_bytes: 1288
#include <cstdlib>
#include <iostream>


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

  int x, a, b;
  std::cin >> x >> a >> b;
  auto d = b - a;
  std::cout << (d <= 0 ? "delicious" : x >= d ? "safe" : "dangerous") << std::endl;

  return EXIT_SUCCESS;
}


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

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int kN = 4e5 + 5, kInf = 0x3f3f3f3f;
const ll kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;

int n, a[kN];
std::map <int, int> inc;
inline bool Incr(int mid, int k) {
	++inc[k];
	//printf("%d %d\n", k, inc[k]);
	for(; k > 1 && inc[k] >= mid; --k) {
		inc[k - 1] += inc[k] / mid;
		inc[k] %= mid;
	}
	if(k && inc[k] >= mid) return false;
	return true;
}
bool Check(int mid) {
	inc.clear();
	for(int i = 1; i <= n; ++i) {
		if(a[i] <= a[i - 1]) {
			if(!Incr(mid, a[i])) return false;
			for(auto it = inc.upper_bound(a[i]); it != inc.end(); ) {
				it = inc.erase(it);
			}
		}
	}
	return true;
}
int main() { 
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int T = 1; //rd(T);
	while(T--) {
		bool flag = true;
		rd(n);
		for(int i = 1; i <= n; ++i) {
			rd(a[i]);
			if(a[i] <= a[i - 1]) flag = false;
		}
		if(flag) printf("1\n");
		else {
			int l = 2, r = n;
			while(l < r) {
				int mid = (l + r) >> 1;
				if(Check(mid)) r = mid;
				else l = mid + 1;
				//printf("==%d==\n", mid);
			}
			printf("%d\n", l);
		}
	} return 0;
}

Measured memory_bytes: 4496
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){

	ios::sync_with_stdio(false);
	int N;		cin >> N;
	V H(N);		VECCIN(H);
	V dp(N);		dp[N - 1] = 0;

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

	int ans = 0;
	for(int i = 0 ; i < N ; i++)
		ans = max(ans , dp[i]);
    
	SCOUT(ans) << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a==7&&b==5&&c==5)
    printf("YES");
  else if(a==5&&b==7&&c==5)
    printf("YES");
  else if(a==5&&b==5&&c==7)
    printf("YES");
  else
    printf("NO");

  return 0;

}

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

using namespace std;

typedef long long ll;
  
int main(){
  int N;
  cin >> N;
  vector<pair<int, int>> p(N);
  for(int i = 0; i < N; i++){
    cin >> p.at(i).second >> p.at(i).first;
  }
  sort(p.begin(), p.end());
  ll time = 0;
  for(int i = 0; i < N; i++){
    time += p.at(i).second;
    if(time > p.at(i).first){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int p, q, r;

int single(int x) {
    if(x == 0) return 2;
    else if(x == 1) return 1;
    else return 0;
}

int sekiXY(int x, int y) {
    return min(x, y);
}

int waXY(int x, int y) {
    return max(x, y);
}

typedef string::const_iterator State;
class ParseError {};

struct Parser {
    // エラー検出
    void consume(State &begin, char expected) {
        if(*begin == expected) begin++;
        else {
            cerr << "Expected '" << expected << "' but got '" << *begin << "'" << endl;
            cerr << "Rest string is '";
            while(*begin) {
                cerr << *begin++;
            }
            cerr << "'" << endl;
            throw ParseError();
        }
    }

    // 数字の列をパースして、その数を返す
    int number(State &begin) {
        int ret = 0;
        if(*begin == 'P') ret = p;
        else if(*begin == 'Q') ret = q;
        else if(*begin == 'R') ret = r;
        else if(isdigit(*begin)) ret = *begin - '0';
        else return 0;
        
        begin++;
        return ret;
    }

    // 括弧か数をパースして、その評価結果を返す
    int factor(State &begin) {
        if(*begin == '(') {
            consume(begin, '(');    // '('を飛ばす
            int ret = expression(begin);
            consume(begin, ')');    // ')'を飛ばす
            return ret;
        }else return number(begin);
    }

    // 乗算除算の式をパースして、その評価結果を返す
    int term(State &begin) {
        if(*begin == '-') {
            consume(begin, '-');
            return single(term(begin));
        }else return factor(begin);
    }

    // 四則演算の式をパースして、その評価結果を返す
    int expression(State &begin) {
        int ret = term(begin);
        while(1) {
            if(*begin == '+') {
                consume(begin, '+');
                ret = waXY(ret, term(begin));
            }else if(*begin == '*') {
                consume(begin, '*');
                ret = sekiXY(ret, term(begin));
            }else break;
        }
        return ret;
    }
};

int main() {
    while(1) {
        string s; getline(cin, s);
        if(s.at(0) == '.') break;
        int cnt = 0;
        for(p = 0; p < 3; ++p) {
            for(q = 0; q < 3; ++q) {
                for(r = 0; r < 3; ++r) {
                    Parser ps;
                    State begin = s.begin();
                    if(ps.expression(begin) == 2) cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3168
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    cout << (n % 2 ? 2 * n : n) << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NMK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M, K) = (NMK[0], NMK[1], NMK[2]);
        var A = new int[M];
        var B = new int[M];
        var C = new int[K];
        var D = new int[K];
        for (int i = 0; i < M; i++)
        {
            var AB = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            (A[i], B[i]) = (AB[0] - 1, AB[1] - 1);
        }
        for (int i = 0; i < K; i++)
        {
            var CD = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            (C[i], D[i]) = (CD[0] - 1, CD[1] - 1);
        }

        var adjacencyList = new List<int>[N];

        for (int i = 0; i < N; i++)
            adjacencyList[i] = new List<int>();

        for (int i = 0; i < M; i++)
        {
            adjacencyList[A[i]].Add(B[i]);
            adjacencyList[B[i]].Add(A[i]);
        }

        var blockshipList = new List<int>[N];

        for (int i = 0; i < N; i++)
            blockshipList[i] = new List<int>();

        for (int i = 0; i < K; i++)
        {
            blockshipList[C[i]].Add(D[i]);
            blockshipList[D[i]].Add(C[i]);
        }

        var nodeInfo = new int[N];
        var groupInfo = new List<List<int>>();

        for (int i = 0; i < N; i++)
            nodeInfo[i] = -1;

        void DFS(int v, int g)
        {
            nodeInfo[v] = g;
            groupInfo[g].Add(v);

            foreach (var next in adjacencyList[v])
                if (nodeInfo[next] == -1)
                    DFS(next, g);
        }

        var groupId = 0;

        for (int i = 0; i < N; i++)
        {
            if(nodeInfo[i] == -1)
            {
                groupInfo.Add(new List<int>());

                DFS(i, groupId);

                groupId++;
            }
        }

        var friendCandidateCount = new int[N];

        for (int i = 0; i < N; i++)
        {
            var g = nodeInfo[i];
            var groupCount = groupInfo[g].Count;
            var myselfCount = 1;
            var friendsCount = adjacencyList[i].Count;
            var blocksCount = blockshipList[i].Count(v => nodeInfo[v] == g);

            friendCandidateCount[i] = groupCount - myselfCount - friendsCount - blocksCount;
        }

        for (int i = 0; i < N; i++)
            Write($"{friendCandidateCount[i]} ");

        WriteLine();
    }
}


Measured memory_bytes: 66524
#include<bits/stdc++.h>
using namespace std;
struct node{
	int day,money;
}s[100005];
priority_queue <int> q;
int n,m;
bool cmp(node X,node Y){
	return X.day < Y.day;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;i++)
		scanf("%d%d",&s[i].day,&s[i].money);
	long long ans = 0;
	int now = 1;
	sort(s + 1,s + 1 + n,cmp);
	for(int i = 1;i <= m;i++){
		while(now <= n && s[now].day <= i){
			q.push(s[now].money);	
			now++;		
		}
		if (!q.empty()){
			ans += q.top();
			q.pop();
		}
	}
	printf("%ld\n",ans);
	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

int main() {

int N,X,Y; cin>>N>>X>>Y;

vector<int> ans(N,0);

numrep(i,N){
  for(int j=i+1;j<=N;j++){
    int d=min(abs(j-i),abs(X-i)+abs(Y-j)+1);//X,Yを使用しない場合：X,Yを使用したとき(XからYに移動するために+1回の移動が必要なことに注意)
    ans[d]++;    
  }
}
numrep(i,N-1){
cout << ans[i] << endl;
}
return 0;
}

Measured memory_bytes: 256
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
print((1000-n%1000)%1000)


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

int main() {
    string s; cin >> s;
    int ans = 0, n = s.size()-1;
    for (int i = 0; i < s.size()/2; i++)
    {
        if (s[i] != s[n - i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define 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 pw(x) (1LL<<(x))
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define NEWL EVAL({cout << '\n';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 3;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
#define DIE EVAL({cout << -1 << '\n'; exit(0);})
//------------------------------------------------------------------------------------------------------

const int N = 3e5 + 10;
const int M = 1e5 + 10;

int n, m;
struct Interval {
    int l, r, len;
};
vector<Interval> intervals;

const int base = 1<<17;
int seg[base<<1];

void update(int pos, int val) {
    for(int i = base+pos; i >= 1; i >>= 1) seg[i] += val;
}
int query(int l, int r, int u = 1, int L = 0, int R = base-1) {
    if(l == L and r == R) return seg[u];
    int mid = (L+R)>>1;
    if(r <= mid) return query(l, r, u<<1, L, mid);
    if(l > mid) return query(l, r, u<<1|1, mid+1, R);
    return query(l, mid, u<<1, L, mid) + query(mid+1, r, u<<1|1, mid+1, R);
}

int main() {
    cin >> n >> m;
    REP(i, n) {
        int l, r; cin >> l >> r;
        intervals.push_back({l, r, r-l+1});
    }
    sort(intervals.begin(), intervals.end(),
        [&](const Interval& i1, const Interval& i2) {
            return i1.len < i2.len;
        });
    int nex = 0;
    FOR(d, 1, m+1) {
        while(nex < (int)intervals.size() && intervals[nex].len < d) {
            update(intervals[nex].l, 1);
            update(intervals[nex].r+1, -1);
            nex++;
        }
        int ans = n-nex;
        for(int x = d; x <= m; x += d) {
            ans += query(0, x);
        }
        cout << ans << '\n';
    }
}






























Measured memory_bytes: 8176
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip> 
using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define show(...) 42
#endif


#define f first
#define s second
#define endl "\n"
#define pb push_back
#define  oo 0x3f3f3f3f
#define min_ -1e15
#define limit 1000000007
#define two pair<int,int>
#define int long long int
#define ll long long int
#define mod(x,m) ((x%m+m)%m)
#define all(v) v.begin(),v.end()
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define fori(x,n) for(int i = x; i < n; i++)
#define forj(y,m) for(int j = y; j < m; j++)
#define fork(z,p) for(int k = z; k < p; k++)
#define speedforces std::ios::sync_with_stdio(false)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define input_from_file  freopen("input.txt", "r", stdin);


signed main(){
  //input_from_file;
  speedforces;
  int n; cin>>n;
  vector<long double> dp(n+1,0);
  dp[0] = 1;
  for(int coin = 1;coin <= n; coin++){
    long double prb_h; cin>>prb_h;
    for(int i=coin;i>=0;i--)
    dp[i] = (i == 0 ? 0 : dp[i-1]*prb_h)+dp[i]*(1-prb_h);
  }
  long double ans = 0;
  for(int i=1;i<=n;i++){
    if(i > n/2) ans += dp[i];
  }
  cout<<fixed<<setprecision(15)<<ans<<endl;
}


Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]
ABC = [sum([ A[n][i]*B[i] for i in range(M)]) + C for n in range(N)]
res = len([i for i in ABC if i>0])
print(res)

Measured memory_bytes: 3064
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<utility>	// wrap,pair
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR (i,n) for(int i=n;i>0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;

// 最大公約数（ユークリッドの互除法）
int GCD(int x, int y) {
	if (x > y) {
		swap(x, y);
	}
	int r = y % x;
	while (r != 0) {
		y = x;
		x = r;
		r = y % x;
	}
	return x;
}

// 最小公倍数
int LCM(int x, int y) {
	ll gcd = GCD(x, y);
	return x * y / gcd;
}

// 素数判定(素数ならtrue,合成数ならfalse)
bool IsPrime(int num) {
	if (num < 2) return false; // 0,1
	else if (num == 2) return true;	// 2
	else if (num % 2 == 0) return false; // 偶数

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false; // 割り切れたら素数ではない
	}
	return true; // 全部通ったら素数
}

// pairをsecond基準で昇順sort
// sort(vector_name.begin(),vector_name.end(),compare_by_b);
bool compare_by_b(pair<int, int>a, pair<int, int>b) {
	if (a.second != b.second) return a.second < b.second;
	else return a.first < b.first;
}

// ----------------------------------------------------------------

int main(void) {

	ll n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;

	ll tmp = min({a,b,c,d,e});
	if (tmp < n) {
		if (tmp == n || tmp == 1) cout << n / tmp + 4 << endl;
		else cout << n / tmp + 5 << endl;
	}
	else {
		cout << "5" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)
        cout<<(n-2)*(b-a)+1<<endl;
    else
        cout<<0<<endl; 
 } 

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from collections import *
n = int(input())
As = list(map(int,input().split()))

d = Counter()
for a in As:
    d[a] += 1

two = 0
num = 0
for k,v in d.items():
    if v == 1:
        continue
    elif v % 2 == 0:
        two += 1
        num += v // 2 - 1
    else:
        num += v // 2

num += (two + 1) // 2

print(n - (num * 2))


Measured memory_bytes: 18656
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,m,n) for(int i=0;i<n;i++)
int N = 5;
int main(){
	int a[N];
	REP(i,N){
		cin >> a[i];
	}
	int k=0;
	cin >> k;
	bool flag = false ;
	
	REP(i,N){
		REP2(j,i,N){
			if(a[j]-a[i] > k){
				flag = true;
			}
		}
	}
	
	if(flag == true){
		cout << ":("<< endl;
	}else{
		cout << "Yay!"<< endl;
	}
	
	return 0;
}

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

int main(){
  string S, T;
  int A, B;
  string U;

  cin >> S;
  cin >> T;
  cin >> A;
  cin >> B;
  cin >> U;

  if (S == U) A--;
  else B--;

  cout << A << " " << B << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if (b-a==c-b) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21972
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
ll f[3005],inv[3005],S[3005][3005],mi1[3005],mi2[3005],n,mod,ans;
ll ksm(ll x,ll y,ll mod){
	ll anss=1,t=x;
	while(y){
		if(y&1) anss=anss*t%mod;
		t=t*t%mod;
		y>>=1;
	}
	return anss;
}
ll C(ll n,ll m){
	return f[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	scanf("%lld%lld",&n,&mod);
	for(ll i=0;i<=n;i++) mi1[i]=ksm(2,ksm(2,i,mod-1),mod);
	for(ll i=0;i<=n;i++) mi2[i]=ksm(2,i,mod);
	f[0]=1;
	for(ll i=1;i<=n;i++) f[i]=f[i-1]*i%mod;
	inv[n]=ksm(f[n],mod-2,mod);
	for(ll i=n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	S[0][0]=1;
	for(ll i=1;i<=n+1;i++){
		for(ll t=1;t<=i;t++){
			S[i][t]=(S[i-1][t]*t+S[i-1][t-1])%mod;
		}
	}
	for(ll i=0;i<=n;i++){
		ll now=0,qwq=1;
		for(ll t=0;t<=i;t++){
			now=(now+S[i+1][t+1]*qwq)%mod;
			qwq=qwq*mi2[n-i]%mod;
		}
//		cout<<ans<<endl;
		ans=(ans+((i&1)?mod-1:1)*mi1[n-i]%mod*C(n,i)%mod*now)%mod;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 50092
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 93193111451418101
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll a[114514], b[114514], qfront[114514], qback[114514];
ll power(ll a, ll b, ll p) { // aのb乗をpで割ったあまりを計算する関数
  if (b <= 0) {
    return 1;
  }                            // 0乗は1
  if (b % 2 == 0) {            //２の倍数なら省略できて
    ll d = power(a, b / 2, p); //わるう
    return (d * d) % p;        //２割ったので二乗う
  }
  return a * power(a, b - 1, p) % p; //２で割れないなら一個進める
}

int main() {
  string s;
  cin >> s;
  ll qcnt = 0;
  REP(i, (signed)s.size()) {
    if (s[i] == 'A') {
      a[i]++;
    }
    if (s[i] == 'C') {
      b[i]++;
    }
    if (s[i] == '?') {
      qcnt++;
      qfront[i]++;
      qback[i]++;
    }
  }
  REP(i, (signed)s.size()) {
    if (i != s.size() - 1) {
      a[i + 1] += a[i];
      qfront[i + 1] += qfront[i];
    }
  }
  for (int i = (signed)s.size() - 1; i >= 1; i--) {
    b[i - 1] += b[i];
    qback[i - 1] += qback[i];
  }
  ll ret = 0;
  REP(i, (signed)s.size()) {
    if (i == 0 || i == s.size() - 1 || !(s[i] == 'B' || s[i] == '?')) {
      continue;
    }
    if (s[i] == '?') {
      qcnt--;
    }
    ret += (a[i - 1] * b[i + 1] % MOD) * power(3, qcnt, MOD);
    ret += (qfront[i - 1] * b[i + 1] % MOD) * power(3, qcnt - 1, MOD);
    ret += (a[i - 1] * qback[i + 1] % MOD) * power(3, qcnt - 1, MOD);
    ret += (qfront[i - 1] * qback[i + 1] % MOD) * power(3, qcnt - 2, MOD);
    ret %= MOD;

    if (s[i] == '?') {
      qcnt++;
    }
  }
  cout << ret << endl;
}


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

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

signed main() {
    cin >> N >> K;
    vi p(N);
    cin >> p;
    sort(ALL(p));
    REP(i, K) {
        ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll dp[41][401][401];

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

    // input
    ll N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    FOR(i, 0, N){
        cin >> A.at(i);
        cin >> B.at(i);
        cin >> C.at(i);
    }
    
    FOR(i, 0, 41){
        FOR(j, 0, 401){
            FOR(k, 0, 401){
                dp[i][j][k] = inf;
            }
        }
    }
    dp[0][0][0] = 0;
    
    FOR(i, 1, N+1){
        // i番目の薬を使うかどうか
        ll a = A[i-1];
        ll b = B[i-1];
        ll c = C[i-1];

        FOR(j, 0, 401){
            FOR(k, 0, 401){
                dp[i][j][k] = dp[i-1][j][k];
                if(j-a>=0 && k-b>=0){
                    dp[i][j][k] = min(dp[i-1][j][k], dp[i-1][j-a][k-b] + c); 
                }
            }
        }
    }

    ll min_cost = inf;

    FOR(i, 1, 401){
        FOR(j, 1, 401){
            if(j * Ma == i * Mb){
                ll cost = dp[N][i][j];
                min_cost = min(min_cost, cost);
            }
        }
    }

    if(min_cost==inf){
        p(-1);
    }else{
        p(min_cost);
    }
    
    return 0;
}

Measured memory_bytes: 51712
h,w,k = gets.split.map &:to_i
cake = Array.new(h) { gets.chomp }
cut = Array.new(h) { [0] * w }

num = 1
top = 0
left = 0
fill = false

h.times do |i|
  w.times do |j|
    if cake[i][j] == "#"
      fill = true
      top.upto(i) do |y|
        left.upto(j) do |x|
          cut[y][x] = num
        end
      end
      left = j + 1
      num += 1
    elsif j == w - 1
      if fill
        top.upto(i) do |y|
          left.upto(j) do |x|
            cut[y][x] = num - 1
          end
        end
      end
    end
  end
  top = i + 1 if fill
  fill = false
  left = 0
end

unless fill
  top.upto(h-1) do |y|
    0.upto(w-1) do |x|
      cut[y][x] = cut[y-1][x]
    end
  end
end

h.times do |y|
  puts cut[y].join(" ")
end



Measured memory_bytes: 3196
#include <iostream>
//#include <numeric>
#include <vector>
//#include <cstdint>
//#include <string>
//#include <cstdlib>
using namespace std;

int main() {
	//char* array;
	//cin >> array;

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

	for (int i = 0; i < a; i++) {
		for (int j = 0; j < a; j++) {
			if (j != i) {
				n += b[i] * b[j];
			}
		}
	}

	cout << n / 2;

	return 0;

}

Measured memory_bytes: 256
function main(input) {
  input = input.trim();
  const a = input.split(" ").map(Number);
  if(a[0]==a[1]){
    console.log(a[2]);
  }
  else if(a[1]==a[2]){
    console.log(a[0]);
  }
  else if(a[0]==a[2]){
    console.log(a[1]);
  }      
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29568
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
set<ll> s;
void check(ll n, ll d) {
  if (s.find(d) != s.end() || d == 1) return;
  while (n % d == 0) n /= d;
  if (n % d == 1) s.insert(d);
}
int main() {
  ll n; cin >> n;
  ll m = n - 1;
  for (ll i = 1; i * i <= m; ++i) {
    if (m % i == 0) {
      s.insert(i);
      s.insert(m / i);
    }
  }
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      check(n, i);
      check(n, n / i);
    }
  }
  //for (auto x : s) cout << x << " "; cout << endl;
  int ans = s.size() - 1;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
// template {{{

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

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second

using ll = long long;
using ull = unsigned long long;

template<typename T, size_t H, size_t W>
using matrix = std::array<std::array<T, W>, H>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

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

template<typename T>
inline T sq(T x){ return x * x; }

template<typename T, typename U>
inline void chmax(T &x, U y){ x = std::max<T>(x, y); }

template<typename T, typename U>
inline void chmin(T &x, U y){ x = std::min<T>(x, y); }

template<typename T>
inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); }

template<typename T>
inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); }

template<typename T>
inline void unique(T &c){ std::sort(c); c.erase(std::unique(std::begin(c), std::end(c))); }

// }}}

using tp = tuple<int, int, int>;

int conv[256];

int w, h, n;
int sx, sy, gx, gy;
int g[1024][1024];
int dist[1024][1024];

int main()
{
	rep(i, 4) conv["LURD"[i]] = i;

	cin >> w >> h >> n;
	cin >> sx >> sy >> gx >> gy;
	w = w * 2 + 1, h = h * 2 + 1;
	sx *= 2, sy *= 2;
	gx *= 2, gy *= 2;
	
	rep(i, w) rep(j, h){
		if (i & j & 1) g[i][j] = INF;
	}

	rep(i, n){
		int x, y, t;
		string s;
		cin >> x >> y >> t >> s;
		x = x * 2 + 1, y = y * 2 + 1;
		rep(k, t) rep(j, s.size()){
			int dir = conv[s[j]];
			int nx = x + dx[dir];
			int ny = y + dy[dir];
			int nnx = nx + dx[dir];
			int nny = ny + dy[dir];
			if (nnx < 0 || nnx >= w || nny < 0 || nny >= h) continue;
			g[nx][ny]++;
			x = nnx;
			y = nny;
		}
	}

	rep(i, w) rep(j, h) dist[i][j] = INF;
	priority_queue<tp, vector<tp>, greater<tp>> pq;
	dist[sx][sy] = 0;
	pq.emplace(0, sx, sy);
	while (pq.size()){
		int sum, x, y;
		tie(sum, x, y) = pq.top(); pq.pop();
		if (dist[x][y] < sum) continue;
		rep(dir, 4){
			int nx = x + dx[dir];
			int ny = y + dy[dir];
			if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if (dist[nx][ny] > sum + g[nx][ny]){
				dist[nx][ny] = sum + g[nx][ny];
				pq.emplace(sum + g[nx][ny], nx, ny);
			}
		}
	}
	
	cout << dist[gx][gy] << endl;
}

Measured memory_bytes: 13936
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define MSG(x) std::cout << #x << " : " << x << "\n";
using namespace std;
using lint = long long;
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; }

int main()
{
    vector<int> a(3);
    vector<int> b(3);
    rep (i, 3)
    {
        cin >> a[i] >> b[i];
    }

    int cnt[4];
    rep (i, 4)
    {
        cnt[i] = 0;
    }

    rep (i, 3)
    {
        cnt[a[i] - 1]++;
        cnt[b[i] - 1]++;
    }

    rep (i, 4)
    {
        if (cnt[i] >= 3)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;


    return 0;
}


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

int main(){
  ll a,b;
  cin >> a >>b;
  ll x=a*b;
  
  ll tmp;
  if(a<b){
      tmp=a;
      a=b;
      b = tmp;
  }
  
  ll r = a%b;
  while(r!=0){
      a = b;
      b = r;
      r = a%b;
  }
  cout << x/b << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s.resize(unique(all(s)) - s.begin());
    cout << s.size();
}


Measured memory_bytes: 512
import itertools
n=list(str(input()))
ans=0
lst=list(itertools.product(["", "+"], repeat=(len(n)-1)))
for i in range(len(lst)):
  just=""
  for k in range(len(n)-1):        
    just+=n[k]+str(lst[i][k])
  just+=n[len(n)-1]
  ans+=eval(just)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}
	int n,k;
	cin>>n>>k;
	vector<int> s(n);
	while(k--){
		int d; cin>>d;
		while(d--){
			int i; cin>>i; i--;
			s[i]=1;
		}
	}
	int cont=n;
	for(int &x:s)cont-=x;
	cout<<cont<<"\n";

	return 0;	
}



Measured memory_bytes: 3644
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, K, S):
    S = [int(s) for s in S]
    point_l = 0
    point_r = 0
    # decision r
    num_0 = 0 if S[0] == 1 else 1
    flg = S[0]
    for i in range(N):
        if S[i] != flg:
            if flg == 1:
                num_0 += 1
                if num_0 > K:
                    point_r = i - 1
                    break
            flg = S[i]
        if i == N - 1:
            point_r = i
            break
    # measuring method
    ans = point_r - point_l + 1
    while point_r < N - 1:
        # move point_l
        for i in range(0, N):
            if S[point_l + i] != S[point_l + i + 1]:
                if S[point_l + i + 1] == 1:
                    point_l += i + 1
                    break
        # move point_r
        for i in range(1, N):
            if point_r + i == N - 1:
                point_r = N - 1
                break
            if S[point_r + i] != S[point_r + i + 1]:
                if S[point_r + i + 1] == 0:
                    point_r += i
                    break
        ans = max(ans, point_r - point_l + 1)

    print(ans)


if __name__ == '__main__':
    N, K = map(int, input().split())
    S = input()
    solve(N, K, S)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


Measured memory_bytes: 9840