akhauriyash/Code-Regression huggingface dataset:
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Author: z0marlin
Title: b.cpp
Time: 15-08-2019T13:18:05+0530 
I suck at CP T_T
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
#include <bits/stdc++.h>
#if DEBUG
#define dprintf(...) printf(__VA_ARGS__)
#else
#define dprintf(...)
#endif
#define FOR(i, a, n) for(int i = a; i < n; ++i)
#define FORE(a, v) for(auto a:v)
#define MAX(a, b) ((a>b)?a:b)
#define MIN(a, b) ((a<b)?a:b)
#define MP(i, j) make_pair(i, j)
#define PB(a) push_back(a)
#define PPB(a) pop_back(a)
#define all(a) a.begin(), a.end()

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii_t;
typedef pair<ll,ll> pll_t;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;

const int MAX_SZ=1e6+2;
const int MOD=1e9+7;
int t = 1, n, m, q, ql, qr;
char ch;

int lg10(int n){
    int cnt=-1;
    while(n){
        cnt++;
        n/=10;
    }
    return cnt;
}

int solve(){
    int rad = lg10(n);
    int count=0, p=1;
    if(rad%2==0){
        FOR(i,0,rad) p*=10;
        count+=n-p+1;
    }
    dprintf("rad: %d, count: %d\n", rad, count);
    p=9;
    for(int i=0;i<rad;i+=2){
        count+=p;
        p*=100;
    }

	return count;
}

int main(){
	// scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
        printf("%d\n", solve());
    }
}

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

using namespace std;
const int maxn = 1e5+10;
int main()
{
	int n;
	cin >> n;
	string s[maxn];
	int a[3];
	memset(a,0,sizeof(a));
	int cnt = 0;
	for(int i = 0;i < n;i ++){
		cin >> s[i];
		int l =s[i].size();
		for(int j = 1;j < l;j ++){
			if(s[i][j - 1] =='A' && s[i][j] == 'B'){
				cnt ++;
			}
		}
		if(s[i][0] == 'B') a[0] ++;
		if(s[i][l-1] == 'A') a[1]++;
		if(s[i][l-1] == 'A' && s[i][0] =='B') a[2] ++;
	}
	if(a[0] < a[1])  cnt += a[0];
	else cnt += a[1];
	if(a[0] == a[1] && a[1] == a[2] && a[2] != 0) cnt --;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>

using namespace std;
bool used[1000010];
int main(){
	int i,s;
	cin >> s;
	for(i=0;i<=1000000;i++) used[i] = false;
	used[s] = true;
	for(i=0;i<=1000000;i++){
		if(s&1){
			s = 3*s + 1;
			if(used[s]){
				cout << i+2 << endl;
				return 0;
			}
			used[s] = true;
		}else{
			s /= 2;
			if(used[s]){
				cout << i+2 << endl;
				return 0;
			}
			used[s] = true;
		}
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,a,b,rem,ans;
	cin>>n>>a>>b;
	if(a==0)
	{
		cout<<"0"<<endl;
		return 0;
	}
	rem=n%(a+b);
	ans=n/(a+b)*a;
	if(rem==0)
		cout<<ans<<endl;
	else 
	{
		if(rem-a>=0)
			ans+=a;
		else
			ans+=rem;
		cout<<ans<<endl;
	}
	return 0;
}


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

using namespace std;
using ll = long long;

const ll nax = 1e5 + 12;

ll in[nax];

int main() {

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

  ll n, m;
  cin >> n >> m;

  priority_queue<ll>pq;
  for (ll i = 1; i <= n; i++) {
    cin >> in[i];
    pq.push (in[i]);
  }

  while (m--) {
    ll tp = pq.top();
    pq.pop();
    tp /= 2;
    pq.push (tp);
  }

  ll ans = 0;
  while (!pq.empty() ) {
    ans += pq.top();
    pq.pop();
  }

  cout << ans << '\n';

  return 0;
}



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

int main(){
    deque<int> a;
    int q; cin >> q;
    rep(i ,q){
        int m , n , o;
        cin >> m;
        switch (m)
        {
        case 0:
            cin >> n >> o;
            if( n == 0){
                a.push_front(o);
            } else {
                a.push_back(o);
            }
            break;
        
        case 1:
            cin >> m;
            cout << a[m] << endl;
            break;

        case 2:
            cin >> m;
            if( m == 0) a.pop_front();
            else a.pop_back();
            break;
        default:
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 4572
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    X = ri()
    money = 100
    month = 0
    while money < X:
        money += money // 100
        month += 1
    print(month)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 9152
N,W=map(int,input().split())
w=[0 for i in range(N)]
v=[0 for i in range(N)]
t=[[] for i in range(4)]
for i in range(N):
    w[i],v[i]=map(int,input().split())
    t[w[i]-w[0]].append(v[i])
for i in range(4):
    t[i].sort(reverse=True)
ans=0
s=[[0 for j in range(len(t[i])+1)] for i in range(4)]
for i in range(4):
    for j in range(1,len(t[i])+1):
        s[i][j]=s[i][j-1]+t[i][j-1]
for a0 in range(len(s[0])):
    for a1 in range(len(s[1])):
        for a2 in range(len(s[2])):
            for a3 in range(len(s[3])):
                tmp=s[0][a0]+s[1][a1]+s[2][a2]+s[3][a3]
                wt=a0*w[0]+a1*(w[0]+1)+a2*(w[0]+2)+a3*(w[0]+3)
                if wt>W:
                    continue
                if ans<tmp:
                    ans=tmp
print(ans)


Measured memory_bytes: 43756
N,M =  map(int,input().split())
n = [[] for i in range (N)]
for i in range(M):
  p,S = input().split()
  p = int(p)-1
  n[p].append(S)
ans = 0
ac = 0
for j in n:
  count=0
  for i in j:
    if i=="WA":
      count+=1
    else:
      ans+=count
      ac+=1
      break
print(ac,ans)
  

Measured memory_bytes: 20376
n,k = map(int,input().split())
h = [0]*n

for i in range(n):
  h[i] = int(input())
ans = []
h.sort()
for i in range(0,n-k+1):
  ans.append(h[i+k-1]-h[i])
  #print(i,i+k)
print(min(ans))

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

int main() {
  string s;
  cin >> s;
  bool ans = false;
  for(int i = 0; i < s.length()-1; i++) {
    if(s[i] == 'A' && s[i+1] == 'C') {
      ans = true;
    }
  }
  if(ans) 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++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    int c = max(a,b);
    int d = min (a,b);
    REP(i,c) {
        cout << d;
    }


    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int main(){
	int n,m;
	cin>>n>>m;
	vi A(n),B(m);
	rep(i,n)cin>>A[i];
	rep(i,m)cin>>B[i];
	int out=0;
	rep(i,m){
		int t=-1;
		rep(j,n)if(A[j]==B[i]){
			t=j;
			break;
		}
		if(t==-1)continue;
		int I=i;
		for(;t<n;t++)if(A[t]==B[I]){
			I++;
			if(I==m)break;
		}
		out=max(out,I-i);
	}
	cout<<out<<endl;
}

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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define pii pair<int,int>

int main(){
	ll n;
	cin >> n;
	map<string,ll>mp;
	ll ans = 0;
	f(n){
		string s;
		cin >> s;
		sort(s.begin(),s.end());
		ans += mp[s];
		mp[s]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
n = gets.to_i
dp = Array.new(n+1).map{Array.new(3,0)}
n.times do |x|
    a = gets.split.map(&:to_i)
    3.times do |i|
        3.times do |j|
            next if i == j
            dp[x+1][i] = dp[x][j]+a[i] if dp[x+1][i] < dp[x][j]+a[i]
        end
    end
end
puts dp[n].max

Measured memory_bytes: 10108
L = list(input())
n = len(L)
a = []
b = []
for i,l in enumerate(L):
    if l =='R':
        a.append(i)
    else:
        b.append(i)
from bisect import bisect_left
M = []
for i,l in enumerate(L):
    if l=='R':
        j = bisect_left(b,i)
        idx = b[j]
        M.append((l,idx))
    else:
        j = bisect_left(a,i)
        idx = a[j-1]
        M.append((l,idx))
ANS = [0]*n
for i in range(len(M)):
    l,idx = M[i]
    if l=='R':
        if (idx-i)%2==0:
            ANS[idx] += 1
        else:
            ANS[idx-1]+=1
    else:
        if (idx-i)%2==0:
            ANS[idx] += 1
        else:
            ANS[idx+1]+=1
for i,a in enumerate(ANS):
    ANS[i] = str(a)
print(' '.join(ANS))


Measured memory_bytes: 93344
function main(s) {
	n = Number(s.split("\n")[0]);
	a = s.split("\n")[1].split(" ");
	z = 0;
	while (true) {
		b = true;
		for (var i = 0; i < a.length; i++) {
			if (a[i] % 2 === 1) {b = false;}
			a[i] = a[i]/2;
		}
		if (!b) {break;}
		z++;
	}
	console.log(z);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 9420
import java.io.InputStream;
import java.util.Scanner;

public class Main {


	public static void main(String args[]) {
        InputStream inputStream = System.in;
        Scanner sc = new Scanner(inputStream);
        String out;
        String N=sc.next();
        long A = sc.nextLong();
        //int B = sc.nextInt();
        long count=A;
        int last=0;
        StringBuilder K=new StringBuilder();
        for(int i=0;i<N.length();i++) {
        	//System.out.println(N.charAt(i));
        	count-=Math.pow(Character.getNumericValue(N.charAt(i)), 500000000000000L);
        	if(count<=0) {
        		System.out.println(N.charAt(i));
        		break;}
        }
        //System.out.println(K);
        //System.out.println();
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#include <unordered_set>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()

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

using namespace std;
typedef long long ll;
const int INF = 10000000;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for(int i = 0; i < 101; ++i) {
        c = c - b;
        if(c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a = a - d;
        if(a <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
c[];main(n,m,i){for(;scanf("%d%d",&m,&n)*m;puts("")){int q[1024]={i=0},t=1,p=m;for(;n--;)for(*c=!scanf("%s",c+3),++i%3||strcat(c,"Fizz"),i%5||strcat(c,"Buzz"),*c||sprintf(c,"%d",i),strcmp(c+3,c)&&p>1&&(q[t]=p--);q[t=t%m+1];);for(t=i=0;m--;q[++i]||(t=printf(" %d"+!t,i)));}}

Measured memory_bytes: 640
/*
 * a.cpp
 *
 *  Created on: 2019/06/08
 *      Author: MEIP-users
 */




#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <locale>
#include <queue>
#include <tuple>
#include <map>
#include <fstream>

using namespace std;


#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))




int main() {
	int x;
	cin >> x;
	int ans = 0;
	int y = 360;
	while(1){
		ans += floor(y/x);
		if(y%x==0){
			break;
		}else{
			y = 360 + y%x;

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


Measured memory_bytes: 3592
($n,$m)=glob<>;
@a=map~~<>,1..$n;
@b=<>;
for$i(0..$n-$m){
	for$j(0..$n-$m){
		$f=1;
		for$k(0..$m-1){
			$f&=$a[$i+$k]=~/^.{$j}$b[$k]/;
		}
		$s+=$f;
	}
}
print$s?Yes:No


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const int mod = 1e9 + 7;

int main (){
    string s;
    int alfa[26] = {};

    cin >> s;

    for (int i=0; i<s.size(); i++){
        alfa[s[i] - 'a']++;
    }

    for (int i=0; i<26; i++){
        if (alfa[i]%2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

bool ma[1000][1000] = {};
int ans = 0;
int N, M, a[1000], b[1000];

void perm(int *a, int n) {
  if (n == 1) {
    // for (int i = 0; i < N; i++) {
    //   printf("%d ", a[i]);
    // }
    // puts("");
    if (ma[a[0]][a[1]]) {
      ans++;
    }
    return;
  }

  for (int i = 0; i < n; i++) {
    swap(a[i], a[n-1]);

    if (n < N) {
      if (ma[a[n-1]][a[n]]) perm(a, n-1);
    } else {
      if (a[n-1] == 1) perm(a, n-1);
    }

    swap(a[n-1], a[i]);
  }
}

int main(int argc, char *argv[])
{
  vector<int> q[1000];

  cin >> N >> M;

  int c, d;
  for (int i = 0; i < M; i++) {
    cin >> c >> d;
    ma[c][d] = true;
    ma[d][c] = true;
  }

  for (int i = 1; i <= N; i++) a[i-1] = i;
  perm(a, N);

  // for (int i = 0; i < N; i++) {
  //   for (int j = 0; j < M; j++) {
  //   printf("%d ", ma[i][j]);
  //   }
  //   puts("");
  // }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int N, W, w1, b1;
ll ans = 0;
vector<vector<ll>> vv(4, vector<ll>(0));
void dfs(ll x, ll a, ll b) {
  if (x == 4) {
    chmax(ans, a);
    return;
  }

  dfs(x + 1, a, b);
  rep(i, 0, vv[x].size()) {
    if ((w1 + x) * (i + 1) + b > W)
      break;
    dfs(x + 1, a + vv[x][i], b + (w1 + x) * (i + 1));
  }
}

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

  cin >> N >> W;
  cin >> w1 >> b1;
  vv[0].push_back(b1);
  rep(i, 1, N) {
    int a, b;
    cin >> a >> b;
    vv[a - w1].push_back(b);
  }

  rep(i, 0, 4) {
    sort(vv[i].rbegin(), vv[i].rend());
    rep(j, 1, vv[i].size()) vv[i][j] = vv[i][j - 1] + vv[i][j];
  }

  dfs(0, 0, 0);
  cout << ans << 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 ll INF = 1LL<<60;

int main() 
{
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> S(a);
    vector<ll> T(b);
    rep(i,a) cin >> S[i];
    rep(i,b) cin >> T[i];


    auto f = [&](ll x) {
        ll sl = -INF; ll sr = INF;
        ll tl = -INF; ll tr = INF;
        auto itS  = lower_bound(S.begin(), S.end(),x);
        if (itS != S.end()) sr = *itS;
        if (itS - S.begin() > 0) sl = *(--itS);        
        auto itT  = lower_bound(T.begin(), T.end(),x);
        if (itT != T.end()) tr = *itT;
        if (itT - T.begin() > 0) tl = *(--itT);

        auto calc = [&](ll x, ll y) {
            if (x < 0 && y < 0) return abs(min(x, y));
            if (x > 0 && y > 0) return max(x, y);
            return min(abs(x)*2 + abs(y), abs(x) + abs(y)*2);
        };

        ll res = calc(sl-x, tl-x);
        res = min(res, calc(sl-x, tr-x));
        res = min(res, calc(sr-x, tl-x));
        res = min(res, calc(sr-x, tr-x));

       return res;
    };

    rep(i,q) {
        ll x;
        cin >> x;
        cout << f(x) << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

void pr(vector<int> &x, const char c, const char d, const char e) {
	cout << x[0] << c << x[1] << d << x[2] << e << x[3] << "=7" << endl;
}

int main(void) {
	string s;
	cin >> s;
	
	vector<int> x(4);
	for(int i = 0; i < s.size(); ++i) {
		x[i] = (int)(s[i] - '0');
	}
	
	if( x[0] + x[1] + x[2] + x[3] == 7 ) pr(x, '+', '+', '+');
	else if( x[0] - x[1] + x[2] + x[3] == 7 ) pr(x, '-', '+', '+');
	else if( x[0] - x[1] - x[2] + x[3] == 7 ) pr(x, '-', '-', '+');
	else if( x[0] - x[1] - x[2] - x[3] == 7 ) pr(x, '-', '-', '-');
	else if( x[0] + x[1] - x[2] - x[3] == 7 ) pr(x, '+', '-', '-');
	else if( x[0] + x[1] + x[2] - x[3] == 7 ) pr(x, '+', '+', '-');
	else if( x[0] + x[1] - x[2] + x[3] == 7 ) pr(x, '+', '-', '+');
	else if( x[0] - x[1] + x[2] - x[3] == 7 ) pr(x, '-', '+', '-');
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-12;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

void NO() {
    cout << "No\n";
    exit(0);
}

void run() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    if (H % h == 0 && W % w == 0) NO();
    cout << "Yes\n";
    if (H % h != 0) {
        rep(i, 0, H) {
            rep(j, 0, W) {
                if (i % h == 0) cout << 1000 * (h - 1) - 1 << " ";
                else cout << -1000 << " ";
            }
            cout << "\n";
        }
    } else {
        rep(i, 0, H) {
            rep(j, 0, W) {
                if (j % w == 0) cout << 1000 * (w - 1) - 1 << " ";
                else cout << -1000 << " ";
            }
            cout << "\n";
        }
    }
}


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

 
 
//----------------------------MACROS-------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 1e6 + 1;//                                                             |
//----------------------------------------------------------------------------------


void solve()
{
    
    ll n;cin>>n;
    
    ll dp[3][n];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        if(i>0){
            for(int j=0;j<3;j++){
                for(int k=0;k<3;k++){
                    if(j!=k){
                        dp[j][i]=max(dp[j][i],dp[k][i-1]);
                    }
                }
            }
        }
        dp[0][i]+=a;
        dp[1][i]+=b;
        dp[2][i]+=c;
    }
    ll ans=0;
    for(int i=0;i<3;i++){
        ans=max(ans,dp[i][n-1]);
    }
    cout<<ans<<"\n";
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    
	return 0;
}

Measured memory_bytes: 5980
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	n := [...]int{111, 222, 333, 444, 555, 666, 777, 888, 999}
	for i := 0; i < len(n); i++ {
		if N > n[i] {
			continue
		} else {
			fmt.Println(n[i])
			break
		}
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define hell 1000000007
#define PI 3.14159265358979323846
#include <fstream>
using namespace std;
vector<ll> adj[100005];
ll vis[100005];
stack<ll> st;
void dfs(ll x)
{
    vis[x]=1;
    for(ll i=0;i<adj[x].size();i++)
        if(!vis[adj[x][i]])
        dfs(adj[x][i]);
    st.push(x);
}
int main()
{
    //  freopen("timber_input.txt", "r", stdin);
   // freopen("out3_test.txt", "w", stdout);
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--) {
    ll n,m,i,j;
    cin>>n>>m;
    ll x,y;
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
    }
    for(i=1;i<=n;i++)
        vis[i]=0;
     ll dis[n+5];
    for(i=1;i<=n;i++)
        dis[i]=0;
    for(i=1;i<=n;i++)
    {
        if(!vis[i])
            dfs(i);

    }
    while(!st.empty())
        {
            x=st.top();
            st.pop();
         //   cout<<x<<"\n";
            for(j=0;j<adj[x].size();j++)
                if(dis[adj[x][j]]<dis[x]+1)
                dis[adj[x][j]]=dis[x]+1;
        }
    ll ans=0;
    for(i=1;i<=n;i++)
    ans=max(ans,dis[i]);
    cout<<ans;

    }

}


Measured memory_bytes: 13520
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

int main(void){
  int n;
  cin >> n;
  vector<int> d(n);
  REP(i, n) cin >> d[i];
  sort(ALL(d));
  int c = n/2 -1;
  cout << d[c+1] - d[c] << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
vector<ll> a,b;
ll B=0;

void solve(){
    cin >> n;
    a.resize(n,0);b.resize(n,0);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    while (true){
        int change=0;
        rep(i,n){
            ll x=b[(n+i-1)%n],y=b[(n+i+1)%n];
            if (b[i]<x+y) continue;
            if (a[i]==b[i]) continue;
            change+=1;
            ll t=b[i]%(x+y);
            if (t<a[i]){
                ll p=b[i]-a[i];
                if (p%(x+y)!=0) {
                    B=-1;
                }
                B+=p/(x+y);
                b[i]=a[i];
            }
            else{
                B+=b[i]/(x+y);
                b[i]=t;
            }
            
        }
        if (change==0 || B==-1) break;
    }

    bool pos=true;
    rep(i,n) {
        if (a[i]!=b[i]) {
            pos = false;
        }
    }
    if (pos) cout << B << endl;
    else cout << -1 << endl;
    

}

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

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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> sai(N, vector<int>(2));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> sai.at(i).at(j);
        }
    }
    int h = 0;

    for (int i = 0; i < (N - 2); i++) {
        if (sai.at(i).at(0) == sai.at(i).at(1) && sai.at(i + 1).at(0) == sai.at(i + 1).at(1) && sai.at(i + 2).at(0) == sai.at(i + 2).at(1)) {
            h++;
        }
        else {
            continue;
        }
    }
    if (h == 0) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}

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

string a[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int main(){
    string S;cin>>S;
    int ans;
    rep(i,7)if(S==a[i])ans=7-i-1;
    if(ans==0)ans=7;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
n,p = map(int, input().split())
s = input()
ans = 0
ruisekiwa = [0]*(n+1)
ten = 1

if 10 % p == 0:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    for i in range(0, n)[::-1]:
        a =  int(s[i]) * ten % p
        ruisekiwa[i] = (ruisekiwa[i+1] + a) % p
        ten *= 10
        ten %= p

    cnt = [0]*p
    for i in range(0, n+1)[::-1]:
        ans += cnt[ruisekiwa[i]]
        cnt[ruisekiwa[i]] += 1

print(ans)


Measured memory_bytes: 11076
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
int t[30][200001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, C;
    cin >> N >> C;
    REP(i, C){
        REP(j, 200001){
            t[i][j] = 0;
        }
    }
    REP(i, N){
        int s, e, c;
        cin >> s >> e >> c;
        s*=2; e*=2;
        s--;
        t[c-1][s]++;
        t[c-1][e]--;
    }
    REP(i, C){
        REP(j, 200000){
            t[i][j+1] = t[i][j+1] + t[i][j];
            //cout << t[i][j];
        }
        REP(j, 200001){
            t[i][j] = min(t[i][j], 1);
            //cout << t[i][j];
        }
        //cout << "\n";
    }
    int ans = -1;
    REP(i, 200001){
        int tmp = 0;
        REP(j, C){
            tmp += t[j][i];
        }
        ans = max(ans, tmp);
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <vector>
using namespace std;
const int N = 100000 + 10;
int n,m;
int a[N];
int main() {
    scanf("%d%d",&n,&m);
    if(n==1) {
        printf("1\n1\n1\n"); return 0;
    }
    vector<int> odd,even;
    for(int i=1;i<=m;i++) {
        scanf("%d",&a[i]);
        if(a[i]&1) odd.push_back(a[i]);
        else even.push_back(a[i]);
    }
    if(m==1) {
        printf("%d\n", a[1]);
        printf("2\n");
        printf("%d %d\n", a[1]-1,1);
        return 0;
    }
    vector<int> res;
    if(n%2 == 0) {
        if(odd.size() > 2) {
            return !printf("Impossible\n");
        }
        vector<int> v;
        if(odd.size() == 2) {
            v.push_back(odd[0]);
            for(auto x: even) v.push_back(x);
            v.push_back(odd[1]);
        } else {
            for(auto x: even) v.push_back(x);
        }
        for(auto x: v) printf("%d ", x); printf("\n");
        for(int i=0;i<v.size();i++) {
            if(i==0) {
            if(v[i]>1) res.push_back(v[i]-1);//printf("%d ", v[i]-1);
            }else if(i==(int)v.size()-1) res.push_back(v[i]+1);
            else res.push_back(v[i]);
        }
    } else {
        if(odd.size() > 1) {
            return !printf("Impossible\n");
        }
        vector<int> v;

        v.push_back(odd[0]);
        for(auto x: even) v.push_back(x);
        for(auto x: v) printf("%d ", x); printf("\n");
        for(int i=0;i<v.size();i++) {
            if(i==0) {
                if(v[i]>1) res.push_back(v[i]-1);
            }
            else if(i==(int)v.size()-1) res.push_back(v[i]+1);
            else res.push_back(v[i]);
        }
    }
    printf("%d\n", res.size());
    for(auto x: res) {
        printf("%d ", x);
    }

}


Measured memory_bytes: 888
import copy
N = int(input())
lst1 = list(input().split())
lst2 = copy.copy(lst1)

def bubble_sort(lst):
    for i in range(N):
        for j in range(N-1,i,-1):
            if (int(lst[j][1]) < int(lst[j-1][1])):
                lst[j],lst[j-1] = lst[j-1],lst[j]
    return lst
    
def selection_sort(lst):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if (int(lst[j][1]) < int(lst[minj][1])):
                minj = j
        lst[i],lst[minj] = lst[minj],lst[i]
    return lst

res1 = " ".join(bubble_sort(lst1))
res2 = " ".join(selection_sort(lst2))
print(res1)
print('Stable')
print(res2)
if (res1 == res2):
    print('Stable')
else:
    print('Not stable')


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

int n, a[4003][2], b[2003][2], c[4003][2003][2], dp[2003][2003];
char ch;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= 2 * n; ++i) {
		cin >> ch >> a[i][1];
		a[i][0] = ch == 'B' ? 0 : 1;
		b[a[i][1]][a[i][0]] = i;
	}
	for(int i = 2 * n; i >= 1; --i) {
		for(int j = 1; j <= n; ++j) {
			c[i][j][0] = c[i + 1][j][0];
			c[i][j][1] = c[i + 1][j][1];
		}
		++c[i][a[i][1]][a[i][0]];
	}
	for(int i = 1; i <= 2 * n; ++i) {
		for(int j = 2; j <= n; ++j) {
			c[i][j][0] += c[i][j - 1][0];
			c[i][j][1] += c[i][j - 1][1];
		}
	}
	for(int i = 0; i <= n; ++i) {
		for(int j = 0; j <= n; ++j) {
			if(i + j) dp[i][j] = 1e9;
			if(i) {
				dp[i][j] = dp[i - 1][j] + (b[i][0] - (i + j) + (c[b[i][0]][i - 1][0] + c[b[i][0]][j][1]));
			}
			if(j) {
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j][1] - (i + j) + (c[b[j][1]][i][0] + c[b[j][1]][j - 1][1])));
			}
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}


Measured memory_bytes: 78592
#include <cstdio>
#include <cstring>
#include <vector>

const int N = 71;
const int N2 = 36;
const int M = 200;
const int MOD = (int)1e9 + 7;

int fact[N], inv_fact[N], binom[M][M], n, m, dp[N2][N2];
char s[N];

void update(int& x, int a)
{
    x += a;
    if (x >= MOD) {
        x -= MOD;
    }
}

int main()
{
#ifdef LOCAL_JUDGE
    freopen("F.in", "r", stdin);
#endif
    fact[0] = inv_fact[0] = inv_fact[1] = 1;
    for (int i = 2; i < N; ++ i) {
        inv_fact[i] = 1LL * (MOD - MOD / i) * inv_fact[MOD % i] % MOD;
    }
    for (int i = 1; i < N; ++ i) {
        fact[i] = 1LL * i * fact[i - 1] % MOD;
        inv_fact[i] = 1LL * inv_fact[i] * inv_fact[i - 1] % MOD;
    }
    for (int i = 0; i < M; ++ i) {
        binom[i][0] = 1;
        for (int j = 1; j <= i; ++ j) {
            binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % MOD;
        }
    }
    scanf("%d%d%s", &n, &m, s);
    int result = 1;
    for (int ab = 0; ab * 2 <= m; ++ ab) {
        for (int a = !ab; ab * 2 + a <= m; ++ a) {
            std::vector<int> sz(ab);
            int cnt_ab = 0, cnt_a = 0;
            for (int i = 0; i < m; ++ i) {
                if (s[i] == 'r') { // A
                    if (cnt_ab + cnt_a < ab + a) {
                        cnt_a ++;
                    } else if (cnt_ab) {
                        sz[ab - cnt_ab] ++;
                    }
                } else {
                    if (cnt_a && cnt_ab < ab) {
                        cnt_a --;
                        cnt_ab ++;
                    } else if (cnt_ab) {
                        sz[ab - cnt_ab] ++;
                    }
                }
            }
            if (cnt_ab != ab || cnt_a != a) {
                continue;
            }
            for (int i = 1; i < ab; ++ i) {
                sz[i] += sz[i - 1];
            }
            memset(dp, 0, sizeof(dp));
            dp[0][0] = 1LL * fact[ab + a] * inv_fact[a] % MOD;
            for (int q = 0; 2 * q - 1 <= n; ++ q) {
                for (int cnt = ab; cnt >= 0; -- cnt) {
                    for (int used = (n + 1 >> 1) - cnt; used >= 0; -- used) {
                        for (int k = 1; cnt + k <= ab && (cnt + k + used + k * q << 1) - 1 <= n && used + k * q <= sz[cnt + k - 1]; ++ k) {
                            update(dp[cnt + k][used + k * q], 1LL * dp[cnt][used] * inv_fact[k] % MOD);
                        }
                    }
                }
            }
            for (int used = (n + 1 >> 1) - ab; used >= 0; -- used) {
                int parts = ab + a;
                int occ = (used * 2 + ab) + a + (parts - 1);
                int balls = n - occ;
                int boxes = (2 * used + 3 * ab) + a + (parts + 1);
                update(result, 1LL * binom[balls + boxes - 1][boxes - 1] * dp[ab][used] % MOD);
            }
        }
    }
    printf("%d\n", result);
}

Measured memory_bytes: 384
from bisect import*
class SqrtSet:
    def __init__(self,block_limit=201):
        self.key=[]
        self.child=[[]]
        self.block_limit=block_limit
    def le(self,key):
        ret=key
        i=bisect_left(self.key,key)
        if i:ret=self.key[i-1]
        block=self.child[i]
        i=bisect_left(block,key)
        if i:ret=block[i-1]
        return ret
    def ge(self,key):
        ret=key
        i=bisect(self.key,key)
        if i<len(self.key):ret=self.key[i]
        block=self.child[i]
        i=bisect(block,key)
        if i<len(block):ret=block[i]
        return ret
    def insert(self,key):
        i=bisect(self.key,key)
        block=self.child[i]
        insort(block,key)
        if len(block)==self.block_limit:
            sep=self.block_limit//2
            self.key.insert(i,block[sep])
            self.child.insert(i+1,block[sep+1:])
            self.child[i]=block[:sep]
def main():
    n,*p=map(int,open(0).read().split())
    l=[0]*n
    for i,v in enumerate(p,1):l[v-1]=i
    t=SqrtSet()
    insert,le,ge=t.insert,t.le,t.ge
    insert(0),insert(n+1)
    a=0
    for i,v in list(enumerate(l,1))[::-1]:
        f,b=ge(v),le(v)
        g,c=ge(f),le(b)
        a+=i*((f-v)*(b-c)+(v-b)*(g-f))
        insert(v)
    print(a)
main()

Measured memory_bytes: 22472
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a == 7 && b == 5 && c == 5){
		cout << "YES" << endl;
		return 0;
	}
	if(b == 7 && a == 5 && c == 5){
		cout << "YES" << endl;
		return 0;
	}
	if(c == 7 && b == 5 && a == 5){
		cout << "YES" << endl;
		return 0;
	}
	else{
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
string = input()
n = int(input())
for i in range(n):
    inp = [x for x in input().split()]
    a = int(inp[1])
    b = int(inp[2])
    if inp[0] == 'print':
        print(string[a:b+1])
    elif inp[0] == 'reverse':
        string = string[:a] + string[a:b+1][::-1] +string[b+1:]
    else:
        string = string[:a] + inp[3] + string[b+1:]



Measured memory_bytes: 5616
w,h,n=map(int,input().split())
x_1=[0]
x_2=[w]
y_1=[0]
y_2=[h]

for _ in range(n):
    tmp_x,tmp_y,tmp_a=map(int,input().split())
    if tmp_a==1:
        x_1.append(tmp_x)
    elif tmp_a==2:
        x_2.append(tmp_x)
    elif tmp_a==3:
        y_1.append(tmp_y)
    elif tmp_a==4:    
        y_2.append(tmp_y)
        
ans=max(0,(min(x_2)-max(x_1)))*max(0,(min(y_2)-max(y_1)))

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
string N;
//---------------------------------------------------------------------------------------------------
int g[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1};
int memo[1010110][2];
int f(int i, int j) { // =[0,i]円+j円を支払う最小枚数
    if (i < 0) {
        if(j == 0) return 0;
        else return 1;
    }
    if (0 <= memo[i][j]) return memo[i][j];

    int res = inf;
    rep(d, 0, 10) {
        int n = N[i] - '0' + j;

        int sm = g[d];
        if (d < n) sm += f(i - 1, 1) + g[10 + d - n];
        else sm += f(i - 1, 0) + g[d - n];

        chmin(res, sm);
    }

    return memo[i][j] = res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, 1010110) rep(j, 0, 2) memo[i][j] = -1;
    cout << f(N.length() - 1, 0) << endl;
}


Measured memory_bytes: 89372
n = int(input())
A = list(map(int, input().split()))
s, t = sum(A), n * (n + 1) // 2
if s % t != 0:
    print('NO')
else:
    k = s // t
    D = [A[i+1] - A[i] for i in range(n-1)] + [A[0] - A[-1]]
    D = [d - k for d in D]
    print('YES' if all((d <= 0 and d % n == 0 for d in D)) else 'NO')


Measured memory_bytes: 14260
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ll long long int
#define ld double
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define be begin
#define sz(a) (ll)a.size()
#define INF 1e18
 
typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
 
ll mod=1e9+7;
// ll gcd(ll a, ll b){
//     if(a<b) swap(a,b);
//     if(b==0) return a;
//     return gcd(b,a%b);
// }
 
// ll fun(ll x, ll y){
//     ll rem=1;
//     while(y!=0){
//         if(y%2==1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y/=2;
//     }
//     return rem;
// }




int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin>>n>>k;
	ll x[n+1][n+1],t[n+1][n+1],rem[n+1][n+1];
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			if(i==j) rem[i][j]=1; else rem[i][j]=0;
			cin>>x[i][j];
		} 
	}
	while(k!=0){
		if(k&1){
			for(ll i=1;i<=n;i++){
				for(ll j=1;j<=n;j++){
					t[i][j]=0;
				}
			}
			for(ll i=1;i<=n;i++){
				for(ll j=1;j<=n;j++){
					for(ll k=1;k<=n;k++){
						t[i][j]=(t[i][j]+rem[i][k]*x[k][j])%mod;
					}
				}
			}
			for(ll i=1;i<=n;i++){
				for(ll j=1;j<=n;j++){
					rem[i][j]=t[i][j];
				}
			}
		}
		for(ll i=1;i<=n;i++){
			for(ll j=1;j<=n;j++){
				t[i][j]=0;
			}
		}
		for(ll i=1;i<=n;i++){
			for(ll j=1;j<=n;j++){
				for(ll k=1;k<=n;k++){
					t[i][j]=(t[i][j]+x[i][k]*x[k][j])%mod;
				}
			}
		}
		for(ll i=1;i<=n;i++){
			for(ll j=1;j<=n;j++){
				x[i][j]=t[i][j];
			}
		}
		k/=2;
	}
	ll ans=0;
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			ans=(ans+rem[i][j])%mod;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int join = a * (int) Math.pow(10, (int) Math.log10(b) + 1) + b;
		System.out.println(IntStream.rangeClosed(1, 317).anyMatch(i -> join == i * i) ? "Yes" : "No");
	}
}


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

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int N = 21;
const int Mod = 1e9 + 7;

int n, m, q;
int dp[2][N][1 << 19];
bool ban[N][N][2];

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

int main(){	
	scanf("%d%d%d", &n, &m, &q);
	while(q--){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		ban[a][b][c ^ 1] = true;
	}

	int s = 0, P = (1 << (n - 1)) - 1;
	dp[0][0][0] = 1;
	For(i, 1, m){
		For(j, 0, n - 2){
			int msk = (1 << j) - 1;
			For(k, 0, P){
				int &val = dp[s][j][k];
				if(!val) continue;

				if(!(k & (1 << j)) && !ban[i][j + 1][0])
					add(dp[s][j + 1][k], val);
				if(!ban[i][j + 1][1]){
					if(k & (1 << j))
						add(dp[s][j + 1][k], val);
					else{
						int a = k & (P ^ msk), b = (k & msk) | (1 << j);
						a -= a & (-a);
						add(dp[s][j + 1][a | b], val);
					}
				}

				val = 0;
			}
			if(j == n - 2) For(k, 0, P) dp[s ^ 1][0][k] = dp[s][n - 1][k], dp[s][n - 1][k] = 0;
		}
		s ^= 1;
	}

	int ans = 0;
	For(i, 0, P) add(ans, dp[s][0][i]);
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 86272
n = int(input())
arr = list(map(int, input().split()))
total = 1
if 0 in arr:
    print(0)
else:
    for num in arr:
        if total > 10**18:
            break
        total *= num
    if total > 10**18:
        print(-1)
    else:
        print(total)

Measured memory_bytes: 84656
char buf[5];
sz;
N;
char fs[]="1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n6\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n7\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n6\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n8\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n6\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n7\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n6\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n9\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n6\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n7\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n6\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n8\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n6\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n7\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n6\n1\n2\n1\n3\n1\n2\n1\n4\n1\n2\n1\n3\n1\n2\n1\n5\n1\n2\n1\n";
main(){
	read(0,buf,5);
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(;--N;)write(1,fs,2*N);
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
const int MOD = 998244353;

ll A[200010];
ll B[200010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = A[i] - i;
	}
	ll ans = 0;
	sort(B, B + N);
	ll b = B[N / 2];
	for (int i = 0; i < N; i++) {
		ans += abs(A[i] - (b + i));
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
s=input()+"X"
t=["A","G","T","C"]
ans=0
c=0
f=False
for i in s:
  if i in t:
    if f:
      c+=1
    else:
      f=True
      c=1
  else:
    f=False
    ans=max(ans,c)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include<string.h>
#include <algorithm>
#include<vector>
using namespace std;
const int maxn = 5000+10;
bool g[1010][1010]= {0};
struct Edge {
	int to, nxt;
} e[maxn];
int head[maxn], cnte=1;
int n, m;
inline void add(const int& from, const int& to) {
	++cnte;
	e[cnte].to = to;
	e[cnte].nxt = head[from];
	head[from] = cnte;
}
int path[maxn];
int vi;
int depth[maxn];
void clear() {
	memset(path,0,sizeof(path));
	memset(depth,-1,sizeof(depth));
}
int sum=100000;
vector<int> ans;

void dfs(int u,int f,int dis) {
	depth[u]=dis;
	for(int i=head[u]; i; i=e[i].nxt) {
		
		int nv = e[i].to;
		if(depth[nv]==-1) {
			path[nv]=u;
			dfs(nv,f,dis+1);
		} else {
			if(nv==f) {
				path[nv]=u;
				if(sum>depth[u]) {
					ans.clear();
					sum=depth[u];
					while(path[nv]!=f) {
						ans.push_back(nv);
						nv=path[nv];
					}
					ans.push_back(nv);
				}
			} else if(depth[nv]>depth[u]+1) {
				path[nv]=u;
				dfs(nv,f,dis+1);
			}
		}
	}
}
int main() {
	memset(head,0,sizeof(head));
	cin>>n>>m;
	for(int i=0; i<m; i++) {
		int u,v;
		cin>>u>>v;
		g[u][v]=1;
		add(u,v);
	}
	for(int i=1; i<=n; i++) {
		clear();
		dfs(i,i,1);
	}
	if(sum==1e5)cout<<"-1";
	else {
		cout<<sum<<endl;
		for(int i=0; i<ans.size(); i++)
			cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 1408