akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T; 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int N,res=0;
vector<T> ans;
int ink[10][10];
int sx[5]={-1,0,0,0,1};
int mx[9]={-1,-1,-1,0,0,0,1,1,1};
int lx[13]={-2,-1,-1,-1,0,0,0,0,0,1,1,1,2};
int sy[5]={0,1,-1,0,0};
int my[9]={-1,0,1,-1,0,1,-1,0,1};
int ly[13]={0,1,0,-1,2,1,0,-1,-2,1,0,-1,0};
void ps(int x,int y)
{
	for(int i=0;i<5;i++)
	{
		int nx=x+sx[i],ny=y+sy[i];
		ink[nx][ny]--;
	}
	res -= 5;
}
void psr(int x,int y)
{
	for(int i=0;i<5;i++)
	{
		int nx=x+sx[i],ny=y+sy[i];
		ink[nx][ny]++;
	}
	res += 5;
}
bool psc(int x,int y)
{
	for(int i=0;i<5;i++)
	{
		int nx=x+sx[i],ny=y+sy[i];
		if(ink[nx][ny]==0)return false;
	}
	return true;
}
void pm(int x,int y)
{
	for(int i=0;i<9;i++)
	{
		int nx=x+mx[i],ny=y+my[i];
		ink[nx][ny]--;
	}
	res -= 9;
}
void pmr(int x,int y)
{
	for(int i=0;i<9;i++)
	{
		int nx=x+mx[i],ny=y+my[i];
		ink[nx][ny]++;
	}
	res += 9;
}
bool pmc(int x,int y)
{
	for(int i=0;i<9;i++)
	{
		int nx=x+mx[i],ny=y+my[i];
		if(ink[nx][ny]==0)return false;
	}
	return true;
}
void pl(int x,int y)
{
	for(int i=0;i<13;i++)
	{
		int nx=x+lx[i],ny=y+ly[i];
		ink[nx][ny]--;
	}
	res -= 13;
}
void plr(int x,int y)
{
	for(int i=0;i<13;i++)
	{
		int nx=x+lx[i],ny=y+ly[i];
		ink[nx][ny]++;
	}
	res += 13;
}
bool plc(int x,int y)
{
	for(int i=0;i<13;i++)
	{
		int nx=x+lx[i],ny=y+ly[i];
		if(ink[nx][ny]==0)return false;
	}
	return true;
}
bool dfs(int d)
{
	if(res > 13*(N-d))return false;
	if(d==N)
	{
		if(res==0)return true;
		else return false;
	}
	int x,y;
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(ink[i][j]>0)
			{
				x=i,y=j;
				goto next;
			}
		}
	}
	next:;
	if(psc(x+1,y))
	{
		ps(x+1,y);
		bool f = dfs(d+1);
		if(f)ans.pb(T(P(x+1,y),1));
		psr(x+1,y);
		if(f)return true;
	}
	if(pmc(x+1,y+1))
	{
		pm(x+1,y+1);
		bool f = dfs(d+1);
		if(f)ans.pb(T(P(x+1,y+1),2));
		pmr(x+1,y+1);
		if(f)return true;
	}
	if(plc(x+2,y))
	{
		pl(x+2,y);
		bool f = dfs(d+1);
		if(f)ans.pb(T(P(x+2,y),3));
		plr(x+2,y);
		if(f)return true;
	}
	return false;
}
int main()
{
	cin >> N;
	for(int i=0;i<10;i++)for(int j=0;j<10;j++)
	{
		cin >> ink[i][j];
		res += ink[i][j];
	}
	dfs(0);
	for(int i=0;i<N;i++)printf("%d %d %d\n",ans[i].fi.sec,ans[i].fi.fi,ans[i].sec);
	return 0;
}

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

using namespace std;

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

typedef int _loop_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 DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
char s[252521];

int main(){
  scanf("%d",&n);
  scanf("%s",s);
  int r = count(s,s+n,'.');
  int l = 0;
  int ans = l+r;
  REP(i,n){
    if(s[i]=='.'){
      r--;
    }else{
      l++;
    }
    CHMIN(ans,l+r);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  char temp='?';
  int N,K,ans=0,count=1;
  cin>>N>>K;

  string S;
  cin>>S;
  for(int i=0;i<N;i++){
    if(S[i]!=temp){
      ans+=count-1;
      temp=S[i];
      count=1;
    }else count++;
  }
  ans+=count-1;
  cout<<min(N-1,ans+K*2)<<endl;
}


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

int main()
{
    int s, s1 = 0, s2 = 0, s3 = 0;

    cin >> s;
    s1 = s / 100;
    s2 = (s - (s1 * 100)) / 10;
    s3 =  s - (s1 * 100) - (s2 * 10);
    cout << s1 + s2 + s3 << endl;
}

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

signed main() {
  int h,w,a,b;
    scanf("%d%d%d%d",&h,&w,&a,&b);
  for(int i=0;i<h;i++){
    if(i<b){
    	string s(a,'0');
    	string t(w-a,'1');
        s+=t;
    	//printf("%s\n",ans);
        cout<<s<<endl;
    }
    else{
        string s(a,'1');
    	string t(w-a,'0');
    	s+=t;
    	//printf("%s\n",ans);
        cout<<s<<endl;
    }
  }
}


Measured memory_bytes: 1280
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int n;
int m, v, p;

ll inp[N];
ll cum[N];

int f(int mid){
  if(mid <= p){
    return 1;
  }
  if(inp[mid] + m < inp[p]){
    return 0;
  }
  ll need = 0;
  for(int i = 1; i <= n; i++){
    if(i < p || i >= mid){
      need += m;
    } else {
      need += inp[mid] + m - inp[i];
    }
  }
  return need >= 1ll * m * v;
}

int Solve(){
  int low = 1, high = n, ans = p;
  while(low <= high){
    int mid = (low + high) >> 1;
    if(f(mid)){
      ans = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  return ans;
}

int main(){
  int test = 1;
  //fastScan(test);
  while(test--){
    fastScan(n);
    fastScan(m);
    fastScan(v);
    fastScan(p);
    for(int i = 1; i <= n; i++){
      fastScan(inp[i]);
      cum[i] += cum[i - 1] + inp[i];
    }
    sort(inp + 1, inp + n + 1, greater < ll > ());
    printf("%d\n", Solve());
  }
  return 0;
}


Measured memory_bytes: 1792
import java.io.*;

public class Main{
    public static void main(String[] args){
        BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
        try{
        String line=reader.readLine();
        int n=Integer.parseInt(line);
        System.out.println(n*n*n);
        }catch(IOException e){
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 24416
/*Rabbi Zidni Ilma*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define mod 10000007
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)


int main()
{
	ll tc,i,n,x,ans;
    scl(n);
    if(n==0)
	printf("1\n");
	else
	printf("0\n");
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, K, ans = 1;

	cin >> N >> K;

	rep(i, N) {
		if (ans < K) ans *= 2;
		else ans += K;
	}

	cout << ans << endl;

	return 0;
}


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

const int INF = 100000000; // 十分大きな値

/*
やりたいこと	実装
mask で表された部分のフラグをまとめて立てる	bit ｜= mask
mask で表された部分のフラグをまとめて消す	bit &= ~mask
mask で表された部分の情報のみを取り出したもの	bit & mask
mask で表された部分のどれかのフラグが立っているかどうか	if (bit & mask)
mask で表された部分のすべてのフラグが立っているかどうか	if ((bit & mask) == mask)
*/

/* 入力 */
int N,V;
int dist[21][21];

/* メモ再帰 */
int dp[(1<<20) + 1][21]; // dpテーブルは余裕をもったサイズにする
int rec(int bit, int v)
{
  // すでに探索済みだったらリターン
  if (dp[bit][v] != -1) return dp[bit][v];

  // 初期値
  if (bit == (1<<v)) {
    return dp[bit][v] = dist[0][v];
  }

  // 答えを格納する変数
  int res = INF;

  // bit の v を除いたもの
  int prev_bit = bit & ~(1<<v);

  // v の手前のノードとして u を全探索
  for (int u = 0; u < N; ++u) {
    if (!(prev_bit & (1<<u))) continue; // u が prev_bit になかったらダメ

    // 再帰的に探索
    if (res > rec(prev_bit, u) + dist[u][v]) {
      res = rec(prev_bit, u) + dist[u][v];
    }
  }

  return dp[bit][v] = res; // メモしながらリターン
}

int main()
{
  // 入力
  cin >> N >> V;
  for(int i=0;i<21;i++)for(int j=0;j<21;j++){
    if(i==j) dist[i][j]=0;
    else dist[i][j]=INF;
  }
  for(int i=0;i<V;i++){
    int s,t,d; cin >> s >> t >> d;
    dist[s][t]=d;
  }

  // テーブルを全部 -1 にしておく (-1 でなかったところは探索済)
  for (int bit = 0; bit < (1<<N); ++bit) for (int v = 0; v < N; ++v) dp[bit][v] = -1;

  // 探索
  int res = INF;
  if (res > rec((1<<N)-1, 0)) {
    res = rec((1<<N)-1, 0);
  }

  if(res>=INF/2) cout << -1 << endl;
  else cout << res << endl;
}



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

const bool DEBUG = false;

int main(int argc, char const *argv[]) {
  int N;
  string S;
  cin >> N >> S;
  char s_prev;
  bool init = true;
  int total = 1;
  for (auto &&s : S) {
    if (DEBUG) cout << s << endl;
    if (init) {
      s_prev = s;
      init = false;
      continue;
    }
    if (s != s_prev) {
      total += 1;
    }
    s_prev = s;
  }
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int H,N;

  cin >> H;
  cin >> N;

  vector <long int> ATTACK(N);

  long int totalAttack = 0;
  for(int i = 0; i < N; i++){
      int tmp = 0;
      cin >> tmp;
      totalAttack += tmp;
  }

  if(totalAttack >= H){
      cout << "Yes" << endl;
  }else {
      cout << "No" << endl;
  }
}

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

int main(){
  int n;
  cin >> n;
  for(int i=1;i<50000;i++){
    if((int)(i*1.08) == n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    m[s]++;
  }

  vector<pair<int, string>> p;
  for (auto x : m) {
    p.push_back(make_pair(x.second, x.first));
  }
  sort(p.begin(), p.end());
  int ma = (*--p.end()).first;
  for (int i = 0; i < p.size(); i++) {
    if (p[i].first == ma) cout << p[i].second << endl;
  }
}


Measured memory_bytes: 28912
#include<bits/stdc++.h>
#define fastAF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mapll map<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define deb(x) cout<<x
using namespace std;
int main()
{
    fastAF
   ll int d,t,s,x;
   cin>>d>>t>>s;
   if(d%s!=0){
       x=d/s+1;
   }else{
       x=d/s;
   }
   if(x<=t){
       cout<<"Yes\n";
   }else{
       cout<<"No\n";
   }
}
 
 
 

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

#define rep(i, n) for(long long i=0;i<n;i++)
using ll = long long;
const ll INF = (1LL<<60);

int main(){

    ll n; cin >> n;
    ll p[n];
    rep(i, n) cin >> p[i];

    vector<ll> dp(n, INF);
    dp[0] = p[0];
    for(ll i=1;i<n;i++){
        dp[i] = min(dp[i-1], p[i]);
    }

    ll cnt = 0;
    rep(i, n) if(dp[i]==p[i]) cnt++;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3328
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 21 23:12:36 2020

@author: liang
"""

"""
eval関数
入力 :　式
    eval("2+3")
出力 : 値
    5
"""
S = input()

ans = S[0]
for i in range(8):
    tmp = S[0]
    
    for j in range(3):
        if i>>j&1 == 1:
            tmp += "+" + S[j+1]
        else:
            tmp += "-" + S[j+1]
    #print(tmp)
    #print(eval(tmp))
    if eval(tmp) == 7:
        #print("ok")
        ans = tmp
        ans += "=7"
        #print(ans)
        break
print(ans)

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

//library----------------------------------------------


int main(){
    CIN(N);
    vi A(N),B(N),C(N);
    rep(i,N) {cin>>A[i];--A[i];}
    rep(i,N) cin>>B[i];
    rep(i,N-1) cin>>C[i];

    int ans=0;
    rep(i,N){
        ans+=B[A[i]];
        if(A[i]+1==A[i+1]) ans+=C[A[i]];
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    cout << n + n * n + n * n * n << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<double> x(n + 1), y(n + 1);
    for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
    vector<int> v(n);
    int fac = 1;
    for (int i = 0; i < n; i++) v[i] = i + 1, fac *= (i + 1);
    double sum = 0;
    do {
        for (int i = 0; i < n - 1; i++) {
            double dx = x[v[i]] - x[v[i + 1]];
            double dy = y[v[i]] - y[v[i + 1]];
            sum += sqrt(dx * dx + dy * dy);
        }
    } while (next_permutation(all(v)));
    cout << fixed << setprecision(10) << sum / fac << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long x = sc.nextLong();
		long a = x;
		long b = n - x;
		long ans = 0;
		while(a > 0 && b > 0) {
			if (a <= b) {
				long r = b % a;
				ans += (b - r) * 3;
				b = r;
			}else{
				long r = a % b;
				ans += (a - r) * 3;
				a = r;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 10192
n, m = [int(i) for i in input().split()]

matrix = []
for ni in range(n):
    matrix.append([int(a) for a in input().split()])

vector = []
for mi in range(m):
    vector.append(int(input()))

for ni in range(n):
    sum = 0
    for mi in range(m):
        sum += matrix[ni][mi] * vector[mi]

    print(sum)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/4
#define MAX_N 1000000001

int main(){
    cin.sync_with_stdio(false);
    int n, m, r;
    while(cin >> n >> m, n | m) {
        int d[n][n][2];
        rep(i, n)rep(j, n) d[i][j][0] = d[i][j][1] = (i != j) ? INF : 0;

        map<int, int> sea;
        int cnt = 0;
        rep(i, m) {
            int x, y, t;
            char sl;
            cin >> x >> y >> t >> sl; x--, y--;
            if (t < d[x][y][sl == 'S']) d[x][y][sl == 'S'] = d[y][x][sl == 'S'] = t;
            if (sl == 'S') {
                if (!sea.count(x)) sea[x] = cnt++;
                if (!sea.count(y)) sea[y] = cnt++;
            }
        }

        cin >> r;
        vector<int> z(r);
        rep(i, r) cin >> z[i], z[i]--;

        rep(i, n)rep(j, n)rep(k, n) {
            minch(d[j][k][0], d[j][i][0] + d[i][k][0]);
            minch(d[j][k][1], d[j][i][1] + d[i][k][1]);
        }

        if (cnt > 0) {
            int dp[r][cnt];
            rep(i, r)rep(j, cnt) dp[i][j] = INF;
            dp[0][sea[z[0]]] = 0;
            repl(i, 1, r) {
                each(j, sea) {
                    minch(dp[i][j.se], dp[i - 1][j.se] + d[z[i - 1]][z[i]][0]);
                    each(k, sea) {
                        minch(dp[i][j.se], dp[i - 1][k.se] + d[z[i - 1]][k.fi][0] + d[k.fi][j.fi][1] + d[j.fi][z[i]][0]);
                    }
                }
            }
            int ans = INF;
            rep(i, cnt) minch(ans, dp[r - 1][i]);
            cout << ans << endl;
        } else {
            int ans = 0;
            rep(i, r - 1) {
                ans += d[z[i]][z[i + 1]][0];
            }
            cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
int main() {
    
	int n , k , total=1 ;
	
	cin >> n >> k ;
	
	while(n--)
	{
	    if(total*2>(total+k)) total+=k;
	    else total<<=1 ;
	}
	
	cout<<total;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
long long N;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int N, M, K; cin >> N >> M >> K; ll ans = 0;
  COMinit();
  for(int i=1; i<=M-1; i++){
    ans+=(M-i)%mod*N%mod*N%mod*COM(N*M-2, K-2)%mod*i%mod;
    ans%=mod;
  }
  for(int i=1; i<=N-1; i++){
    ans+=(N-i)%mod*M%mod*M%mod*COM(N*M-2, K-2)%mod*i%mod;
    ans%=mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 27076
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;

ul binpow(ul n, ul x, ul mod)
{
  ul tgt = 1;
  ul dig = n;
  while (x > 0) {
    if (x%2) {
      tgt = (tgt * dig) % mod;
    }
    dig = (dig * dig) % mod;
    x /= 2;
  }
  return tgt;
}

class Comb
{
public:
  ul mod;
  vector< ul > fact;
  vector< ul > factf;
  void init(ul size, ul imod) {
    mod = imod;
    fact.resize(size+1);
    factf.resize(size+1);
    fact[0] = 1;
    factf[0] = 1;
    for (ul i = 1; i <= size; ++i) {
      fact[i] = fact[i-1]*i%mod;
      factf[i] = binpow(fact[i], mod-2, mod);
    }
  }
  ul comb(ul n, ul k) {
    if (n<k) return 0;
    if (k==0 || n==k) return 1;
    return ((fact[n] * factf[k]) % mod * factf[n-k]) % mod;
  }
};

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  Comb comb;
  comb.init(2e5, 1e9+7);

  int n, m, k;
  cin >> n >> m >> k;
  ul ans = 0;
  ul line = 0;
  for (int i=0; i<n; ++i) {
    ul left = 0;
    for (int j=0; j<m; ++j) {
      left += j;
      ul cur = j*(j+1)/2 + (m-j-1)*(m-j)/2;
      if (i>0) {
        cur = (cur+m + (cur + m*i))*i/2;
      } else {
        cur = 0;
      }
      ans += cur + left;
      ans %= 1000000007;
    }
  }
  cout << ans * comb.comb(n*m-2, k-2) % 1000000007 << endl;
  return 0;
}


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


void solve(std::string S, std::string T){
    int cnt = 0;
    for (int i=0; i<S.size(); i++) {
        if (S[i] != T[i]) {
            cnt++;
        }
    }
    printf("%d\n", cnt);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}

Measured memory_bytes: 4188
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Train
            var line = ReadLine();
            int n = line[0];
            int i = line[1];

            Console.WriteLine(n - i + 1);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine().TrimEnd();
            var array = line.Split(' ');
            var numbers = new List<int>();

            foreach (var s in array)
            {
                int num = int.Parse(s);
                numbers.Add(num);
            }

            return numbers;
        }
    }
}

Measured memory_bytes: 13140
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

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

int cal(int n){ //·µ»ØµÄÊÇÒò×Ó×ÜÊý
    int count=2;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){
            if(i==sqrt(n) && n/i==i){ //Èç¹ûÁ½Òò×ÓÏàÍ¬£¬ÔòÖ»¼Ó1
                 count++;   
            }
            else count+=2;
        }
    }
    return count;
}

const int MAXN  = 200+10;
int ans[MAXN];

int main(){
	int cur = 0;
	for(int i=1;i<MAXN;i++){
		if(cal(i)==8&&i%2==1){
			cur++;
		}
		ans[i] = cur;
	}
	int T = 0;
	scanf("%d",&T);
	printf("%d\n",ans[T]);
	return 0;
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

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

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    string s, t;
    cin >> s >> t;

    if (s[0] == t[2] && s[2] == t[0] && s[1] == t[1])
        cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }
}


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

for i in range(n):
    x.append(input().rstrip())
for i in range(m):
    y.append(input().rstrip())

for i in range(n-m+1):
    for j in range(n-m+1):
        z = True
        for k in range(m):
            for l in range(m):
                if x[i+k][j+l] != y[k][l]:
                    z = False
                    break
            if not z: break
        if z:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3064
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

d = {i:[] for i in range(K)}
score = {"r":P, "s":R, "p":S}

for i in range(len(T)):
    d[i%K].append(T[i])
  
ans = 0
cnt = 1
for val in d.values():
    cnt = 1
    for i in range(len(val)-1):
        if(val[i] == val[i+1]):
            cnt += 1
            
        else:
            if(cnt > 1):
                if(cnt%2 == 0):
                    ans += score[val[i]]*(cnt//2)
                    cnt = 1
                else:
                    ans += score[val[i]]*(cnt//2+1)
                    cnt = 1
            else:
                ans += score[val[i]]
    if(cnt > 1):
        if(cnt%2 == 0):
            ans += score[val[i]]*(cnt//2)
        else:
            ans += score[val[i]]*(cnt//2+1)
    
    else:
        ans += score[val[-1]]
    
print(ans)

Measured memory_bytes: 25008
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,x;
  cin >> n >> x;
  vec m(n);
  for(ll i=0;i<n;i++)cin >> m[i];

  sort(m.begin(),m.end());
  ll s=0;
  for(ll i=0;i<n;i++)s+=m[i];
  ll ans=(x-s)/m[0]+n;
  cout << ans << endl;

}

Measured memory_bytes: 3628
import queue
K = int(input())
q = queue.Queue()
for k in range(1,10):
    q.put(k)

for k in range(K):
    p = q.get()
    if p %10 != 0:
        q.put(10*p + p%10 -1)
    q.put(10*p + p%10)
    if p % 10 != 9:
        q.put(p*10 +p%10 +1)
    
print(p)

Measured memory_bytes: 57428
use proconio::input;
fn main() {
    input!(n: usize);
    if n % 10 == 3 {
        println!("bon");
    } else if n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8 {
        println!("pon");
    } else {
        println!("hon");
    }
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 100000000711111111ll
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<*it.F<<' '<<*it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
ll nCrModp(ll n,ll r,ll p=MOD)
{ll C[r+1];memset(C,0,sizeof(C));C[0]=1;for(ll i=1;i<=n;i++)
{for(ll j=min(i,r);j>0;j--)
C[j]=(C[j]+C[j-1])%p;}
return C[r];}
ll ans = 0;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m;
    cin>>n>>m;
    cout<<nCrModp(n,2) + nCrModp(m,2);
    

    return 0;
}







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

int main(){
  int K; cin >> K;
  vector<int> ans = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << ans[K - 1] << endl;
}


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

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    cout<<a[n/2]-a[n/2-1]<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
	int n,q;
	scanf("%d %d\n",&n,&q);
	char s[n];
	scanf("%s",s);
	int i=0;
	int h[n];
	h[0]=0;
	for(i=0;i<n-1;i++){
		if(s[i]=='A'&&s[i+1]=='C') h[i+1] = 1+h[i];
		else h[i+1]=h[i];
	}
	for(i=0;i<q;i++){
		int l,r;
		scanf("%d %d\n",&l,&r);
		int k=h[r-1]-h[l-1];
		printf("%d\n",k);
	}
	return 0;
}

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

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

    if (x == 7 || x == 5 || x == 3)
        puts("YES");
    else puts("NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

vector<vector<edge>> g;

vector<bool> see;


int main() {

	ll R, G;
	cin >> R >> G;

	cout << G * 2 - R;
	
	system("PAUSE");

	

}


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

int main(void){
    int n, d, x, y, ans=0;
    cin >> n >> d;
    for (size_t i = 0; i < n; i++)
    {
        cin >> x >> y;
        if (sqrt(pow(x,2)+pow(y,2)) <= d){
            ans++;
        }
    }
    cout << ans;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++) cin >> a[i];
	long long l=-10000000000, r=10000000000, m=(l+r)/2;
	long long cnt=LLONG_MAX, last, t, t1;
	while(l<=r){
		//cout << m << endl;
		t=t1=0;
		for(int i=0; i<n; i++){
			t+=abs(a[i]-((l+m)/2+i+1));
			t1+=abs(a[i]-((m+r)/2+i+1));
			//cnt+=abs(a[i]-(m+i+1));
		}
		cnt=min(cnt, min(t, t1));
		if(t==t1){
			l=(l+m)/2+1;
			r=(r+m)/2-1;
		}
		else if(t<t1){
			r=(r+m)/2-1;
		}
		else l=(l+m)/2+1;
		m=(l+r)/2;
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
using namespace std;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    
    vector<int> f(26, 0);

    for(int i = 0; i < n; i += 1) {
        f[s[i] - 'a'] += 1;
    }
    
    int ans = 1;

    for(int i = 0; i < 26; i += 1) {
        ans = 1LL * ans * (f[i] + 1) % MOD;
    }
    
    ans -= 1;
    if(ans < 0)
        ans += MOD;
    cout << ans << "\n";
}

Measured memory_bytes: 512
n = int(input())
a = [[0]*n for i in range(n)]
  
for i in range(n):
    v = list(map(int, input().split()))
    u = v[0]
    k = v[1]
    for j in range(k):
        a[u - 1][v[2 + j] - 1] = 1

d = [0] * n
f = [0] * n
isDiscovered = [False] * n
time_stamp = 0

def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp = time_stamp + 1
    d[x] = time_stamp
    for i in range(n):
        if a[x][i] == 1 and isDiscovered[i] == False:
            dfs(i)
    time_stamp = time_stamp + 1
    f[x] = time_stamp

for i in range(n):
    if isDiscovered[i] == False:
        dfs(i)

for i in range(n):
    print(i+1, d[i], f[i])

Measured memory_bytes: 5796
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	
		for(int i=0;i<5;i++) {
			int a = sc.nextInt();
		     if(a==0) {
		    	 System.out.println(i+1);
		    	 return;
		     }
		}
		

	}

}


Measured memory_bytes: 35628
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
typedef pair<int, int>P;

int main() {
	int m;
	while (cin >> m, m) {
		vector<P>v;
		set<P>s;
		for (int i = 0;i < m;i++) {
			int a, b;
			cin >> a >> b;
			v.push_back(make_pair(a, b));
		}
		int n;
		cin >> n;
		for (int i = 0;i < n;i++) {
			int a, b;
			cin >> a >> b;
			s.insert(make_pair(a, b));
		}

		sort(v.begin(), v.end());
		P ans = make_pair(0, 0);

		for (auto itr = s.begin();itr != s.end();itr++) {
			P dif;
			dif.first = (*itr).first - v[0].first;
			dif.second = (*itr).second - v[0].second;
			int c = 1;
			for (int i = 1;i < m;i++) {
				P a = make_pair(v[i].first + dif.first, v[i].second + dif.second);
				auto it = s.find(a);
				if (it != s.end())c++;
			}
			ans = dif;
			if (c == m)break;
		}
		cout << ans.first << ' ' << ans.second << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
int n;
char in[M];
int main()
{
    while (~scanf("%s", in+1)) {
        n = strlen(in+1);

        int c0=0, c1=0;
        REP(i,1,n) {
            if (in[i]=='0') c0++;
            else c1++;
        }
        printf("%d\n", min(c0, c1)*2);
    }
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int m=s.length();
  string sub="";
  string ans="...";
  if(m>n){
    for(int i=0;i<n;i++) sub+=s[i];
  }
  if(m>n)
  cout<<sub+ans<<endl;
  else
    cout<<s<<endl;
  return 0;
}


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

#define ll long long
#define pb push_back


int main() {
	int n;
	cin >> n;
	vector<int> v;
	long long ans = 0;
	for (int i = 0; i < n; i++){
		int a;
		cin >> a;
		v.pb(a);
	}
	for(int j = 1; j < n; j++){
		if (v[j] < v[j - 1]){
			ans += v[j - 1] - v[j];
			v[j] = v[j - 1];
		}
	}
	cout << ans;
}


Measured memory_bytes: 4292
program ABC152B
    implicit none
    integer(8)::a,b,i
    read(5,*)a,b

    if(a<b)then
        do i=1,b
            write(*,fmt='(i0)',advance='no')a
        end do
        print'(A)',""
    else
        do i=1,a
            write(*,fmt='(i0)',advance='no')b
        end do
        print'(A)',""
    end if
end program ABC152B

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
int d;
cin >>d ;
if(d==25)cout << "Christmas";
else if(d==24) cout << "Christmas Eve";
else if(d==23) cout << "Christmas Eve Eve";
else cout << "Christmas Eve Eve Eve";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;
ll a[100005];
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    cin >> a[i];
    ll mins = 2, maxs = 2;
    bool flag = true;
    for(int i = n; i >= 1; i--)
    {
        bool ok = false;
        if(maxs < a[i])flag = false;
        if(maxs/a[i] != mins/a[i] || mins%a[i] == 0 || maxs%a[i] == 0)
        {
            ll x = mins, y = maxs;
            ll chang = y-y%a[i]-x;
            ll sum = chang/a[i];
            mins = y-y%a[i]-sum*a[i];
            maxs = y-y%a[i]+a[i]-1;
            ok = true;
        }
        if(!ok)flag = false;
        if(!flag)break;
    }
    if(flag)
    {
        cout << mins << ' ' << maxs << endl;
    }
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 1024
n=int(input())
M=[]
A=[]
R=[]
C=[]
H=[]
for i in range(n):
    S=input()
    if S[0]=='M':
        M.append(S)
    elif S[0]=='A':
        A.append(S)
    elif S[0]=='R':
        R.append(S)
    elif S[0]=='C':
        C.append(S)
    elif S[0]=='H':
        H.append(S)
score=[]
if len(M)!=0:
    score.append(len(M))
if len(A)!=0:
    score.append(len(A))
if len(R)!=0:
    score.append(len(R))
if len(C)!=0:
    score.append(len(C))
if len(H)!=0:
    score.append(len(H))

l=len(score)
if l==3:
    print(score[0]*score[1]*score[2])
elif l<=2:
    print(0)
elif l==4:
    k=score[0]*score[1]*score[2]*score[3]
    ans=0
    for i in range(4):
        ans+=k//score[i]
    print(ans)
else:
    k=score[0]*score[1]*score[2]*score[3]*score[4]
    ans=0
    for i in range(4):
        for j in range(i+1,5):
            ans+=k//(score[i]*score[j])
    print(ans)

Measured memory_bytes: 10096
import math
import sys

def findFactors(n):
    now=n
    f=[]
    while now%2==0:
        now//=2
        f.append(2)
    p=3
    while p<=math.sqrt(n):
        while now%p==0:
            now//=p
            f.append(p)
        p+=2
        if now==1:
            break
    if now>math.sqrt(n):
        f.append(now)
    return f

def cmb(n,r):
    if (r<0 or r>n):
        return 0
    r=min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod

mod=10**9+7
N=10**5+100
g1=[1,1]
g2=[1,1]
inverse=[0,1]

#n!とその逆元を求めておく
for i in range(2,N+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)

n,m=map(int,input().split())
if m==1:
    print(1)
    sys.exit()

F=findFactors(m)
ans=1

now=F[0]
cnt=0
for f in F:
    if f==now:
        cnt+=1
    else:
        ans*=cmb(n-1+cnt,cnt)
        ans%=mod
        now=f
        cnt=1
ans*=cmb(n-1+cnt,cnt)
ans%=mod
print(ans)

Measured memory_bytes: 15124
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

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

    if (N == 100) {
        N++;
    }
    if (D == 0) {
        std::cout << N << std::endl;
    }
    else if (D == 1) {
        std::cout << N * 100LL << std::endl;
    }
    else if (D == 2) {
        std::cout << N * 10000LL << std::endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int((x).size()))
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
template<typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); }
template<typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); }
typedef long long ll;

int n;
std::string s;

int main() {
    std::cin >> s;
    n = sz(s);
    if (((s[0] == s[n-1] ? 1 : 0) + (n%2)) % 2) printf("First\n");
    else printf("Second\n");
}


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

int main() {
	int h, n; cin >> h >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		sum += a;
	}
	if (sum >= h) cout << "Yes";
	else cout << "No";
	cout << endl;
}

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

pf_list = []
pf_list.append(n//2+ n//4+ n//8+ n//16+ n//32+ n//64)
pf_list.append(n//3+ n//9+ n//27+ n//81)
pf_list.append(n//5+ n//25)
pf_list.append(n//7+ n//49)
pf_list.append(n//11); pf_list.append(n//13); pf_list.append(n//17); pf_list.append(n//19)
pf_list.append(n//23); pf_list.append(n//29); pf_list.append(n//31); pf_list.append(n//37)
pf_list.append(n//41); pf_list.append(n//43); pf_list.append(n//47)


a = [1 if i >= 74 else 0 for i in pf_list]
b = [1 if i >= 24 else 0 for i in pf_list]
c = [1 if i >= 14 else 0 for i in pf_list]
d = [1 if i >= 4 else 0 for i in pf_list]
e = [1 if i >= 2 else 0 for i in pf_list]

ans = 0
for i in range(15):
    for j in range(15):
        if i == j:
            continue
        for k in range(j):
            if i == k:
                continue
            ans += e[i]*d[j]*d[k]
for i in range(15):
    for j in range(15):
        if i == j:
            continue
        ans += e[i]*b[j]
for i in range(15):
    for j in range(15):
        if i == j:
            continue
        ans += d[i]*c[j]
for i in range(15):
    ans += a[i]

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    void solve(){  
        int n;
        cin>>n;
        vector<ll>a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        vector<ll>pref(n+1);
        for(int i=n-1;i>=0;i--){
            pref[i]=pref[i+1]+a[i];
        }
        ll ans=0;
        for(int i=0;i<n;i++){
            ans=add(ans,mul(a[i],pref[i+1]));
        }
        cout<<ans;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Measured memory_bytes: 6364
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

vector<int> ra(MX,0);
vector<int> par(MX,0);
using P = pair<int, int>;
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

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

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

signed main(){
    string s;
    cin >> s;
    string a = s.substr(0,s.length()/2);
    string b = s.substr(s.length()/2+1);
    //cout << a<<" " <<b << endl;
    bool f = true;
    rep(i,s.length()/2) {
        int j = s.length()-1-i;
        if(s[i]!=s[j]) f = false;    
    }
    rep(i,a.length()/2) {
        int j = a.length()-1-i;
        if(a[i]!=a[j]) f = false;
    }

    rep(i,b.length()/2) {
        int j = b.length()-1-i;
        if(b[i]!=b[j]) f = false;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 8064
object Main extends App {
  val n = io.StdIn.readLine()
  val p = io.StdIn.readLine().split(" ").map(_.toInt)
  val pSize = p.size
  val maxIndex = pSize - 1
  var startIndex = 0
  var result = 0
  while (startIndex + 2 <= maxIndex) {
    val i1 = p(startIndex)
    val i2 = p(startIndex + 1)
    val i3 = p(startIndex + 2)
    if ((i1 <= i2) && (i2 < i3)) result += 1
    else if ((i3 <= i2) && (i2 < i1)) result += 1
    startIndex += 1
  }
  println(result)
}

Measured memory_bytes: 25500
prime = [2]
def check(x):
    for i in prime:
        if x % i ==0:
            return False
        elif x < i * i:
            break
    return True

def set():
    for i in range(3,10**5,2):
        if check(i):
            prime.append(i)


set()
#print('ok')
#print(prime)
p,q = [int(i) for i in input().split(' ')]
if q % p == 0:
    q = q //p
    p = 1
for i in prime:
    while True:
        if p % i ==0 and q % i == 0:
            p = p // i
            q = q // i
            #print(p,q,i)
        else:
            break
 
ans = 1
#print(p,q)
for i in prime:
    if q % i == 0:
#        print(q,i)
        q = q // i
        ans *= i
        while q % i ==0:
            q = q // i
            
ans *= q
    

print(ans)



Measured memory_bytes: 5772