akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

int main(){
    while(1){
        int R, C;
        cin >> R >> C;
        if(R == 0 && C == 0) break;

        bool osenbei[R][C]; // 1 no, 0 ok
        FOR(i,0,R) FOR(j,0,C) cin >> osenbei[i][j];

        // ??¨??¢?´¢
        int ans = 0;
        FOR(i,0,1<<R){
            int omote = 0;
            bool change[R];
            FOR(j,0,R) change[j] = false;
            FOR(j,0,R) if((i >> j) & 1) change[j] = true; // ?£???????
            FOR(j,0,C){
                int o = 0;
                FOR(ii,0,R) o += (osenbei[ii][j] ^ change[ii]) ? 0 : 1;
                omote += max(o, R - o);
            }
            ans = max(ans, omote);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3152
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

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

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#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 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 arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int A, B, X;
	cin >> A >> B >> X;

	if ( ( A <= X ) && ( X <= A + B ) )
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> xx(n);
  vector<int> yy(m);
  bool flag = true;
  for (int i = 0; i < n; i++) cin >> xx[i];
  for (int i = 0; i < m; i++) cin >> yy[i];
  sort(xx.begin(), xx.end());
  sort(yy.begin(), yy.end());
  if (xx[n - 1] >= yy[0] || yy[0] <= x || xx[n - 1] >= y) flag = false;
  if (flag) cout << "No War" << endl;
  else cout << "War" << endl;
}


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

int main(){
    int N, Q;
    int l, r;
    int ACcounter[100002] = {};
    string S;

    cin >> N >> Q >> S;
    char state = '$';
    for(int i=1;i<=N;i++){
        if(state == 'A' && S[i-1] == 'C'){
            ACcounter[i] = ACcounter[i-1] + 1;
        }
        else{
            ACcounter[i] = ACcounter[i-1];
        }
        state = S[i-1];
    }
    // for(int i=0;i<=N;i++) cout << ACcounter[i] << " ";
    // cout << endl;
    for(int i=0;i<Q;i++){
        cin >> l >> r;
        cout << ACcounter[r] - ACcounter[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define ll long long

#define INF 1e9;
#define N 1001000

vector<int> A, B, odd;
int dp1[N], dp2[N];

void init(){
    A.push_back(1);
    B.push_back(1);
    odd.push_back(1);

    for(int i = 1;; i++){
        int x = A[i-1] + (i + 1);
        if(x > N) break;
        else A.push_back(x);
    }
    for(int i = 1;; i++){
        int x = B[i-1] + A[i];
        if(x > N) break;
        else B.push_back(x);
        if(x % 2 == 1) odd.push_back(x);
    }

    rep(i,N) dp1[i] = INF;
    rep(i,N) dp2[i] = INF;
    dp1[0] = 0, dp2[0] = 0;
    for(int i = 0; i < B.size(); i++){
        for(int j = 1; j < N; j++){
            if(j - B[i] >= 0){
                dp1[j] = min(dp1[j],dp1[j - B[i]] + 1);
            }
        }
    }
    for(int i = 0; i < odd.size(); i++){
        for(int j = 1; j < N; j++){
            if(j - odd[i] >= 0){
                dp2[j] = min(dp2[j],dp2[j - odd[i]] + 1);
            }
        }
    }
}

int main() {
    init();
    while(true){
        int n;
        cin >> n;
        if(n == 0) return 0;

        cout << dp1[n] << " " << dp2[n] << endl;
    }
}



Measured memory_bytes: 10856
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) begin(v), end(v)
using std::cin;
using std::cout;
using pii = std::pair<int, int>;
const int MAXN = 1e5 + 10;
int a[MAXN];

std::vector<int> G[MAXN];

void change(int L, int R, int v) {
    //cout << L << '-'<<R<<"\n";
    (a[L] += v) %= 26;
    (a[R + 1] -= v) %= 26;
}

void solve() {
    std::string s;
    cin >> s;
    int n = s.length();
    for (int i = 0; i + i < n; ++i) {
        change(i + 1, i + 1, s[i] - s[n - i - 1]);
    }
    int m; cin >> m;
    std::vector<pii> ls;
    double mm = 0.5 * (n + 1);
    for (int i = 0, x, y; i < m; ++i) {
        cin >> x >> y;
        if (x > mm  && y > mm) {
            x = n - x + 1;
            y = n - y + 1;
            std::swap(x, y);
        }
        if (x <=mm && y >mm) {
            y = n - y + 1;
            if (x == y) continue;
            if (x > y) std::swap(x, y);
            y--;
        }
        G[x].push_back(y);
    }
    for (int i = 1; i + i <= n; ++i) {
        if (!G[i].empty()) {
            std::sort(all(G[i]));
            G[i].erase(std::unique(all(G[i])), end(G[i]));
            int k = G[i].size();
            change(i, G[i][0], -a[i]);
            for (int j = 1; j < k; ++j) {
                G[G[i][j - 1] + 1].push_back(G[i][j]);
            }
        }
        if (a[i] != 0) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}

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


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int C[N],S[N],F[N];
    for(int i = 0;i < N-1;i++){
        cin >> C[i] >> S[i] >> F[i];
    }
    for(int i = 0;i < N;i++){
        if(i != N-1){
        long long int ans = 0;
        int memo = i+1;
        for(int t = 1;1;t++){
            if(S[memo-1] <= t && t%F[memo-1] == 0){ 
                t = t + C[memo-1];
                memo++;  
                if(memo == N){
                ans = t;
                break;
                }
                t--;
            }
        }
        cout << ans << endl;
    }
    }
    long long int a = 0;
    cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int pos1,pos2;
bool flag = 0;
string s;
cin>>s;
if(s.size() == 2){
    if(s[0]==s[1])
        cout<<1<<" "<<2<<endl;
    else
        cout<<-1<<" "<<-1<<endl;
    return 0;
}
for(int i = 0 ; i<s.size()-2; i++){
    if(s[i] == s[i+1] || s[i+1]==s[i+2] || s[i+2]==s[i]){
        pos1 = i+1;
        pos2 = i+3;
        flag = 1;
        break;
    }
}
if(flag == 0)
    cout<<-1<<" "<<-1<<endl;
if(flag == 1)
    cout<<pos1<<" "<<pos2<<endl;

}


Measured memory_bytes: 512
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d%d",&x,&y);
	if(x==1&&y==1)
	{
		printf("%d",1);
	}
	else if(x==1)
	{
		printf("%d",y-2);
	}
	else if(y==1)
	{
		printf("%d",x-2);
	}
	else
	{
		printf("%lld",1ll*(x-2)*(y-2));
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A[51];
int main() {
	int a,x;
	double b;
	cin>>a;
	for(int i=1;i<=a;i++)cin>>A[i];
	sort(A+1,A+a+1),b=A[1];
	for(int i=2;i<=a;i++)b=(b+A[i])/2;
	printf("%.6f",b);
}

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

using namespace std;

int a, b;

int main()
{
    cin >> a >> b;
    if(a > b)
    {
        for(int i = 0; i < a; i++) cout << b;
    }
    else
    {
        for(int i = 0; i < b; i++) cout << a;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
ab.sort()
ans = 0
now = 1
for i in range(m):
	if now <= ab[i][0]:
		ans += 1
		now = ab[i][1]
	now = min(now, ab[i][1])
print(ans)

Measured memory_bytes: 27620
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[2] = {-1, 1};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i < sqrt(n); i++){
        if(n%i==0 && n%(n/i-1)!=0){
            ans+=n/i-1;
            //cout << i << endl;
        }
    }
    cout << ans << endl;
    //for(ll i = 0; i < a.size(); i++)
      //  cout << a[i] << endl;
    return 0;
}


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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
void solve(void)
{
    vector<string> s(3);
    rep(i, 3) cin >> s[i];
    rep(i, 3) cout << s[i][i];
    cout << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3608
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	ll n;cin>>n;
	vi a(n+1);
	rep(i,0,n+1) cin>>a[i];

	if(n==0)
	{
		if(a[0]==1) cout<<1<<"\n";
		else cout<<"-1\n";
		return 0;
	}

	if(a[0]!=0)
	{
		cout<<"-1\n";
		return 0;
	} 

	vi nl(n+1,inf);
	nl[0]=1;
	ll pos=1;
	ll ans = 0;
	rep(i,1,n+1)
	{
		ll mx_nodes = (nl[i-1]>=1e15?inf:2*nl[i-1]);
		if(a[i]>mx_nodes) pos=0;
		else nl[i] = mx_nodes - a[i];
	}

	// debug_v(nl);
	ll f=1;
	repr(i,n,-1)
	{
		nl[i] =  min(nl[i],(i+1<=n ?a[i+1]+nl[i+1]:0));
		ans += nl[i]+a[i];
		if(i!=n && nl[i]==0) pos=0;
		if(i>=40 || (nl[i]+a[i]<=(1ll<<i))) f=0;
		else pos=0;
	}

	if(pos==0) cout<<"-1";
	else cout<<ans;


	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
string str;
bool ok=true;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str;
	rep(sz(str)){
		if(str[i]=='L'&&i%2==0) ok=false;
		if(str[i]=='R'&&i%2==1) ok=false;
	}
	print1(ok?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
ans = 0
me = []
for i in range(N):
    if T[i] == "r":
        ans += P
        log = P
        me.append("p")
    elif T[i] == "s":
        ans += R
        log = R
        me.append("r")
    else:
        ans += S
        log = S
        me.append("s")
    if i>=K:
        if me[i] == me[i-K]:
            ans -= log
            if (i+K) < N:
                if T[i+K] == "r":
                    if me[i-K] != "s":
                        me[i] = "s"
                    else:
                        me[i] = "r"
                if T[i+K] == "s":
                    if me[i-K] != "p":
                        me[i] = "p"
                    else:
                        me[i] = "s"
                if T[i+K] == "p":
                    if me[i-K] != "r":
                        me[i] = "r"
                    else:
                        me[i] = "p"
print(ans)

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

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d)
		cout<<"Yes";
	else
	{
		if(abs(a-b)<=d && abs(b-c)<=d)
			cout<<"Yes";
		else
			cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, a, b;std::cin >> n >> a >> b;
  vll h(n);re(i,n) std::cin >> h[i];
  sort(h.begin(), h.end());
  ll l = 0, r = 1000000001;
  while(r-l>1){
    ll mid = (l+r)/2;
    ll i = upper_bound(h.begin(), h.end(), mid*b) - h.begin();
    ll c = 0;
    for(;i<n;i++){
      c += ((h[i]-mid*b)/(a-b)) + ((h[i]-mid*b)%(a-b)!=0?1:0);
    }
    if(c>mid) l = mid;
    else r = mid;
  }
  std::cout << r << '\n';
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;

int main(void)
{
	int a;
	cin >> a;

	string str1, str2;

	cin >> str1 >> str2;

	vector<char> v;

	for (int i = 0; i < a; i++) {
		v.push_back(str1[i]);
		v.push_back(str2[i]);
	}

	for (int i = 0; i < a*2; i++) {
		cout << v[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#pragma GCC optimize(3)
using namespace std;
int r,l,ans; string s;
signed main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	r=s.length()-1;
	while(l<=r)
	{
		if(s[l]==s[r]) l++,r--;
		else
			if(s[l]=='x'||s[r]=='x')
			{
				ans++;
				s[l]=='x'?l++:r--;
			} 
			else
			{
				cout<<-1<<endl;
				return 0;
			}
	}
	cout<<ans<<endl;
}



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

int main(void){
    int h, w;
    cin >> h >> w;
    char grid[h][w];
    bool flag = false;
    for (int i=0; i<h; i++) for (int j=0; j<w; j++) cin >> grid[i][j];
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            if (grid[i][j] == '#'){
                if ((i==0 && j==0) && (grid[i][j+1]=='.') && (grid[i+1][j]=='.')) flag = true;
                else if ((i==0 && j==w-1) && (grid[i][j-1]=='.') && (grid[i+1][j]=='.')) flag = true;
                else if ((i==h-1 && j==0) && (grid[i-1][j]=='.') && (grid[i][j+1]=='.')) flag = true;
                else if ((i==h-1 && j==w-1) && (grid[i-1][j]=='.') && (grid[i][j-1]=='.')) flag = true;
                else if ((i == 0) && (grid[i][j-1]=='.') && (grid[i][j+1]=='.') && (grid[i+1][j]=='.')) flag = true;
                else if ((i == h-1) && (grid[i][j-1]=='.') && (grid[i][j+1]=='.') && (grid[i-1][j])=='.') flag = true;
                else if ((j == 0) && (grid[i-1][j]=='.') && (grid[i+1][j]=='.') && (grid[i][j+1]=='.')) flag = true;
                else if ((j == w-1) && (grid[i-1][j]=='.') && (grid[i+1][j]=='.') && (grid[i][j-1]=='.')) flag = true;
                else if (grid[i][j-1]=='.' && grid[i][j+1]=='.' && grid[i-1][j]=='.' && grid[i+1][j]=='.') flag = true;
                if (flag){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3640
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
  static void Main(string[] args) {
    int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    int N = input[0];
    int A = input[1];

    int[] x = new int[N + 1];
    input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    for (int i = 0; i < N; ++i) {
      x[i + 1] = input[i];
    }

    long[,,] dp = new long[N + 1, N + 1, N * A + 1];

    for (int i = 0; i < N; ++i) dp[i, 0, 0] = 1;

    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= i; ++j) {
        for (int k = 1; k <= N * A; ++k) {
          if (k < x[i]) {
            dp[i, j, k] = dp[i - 1, j, k];
          } else {
            dp[i, j, k] = dp[i - 1, j, k] + dp[i - 1, j - 1, k - x[i]];
          }
        }
      }
    }

    long ans = 0;
    for (int j = 1; j <= N; ++j) {
      ans += dp[N, j, j * A];
    }

    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 60384
#include <cstdio>

int H, W;
char photo[101][101];

int main(){
	scanf("%d %d", &H, &W);

	for (int i = 0; i < H; i++){
		scanf("%s", &(photo[i]));
	}
	for (int i = 0; i < H; i++){
		for (int x = 0; x < 2; x++){
			for (int c = 0; c < W; c++){
				printf("%c", photo[i][c]);
			}
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int a(int a,int b){return a+b;}
int b(int a,int b){return a-b;}
int c(int a,int b){return a*b;}
int d(int a,int b){return a/b;}
int main(){
  int n,m;
  char op;
  while(cin >> n >> op >> m&& op!='?'){
    if(op=='+')cout << a(n,m) << endl;
    else if(op=='-')cout << b(n,m) << endl;
    else if(op=='*')cout << c(n,m) << endl;
    else if(op=='/')cout << d(n,m) << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
#define MOD 1000000007
using namespace std;
typedef pair<int,int>pii;
int n,k,ans;
vector<int>G[100010];
void dfs(int x,int lst,int flg){
	int rem=0;
	for(auto to:G[x])if(to!=lst){
		ans=ans*(k-rem-flg)%MOD;
		rem++;
		dfs(to,x,2);
	}
}
signed main(){
	cin>>n>>k;ans=k;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		G[x].pb(y);
		G[y].pb(x);
	}
	dfs(1,-1,1);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int a[n],b[n];
	rep(i,n) cin>>a[i];

	if(n%2==0){
		rep(i,n){
			if(i%2==0){
				b[n/2+i/2]=a[i];
			}
			else b[n/2-(i+1)/2]=a[i];
		}
	}
	else{
		rep(i,n){
			if(i%2==0){
				b[n/2-i/2]=a[i];
			}
			else b[n/2+(i+1)/2]=a[i];
		}
	}

	rep(i,n) cout<<b[i]<<" ";
	cout<<"\n";

}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(){
    int n,d,x;
    cin >> n >> d >> x;
    vector<int>v(d+1,0);

    for(int i = 0;i < n;i++){
        int a,temp;
        cin >> a;
        temp = a;
        a++;
        while(d-a>=0){
            v[a]++;
            a += temp;
        }
        v[0]++;
    }

    cout << accumulate(v.begin(),v.end(),0) + x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

int main() {
    std::set<int> s;

    s.insert(1);
    s.insert(2);
    s.insert(3);

    int A,B;
    std::cin >> A >> B ;

    s.erase(A);
    s.erase(B);

    for(auto itr = s.begin();itr!=s.end();++itr){
        std::cout << *itr << std::endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll n;
  cin >> n;
  ll a[n],b[n];
  ll asum=0,bsum=0;
  rep(i,n){
    cin >> a[i];
    asum+=a[i];
  }
  rep(i,n){
    cin >> b[i];
    bsum+=b[i];
  }
  if(bsum>asum){
    cout << -1 << endl;
    return 0;
  }

  priority_queue<ll> q;
  ll change_sum=0;
  ll ans=0;
  rep(i,n){
    ll t=a[i]-b[i];
    if(t>0) q.push(t);
    else if(t<0){
      change_sum+=-t;
      ans++;
    }
  }
  //  cout << ans << endl;
  while(change_sum>0){
    change_sum-=q.top();q.pop();
    ans++;
  }
  cout << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 2428
#!/usr/bin/env python3
def main():
    S = input()

    if 'S' not in S:
        print(3)
    elif 'R' not in S:
        print(0)
    elif S.count('S') == 1:
        if S[1] == 'S':
            print(1)
        else:
            print(2)
    elif S.count('S') == 2:
        print(1)


if __name__ == '__main__':
    main()


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

int main() {
    string s, t;
    int flag = 0;
    cin >> s;
    cin >> t;
    for (int i=0; i<(int)(s.length()); ++i) {
        if (s[i]==t[i]) {
            ++flag;
        }
    }
    if (flag == (int)(s.length())) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3568
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long LL;
const LL N=21,M=(1<<19)+3,mo=1e9+7;

int dir[N][N],m2[N<<1],nex[N<<1];
int n,m,k,a,b,c;
LL f[2][N][M],g[N][M];

int main()
{
	cin>>n>>m>>k; --n;
	fo(i,1,k){
		scanf("%d%d%d",&a,&b,&c);
		dir[a][b]=c+1;
	}
	int u=0,v;
	f[0][0][0]=1;
	m2[1]=1;
	fo(i,2,n+1)m2[i]=m2[i-1]<<1;
	int zd=(m2[n]<<1)-1;
	fo(p,1,m){
		v=u^1;
		fo(l,0,n)fo(i,0,zd)f[v][l][i]=0;
		fo(l,0,n)fo(i,0,zd)g[l][i]=0;
		fd(i,zd,0){
			LL ok=f[u][0][i]%mo; nex[n]=n+1;
			fd(l,n,2)if(i&m2[l])nex[l-1]=l;else nex[l-1]=nex[l];
    		if(!i)g[0][0]=ok;
			fo(l,1,n){
				if((i&m2[l])==0&&dir[p][l]!=1&&nex[l]!=n+1)
				f[u][l][(i^m2[nex[l]])^m2[l]]=f[u][l][(i^m2[nex[l]])^m2[l]]+ok;
				ok=(f[u][l][i]+ok)%mo;
				if(dir[p][l]&&(((i&m2[l])>0)-(dir[p][l]==2)))break;
				if(nex[l]==n+1&&(i&m2[l])>0)g[l][i]=ok;
			}
		}
		fo(i,0,n-1)
		fo(l,0,zd)if(g[i][l]){
			g[i][l]=g[i][l]%mo;
			if(dir[p][i+1]!=2)g[i+1][l]=g[i+1][l]+g[i][l];
			if(dir[p][i+1]!=1)g[i+1][l^m2[i+1]]=g[i+1][l^m2[i+1]]+g[i][l];
		}
		fo(i,0,zd)f[v][0][i]=g[n][i];
		u=v;
	}
	LL ans=0;
	fo(i,0,zd)ans=(ans+f[v][0][i])%mo;
	cout<<ans;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

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

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

    char A[10][10]; memset(A, '.', sizeof(A));
    int H, W; cin >> H >> W;
    REP(i,1,H+1) REP(j,1,W+1) cin >> A[i][j];

    REP(i,1,H+1) REP(j,1,W+1) {
        if(A[i][j] == '.') continue;
        int cnt = 0; rep(k,4) if(A[i +dy[k]][j +dx[k]] == '#') cnt++;

        if((i==1 && j==1) || (i==H && j==W)) {
            if(cnt!=1) {
                cout << "Impossible" << endl;
                return 0;
            }
        } else {
            if(cnt!=2) {
                cout << "Impossible" << endl;
                return 0;
            }
        }

        if(A[i-1][j]=='#' && A[i][j-1]=='#') {
            cout << "Impossible" << endl;
            return 0;
        }
    }

    cout << "Possible" << endl;
    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abs/tasks/arc089_a

def movable?(diff_t, diff_x, diff_y)
  tmp = diff_t - diff_x.abs - diff_y.abs
  tmp >= 0 && tmp.even?
end

N = gets.to_i
ts = Array.new(N)
xs = Array.new(N)
ys = Array.new(N)
N.times do |i|
  ts[i], xs[i], ys[i] = gets.split.map(&:to_i)
end

prev_t, prev_x, prev_y = 0, 0, 0
N.times do |i|
  unless movable?(ts[i] - prev_t, xs[i] - prev_x, ys[i] - prev_y)
    puts 'No'
    exit
  end
end

puts 'Yes'


Measured memory_bytes: 4092
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

string S;
ll Q;
deque<char> deq;
int main(){
    cin>>S;
    for(auto c:S){
        deq.push_back(c);
    }
    cin>>Q;
    bool flag=false;
    for(ll i=0;i<Q;i++){
        ll t;
        cin>>t;
        if(t==1){
            flag=!flag;
        }else{
            ll f;
            char c;
            cin>>f>>c;
            if(flag^(f==1)){
                deq.push_front(c);
            }else{
                deq.push_back(c);
            }
        }
    }
    if(flag==true){
        reverse(deq.begin(),deq.end());
    }
    for(auto c:deq){
        cout<<c;
    }

    return 0;
}

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        cin >> list[i];
    list.push_back(0);
    reverse(list.begin(), list.end());
    int ans = 0;
    for (int i = 1; i <= 100; i++)
    {
        int tmp = 0;
        for (int j = 0; j < N + 1; j++)
        {
            if (list[j] < i && list[j + 1] >= i)
                tmp++;
        }
        ans += tmp;
    }
    cout << ans;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    n=n%10;
    if(n==2||n==4||n==5||n==7||n==9)
    {
        cout<<"hon";
    }
    else if(n==0||n==1||n==6||n==8)
    {
        cout<<"pon";
    }
    else
        cout<<"bon";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<int> g[100005];
bool b[100005];
int c[100005], l[100005], r[100005];

void dfs(int x, int p) {
    if (b[x]) l[x] = r[x] = c[x];
    else l[x] = -890328, r[x] = 890328;
    for (int i : g[x]) if (i != p) {
        dfs(i, x);
        l[x] = max(l[x], l[i] - 1);
        r[x] = min(r[x], r[i] + 1);
    }
}

void dfs2(int x, int p) {
    for (int i : g[x]) if (i != p) {
        if (c[x] - 1 >= l[i] && c[x] - 1 <= r[i]) c[i] = c[x] - 1;
        else if (c[x] + 1 >= l[i] && c[x] + 1 <= r[i]) c[i] = c[x] + 1;
        else {
            cout << "No";
            exit(0);
        }
        dfs2(i, x);
    }
}

int main() {
    ios::sync_with_stdio(false);
    int n, k, u = 0, v;
    cin >> n;
    for (int i = 1; i < n; i++) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
    cin >> k;
    for (int i = 1; i <= k; i++) cin >> u >> v, b[u] = 1, c[u] = v;
    dfs(u, u);
    dfs2(u, u);
    //for (int i = 1; i <= n; i++) cout << l[i] << ' ' << r[i] << '\n';
    cout << "Yes\n";
    for (int i = 1; i <= n; i++) cout << c[i] << '\n';
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#define int long long 
#define pb push_back
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define bst ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define no cout << "NO" << endl;
#define yes cout << "YES" << endl;

using namespace std;

const int N = 5e5 + 10, mod = 1e9 + 7, inf = 1e18 + 7, logn = 23;
const double pi = acos(-1);

int dp[N];
vector<int> gr[N];
int vis[N];

void dfs(int v) {
	vis[v] = 1;
	for(auto it: gr[v]) {
		if(!vis[it]) {
			dfs(it);
		}
		if(dp[v] < dp[it] + 1) {
			dp[v] = dp[it] + 1;
		}
	}
}
void solve() {
	//soln
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		int l, r;
		cin >> l >> r;
		gr[l].pb(r);
 	}
 	for(int i = 1; i <= n; i++) {
 		if(!vis[i]) dfs(i);
 	}
 	int ans = 0;
 	for(int i = 1; i <= n; i++) {
		ans = max(ans, dp[i]);
 	}
 	cout << ans << endl;
}
main() {
	bst;
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}
	

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

int main(){
  double A,B,K;
  cin >> A >> B >> K;
  if((B-A+1)/2 <= K){
    for(int i=A;i<=B;i++)
      cout << i << endl;
  }
  else{
    for(int i=A;i<A+K;i++)
      cout << i << endl;
  	for(int j=B-K+1;j<=B;j++)
      cout << j << endl;
  }
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

//const int N = 1e3 + 5;
const int mod = 1e9 + 7;
typedef long long int ll;	

map<ll,ll> m;
ll a,b,c,d;

ll solve(ll N){
	if (N == 0) return 0;
	if (N == 1) return d;
	if(m.count(N)) return  m[N];
	else{
		ll res= 1e18;
		if (N < res/d) res = N*d;
		res = min(res, d*(N%2) + a + solve(N/2));
		res = min(res, d*(2-(N%2)) + a + solve((N+1)/2));
		res = min(res, d*(N%3) + b +  solve(N/3));
		res = min(res, d*(3 - (N%3)) + b + solve((N+2)/3));
		res = min(res, d*(N%5) + c + solve(N/5));
		res = min(res, d*(5 - (N%5)) + c + solve((N+4)/5));
		m[N] = res;
		return res;
	}
}
		

int main(){
	fast;	
	int t;
	cin>>t;
	while(t--){
		m.clear();
		m[0]=0;
		ll N;
		cin>>N>>a>>b>>c>>d;
		cout<<solve(N)<<endl;
	}			
}
	


Measured memory_bytes: 4380
#include<iostream>
#include<math.h>
#include<float.h>
#include<cstdio>
using namespace std;
#define equals(a,b) fabs((a)-(b))<DBL_EPSILON*fmax(1,fmax(fabs(a),fabs(b)))
class Point{
    public:
        double x,y;
        Point(double x=0,double y=0):x(x),y(y){}

        Point operator + (Point p){return Point(x+p.x,y+p.y);}
        Point operator - (Point p){return Point(x-p.x,y-p.y);}
        Point operator * (double a){return Point(a*x,a*y);}
        Point operator / (double a){return Point(x/a,y/a);}
            
        double norm(){return x*x+y*y;}
        double abs(){return sqrt(norm());}    
        
        bool operator < (const Point &p)const{
            return x!=p.x?x<p.x:y<p.y;
        }
        bool operator == (const Point &p)const{
            return equals(x,p.x)&&equals(y,p.y);
        }
};
typedef Point Vector;
struct Segment{
    Point p1,p2;
};
typedef Segment Line;

double dot(Vector a,Vector b){//内積
    return a.x*b.x+a.y*b.y;
}
Point project(Segment s,Point p){
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/base.norm();
    return s.p1+base*r;
}

int main(){
    int q;
    Point p1,p2;
    scanf("%lf %lf %lf %lf",&p1.x,&p1.y,&p2.x,&p2.y);
    Segment s;
    s.p1=p1;  s.p2=p2;
    cin>>q;
    Point p,pp;
    for(int i=0;i<q;i++){
        cin>>p.x>>p.y;
        pp=project(s,p);
        printf("%.10f %.10f\n",pp.x,pp.y);
    }
    return 0;
}




Measured memory_bytes: 3276
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007


signed main(){

	lli n;
	cin>>n;

	/*桁数が1,3,5などの数*/

	/*自分の桁の数をまず判定することにする*/

	lli cnt=0;
	lli num = n;
	while(num>0){
		num/=10;
		cnt++;
	}
	lli sum=0;

	lli base=1;
	if(cnt%2==1){
		for(lli i=0;i<cnt-1;i++)base*=10;
		sum += n-base+1;
	}

	/*そこから自分の数以下の奇数の桁数のものについて、数を足し続ける*/
	/*1の場合9,3の場合は100～999なので、999-100+1で900個*/
	lli next = 1;
	base = 1;
	for(lli i=0;i<cnt;i++){
		next *= 10;
		base *= 10;
	}
	/*cntが偶数の場合はnextを1引く,baseは10で割る*/
	/*cntが奇数の場合はnextを10で割って1引く、baseは100で割る*/
	if(cnt%2==0){
		next-=1;
		next/=10;
		base/=100;
	}
	else{
		next/=100;
		next-=1;
		base/=1000;
	}
	while(base>0){
		sum += next-base+1;
		next/=100;
		base/=100;
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import cProfile
input = sys.stdin.readline
def main():
    n=int(input())
    a=[int(input()) for _ in range(n)]
    l=[1]
    i=0
    aa=1
    while True:
        aa=a[aa-1]
        if aa == 2:
            print(i+1)
            sys.exit()
        if i>n:
            print(-1)
            sys.exit()
        i+=1
main()

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;

struct Edge {
  int a, b, w;
};
vector<Edge> g[MAX_N];

int color[MAX_N];

void dfs(int v, int prev, int col) {
  color[v] = col;
  for (Edge u : g[v]) if (u.b != prev) {
    dfs(u.b, v, (col + u.w) & 1);
  }
}

int main2() {

  REP(i, MAX_N) g[i].clear();
  REP(i, MAX_N) color[i] = 0;

  int N = nextInt();
  REP(i, N-1) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    int w = nextInt();
    g[a].push_back((Edge){a, b, w});
    g[b].push_back((Edge){b, a, w});
  }

  dfs(0, -1, 0);
  REP(i, N) printf("%d\n", color[i]);
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 8704
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }

    let mut ret = a[0];
    for i in 1..n {
        ret = gcd(ret, a[i]);
    }
    println!("{}", ret);
}

#[allow(dead_code)]
pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
#[allow(dead_code)]
pub fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}
#[allow(dead_code)]
#[doc = " ax + by = gcd"]
#[doc = " (gcd, x, y)"]
pub fn extgcd(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (gcd, x, y) = extgcd(b, a % b);
        (gcd, y, x - (a / b) * y)
    }
}

Measured memory_bytes: 4352
#include<stdio.h>

int main(void)
{
	int x,y,i,j;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0) break;
		if(x<0 || y<0);
		else if(x<=300 && y<=300){
			for(i=0;i<x;i++){
				for(j=0;j<y;j++){
					if(i==0 || i == x-1 || j==0 || j==y-1) printf("#");
					else printf(".");
				}
				printf("\n");
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int N;
	cin >> N;
	double ans = 0;
	long long ans2 = 1;
	bool Zero = false;
	for (int i = 0; i < N; i++) {
		long long A;
		cin >> A;
		ans2 *= A;
		if (A > 0) ans += log10(A);
		else Zero = true;
	}
	if (Zero) cout << 0 << endl;
	else  cout << (ans <= 18 && ans2 <= (long long)pow(10, 18) ? ans2 : -1) << endl;
}


Measured memory_bytes: 3996
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

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

    int x = min(a, b);
    
    rep(i, max(a, b)) {
        cout << x;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<ll> a(N*3);
  for(int i=0; i<N*3; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end(),greater<int>());
  ll ans=0;
  int count=0;
  for(int i=0; i<3*N; i++){
    if(i%2 != 0){
      ans += a[i];
      count++;
    }
    if(N == count){
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main(){
  int N,i,j,c,l,r;scanf("%d",&N);
  int A[N][N-1],itr[N] = {};
  c = N*(N-1)/2;
  for(i=0;i<N;i++){
    for(j=0;j<N-1;j++){
      scanf("%d",&A[i][j]);A[i][j]--;
    }
  }
  queue<pair<int,int>> q;int game;
  for(i=0;i<N-1;i++){
    if(i < A[i][itr[i]] && A[A[i][itr[i]]][itr[A[i][itr[i]]]] == i) q.push(make_pair(i,A[i][itr[i]]));
  }
  for(i=0;c;i++){
    game = q.size();
    if(game == 0){
      printf("-1\n");return 0;
    }
    for(j=0;j<game;j++){
      l = q.front().first;r = q.front().second;q.pop();
      c--;
      itr[l]++;itr[r]++;
      if(itr[l] < N-1 && itr[A[l][itr[l]]] < N-1 && A[A[l][itr[l]]][itr[A[l][itr[l]]]] == l) q.push(make_pair(l,A[l][itr[l]]));
      if(itr[r] < N-1 && itr[A[r][itr[r]]] < N-1 && A[A[r][itr[r]]][itr[A[r][itr[r]]]] == r) q.push(make_pair(r,A[r][itr[r]]));
    }
  }
  printf("%d\n",i);
}

Measured memory_bytes: 7560
M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()



Measured memory_bytes: 133264
#include <stdio.h>
#include <string.h>

int main()
{
	char T[1001], P[1001];
	int len_T, len_P;
	int i, j, k;

	scanf("%s", T);
	scanf("%s", P);

	len_T = strlen(T);
	len_P = strlen(P);

	// 文字列検索
	for(i = 0; i < len_T; i++){
		for(j = i, k = 0; j < i + len_P; j++, k++)
			if(T[j] != P[k])
				break;
		if(k == len_P)
			printf("%d\n", i);
	}

	return 0;
}


Measured memory_bytes: 2112
#include<iostream>
using namespace std;
int main(){
    long long int n,a,min,nu=0;
    cin >> n;
    for(int i=1;i<=5;i++){
        cin>>a;
        if(i==1){
            min = a;
        }else{
            if(min>a){
                min = a;
            }
        }
    }
    nu = n/min;
    if(n%min!=0){
        nu += 1 ;
    }
    nu += 4 ;
    cout << nu << endl ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{


   int a,b;
   while(cin>>a>>b)
   {
       if(a==b)
       {
           cout<<"Draw"<<endl;
       }
       else if(a==1)
       {
           cout<<"Alice"<<endl;
       }
       else if(b==1)
       {
           cout<<"Bob"<<endl;
       }
       else if(a>b)
       {
          cout<<"Alice"<<endl;
       }
       else
       {
           cout<<"Bob"<<endl;
       }
   }

   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int main(void) {
	char in[3];
	scanf("%s", in);
	if (in[0] == '9' || in[1] == '9') {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}


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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int x, y;
  cin >> x >> y;
  for(int a = 0; a <= y; ++a) {
    for(int b = 0; b <= y; ++b) {
      if(a * 2 + b * 4 == y && a + b == x) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
}

Measured memory_bytes: 3636
import math

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


a = int(input())

while(True):
    if is_prime(a):
        print(a)
        break
    else:
        a+=1

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

int main()
{
    string s; cin >> s;

    int answer = numeric_limits<int>::max();
    for (char goal = 'a'; goal <= 'z'; goal++)
    {
        int option = 0;

        int run = 0;
        for (const auto c : s)
            if (c == goal)
            {
                option = max(option, run);
                run = 0;
            }
            else run++;
        option = max(option, run);

        answer = min(answer, option);
    }

    cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;

    if(x<a)
    {
        a=a-x;
    }
    else
    {
        a=x-a;
    }

    if(x<b)
    {
        b=b-x;
    }
    else
    {
        b=x-b;
    }

    if(a<b)
    {
            cout<<"A";
    }
    else
    {
            cout<<"B";
    }
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<complex>
using namespace std;

void grading(int m, int f, int r){
    if(m == -1 || f == -1) {cout << "F" <<endl;return;}
    if(m+f >= 80) {cout << "A" <<endl;return;}
    if(m+f >= 65) {cout << "B" <<endl;return;}
    if(m+f >= 50) {cout << "C" <<endl;return;}
    if(m+f >= 30){
        if(r >= 50) {cout << "C" <<endl;return;}
        cout << "D" <<endl;return;
    }
    if(m+f < 30) {cout << "F" << endl;return;}
}

int main(){
    int m, f, r;
    cin >> m >> f >> r;
        while( m!=-1 || f !=-1 || r!=-1){
            grading(m ,f, r);
            cin >> m >> f >> r;
        }
    return 0;
}

Measured memory_bytes: 3096