akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int tmp,count = 0;

	for(int i = 0; i < 3; i++){

		scanf("%d",&tmp);
		if(tmp%2 == 1){

			count++;
		}
	}

	if(count >= 2){

		printf("Hom\n");

	}else{

		printf("Tem\n");
	}

	return 0;
}



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

x = dict()
for i in input().split():
    x[i] = x.get(i, 0) + 1

m = int(input())

for i in input().split():
    if i not in x or x[i] == 0:
        print("NO")
        exit()
    else:
        x[i] -= 1
print("YES")

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

int main(void) {
  int N;
  cin >> N;

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

  sort(a, a + N, greater<int>());

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      ans += a[i];
    } else {
      ans -= a[i];
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 long double a,b,c;
 cin>>a>>b>>c;
 long double eps = 1e-15;
 if( sqrt(a) + sqrt(b) + eps< sqrt(c) ){
  cout<<"Yes"<<endl;
 }else{
  cout<<"No"<<endl;
 }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;int ans1=0,ans2=0;
	for(int i=0;i<s.size();i++)
	{ 
	  if(i%2==0)
	    {if(s[i]=='0')ans1++;
		  else ans2++;
  }
	  else 
	  {
        if(s[i]=='1')ans1++;
          else ans2++;
	}}
	cout<<min(ans1,ans2);
	return 0;
} 

Measured memory_bytes: 512
n, m = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i)
if m <= n
  puts "0"
else
  x.sort!
  d = []
  x.each_cons(2) do |i, j|
    d << j - i
  end
  d.sort!
  puts d[0..(m - n - 1)].inject(:+) || 0
end

Measured memory_bytes: 10608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#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()

int main(){
    string s;
    cin>>s;
    cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
}

Measured memory_bytes: 256
main :: IO ()
main = do
  [a, b] <- fmap words getLine
  let inta = read a :: Int  
  let intb = read b :: Int

  putStrLn $ compare' inta intb

compare' :: Int -> Int -> String
compare' a b | a < b = "a < b"
             | a > b = "a > b"
             | otherwise = "a == b"

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
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; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
}c(200005);


//m^n
mint f(int m, int n) {
	if (0 == n) {
		return 1;
	}
	mint x = f(m, n / 2);
	x *= x;
	if (1 == n % 2) {
		x *= (mint)m;
	}
	return x;
}
// nCa
mint choose(int n, int a) {
	mint x = 1;
	mint y = 1;
	for (int m = 0; m < a; ++m) {
		x *= (mint)(n - m);
		y *= (mint)(a - m);
	}
	return x / y;
}
// nPk
mint nPk(int n, int a) {
	mint ret = choose(n, a);
	for (int n = 1; n <= a; ++n) {
		ret *= n;
	}
	return ret;
}


int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	mint sum = 0;
	mint ans = 0;
	mint sum2 = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		sum += (mint)A[i];
		sum2 += (mint)A[i] * A[i];
	}
	sum = sum * sum;
	sum -= sum2;
	sum /= 2;
	cout << sum << endl;
	return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    char grid[100][100];
    for(int i = 0; i < 50; i++){
        for(int j = 0; j < 100; j++){
            grid[i][j] = '#';
        }
    }
    for(int i = 50; i < 100; i++){
        for(int j = 0; j < 100; j++){
            grid[i][j] = '.';
        }
    }
    for(int i = 0; i < a - 1; i++){
        grid[2 * (i / 50)][2 * (i % 50)] = '.';
    }
    for(int i = 0; i < b - 1; i++){
        grid[99 - 2 * (i / 50)][99 - 2 * (i % 50)] = '#';
    }
    cout << 100 << " " << 100 << endl;
    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){
            cout << grid[i][j];
        }
        cout << endl;
    }
}

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

struct Data{
  string name;
  int win;
  int lose;
};

vector<Data> team;

bool comp(const Data& d1, const Data& d2){
  if(d1.win == d2.win) return (d1.lose < d2.lose);
  return (d1.win > d2.win);
}

int main(void){
  int n;
  while(cin >> n, n != 0){
    team.clear();
    for(int i = 0; i < n; i++){
      Data t;
      cin >> t.name;
      t.win = 0; t.lose = 0;
      for(int j = 0; j < n - 1; j++){
        int res;  cin >> res;
        if(res == 0) t.win++;
        if(res == 1) t.lose++;
      }
      team.push_back(t);
    }
    sort(team.begin(), team.end(), comp);
    for(int i = 0; i < team.size(); i++){
      cout << team[i].name << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const long long inf=6000000000000000000ll;
int Q,n,m,D,c[27],a[N][27],t[N],as[N],su[27],ans,i,j,x,y,s=-1000000000;
set<int> p[27];
int cal(int x,int y)
{
	int sum=ans;
	sum-=a[x][t[x]];
	sum+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	sum+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	it=p[y].lower_bound(x);
	e=it;
	--e;
	sum-=c[y]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	return sum;
}
void Change(int x,int y)
{
	ans-=a[x][t[x]];
	ans+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	ans+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	p[t[x]].erase(x);
	t[x]=y;
	p[t[x]].insert(x);
	it=p[t[x]].find(x);
	e=it;
	--e;
	++it;
	ans-=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
}
void up()
{
	if(s<ans)
	{
		s=ans;
		for(int i=1;i<=D;++i)
			as[i]=t[i];
	}
}
mt19937 rnd(time(0));
double rand_f() {return double(rnd())/double(RAND_MAX);}
int u=0;
void SA()
{
	double T=500;
	while(T>0.001)
	{
		int a=rnd()%D+1,b=rnd()%26+1;
		while(b==t[a])
			b=rnd()%26+1;
		int tmp=cal(a,b);
		if(tmp>ans||rand_f()<exp((tmp-ans)/T))
		{
			Change(a,b);
			up();
		}
		T=T*0.999;
	}
	//cout<<s<<' '<<ans<<endl;
}
void Find()
{
	int i,j;
	for(i=1;i<=26;++i)
	{
		p[i].clear(); 
		p[i].insert(D+1);
		p[i].insert(0);
	}
	memset(su,0,sizeof(su));
	ans=0;
	for(i=1;i<=D;++i)
	{
		for(j=1;j<=26;++j)
			++su[j];
		t[i]=1;
		for(j=2;j<=26;++j)
			if(su[t[i]]*c[t[i]]+a[i][t[i]]<su[j]*c[j]+a[i][j])
				t[i]=j;
		ans+=a[i][t[i]];
		su[t[i]]=0;
		for(j=1;j<=26;++j)
			ans-=su[j]*c[j];
		p[t[i]].insert(i);
		//as[i]=t[i];
	}
}
int main()
{
	scanf("%d",&D);
	for(i=1;i<=26;++i)
		scanf("%d",&c[i]);
	for(i=1;i<=D;++i)
		for(j=1;j<=26;++j)
			scanf("%d",&a[i][j]);
	Find();
	up();
	while(1.0*clock()/CLOCKS_PER_SEC<1.85)
	{
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		//Find();
		//up();
		//cout<<'?'<<' '<<s<<' '<<ans<<endl;
	}
	for(i=1;i<=D;++i)
	{
		cout<<as[i]<<endl;
		assert(as[i]>=1&&as[i]<=26);
	}
}

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

typedef long long ll;

ll mod = 8589934609ll;

ll mul(ll x,ll y) { // x * y
    ll res =  (x*(y>>30))%mod;

    res = (res<<15)%mod;
    res = (res<<15)%mod;
    res += x*(((y>>30)<<30)^y);
    res %= mod;
    return res;
}

ll powmod(ll x,ll p) {
    if(p == 0) return 1;
    if(p == 1) return x;

    if(p%2) return mul(x,powmod(x,p-1));
    else return powmod(mul(x,x),p/2);
}

ll modInverse(ll x) { // x^(mod-2)
    return powmod(x,mod-2);
}

int main() {
    int n,o,y;
    ll ans = 0;
    cin>>n;


    for(int i=0; i<n; ++i) {
        cin>>o>>y;

        switch(o) {
        case 1:
            ans += y;
            ans %= mod;
            break;
        case 2:
            ans -= y;
            ans = (ans+mod)%mod;
            break;
        case 3:
            ans = mul(ans,y);
            break;
        case 4:
            ans = mul(ans,modInverse(y));
            break;
        }
    }

    if(ans >= 1ll<<31) ans -= mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 848
S = input()

reversedS = S[::-1]

str1 = S[:int((len(S)-1)/2)]
reversedStr1 = str1[::-1]

str2 = S[int((len(S)+3)/2)-1:]
reversedStr2 = str2[::-1]

flag = False
if S == reversedS:
  if str1 == reversedStr1:
    if str2 == reversedStr2:
      print('Yes')
      flag = True
      
if flag == False:
  print('No')



Measured memory_bytes: 3064
H,W,D = map(int,input().split())
P = [None]*(H*W+1)

for h in range(H):
  A = list(map(int,input().split()))
  for w in range(W):
    P[A[w]] = [h,w]

B = [0]*(H*W+1)

for n in range(D+1,H*W+1):
  B[n] = B[n-D]+abs(P[n][0]-P[n-D][0])+abs(P[n][1]-P[n-D][1])

Q = int(input())
ans = 0
for q in range(Q):
  L,R = map(int,input().split())
  print(B[R]-B[L])

Measured memory_bytes: 20524
n, y = map(int, input().split())

for a in range(0, n + 1):
    for b in range(0, n + 1 - a):
        c = n - a - b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(a, b, c)
            exit()
print(-1, -1, -1)


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

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define LOOP(N) for(int i=(int)(N); i--;)
#define REP(i, N) for(int i=0; i<(N); ++i)
#define FOR(i, start, end) for(int i=(int)(start); i<(end); ++i)
#define ALL(a) (a).begin(),(a).end()

class FastIO {
public:
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
    }
    ~FastIO() {}

    template <class T>
    void scan(T &v) {
        cin >> v;
    }
    template <class T, class... Rest>
    void scan(T &v, Rest&... rest) {
        scan(v);
        scan(rest...);
    }

    template <class T>
    void print(T v) {
        cout << v;
    }
    template <class T, class... Rest>
    void print(T v, Rest... rest) {
        print(v);
        print(" ");
        print(rest...);
    }
    template <class T>
    void print(vector<T> v) {
        for (T t: v) {
            print(t);
            print(" ");
        }
        print("\b\n");
    }
    template <class T>
    void prints(T v) {
        print(v);
        cout << "\n";
    }
};

void _main(FastIO&);
int main() {
    FastIO io;
    _main(io);
}



void _main(FastIO &io) {
    int N, W; io.scan(N, W);
    vector<int> w(N+1), v(N+1);
    REP(i, N) {
        io.scan(w[i+1], v[i+1]);
    }
    
    vector< vector<ll> > value(N+1, vector<ll>(W+1));
    REP(i, W+1) {
        value[0][i] = 0;
    }
    FOR(i, 1, N+1) {
        REP(j, w[i]) {
            value[i][j] = value[i-1][j];
        }
        FOR(j, w[i], W+1) {
            value[i][j] = max(value[i-1][j], value[i-1][j-w[i]] + v[i]);
        }
    }
    io.print(value[N][W]);
}

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

using namespace std;
int main() {
  string s;
  cin >> s;
  if (s == "Sunny")
    cout << "Cloudy" << endl;
  else if (s == "Cloudy")
    cout << "Rainy" << endl;
  else if (s == "Rainy")
    cout << "Sunny" << endl;
  return 0;
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

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

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

bool used[113];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a;
	cin>>n>>a;
	cout<<n*n-a<<'\n';
	return 0;
}


Measured memory_bytes: 256
from itertools import permutations

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))


l = []
for pp in permutations(range(1,n+1)):
	l.append(list(pp))

a = l.index(p)
b = l.index(q)
print(abs(a - b))




Measured memory_bytes: 10228
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  set<char> st;
  for (int i = 0; i < N; i++)
  {
    char s;
    cin >> s;
    st.insert(s);
  }
  if (st.size() == 3)
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a==1)a=14;
  if(b==1)b=14;
  if(a>b)printf("Alice");
  else if(a==b)printf("Draw");
  else printf("Bob");
  return 0;
}


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

int main() 
{
  int n;
  cin >> n;
  int m500 = n / 500;
  n = n % 500;
  int m5 = n / 5;
  long long sum = m500*1000 + m5*5;
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	string s; cin >> s; int t = s.length(); int a[26] = {0};
	bool flag = true;
	if(t < 26){
		flag = false;
		Rep(i, t){
			int k = s[i] - 'a';
			a[k] += 1;
		}
		Rep(i, 26){
			if(a[i] == 0){
				char k = 'a' + i;
				string l; l = k;
				s += l;
				break;
			}
		}
		cout << s << endl;
	}else if(s == "zyxwvutsrqponmlkjihgfedcba"){
		cout<<-1<<endl;
	}else{
		string k = s, r;
		next_permutation(s.begin(), s.end());
		Rep(i, 26){
			r += s[i];
			if(k[i] != s[i]) break;
		}
		cout << r << endl;
	}
}

Measured memory_bytes: 764
#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()

int main(){
  ll n, Ma,Mb; cin >> n >> Ma >> Mb;
  vector<ll> t(n), c(n);
  REP(i,n){
    ll a,b; cin >> a >> b >> c[i];
    t[i] = Mb*a-Ma*b; 
  }
  //dp[i][j]:i番目までみてtiの和がj-4000となる場合のコストの最小値
  const ll INF = 10000;
  vector<vector<ll>> dp(n+1, vector<ll>(8001,INF));
  REP(i,n) dp[i+1][t[i]+4000] = c[i];

  FOR(i,1,n) REP(j,8001) if(dp[i][j] != INF){
    dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    dp[i+1][j+t[i]] = min(dp[i+1][j+t[i]], dp[i][j] + c[i]);
  }
  if(dp[n][4000] == INF) cout << -1 << endl;
  else cout << dp[n][4000] << endl;
}



Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int n;
    cin>>n;
    vector<long long>l(87);
    l[0]=2;
    l[1]=1;
    for(int i=2;i<87;i++)l[i]=l[i-1]+l[i-2];
    cout<<l[n];
	return 0;
}


Measured memory_bytes: 3576
import sys
sys.setrecursionlimit(10**9)

s = input()

K = float('inf')
if all(c == '0' for c in s):
    K = len(s)
elif all(c == '1' for c in s):
    K = len(s)
else:
    for k in range(1, len(s)):
        if s[k] != s[k-1]:
            K = min(K, max(k, len(s)-k))
        else:
            continue

print(K)


Measured memory_bytes: 3188
# coding: utf-8


def main():
    N, K = map(int, input().split())
    d = [None] * K
    A = [None] * K

    for i in range(K):
        d[i] = int(input())
        A[i] = list(map(int, input().split()))
        A[i] = [x-1 for x in A[i]]
    
    have = [0] * N
    for a in A:
        for x in a:
            have[x] += 1
    
    ans = 0
    for i in range(N):
        if have[i] == 0:
            ans += 1
    
    return ans


print(main())


Measured memory_bytes: 9204
from sys import stdin


def main():
    n, x, y = map(int, stdin.readline().split())
    x -= 1
    y -= 1

    summary = [0] * (n - 1)
    for i in range(n):
        for j in range(i + 1, n):
            d = min(j - i, abs(i - x) + abs(j - y) + 1, abs(i - y) + abs(j - x) + 1)
            summary[d - 1] += 1
    print(*summary, sep='\n')


if __name__ == "__main__":
    main()


Measured memory_bytes: 45020
#include <bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define endl "\n"
	#define space " "
	#define ll long long int
	#define vl vector<ll>
	#define vvl vector < vll >
	#define pii pair<int,int>
	#define pll pair<ll,ll>
	#define vpl vector < pll >
	#define mod 1000000007
	#define pi 3.1415926535897932384626433
	#define inf 1000000000000000000
	#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y) 
	#define mem(a,val) memset(a,val,sizeof(a))
	#define pb push_back
	#define f first
	#define s second
	
	void solve()
	{
		ll n; cin>>n; ll a[n],r=1;
		for (ll i = 0; i < n; ++i)
		{
			/* code */
			cin>>a[i];
		}
		for (ll i = 0; i < n; ++i)
		{
			/* code */
			if(a[i]==0){
				cout<<0; return;
			}
		}
		for (ll i = 0; i < n; ++i)
		{
			/* code */
			if(a[i]>inf/r){
				cout<<-1; return;
			}
			r*=a[i];
		}
		cout<<r;
	}

	signed main()
	{

	fast;
	

	ll T=1;
	// cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
	}


Measured memory_bytes: 4436
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

p = 0
t = 0
for i in range(len(a)):
    if p > a[i]:
        add = p - a[i]
        t += add
        p = a[i] + add
    else:
        p = a[i]

print(t)


Measured memory_bytes: 32300
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int s;
  cin>>s;
  int head = s/1000 * 10 + s/100 % 10;
  int tail = ((s/10) % 10)*10 + s % 10;
  bool h_12 = (head > 0 && head < 13) ? true : false;
  bool t_12 = (tail > 0 && tail < 13) ? true : false;
  
  if(h_12 && t_12) cout<<"AMBIGUOUS"<<endl;
  else if (!(h_12 || t_12)) cout<<"NA"<<endl;
  else if(!(h_12) && t_12) cout<<"YYMM"<<endl;
  else cout<<"MMYY"<<endl;
  //cout<<head<<endl<<tail<<endl;
}



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

int main(){
  int num;
  cin >> num;
  
  int lastNum = num % 10;
  
  if(lastNum == 3){
  	cout << "bon" << endl;
  }else if(lastNum == 0 || lastNum == 1 || lastNum == 6 || lastNum == 8 ){
  	cout << "pon" << endl;
  }else{
 	cout << "hon" << endl;
  }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200020];
int main()
{
    ios::sync_with_stdio(false);
    ll k,n;cin>>k>>n;
    for(ll i=1;i<=n;i++) cin>>a[i];
    a[n+1]=k+a[1];
    ll MAX=0;
    for(ll i=2;i<=n+1;i++)
    {
        MAX=max(MAX,a[i]-a[i-1]);
    }
    cout<<k-MAX;
	return 0;
}


Measured memory_bytes: 1792
from fractions import gcd
a, b, c, d = map(int, input().split())
"""
ans: B以下の整数から条件を満たす個数　 - A-1以下の整数から条件を満たす個数
X以下の整数から条件： X - X//c -X//d + X//lcm(c,d)
"""
def count(X, t):
    return X//t
cd = c * d // gcd(c, d)
b_under = b - count(b, c) - count(b, d) + count(b, cd)
a_under = a-1 - count(a-1, c) - count(a-1, d) + count(a-1, cd)

print( b_under - a_under )

Measured memory_bytes: 5048
#[allow(dead_code)]
fn primes(num: i64) -> Vec<i64> {
    let mut ans = vec![1];
    let mut cur = num;
    for i in 2.. {
        if i * i > num { break; }
        if cur % i == 0 {
            while cur % i == 0 {
                ans.push(i);
                cur /= i;
            }
        }
    }
    if cur > 1 {
        ans.push(cur);
    }
    return ans;
}

#[test]
fn test_primes() {
    assert_eq!(primes(1), vec![1]);
    assert_eq!(primes(140), vec![1, 2, 2, 5, 7])
}

// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
test! {
r"2
" => r"1",

r"13
" => r"78",

r"1
" => r"0"
}

use proconio::{input, fastout};
use proconio::source::auto::AutoSource;
use num_integer::Integer;

fn solve(src: &str) -> String {
    let source = AutoSource::from(src);
    input! {
       from source,
       n:i64,
    }
    let n: i64 = n;

    let ans = n * (n - 1) / 2;

    format!("{}", ans)
}


#[fastout]
fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&*s));
}


Measured memory_bytes: 2200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<double> sum(N+1, 0.0);
    rep(i, N) {
        double p;
        cin >> p;
        sum[i+1] += sum[i] + (p + 1.0) / 2.0;
    }

    double ans = 0;
    rep(i, N-K+1) chmax(ans, sum[i+K] - sum[i]);
    cout.precision(20);
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int a[5] = {5,7,5,7,7};

int main(){

  int n;
  while(true){
    cin >> n;
    if(n == 0) break;

    vector<int> v;
    REP(i,n){
      string s;
      cin >> s;
      v.pb(s.length());
    }

    for(int i = 0; i < n - 4; ++i){
      int sum, j = i;
      bool tanka = true;
      for(int idx = 0; idx < 5; ++idx){
        sum = a[idx];
        while(true){
          if(sum == v[j]){
            sum = 0;
            j++;
            break;
          }else if(sum > v[j]){
            sum -= v[j];
            j++;
          }else{
            tanka = false;
            break;
          }
        }
        if(!tanka){
          break;
        }
      }
      if(tanka){
        cout << i+1 << endl;
        break;
      }

    }
  }
  return 0;
}



Measured memory_bytes: 3144
a, b, c, x, y = map(int, input().split())

res = (
    c * max(x, y) * 2,
    a*x + b*y,
    c*x*2 + b*max(y-x, 0),
    c*y*2 + a*max(x-y, 0)
)

print(min(res))

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

using namespace  std;
#define inf 999999999999999999
#define int long long 
#define N 666666
int dis[66][2600]; 
int vis[66][2600]; 
int n,m,s;

int C[N],D[N];
//*********************建图 
int head[N];
int cnt;
struct edge{
	int u;
	int v;
	int a;
	int b;
	int next;
}e[N];
void addedge(int u,int v,int a,int b){
	e[++cnt].v=v;
	e[cnt].a=a;
	e[cnt].b=b;
	e[cnt].next=head[u];
	head[u]=cnt;
}

void init(){
	for(int i=0;i<=n;i++)
		for(int j=0;j<=2555;j++)
			dis[i][j]=inf;
	return ;
}

void dij(){
	dis[1][s]=0;
	 queue<pair<int,int> > q;
	 q.push(make_pair(1,s));
	 while(!q.empty()){
	 	int u=q.front().first;
	 	int w=q.front().second;
	 	q.pop();
	 	for(int i=head[u];i;i=e[i].next){
	 		int v=e[i].v;
	 		int a=e[i].a;
	 		int b=e[i].b;
	 		if(w-a>=0&&dis[v][w-a]>dis[u][w]+b){
	 			dis[v][w-a]=min(dis[v][w-a],dis[u][w]+b);
	 			q.push(make_pair(v,w-a));
			}
		}
		if(dis[u][w]+D[u]<dis[u][min(2500*1ll,w+C[u])]){
			dis[u][min(2500*1ll,w+C[u])]=dis[u][w]+D[u];
			q.push(make_pair(u,min(2500*1ll,w+C[u])));
		}
	 }
}
signed main(){
	
	cin>>n>>m>>s;
	s=min(s,2500*1ll);
	init();
	for(int i=1;i<=m;i++){
		int a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		addedge(a,b,c,d);
		addedge(b,a,c,d);
	}
	for(int i=1;i<=n;i++) scanf("%lld%lld",&C[i],&D[i]);
	dij();
	
	for(int i=2;i<=n;i++){
		int res=inf;
		for(int j=0;j<=2500;j++) res=min(res,dis[i][j]);
		printf("%lld\n",res);
	} 
	return 0;
} 

Measured memory_bytes: 5412
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;


void solve(){
    ll n; cin >> n;
    Vl d(n);
    rep(i, 0, n) cin >> d[i];

    sort(ALL(d));

    ll ans = 0;
    Rep(i, d[d.size()/2 - 1]+1, d[d.size()/2]) ans++;

    cout << ans << endl;
}

int main() {
    solve();
}


Measured memory_bytes: 1024
N = int(input())
s_list = []
count = 0
n, m, l = 0, 0, 0
 
for i in range(N):
  s = input()
  s_list.append(s)
  count += s.count('AB')
  if s[0] == 'B' and s[-1] == 'A':
    n += 1
    continue
  elif s[-1] == 'A':
    m += 1
  elif s[0] == 'B':
    l += 1

if m == 0 and l == 0:
  if n == 0:
    print(int(count))
  else:
    print(int(count + (n - 1)))
else:
  print(int(count + min(n+m, n+l)))

Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <iomanip>
#include <bits/stdc++.h>
#include <fstream>
#include <map>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#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--)

int main(){
    string s;
    while(1){
        ll ans = 0;
        cin >> s;
        if(s == "0") break;
        REP(i, s.size()){
            ans += s[i] - '0';
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC083D {
    class Program {
        static void Main(string[] args) {
            string S = Console.ReadLine();
            int len = S.Length;
            int half = (len + 1) / 2;
            int center = (len % 2 == 0) ? len / 2 - 1 : len / 2;
            string mark = S.Substring(center, 1);
            bool ok = true;
            int i = 0;
            while (ok && half + i < len) {
                string low = (len % 2 == 0) ? S.Substring(center - i, 1) : S.Substring(center - i - 1, 1);
                string high = S.Substring(center + i + 1, 1);
                if (low != mark || high != mark) {
                    ok = false;
                } else {
                    i++;
                }
            }
            Console.WriteLine(half + i);
        }
    }
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

vector<int64_t> fct, inv;
void finit(int cmx, ll mod =MD){
	fct.resize(cmx+20); inv.resize(cmx+20);
	auto bin_pows =[](ll x, ll n, ll mod){
		ll res = 1LL;
		for(; n > 0; n >>=1, x = x*x %mod) if(n & 1) res = res * x %mod;
		return res;
	};
	fct[0] = fct[1] = inv[1] = 1;
	for(int i=2;i<cmx+3;i++) fct[i] = fct[i-1] * i % mod;
	inv[cmx] = bin_pows(fct[cmx], mod-2, mod);
	for(int i=cmx;i>=1;i--) inv[i-1] = inv[i] * i % mod;
}
ll nCk(ll n, ll k, ll mod =MD) {
	if(k > n || n <0 || k <0) return 0;
	ll ret =fct[n] * inv[k] % mod * inv[n-k] % mod;
	return ret;
}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n+1);
	rep(i, n+1) cin >>a[i];
	finit(100100);
	VI ck(n+2, -1);
	int lf=0, rg=0;
	rep(i, n+1){
		if(ck[a[i]] !=-1){
			rg = i; lf = ck[a[i]]; break;
		}
		ck[a[i]] = i;
	}
	//dbg(lf, rg);
	rep2(k, 1, n+2){
		ll ans = nCk(n+1, k);
		ans += MD - nCk(n+1 -(rg-lf+1), k-1);
		cout << ans %MD <<"\n";
	}
	return 0;
}


Measured memory_bytes: 3584
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	divider := []string{"dream", "dreamer", "erase", "eraser"}
	dp := [100000]bool{}
	dp[0] = true
	for i := range s {
		if !dp[i] {
			continue
		}
		for _, d := range divider {
			l := len(d)
			if i+l <= len(s) && s[i:i+l] == d {
				dp[i+l] = true
			}
		}
	}

	if dp[len(s)] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pll, pii> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int main() {
	ll K, A, B;
	cin >> K >> A >> B;
	
	ll ans = 1 + min(K, A - 1);
	K -= ans - 1;
	if (K & 1) {
		K--;
		ans++;
	}
	if (B - A > 1) ans += (B - A) * (K / 2);
	else ans += K;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        final long N = sc.nextLong();

        long ans = Long.MAX_VALUE;
        for (long i = 1; i <= Math.sqrt(N); i++) {
            if (i * (N / i) == N) {
                ans = Math.min(ans, i + N / i - 2);
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int n;
    cin>>n;
    for(int i=1;i<=50000;i++){
        if((i*108)/100==n){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
    
    
}


Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;



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

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(4);
	//init();
	solve();
	stop
		return 0;
}



Measured memory_bytes: 3180
import java.util.*;
 
public class Main{
  public static void main(String...args){
    Scanner s = new Scanner(System.in);
    int n = s.nextInt(); int[] x = new int[n];
    int max = 0, min = 0;
    for(int i = 0;i < n;i++){
      x[i] = s.nextInt();
      if(i == 0 || x[i] < min){ min = x[i]; }
      if(i == 0 || x[i] > max){ max = x[i]; }
    }
    int minv = 0;
    for(int i = min;i < max;i++){
      int tmp = 0;
      for(int j = 0;j < n;j++){
        tmp+=(x[j]-i)*(x[j]-i);
      }
      if(i == min || tmp < minv){minv = tmp;}
    }
    System.out.println(minv);
  }
}

Measured memory_bytes: 22868
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;
const string YES = "Yes";
const string NO = "No";

ll A;
ll B;
ll C;
ll D;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    solve();
}

// 1 <= A,B,C,D <= 100
// 入力はすべて整数である。

// ll A, ll B, ll C, ll D
// 高橋君が勝つなら Yes、負けるなら No を出力せよ。
void solve(){
    while(1){
        C-=B;
        if(C<=0){
            cout<<"Yes"<<endl;
            return;
        }
        A-=D;
        if(A<=0){
            cout<<"No"<<endl;
            return;
        }
    }
}


Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, T;
    cin >> A >> B >> T;
    int ans = 0;
    for(int i = A; i <= T; i += A) ans += B;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
L,R = list(map(int,input().split()))

dif = R - L
_L, _R = L%2019,R%2019

if _R < _L:
  print(0)
elif _L < _R and dif >= 2018: 
  print(0)
elif _L < _R and dif < 2018:
  _m = (L*(L+1)%2019)
  for i in range(L,R+1):
    for j in range(i+1,R+1):
      _m = min(_m,(i*j)%2019)
  print(_m)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define iof freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define BiEdge(v,a,b) (v)[(a)].pb((b)),(v)[(b)].pb((a))
#define ll long long
#define ld long double
#define pb push_back
#define Pb pop_back
#define F first
#define S second
#define X real()
#define Y imag()
#define pi acos(-1)
#define eps 1e-7
#define bpc __builtin_popcount
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
#define cross(a,b) (conj(a)*(b)).real()
#define dot(a,b) (conj(a)*(b)).imag()
typedef complex <ld> point ;
typedef vector <point> polygon ;
typedef tuple <ll,ll,ll> line ;
const int mod = 1e9+7 , A = 1e9+1 ;

int main()
{
	ios
	ll n ; cin >> n ;
	ll a[n] , dp[n] ;
	for (int i = 0 ; i < n ; cin >> a[i++]) ;
	dp[0] = 0 , dp[1] = abs(a[1]-a[0]) ;
	for (int i = 2 ; i < n ; i++)
		dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]) , dp[i-2] + abs(a[i] - a[i-2])) ;
	cout << dp[n-1] ;
	return 0 ;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int mod = 1e9 + 7;
string str{"AGCT"};
#define rep(i,n) for(int i = 0; i < n; ++i)
int main(){
    Int N; cin >> N;
    Int dp[106][5][5] = {0};
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < str.size(); ++j){
            for(int k = 0; k < str.size(); ++k){
                char prev = str[k];
                char lst  = str[j];
                dp[i][j][k] %= mod;
                if(i == 0 and (j == 4 or k == 4)) continue;
                Int now = ( i ? dp[i][j][k] : 1);
                if(now == 0) continue;
                if(lst == 'A' and prev == 'C'){
                    
                    rep(l,4)
                    if(str[l] != 'G')dp[i + 1][k][l] += now;
                    
                } else if(lst == 'A' and prev == 'G'){
                    
                    rep(l,4)rep(m,4){
                        if(str[m] == 'C' or str[l] == 'C') continue;
                        dp[i+2][m][l] += now;
                    }
                    dp[i+1][k][4] += now;
                    
                } else if(lst == 'G' and prev == 'A'){
                    
                    rep(l,4)
                    if(str[l] != 'C')dp[i + 1][k][l] += now;
                    
                } else if(lst == 'A' and prev == 'T'){
                    
                    rep(l,4)rep(m,4){
                        if(str[l] == 'G' and str[m] == 'C')continue;
                        dp[i+2][l][m] += now;
                    }
                    dp[i+1][3][4] += now;
                    
                }else {
                    rep(l,4)dp[i+1][k][l] += now;
                }
            }
        }
    }
    Int ans = 0;
    for(int j = 0; j < 4; ++j)
        for(int k = 0; k < 4; ++k){
            ans += dp[N-2][j][k];
            ans %= mod;
        }
    
    ans += dp[N-2][1][4] * 3;
    ans += dp[N-2][3][4] * 4;
    ans %= mod;
    cout << ans << endl;
}



Measured memory_bytes: 256
a,b,c = list(map(int,input().split()))
if a>b:
 w = a
 a = b
 b = w
if a>c:
 w = a
 a = c
 c = w
if b>c:
 w = b
 b = c
 c = w
print(f"{a} {b} {c}")



Measured memory_bytes: 5608
n,m = map(int, input().split())
ab = []
cd = []
for _ in range(n):
    ab.append(list(map(int, input().split())))

for _ in range(m):
    cd.append(list(map(int, input().split())))

for i in range(n):
    minNum = float('inf')
    ans = 0
    for j in range(m):
        if abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) < minNum:
            minNum = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
            ans = j + 1
    print(ans)

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

int main() {
	//九九を計算して一致した時点でYes出力
  	int n;
  	cin >> n;
  	for(int i=1;i<10;i++){
      for(int j=1;j<10;j++){
        if(n == i*j){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  	cout << "No" << endl;
  	return 0;  
}


Measured memory_bytes: 3636
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C++ (GCC 5.4.1)
*/

#include <bits/stdc++.h>
using namespace std;

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int ma = 0,m = 0;
	vector<int> menu(5);

	for(int i = 0; i < 5; ++i){
		cin >> menu.at(i);
		if(menu.at(i) % 10 != 0 && menu.at(i) % 10 < menu.at(ma) % 10)	ma = i;
	}
	for(int i = 0; i < 5; ++i){
		if(i != ma){
			if(menu.at(i) % 10 != 0)	m += menu.at(i) + (10 - menu.at(i) % 10); 
			else	m += menu.at(i);
		}
	}
	m += menu.at(ma);
	OUT(m) BR;
	RET;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;

//#define cerr if (false) cerr


ll n, c;

ll w[33][33];

map<ll, ll> colors[3];

ll trycol(ll a, ll b, ll c) {
  vector<ll> cc = {a, b, c};
  ll cnt = 0;
  for (int i = 0; i < 3; i++) {
    for (auto x: colors[i])
      cnt+= w[x.first][cc[i]]*x.second;
  }
  return cnt;
}

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n >> c;

  for (int i = 1; i <= c; i++) {
    for (int j = 1; j <= c; j++) {
      cin >> w[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ll x; cin >> x;
      colors[(i+j)%3][x]++;
    }
  }
  ll anw = 1e9;
  for (int i = 1; i <= c; i++) {
    for (int j = 1; j <= c; j++) {
      for (int k = 1; k <= c; k++) {
        if (i == j || i == k || j == k) continue;
        anw = min(anw, trycol(i, j, k));
      }
    }
  }
  cout << anw << endl;

}



Measured memory_bytes: 256
n,k = map(int,input().split())
a = [int(input()) for _ in range(n)]

a.sort()
b = a[k-1] - a[0]
for i in range(n-k+1):
    if a[i+k-1] - a[i] < b:
        b = a[i+k-1] - a[i]
print(b)

Measured memory_bytes: 7384
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N,M,C;cin>>N>>M>>C;
  vector<int>B(M);
  for (int i=0;i<M;++i)cin>>B[i];
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  int ans=0;
  for (int i=0;i<N;++i){
    int tmp=C;
    for (int j=0;j<M;++j){
      tmp+=B[j]*A[i][j];
    }
    if (tmp>0) ++ans;
  }
  cout<<ans<<endl;
}
      
  


Measured memory_bytes: 256
def main():
    # D, Tは文字数カウントするだけだからint型にする必要なし.
    n = int(input())
    D = input().split()
    m = int(input())
    T = input().split()
    dic = dict()
    
    # 辞書はDだけで十分.Counterより速い.
    for d in D:
        # dic.get(d)と比べると, if in の方が速い.
        if d in dic:
            dic[d] += 1
        else:
            dic[d] = 1
            
    for t in T:
        if t not in dic or dic[t] == 0:
            print('NO')
            return
        else:
            dic[t] -= 1
    print('YES')
main()

Measured memory_bytes: 53604
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args){

        Scanner scan=new Scanner(System.in);
        int n=0,k=0;
        if(scan.hasNext())
            n=scan.nextInt();
        if(scan.hasNext())
            k=scan.nextInt();
        int[] arr=new int[n];
        for(int i=0;i<n;i++){
            if(scan.hasNext())
                arr[i]=scan.nextInt();
        }
        int[] dp=new int[n];
        dp[0]=0;
        dp[1]=Math.abs(arr[1]-arr[0]);
        for(int i=2;i<n;i++){
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(k,i);j++){
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(arr[i]-arr[i-j]));
            }
            //dp[i]=Math.min(dp[i-1]+Math.abs(arr[i]-arr[i-1]),dp[i-2]+Math.abs(arr[i]-arr[i-2]));
        }
        System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 57048
n=int(input())
s=input()
count=0
A=[[0,0,0]for i in range(n)]
for i in range(0,n):
    if s[n-i-1]=="R":
        A[n-i-2][0]=A[n-i-1][0]+1
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="G":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]+1
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="B":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]+1
for i in range(0,n-3):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            if s1=="R" and s2=="G":
                s3="B"
            elif s1=="G" and s2=="R":
                s3="B"
            elif s1=="R" and s2=="B":
                s3="G"
            elif s1=="B" and s2=="R":
                s3="G"
            elif s1=="B" and s2=="G":
                s3="R"
            elif s1=="G" and s2=="B":
                s3="R"
            if s3=="R":
                s4=0
            if s3=="G":
                s4=1
            if s3=="B":
                s4=2
            count=count+A[j][s4]
            if j+j-i+1<=n: 
                if s[j+j-i]==s3:
                    count=count-1
print(count)

Measured memory_bytes: 69860
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    A, B = map(int, input().split())
    print("Possible" if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0 else "Impossible")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316