akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll T1, T2, A1, A2, B1, B2;
  cin>>T1>>T2>>A1>>A2>>B1>>B2;
  if(A1<B1) {
    swap(A1, B1);
    swap(A2, B2);
  }
  A1 = A1 - B1;
  A2 = A2 - B2;
  if(A1*T1+A2*T2==0) {
    cout<<"infinity"<<endl;
    return 0;
  }
  if(A1*T1+A2*T2>0) {
    cout<<0<<endl;
    return 0;
  }
  ll ans = 1;
  ll S = abs(A1*T1+A2*T2);
  if(A1*T1%S==0) {
    ans += ((A1*T1)/S-1)*2+1;
  }
  else {
    ans += (A1*T1)/S*2;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <math.h>

using namespace std;

int n, t, a;
int h[1005];

int main(void)
{
	cin >> n >> t >> a;
	for(int i = 1; i <= n; i++) cin >> h[i];
	
	double ans = 1e9; int ans_i;
	for(int i = 1; i <= n; i++){
		if(fabs(t-0.006*h[i] - a) < ans){
			ans = fabs(t-0.006*h[i]-a);
			ans_i = i;
		}
	}
	cout << ans_i << endl;
	
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define lP pair<ll,ll>
#define iP pair<int,int>

typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;

string s;

int main(){
	cin >> s;
	if (s == "ani") {
		cout << "square1001" << endl;
	}
	else {
		cout << "e869120" << endl;
	}
	return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;

    vector<vector<int>> s(M);
    for(int i = 0; i < M; i++)
    {
        int k;
        cin >> k;

        s[i].resize(k);
        for(int j = 0; j < k; j++)
        {
            cin >> s[i][j];
            s[i][j]--;
        }
    }

    vector<int> p(M);
    for(int i = 0; i < M; i++)
    {
        cin >> p[i];
    }

    long long ans = 0;
    for(int i = 0; i < (1 << N); i++)
    {
        bool ok = true;
        for(int j = 0; j < M; j++)
        {
            int cnt = 0;
            for(int k = 0; k < s[j].size(); k++)
            {
                if(i & (1 << s[j][k]))
                {
                    cnt++;
                }
            }

            if(cnt % 2 != p[j])
            {
                ok = false;
                break;
            }
        }

        if(ok)
        {
            ans++;
        }
    }

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

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

bool col[8];
int zyougen[8] = {400, 800, 1200, 1600, 2000, 2400, 2800, 3200};
int rnd;

void categrize_color(int rate) {
    for(int i = 0; i < 8; ++i) {
        if(rate < zyougen[i]) { col[i] = true; return ;}
    }
    ++rnd; return;
}

int main()
{
    int N;
    scanf("%d", &N);
    for(int i = 0; i < N; ++i) {
        int a; scanf("%d", &a); 
        categrize_color(a);
    }
    int mn_res = 0;
    for(int i = 0; i < 8; ++i) if(col[i]) ++mn_res;
    int max_res = mn_res + rnd;
    if(rnd != 0) mn_res = max(mn_res, 1);
    printf("%d %d\n", mn_res, max_res);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
B = []
C = []
sat = 0#合計満足度
for x in input().split():
    A.append(int(x))
for x in input().split():
    B.append(int(x))
    sat += int(x)
for x in input().split():
    C.append(int(x))

for i in range(N-1):
    if A[i+1] == A[i] + 1:
        sat += C[A[i]-1]

print(sat)

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D){

  for(int i = 0; i < 100000000; i++){
    if(i % 2 == 0) {
      C -= B;
      if(C <= 0) {
        cout << YES << endl;
        break;
      }
    }
    else {
      A -= D;
      if(A <= 0) {
        cout << NO << endl;
        break;
      }
    }
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
  long long D;
  scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
//---------------------------------------------------------------
int main(){
  string S;
  cin>>S;
  if(S=="ABC")S = "ARC";
  else S="ABC";

  cout<<S<<endl;




}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    int N,C;cin>>N>>C;
    vector<vector<int>> cnt(C,vector<int>(MAX,0));
    for(int i=0;i<N;i++){
        int a,b,c;cin>>a>>b>>c;
        c--;
        cnt[c][a]++;
        cnt[c][b+1]--;
    }
    
    for(int i=0;i<C;i++){
        for(int j=1;j<MAX;j++){
            cnt[i][j]+=cnt[i][j-1];
        }
    }
    
    for(int i=0;i<C;i++){
        for(int j=0;j<MAX;j++){
            if(cnt[i][j]>1) cnt[i][j]=1;
        }
    }
    
    vector<int> sum(MAX,0);
    
    int ans=0;
    
    for(int i=0;i<MAX;i++){
        for(int j=0;j<C;j++){
            sum[i]+=cnt[j][i];
        }
        ans=max(ans,sum[i]);
    }
    
    cout<<ans<<endl;
    
    
}




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

using namespace std;
using ll = long long;

int main() {
	int n; ll k; scanf("%d %lld", &n, &k);
	vector<int> arr(n);
	for (int i = 0; i < n; ++i) scanf("%d", &arr[i]);
	vector<int> nextAppear(n, -1), lengthToNext(n, -1);
	map<int, int> occ;
	for (int i = n - 1; i >= 0; --i) {
		if (occ.count(arr[i]) > 0) {
			nextAppear[i] = (occ[arr[i]] + 1) % n;
			lengthToNext[i] = occ[arr[i]] + 1 - i;
//			printf("LTN %d = %d\n", i, lengthToNext[i]);
		}
		occ[arr[i]] = i;
	}
	for (int i = 0; i < n; ++i) {
		if (nextAppear[i] == -1) {
			nextAppear[i] = (occ[arr[i]] + 1) % n;
			if (occ[arr[i]] == i) {
				lengthToNext[i] = n + 1;
			} else {
				lengthToNext[i] = n - (i - occ[arr[i]]) + 1;
			}
//			printf("LTN %d = %d\n", i, lengthToNext[i]);
		}
	}
	vector<vector<ll>> totalJumpLen(60, vector<ll>(n, 0));
	for (int i = 0; i < n; ++i) totalJumpLen[0][i] = lengthToNext[i];
	for (int js = 1; js < 60; ++js) {
		for (int i = 0; i < n; ++i) {
			int halfJTarget = (i + totalJumpLen[js-1][i]) % n;
			totalJumpLen[js][i] = totalJumpLen[js-1][i] + totalJumpLen[js-1][halfJTarget];
			if (totalJumpLen[js][i] >= n * k) totalJumpLen[js][i] = n * k;
		}
	}
	ll targetLength = n * (k - 1);
	ll cLenCover = 0; 
	// make jumps as long as cLenCover <= targetLength
	int cidx = 0;
	for (int js = 59; js >= 0; --js) {
		if (cLenCover + totalJumpLen[js][cidx] <= targetLength) {
//			printf("executing jump %lld\n", 1LL << js);
//			printf("length %lld\n", totalJumpLen[js][cidx]);
			cLenCover += totalJumpLen[js][cidx];
			cidx = (cidx + totalJumpLen[js][cidx]) % n;
//			printf("now crossed %lld\n", cLenCover);
		}
	}
	multiset<int> curSetIn;
	vector<int> sequence;
	auto popElement = [&curSetIn, &sequence] () {
		curSetIn.erase(curSetIn.find(sequence.back()));
		sequence.pop_back();
	};
	auto addElement = [&curSetIn, &sequence] (int x) {curSetIn.insert(x); sequence.push_back(x);};
//	printf("jumped to %lld\n", cLenCover);
	for (ll i = cLenCover; i < n * k; ++i) {
		if (curSetIn.find(arr[i % n]) == curSetIn.end()) addElement(arr[i % n]);
		else {
			while (sequence.back() != arr[i % n]) popElement();
			popElement();
		}
	}
	for (int x : sequence) printf("%d ", x);
	printf("\n");
	return 0;
}


Measured memory_bytes: 119008
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    rep(i,1000){
        int x=0;
        int a[]={i/100,i%100/10,i%10};
        rep(j,n){
            if(a[x]==s[j]-'0')x++;
            if(x==3)break;
        }
        if(x==3)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,K;
    long long ans;
    ans=0;
    cin>>N>>K;
    if(N>K){
        vector<long long>H(N);
        for(int i=0;i<N;i++){
            cin>>H[i];
        }
        sort(H.begin(),H.end());
        for(int i=0;i<N-K;i++){
            ans+=H[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,us,ue,loop=0;
    while(cin>>a>>b&&a!=0&&b!=0){
        if(loop!=0) cout<<endl;
        for(int i=0;i<8;i++){
            if(((a+i)%4==0&&(a+i)%100!=0)||(a+i)%400==0){
                us=a+i;
                break;
            }
        }
        for(int j=0;j<8;j++){
            if(((b-j)%4==0&&(b-j)%100!=0)||(b-j)%400==0){
                ue=b-j;
                break;
            }
        }
        if(us>ue) cout<<"NA"<<endl;
        else{
            for(int k=us;k<=ue;k+=4){
                if((k%4==0&&k%100!=0)||k%400==0){
                    cout<<k<<endl;
                } 
            }
        }
    loop++;    
    }
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int size=s.size();
	for(int i=0;i<size;i++){
		for(int j=0;j<size;j++){
			if(s[i]==s[j] && i!=j){
				cout << "no" << endl;
				return 0;
			}else{
				continue;
			}
		}
	}
	cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> edge[110];
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            int x;
            cin>>x;
            edge[u].push_back(x);
        }
    }
    int d[110];
    fill(d,d+110,-1);
    d[1]=0;
    queue<int> Q;
    Q.push(1);
    while(!Q.empty()){
        int now=Q.front();Q.pop();
        for(auto it:edge[now]){
            if(d[it]!=-1)continue;
            d[it]=d[now]+1;
            Q.push(it);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<i<<' '<<d[i]<<endl;
    }
}


Measured memory_bytes: 3188
#include <iostream>
using namespace std; 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    const int L = 21;
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int S = a1+a2+a3;
    if (S<=L){
        cout << "win" << "\n";
    }
    else {
        cout << "bust" << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
import math
N, H = map(int,input().split())
A = []
B = []
for i in range(N):
  a, b = map(int,input().split())
  A.append(a)
  B.append(b)
A = sorted(A)[::-1]
B = sorted(B)[::-1]
sum1 = 0
cnt = 0
for i in range(N):
  if B[i] >= A[0]:
    sum1 += B[i]
    cnt += 1
    if sum1 >= H:
      print(cnt)
      exit()
  else:
    break
print(math.ceil((H-sum1)/A[0])+cnt)

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

int main(){
    int n,m,p,x;
    int t[110];
    int sum = 0;

    cin >> n;    
    for(int i = 0; i < n; i++){
        cin >> t[i];
        sum += t[i];
    }

    cin >> m;
    for(int j = 0; j < m; j++){
        cin >> p >> x;
        cout << sum + (x - t[p-1]) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long N,M;
    cin>>N>>M;
    //cout<<N<<M<<endl;
    vector<pair<long,long> > pairs(N);
    for (int i=0;i<N;i++){
        long long a,b;
        cin>>a>>b;
        //cout<<a<<b<<endl;
        pairs[i]=make_pair(a,b);
    }
    sort(pairs.begin(),pairs.end());
    long long ans=0;
    for (int i=0;i<N;i++){
        //cout<<pairs[i].first<<" "<<pairs[i].second<<endl;
        if(M<=pairs[i].second){
            ans+=pairs[i].first*M;
            break;
        }
        else{
            ans+=pairs[i].first*pairs[i].second;
            M-=pairs[i].second;
        }

        
    }
    cout<<ans<<endl;

}

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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;

constexpr ll MOD = 1000000007LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;

struct Graph {
    Graph(const int v) : V{v}, edge(v), rev_edge(v) {}
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
        rev_edge[to].push_back(from);
    }
    const int V;
    vector<vector<int>> edge;
    vector<vector<int>> rev_edge;
};

int main()
{
    int N, K;
    cin >> N >> K;
    Graph g(N);
    using P = pair<int, int>;
    vector<P> edge(N - 1);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g.addEdge(a, b);
        g.addEdge(b, a);
        edge[i] = {a, b};
    }
    int ans = N;
    if (K % 2 == 0) {
        for (int i = 0; i < N; i++) {
            vector<bool> used(N, false);
            queue<P> q;
            q.push({i, 0});
            used[i] = true;
            while (not q.empty()) {
                const int s = q.front().first;
                const int d = q.front().second;
                q.pop();
                for (const int to : g.edge[s]) {
                    if (not used[to] and d + 1 <= K / 2) {
                        used[to] = true;
                        q.push({to, d + 1});
                    }
                }
            }
            int sum = 0;
            for (int i = 0; i < N; i++) {
                if (not used[i]) {
                    sum++;
                }
            }
            ans = min(ans, sum);
        }
    } else {
        for (int i = 0; i < N - 1; i++) {
            const int u = edge[i].first;
            const int v = edge[i].second;
            vector<bool> used(N, false);
            queue<P> q;
            q.push({u, 0});
            q.push({v, 0});
            used[u] = true;
            used[v] = true;
            while (not q.empty()) {
                const int s = q.front().first;
                const int d = q.front().second;
                q.pop();
                for (const int to : g.edge[s]) {
                    if (not used[to] and d + 1 <= K / 2) {
                        used[to] = true;
                        q.push({to, d + 1});
                    }
                }
            }
            int sum = 0;
            for (int i = 0; i < N; i++) {
                if (not used[i]) {
                    sum++;
                }
            }
            ans = min(ans, sum);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
int main()
{
    int paint[110][110];
	int h,w,n,x=0;
	int i,j;
    cin>>h>>w>>n;
    int a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        for(j=0; j<a[i]; j++)
        {
            if((x/w)%2==0) paint[x/w][x%w]=i+1;
            else paint[x/w][w-(x%w)-1]=i+1;
            x++;
        }
    }
    for(i=0; i<h; i++)
    {
        for(j=0; j<w; j++)
        {
            if(j==w-1) printf("%d\n",paint[i][j]);
            else printf("%d ",paint[i][j]);
        }
    }
    return 0;
} 

Measured memory_bytes: 384
function Main(input){
  input = input.split(" ");
  var a = parseInt(input[0],10);
  var b = parseInt(input[1],10);
  var t = parseFloat(input[2],10)+0.5;
  var sum = 0;
  var tmp = a;
  
  while(tmp<t){
  sum += b;
  tmp += a;
  }
  console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin","utf-8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;
    double ans = 0;
    rep(i, n){
        double b;string s;
        cin>>b>>s;
        if(s=="JPY"){
            ans += b;
        }else{
            ans += 380000.0*b;
        }
    }
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
   ll n,k,a,b;
   cin >> n>>k;
   vector <pair<ll,ll>> p;
   for(ll i=0;i<n;i++) {
     cin >>a>>b;
     p.push_back(make_pair(a,b));
   }
   sort(p.begin(),p.end());
   ll sum=0;
   for(ll i=0;i<n;i++){
     sum+=p[i].second;
     if(sum>=k) {
       cout << p[i].first<<endl;
       return 0;
     }
   }
  }


Measured memory_bytes: 2420
N, K = gets.split.map(&:to_i)
M = 10**9 + 7

fac, inv, fiv = [1, 1], [1, 1], [1, 1]
(2 .. N).each do |i|
  fac[i] = fac[i - 1] * i % M
  inv[i] = M - inv[M % i] * (M / i) % M
  fiv[i] = fiv[i - 1] * inv[i] % M
end
c = ->(n, m){fac[n] * fiv[n - m] * fiv[m] % M}
f = ->(n, m){fac[n - 1] * fiv[m] * fiv[n - m - 1] % M}
puts (0 .. [K, N - 1].min).inject(0){|s, m| s + c[N, m] * f[N, m] % M} % M

Measured memory_bytes: 6760
#include <iostream>
#include <vector>
#include <utility>
#include <cstdio>
#define llint long long
#define mod 1000000007
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[2][20];
llint dp[1<<18][55];
llint pop[1<<18];

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

  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[0][i];
  for(int i = 0; i < n; i++) cin >> a[1][i];
  for(int i = 1; i < (1<<18); i++) pop[i] = pop[i&(i-1)] + 1;

  llint N = 1<<n;
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= 50; j++){
      dp[i][j] = inf;
    }
  }
  dp[0][0] = 0;

  for(int i = 0; i < N; i++){
    for(int j = 0; j <= 50; j++){
      llint cnt = 0;
      for(int k = 0; k < n; k++){
        if(i & (1<<k)) continue;
        cnt++;
        llint d = abs(pop[i]-k), v = a[d%2][k];
        if(v < j) continue;
        dp[i|(1<<k)][v] = min(dp[i|(1<<k)][v], dp[i][j] + cnt-1);
      }
    }
  }

  /*for(int i = 0; i < N; i++){
    for(int j = 0; j < 5; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/

  llint ans = inf;
  for(int j = 0; j <= 50; j++) ans = min(ans, dp[N-1][j]);
  if(ans > inf/2) ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 115072
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N,D;

int main() {

	scanf("%d%d", &N,&D);



	printf("%d\n", N/(2*D+1)+ !!(N % (2 * D + 1)));
	
	return 0;
}


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

int main() {
  int sx, sy, tx, ty;
  
  cin >> sx >> sy >> tx >> ty;
  string route;
  int posx = 0, posy = 0;
  
for ( int i = 0; i< (tx-sx); i++){
 route += 'R'; 
}
for ( int i = 0; i< (ty-sy); i++){
 route += 'U'; 
}
for ( int i = 0; i< (tx-sx); i++){
 route += 'L'; 
}
for ( int i = 0; i< (ty-sy); i++){
 route += 'D'; 
} 
 route += 'D';
for ( int i = 0; i< (tx-sx)+1; i++){
 route += 'R'; 
}
for ( int i = 0; i< (ty-sy)+1; i++){
 route += 'U'; 
} 
 route += 'L';   
 route += 'U';
for ( int i = 0; i< (tx-sx)+1; i++){
 route += 'L'; 
}
for ( int i = 0; i< (ty-sy)+1; i++){
 route += 'D'; 
}  
 route += 'R'; 
  
  cout << route << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;
int main(){
    int N;
    cin>>N;
    vector<int>a(N);
    int mi=10000*N;
    int sum=0;
    rep(i,N){
        cin>>a[i];
    }
    FOR(i,-100,101){
        rep(j,N){
            sum+=(a[j]-i)*(a[j]-i);
        }
        mi=min(mi,sum);
        sum=0;
    }
    cout<<mi<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
import itertools

def read():
    M1, D1 = list(map(int, input().strip().split()))
    M2, D2 = list(map(int, input().strip().split()))
    return M1, D1, M2, D2


def solve(M1, D1, M2, D2):
    if M1 != M2:
        return 1
    return 0
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)


Measured memory_bytes: 38384
"""
https://atcoder.jp/contests/dp/tasks/dp_j
"""
from sys import stdin
input = stdin.readline

n = int(input())
c = [0] * 4
l = list(map(int, input().split()))

for i in l:
    c[i] += 1

dp = [[[0.0] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
dp[0][0][0] = 0
for n3 in range(0, c[3] + 1):
    for n2 in range(0, c[2] + c[3] - n3 + 1):
        for n1 in range(0, n-c[0]- n3 - n2 + 1):
            if n1 == n2 == n3 == 0:
                continue
            temp = n
            if n1 != 0:
                # temp += n1 * dp[(n1 - 1, n2, n3)]
                temp += n1*dp[n1 - 1][n2][n3]
            if n2 != 0:
                # temp += n2 * dp[(n1 + 1, n2 - 1, n3)]
                temp += n2*dp[n1 + 1][n2 - 1][n3]
            if n3 != 0:
                # temp += n3 * dp[(n1, n2 + 1, n3 - 1)]
                temp += n3*dp[n1][n2 + 1][n3 - 1]
            dp[n1][n2][n3] = temp / (n1 + n2 + n3)

print(dp[c[1]][c[2]][c[3]])


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

using namespace std;
typedef long long ll;
int N;
ll x;
ll a[2001];
ll ma[2001];
ll ans = 1e18;
int main() {
  cin >> N >> x;

  for(int i = 0; i < N; i++) {
    cin >> a[i];
    ma[i] = a[i];
  }

  for(int i = 0; i < N; i++) {
    ll b = 0;
    int k;
    for(int j = 0; j < N; j++) {
       k = j - i - 1;
      b += ma[j];
      if(k < 0) k += N;
      ma[j] = min(ma[j],a[k]);
      //cout <<"ma["<<j<<"] = "<<ma[j]<<endl;
    }
    ans = min(ans,(ll)i*x+b);
  }

  cout << ans <<endl;
}
      
      
    
  


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG //提出時に消す
#include <bits/stdc++.h>
//#include <atcoder/scc>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define all(x) (x).begin(), (x).end()
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007ll

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n, -1) {}

  //functions
  void init_tree() {
    for (int i = 0; i < d.size(); i++) {
      d[i] = -1;
    }
  }
  
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x) {
    return -d[find(x)];
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15)
  ll n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    uf.unite(a, b);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (!uf.same(0, i)) {
      ans++;
      uf.unite(0, i);
    }
  }
  cout << ans << endl;
  
}



Measured memory_bytes: 3708
import bisect
import itertools

N = int(input()) # それぞれのパーツの数
A = list(map(int, input().split())) # 小さい
B = list(map(int, input().split())) # 中くらい
C = list(map(int, input().split())) # 大きい

# Cは並び替え不要
A.sort()
B.sort()

# Bの各要素でAを二分探索して返ってきたindexを先に保有しておく
b_counts = [0] * N
for i in range(N):
    b_count = bisect.bisect_left(A, B[i])
    b_counts[i] = b_count

cumsum_b_counts = list(itertools.accumulate(b_counts))
cumsum_b_counts = [0] + cumsum_b_counts

# Cの各要素でBを二分探索。上記で保有しておいたb_countsを活用する
total = 0
for c in C:
    count = bisect.bisect_left(B, c)
    total += cumsum_b_counts[count]

print(total)

    

Measured memory_bytes: 31040
n=int(input())

a=list(map(int,input().split()))
ans=1
if 0 in a:
  print(0)

else:
  for i in range(n):
    ans=ans*a[i]
    if ans>10**18:
      print(-1)
      break
    else:
      continue
  if ans <= 10**18:
    print(ans)
   

Measured memory_bytes: 21540
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, K;
  cin >> N >> K;
  vector<ll> X(N);
  for(int i=0; i<N; i++) {
    cin >> X[i];
  }
  ll m = 1e+18;
  for(int i=0; i<N-K+1; i++) {
    if(X[i+K-1] * X[i] < 0) {
      if(m > X[i+K-1] - X[i] + min(X[i+K-1], abs(X[i]))) {
	m = X[i+K-1] - X[i] + min(X[i+K-1], abs(X[i]));
      }
    } else {
      if(m > X[i+K-1] - X[i] + min(abs(X[i+K-1]), abs(X[i]))) {
	m = X[i+K-1] - X[i] + min(abs(X[i+K-1]), abs(X[i]));
      }
    }
  }

  cout << m << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define i64 long long
#define maxn (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	int N,M,C;
	scanf("%d %d %d",&N,&M,&C);
	int A[N][M], B[M];
	for(int i=0;i<M;i++) scanf("%d",&B[i]);
	
	int cnt = 0;
	for(int i=0;i<N;i++){
		int sum =0;
		for(int j=0;j<M;j++) {
			scanf("%d",&A[i][j]);
			sum+=(A[i][j]*B[j]);
		}
		sum+=C;
		if(sum>0) cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n, a[200005], b[200005];
const int MAX = 200005;
ll ans;

struct segment_tree {
	int t[2*MAX];
	void build() {
		for(int i = 0; i < n; i++) t[i + n] = a[i];
		for(int i = n-1; i >= 1; i--) t[i] = min(t[i<<1], t[i<<1|1]);
	}
	// [l,r]
	int query(int l, int r) {
		++r;
		int ret = MAX;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if(l & 1) ret = min(ret, t[l++]);
			if(r & 1) ret = min(ret, t[--r]);
		}
		return ret;
	}
} st;

void dfs(int l, int r) {
	int ret = st.query(l, r), pos = b[ret];
	ans += (ll)ret * (ll)(r-pos+1) * (ll)(pos-l+1);
	if (l <= pos-1) dfs(l, pos-1);
	if (pos+1 <= r) dfs(pos+1, r);
	return;
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	FOR(i, n) {
		cin >> a[i];
		b[a[i]] = i;
	}
	st.build();
	dfs(0, n-1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
 
long long m=998244353;
long long modRecursive(long long a,long long b,long long c)
{
    if(b == 0) return 1;
    if(b%2 ==0) return modRecursive((a*a)%c,b/2,c);
    else return ((a%c)*(modRecursive((a*a)%c,b/2,c)))%c;
}
 
int main()
{
    long long n,maxi=0;
    cin>>n;
    long long a[n],freq[n+1]={0};
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        freq[a[i]]++;
        maxi=max(a[i],maxi);
    }
    long long ans=1,d=0;
    for(int i=0; i<=maxi; i++)
        if(freq[i]==0) d=1;
    if(d || freq[0]>1 || a[0]!=0) cout<<0<<endl;
    else
    {
        for(int i=1; i<=maxi; i++)
        {
            long long c=freq[i],d=freq[i-1];
            ans=(ans*(modRecursive(d,c,m)%m))%m;
        }
        cout<<ans%m<<endl;
    }
    return 0;
}

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


//TEMPLATE
#define pb              push_back
#define mp              make_pair
#define ll              long long
#define pi              3.1415926536
#define mod             1000000007
#define newline         printf("\n")
#define printminusone   printf("-1\n")
#define scl1(n)         scanf("%lld", &n)
#define scl2(a, b)      scanf("%lld %lld", &a, &b)
#define printl(n)       printf("%lld\n", n)
#define scd1(n)         scanf("%lf", &n)
#define scd2(a, b)      scanf("%lf %lf", &a, &b)
#define printd(n)       printf("%lf\n", n)
#define printcase       printf("Case %lld: ", i)
#define reversed(s)     reverse(s.begin(), s.end())
#define asorted(s)      sort(s.begin(), s.end())
#define dsorted(s)      sort(s.begin(), s.end(), cmp)
#define for0(i, n)      for (i = 0; i < n; i++)
#define for1(i, n)      for (i = 1; i <= n; i++)
#define pii             pair <ll, ll>
#define piii            pair <ll, pii>
#define SIZE            100005
#define INF             1000000005
#define F               first
#define S               second
#define FR              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(arr, x)      memset(arr, x, sizeof arr)

ll n, k;
ll h[SIZE];
ll dp[SIZE];

ll solve(ll in) {
    if(in == n) return 0;
    if(dp[in] != -1) return dp[in];

    ll t = INF, i, c;
    for(i = in+1, c = 1; c <= k && i <= n; i++, c++) {
        t = min(t, abs(h[in] - h[i]) + solve(i));
    }

    return dp[in] = t;
}

int main() {
    ll t = 0, x, y, z, i, j, g, p, q, ans = 0, sum = 0, c = 0;
    ms(dp, -1);

    scl2(n, k);
    for1(i, n) scl1(h[i]);

    ans = solve(1);
    printl(ans);

    return 0;
}



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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const int MOD = 1e+9 + 7;

int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    REP(i, N) cin >> A[i];

    vector<long long> s(A);
    for(int i = N-2; i >= 0; --i){
        s[i] += s[i+1];
        s[i] %= MOD;
    }

    long long ans = 0;
    REP(i, N-1){
        ans += s[i+1]*A[i] % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6372
#include<iostream>
#include<cstdlib>
using namespace std;

int main()
{
  int n;
  cin >> n;

  int t, a;
  cin >> t >> a;

  int h;
  int min = 1 << 30;
  int tmp = 0;

  for(int i = 1; i <= n; i++){
    cin >> h;
    h = t*1000 - h*6 - a*1000;

    if(h < 0) h *= -1;

    if(min > h){
      min = h;
      tmp = i;
    }
  }

  cout << tmp << endl;

  return 0;

}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
counter_map = [0] * (m + 1)

for i in range(n):
    k, *a = map(int, input().split())
    for j in a:
        counter_map[j] += 1

res = 0
for i in range(m + 1):
    if counter_map[i] == n:
        res += 1

print(res)

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

//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    string c = "ABC";
    int ans=0;
    rep(i,n-2){
        if(s[i]==c[0] && s[i+1]==c[1] && s[i+2] == c[2])++ans;
    }
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

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

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

n = inn()
a = inl()
b = inl()
sum = 0
for i in range(n-1,-1,-1):
    x = min(a[i+1],b[i])
    sum += x
    b[i] -= x
    x = min(a[i],b[i])
    sum += x
    a[i] -= x
print(sum)


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

int main() {
    int N;
    cin >> N;

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    sort(A.begin(), A.end(),greater<int>());

    int diff= 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            diff += A.at(i);
        }
        else {
            diff -= A.at(i);
        }
    }

    cout << diff << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

int v[20100];
int t[100];
int mxvv[100];
int mxv[20100];
int n;
int total = 0;
int main(){
    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> mxvv[i];
    }
    int tt = 0;
    for (int i = 0; i < n; ++i) {
        total += t[i];
        for (; tt < total; ++tt) {
            mxv[tt] = mxvv[i];
            v[tt] = 0;
        }
    }
    mxv[total] = mxvv[n - 1];
    //mxv[i] => i sec ~ i + 1 sec;
    while (1) {
        bool update = false;
        for (int t = 1; t < total; ++t) {
            if (v[t] <= v[t + 1] && v[t] <= v[t - 1] && v[t] < mxv[t] && v[t] < mxv[t - 1]) {
                v[t]++;
                update = true;
            }
        }
        if (!update) break;
    }

    // for (int t = 0; t <= total; ++t) {
    //     cout << t << " : " << v[t] << " max " << mxv[t] << endl;
    // }
    // cout << endl;

    double ans = 0;
    for (int t = 1; t <= total; ++t) {
        ans += (v[t - 1] + v[t]) / 2.;
        if (v[t - 1] == v[t] && v[t] < mxv[t - 1]){
            ans += 0.25;
        }

        //cout << "0 - " << t << " : " << ans << endl;
    }
    cout << fixed << setprecision(12) << ans << endl;
}

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

#define REP(i, a, b) for(int i = a; i < b; i++)

const int baza = 10007;
const int mod = 1e9 + 7;

map <pair <int, int>, int> imam;

long long int rj = 0;

int n;

string s, tr;

int h1, h2;

int main()
{
    cin >> n >> s;
    REP(mask, 0, (1<<n))
    {
        tr.clear();
        REP(i, 0, n)
        {
            if(mask & (1<<i))
            {
                tr.push_back(s[i]);
            }
        }
        h1 = 0;
        REP(i, 0, tr.size())
        {
            h1 = (long long) ((long long) h1 * baza + tr[i]) % mod;
        }
        tr.clear();
        REP(i, 0, n)
        {
            if(!(mask & (1<<i)))
            {
                tr.push_back(s[i]);
            }
        }
        //reverse(tr.begin(), tr.end());
        h2 = 0;
        REP(i, 0, tr.size())
        {
            h2 = (long long) ((long long) h2 * baza + tr[i]) % mod;
        }
        imam[make_pair(h1, h2)]++;
    }
    REP(mask, 0, (1<<n))
    {
        tr.clear();
        REP(i, 0, n)
        {
            if(mask & (1<<i))
            {
                tr.push_back(s[2 * n - i - 1]);
            }
        }
        h1 = 0;
        REP(i, 0, tr.size())
        {
            h1 = (long long) ((long long) h1 * baza + tr[i]) % mod;
        }
        tr.clear();
        REP(i, 0, n)
        {
            if(!(mask & (1<<i)))
            {
                tr.push_back(s[2 * n - i - 1]);
            }
        }
        //reverse(tr.begin(), tr.end());
        h2 = 0;
        REP(i, 0, tr.size())
        {
            h2 = (long long) ((long long) h2 * baza + tr[i]) % mod;
        }
        rj += imam[make_pair(h1, h2)];
    }
    cout << rj << endl;
    return 0;
}


Measured memory_bytes: 33024
#include <stdio.h>
int main()
{
    int X,A;
    scanf("%d",&X);
    scanf("%d",&A);


        if((X>=0)&&(A<=9)){
        if(X<A){
            printf("0\n");
        }
        else{
            printf("10\n");
        }
        }

    return 0;
}


Measured memory_bytes: 128
M,D=map(int,input().split())

count=0

i=10
while i<D+1:
  if D<10:break
  temp=str(i)
  d1=int(temp[0])
  d2=int(temp[1])
  if d1*d2<=M and d1>1 and d2>1:
    count+=1
    #print(d1,d2)
  
  i=i+1
  
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define MAX 333
#define endl '\n'
#define boost ios_base::sync_with_stdio(0);cin.tie(0)
#define ONLINE_JUDGE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
const int inf=1e15;
int ans[MAX][MAX];
int cnt=0;

int32_t main()
{
	//ONLINE_JUDGE;
    boost;

    int n,m,k;
    cin>>n>>m>>k;
    memset(ans,-1,sizeof ans);
    int a[n+5]={0};
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		char c;
    		cin>>c;
    		if(c=='#')
    		{
    			ans[i+1][j+1]=++cnt;
    			a[i+1]++;
    		}
    	}
    }
    
    for(int i=1;i<=n;i++)
    {
    	if(a[i]>0)
    	{
    		for(int j=1;j<=m;j++)
    		{
    			if(ans[i][j]==-1)
    				ans[i][j]=ans[i][j-1];
    		}
    		for(int j=m;j>0;j--)
    		{
    			if(ans[i][j]==-1)
    				ans[i][j]=ans[i][j+1];
    		}
    	}
    }

    for(int i=1;i<=n;i++)
    {
    	if(a[i]==0)
    	{
    		if(a[i-1]>0)
    		{
    			a[i]=1;
    			for(int j=1;j<=m;j++)
    				ans[i][j]=ans[i-1][j];
    		}
    		else if(a[i+1]>0)
    		{
    			a[i]=1;
    			for(int j=1;j<=m;j++)
    				ans[i][j]=ans[i+1][j];
    		}
    	}
    }


    for(int i=n;i>0;i--)
    {
    	if(a[i]==0)
    	{
    		if(a[i+1]>0)
    		{
    			a[i]=1;
    			for(int j=m;j>0;j--)
    				ans[i][j]=ans[i+1][j];
    		}
    		else if(a[i-1]>0)
    		{
    			a[i]=1;
    			for(int j=m;j>0;j--)
    				ans[i][j]=ans[i-1][j];
    		}
    	}
    }

    for(int i=1;i<=n;i++)
   	{
   		for(int j=1;j<=m;j++)
   			cout<<ans[i][j]<<" ";
   		cout<<endl;
   	}
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
bool vis[26];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	if(s.size()==26){
		int p;
		for(p=25;p>=0;p--)
			if(s[p]<s[p+1])
				break;
		if(p==-1)
			cout<<-1<<endl;
		else{
			next_permutation(s.begin()+p,s.end());
			s=s.substr(0,p+1);
			cout<<s<<endl;
		}
	}
	else{
		for(auto it:s)
			vis[it-'a']=true;
		for(int i=0;i<26;i++)
			if(!vis[i]){
				cout<<s<<char('a'+i)<<endl;
				break;
			}
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char S[3];
  char A[3] = "AAA";
  char B[3] = "BBB";

  scanf("%s", S);

  if(strncmp(S, A, 3) == 0 && strncmp(S, B, 3) != 0) printf("No");
  else if(strncmp(S, A, 3) != 0 && strncmp(S, B, 3) == 0) printf("No");
  else printf("Yes");

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long g,q,re=1e18;
    scanf("%lld",&q);
    for(g=1;g*g<=q;g++)if(q%g==0){
        re=min(re,(g+(q/g))-2);
    }
    printf("%lld\n",re);
    return 0;
}


Measured memory_bytes: 256
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b = na()
print((a + b) % 24)

Measured memory_bytes: 3900
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 1010
#define MOD 1000000007
using namespace std;
typedef long long ll;
vector<int> a[MAXN],id[MAXN];
int vis[MAXN];
int n,m,k,cnt;
int dfn[MAXN],low[MAXN];
ll mi[MAXN],inv[MAXN],fac[MAXN],ans=1ll;
ll fsp(ll x,int y){
	ll res=1;
	while(y){
		if(y&1)
			res=res*x%MOD;
		x=x*x%MOD;
		y>>=1;	
	}
	return res;
}
ll C(int n,int m){
	return fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}
int gcd(int x,int y){
	if(y==0)
		return x;
	return gcd(y,x%y);	
}
int s[MAXN],s1[MAXN],top,used[MAXN];
void dfs(int x){
	dfn[x]=low[x]=++cnt;
	for(int i=0;i<a[x].size();i++){
		if(vis[id[x][i]]==1)
			continue;
		int u=a[x][i];
		s[++top]=id[x][i];
		vis[id[x][i]]=1;
		s1[top]=x;
		if(dfn[u]==0){
			dfs(u);
			low[x]=min(low[x],low[u]);
			if(low[u]>=dfn[x]){
				bool flag=1;
				int tot=0;
				for(int j=top;s[j+1]!=id[x][i];j--){
					if(used[s1[j]]==1)
						flag=0;
					tot++;
					used[s1[j]]=1;
				}
				if(flag){
					ll res=0;
					for(int j=1;j<=tot;j++){
						res+=mi[gcd(j,tot)];
						res%=MOD;
					}
					res*=fsp(tot,MOD-2);
					res%=MOD;
					ans*=res;
					ans%=MOD;
				}
				else{
					ans=ans*C(tot+k-1,k-1)%MOD;
				}
				//PF("|{%d:",x);
				for(;s[top+1]!=id[x][i];top--){
					used[s1[top]]=0;
					//PF("%d(%d) ",s1[top],s[top]);
				}
			//	PF("|[%d]\n",top);
			}
		}
		else
			low[x]=min(low[x],dfn[u]);
	}
}
int main(){
	SF("%d%d%d",&n,&m,&k);
	int u,v;
	for(int i=1;i<=m;i++){
		SF("%d%d",&u,&v);
		a[u].push_back(v);
		a[v].push_back(u);
		id[u].push_back(i);
		id[v].push_back(i);
	}
	fac[0]=1ll;
	mi[0]=1ll;
	for(int i=1;i<=MAXN-10;i++){
		fac[i]=fac[i-1]*i%MOD;
		mi[i]=mi[i-1]*k%MOD;
	}
	inv[MAXN-10]=fsp(fac[MAXN-10],MOD-2);
	for(int i=MAXN-10;i>=1;i--)
		inv[i-1]=inv[i]*i%MOD;
	for(int i=1;i<=n;i++)
		if(dfn[i]==0)
			dfs(i);
	PF("%lld",ans);
}	

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int get(int x) {
  if (x==1) return 300000;
  if (x==2) return 200000;
  if (x==3) return 100000;
  return 0;
}

int main () {
  int x, y;
  cin >> x >> y;
  int ans = get(x)+get(y);
  if (x==1&&y==1) ans += 400000;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/



signed main() {
	string s; cin >> s;
	int cnt = 0;
	rep(i, s.size()) {
		if (s[i] == 'o')cnt++;
	}
	if (cnt + 15 - s.size() >= 8)cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int N, D; std::cin >> N >> D;

  std::cout << std::ceil((float)N/(1+2*D)) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 100000007

#define p_b push_back
#define m_p make_pair

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FI freopen("input.txt", "r", stdin);
#define FO freopen("output.txt", "w", stdout);

#define MAX 10000000
#define all(x) x.begin(), x.end()
using namespace std;

struct Node
{
	ll val, pos;
};

vector<ll> v;
map<ll, ll> mp;

/*void pow(){
	v.clear();
	v.p_b(0);
	for(ll i=0; ; i++){
		ll value = pow(2, i);
		v.p_b(value);
		if(value >= 1000000000) break;
	}
}*/

/*void sieve(){
	ll arr[MAX];
	memset(arr, 0, sizeof(arr));
	prime.clear();
	prime.p_b(2);
	for(ll i=3; i*i <=MAX; i+=2){
		if(arr[i] == 0){
			for(ll j=i*i; j<=MAX; j+= i){
				arr[j] = 1;
			}
		}
	}
	for(ll i=3; i<=MAX; i+=2){
		if(arr[i] == 0) prime.p_b(i);
	}
}*/



bool pal_check(string s){

	string rs = s;
	reverse(all(rs));

	return rs == s;
}



int main (){
	//FI;
	//sieve();	
	int n;
	cin>>n;
	int arr[n+5];
	
	for(int i=0; i<n; i++){
		cin>>arr[i];
		
	}

	/*for(int i=0; i<n; i++){
		cout<<arr[i]<<" ";
		
	}
	cout<<endl;*/

	bool flag = 0;
	for(int i=0; i<n; i++){
		if(arr[i]%2 == 0){
			if(arr[i]%3 != 0 && arr[i]%5 != 0){
				flag = 1;
				break;
			}
			
		}
	}
	if(flag) cout<<"DENIED"<<endl;
	else 
		cout<<"APPROVED"<<endl;

	
	return 0;
	
}

Measured memory_bytes: 256