akhauriyash/Code-Regression huggingface dataset:
#include <string.h>

int w,h,s,t,max;
int map[101][101];

void solve(int si,int sj){
  int i,j,count=0;

  for(i=si;i<si+t;i++){
    for(j=sj;j<sj+s;j++){
      if(map[i][j]==1){count++;}
    }
  }
  if(max<count){max=count;}
}

int main(void){
  int i,j,n,x,y;
  while(1){
    scanf("%d",&n);
    if(!n) break;

    max = 0;
    memset(map,0,sizeof(map));
    scanf("%d%d",&w,&h);
    while(n--){
      scanf("%d%d",&x,&y);
      map[y-1][x-1]=1;
    }
    scanf("%d%d",&s,&t);

    for(i=0;i<=h-t;i++){
      for(j=0;j<=w-s;j++){
        solve(i,j);
      }
    }
    printf("%d\n",max);
  }

  return 0;
}

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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

LL BOX[3];

int Count(int b, int rest) {
	int size = BOX[b];
	if (b == 2) {
		if (rest % size == 0) {
			return 1;
		}
		return 0;
	}

	int c = 0;
	for (int i = 0; i * size <= rest; ++i) {
		c += Count(b + 1, rest - i * size);
	}

	return c;
}

int main()
{
	LL N;
	cin >> BOX[0] >> BOX[1] >> BOX[2] >> N;

	int c = Count(0, N);
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x[100005],y[100005];
char s[100005],n[100005],bu[100005];
int cnt1=0,cnt2=0;
int main()
{
    memset(x,0,sizeof(x));
    memset(y,0,sizeof(y));
    scanf("%s",s+1);
    int len=strlen(s+1);
    int i,j;
    for(i=len;i>=1;i--)
    {
       n[len-i+1]=s[i];
    } // printf("%s",n+1);
    int d=1;
    for(i=1;i<=len;i++)
    {
        if(s[i]!='x') {bu[d++]=s[i];cnt1++;}
        else cnt2++;
    }
    //printf("%d %d",cnt1,cnt2);
    for(i=1,j=d-1;i<d;i++,j--)
    {
        if(bu[i]!=bu[j])
        {
           printf("-1\n");return 0;
        }
    }
    int k=0,xx=0,pos,cnt=0;;
    if(cnt1%2==1)
    {
    for(i=1;i<=len;i++)
    {
       if(s[i]!='x') k++;
       else xx++;
       if(k==cnt1/2+1){ pos=i;}
    }
    for(i=1,j=len;i<=j;)
    {
        if(s[i]==s[j]){i++;j--;}
        else
        {
            if(s[i]=='x') i++;
            else if(s[j]=='x')j--;
             cnt++;
        }
    }
    }
    else
    {
    for(i=1;i<=len;i++)
    {
       if(s[i]!='x') k++;
       else xx++;
       if(k==cnt1/2){ pos=i;}
    }
    for(i=1,j=len;i<=j;)
    {
        if(s[i]==s[j]){i++;j--;}
        else
        {
            if(s[i]=='x') i++;
            else if(s[j]=='x')j--;
             cnt++;
        }
    }
    } printf("%d\n",cnt);
}


Measured memory_bytes: 1280
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef map<string,int> msi;

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    int k;
    cin >> k;
    if (k == 0) break;

    string sstr, gstr;
    cin >> sstr >> gstr;

    msi dists;
    dists[sstr] = 0;

    queue<string> q;
    q.push(sstr);

    while (! q.empty()) {
      string u = q.front(); q.pop();

      int i;
      for (i = 0; i < k && u[i] == gstr[i]; i++);
      if (i == k) break;

      int ud = dists[u];
      int r = (gstr[i] - u[i] + 10) % 10;

      for (; i < k; i++) {
	u[i] = (((u[i] - '0') + r) % 10) + '0';
	if (dists.find(u) == dists.end()) {
	  dists[u] = ud + 1;
	  q.push(u);
	}
      }
    }

    cout << dists[gstr] << endl;
  }

  return 0;
}

Measured memory_bytes: 2644
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <map>
#include <istream>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <stack>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string>

// #define int long long
#define ull unsigned long long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

using namespace std;

typedef long long ll;
typedef long double ld;

struct node{
    string s;
    int ind, sc;
};

bool comp(node a, node b){
    if(a.s == b.s){
        return a.sc > b.sc;
    }
    return a.s < b.s;
}


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<node> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i].s >> a[i].sc;
        a[i].ind = i + 1;
    }
    sort(all(a), comp);
    for(int i = 0;i < n;i++){
        cout << a[i].ind << endl;
    }
    rr;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll inf=1000000000000000000;
  ll x[n],y[n];
  vector<pair<ll,ll>>vx,vy;
  for(ll i=0;i<n;i++){
    cin>>x[i]>>y[i];
    vx.push_back(make_pair(x[i],i));
    vy.push_back(make_pair(y[i],i));
  }
  sort(vx.begin(),vx.end());
  sort(vy.begin(),vy.end());
  vector<pair<ll,ll>>listx[n],listy[n];
  for(ll i=0;i<n;i++){
    ll xf=vx[i].first,xs=vx[i].second;
    ll yf=vy[i].first,ys=vy[i].second;
    if(i==0){
      ll xnf=vx[i+1].first,xns=vx[i+1].second;
      ll ynf=vy[i+1].first,yns=vy[i+1].second;
      listx[xs].push_back(make_pair(xnf-xf,xns));
      listy[ys].push_back(make_pair(ynf-yf,yns));
    }
    else if(i==n-1){
      ll xpf=vx[i-1].first,xps=vx[i-1].second;
      ll ypf=vy[i-1].first,yps=vy[i-1].second;
      listx[xs].push_back(make_pair(xf-xpf,xps));
      listy[ys].push_back(make_pair(yf-ypf,yps));
    }
    else{
      ll xnf=vx[i+1].first,xns=vx[i+1].second;
      ll ynf=vy[i+1].first,yns=vy[i+1].second;
      listx[xs].push_back(make_pair(xnf-xf,xns));
      listy[ys].push_back(make_pair(ynf-yf,yns));
      ll xpf=vx[i-1].first,xps=vx[i-1].second;
      ll ypf=vy[i-1].first,yps=vy[i-1].second;
      listx[xs].push_back(make_pair(xf-xpf,xps));
      listy[ys].push_back(make_pair(yf-ypf,yps));
    }
  }
  //cout<<listy[2][1].first;return 0;
              
  //for(ll i=0;i<n;i++)cout<<listy[i][0].first<<"  "<<listy[i][0].second<<endl;return 0;
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>p;
  ll d[n];
  fill(d,d+n,inf);
  d[0]=0;
  p.push(make_pair((ll)0,(ll)0));//(距離、番号）
  ll ans=0;
  bool used[n];
  fill(used,used+n,false);
  while(p.size()>0){
    pair<ll,ll>pnow=p.top();p.pop();
    ll pnf=pnow.first,pns=pnow.second;
    if(used[pns])continue;
    used[pns]=true;
    //cout<<pnf<<" "<<pns<<endl;
    ans+=pnf;
    for(ll i=0;i<listx[pns].size();i++){
      ll lxf=listx[pns][i].first,lxs=listx[pns][i].second;
      if(lxf<d[lxs]){
        d[lxs]=lxf;
        p.push(make_pair(d[lxs],lxs));
      }
    }
    for(ll i=0;i<listy[pns].size();i++){
      ll lyf=listy[pns][i].first,lys=listy[pns][i].second;
      if(lyf<d[lys]){
        d[lys]=lyf;
        p.push(make_pair(d[lys],lys));
      }
    }
    //cout<<d[0]<<" "<<d[1]<<" "<<d[2]<<endl;
  }
  cout<<ans<<endl;
}
    
    
                   

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

int kaib(int in){
    return in * 100 + (in/10%10) * 10 + (in/100);
}

int main(){
    int A, B;

    cin >> A >> B;

    int a = A/100;
    if(kaib(a)<A){
        a++;
    }
    int i = 0;
    while(true){
        if(B < kaib(a+i)){
            break;
        }
        i++;
    }

    cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ss string
#define ll long long int
#define Endl endl
#define forn for(long long int i=0;i<n;i++)
#define u_b upper_bound
#define rep(i,n)         for(int i=0;i<n;i++)
#define ld long double
#define tc long long t;cin>>t;while(t--)
#define fr(i,a,b)        for(long long int i=a;i<=b;i++)
#define E endl
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define V vector<ll>v;
#define aaste long long int n;cin>>n;long long int a[n];for(long long int i=0;i<n;i++)cin>>a[i];
const ll   mod=            1e9 + 7;
const ll   MOD1=           (int)1e9 + 9;
const ll   MOD2=           998244353;
const ld    pi=             atan2(0, -1);
const ld    eps=            1e-9;
ll         tests=          1;

using namespace std;
int binarySearch(int arr[], int l, int r, int x)
{
	if (r >= l) {
		int mid = l + (r - l) / 2;
		if (arr[mid] == x)
			return mid;
		if (arr[mid] > x)
			return binarySearch(arr, l, mid - 1, x);
		return binarySearch(arr, mid + 1, r, x);
	}
	return l;
}
void swap(ll *p1, ll *p2)
{
   ll temp=*p1;
   *p1=*p2;
   *p2=temp;
}
// ll ctr=1;
// ll vis[10001];
// ll color[10001];
// vector<ll>v[10001];
// void dfs(ll node,ll colr)
// {
// 	vis[node]=1;
// 	for(ll i=0;i<v[node].size();i++)
// 	{
//        if(!vis[v[node][i]])
//        {
//        	  if(color[v[node][i]]!=colr)
//        	  	ctr++;
//        	dfs(v[node][i],color[v[node][i]]);
//        }
// 	}
// }
 // for(ll i=2;i<=n;i++)
    // {
    //       ll x;
    //      cin>>x;
    //    v[i].push_back(x);
    //    v[x].push_back(i);
    // }
    // fr(i,1,n)
    // {
    // 	cin>>color[i];
    // }
    // ll result=0;
    // dfs(1,color[1]);
    // result+=ctr;
    // cout<<result;
   // for(ll i=1;i<=n;i++)
   // {
   // 	   cout<<i;
   // 	for(ll j=0;j<v[i].size();j++)
   // 	{
   // 		cout<<"-"<<v[i][j];
   // 	}
   // 	cout<<endl;
   // }
int main()
{
    #ifndef ONLINE_JUDGE
	{
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	}
   #endif
  
    ll a,b;
    cin>>a>>b;
    if(b>=a)
    	cout<<"unsafe";
    else
    	cout<<"safe";
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 
#include <cctype>

using namespace std;

void print(int A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void insertsort(int A[], int N) {
    for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        print(A, N);
    }
}

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

    print(A, N);
    insertsort(A, N);
    return 0;
}


Measured memory_bytes: 3056
#include <cstdio>
#include <climits>
using namespace std;

int n;
int con[21][21];
int cost[21];
bool used[21];

int dijkstra(int stt, int end) {
  int a, b, c, d;

  for (int i=1; i<=n; i++) cost[i] = INT_MAX;
  for (int i=1; i<=n; i++) used[i] = false;

  cost[stt] = 0;
  used[stt] = true;
  a = stt;
  while (!used[end]) {
    for (int i=1; i<=n; i++) {
      if (!used[i] && con[a][i]!=INT_MAX) {
        b = cost[a] + con[a][i];
        if (b < cost[i]) {
          cost[i] = b;
        }
      }
    }
    c = INT_MAX;
    d = 0;
    for (int i=1; i<=n; i++) {
      if (!used[i] && cost[i] < c) {
        c = cost[i];
        d = i;
      }
    }
    used[d] = true;
    a = d;
  }

  return cost[end];
}

int main() {
  int m, a, b, c, d;
  int stt, end, budget, pole, ans;

  scanf("%d", &n);
  scanf("%d", &m);

  for (int i=1; i<=n; i++) {
    for (int j=1; j<=n; j++) {
      con[i][j] = INT_MAX;
    }
  }

  for (int i=0; i<m; i++) {
    scanf("%d,%d,%d,%d", &a, &b, &c, &d);
    con[a][b] = c;
    con[b][a] = d;
  }
  scanf("%d,%d,%d,%d", &stt, &end, &budget, &pole);

  ans = budget - dijkstra(stt, end) - dijkstra(end, stt) - pole;
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 1028
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

#define ARRAY_SIZE 300000

int data[ARRAY_SIZE];
int sorted_data[ARRAY_SIZE];
int smaller;
int larger;

int is_smaller(const void* a, const void* b)
{
  return *(int*)a < *(int*)b;
}

void print_array(int* data, int size)
{
  for(int i = 0; i < size; i++) {
    printf("%d\n", data[i]);
  }
}

void find_median(int* data, int size)
{
  larger  = data[size/2-1];
  smaller = data[size/2];
}

int main()
{
  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &data[i]);
  }
  memcpy(sorted_data, data, sizeof(int) * n);
  qsort(sorted_data, n, sizeof(int), is_smaller);
  //print_array(data, n);

  find_median(sorted_data, n);
  for(int i = 0; i < n; i++) {
    if(data[i] <= smaller) {
      printf("%d\n", larger);
    } else {
      printf("%d\n", smaller);
    }
  }
  return 0;
}


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

const ll MOD = 1000000007;

int a[100005];
int c[100005];
int d[100005];

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

    int n;
    cin >> n;
    ll ans  = 1;
    ll mult = 0;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        if (a[i] == 0)
            mult++;
    for (int i = 0; i < n; i++) {
        if (a[i]) {
            if (!c[a[i] - 1]) {
                cout << 0 << endl;
                return 0;
            }
            ans = ans * c[a[i] - 1] % MOD;
            c[a[i] - 1]--;
        }
        c[a[i]]++;
    }
    if (mult == 0 || mult > 3) {
        ans = 0;
    } else if (mult == 1) {
        ans = ans * 3 % MOD;
    } else if (mult == 2) {
        ans = ans * 6 % MOD;
    } else {
        ans = ans * 6 % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stack>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <tuple>

using namespace std;

int main() {
  int n,k;
  string s;
  cin >> n >> k >> s;
  
  int result = 0;
  int unfortunate = 0;
  
  //一度の操作で幸せになれるのは、捜査の両端の人のみ(=+2)
  char old_c = s[0];
  for (int i = 1; i < s.size(); i++) {
    char c = s[i];
    if (old_c == c) {
      // すでに幸せ(LとRの違いは無視していい)
      result++;
    } else {
      // まだ不幸せ
      unfortunate++;
    }
    
    old_c = c;
  }
  
  result += min(2*k, unfortunate);
 
  cout << result << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



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

const int MAX_V=50;
const int MAX_S=MAX_V*50+5;
const ll INF=1e18;

struct Edge{
  int to,a,b;
  Edge(int to, int a, int b):to(to),a(a),b(b) {}
};

struct Data {
  int v, s;
  ll x;
  Data(int v, int s, ll x):v(v),s(s),x(x) {}
  bool operator<(const Data& a) const {
    return x > a.x;
  }
};

vector<Edge> g[MAX_V];
ll dp[MAX_V][MAX_S+5];


int main(){
  int n,m,s;
  cin >>n>>m>>s;
  rep(i,m){
    int u,v,a,b;
    cin >>u>>v>>a>>b;
    --u; --v;
    g[u].emplace_back(v,a,b);
    g[v].emplace_back(u,a,b);
  }
  vector<int> c(n), d(n);
  rep(i,n) cin >> c[i] >> d[i];

  rep(i,MAX_V)rep(j,MAX_S+5)dp[i][j] =INF;
  s=min(s,MAX_S);

  priority_queue<Data> q;
  auto push =[&](int v,int s, ll x){
    if (s<0) return ;
    if (dp[v][s]<=x) return;
    dp[v][s]=x;
    q.emplace(v,s,x);
  };

  push(0,s,0);
  while (!q.empty()){
    Data hoge =q.top(); q.pop();
    int v=hoge.v, s=hoge.s;
    ll x =hoge.x;
    if(dp[v][s]>x) continue;
    {
      int ns=min(s+c[v],MAX_S);
      push(v,ns,x+d[v]);
    }
    for(Edge e :g[v]){
      push(e.to,s-e.a,x+e.b);
    }
  }
  for (int i=1;i<n;++i){
    ll ans =INF;
    rep(j,MAX_S+5){
      ans =min(ans,dp[i][j]);
    }
    cout <<ans<<endl;
  }



}


Measured memory_bytes: 6296
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

sum1 = 0
sum2 = 0
sum3 = 0
dif = []
for i in range(n):
    sum1 += abs(x[i] - y[i])
    sum2 += abs(x[i] - y[i])**2
    sum3 += abs(x[i] - y[i])**3
    dif += [abs(x[i] - y[i])]
print("%f" %sum1)
print("%f" %(sum2)**(1/2))
print("%f" %(sum3)**(1/3))
print("%f" %max(dif))


Measured memory_bytes: 5644
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<sstream>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>p(n);
	int cnt = 0;
	rep(i, n) {
		cin >> p[i];
		if (p[i] != i + 1) {
			cnt++;
		}
	}
	if (cnt <= 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<long long> A(N), B(N), C(N);
    REP(i, N){
        cin >> A[i];
        B[i] = i - A[i];
        C[i] = i + A[i];
    }
    map<long long, long long> mp;
    mp[C[0]]++;
    long long ans = 0;
    for(int j=1; j<N; j++){
        ans += mp[B[j]];
        mp[C[j]]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 30628
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 400010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

template <class T> void read(T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  cout << a[0] + a[1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  int x = 0;
  rep(i, S.size())
  {
    if (S[i] == 'I')
      x++;
    else if (S[i] == 'D')
      x--;
    ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	vector<vector<int>> a(3,vector<int> (3,0));
	int i, j,k;
	for(i = 0; i < 3; ++i) {
		for(j = 0; j < 3; ++j) {
			cin >> a.at(i).at(j);
		}
	}
	int n;
	cin >> n;
	vector<int> b(n);
	for(k = 0; k <n; ++k) {
		cin >> b.at(k);
		for(i = 0; i < 3; ++i) {
			for(j = 0; j < 3; ++j) {
				if(b.at(k) == a.at(i).at(j))
					a.at(i).at(j) = 0;
			}
		}
	}
	for(i = 0; i < 3; ++i) {
		if((a.at(i).at(0) == a.at(i).at(1) && a.at(i).at(1) == a.at(i).at(2))
			|| (a.at(0).at(i) == a.at(1).at(i) && a.at(1).at(i) == a.at(2).at(i))
			|| (a.at(0).at(0) == a.at(1).at(1) && a.at(1).at(1) == a.at(2).at(2))
			|| (a.at(0).at(2) == a.at(1).at(1) && a.at(1).at(1) == a.at(2).at(0))) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String [] letters = new String[3];

        for (int i = 0; i < 3; i++) {
            letters[i] = input.readLine();
        }
        int current = 0;
        int [] positions = new int[3];
        while (true){
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        }
    }
}



Measured memory_bytes: 22996
#define M(a,b) (a<b?a:b)
#define S(a,b) sqrt(a*a+b*b)
main(a,b,c,n,r){for(;scanf("%d%d%d",&a,&b,&c),a|b|c;)for(scanf("%d",&n);n--;puts((2*r>M(M(S(a,b),S(b,c)),S(c,a)))?"OK":"NA"))scanf("%d",&r);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec(x) vector<x>
#define pb push_back
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pair<ll,ll>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define ff first
#define ss second
#define mp make_pair
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main()
{
ll t;
cin>>t;
ll a[t];
for(ll i=0;i<t;i++)
{
cin>>a[i];

}
sort(a,a+t);
ll len=t*2-1;
ll j=0;
ll b[len];
ll cont=0;
for(ll i=t-1;i>=0;i--)
{
   if(i==t-1)
   {
      b[j]=a[i];
      j++;
   }
   else
   {
       b[j]=a[i];
       b[j+1]=a[i];
       j=j+2;
   }

}
ll sum=0;
for(ll i=0;i<len;i++)
{
    sum=sum+b[i];
    cont++;
    if(cont==t-1)
        break;

}
cout<<sum<<endl;


}


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

using namespace std;
using Int = long long;

int x[10 * 10] = {0};

signed main(){
    int n;
    vector<int> p;

    cin >> n;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(p[i] != i + 1){
            cnt++;
        }
    }
    if(cnt == 2 || cnt == 0){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
#include <set> 
using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
typedef pair<pair<int, int>, int> PP;

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

const ll INF = 1e15;
const ll MAX = 510000;
const ll MOD = 1000000007;


int main(void) {
	int N, K, Q; cin >> N >> K >> Q;
	vector<int> point(N);
	for (int i = 0; i < Q; i++) {
		int n; cin >> n;n--;
		point[n]++;
	}
	for (int i = 0; i < N; i++) {
		if (K - Q + point[i] > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

}


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

int main(){
	vector<int> a(9);
	rep(i, 9) cin >> a.at(i);
	
	int n;
	cin >> n;
	
	vector<int> b(n);
	vector<bool> c(9, false);
	rep(i, n) {
		cin >> b.at(i);
		rep(j, 9) {
			if (a.at(j) == b.at(i)) c.at(j) = true;
		}
	}
	
	if ((c.at(0)&&c.at(1)&&c.at(2))||
		(c.at(3)&&c.at(4)&&c.at(5))||
		(c.at(6)&&c.at(7)&&c.at(8))||
		(c.at(0)&&c.at(3)&&c.at(6))||
		(c.at(1)&&c.at(4)&&c.at(7))||
		(c.at(2)&&c.at(5)&&c.at(8))||
		(c.at(0)&&c.at(4)&&c.at(8))||
		(c.at(2)&&c.at(4)&&c.at(6))) {
			cout << "Yes" << endl;
		} else {
			cout << "No" <<endl;
		}
}

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

long long xorsum(long long x){
    if(x%4 == 3){return 0;}
    if(x%4 == 1){return 1;}
    if(x%4 == 2){return x+1;}
    if(x%4 == 0){return x;}
}

int main (){
    long long A,B;
    cin >> A >> B;
    cout << (xorsum(A-1) ^ xorsum(B)) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

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

    vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];

    sort(v.begin(), v.end());

    int cnt = 0;
    for(int i = 0 ; i < n && x; i++) {
        if(x >= v[i]) {
            x -= v[i];
            cnt++;
        }
    }

    if(x && cnt == n)
        cnt--;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long

using namespace std;

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


  int a, b, c;
  cin >> a >> b >> c;

  if (a == b && b == c) cout << "Yes";
  else cout << "No";
  cout << endl;



  return 0;
}


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

using namespace std;
using ll = long long;
int n,m,ans;
string s;
// WRWWRWRR
// RRWWWWRR
// RRRWWWWR
// RRRRWWWW
vector<int> idx;
priority_queue<int,vector<int>,greater<int>> pq;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n>>s;
    // WRRR
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'R') idx.push_back(i+1); // 2 3 4
    }
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'R') ans++;
    }
    for(int i=0; i<idx.size(); i++) if(idx[i] <= ans) m++;
    cout<<ans-m;
}


Measured memory_bytes: 4460
#include <bits/stdc++.h>
using namespace std;
int main(){
    int64_t a, b, x;
    cin >> a >> b >> x;
    if(a%x==0){
        cout << b/x - a/x + 1 << endl;
    }else{
        cout << b/x - a/x << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n,k;
    cin >> n >> k;
    int p[n];
    rep(i,n)cin >> p[i];

    int ans = 0;

    priority_queue<int> ma;
    priority_queue<int> mi;
    int flag[n] = {};
    int f[n] = {};
    int cnt = 0;
    rep(i,n){
        if(i == 0){
            cnt = 1;
        }else{
            if(p[i-1] < p[i]){
                cnt++;
            }else{
                cnt = 1;
            }
        }
        if(cnt>=k){
            f[i-k+1] = 1;
        }
    }

    cnt = 0;
    rep(i,n)cnt += f[i];

    rep(i,n-k+1){
        if(i == 0){
            rep(j,k){
                ma.push(p[j]);
                mi.push(-p[j]);
            }
            ans++;
            if(f[i] == 1)ans--;
        }else{
            while(flag[ma.top()] == 1){
                ma.pop();
            }
            while(flag[-mi.top()] == 1){
                mi.pop();
            }
            if(ma.top()<p[i+k-1] && mi.top() == -p[i-1]){
                ;
            }else if(f[i] == 0){
                ans++;
            }
            ma.push(p[i+k-1]);
            mi.push(-p[i+k-1]);
            flag[p[i-1]] = 1;
        }
    }

    if(cnt>0)ans++;

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


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

int main() {

  int N;
  long long K;
  cin >> N >> K;

  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<int> count(40);

  // A[0]からA[N-1]までの各桁の1の数を集計
  for (int i = 0; i < N; i++) {
    for (int j = 40; 0 <= j; j--) {
      if (A[i] >> j & 1) {
        count[j]++;
      }
    }
  }

  long long X = 0;

  // 10^12、およそ40桁を調べてXを求める
  for (int i = 40; 0 <= i; i--) {

    // XはKを超えたらダメ
    if (X + (1LL << i) > K) {
      continue;
    }
    
    // 桁の1の数が0の数より少ない場合は、
    // Xのその桁は1にする
    if (count[i] < N - count[i]) {
      X += (1LL << i);
    }

  }

  long long answer = 0;

  // 答えを求める
  for (int i = 0; i < N; i++) {
    answer += X ^ A[i];
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 1024
#140
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

s = sum(b)
for i in range(len(a)-1):
    if a[i]+1 == a[i+1]:
        s += c[a[i]-1]
print(s)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n,m; cin >>n>>m;

  char a[50][50],b[50][50];
  for(int i=0;i<n;i++)
  for(int j=0;j<n;j++)
  cin >>a[i][j];
  for(int i=0;i<m;i++)
  for(int j=0;j<m;j++)
  cin >>b[i][j];

  bool exist = false;
  for(int y=0; y<n;y++){
    for(int x=0;x<n;x++){
      if(y+m-1 >=n|| x+m-1>=n ) continue;

      bool match =true;

      for(int yy=0 ; yy<m;yy++){
        for(int xx=0; xx<m;xx++){
          if(a[y+yy][x+xx]!=b[yy][xx]) match = false;
        }
      }
      if( match ) exist = true;
    }
  }
  if(exist) cout  <<"Yes"<<endl;

  else cout <<"No"<<endl;


  }


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<set>
#include<iomanip>
#include<string>
#include<random>
#include<algorithm>
#include<queue>
#include<functional>

using namespace std;

#define X first
#define Y second

mt19937 rnd((size_t)time(nullptr));

const long long MAXM = 63, INF = 10000000, M = 1000000007;
const int MAXN = 1000010;

char a[MAXN];
int n;
long long f[MAXN];
string s;

bool is_good(int n, int k) {
	return (f[n] - f[k] - f[n - k] == 0);
}

int main()
{
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin >> n;
	cin >> s;
	f[0] = 0;
	for(int i = 1; i <= n; i++) {
		int cur = i;
		f[i] = f[i - 1];
		while (cur % 2 == 0) {
			++f[i];
			cur /= 2;
		}
	}
	bool have_one = false;
	for (int i = 0; i < s.size(); ++i) {
		s[i] = s[i] - 1;
		if (s[i] == '1') {
			have_one = true;
		}
	}
	int sum = 0;
	int pl;
	if (n % 2 == 1) {
		pl = 2;
	}
	else {
		pl = 1;
	}
	for (int i = 0; i < s.size(); i += pl) {
		if (s[i] == '1') {
			if (is_good(n - 1, i)) {
				++sum;
			}
		}
		if (s[i] == '2') {
			if (!have_one) {
				if (is_good(n - 1, i)) {
					++sum;
				}
			}
		}
	}
	if (sum % 2 == 1) {
		if (have_one) {
			cout << "1";
		}
		else {
			cout << "2";
		}
	}
	else {
		cout << "0";
	}
	return 0;
}

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

typedef long long int ll;

int main()
{
  ll n,count=0;cin>>n;
  for(int i=1;i<=n;i++)
  {
    if(i%3==0||i%5==0)
      continue;
    count+=i;
  }
  cout<<count<<"\n";
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
    fast; 
    ll x;
    cin>>x;
    ll ans;
    if(x <= 599)
    {
        ans =8;
    }
    else if(x<= 799)
    {
        ans = 7;
    }
    else if(x<= 999)
    {
        ans = 6;
    }
    else if(x<= 1199)
    {
        ans = 5;
    }
    else if(x<= 1399)
    {
        ans = 4;
    }
    else if(x<= 1599)
    {
        ans = 3;
    }
    else if(x<= 1799)
    {
        ans = 2;
    }
    else if(x<= 1999)
    {
        ans = 1;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

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

llint n;
llint a[1000005];
llint prime[1000005];
bool used[1000005];

llint gcd(llint a, llint b)
{
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	for(int i = 2; i < 1005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 1000005; j+=i) prime[j] = i;
	}
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint g = 0;
	for(int i = 1; i <= n; i++) g = gcd(g, a[i]);
	if(g > 1){
		cout << "not coprime" << endl;
		return 0;
	}
	
	for(int i = 1; i <= n; i++){
		llint v = a[i];
		if(v == 1) continue;
		//for(int j = 1; j <= 10; j++) cout << used[j] << " "; cout << endl;
		while(prime[v]){
			if(used[prime[v]]){
				//cout << a[i] << " " << v << " " << prime[v] << endl;
				cout << "setwise coprime" << endl;
				return 0;
			}
			used[prime[v]] = true;
			llint p = prime[v];
			while(v % p == 0) v /= p;
		}
		if(v == 1) continue;
		if(used[v]){
			cout << "setwise coprime" << endl;
			return 0;
		}
		used[v] = true;
	}
	cout << "pairwise coprime" << endl;
	
	return 0;
}

Measured memory_bytes: 19288
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string S;
  cin >> S;
  if (S[S.size() - 1] == 's') {
    cout << S + "es" << endl;
  } else {
    cout << S + "s" << endl;
  }
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N,T;
  cin >> N >> T;
  vector<ll> v(N);
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  }

  ll max_val = v.back();

  map<ll, int> m;
  for(int i = v.size()-1; i>=0; i--){
    max_val = max(max_val, v.at(i));
    v.at(i) = max_val - v.at(i);

    if(m.count(-v.at(i)) == 0){
      m[-v.at(i)] = 1;
    } else { 
      m[-v.at(i)] += 1;
    }
  }

  for(auto x:m){
    cout << x.second << endl;
    break;
  }
}



Measured memory_bytes: 7296
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), h = scanner.nextInt();
			int[] a = new int[n], b = new int[n];
			IntStream.range(0, n).forEach(i -> {
				a[i] = scanner.nextInt();
				b[i] = scanner.nextInt();
			});
			int maxA = Arrays.stream(a).max().getAsInt();
			int[] filteredB = Arrays.stream(b).filter(i -> i > maxA).toArray();
			long filterdBSum = Arrays.stream(filteredB).mapToLong(i -> (long) i).sum();
			if (h > filterdBSum) {
				System.out.println(((h - filterdBSum) + maxA - 1) / maxA + filteredB.length);
			} else {
				Arrays.sort(filteredB);
				int i = filteredB.length;
				while (h > 0) {
					h -= filteredB[--i];
				}
				System.out.println(filteredB.length - i);
			}
		}
	}
}


Measured memory_bytes: 62284
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

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




int main()
{
  // input & declare
  int h,w;
  int count = 0;
  int dx[4] = {1,0,-1,0};
  int dy[4] = {0,1,0,-1};
  cin >> h >> w;
  std::vector<string> maze;
  int d[h][w];
  string s;
  for(int i = 0; i < h; i++){
    cin >> s;
    maze.push_back(s);
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      d[i][j] = INT_MAX;
      // if (maze[i][j] = '#') {
      //   d[i][j] = -1;
      // }
    }
  }
  std::vector<p> shortest;

  queue<p> q;
  q.push(p(0,0));
  d[0][0] = 0;
  // process
  while (q.size() != 0) {
    p ptmp = q.front();
    q.pop();
    for(int i = 0; i < 4; i++)
    {
      int ny = ptmp.first + dy[i];
      int nx = ptmp.second + dx[i];
      if (ny >= 0 && ny < h && nx >= 0 && nx < w && d[ny][nx] == INT_MAX && maze[ny][nx] == '.') {
        d[ny][nx] = d[ptmp.first][ptmp.second] + 1;
        q.push(p(ny,nx));
       }
       if (ptmp.first == h-1 && ptmp.second == w-1) break;
    }
  }

  if (d[h-1][w-1] == INT_MAX) {
    std::cout << "-1" << '\n';
    exit(0);
  }
  count = (h * w) - 1 - d[h-1][w-1];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if (maze[i][j] == '#') {
        count--;
      }
    }
  }
  // output
  // std::cout << d[h-1][w-1] << '\n';
  std::cout << count << '\n';
}


Measured memory_bytes: 256
x,y=map(int,input().split())
g=[[1,3,5,7,8,10,12],[2],[4,6,9,11]]
def check(num):
    g_num=0
    for i in range(1,3):
        if num in g[i]:
            g_num=i
            break
    return g_num
if check(x)==check(y):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

Measured memory_bytes: 256
import fractions
a,b,c,d=map(int,input().split())
a=a-1

ac=a//c
ad=a//d
bc=b//c
bd=b//d

f=fractions.gcd(c,d)
f=c*d//f

acd=a//f
bcd=b//f

print((b-a)-(bc-ac)-(bd-ad)+(bcd-acd))


Measured memory_bytes: 5048
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

int main()
{
    long long int N;
    scanf("%lld", &N);

    if (N % 2 != 0)
        N *= 2;

    printf("%lld", N);
}


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

ll inf=1<<19-1;


ll dp[(1<<16)];
ll sums[(1<<16)];

ll calc(vector<vector<int>> &compat, int sub){

    ll ans=0;


    for(int i=0;i<=16;i++){
        for(int j=i+1;j<=16;j++){

            if((sub&(1<<i))!=0 && (sub&(1<<j))!=0){
                ans+=compat[i][j];

            }
        }
    }

    return ans;


}



void prepareSums(vector<vector<int>> &compat,int n){
    

    for(int submask=0;submask<(1<<n);submask++){
        dp[submask]=inf;
        
    }
    sums[0]=0;

    for(int submask=1;submask<(1<<n);submask++){
        sums[submask]=calc(compat,submask);
    }

}



ll maxGrouping(vector<vector<int>> &compat, int mask){

    if(mask==0){
        return 0;

    }
    if(dp[mask]!=inf){
        return dp[mask];
    }

    ll ans=0;

    for(int submask=mask;submask!=0;submask=(submask-1)&mask){

        ans=max(ans,sums[submask]+maxGrouping(compat,mask^submask));

    }

    return dp[mask]=ans;


}

int main() {
    int n;
    cin>>n;
    vector<vector<int>> compat(n,vector<int>(n));

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>compat[i][j];
        }
    }
    
    prepareSums(compat,n);

    cout<<maxGrouping(compat,(1<<n)-1);




}


Measured memory_bytes: 4616
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define ll long long

int main(){
  ll n,k,r,s,p,i,score=0;
  bool sb[100001];
  char t[100001];
  scanf("%lld%lld",&n,&k);
  scanf("%lld%lld%lld",&r,&s,&p);
  scanf("%s",t);
  for(i=0;i<strlen(t);i++){
    if(i>=k&&t[i]==t[i-k]&&sb[i-k]){
      continue;
    }
    if(t[i]=='r'){
      score+=p;
      sb[i]=true;
    }else if(t[i]=='s'){
      score+=r;
      sb[i]=true;
    }else if(t[i]=='p'){
      score+=s;
      sb[i]=true;
    }
  }
  printf("%lld",score);
  return 0;
}

Measured memory_bytes: 384
/*
the top of the losers
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    Lcm(a,b)  ((a*b)/(__gcd(a,b)))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define    x            real()
#define    y            imag()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     point        complex<double>
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
typedef  long long     ll ;
typedef  unsigned long long     ull ;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
ll mem[1009][(1<<12)+9];
const int inf=100000000;
int co[1009],M[1009],n,m;
ll solve(int id,int msk){
    if(id==m){
        if(msk==((1<<n)-1)) return 0;
        return inf;
    }

    ll &ret=mem[id][msk];
    if(ret!=-1) return ret;
    ll ans=inf;
    ans=min(ans,solve(id+1,msk));
    ans=min(ans,co[id]+solve(id+1,(msk|M[id])));
    return ret=ans;
}
int main(){
    GO();
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>co[i];
        int cnt;
        cin>>cnt;
        int msk=0;
        for(int j=0;j<cnt;j++){
            int no;
            cin>>no;
            no--;
            msk=setBit1(msk,no);
        }
        M[i]=msk;
    }
    clr(mem,-1);
    ll res=solve(0,0);
    cout<<(res>=inf?-1:res)<<endl;
}

Measured memory_bytes: 32640
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();
		double max = 0;
		double sum = 0;
		double p[] = new double[n];
		for(int i=0;i<n;i++) {
			int h = scan.nextInt();
			p[i] = (0.5*h*(h+1))/h;
			sum += p[i];

			if(i >= k) {
				sum -= p[i-k];
			}

			max = Math.max(max,sum);
		}


		System.out.println(max);

	}

}


Measured memory_bytes: 62156
//Program.cpp
//Author : Aaryan Srivastava 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define pb push_back
#define popb pop_back
#define ull unsigned long long  
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii,int>
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second 
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 2*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace std;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#define AaryanS 0 
#endif


void solve()
{
    // int mxans = 0,n ;
    // cin >> n ;
    // vector<int> c(n),v(n) ;
    // rep(i,n) cin >> v[i] ;
    // rep(i,n) cin >> c[i] ;
    // rep(i,(1<<n)){
    //     int ans = 0 ;
    //     rep(j,n){
    //         if((i>>j)&1)
    //             ans += v[j] - c[j] ;
    //     }
    //     mxans = max(mxans, ans) ;
    // }
    // cout << mxans ;
    int n ;
    cin >> n ;
    vector<int> a(n) ;
    int su = 0, mix = inf, neg = 0;
    rep(i,n){ cin >> a[i] ; su += abs(a[i]) , mix=min(mix,abs(a[i]) ) ; neg += (a[i] < 0) ;} 
    if(neg%2)
        cout << su - 2*mix ;
    else
        cout << su; 
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case " << t << ":\n" ;
        solve();
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 1024
import sys
def c():
    p = [[int(t) for t in r.split(' ')] for r in sys.stdin.read().split('\n') if r != '']
    N, K = p[0]
    D = p[1]
    #print(N, D)
    while True:
        n = N
        while True:
            if n % 10 in D:
                N = N + 1
                break
            #print("mod: ", n % 10)
            n = int(n / 10)
            if n == 0:
                print(N)
                quit()
c()


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s=sc.next();
    int n=s.length();
    int a[] = new int[n];
    Arrays.fill(a,0);
    int f=0;
    int b;
    int t;
    boolean flag=true;
    while(flag){
      b=s.indexOf("RL",f);
      t=s.indexOf("LR",b);
      if(t==-1){
        flag=false;
        t=n-1;
      }
      a[b]=a[b]+(b-f+1)/2+(b-f+1)%2+(t-b)/2;
      a[b+1]=a[b+1]+(b-f+1)/2+(t-b)/2+(t-b)%2;
      f=t+1;
    }
    for(int i=0;i<n;i++){
      System.out.println(a[i]);
    }
  }
}

Measured memory_bytes: 42204