akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 310
int h, w, d;
ll a[N][N];
P b[N*N];
ll s[N*N];

int main(){
	cin>>h>>w>>d;
	rep(i, h) rep(j, w) cin>>a[i][j];
	rep(i, h) rep(j, w) b[a[i][j]] = P(i, j);
	rep1(i, h*w-d){
		int c = abs(b[i].fst-b[i+d].fst)+abs(b[i].snd-b[i+d].snd);
		s[i+d] = c;
	}
	rep1(i, h*w-d) s[i+d] += s[i];
	int q;
	cin>>q;
	while(q--){
		int l, r;
		cin>>l>>r;
		cout<<s[r]-s[l]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  sort(RALL(v));

  int count = 1;
  ll res = v[0];
  for (int i = 2; i < n; ++i) {
    res += v[count];
    if(i % 2 == 1) count++;
  }
  cout << res << endl;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes(){
  cout << "Yes" << endl;
  exit(0);
}

void no(){
  cout << "No" << endl;
  exit(0);
}

int main(){
  ll n; cin >> n;
  string s; cin >> s;
  ll r = 0, b = 0;
  REP(i,SZ(s)) {
    if(s[i]=='R') r++;
    else b++;
  }
  if(r>b) yes();
  else no();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    for(int i=0; i<=M; i++){
        for(int j=0; j<=N; j++){
            if(i*N+j*M-2*i*j==K){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int top = 0;
int stack[1000] = {0};

void push(int x)
{
	stack[++top] = x;
}

int pop()
{
	top--;
	return stack[top + 1];
}

int main(void)
{
	int a = 0;
	int b = 0;
	char str[100] = {0};

	while (scanf("%s", str) != EOF)
	{
		if (str[0] == '+')
		{
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (str[0] == '-')
		{
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (str[0] == '*')
		{
			a = pop();
			b = pop();
			push (a * b);
		}
		else
		{
			push(atoi(str));
		}
	}

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

	return 0;
}


Measured memory_bytes: 2096
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;

//?§??????°??????????????°?????¶????????????????????°
int n,m,h,k;

//???????§???????????§????1day???????????°
int s,t,p;

typedef pair<int,int> P;
typedef pair<P,int> PP;
struct edge{
	int to,cost,time,corp;
	
	edge(int to_,int cost_,int time_,int corp_){
		to=to_; cost=cost_; time=time_; corp=corp_;
	}
	
};
vector<edge> G[100];

const int BIT=1<<8;

// i????????????????????????????????????
int pass_corps[BIT];

// pass_cost[bit] bit?????¨?????????????????????????????????
int pass_cost[BIT];

//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
int corps_cost[BIT];

// d[time][pos]
int d[25][100];

priority_queue<PP,vector<PP>,greater<PP> > q;

const int INF=1e8;

int solve(int use){
	

	for(int i=0;i<=h;i++){
		for(int j=0;j<n;j++) d[i][j]=INF;
	}
	
	d[0][s]=corps_cost[use];
	
	
	// cost,time,pos
	q.push(PP(P(corps_cost[use],0),s));
	while(!q.empty()){
		
		PP pp=q.top(); q.pop();
		
		int cost=pp.first.first,time=pp.first.second,pos=pp.second;
		
		//printf("cost %d, time %d, pos %d\n",cost,time,pos);
		
		if(pos==t){
			while(!q.empty()) q.pop();
			return cost;
		}
		if(d[time][pos]<cost) continue;
		
		for(int i=0;i<G[pos].size();i++){
			edge e=G[pos][i];
			int to=e.to,ncost=cost+e.cost,nt=time+e.time,ncorp=e.corp;
			
			//printf("to %d, ncost %d, nt %d ncorp %d\n",to,ncost,nt,ncorp);
			
			if(nt>h) continue;
			
			if(use&(1<<ncorp)) ncost=cost;
			if(ncost<d[nt][to]){
				d[nt][to]=ncost;
				q.push(PP(P(ncost,nt),to));
			}
			
		}
		
	}
	
	return INF;
	
}

int main(){
	
	while(scanf("%d %d %d %d",&n,&m,&h,&k),n){
		
		for(int i=0;i<n;i++) G[i].clear();
		for(int i=0;i<(1<<k);i++){
			pass_corps[i]=0;
			pass_cost[i]=corps_cost[i]=INF;
		}
		for(int i=0;i<m;i++){
			int a,b,c,h,r;
			scanf("%d %d %d %d %d",&a,&b,&c,&h,&r);
			a--; b--; r--;
			
			G[a].push_back(edge(b,c,h,r));
			G[b].push_back(edge(a,c,h,r));
		}
		
		scanf("%d %d %d",&s,&t,&p);
		s--; t--;
		
		int l,d,corp,corps;
		for(int i=0;i<p;i++){
			
			scanf("%d %d",&l,&d);
			
			corps=0;
			while(l--){
				scanf("%d",&corp);
				corp--;
				corps|=(1<<corp);
			}
			
			pass_corps[i]=corps;
			pass_cost[pass_corps[i]]=d;
		}
				
		//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
		corps_cost[0]=0;
		for(int i=0;i<(1<<k);i++){
			if(corps_cost[i]==INF) continue;
			for(int j=0;j<p;j++){
				corps_cost[i|pass_corps[j]]=min(corps_cost[i|pass_corps[j]],corps_cost[i]+pass_cost[pass_corps[j]]);
			}
		}
		
		int res=INF;
		for(int use=0;use<(1<<k);use++){
			if(corps_cost[use]==INF) continue;
			res=min(res,solve(use));
		}
		if(res==INF) res=-1;
		cout<<res<<endl;	
	}
}

Measured memory_bytes: 1404
<?php

$str_s=str_split(trim(fgets(STDIN)));
$str_t=str_split(trim(fgets(STDIN)));
$count=count($str_s);
$ans=0;
for($i=0;$i<$count;$i++){
    if($str_s[$i]!=$str_t[$i]){
        $ans++;
    }
}
echo $ans;

Measured memory_bytes: 41312
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
const ll LINF = 1e18;
const ll INF = 1e9;
using namespace std;

ll gcd(ll A, ll B) {
    ll rem;
    if(A<B) {
        ll tmp = A;
        A = B;
        B = tmp;
    }
    rem = A % B;
    if (rem == 0) {
        return B;
    }

    return gcd(B, rem);

}

int main() { 
    ll N; cin >> N;
    int a1, a2; cin >> a1 >> a2;
    ll g = gcd(a1, a2);
    // cout << g << endl;
    REP(i, N-2) {
        int a; cin >> a;
        g = gcd(g, a);
    // cout << g << endl;
    }

    cout << g << endl;

    return 0;
}

Measured memory_bytes: 888
n = int(input())
s = input()
num = s[1:].count('E')
ans = [num]

for i in range(1,n):
    if s[i] == 'E':
        num -= 1
    if s[i-1] == 'W':
        num += 1
    ans.append(num)
print(min(ans))

Measured memory_bytes: 15564
from functools import reduce
A, B =  map(int, (input().split(' ')))

def xor_sum(A,B):
        
    if A%2 == 0:
        if B%2 == 1:
            if (B - A + 1) // 2 % 2 == 0:
                hoge = 0
            if (B - A + 1) // 2 % 2 == 1:
                hoge = 1
            print(hoge)
        else:
            if (B - A + 1 - 1) // 2 % 2 == 0:
                hoge = 0
            if (B - A + 1 - 1) // 2 % 2 == 1:
                hoge = 1
            print(hoge ^ B)
    else:
        if B%2 == 0:
            if (B - A + 1 - 2) // 2 % 2 == 0:
                hoge = 0
            if (B - A + 1 - 2) // 2 % 2 == 1:
                hoge = 1
            print((A ^ hoge) ^ B)
        else:
            if (B - A + 1 - 1) // 2 % 2 == 0:
                hoge = 0
            if (B - A + 1 - 1) // 2 % 2 == 1:
                hoge = 1
            print(A ^ hoge)
            
xor_sum(A, B)

Measured memory_bytes: 3572
N,X,Y = map(int, input().split())

dist = [[0 for i in range(N)] for j in range(N)]
for i in range(1,N):
    for j in range(i):
        dist[i][j]=i-j
dist[Y-1][X-1]=1

for i in range(N):
    y1 = min(Y-1+i,N-1)
    y2 = max(Y-1-i,0)
    for j in range(N):
        x1 = min(X-1+j,N-1)
        x2 = max(X-1-j,0)
        dist[min(y1+1,N-1)][x1] = min(dist[y1][x1]+1,dist[min(y1+1,N-1)][x1])
        dist[min(y1+1,N-1)][x2] = min(dist[y1][x2]+1,dist[min(y1+1,N-1)][x2])
        dist[max(y2-1,0)][x1] = min(dist[y2][x1]+1,dist[max(y2-1,0)][x1])
        dist[max(y2-1,0)][x2] = min(dist[y2][x2]+1,dist[max(y2-1,0)][x2])
        dist[y1][min(x1+1,N-1)] = min(dist[y1][x1]+1,dist[y1][min(x1+1,N-1)])
        dist[y2][min(x1+1,N-1)] = min(dist[y2][x1]+1,dist[y2][min(x1+1,N-1)])
        dist[y1][max(x2-1,0)] = min(dist[y1][x2]+1,dist[y1][max(x2-1,0)])
        dist[y2][max(x2-1,0)] = min(dist[y2][x2]+1,dist[y2][max(x2-1,0)])

ans = [0]*(N-1)

for i in range(1,N):
    for j in range(i):
        ans[dist[i][j]-1] += 1

for i in ans:
    print(i)

Measured memory_bytes: 130908
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n,m,k;
    cin >> n >> m >> k;

    REP(i,n+1){
        REP(j,m+1){
            if(i*j+(n-i)*(m-j)==k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
#define ll long long int
#define pb push_back
#define PI 3.1415926535897932384626
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MOD 4294967296
#define MAX 100001
#define forn(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mset(x,v) memset(x, v, sizeof(x))
int main()
{   
      boost;
            int a,b;
            cin>>a>>b;
            if(b>a)
            swap(a,b);
            int d=2*a-1;
            if(a>8)
            {
                  cout<<":(";
                  return 0;
            }
            else
            {
                  int unused=d-a;
                  unused+=abs(16-d);
                  if(unused>=b)
                  {
                        cout<<"Yay!"<<endl;
                  }
                  else
                  {
                        cout<<":(";
                  }
            }
}

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

using namespace std;

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

  for (int i = n - 1; i >= 0; i--) {
    cout << a[i];
    if (i > 0) {
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 1196
#include <iostream>

int main () {
    int n;
    std::cin >> n;
    int a[n], b[n + 1];
    for(int i = 0; i < n; ++i) {
        std::cin >> a[i];
        b[a[i] - 1] = i + 1;
    }
    for(int i = 0; i < n; ++i){
        std::cout << b[i] << " ";
    }
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int V[3100][3100];
ll dp[3100][3100][5];

int main() {
    int R, C, K; cin >> R >> C >> K;
    for (int i = 0; i < K; i++) {
        int r, c, v; cin >> r >> c >> v;
        V[r-1][c-1] = v;
    }

    for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
            for (int k = 2; k >= 0; k--) {
                chmax(dp[i][j][k+1], dp[i][j][k] + V[i][j]);
            }
            for (int k = 0; k < 4; k++) {
                chmax(dp[i+1][j][0], dp[i][j][k]);
                chmax(dp[i][j+1][k], dp[i][j][k]);
            }
        }
    }

    ll ans = 0;
    for (int k = 0; k < 4; k++) chmax(ans, dp[R-1][C-1][k]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 403228
#include <iostream>

using namespace std;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	
	if (a == b)
	{
		cout << c << endl;
	}
	else if (b == c)
	{
		cout << a;
	}
	else if (a == c)
	{
		cout << b << endl;
	}
}

Measured memory_bytes: 256
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

string s;

int32_t main(){_
   
   cin>>n;

   cin >> s;

   int ans = 0;

   for (int i = 0; i < n; ++i)
   {
      if(i+2 < n and s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C')
         ans++;
   }

   cout<<ans;

   return 0;
}

Measured memory_bytes: 256
/*

Coded and Decoded by : Yash Kapoor

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

// s.find_by_order(index);
// s.order_of_key(value);

#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define sz(x) (ll) x.size()
#define dl '\n'
#define elasped_time  1.0 * clock() / CLOCKS_PER_SEC
//#define why (ll)1000000007
#define why (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios                                                                                                            \
  ios_base::sync_with_stdio(false);                                                                                    \
  cin.tie(0);                                                                                                          \
  cout.tie(0);

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power)
{
  ll result = 1;
  while (power) {
    if (power % 2)
      result = (result * base) % mod;
    base = (base * base) % mod;
    power /= 2;
  }
  return result;
}

ll inverse(ll base, ll mod) { return fast_power(base, mod - 2); }
int test = 1;
vl adj[200005];
vl visited(200005);
ll dp[3001][3001];

void solve() {
  string s,t; cin >> s >> t;
  memset(dp,0,sizeof(dp));
  for(ll i = 0; i <= s.size(); i++){
    for(ll j = 0; j <= t.size(); j++){
      if(i == 0 or j == 0){
        dp[i][j] = 0;
        continue;
      }
      if(s[i-1] == t[j-1]){
        dp[i][j] = dp[i-1][j-1] + 1;
      } else {
        dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
      }
    } 
  }
  ll ind = dp[sz(s)][sz(t)];
  string ans("",ind);
  ll i = sz(s), j = sz(t);
  while(i and j){
    if(s[i-1] == t[j-1]){
      ans[ind-1] = s[i-1];
      i--; j--; ind--;
    } else if(dp[i-1][j] > dp[i][j-1]){
      i--;
    } else j--;
  }
  cout << ans << dl;
} 

int main()
{
  // #ifndef ONLINE_JUDGE 
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt", "w", stdout);
  // #endif
  ios 
  ll t = 1;
  //cin >> t;
  while (t--) 
  {
    //cout << "Case #" << test++ << ": ";
    solve();
  }
  //cerr<<endl<<"समय गुज़रा : "<<elasped_time<<dl;
}

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int a;
  string s;
  
  cin >> a >> s;
  
  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
  
  return 0;
}

Measured memory_bytes: 3544
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;



int main(){
    int N;cin >> N;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    int res = 0;
    for(int i=0;i<N;i++){
        //同じ列を抜ける
        while(i+1<N&&A[i]==A[i+1])i++;
        
        if(i+1<N&&A[i]<A[i+1]){
            while(i+1<N&&A[i]<=A[i+1])i++;
        }
        else if(i+1<N&&A[i]>A[i+1]){
            while(i+1<N&&A[i]>=A[i+1])i++;
        }
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String s = scan.next();
	int fromIndex = 0;
	for (int i = 0; i < s.length(); i++) {
	    if(s.charAt(i) == 'A') {
		fromIndex = i;
		break;
	    }
	}
	int toIndex = 0;
	for (int i = s.length()-1; i > -1; i--) {
	    if(s.charAt(i) == 'Z') {
		toIndex = i;
		break;
	    }
	}

	System.out.println(toIndex - fromIndex + 1);
	scan.close();
    }
}


Measured memory_bytes: 26568
#include <iostream>

int main(){
    int x,y;
    while(true){
        std::cin >> x >> y;
        if(x == 0 && y == 0) break;
        if(x<=y) std::cout << x << " " << y << std::endl;
        else std::cout << y << " " << x << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3064
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N,A,B;
  cin>>N>>A>>B;
  ll num=N/(A+B);
  if(A>=N-num*(A+B))
    cout<<A*num+N-num*(A+B)<<endl;
  else
    cout<<A*(num+1)<<endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 200200;

vector<int> E[MAX];
string S;

enum Color { WHITE, GRAY, BLACK };

Color color[MAX][2];

void dfs(int x, int i) {
  if (color[x][i] == GRAY) {
    cout << "Yes\n";
    exit(0);
  }
  if (color[x][i] == BLACK) {
    return;
  }

  color[x][i] = GRAY;
  for (int y : E[x]) {
    if (i == 1) {
      if (S[x] != S[y]) dfs(y, 0);
    } else {
      if (S[x] == S[y]) dfs(y, 1);
    }
  }
  color[x][i] = BLACK;
}

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

  int N, M;
  cin >> N >> M;

  cin >> S;

  REP(i, M) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    E[A].push_back(B);
    E[B].push_back(A);
  }

  REP(i, N) REP(j, 2) {
    if (color[i][j] == WHITE) {
      dfs(i, j);
    }
  }

  cout << "No\n";
  return 0;
}


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

int main(){
int a,b;
  cin>>a>>b;
  vector<int> c(a);
  for(int i=0;i<a;i++)
    cin>>c.at(i);
  sort(c.begin(),c.end());
  vector<int> d=c;
  d.erase(unique(d.begin(), d.end()), d.end());
  int e=d.size();
  d=c;
  vector<int> f(e,0);
  int g=0,h=0;
  for(int i=0;i<a;i=i){
    g=c.at(i);
    while(i<a){
      if(g==c.at(i)){
        i++;
        f.at(h)++;
      }
      else{
        h++;
        break;
      }
    }
  }
  sort(f.begin(),f.end());
  int count=0;
  for(int i=0;i<e-b;i++)
    count+=f.at(i);
  cout<<count<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<P> pairs;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    pairs.push_back(make_pair(b, a));
  }
  sort(pairs.begin(), pairs.end());
  bool flag = true;
  ll now_time = 0, dead_line = 0;
  rep(i, n) {
    now_time += pairs[i].second;
    dead_line = pairs[i].first;
    if (now_time > dead_line) {
      flag = false;
      break;
    }
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 2420
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
signed main()
{
    fasino
    string A,B;
    int ans = 0;
    cin>>A>>B;
    for(int i=0;i<A.size();i++){
        if(A[i]!=B[i]) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3796
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#define data m_data
using namespace std;
const int maxn=500000+5;
map<int,int> mp;
int data[maxn],a[maxn],ans[4*maxn];
struct node{
    int l,r,id;
    bool operator<(node t)const{
        return r<t.r;
    }
}q[4*maxn];
 
int lowbit(int x)
{
    return x&-x;
}
 
int Get_sum(int i)
{
    int ans=0;
    while(i>0){
        ans+=data[i];
        i-=lowbit(i);
    }
    return ans;
}
 
void Update(int i,int x)
{
    while(i<maxn){
        data[i]+=x;
        i+=lowbit(i);
    }
}
 
void solve(int T)
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
    	scanf("%d",&a[i]);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].id=i;
    }
    sort(q,q+m);
    int pre=1;
    for(int i=0;i<m;i++)
    {
        for(int j=pre;j<=q[i].r;j++)
        {
            if(mp[a[j]]!=0)
                Update(mp[a[j]],-1);
                Update(j,1);
                mp[a[j]]=j;
            }
            pre=q[i].r+1;
            ans[q[i].id]=Get_sum(q[i].r)-Get_sum(q[i].l-1);
    }
    for(int i=0;i<m;i++)
        printf("%d\n",ans[i]);
    return;
}

int main(){
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


Measured memory_bytes: 38936
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
#define MOD 1000000007
int main(){
    ll N;
    cin >> N;
    ll a[N];
    ll i;
    ll sum1=0,sum2=0;
    ll cnt1=0,cnt2=0;
    ll t=1;
    for(i=0;i<N;i++){
        cin >> a[i];
        sum1+=a[i];
        sum2-=a[i];
        if(sum1*t<=0){
            cnt1+=abs(sum1)+1;
            sum1=t;
        }
        if(sum2*t<=0){
            cnt2+=abs(sum2)+1;
            sum2=t;
        }
        t*=-1;
    }
    cout << min(cnt1,cnt2);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
 
using namespace std;
 
int h,w,sx,sy,gx,gy,tx,ty;
char house[505][505];   
bool isvisited[505][505]={false};
 
void search(int x,int y){
    if(isvisited[x][y]){
        return;
    }
    isvisited[x][y]=true;
 
    if(x<=0 || x>h || y<=0 || y>w){
        return;
    }
 
    if(house[x][y]=='#'){
        return;
    }
 
    search(x-1,y-1);
    search(x-1,y);
    search(x-1,y+1);
    search(x,y-1);
    search(x,y);
    search(x,y+1);
    search(x+1,y-1);
    search(x+1,y);
    search(x+1,y+1);
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s,t,u;
  int a,b;
  cin>>s;
  rep(i,s.size()){
    cout<<'x';
  }
  cout<<'\n';
  return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

X,K,D = LI()

sign = np.sign(X)
x = abs(X)

# if x//D==0:
#     if K%2==0:
#         ans = X
#     else:
#         ans = -1 * sign * (x - D)
if x//D>K:
    ans = sign * (x-K*D)
# ちょうど0で振動する場合
elif x%D==0:
    if (K - x//D) % 2 ==0:
        ans = 0
    else:
        ans = -1 * D
else:
    # 残り回数が偶数回
    if (K - x//D) % 2 ==0:
        # print('even')
        ans = sign * (x- (x//D)*D)
    else:
        # print('odd')
        ans = -1 * sign * (x - (x//D)*D -D)
print(abs(ans))

Measured memory_bytes: 27208
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;



int main()
{
  int A, B, K;
  vector<int> vec;
  cin >> A >> B >> K;
  for(int i = 1; i <= min(A, B); i++) {
    if ((A % i) == 0 && (B % i) == 0) {
      vec.push_back(i);
    }
  }
  reverse(ALL(vec));
  cout << vec[K-1] << 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;

int main(){
 int n, m;
  cin >> n >> m;
  
  vector<int> a(m), b(m);
  rep(i, m){
    a[i] = i+1;
    if(n % 2 ==0){
    	if(i+1 <= n/4) b[i] = n - i;
    	else b[i] = n - a[i];
    }
    else
    	b[i] = n - i;  
    cout << a[i] <<  " " << b[i] << endl;
    }
   
    return 0;
  }
    
    

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

#define N 3000010 

using namespace std;

char s[N], t[N];

int main() {
    int n, m;
    cin >> n >> m ;
    scanf("%s%s", s + 1, t + 1);
    int d = __gcd(n, m);
    int n_ = n / d, m_ = m / d;
    for (int i = 0; i < d; i ++ ) {
        int k1 = i * n_ + 1, k2 = i * m_ + 1;
        if (s[k1] != t[k2]) {
            puts("-1");
            return 0;
        }
    }
    cout << (long long)n_ * m_ * d << endl ;
    return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<stack>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const ll m = (1e+9) + 7;

int main() {
	int n, m;
	static ll ans;
	vector<pair<int, int>> p;
	cin >> n >> m;
	priority_queue<int> que;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		p.push_back(make_pair(a, b));
	}
	sort(p.begin(), p.end(),greater<pair<int,int>>());
	for (int day = 1; day <= m; ++day) {
		while (!p.empty() && p.back().first == day) {
			que.push(p.back().second);
			p.pop_back();
		}
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n,k; cin >> n >> k;
    int ans = 0;
    for(int i=0;i<n;i++){
        int x; cin >> x;
        ans += 2*min(x,abs(k-x));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main()
{
  int i,j,l,k,q,n,p[N+1],m[N+1][N+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d%d",&p[i-1],&p[i]);
  for(i=1;i<=n;i++) m[i][i]=0;

  for(l=2;l<=n;l++)
  {
    for(i=1;i<=n-l+1;i++)
    {
      j = i+l-1;
      m[i][j] = (1<<21);
      for(k=i;k<=j-1;k++)
      {
        q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        if(m[i][j]>=q)m[i][j]=q;
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}



Measured memory_bytes: 2084
X, K, D = map(int, input().split())
X = abs(X)

min_abs = 10**15
min_step = X // D
if K <= min_step:
    min_abs = X - D*K
else:
    lowest_plus = X - D*min_step
    highest_minus = abs(lowest_plus - D)
    if (K - min_step) % 2 == 0:
        min_abs = lowest_plus
    else:
        min_abs = highest_minus

print(min_abs)

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

using namespace std;

int main()
{
  long long A, B, C, D;
  cin >> A >> B >> C >> D;

  long long n_c = (B / C) - (A / C + 1) + 1;
  if (A % C == 0) {
    n_c += 1;
  }

  long long n_d = (B / D) - (A / D + 1) + 1;
  if (A % D == 0) {
    n_d += 1;
  }

  long long CD = C * D / __gcd(C, D);
  long long n_cd = (B / CD) - (A / CD + 1) + 1;
  if (A % CD == 0) {
    n_cd += 1;
  }

  long long ans = (B - A + 1) - n_c - n_d + n_cd;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s, t;
    cin >> s >> t;
    FOR(i, 0, s.size()-1) {
        string tmp = s.substr(i, s.size()-i) + s.substr(0, i);
        if (tmp == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;
const ll inf = (ll) 9e18;

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

  int h, n;
  cin >> h >> n;
  vector<Pii> ab(n);
  for (auto &x: ab) cin >> x.first >> x.second;

  vector<ll> dp(h+1, inf);
  dp[h] = 0;
  for (int i = h; i > 0; i--) {
    for (int j = 0; j < n; j++) {
      dp[max(0, i-ab[j].first)] = min(dp[max(0, i-ab[j].first)], dp[i] + ab[j].second);
    }
  }

  cout << dp[0] << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int, int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef pair<double, int> PDI;
typedef vector<PDI> VD;

string s;
bool dp[100010];
signed main()
{
  cin >> s;
  dp[0] = true;
  
  for(int i = 0; i < s.size(); i++){
    if(dp[i]){
      if(s.size() - i >= 5){
	if(s[i] == 'e' && s[i + 1] == 'r' && s[i + 2] == 'a' && s[i + 3] == 's' && s[i + 4] == 'e'){
	  dp[i + 5] = true;
	  if(s.size() - i >= 6 && s[i + 5] == 'r'){
	    dp[i + 6] = true;
	  }
	}

	if(s[i] == 'd' && s[i + 1] == 'r' && s[i + 2] == 'e' && s[i + 3] == 'a' && s[i + 4] == 'm'){
	  dp[i + 5] = true;
	  if(s.size() - i >= 7 && s[i + 5] == 'e' && s[i + 6] == 'r'){
	    dp[i + 7] = true;
	  }
	}
      }
    }
  }

  cout << (dp[s.size()] ? "YES" : "NO") << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<fstream>
#include<string>
using namespace std;
typedef long long ll;
#define int ll
const ll inf=((ll)1<<59);
ll dp1[200005][20]={0},dp2[200005][20]={0},ar[200005]={0};
signed main(){
  ll n;
  cin>>n;
  for(ll i=1;i<=n;i++) cin>>ar[i];
  for(ll i=0;i<200005;i++){
    for(ll j=0;j<=15;j++){
      dp1[i][j]=inf;
      dp2[i][j]=inf;
    }
  }
  for(ll i=0;i<=15;i++){
    dp1[n+1][i]=0;
    dp1[n][i]=i;
  }
  for(ll i=n-1;i>=1;i--){
    for(ll j=0;j<=15;j++){
      ll dis=((ar[i]*((ll)1<<(2*j))+ar[i+1]-1)/ar[i+1])-1;
      ll x=0;
      while(dis>0){
        dis/=4;
        x++;
      }
      //if(j==0) cout<<i<<" "<<x<<endl;
      if(x>=15) dp1[i][j]=min(dp1[i][j],(n-i)*(x-15)+dp1[i+1][15]+j);
      else dp1[i][j]=min(dp1[i][j],dp1[i+1][x]+j);
    }
  }
  for(ll i=0;i<=15;i++) {
    dp2[0][i]=0;
    dp2[1][i]=i;
  }
  for(ll i=2;i<=n;i++){
    for(ll j=0;j<=15;j++){
      ll dis=((ar[i]*((ll)1<<(2*j))+ar[i-1]-1)/ar[i-1])-1;
      ll x=0;
      while(dis>0){
        dis/=4;
        x++;
      }
      if(x>=15) dp2[i][j]=min(dp2[i][j],(i-1)*(x-15)+dp2[i-1][15]+j);
      else dp2[i][j]=min(dp2[i][j],dp2[i-1][x]+j);
    }
  }
  ll ans=inf;
/*  for(int i=0;i<=n;i++){
    for(int j=0;j<=15;j++) cout<<(dp1[i][j]==inf?-1:dp1[i][j])<<" ";
    cout<<endl;
  }
  cout<<endl<<endl;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=15;j++) cout<<(dp2[i][j]==inf?-1:dp2[i][j])<<" ";
    cout<<endl;
  }*/
  for(ll i=0;i<=n;i++){
    ans=min(ans,i+(dp2[i][0]+dp1[i+1][0])*2);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 64384
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int a,b,c;
  cin>>a>>b>>c;
  if(a<=c*b) cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3644
NM = input()
NMs = NM.split(" ")
N = int(NMs[0])
M = int(NMs[1])
A = input()
Ai = A.split(" ")
days = 0
for i in Ai:
    days = days + int(i)
if days <= N:
    print (N - days)
else:
    print("-1")


Measured memory_bytes: 65612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			long a = Integer.parseInt(arr[0]);
			long b = Integer.parseInt(arr[1]);
			
			long n_gcd = gcd(a, b);
			long n_lcm = a * b / n_gcd;
			
			System.out.println(n_gcd + " " + n_lcm);
		}
	}
	
	public static long gcd(long x, long y) {
		if (x < y) {
			long temp = x;
			x = y;
			y = temp;
		}
		
		while (y > 0) {
			long r = x % y;
			x = y;
			y = r;
		}
		
		return x;
	}

}

Measured memory_bytes: 24264
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N;
    cin >> N;
    vector<Pii> A(N);
    for(int i=0; i<N; i++){
        scanf(" %d", &A[i].first); A[i].second = i+1; 
    }

    sort(A.begin(), A.end());
    for(int i=0; i<N; i++) cout << A[i].second << " ";
    cout << endl;
}

Measured memory_bytes: 1664
n,*a=map(int,open(0).read().split());b={};M=10**9+7;p=n+1;q=r=1
for i,x in enumerate(a):
 if x in b:d=i-b[x];break
 b[x]=i
for k in range(n+1):print((p-q)%M);q=q*(n-d-k)*r%M;r=pow(k+2,M-2,M);p=p*(n-k)*r%M

Measured memory_bytes: 62772
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        sc.close();

        long ret = (long) (a + Math.pow(a, 2) + Math.pow(a, 3));

        System.out.println(ret);
    }
}


Measured memory_bytes: 37344
import sys
sys.setrecursionlimit(10**6)
n = int(input())
p = list(map(int, input().split()))
c = [[] for _ in range(n)]
is_leaf = [True for _ in range(n)]
for i in range(n):
	p[i] -= 1
	c[p[i]].append(i)
	is_leaf[p[i]] = False

if sum(is_leaf) == 0:
	if n%2 == 0:
		print("POSSIBLE")
	else:
		print("IMPOSSIBLE")
	sys.exit()

for i in range(n):
	if is_leaf[i]:
		cur = i
		break

visited_set = {cur}
visited_list = [cur]
while p[cur] not in visited_set:
	visited_list.append(p[cur])
	visited_set.add(p[cur])
	cur = p[cur]

root = p[cur]

grundy = [-1 for _ in range(n)]
g_set = [set() for _ in range(n)]

def dfs(x):
	res = 0
	for v in c[x]:
		dfs(v)
		g_set[x].add(grundy[v])
	while res in g_set[x]:
		res += 1
	grundy[x] = res
	return res

loop = [False for _ in range(n)]
loop[root] = True
ind = len(visited_list)-1
while visited_list[ind] != root:
	loop[visited_list[ind]] = True
	ind -= 1
#print(loop)

for i in range(n):
	if loop[i]:
		for x in c[i]:
			if not loop[x]:
				dfs(x)
				g_set[i].add(grundy[x])

cand = []
num = 0
while num in g_set[root]:
	num += 1
cand.append(num)
num += 1
while num in g_set[root]:
	num += 1
cand.append(num)

for x in cand:
	cur = root
	grundy[root] = x
	while True:
		num = 0
		while num in g_set[p[cur]] or num == grundy[cur]:
			num += 1
		grundy[p[cur]] = num
		if p[cur] == root:
			break
		cur = p[cur]
	if grundy[root] == x:
		#print(grundy)
		print("POSSIBLE")
		sys.exit()

print("IMPOSSIBLE")

Measured memory_bytes: 177596
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define INF 9999999
int n, m, s, g1, g2;
int D[100][100];

int cost[100][100];

void wf() {
  for(int m = 0; m < n; ++m) {
    for(int i = 0; i < n; ++i) {
      for(int j = 0; j < n; ++j) {
	D[i][j] = min(D[i][j], D[i][m] + D[m][j]);
      }
    }
  }
}

void solve() {
  wf();
  int ans = INF;
  for(int i = 0; i < n; ++i) {
    ans = min(ans, D[s][i] + D[i][g1] + D[i][g2]);
  }
  cout << ans << endl;
}

main() {
  while((cin >> n >> m >> s >> g1 >> g2) &&
	(n || m || s || g1 || g2)) {
    s--; g1--; g2--;
    for(int i = 0; i < n; ++i) {
      for(int j = 0; j < n; ++j) {
	D[i][j] = i == j ? 0 : INF;
      }
    }
    for(int i = 0; i < m; ++i) {
      int b1, b2, c;
      cin >> b1 >> b2 >> c;
      b1--; b2--;
      D[b1][b2] = c;
    }
    solve();
  }
}

Measured memory_bytes: 904
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(d%2 ==0){
  cout <<a-b << endl;
  }
  
  else{
  cout << (a-b)*(-1) << endl;
  }
}


Measured memory_bytes: 256
s = gets.chomp
t = gets.chomp

delta = s.length - t.length
ans = 9999

def difference(s, t)
  tmp = 0
  s.length.times do |i|
    tmp += 1 if s[i] != t[i]
  end

  return tmp
end

(delta+1).times do |i|
  tmp = difference(s[i..(i+t.length - 1)], t)
  ans = [ans, tmp].min
end

puts ans


Measured memory_bytes: 14364
N,W=map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]



max_sum = sum([i[1] for i in A])

max_value=10**10
dp = [[max_value for i in range(max_sum+1) ] for j in range(N+1)]
dp[0][0]=0

for i in range(N):
    for v in range(max_sum+1):
        if v>=A[i][1]:
            dp[i+1][v] = min([dp[i][v-A[i][1]]+A[i][0], dp[i][v]])

        else:
            dp[i+1][v] = dp[i][v]

#ここでindexは価値と同値、複数あることを考慮して反転後indexで最も価値のある個所を取得
# try:
#     print(max_sum-dp[N][::-1].index(W))
# except:
#     print(max_sum-dp[N][::-1].index(W))
for i,w in enumerate(dp[N][::-1]):
    if w <=W:
        print(max_sum-i)
        break
#     print(int(dp[N][W]))

Measured memory_bytes: 172272
package main

import (
    "fmt"
)

func checkSubstr(s string, d []string) bool {
    for i := 0; i < len(d); i++ {
        //s[0:len(d[i])]のエラーチェック
        if len(s) < len(d[i]) {
            continue
        }
        if s[0:len(d[i])] == d[i] {
            if len(s) == len(d[i]) {
                return true
            }
            return checkSubstr(s[len(d[i]):], d)
        }
    }
    return false
}

func reverse(s string) string {
    rs := []rune(s)
    for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
        rs[i], rs[j] = rs[j], rs[i]
    }
    return string(rs)
}

func main() {
    var s string
    fmt.Scan(&s)
    d := []string{"maerd", "remaerd", "esare", "resare"}
    s = reverse(s)

    if checkSubstr(s, d) {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
#define int long long
using namespace std;
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;}
typedef pair<int,int> P;
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
const int Z=50000;
const int L=4150;
bool ok(char a,char b){
    return (a==b||a=='?'||b=='?');
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string a,b,c;
    cin >> a >> b >> c;
    bool ab[100100],bc[100100],ac[100100];
    rep(i,100100) ab[i]=bc[i]=ac[i]=1;
    int A=a.size(),B=b.size(),C=c.size();
    
    rep(i,A)rep(j,B) if(!ok(a[i],b[j])) ab[i-j+Z]=0;
    rep(i,A)rep(j,C) if(!ok(a[i],c[j])) ac[i-j+Z]=0;
    rep(i,B)rep(j,C) if(!ok(b[i],c[j])) bc[i-j+Z]=0;
    int ans=A+B+C;
    for(int i=-L;i<L;i++){
        for(int j=-L;j<L;j++){
            if(ab[i+Z]&&ac[j+Z]&&bc[j-i+Z]){
                int left=min({0LL,i,j});
                int right=max({A,B+i,C+j});
                chmin(ans,right-left);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
import random
import copy
D=int(input())                                          #コンテの日数
c=list(map(int,input().split()))                        #26タイプ(AAC~AZC)のコンテストの満足度低下度
s=[list(map(int,input().split())) for _ in range(D)]    #s[d][i]...d(1<=d<=D)日目にi(1<=i<=26)番目のコンテストを行った時の満足度上昇
#types=[int(input()) for _ in range(D)]                  #コンテタイプ(1~26)
#満足度低下はΣ(1<=i<=26)ci*(d-last(d,i))                  #なおlast(d,i)=d日目以前に最後にタイプiのコンテストをやった日にち(ない場合0)
#よって満足度はs[d][i]-Σ(1<=i<=26)ci*(d-last(d,i))
#i日目のスコアはmax(10^6+s[d][i]-Σ(1<=i<=26)ci*(d-last(d,i)),0)
#last=[0]*26                                             #typeごとに、最後に使われた日にちを記録するよ
typ=0
ans=0
#greedyに最大とりまーす
#D=365
types=[(i%26)+1 for i in range(D)]
#print(l)
sc = [0] * D
last=[0]*26
for i in range(D):
    typ = types[i] - 1
    score = s[i][typ]
    dwn = 0
    last[typ] = (i + 1)
    for j in range(26):
        dwn = dwn + c[j] * ((i + 1) - last[j])
    ans = score - dwn
    # print(score,last)
    sc[i] = min(ans+10**6,0)
all = sum(sc)
for _ in range(4000):
    types2 = []
    mi=float("inf")
    ind=0
    for i in range(D):
        if mi>sc[i]:
            mi=sc[i]
            ind=i
    l=list(range(1,D+1))
    #print(l)
    #print(ind,types[ind]-1)
    l.pop(ind-1)
    ind2=random.choice(l)
    spans=ind//26
    types2=copy.deepcopy(types)
    buf=types[ind]
    types[ind]=types[ind2-1]
    types[ind2-1]=buf
    sc2=[0]*D
    last=[0]*26
    for i in range(D):
        typ = types[i] - 1
        score = s[i][typ]
        dwn = 0
        last[typ] = (i + 1)
        for j in range(26):
            dwn = dwn + c[j] * ((i + 1) - last[j])
        ans = score - dwn
                # print(score,last)
        sc2[i] = min(ans+10**6,0)
    all2 = sum(sc2)
    if all2<=all:
        types=types2
    else:
        sc=sc2
        all=all2
        sc2=[]
        #print(114514)
    #print(all)
    #input()
for i in range(D):
    print(types[i])



Measured memory_bytes: 82020
K = int(input())


def ns(n):
    return sum([int(c) for c in str(n)])


ans, base = 0, 1
for _ in range(K):
    ans += base
    print(ans)

    if (ans + base) / ns(ans + base) > (ans + 10 * base) / ns(ans + 10 * base):
        base *= 10

Measured memory_bytes: 38896