akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long int
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

int main() {
    IOS;

    ll a, b; cin>>a>>b;
    if(a<b) swap(a, b);

    if( (a+b)%2!=0 ) cout<<"IMPOSSIBLE"<<endl;
    else cout<<(a+b)/2<<endl;

    return 0;
}


Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [n, m] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)
let a = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)

const [, , ..._bc] = stdin.trim().split('\n')
const bc = _bc.map(e => e.split(' ').map(Number))

const ans = _ => {
  let pool = a.map(e => [e, 1])

  for (let i = 0; i < m; i++) {
    const [b, c] = bc[i]

    pool.push([c, b])
  }

  pool.sort((a, b) => {
    return b[0] - a[0]
  })

  let i = 0
  let sum = 0
  let count = 0
  while (count < n) {
    const card = pool[i][0]
    sum += card
    count++
    pool[i][1]--
    if (pool[i][1] <= 0) {
      i++
    }
  }

  return sum
}

console.log(ans())


Measured memory_bytes: 73644
#include<iostream>
#include<math.h>
#include<set>
#define ll long long
using namespace std;

int main(){
  ll A,B,C,K;

  cin >> A >> B >> C >> K;

  if (A >= K){
    cout << K << endl;
    return 0;
  }

  if(A+B >= K){
    cout << A << endl;
    return 0;
  }

  cout << A-(K-A-B) << endl;



}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 998244353;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

std::vector<int> par;
std::vector<int> rak; // rank

void init(int n) {
  par.resize(n+1);
  rak.resize(n+1, 0);
  for(int i=1; i<=n; i++) {
    par[i] = i;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x==y) return;
  if (rak[x] < rak[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rak[x] == rak[y]) rak[x]++;
  }
}

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

vector<bool> used(100001);

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

  int n, m; cin >> n >> m;
  init(m);
  rep(i, n) {
    int k; cin >> k;
    int l0; cin >> l0;
    used[l0] = true;
    rep(j, k-1) {
      int l; cin >> l;
      unite(l0, l);
      used[l] = true;
    }
  }

  vector<int> parents;
  for(int i=1; i<=m; i++) {
    if (used[i]) {
      parents.push_back(find(i));
    }
  }

  sort(parents.begin(), parents.end());
  auto sz = parents.size();
  if (parents[0] == parents[sz-1]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=2005;

int n,a[N],last[N],deg[N],cnt;
bool vis[N];
struct edge{int to,next;}e[N*N];

int gcd(int x,int y)
{
	if (!y) return x;
	else return gcd(y,x%y);
}

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
	deg[v]++;
}

void dfs(int x)
{
	vis[x]=1;
	for (int i=1;i<=n;i++)
		if (!vis[i]&&gcd(a[x],a[i])>1)
		{
			addedge(x,i);
			dfs(i);
		}
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++) if (!vis[i]) dfs(i);
	memset(vis,0,sizeof(vis));
	for (int i=1;i<=n;i++)
	{
		for (int j=n;j>=1;j--)
			if (!vis[j]&&!deg[j])
			{
				vis[j]=1;
				printf("%d ",a[j]);
				for (int k=last[j];k;k=e[k].next) deg[e[k].to]--;
				break;
			}
	}
	return 0;
}

Measured memory_bytes: 384
def check():
    N = int(input())
    A = list(map(int, input().split()))
    if len(set(A))==1:
        if max(A)==N-1:
            return 'Yes'
    large = max(A)
    small = large-1
    n_s = list(map(lambda x:x-small,A)).count(0)
    if large==n_s:
        if n_s==N:
            return 'Yes'
        return 'No'
    if large<n_s:
        return 'No'
    if 2*(large-n_s)+n_s<=N:
        return 'Yes'
    return 'No'
print(check())

Measured memory_bytes: 20844
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int dp[200010];
struct RMQ
{
    int n;
    vector<int> dat;
    const int def = 0;
    RMQ() {}
    RMQ(int n_) { init(n_); }
    RMQ(int n_, int *a)
    {
        init(n_);
        build(n_, a);
    }
    void init(int n_)
    {
        n = 1;
        while (n < n_)
            n *= 2;
        dat.clear();
        dat.resize(2 * n - 1, def);
    }
    void build(int n_, int *a)
    {
        for (int i = 0; i < n_; i++)
            dat[i + n - 1] = a[i];
        for (int i = n - 2; i >= 0; i--)
            dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
    void update(int k, int a)
    {
        k += n - 1;
        dat[k] = a;
        while (k > 0)
        {
            k = (k - 1) / 2;
            dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    int query(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
            return def;
        if (a <= l && r <= b)
            return dat[k];
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
    int query(int a, int b)
    {
        return query(a, b, 0, 0, n);
    }
};

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

    int n;
    cin >> n;
    vector<int> a(n), h(n);
    rep(i, n) cin >> h[i];
    rep(i, n) cin >> a[i];
    vector<int> P(n + 1);
    rep(i, n) P[h[i]] = i + 1;
    RMQ rmq(n + 1);
    rep(i, n)
    {
        int pos = P[i + 1];
        int tmp = rmq.query(0, pos);
        dp[i + 1] = tmp + a[P[i + 1] - 1];
        rmq.update(pos, dp[i + 1]);
        //cout << pos << " " << tmp << " " << dp[i + 1] << endl;
        if (i == n)
            return 0;
    }
    int ans = 0;
    rep(i, n) ans = max(ans, dp[i + 1]);
    cout << ans << endl;
}

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

float rev(float a){
    float ans;
    ans = 1/a;
    return ans;
}

int main(){
   int n; cin >> n; int i=0;
   vector<float> a(100);
   while(i<n){
       cin >> a[i++];
   }

float ans=0;

for(int j=0; j<n; j++){
ans += rev(a[j]);
}

cout << rev(ans) << endl;
return 0;
}

Measured memory_bytes: 256
# ほぼ最短路を求めるだけ

import heapq as hp
import numpy as np

H,W = map(int,input().split())
S = np.array([list(input()) for _ in range(H)])
S = np.pad(S,1,'constant')
visited = np.zeros_like(S,dtype=np.bool)

dist = np.inf

h = []
hp.heappush(h,(0,1,1))

while h:
  d,x,y = hp.heappop(h)
  if x == H and y == W:
    dist = d
    break
  for dx,dy in [[0,1],[1,0],[-1,0],[0,-1]]:
    nx = x+dx
    ny = y+dy
    if S[nx,ny] == '.' and not visited[nx,ny]:
      visited[nx,ny] = True
      hp.heappush(h,(d+1,nx,ny))
      
if dist == np.inf:
  print(-1)
else:
  print((S == '.').sum() - dist - 1)


Measured memory_bytes: 13468
#include <iostream>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include <algorithm>
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define l long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i]}
using namespace std;
int main(){
    FAST
    int n; cin >> n;
    int x, y;
    ll counter=0;
    for(int a=1; a<=n; a++){
        for(int b=1; b<=n; b++){
            for(int c=1; c<=n; c++){
                x=__gcd(a,b);
                y=__gcd(x,c);
                counter+=y;
            }
        }
    }
    cout << counter << endl;
    return 0;
}


Measured memory_bytes: 3612
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

n = int(input())
a = list(map(int, input().split()))

phase = 0
now = [0,0,0]
ans=1

for i in range(n):
    if(a[i]==-1):
        now[phase]=1
        ans*=3-phase
        ans%=1000000007
        phase+=1
    else:
        corr = []
        for j in range(3):
            if(now[j]==a[i]):
                corr.append(j)
        ans*=len(corr)
        ans%=1000000007
        if(len(corr)!=0):
            now[corr[0]]+=1
print(ans) 

Measured memory_bytes: 52952
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

ans = 0
for _ in range(n):
    a = list(map(int, input().split()))
    s = 0
    for ai, bi in zip(a, b):
        s += ai * bi
    s += c
    if s > 0:
        ans += 1

print(ans)

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

int f(int n) {
  if (n % 2) n = n * 3 + 1;
  else n = n / 2;
  return n;
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int s; cin >> s;
  map<int, int> m;
  int i = 1;
  while (!m[s]) {
    m[s] = 1;
    s = f(s);
    i++;
  }
  cout << i << '\n';
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  string S; cin>>S;
  if(S[0]!='A'){cout<<"WA"<<endl; return 0; }
  int c=0,l=0;
  for(int i=2;i<(S.size()-1);i++){
    if(S[i]=='C') {c++; l=i;}
  }
  if(c!=1) { cout<<"WA"<<endl; return 0; }
  for(int i=1;i<S.size();i++){
    if((i!=l)&&(S[i]>='A')&&(S[i]<='Z')){
      cout<<"WA"<<endl;
      return 0;
    }
  }
  cout<<"AC"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int min(int arr[], int n) 
{ 
    multiset<int> last; 
  
    // last element in each  increasing subsequence  
    // found so far 
    for (int i = 0; i < n; i++) { 
  
        // here our current element is arr[i] 
        multiset<int>::iterator it = last.lower_bound(arr[i]); 
  
        // iterator to the first element larger  
        // than or equal to arr[i] 
        if (it == last.begin()) 
  
            // if all the elements in last larger 
            // than or to arr[i] then insert it into last 
            last.insert(arr[i]); 
  
        else { 
            it--; 
  
            // the largest element smaller than arr[i] is the number 
            // before *it which is it-- 
            last.erase(it); // erase the largest element smaller than arr[i] 
            last.insert(arr[i]); // and replace it with arr[i] 
        } 
    } 
    return last.size(); // our answer is the size of last 
} 
int main()
{
      ios::sync_with_stdio(false);
  cin.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    cout<<min(a,n);
}


Measured memory_bytes: 5376
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
//const int INF = 100100100;
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

int X, n;
vector<int> a;

int N[1000000];

signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	int mx = 0;
	rep(i, n) {
		int x;;
		cin >> x;
		a.pb(x);
		N[x]++;
		N[x+1]++;
		if(x > 0 )N[x-1]++;
		mx = max(mx, x);
	}
	int nyan = 0;
	rep(i, mx) {
		if (nyan < N[i]) {
			nyan = N[i];
			X = i;
		}
	}
	int num = 0;
	rep(i, n) {
		if (a[i] + 1 == X or a[i] - 1 == X or a[i] == X) {
			num++;
		}
	}
	cout << num << endl;
	return 0;
}



Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long(i)=0;i<(n);i++)
long long n,a[200001];

long long fb(long long b){
  long long rtn=0;
  REP(i,n) rtn+=abs(a[i]-b-i-1);
  return rtn;
}

long long tri_search(long long l, long long r){
  long long x1=(r-l+1)/3+l,x2=x1+(r-l+1)/3,rtn;
  //cout<<l<<" "<<x1<<" "<<x2<<" "<<r<<endl;
  if(r-l<=3) return min(fb(x1),fb(x2));
  if(fb(x1)>fb(x2)) rtn=tri_search(x1,r);
  else rtn=tri_search(l,x2);
  return rtn;
} 

int main(){
  cin>>n;
  REP(i,n) cin>>a[i];
  cout<<tri_search(-1e10,1e10);
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

int main(void){
    double x1,y1,x2,y2;
    double a,b;
    double c;
    
    scanf( "%lf %lf %lf %lf" , &x1, &y1, &x2, &y2 );
    a = fabs( x1 - x2 );
    b = fabs( y1 - y2 );
    
    a = a * a;
    b = b * b;
    
    c = sqrt( a + b );
    printf("%f\n",c);
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    ll n,d;
    cin >> n >> d;
    ll ans=0;
    for(int i=0; i<n; i++){
        ll x,y;
        cin >> x >> y;
        if(x*x+y*y<=d*d){
            ans ++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(){
    string s;
    cin >> s;
    unsigned long long c = 0, cb = 0;
    for (int i = 0, n = s.length(); i < n; i++){
        if (s[i] == 'B')
            cb++;
        else
            c += cb;
    }
    cout << c << endl;
}


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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


int main() {
    ll a;
    ld b;
    cin >> a >> b;

    ld ans = a * b;
    prt((ll)ans);

    return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto e : a) cout << e << ' ';
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);


using namespace std;

const int N = 2e5 + 5;

int main()
{
    ll n; cin >> n;
    ll x = 1;
    int st = 0;
    while(x < n)
    {
        x *= 2;
        st++;
    }
    if(x != n)st--;
    ll ans = pow(2, st + 1);
    ans --;
    cout << ans << endl;
    return 0;
}
/*
-1000000000
1000000000
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define LL long long
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
LL n,m,l,dis[305][305],newdis[305][305];

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    cin>>n>>m>>l;
    for(int i=1;i<305;i++)
    {
        for(int j=1;j<305;j++)
        {
            dis[i][j]=newdis[i][j]=inf;
        }
        dis[i][i]=newdis[i][i]=0;
    }
    for(int i=0;i<m;i++)
    {
        int u,v;
        LL w;
        cin>>u>>v>>w;
        newdis[u][v]=dis[u][v]=w;
        newdis[v][u]=dis[v][u]=w;
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(dis[i][k]!=inf&&dis[k][j]!=inf)
                    dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            newdis[i][j]=(dis[i][j]<=l?1:inf);
        }
        newdis[i][i]=0;
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(newdis[i][k]!=inf&&newdis[k][j]!=inf)
                    newdis[i][j]=min(newdis[i][j],newdis[i][k]+newdis[k][j]);
            }
        }
    }
    int q;
    cin>>q;
    int s,t;
    while(q--)
    {
        cin>>s>>t;
        if(newdis[s][t]==inf)
        {
            cout<<"-1\n";
        }
        else
        {
            cout<<newdis[s][t]-1<<"\n";
        }
    }
	return 0;
}



Measured memory_bytes: 5084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int n = s.length;
		int[] tmp = new int[n];
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (s[i] == s[j]) {
					count++;
				}
			}
			tmp[i] = count;
			if (tmp[i] % 2 != 0) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 9428
def e_rotation_matching():
    N, M = [int(i) for i in input().split()]

    if N % 2 == 1:
        ans = [(left, N - left) for left in range(1, (N // 2) + 1)]
    else:
        ans = []
        flag = False
        left, right = 1, N - 1
        while left < right:
            if not flag and right - left <= N // 2:
                right -= 1
                flag = True
            ans.append((left, right))
            left += 1
            right -= 1
    return '\n'.join([f'{a} {b}' for a, b in ans[:M]])

print(e_rotation_matching())

Measured memory_bytes: 28588
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define EPS 1e-10
 
using namespace std;
typedef long long int ll;
 
double add(double a, double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0;
	return a+b;
}
 
struct P{
	double x, y;
	P() {}
	P(double x, double y): x(x), y(y){
	}
	P operator+ (P p){
		return P(add(x, p.x), add(y, p.y));
	}
	P operator- (P p){
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator* (double d){
		return P(x*d, y*d);
	}
	double dot(P p){
		return add(x*p.x, y*p.y);
	}
	double det(P p){
		return add(x*p.y, -y*p.x);
	}
};
 
bool on_seg(P p1, P p2, P q){
	return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0;
}
 
P intersection(P p1, P p2, P q1, P q2){
	return p1+(p2-p1)*((q2-q1).det(q1-p1) / (q2-q1).det(p2-p1));
}

double dist(P p1, P p2, P q){
	double d1=sqrt((p1-q).dot(p1-q)), d2=sqrt((p2-q).dot(p2-q));
	if(abs(p1.x-p2.x)<EPS && abs(p1.y-p2.y)<EPS){
		return d1;
	}
	P r=P((p2-p1).y, (p1-p2).x);
	P s=intersection(p1, p2, q, q+r);
	if(on_seg(p1, p2, s)){
		return sqrt((q-s).dot(q-s));
	}else{
		return min(d1, d2);
	}
}

int main()
{
	while(1){
		int n, r0;
		scanf("%d %d", &r0, &n);
		if(r0==0 && n==0) return 0;
		double r=(double)r0;
		if(n==0){
			printf("%d\n", 0);
			continue;
		}
		double h[41]={};
		for(int i=0; i<n; i++){
			int xl, xr;
			double h0;
			scanf("%d %d %lf", &xl, &xr, &h0);
			xl+=20, xr+=20;
			for(int j=xl; j<xr; j++){
				h[j]=max(h[j], h0);
			}
		}
		double d1=0, d2=h[20];
		for(int t=0; t<100; t++){
			double d=(d1+d2)/2;
			P p=P(20.0, d-r);
			double D=100.0;
			for(int i=0; i<40; i++){
				P q1=P((double)i, h[i]), q2=P((double)(i+1), h[i]);
				D=min(D, dist(q1, q2, p));
			}
			for(int i=0; i<=40; i++){
				P q1, q2;
				if(i==0){
					q1=P((double)i, 0), q2=P((double)i, h[0]);
				}else if(i==40){
					q1=P((double)i, h[39]), q2=P((double)i, 0);
				}else{
					q1=P((double)i, h[i-1]), q2=P((double)i, h[i]);
				}
				D=min(D, dist(q1, q2, p));
			}
			if(D>r-EPS){
				d1=d;
			}else{
				d2=d;
			}
		}
		printf("%.6lf\n", d1);
	}
	return 0;
}


Measured memory_bytes: 3152
import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
s = [S() for _ in range(I())]
t = [S() for _ in range(I())]
ans = 0
count_s = collections.defaultdict(int)
count_t = collections.defaultdict(int)
for x in s:
    count_s[x] += 1
for y in t:
    count_t[y] += 1
for k,v in count_s.items():
    ans = max(ans,v-count_t[k])
print(ans)


Measured memory_bytes: 3316
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DAliceBrown solver = new DAliceBrown();
        solver.solve(1, in, out);
        out.close();
    }

    static class DAliceBrown {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long x = in.nextLong();
            long y = in.nextLong();
            out.println(Math.abs(x - y) <= 1 ? "Brown" : "Alice");
        }

    }
}



Measured memory_bytes: 25172
#include <bits/stdc++.h>
//一括include
using namespace std;
int main()
{
    int n, h, w;
    cin >> n >> h >> w;
    int a[1010] = {};
    int b[1010] = {};
    int count = 0;
    for (int i = 0; i < n;i++){
        cin >> a[i]>>b[i];
        if (a[i] >= h && b[i] >= w)
        {
            count++;
            
        }
        
    }
    
    cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll int 
ll a[100005];
ll ch(ll n){
  ll cn=0;
  while(n){
    cn+=1;
    n/=10;
}
  return (cn%2)==1;
}
int main(){
  ll i,j,k,n,m,t;
  cin>>n;ll ans=0;
  for(i=1;i<=n;i++){
     ans+=ch(i);
  }
  cout<<ans<<"\n";
  
}

Measured memory_bytes: 256
s = input().strip()
v = {}

for c in s:
  if c not in v:
    v[c] = 1
  else:
    v[c] += 1

if len(v) == 2 and list(v.values())[0] == 2 and list(v.values())[1] == 2:
  print('Yes')
else:
  print('No')
  

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define MAX 1000001
#define M 1000000007
#define ll long long
#define ld long double

// #define left (2*i+1)
// #define right (2*i+2)
// #define mid ((l+r)>>1)

using namespace std;

int main() {
	int n;
	cin >> n;
	ll a[n], b[n];
	for (int i=0;i<n;i++) {
		cin >> a[i];
	}
	for (int i=0;i<n;i++) {
		cin >> b[i];
	}
	ll left = 0;
	while(1) {
		int f = 0, v;
		for (int i=0;i<n;i++) {
			if (a[i]>b[i]) {
				f = 1;
				v = i;
				break;
			}
		}
		// cout << v << endl;
		if (!f) {
			cout << "Yes";
			return 0;
		}
		ll left = (a[v]-b[v])*2;
		while(left) {
			int fl = 0;
			for (int i=0;i<n;i++) {
				if (a[i]<b[i]) {
					ll df = b[i]-a[i];
					if (df>1) fl = 1;
					if (left<=df) {
						a[i]+=left;
						left = 0;
						break;
					}
					else {
						ll tk = (df/2)*2;
						left-=tk;
						a[i]+=tk;
					}
				}
			}
			if (!fl) break;
		}
		if (left) {
			cout << "No";
			return 0;
		}
		a[v] = b[v];
		// for (int i=0;i<n;i++) cout << a[i] << " ";
		// cout << endl;
		// for (int i=0;i<n;i++) cout << b[i] << " ";
		// cout << endl;
	}
	// for (int i=0;i<n;i++) cout << a[i] << " ";
	// cout << endl;
	// for (int i=0;i<n;i++) cout << b[i] << " ";
	// cout << endl;
	return 0;
}

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

int main() { 
	int n;
	cin >> n;
	map<int,bool> m;
	m[n] = 1;
	int cnt = 1;
	while (n > 0) {
		cnt++;
		if (n % 2 == 1) {
			n = (n * 3)  + 1;
		}else {
			n /= 2;
		}
		if (m[n]) {
			cout << cnt;
			return 0;
		}
	//	cout << n << endl;
		m[n] = 1;
	}
	return 0; 
} 



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int n, *m, x, i, min, sum = 0, diff, count;

  scanf("%d %d", &n, &x);
  m = malloc(sizeof(int) * n);

  for (i = 0; i < n; i++) {
    scanf("%d", &m[i]);
    sum += m[i];
  }

  diff = x - sum;
  count = n;

  min = m[0];
  for (i = 1; i < n; i++) {
    if (min > m[i]) {
      min = m[i];
    }
  }

  while (diff >= min) {
    count++;
    diff -= min;
  }

  printf("%d\n", count);

  return 0;
}


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

int main(){
	int n,m;	cin>>n>>m;
	int a[n],b[n];	for(int i=0;i<n;i++)cin>>a[i]>>b[i];

	int c[m],d[m];	for(int i=0;i<m;i++)cin>>c[i]>>d[i];

	int xl,yl,sum,ans;
	for(int i=0;i<n;i++){
		xl=200000000,yl=200000000;
		sum=xl+yl;

		for(int j=0;j<m;j++){
			if(abs(a[i]-c[j]) + abs(b[i]-d[j])<sum){
				sum=abs(a[i]-c[j]) + abs(b[i]-d[j]);
				ans=j+1;
			}
		}

		cout<<ans<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,a,v;
  int a_top,v_top=-1;

  scanf("%d",&n);
  while(n-->0){
    scanf("%d %d",&a,&v);

    if(v_top==-1){ a_top=a; v_top=v; }
    else if(v_top<v){ a_top=a; v_top=v; }
    else if(v_top==v && a_top>a){ a_top=a; v_top=v; }
  }
  printf("%d %d\n",a_top,v_top);
  return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
   int n;cin>>n;
   int a = n/100,b = n%100;
   if(a>=1 && a<=12 && b>=1 && b<=12)cout<<"AMBIGUOUS";
   else if(a>=1 && a<=12)cout<<"MMYY";
   else if(b>=1 && b<=12)cout<<"YYMM";
   else cout<<"NA";
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, a, b) for(int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える


const ll MOD = pow(10, 9) + 7;

ll mod_pow(ll a, ll b, ll mod){
    ll res = 1;
    while(b > 0){
        if(b & 1) res = res * a % mod;
        a = a*a % mod;

        b >>= 1;
    }
    return res;
}

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


    //gcd = gとなる組合わせの数d[g]を計算する
    ll d[100010];
    //gcd = g <=> gの倍数 - 2*gの倍数 - 3*gの倍数...
    //↓gの倍数
    for(int g = 1; g <= k; g++){
        int m = k/g;
        d[g] = mod_pow(m, n, MOD);
    }
    //↓2*gの倍数,3の倍数,,,をひいてゆく
    for(int g = k; g >= 1; g--){
        for(int gg = 2*g; gg <= k; gg += g){
            d[g] -= d[gg];
            d[g] %= MOD;
        }        
    }


    ll ans = 0;
    for(int g = 1; g <= k; g++){
        ans += d[g] * g;
        ans %= MOD;
    }

    if(ans < 0) ans += MOD;

    cout << ans << endl;
}

Measured memory_bytes: 4364
import java.io.*;
import java.util.*;
public class Main
{
    static PrintWriter out=new PrintWriter((System.out));
    public static void main(String args[])throws IOException
    {
        Reader sc=new Reader();
        int a=sc.nextInt();
        int b=sc.nextInt();
        out.println(a*b);
        out.close();
    }

    public static void solve()
    {
    }

    static class Reader
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next()
        {
            while(!st.hasMoreTokens())
            {
                try
                {
                    st=new StringTokenizer(br.readLine());
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

        public long nextLong()
        {
            return Long.parseLong(next());
        }

        public double nextDouble()
        {
            return Double.parseDouble(next());
        }

        public String nextLine()
        {
            try
            {
                return br.readLine();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext()
        {
            String next=null;
            try
            {
                next=br.readLine();
            }
            catch(Exception e)
            {
            }
            if(next==null)
            {
                return false;
            }
            st=new StringTokenizer(next);
            return true;
        }
    }
}


Measured memory_bytes: 32672
#include<bits/stdc++.h>
using namespace std;
long long int n,k;
long long int a[100000];
long long int dp[100001];
long long int x;
long long int abs(long long int x,long long int y)
{
	if(x>=y)
	return(x-y);
	else
	return (y-x);
}
long long int frog(long long int start)
{
	if(start==n-1)
	return 0;
	if(dp[start]!=INT_MAX)
	return dp[start];
	for(int i=1;i<=k;i++)
	{
		if(start+i>n-1)
		continue;
		x=abs(a[i+start],a[start])+frog(start+i);
		dp[start]=min(dp[start],x);
	}
	return dp[start];
}
int main()
{
	cin>>n>>k;
	long long int res;
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<100001;i++)
	dp[i]=INT_MAX;
	res=frog(0);
	cout<<res<<"\n";
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
using ll = long long;
using namespace std;

int main()
{
    int N;
    cin >> N;
    int V[N];
    int C[N];
    REP(i, N) cin >> V[i];
    REP(i, N) cin >> C[i];

    int ret = 0;
    REP(i, N)
    {
        ret += max(0, V[i]-C[i]);
    }

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n_,m;
    cin >> n_ >> m;
    for(int i=0; i<(m+1)/2; i++){
        cout << i+1 << ' ' << m+1-i << endl;
    }
    for(int i=(m+1)/2; i<m; i++){
        int j = i - (m+1)/2;
        cout << m+2+j << ' ' << 2*m+1-j << endl;
    }
    return 0;
}


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

int gcd(int x, int y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

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

    vector<int> num(100001);
    ll ans = 0;
    rep(i, n) {
        ans += a[i];
        num[a[i]]++;
    }

    rep(i, q) {
        ans -= (b[i] * (ll)num[b[i]]);
        ans += (c[i] * (ll)num[b[i]]);
        num[c[i]] += num[b[i]];
        num[b[i]] = 0;
        cout << ans << endl;
    }
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

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

int main()
{
  int N;
  double X[100];
  int count=0;
  int xmax=0;
  int res=999999999;

  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> X[i];
    if(xmax<X[i]){
      xmax = X[i];
    }
  }

  
  for (int i = 0; i <=xmax; i++)
  {
    int sum = 0;
    for (int j = 0; j < N; j++)
    {
      sum += (X[j] - (double)i)*(X[j] - (double)i);
      // cout << X[j] << ":" << i << endl;
    }
    if(res>sum){
      res = sum;
    }
  }
  
  

  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n;
  scanf("%d", &n);
  int max = 0, min = MOD;
  rep(i, 0, n){
    int a;
    scanf("%d", &a);
    max = max(max, a);
    min = min(min, a);
  }
  printf("%d\n", max- min);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

const int MAX = 1000;
typedef long long ll;

vector<ll> V;

ll make(ll a, ll b){

  for(int i = 0; i <= log10(b); i++)
    a *= 10LL;

  return a+b;
}

ll solve(){
  vector<ll> ans;

  int LIM = min(MAX,(int)V.size());
  for(int i = 0; i < LIM; i++)
    for(int j = 0; j < LIM; j++)
      if(i != j) ans.push_back(make(V[i],V[j]));

  sort(ans.begin(),ans.end());
  return ans[2];
}

int main(){

  int n;
  cin >> n;
  while(n--){
    int in;
    cin >> in;
    V.push_back(in);
  }
  sort(V.begin(),V.end());
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 10952
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,loop;
	cin >> N;
	int sumright=0,sumleft=0;
	vector<int> W(N);
	for(loop=0;loop<N;loop++){
		cin >> W[loop];
		sumright+=W[loop];
	}
	int minabs=114514;
	for(loop=0;loop<N;loop++){
		sumright-=W[loop];
		sumleft+=W[loop];
		if(abs(sumright-sumleft)<minabs){
			minabs=abs(sumright-sumleft);
		}
	}
	cout << minabs << endl;
	return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

ll baisuu_atob(ll a, ll b, ll x){
    if(a % x > 0) a += x - (a % x);
    b -= a;
    if(b < 0) return 0;
    else return b/x + 1;
}

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    ll r = a % b;
    if(r == 0) return b;
    else return gcd(b, r);
}

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a*b/g;
}

int main(void){
    ll N, M; cin >> N >> M;
    ll upplim = M+1;
    ll A[N]; rep(i, N) cin >> A[i];
    rep(i, N) A[i] /= 2;
    ll lcm_A = 1;
    rep(i, N){
        lcm_A = lcm(lcm_A, A[i]);
        if(lcm_A >= upplim){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, N){
        if((lcm_A / A[i]) % 2 == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    //lcm_Aの奇数倍が1からMまでにいくつあるか
    ll ans = (M / lcm_A + 1) / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
n = gets.to_i
s = gets.chomp.chars
x_max = 0

x = s.inject(0){|sum, t|
    case t
    when "I" then
        sum += 1
    when "D" then
        sum -= 1
    end
    
    x_max = [x_max, sum].max
    sum
}

puts x_max

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int n,k,ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(k);
	while (n) n/=k,ans++;
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define vi vector <ll>
#define hell 998244353
#define pii pair <ll,ll>
#define inf (ll)(1e16)
#define pb push_back

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    vi a(n);
    rep(i,0,n)
        cin>>a[i];
    ll ans=0;
    rep(i,1,n)
    {
        ll c=0;
        while(i<n&&a[i]<=a[i-1])
        {
            i++;
            c++;
        }
        ans=max(ans,c);
    }
    cout<<ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int n, m;
    cin >> n >> m;
    using pii=pair<int, int>;
    vector<pii> st,ch;
    rep(i, n) {
        int a, b; cin >> a >> b;
        st.emplace_back(a,b); 
    }
    rep(i, m) {
        int c, d; cin >> c >> d;
        ch.emplace_back(c,d); 
    }
    for(auto& s : st) {
        int d = numeric_limits<int>::max(), mi;
        rep(i, m) {
            auto& c = ch[i]; 
            int tmp = abs(s.first - c.first) 
                + abs(s.second-c.second);
            if (d > tmp) {
                mi = i+1;
                d = tmp;
            }
        }
        cout << mi << endl; 
    }
    
    return 0;
}

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

const int N = 2e5 + 5;

long long BIT[N];
pair<int, int> arr[N];
int n;

void update(int pos, long long val) {
  for (; pos < N ; pos += pos & -pos)
    BIT[pos] = max(BIT[pos], val);
}

long long query(int x) {
  long long ret = 0;
  while (x) {
    ret = max(ret, BIT[x]);
    x -= x & -x;
  }
  return ret;
}

void read() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i].first);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i].second);
}

long long work() {
  // sort(arr + 1, arr + n + 1);
  for (int i = 1 ; i <= n ; i++) {
    long long val = query(arr[i].first-1);
    update(arr[i].first, val + arr[i].second);
  }
  return query(N-1);
}

int main() {
  read();
  cout << work() << endl;
  return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<queue>
#include<vector>
#include<string>
#include<stack>

int n, m, ans, count;
bool use[8];
std::vector<std::vector<int>>v(8);

void dfs(int now) {
	use[now] = true;
	count++;
	if (count == n) {
		ans++;
		use[now] = false;
		count--;
		return;
	}
	for (auto next : v[now]) {
		if (use[next])continue;
		dfs(next);
	}
	use[now] = false;
	count--;
	return;
}

int main() {
	std::cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		std::cin >> a >> b;
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}

	dfs(0);
	printf("%d\n", ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
    
        System.out.println(gcd(x, y));
    }
    
    static int gcd(int x, int y){
        if(x < y){
            int tmp = x;
            x = y;
            y = tmp;
        }
        while(y > 0){
            int r = x % y;
            x = y;
            y = r;
        }
        return x;
    }
}


Measured memory_bytes: 26296