akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <set>
#include<bits/stdc++.h>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
long long int dp[105][100005];
int main(){
    vector <long long int > v;
    vector <long long int > u;u.push_back(0);
    v.push_back(0);
    int n , w;
    cin>>n>>w;
    for(int i = 0;i<n;i++){
        long long int z , x;
        cin>>z>>x;
        v.push_back(z);
        u.push_back(x);
    }
    long long int answer = 0;
    for(int i = 1;i<=n;i++){
        for(int j = 0;j<=w;j++){
            dp[i][j] = max(dp[i-1][j],dp[i][j] );
            answer = max(answer , dp[i][j  ] );
            if(v[i]+ j <=w ){
                dp[i][v[i]+j  ] = max(dp[i][v[i]+j ],dp[i-1][j ]+u[i]   );
                answer = max(answer , dp[i][v[i]+j  ] );
            }
        }
    }
    cout<<answer;
}


Measured memory_bytes: 79360
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int l = in.nextInt();
        int r = in.nextInt();
        int d = in.nextInt();

        int answer = 0;
        for (int i = l; i <= r; i++) {
            if ((i % d) == 0) {
                answer++;
            }
        }
        out.println(answer);
    }
}


Measured memory_bytes: 32292
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

const char* colors = "RGBY";

int main()
{
	int h, w, d;
	vector<vector<char>> ans;

	scanf("%d%d%d", &h, &w, &d);
	ans.resize(h);
	for(auto& x : ans)
		x.resize(w);

	int s = d;
	if(d % 2 == 1)
		s = 1;

	for(int x = 0; x < w; ++x) {
		for(int y = 0; y < h; ++y) {

			int p = x - y + s * 100000;
			int q = x + y + s * 100000;

			int pg = (p / s) & 1;
			int qg = (q / s) & 1;
			int c = pg * 2 + qg * 1;

			ans[y][x] = c;
		}
	}

	for(int y = 0; y < h; ++y) {
		for(int x = 0; x < w; ++x) {
			int c = ans[y][x];
			printf("%c", colors[c]);
			//printf("%d ", c);
		}
		printf("\n");
	}


	return 0;
}

/* waffle */


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int dp[125252][3];

int main(){
    int n,k,r,s,p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;
    auto win = [&](char c, int h){
        if(c=='r')return h==2 ? p : 0;
        if(c=='s')return h==0 ? r : 0;
        if(c=='p')return h==1 ? s : 0;
        return 0;
    };
    int ans = 0;
    REP(sh,k){
        string tt;
        int it = sh;
        while(it<n){
            tt += t[it];
            it += k;
        }
        int m = tt.size();
        REP(i,m+1)REP(j,3)dp[i][j] = -(1<<30);
        REP(j,3)dp[0][j] = 0;
        REP(i,m){
            REP(j,3){
                REP(jj,3)if(j!=jj){
                    CHMAX(dp[i+1][jj], dp[i][j] + win(tt[i], jj));
                }
            }
        }
        ans += *max_element(dp[m], dp[m]+3);
    }
    cout<<ans<<endl;
    return 0;
}


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

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

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    for (int i=K; i<N; ++i) {
        if (a[i] > a[i-K]) {
            cout << "Yes" << '\n';
        } else {
            cout << "No" << '\n';
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

//r本再利用されない時、N本から再利用して売れる本数
int rec(int m,int n,int N,int r){
  if(N == 0) return 0;

  int k = N/m * n;//新たに作り出す本数
  r = N%m;//再利用されない本数
  int res = N + k;//売った本数
  
  while(1){
    k = k/m * n;//k本からk/m本再利用
    res += k;
    r += k%m;
    if(k < m){//k本で再利用できなくなったら
      k += r;
      res += rec(m,n,k,r);
    }
  }
}

int main(){
  string S;
  cin >> S;
  int k = S.size();
  int c = 0;//k日目までの勝ち数

  rep(i,k){
    if(S[i] == 'o') c++;
  }
  if(c >= 8) cout << "YES" << endl;
  else {
    if(15-k >= 8 - c) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll mod = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);

	ll a,b,c;cin>>a;
	b=a*a;c=b*a;
	cout<<a+b+c<<endl;


}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


ll n,m,q;
ll a[50],b[50],c[50],d[50];
ll ans;
void Rep(vector<ll> v){
    if((ll)v.size()==n){
        ll sum=0;
        rep(j,0,q-1){
            if(v[b[j]-1]-v[a[j]-1]==c[j]){
                sum+=d[j];
            }
        }
        ans=max(ans,sum);
        return ;
    }
    
    if((ll)v.size()==0){
        rep(i,1,m){
            v.pb(i);
            Rep(v);
            v.pop_back();
        }
        return ;
    }
    rep(i,v[v.size()-1],m){
        v.pb(i);
        Rep(v);
        v.pop_back();
    }

    
}


int main(){
    cin>>n>>m>>q;
    
    rep(i,0,q-1){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    vector<ll> v;
    ans=0;
    Rep(v);
    
    cout<<ans<<endl;
    return 0;
}


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

int main(void) {
	string S;
	cin >> S;

	int flag = 0;
	int N = S.length();
	for (int i = 0; i < N/2; i++) {
		if (S[i] != S[N - 1 - i]) flag++;
	}
	if (flag > 0) {
		cout << "No" << endl;
		return 0;
	}

	int lSize = (S.length() - 1) / 2;
	int rSize = (S.length() + 3) / 2 - 1;
	string l, r;
	l = S.substr(0,lSize);
	r = S.substr(rSize);
	
	int size1 = l.length();
	int size2 = r.length();
	for (int i = 0; i < size1 / 2; i++) {
		if (l[i] != l[size1 - 1 - i]) flag++;
	}
	for (int i = 0; i < size2 / 2; i++) {
		if (r[i] != r[size2 - 1 - i]) flag++;
	}
	if (flag > 0) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main() {
  int n; cin >> n;
  map<string, int> s;
  rep(i,n) {
    string st;
    cin >> st;
    s[st]++;
  }

  cout << "AC x " << s["AC"] << endl;
  cout << "WA x " << s["WA"] << endl;
  cout << "TLE x " << s["TLE"] << endl;
  cout << "RE x " << s["RE"] << endl;
  
  

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(F f,T ti):f(f),ti(ti){}
  void init(int n_){    
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  void build(const vector<T> &v){
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  void set_val(int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
  }
  T query(int a,int b){
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
};


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template<typename T,T MOD = 1000000007>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
  
  Mint inv(){return pow(MOD-2);}
  
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
  
  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-(){return v?MOD-v:v;}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}
};
//INSERT ABOVE HERE
signed main(){
  int n,q;
  cin>>n>>q;
  vector<int> p(n);  
  for(int i=0;i<n;i++) cin>>p[i],p[i]--;

  using ll = long long;
  using M = Mint<int>;
  using P = pair<M, ll>;
  auto mlcm=[&](ll a,ll b){return a/__gcd(a,b)*b;};
  auto f=[&](P a,P b){
           P c;
           c.second=mlcm(a.second,b.second);
           c.first+=a.first*M(c.second/a.second);
           c.first+=b.first*M(c.second/b.second);
           return c;
         };
  P ti(M(0),1);
  SegmentTree<P> seg(f,ti);
  vector<P> vp(n,ti);
  for(int i=0;i<n;i++){
    ll sum=i+1,cnt=1,pos=p[i];
    while(pos!=i){
      sum+=pos+1;
      cnt++;
      pos=p[pos];
    }
    vp[i].first=M(sum);
    vp[i].second=cnt;
  }
  seg.build(vp);
  
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    l--;
    cout<<seg.query(l,r).first.v<<"\n";   
  }
  cout<<flush;
  return 0;
}



Measured memory_bytes: 8888
while True:
    x,y = map(int,input().split())
    if x==0 and y==0: break

    a = max(x,y)
    b = min(x,y)
    p = 0
    while True:
        p += 1
        q = a%b
        a,b = b,q
        if q==0: break
    print(a,p)


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

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

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

  vector<int> a(n);
  rep(i,n) cin >> a.at(i);

  int ans = 0;
  rep(i,n) if((i+1)%2==1&&a.at(i)%2==1)ans++;

  cout << ans;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0)cout<<1<<endl;
  if(b==0)cout<<2<<endl;
  if(c==0)cout<<3<<endl;
  if(d==0)cout<<4<<endl;
  if(e==0)cout<<5<<endl;
}

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

unordered_map<int, int> primes(int x) {
    unordered_map<int, int> mp;
    for (int i = 2; i <= x; i++) {
        while (x % i == 0) {
            mp[i]++;
            x /= i;
        }
    }
    return mp;
}

int main() {
    int n;
    cin >> n;
    unordered_map<int, int> mp;
    for (int i = 2; i <= n; i++) {
        unordered_map<int, int> mp_i = primes(i);
        for (auto p: mp_i) {
            mp[p.first] += p.second;
        }
    }

    unordered_map<int, int> mp_count;
    for (auto p: mp) {
        if (p.second >= 74)
            mp_count[75]++;
        if (p.second >= 24)
            mp_count[25]++;
        if (p.second >= 14)
            mp_count[15]++;
        if (p.second >= 4)
            mp_count[5]++;
        if (p.second >= 2)
            mp_count[3]++;
    }
    int ans = mp_count[75] + mp_count[25] * (mp_count[3] - 1) + mp_count[15] * (mp_count[5] - 1) + mp_count[5] * (mp_count[5] - 1) * (mp_count[3] - 2) / 2;
    cout << ans << endl;
    return 0;
}


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

#define mx 2001

int ar[mx];

bitset<mx*mx> mask;
/*
//Constuct 01: 8 bits initialized to zero
bitset<8> bitset1;

//Construct 02: Construct it from a integer number
bitset<8> bitset2(177);


//Construct 03: Construct it from string
bitset<8> bitset3(string("11111100"));

cout << bitset3 << endl;

//Usage 01: Set and Reset a bit in the bitset
bitset2.reset(); cout << bitset2 << endl;
bitset2.set(4); cout << bitset2 << endl;
bitset2.set(7); cout << bitset2 << endl;

bitset3.set();  cout << bitset3 << endl;
bitset3.reset(1); cout << bitset3 << endl;
bitset3.reset(2); cout << bitset3 << endl;

//Usage 02: Testing a perticular Bit
cout << "Bitset3: " << bitset3 << endl;
for (int i=0; i<bitset3.size(); i++)
{
    if (bitset3.test(i))
        cout << "Bit " << i << " is Set" << endl;
    else
        cout << "Bit " << i << " is Not Set" << endl;
}




*/
int res(int n, int s)
{
    int i;
    mask.reset();
    mask.set(0);
    for(i=0;i<n;i++){
        mask|=(mask<<ar[i]);
    }
    while(!mask.test(s)) s++;
    return s;
}

int main()
{
    int n,s=0,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ar[i]);
        s+=ar[i];
    }
    printf("%d\n",res(n,(s+1)/2));
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];

    vector<vector<ll>> vs(4);
    REP(i, N){
    	vs[w[i]-w[0]].push_back(v[i]);
    }
    REP(i, 4) sort(vs[i].rbegin(), vs[i].rend());

    vector<vector<ll>> ss(4);
    REP(i, 4){
    	ss[i].push_back(0);
    	REP(j, vs[i].size()){
    		ss[i].push_back(ss[i][j]+vs[i][j]);
    	}
    }

    ll res = 0;
    REP(i, ss[0].size()){
    	REP(j, ss[1].size()){
    		REP(k, ss[2].size()){
    			REP(l, ss[3].size()){
    				ll wsum = 0;
    				wsum += w[0] * i;
    				wsum += (w[0]+1) * j;
    				wsum += (w[0]+2) * k;
    				wsum += (w[0]+3) * l;

    				if(wsum<=W){
    					chmax(res, ss[0][i]+ss[1][j]+ss[2][k]+ss[3][l]);
    				}
    			}
    		}
    	}
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const dx[]={-1,0,1,0},dy[]={0,1,0,-1};
int dis[505][505],c[505][505];
void extend(int x,int y)
{
    for(int j=0;j<4;j++)
    {
        int nx=x+dx[j],ny=y+dy[j];
        if(dis[nx][ny]>dis[x][y]+c[nx][ny])
            dis[nx][ny]=dis[x][y]+c[nx][ny],
            extend(nx,ny);
    }
}
int main()
{
    int n,a,x,y;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            dis[i][j]=min(min(i,j),min(n-i+1,n-j+1)),c[i][j]=1;
    int ans=0;
    for(int i=1;i<=n*n;i++)
    {
        scanf("%d",&a);
        x=(a-1)/n+1,y=a%n;
        if(!y)y=n;
        //cout<<x<<" "<<y<<" "<<dis[x][y]<<" ";
        ans+=dis[x][y]-1;
        c[x][y]=0;
        for(int j=0;j<4;j++)
        {
            int nx=x+dx[j],ny=y+dy[j];
            dis[x][y]=min(dis[x][y],dis[nx][ny]);
        }
        extend(x,y);
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 20928
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool ok = true;
    if(s[0] != 'm') ok = false;
    if(s.back() != 'w') ok = false;
    while(1)
    {
        string t = "";
        for(int i = 0; i < s.size(); i++)
        {
            if(i + 3 != s.size() && i != 0 && s.substr(i, 3) == "mew")
            {
                i += 2;
            }
            else
            {
                t += s[i];
            }
        }
        if(t == "mew") break;
        if(t == s)
        {
            ok = false; //変化なし
            break;
        }
        s = t;
    }
    cout << (ok ? "Cat" : "Rabbit") << endl;
    return 0;
}



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

int main() {
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    int maxX = x;
    int minY = y;
    
    for(int i = 0; i < n; i++)
    {   
        int xi;
        cin >> xi;
        maxX = max(maxX, xi);
    }
    for(int i = 0; i < m; i++)
    {
        int yi;
        cin >> yi;
        minY = min(minY, yi);
    }
    
    string ans = "No War";
    if (maxX >= minY) ans = "War";

    cout << ans << endl; 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // System.out.println("Hello Java");
        Scanner sc = new Scanner(System.in);

        if (sc.next().equals(sc.next())) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<chrono>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<numeric>
#include<omp.h>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
constexpr double PI = 3.14159265358979323846;
int main()
{
	int N,M;
	cin >> N >> M;
	int sum = N;
	int a;
	for (int i = 0; i < M; i++)
	{
		cin >> a;
		sum -= a;
	}

	if (sum < 0)std::cout << "-1" << std::endl;
	else std::cout << sum << std::endl;

}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  while(cin >> n) {
    if(!n) return 0;
    map<string, int> m;
    rep(i, 0, n) {
      string s;
      int p;
      cin >> s >> p;
      m[s] = p;
    }

    cin >> n;
    string o[100];
    vector<string> q[100];
    rep(i, 0, n) {
      cin >> o[i];
      int k;
      cin >> k;
      rep(j, 0, k) {
        string sum;
        cin >> sum;
        q[i].pb(sum);
      }
    }

    rep(i, 0, 100) {
      rep(j, 0, n) {
        int f = 0;
        int gou = 0;
        rep(k, 0, q[i].size()) {
          if(m.count(q[i][k])) {
            gou += m[q[i][k]];
          }else f = 1;
        }
        if(!f) {
          if(m.count(o[i])) {
            m[o[i]] = min(m[o[i]], gou);
          }else m[o[i]] = gou;
        }
      }
    }

    string s;
    cin >> s;
    cout << m[s] << endl;
  }
}

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

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

  for (int c = 0; c <= x; c++) {
    int t = x - c;
    int asi = c*2 + t*4;
    if (asi == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3628
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: f64 = read();
    let n: f64 = read();
    println!("{}", x / n);
}


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

int main(){
	
	int A, B, C, D;
	int time;
	cin >> A >> B >> C >> D;
	
	if( B <= C or D <= A ){
		time = 0;
	}else if( A > C ){
		time = min( B, D ) - A;
	}else if( A <= C ){
		time = min( B, D ) - C;
	}
	
	cout << time << endl;
	
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define pi 3.14159265358979323846264338327950L
#define FOR(i,a,b) for(int i=a;i<b;i++)

int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    IOS
    int a[6];
    FOR(i,1,6)
    {
        cin>>a[i];
    }
    FOR(i,1,6)
    {
        if(a[i]==0)
        {
            cout<<i<<endl;
            break;
        }
    }




    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 1000*101;

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


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

	bool found = 0;
	int a, b;
	cin >> a >> b;
	for(int i = 1; i <= 10000; i++) {
		if( int(i * 0.08) == a && int(i * 0.10) == b) {
			cout << i << endl;
			found = 1;
			break;
		}
	}
	if(!found) {
		cout << -1 << endl;
	}
	return 0;
}		


Measured memory_bytes: 256
#include<stdio.h>

	int dice[6];
	int dice2[6];
	int i,j;
	
void emov(){
	int buf;
	buf = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = dice[2];
	dice[2] = buf;
}
void smov(){
int buf;
	buf = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = dice[1];
	dice[1] = buf;
}

int main(){
	for(i=0;i<6;i++){
	scanf("%d",&dice[i]);
	}
	for(i=0;i<6;i++){
	scanf("%d",&dice2[i]);
	}
	
	for(i=0; dice[1] != dice2[1] && i<3; i++){
		smov();
	}
	if(dice[1] != dice2[1]){
		emov();
		for(i=0; dice[1] != dice2[1] && i<3; i++){
			smov();
		}
	}
	if(dice[1]==dice[1]){
		for(i=0; dice[0]!=dice2[0] && i<3; i++){
			emov();
		}
		if(dice[0]==dice[0] && dice[2]==dice2[2] && dice[3]==dice2[3] && dice[4]==dice[4] && dice[5]==dice[5]){
			printf("Yes\n");
		}
			else{
				printf("No\n");
			}
	}
    return 0;
}



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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

ll addmod(ll a,ll b)
{
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a %=mod;
    b%=mod;
    return (a*b)%mod;
}
ll submod(ll a,ll b)
{
    ll x  = a-b;
    if(x<0)x+=mod;
    x%=mod;
    return x;
}
bool comp(pair<pi,ll>a,pair<pi,ll>b)
{
    if(a.fi.fi==b.fi.fi)return a.fi.se<b.fi.se;
    return a.fi.fi<b.fi.fi;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll a,b,c,d; cin>>a>>b>>c>>d;
    bool flag = true;
    while(a>0&&c>0)
    {
        if(flag)
        {
            c-=b;
            flag = false;
        }
        else a-=d,flag = true;
    }
    if(a>0)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}
/*
5 10 10
22 23
17 19
13 17
8 12
2 6
*/


Measured memory_bytes: 3652
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;
const int mod = 1e9+7;

long long fast_pw(long long x, long long y) {
	long long ret = 1;

	for(;y;y>>=1) {
		if(y & 1) ret = (ret * x) % mod;
		x = (x * x) % mod;
	}
	return ret;
}

long long dp[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;

	for(int i = k; i >= 1; i--) {
		dp[i] = fast_pw(k / i, n);
		for(int j = i + i; j <= k; j += i) {
			dp[i] = (dp[i] - dp[j] + mod) % mod;
		}
	}

	long long ans = 0;

	for(int i = 1; i <= k; i++) {
		ans += i * dp[i];
		ans %= mod;
	}

	cout << ans;
		

	return 0;
}


Measured memory_bytes: 4424
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int s[3010][3010];
int a[2][1010][1010];
int main(){
  int n,k;
  cin>>n>>k;
  rep(i,n){
    int x,y;
    char c;
    cin>>x>>y>>c;
    if(c=='B')x+=k;
    x%=2*k;
    y%=2*k;
    s[x][y]++,s[x+k][y+k]++,s[x+k][y]--,s[x][y+k]--;
  }
  int ans=0;
  rep(i,3*k)rep(j,3*k)s[i][j+1]+=s[i][j];
  rep(i,3*k)rep(j,3*k){
    s[i+1][j]+=s[i][j];
    ans=max(ans,a[(i/k+j/k)%2][i%k][j%k]+=s[i][j]);
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A,B,C;
  	cin >> A >> B >> C;
  	if(A > B)
    {
      if(B > C || C > A)
      {
        cout << "No" << endl;
      }
      else
      {
        cout << "Yes" << endl;
      }
    }
  	else
    {
      if(B > C && A < C)
      {
        cout << "Yes" << endl;
      }
      else
      {
        cout << "No" << endl;
      }
    }
    
	
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;
const int INFLL=1001001001001001001ll;
const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}


struct PalindromicTree{
    struct node{
    map<char,int>nex;
        int len,suflink,height,firapp,cnt;
        //length,suffix link,height,first appearance
    };

    string s;
    vector<node>v;
    vector<int>ord;
    int n,suf;

    bool process(int pos){
        char ch=s[pos];
        int cur=suf;
        while(true){
            if(pos-1-v[cur].len>=0&&s[pos-1-v[cur].len]==ch)break;
            cur=v[cur].suflink;
        }

        if(v[cur].nex.count(ch)){
            suf=v[cur].nex[ch];
            v[suf].cnt++;
            return false;
        }

        suf=n++;

        v[suf].len=v[cur].len+2;
        v[suf].firapp=pos;
        v[suf].cnt=1;
        v[cur].nex[ch]=suf;

        if(v[suf].len==1){
            v[suf].suflink=1;
            v[suf].height=1;
            return true;
        }

        while(true){
            cur=v[cur].suflink;
            if(pos-1-v[cur].len>=0&&s[pos-1-v[cur].len]==ch){
                v[suf].suflink=v[cur].nex[ch];
                break;
            }
        }
        v[suf].height=1+v[v[suf].suflink].height;
        return true;
    }

    void init(const string &s){
        this->s=s;
        v.clear();
        v.resize(s.size()+10);

        n=2;
        suf=1;
        v[0].firapp=v[1].firapp=-1;
        v[0].len=-1;
        v[1].len=0;
        v[0].suflink=v[1].suflink=0;
        v[0].height=v[1].height=0;
    }

    void calcOrd(){
        ord={0,1};
        for(int i=0;i<ord.size();i++){
            for(auto &p:v[ord[i]].nex)ord.pb(p.se);
        }
    }

    void calcCnt(){
        assert(ord.size());
        for(int i=ord.size()-1;i>=0;i--){
            v[v[ord[i]].suflink].cnt+=v[ord[i]].cnt;
        }
        v[0].cnt=v[1].cnt=0;
    }
};

int dps[1111111],dpt[1111111];

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

    string S,T;
    cin>>S>>T;

    string ST=S+"@*"+T;
    PalindromicTree pt;pt.init(ST);
    for(int i=0;i<ST.size();i++){
        pt.process(i);
        if(i<S.size())dps[pt.suf]++;
        else if(i>S.size())dpt[pt.suf]++;

    }


    int ans=0;
    for(int i=pt.n-1;i>=2;i--){
        ans+=dps[i]*dpt[i];
        dps[pt.v[i].suflink]+=dps[i];
        dpt[pt.v[i].suflink]+=dpt[i];
    }

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

Measured memory_bytes: 19332
#include <stdio.h>

int main (){
	int n, i, j, a;
	char c;
	scanf("%d", &n);
	while(n != 0){
		int p[11] = {}, b = 0;
		for(i = 0; i < 100; i++){
			j = i % n;
			scanf("%c", &c);
			if(c == 'M'){
				p[j]++;
			} else if(c == 'S'){
				b += p[j] + 1;
				p[j] = 0;
			} else if(c == 'L'){
				p[j] += b + 1;
				b = 0;
			} else {
				i--;
			}
		}
		for(i = 0; i < n - 1; i++){
			for(j = i + 1; j < n; j++){
				if(p[i] > p[j]){
					a = p[i];
					p[i] = p[j];
					p[j] = a;
				}
			}
		}
		for(i = 0; i < n; i++){
			printf("%d ", p[i]);
		}
		printf("%d\n", b);
		scanf("%d", &n);
	}
	return 0;
}

Measured memory_bytes: 600
/*
 AtCoder XXX 000
 */
 
#include <stdio.h>
 
int main(void){
   
    int arare=3;
    char c;
    int i;
    int n;
	
    scanf("%d",&n);
    
    for(i=0; i<n; i++){
      scanf("%c",&c); 
      if(c == 'Y') arare=4;
    }
    
    arare==3 ? printf("Three\n") : printf("Four\n");
  
	return 0;
}

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

#define ll long long int

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast_io std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;
#define trace3(x,y,z) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;
#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;

#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(),(v).end()


using namespace std;
///////////////////////////////////////////////////////

const int N = 1e5;

int n,op=0;
int a[N+5];
vector<int> miss;

int main()
{
	fast_io;

	cin>>n;
	FOR(i,1,n){
		cin>>a[i];
		if(a[i] == i) miss.pb(i);
	}

	if(miss.size() == 0){
		cout<<0<<endl;
		return 0;
	}

	// for(int u:miss) cout<<u<<" ";
	// cout<<endl;

	for(int i = 0;i<miss.size()-1;i++){
		if(miss[i]+1 == miss[i+1]){
			a[miss[i]] = miss[i]+1;
			a[miss[i]+1] = a[miss[i]];
			op++;
			miss[i] = -10;
			miss[i+1] = -10;
			i++;
		}
	}

	// trace(op);

	for(int i = 0;i<miss.size();i++){
		if(miss[i] != -10) op++;
	}

	cout<<op<<endl;

	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for (auto&& e : p) cin >> e;
  int ans = 0;
  int cur_min = 1000000;

  for (int i = 0; i < n; i++) {
    if (p[i] < cur_min) {
      ans++;
      cur_min = p[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;

vector<ll> sq;
ll dp[100100][5];

ll solve(int now, int cnt, ll sum) {
	if (sum == n)return 1;
	if (cnt == 4)return 0;
	ll res = 0;
	FOR(i, now, sq.size()) {
		if (sum + sq[i] > (1 << 15))break;
		res += solve(i, cnt + 1, sum + sq[i]);
	}
	return res;
}

int main() {
	for (int i = 1; i*i <= (1 << 15); i++) {
		sq.push_back(i*i);
	}
	//dp[0][0] = 1;
	while (cin >> n&&n) {
		cout << solve(0, 0, 0) << endl;
	}
}

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

using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int main(){
    ll a,b;
    while(cin>>a>>b)
        cout<<gcd(a,b)<<' '<<lcm(a,b)<<endl;
    return 0;
}

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

long long f[2][3][2][3];//状态，位置，0个数 
const long long mod=1e9+7;
int n;
char s[1000010];

int main(){
	int op=0;
	f[0][0][1][0]=1;
	scanf("%s",s+1);
	n=strlen(s+1);s[n+1]='1';
	for(int i=1;i<=n+1;i++){
		op^=1;memset(f[op],0,sizeof(f[op]));
		if(s[i]!='0'){
			f[op][0][1][0]+=f[op^1][0][0][0]+f[op^1][0][0][2]+f[op^1][0][1][1];
			f[op][0][0][0]+=f[op^1][0][0][1]+f[op^1][0][1][2];
			f[op][1][1][0]+=f[op^1][1][0][2]+f[op^1][1][1][1];
			f[op][1][0][0]+=f[op^1][0][1][0]+f[op^1][1][1][0]+f[op^1][1][1][2]+f[op^1][1][0][1];
			f[op][2][1][0]+=f[op^1][1][0][0]+f[op^1][2][0][2]+f[op^1][2][1][1]+f[op^1][2][0][0];
			f[op][2][0][0]+=f[op^1][2][1][2]+f[op^1][2][1][0]+f[op^1][2][0][1];
		}
		if(s[i]!='1'){
			for(int j=0;j<3;j++)
				for(int k=0;k<2;k++)
					f[op][j][k][2]+=f[op^1][j][k][1],f[op][j][k][1]+=f[op^1][j][k][2]+f[op^1][j][k][0];
		}
		for(int j=0;j<3;j++)
			for(int k=0;k<2;k++)
				for(int q=0;q<3;q++) f[op][j][k][q]%=mod;
	}
	printf("%lld",(f[op][2][0][0]+f[op][2][1][0])%mod);
}

Measured memory_bytes: 512
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=parseInt(readline())
    println(ifelse(n-500*div(n,500)<=a,"Yes","No"))
end
main()

Measured memory_bytes: 164628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int h,w;
string ss[2005];
int hs[2005][2005];
int vs[2005][2005];
int main(){
    cin >> h >> w;    
    for(int i=0; i<h; i++){
        cin >> ss[i];
    }

    int cnt=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if( ss[i][j]=='#' ){
                for( int k=0; k<cnt; k++) vs[i][j-1-k] = cnt;
                cnt = 0;
            }else{
                cnt++;
            }
        }
        if( cnt != 0 ){
            for( int k=0; k<cnt; k++) vs[i][w-1-k] = cnt;
            cnt = 0;
        }
    }
    for(int i=0; i<w; i++){
        for(int j=0; j<h; j++){
            if( ss[j][i]=='#' ){
                for( int k=0; k<cnt; k++) hs[j-1-k][i] = cnt;
                cnt = 0;
            }else{
                cnt++;
            }
        }
        if( cnt != 0 ){
            for( int k=0; k<cnt; k++) hs[h-1-k][i] = cnt;
            cnt = 0;
        }
    }
    /*
    for( int i=0; i<h; i++){
    for( int j=0; j<w; j++){
        cerr << vs[i][j] << ":" <<hs[i][j] << ", ";
    }
    cerr << endl;
    }
    */
    int max=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if( hs[i][j]+vs[i][j] > max) max = hs[i][j]+vs[i][j];
        }
    }
    cout << max-1 << endl;
    return 0;
}


Measured memory_bytes: 35712
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int64_t N, Q;
  cin >> N >> Q;

  vector<int64_t> Ws(N+1, N);
  vector<int64_t> Hs(N+1, N);
  int64_t black = (N-2) * (N-2);
  int64_t W = N, H = N;
  for (int64_t q = 0; q < Q; ++q) {
    int64_t type, x;
    cin >> type >> x;
    if (type == 1) {
      if (x < W) {
        for (int64_t c = x; c < W; ++c) {
          Hs[c] = H;
        }
        W = x;
      }
      black -= Hs[x] - 2;
    } else if (type == 2) {
      if (x < H) {
        for (int64_t r = x; r < H; ++r) {
          Ws[r] = W;
        }
        H = x;
      }
      black -= Ws[x] - 2;
    }
  }
  cout << black << endl;
  
  return 0;
}


Measured memory_bytes: 6424
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n = int(input())
  s = input()
  
  cnt = 0
  for i in range(1,n-1):
    if s[i] == 'B':
      if s[i-1] == 'A' and s[i+1] == 'C':
        cnt += 1
  print(cnt)
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
int main()
{
    long long n,k;
    cin>>n>>k;
    cout<<min(n%k,-(n%k-k))<<endl;
	return 0;
}


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

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size() - 2; i++) {
		if (s.substr(i,3)=="ABC") {
			ans++;
			i += 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
//#define long long ll
//unsigned long long ;
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;
int f[10][10];
int first(int k){
	return k%10;
}
int last(int k){
	while(k>9)k/=10;
	return k;
}
int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	int n,ans=0;
	cin >> n;
	for(int i=1; i<=n; i++){
		int x=first(i), y=last(i);
		f[x][y]++;
	}
	for(int i=1; i<=n; i++){
		int x=last(i), y=first(i);
		ans+=f[x][y];
	}
	cout<<ans<<endl;
	return 0;
}

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

int i, j;

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    int count[n] = {0};

    for (i = 1; i < n; i++)
    {
        for (j = i + 1; j <= n; j++)
        {
            int k = min(abs(j - i),
                        abs(x - i) + 1 + abs(y - j));
            count[k]++;
        }
    }

    for (i = 1; i < n; i++)
    {
        cout << count[i] << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int[] array = new int[5];
			for(int i = 0; i < array.length; i++) {
				array[i] = in.nextInt();
			}
			int k = in.nextInt();
			String ans = "Yay!";
			for(int i = 0; i < array.length; i++) {
				for(int j = i + 1; j < array.length; j++) {
					if(array[j] - array[i] > k) {
						ans = ":(";
						break;
					}
				}
			}
			out.println(ans);
 		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;	

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 22868
n, m = map(int, input().split())
A = [[0 for j in range(m)] for i in range(n)]

for i in range(n):
    a = list(map(int,input().split()))[1:]
    for j in a:
        A[i][j-1] = 1

count = 0
for j in range(m):
    flag = True 
    for i in range(n):
        if A[i][j] == 0:
            flag = False 
    if flag:
        count += 1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> pl;
const int INF=100000001;

int main(){
    int n;cin>>n;
    int ans=n*n*n;
    cout<<ans<<endl;

  return 0;
}


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

int main(){
    int A[2];cin>>A[0]>>A[1];
    int ans=0;
    REP(i,2){
        if(A[i]==3) ans+=100000;
        else if(A[i]==2) ans+=200000;
        else if(A[i]==1) ans+=300000;
    }
    if(A[0]==1&&A[1]==1) ans+=400000;
    cout<<ans<<endl;
}

Measured memory_bytes: 256