akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int x = scanner.nextInt();

        final int[] distances = new int[n];
        for (int i = 0; i < n; i++) {
            distances[i] = Math.abs(scanner.nextInt() - x);
        }

        if (distances.length == 1) {
            System.out.println(distances[0]);
            return;
        }

        int res = euclidean(distances[0], distances[1]);
        for (int i = 2; i < n; i++) {
            res = euclidean(res, distances[i]);
        }

        System.out.println(res);
    }

    public static int euclidean(int x, int y) {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    }

}


Measured memory_bytes: 50632
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
int a,b;
int main() {
	cin>>a>>b;
	int total;
	if((a+b)%2==0)total=(a+b)/2;
	if((a+b)%2==1)total=(a+b)/2+1;

		cout<<total<<endl;
		return 0;
}


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

int main() {
  int N;
  cin >> N;
  int n=N;
  long ans=1;
  while(n--){
    ans=ans*(n+1)%1000000007;
  }
  
    cout<<ans<<endl;
  
  
}

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

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(v) (v).begin(),(v).end()
#define endl '\n'

using namespace std;

const int N = 100005;
const int MOD = 1e9 + 7;
const int INF = 2000000000;
const ll INFLL = 1LL * INF * INF;

int n, a[N];
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int cur = 0, res = INF;
    for (int i = 1; i < n; i++) {
        cur += a[i];
        res = min(res, abs(cur - (sum - cur)));
    }
    cout << res << endl;
    return 0;
}


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

int main() {
  int N, m, sum = 0;
  cin >> N;
  m = N;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  if (m % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,a[1000005],l,r,mid,ans,xl,xr;
bool b[1000005];
bool check(int x){
	xl=0;xr=n<<1;
	for (register int i=1;i<=(n<<1)-1;++i) b[i]=(a[i]>=x);
	for (register int i=n;i>=2;--i){
		if (b[i]==b[i-1]) {xl=i;break;}
	}
	for (register int i=n;i<(n<<1)-1;++i){
		if (b[i]==b[i+1]) {xr=i;break;}
	}
	if (xl==0&&xr==n*2) return b[1];
	return n-xl>xr-n?b[xr]:b[xl];
}
int main(){
	scanf ("%d",&n);
	for (register int i=1;i<=(n<<1)-1;++i) scanf ("%d",&a[i]);
	l=1;r=(n<<1)-1;
	while (l<=r){
		mid=l+r>>1;
		if (check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf ("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------
// [gcd]
template<class T> T gcd(T a,T b)
{if (a < b) swap(a,b);return b ? gcd(b, a % b) : a;}
template<class T> T lcm(const T a, const T b)
{return (a * b / gcd(a, b));}

void Main(){
  int n,q;
  string s;
  cin>>n>>q>>s;
  vi acc(n,0);
  int c = 0;
  rep(i,n-1){
    if(s[i]=='A' && s[i+1]=='C') c++;
    acc[i+1] = c;
  }
  rep(i,q){
    int l,r;
    cin>>l>>r;
    l--;r--;
    cout<<acc[r]-acc[l]<<endl;
  }
} int main(int argc,char** argv)
{fastio; myio; Main();}


Measured memory_bytes: 1488
#include <stdio.h>

int main(){
    int x,y;
    scanf("%d %d",&x,&y);

    int r;
    int cp;

    while(1){
        if(x<y){
            cp=x;
            x=y;
            y=cp;
        }
        if(y==0){
            break;
        }
        x=x%y;
    }

    printf("%d\n",x);
}


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


using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

  ll n; cin >> n;
  string s; cin >> s;
  ll cntr = 0, cntg = 0, cntb = 0;
  for(int i=0;i<n;++i) {
    if(s[i] == 'R') {
      cntr++;
    } else if(s[i] == 'G') {
      cntg++;
    } else {
      cntb++;
    }
  }

  ll ans = cntr * cntg * cntb;

  for(int i=0;i<n;++i) {
    for(int j=1;j<n;++j) {
      int l = i-j, r = i+j;
      if(0 <= l && r < n) {
        if(s[l] != s[i] && s[i] != s[r] && s[r] != s[l]) ans--;
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    vector<int> sum(N + 1, 0);

    for(int i = 1; i < N; i++){
        sum[i + 1] = sum[i];
        if(S[i - 1] == 'A' && S[i] == 'C'){
            sum[i + 1]++;
        }
    }

    for(int cnt = 0; cnt < Q; ++cnt){
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int ans=0;
    for(int i=a;i<=b;i++){
        string s = to_string(i);
        reverse(s.begin(),s.end());
        if(to_string(i)==s)ans++;
    }
    cout <<ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int A, B;
  cin >> A >> B;
  
  if (B % A == 0) {
    cout << A + B << endl;
  } else {
    cout << B - A << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(n*a,b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int> > A(H, vector<int>(W));
  vector<vector<int> > B(H, vector<int>(W));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> B[i][j];
    }
  }

  const int kMaxVal = 80 * (H + W - 1);
  vector<vector<vector<bool> > > dp(H, vector<vector<bool> >(W, vector<bool>(kMaxVal + 1)));

  int d = abs(A[0][0] - B[0][0]);
  dp[0][0][d] = true;

  for (int i = 1; i < H; ++i) {
    int d = abs(A[i][0] - B[i][0]);
    for (int x = 0; x <= kMaxVal; ++x) {
      if (dp[i - 1][0][x] == true) {
	dp[i][0][x + d] = true;
	dp[i][0][abs(x - d)] = true;
      }
    }
  }

  for (int j = 1; j < W; ++j) {
    int d = abs(A[0][j] - B[0][j]);;
    for (int x = 0; x <= kMaxVal; ++x) {
      if (dp[0][j - 1][x] == true) {
	dp[0][j][x + d] = true;
	dp[0][j][abs(x - d)] = true;
      }
    }
  }

  for (int i = 1; i < H; ++i) {
    for (int j = 1; j < W; ++j) {
      int d = abs(A[i][j] - B[i][j]);
      for (int x = 0; x <= kMaxVal; ++x) {
	if (dp[i - 1][j][x] == true or dp[i][j - 1][x] == true) {
	  dp[i][j][x + d] = true;
	  dp[i][j][abs(x - d)] = true;
	}
      }
      
    }
  }

  for (int x = 0; x <= kMaxVal; ++x) {
    if (dp[H - 1][W - 1][x] == true) {
      cout << x << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int D[51];
int A[30];
int main(){
    cin>>N;
    REP(i,31){
        A[i]=0;
    }
    REP(i,N){
        cin>>D[i];
        A[D[i]]++;
    }
    
    if(A[0]>=1){
       cout<<0<<endl;
       return 0;
    }
    REP(i,14){
        if(A[i]>=3){
           cout<<0<<endl;
           return 0;
        }
    }
    
    int ans=0;
    for(int i=0;i<(1<<13);i++){
        vector<int> B;
        B.push_back(0);
        B.push_back(24);
        for(int j=0;j<13;j++){
            if(A[j]==1){
               if((i>>j)&1){
                  B.push_back(j);
               }else{
                  B.push_back(24-j);
               }
            }
            if(A[j]>=2){
              B.push_back(24-j);
              B.push_back(j);
            }
        }
        sort(B.begin(),B.end());
        int now=100;
        REP(k,B.size()-1){
            now=min(now,B[k+1]-B[k]);
        }
       /*
        if(ans<now){
         cout<<"-------------------"<<endl;
           cout<<now<<" "<<i<<endl;
           REP(k,B.size()){
               cout<<B[k]<<endl;
           }
            cout<<"-------------------"<<endl;
        }
        */
        ans=max(ans,now);
    }
    
    cout<<ans<<endl;
    
    return(0);
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
cnt = [1 for x in a if x < 0]
ans = 0
mini = float("inf")
for i in a:
    if i < 0:
        i *= -1
    mini = min(mini, i)
    ans += i
if sum(cnt) % 2 == 0:
    print(ans)
else:
    print(ans - mini * 2)

Measured memory_bytes: 19936
#include <iostream>
#include <vector>
#define llint long long

using namespace std;

llint n;
vector<llint> G[100005];
int distA[100005], distB[100005];

void dfs(int v, int p, int d, int dist[])
{
  dist[v] = d;
  for(int i = 0; i < G[v].size(); i++){
    if(G[v][i] == p) continue;
    dfs(G[v][i], v, d+1, dist);
  }
}

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

  cin >> n;
  llint u, v;
  for(int i = 1; i <= n-1; i++){
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, -1, 0, distA);
  dfs(n, -1, 0, distB);

  int cnt = 0;
  for(int i = 1; i <= n; i++){
    if(distA[i] <= distB[i]) cnt++;
    else cnt--;
  }
  if(cnt > 0) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;

  return 0;
}


Measured memory_bytes: 14336
#include <stack>
#include <cstdio>

using namespace std;
typedef long long int LL;
const int Max_N(5050);
const int Max_M(205);

/*
如果走到的店铺的最左点是l、最右点是r，收益 = Sum{max{B[i][j]   |   l <= i <= r}   |   1 <= j <= M} - Dist(l, r)
对于每个1 <= j <= M，考虑第j种优惠券在每个店铺上产生的价值序列B[1 ~ N][j]，把笛卡尔树建出来，那么一个B[i][j]产生的贡献是一个矩形
直接矩形加法预处理即可 
*/

int N, M, B[Max_N][Max_M], L[Max_N], R[Max_N];
LL V[Max_N][Max_N], Dist[Max_N], Ans;

inline void insert(int x1, int x2, int y1, int y2, int v)
{
	V[x1][y1] += v, V[x2 + 1][y1] -= v, V[x1][y2 + 1] -= v, V[x2 + 1][y2 + 1] += v;
}

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 2;i <= N;++i)
		scanf("%lld", Dist + i), Dist[i] += Dist[i - 1];
	for (int i = 1;i <= N;++i)
		for (int j = 1;j <= M;++j)
			scanf("%d", B[i] + j);
	for (int j = 1;j <= M;++j)
	{
		stack<int> S;
		for (int i = 1;i <= N;++i)
		{
			while (S.empty() == false && B[S.top()][j] < B[i][j])
				R[S.top()] = i - 1, S.pop();
			S.push(i);
		}
		while (S.empty() == false)
			R[S.top()] = N, S.pop();
		for (int i = N;i >= 1;--i)
		{
			while (S.empty() == false && B[S.top()][j] <= B[i][j])
				L[S.top()] = i + 1, S.pop();
			S.push(i);
		}
		while (S.empty() == false)
			L[S.top()] = 1, S.pop();
		for (int i = 1;i <= N;++i)
			insert(L[i], i, i, R[i], B[i][j]);
	}
	for (int l = 1;l <= N;++l)
		for (int r = 1;r <= N;++r)
		{
			V[l][r] += V[l - 1][r] + V[l][r - 1] - V[l - 1][r - 1];
			if (l <= r)
				Ans = max(Ans, V[l][r] - (Dist[r] - Dist[l]));
		}
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 203520
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string ans = "";
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] != 'B') ans += s[i];
        else if(ans.size() != 0) ans.pop_back();
    }
    cout << ans << endl;
    return 0;
}



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

int main()
{
  string s;
  cin >> s;

  string S = "2019/05/01";

  if (s>=S)
  {
    cout << "TBD" << endl;
  }
  else
  {
    cout << "Heisei" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<deque>
#include<stack>
#include<queue>
#include<sstream>
#include<cstdlib>
#define INF 16777216
typedef long long llong;
using namespace std;
deque<int>deq;
int init();
int dfs();
int s2i(string);
string i2s(int);
llong EN2D(llong,llong);
llong EN2R(llong,llong);
llong D2EN(llong,llong);
llong R2EN(llong,llong);
//
int n,tmp,flg,mx,mn,num,sum,i,j,k,H,W,avg;
int main(){
  llong M,Cd,Cr,MD,MR,RA,DA;
  int rD,rR;
  cin >> M >> rD >> rR >> Cd >> Cr;
  
  MD=D2EN(Cd,rD);
  MR=R2EN(Cr,rR);
  if(M<MD+MR){
    cout<<-1<<endl;
  }else{
    // cout<<MD<<" is MD"<<endl;
    // cout<<MR<<" is MR"<<endl;
    DA=D2EN( EN2D(10000,rD),rD);
    RA=R2EN( EN2R(10000,rR),rR);
    
    cout<<M-MD-MR<<endl;
  }

  return 0;
}

llong EN2D(llong x,llong rD){
  return (rD*x)/100 + ((rD*x)%100>0);
}
llong EN2R(llong x,llong rR){
  return (rR*x)/100 + ((rR*x)%100>0);
}
llong D2EN(llong x,llong rD){
  return (100*x)/rD + ((100*x)%rD>0);
}
llong R2EN(llong x,llong rR){
  return (100*x)/rR + ((100*x)%rR>0);
}


int init(){
}
int dfs(){
}


int s2i(string str){
  int num;
  num=atoi(str.c_str());
  return num;
}

string i2s(int num){
  string str;
  stringstream s;
  s<<num;
  s>>str;
  return str;
}

Measured memory_bytes: 1208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

char c[8][8];

int main(){
	REP(i, 8){
		REP(j, 8){
			cin >> c[i][j];
		}
	}
	cout << 90 << endl;
	for (int j = 0; j < 8; j++){
		for (int i = 7; i >= 0; i--){
			cout << c[i][j];
		}
		cout << endl;
	}
	cout << 180 << endl;
	for (int i = 7; i >= 0; i--){
		for (int j = 7; j >= 0; j--){
			cout << c[i][j];
		}
		cout << endl;
	}
	cout << 270 << endl;
	for (int j = 7; j >= 0; j--){
		for (int i = 0; i < 8; i++){
			cout << c[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1136
N = int(input())
C = {}
for _ in range(N):
    a = input().strip()
    if a not in C:
        C[a] = 0
    C[a] += 1
M = int(input())
for _ in range(M):
    a = input().strip()
    if a not in C:
        C[a] = 0
    C[a] -= 1
cmax = -100
for a in C:
    cmax = max(cmax,C[a])
print(max(0,cmax))

Measured memory_bytes: 61664
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main(){
IOS;
long long int x,k,a,b,coun=0;
cin>>x>>k;
while(x--){
    cin>>a>>b;
    if(a*a+b*b<=k*k)
        coun++;
}
cout<<coun<<"\n";
return 0;
}



Measured memory_bytes: 3636
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll h,w;
	cin>>h>>w;
	char matrix[h][w];
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>matrix[i][j];
		}
	}
	ll dp[h+1][w+1];
	for(ll i=0;i<=h;i++){
		for(ll j=0;j<=w;j++){
			dp[i][j]=0;
		}
	}
	for(ll i=1;i<=h;i++){
		for(ll j=1;j<=w;j++){
			if(i==1 && j==1){
				dp[i][j]=1;
			}
			else if(matrix[i-1][j-1]=='.'){
				dp[i][j]=dp[i-1][j]%1000000007+dp[i][j-1]%1000000007;
			}
		}
	}
	cout<<dp[h][w]%1000000007<<endl;
	
}

Measured memory_bytes: 12388
#include <bits/stdc++.h>
using namespace std;
int sz[100005],par[100005];
pair<long long,int> a[100005];
map<long long,int> inv;
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i].first);
		a[i].second=i;
		sz[i]=1;
		inv[a[i].first]=i;
	}
	sort(a+1,a+n+1);
	for (int i=n;i>1;i--)
	{
		if (2*sz[a[i].second]>=n)
		{
			printf("-1");
			return 0;
		}
		int p=inv[a[i].first-n+2*sz[a[i].second]];
		if (!p)
		{
			printf("-1");
			return 0;
		}
		sz[p]+=sz[a[i].second];
		par[a[i].second]=p;
	}
	for (int i=2;i<=n;i++)
	a[1].first-=sz[a[i].second];
	if (a[1].first)
	printf("-1");
	else
	{
		for (int i=2;i<=n;i++)
		printf("%d %d\n",par[a[i].second],a[i].second);
	}
}

Measured memory_bytes: 9984
/**
*    author:  souzai32
*    created: 04.08.2020 01:31:08
**/

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

int main() {

    long long int n,m;
    cin >> n >> m;

    long long ans=1;
    if(n==m) ans*=2;
    else if(abs(n-m)>1) ans=0;

    for(int i=1; i<=n; i++){
        ans*=i;
        if(ans>=1000000007) ans%=1000000007;
    }
    for(int i=1; i<=m; i++){
        ans*=i;
        if(ans>=1000000007) ans%=1000000007;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    
    String num = stdIn.next();
    if (num.contains("7")) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35740
/**
 *    author:  FromDihPout
 *    created: 2020-06-25
**/

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


vector<vector<int>> adj;

int dfs(int u, vector<bool> seen) {
    int paths = 0;
    seen[u] = true;
    bool all = true;
    for (bool s : seen) {
        if (!s) {
            all = false;
            break;
        }
    }
    if (all) {
        return 1;
    }
    
    for (int v : adj[u]) {
        if (seen[v]) continue;
        paths += dfs(v, seen);
    }
    return paths;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    adj.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    vector<bool> seen(n);
    cout << dfs(0, seen) << endl;
    return 0;
}

Measured memory_bytes: 3664
n = int(input())
a = list(map(int, input().split()))
b = [0]*n

for i in range(0, n-1):
  
   if a[i]+b[i] < a[i+1]:
      b[i+1] = 0
   else: 
      b[i+1] = a[i] + b[i] - a[i+1]
      
print(sum(b))

Measured memory_bytes: 32220
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
  foreach (string line; stdin.lines) {
    double[] a = new double[10];
    double a1 = line.chomp.to!double;
    a[0] = a1;
    
    for (int i = 1; i <= 9; i++) {
      if (i % 2 != 0) {
        a[i] = a[i-1] * 2;
      } else {
        a[i] = a[i-1] / 3;
      }
    }

    writefln("%.8f", a.reduce!("a + b"));
  }
}

Measured memory_bytes: 1136
"""
B - Great Ocean View
https://atcoder.jp/contests/abc124/tasks/abc124_b
"""
if __name__ == '__main__':
    input_list = list(map(int, input().split()))
    N = input_list
    input_list = list(map(int, input().split()))
    H_list = input_list

    H1 = H_list[0]
    answer = 1
    for i, Hi in enumerate(H_list):
        if i == 0:
            continue
        else:
            west_H_list = H_list[0:i]
            max_h_west = sorted(west_H_list, reverse=True)[0]
            if max_h_west <= Hi:
                answer += 1

    print(answer)

Measured memory_bytes: 3064
#include <iostream>

int
main()
{
    std::ios::sync_with_stdio(false);
    int price;
    std::cin >> price;
    if (price%1000==0)
    {
        std::cout << "0\n";
        return 0;
    }
    std::cout << 1000-(price%1000) << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

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

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

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, M, T[100], P[100], X[100];

  cin >> N;
  for(int i = 0; i < N; i++) cin >> T[i];
  cin >> M;
  for(int i = 0; i < M; i++) cin >> P[i] >> X[i];

  for(int i = 0; i < M; i++) {
    int sum = 0;
    for(int j = 0; j < N; j++) {
      if(P[i] - 1 == j) sum += X[i];
      else sum += T[j];
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
     char dance[104];
     scanf("%s", dance);
     for (int i = 0; dance[i] != '\0'; i++) {
          // printf("%c %d\n", dance[i], i+1);
          if ((i+1)%2 == 0) {
               if (dance[i] == 'L' || dance[i] == 'U' || dance[i] == 'D') {
                    continue;
               } else {
                    printf("No\n");
                    return 0;
               }
          }
          else {
               if (dance[i] == 'R' || dance[i] == 'U' || dance[i] == 'D') {
                    continue;
               } else {
                    printf("No\n");
                    return 0;
               }
          }
 
     }
     printf("Yes\n");
 
     return 0;
}

Measured memory_bytes: 128
import sys
N = int(input())
A = list(map(int, input().split()))

if N == 0:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
    sys.exit()

capacity = [1 - A[0]]
for i in range(N):
    # i 段目の許容数は上の段の許容数と上の段の歯の数で来まる
    capacity += [2 * (capacity[-1] - A[i])]


corr_flag = 1
if A[-1] > capacity[-1]:
    corr_flag = 0
curr = A[-1]
ans = A[-1]
for i in range(N-1, -1, -1):
    curr = min(capacity[i], A[i] + curr)
    ans += curr
if corr_flag:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 674528
N = int(input())

R = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]
R.sort(key=lambda x:(-x[0],-x[1]))
B.sort(key=lambda x:(x[1],x[0]))

ans = 0
for rx,ry in R:
    for bx,by in B:
        # print(rx,ry,bx,by)
        if rx<bx and ry<by:
            # print("ok")
            ans += 1
            B.remove([bx,by])
            break

print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    // int A, B;
    // char op;
    // cin >> A >> op >> B;

    // if(op == '+'){
    //     cout << A + B << endl;
    // }
    // else{
    //     cout << A - B << endl;
    // }

    int time[101], N, M, problem, stim_time, sum = 0;
    cin >> N;
    pair<int, int> after_drink [101];
    for(int i = 1; i <= N; i++){
        cin >> time[i];
        sum += time[i];
    }
    cin >> M;
    for(int i = 0; i < M; i++){
        cin >> problem >> stim_time;
        pair<int, int> my_pair(problem, stim_time);
        after_drink[i] = my_pair;
    }
    for(int i = 0; i < M; i++){
        pair<int, int> test = after_drink[i];
        int test_problem = test.first;
        int test_problem_time = test.second;
        int original_time = time[test_problem]; 
        int temp = sum;
        temp += test_problem_time - original_time;
        cout << temp << endl;
    }
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main(){
    int n;
    double ans = 0.0,a;
    cin >> n;

    for(int i = 0;i < n;i++){
        cin >> a;
        ans += 1.0/a;
    }    

    ans = 1.0/ans;

    cout << setprecision(16) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
ll N, M, K,H,W, ans, mi1,mi2, A;
string s;
int main() {
	ans = 2000000000;
	cin >> H>>W;
	if (W - H > 2019) {
		cout << 0 << endl;
		return 0;
	}
	else {
		for (ll i = H; i <= W; i++) {
			for (ll j = i + 1; j <= W; j++) {
				ans = min(ans, (i*j) % 2019);
			}
		}
	}
	cout << ans << endl;
	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
typedef long long ll;
const ll M = 1000000007;

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

	vector<ll> v(n);
	for(int i = 0; i<n; i++) {
		v[i] = -1;
	}

	for(int i = 0; i<m; i++) {
		int x;
		cin >> x;
		v[x-1] = 0;
	}

	if (v[0] != 0) v[0] = 1;
	if (v[1] != 0) v[1] = v[0] + 1;
	for (int i = 2; i<n; i++) {
		if (v[i] != 0) {
			v[i] = (v[i-1] + v[i-2]) % M;
		}
	}

	cout << v[n-1];

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string.h>
using namespace std;
int main() 
{
   long long int a, b, c, k;
   cin >> a >> b >> c >> k;
   if(k<=a) 
   cout << k << endl;
   else if(k<=(a+b)) 
   cout << a << endl;
   else
   cout << ((k-(a+b))*(-1))+a << endl;
   
   return 0;
} 


Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
#include<iostream>
#include <fstream>
using namespace std;

#define N	100
#define maxW	10000
int	v[N] = { 0 };
int	w[N] = { 0 };
int C[N+1][maxW+1] = { 0 };

int main(){
	std::istream & c_in = cin;
	int	n, W;
	c_in >> n >> W;
	for (int i = 0; i < n; i++){
		c_in >> v[i+1] >> w[i+1];
	}

	for (int i = 1; i <= n; ++i){
		for (int j = 1; j <= W; ++j){
			if (w[i] <= j){
				if (v[i] + C[i - 1][j - w[i]] > C[i - 1][j]){
					C[i][j] = v[i] + C[i - 1][j - w[i]];
				}
				else
				{
					C[i][j] = C[i - 1][j];
				}
			}
			else{
				C[i][j] = C[i - 1][j];
			}
		}
	}
	printf("%d\n", C[n][W]);
	return 0;
}

Measured memory_bytes: 5052
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
factorial = [i for i in range(10 ** 5 + 1)]
for i in range(2, 10 ** 5 + 1):
    factorial[i] *= factorial[i - 1]
    factorial[i] %= mod

def combination_mod(n, k, mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """

    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if n == k: return 1
    a = factorial[n] % mod
    b = factorial[k] % mod
    c = factorial[n - k] % mod
    return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod

#solve
def solve():
    n, k = LI()
    a = LI()
    a.sort()
    d = defaultdict(int)
    for i, ai in enumerate(sorted(set(a))):
        d[ai] = i
    cont = [0] * n
    for ai in a:
        cont[d[ai]] += 1
    mina = [0] + list(itertools.accumulate(cont))
    ans = 0
    for b, key in sorted(d.items()):
        mina_ = mina[key]
        count = n - mina_

        if count < k:
            continue
        else:
            # print(combination_mod(count, k, mod),combination_mod(count-cont[key], k, mod),count-cont[key])
            ans -= b*(combination_mod(count, k, mod)-combination_mod(count-cont[key], k, mod))
            ans %= mod

    for b, key in sorted(d.items()):
        mina_ = mina[key]
        count = cont[key] + mina_
        if count < k:
            continue
        else:
            ans += b*(combination_mod(count, k, mod)-combination_mod(count-cont[key], k, mod))
            ans %= mod
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 75500
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int L;
string A;
map< string, int > vst;

void solve(void);

int main() {
  while (cin >> A >> L && (A != "0" || L != 0))
    solve();

  return 0;
}

void solve(void) {
  string A0(L, '0'), pre;
  int mini, maxi, diffi, cnt = 0;

  A0.replace(L - A.length(), A.length(), A);
  vst.clear(), vst[A0] = 0;

  pre = A0;
  do {
    string maxs, mins, diffs;
    mins = pre;
    sort(mins.begin(), mins.end());
    maxs = mins;
    reverse(maxs.begin(), maxs.end());

    istringstream iss1(mins), iss2(maxs);
    ostringstream oss;

    iss1 >> mini, iss2 >> maxi, diffi = maxi - mini;
    oss.fill('0'), oss.width(L), oss << diffi, diffs = oss.str(), ++cnt;
    if (vst.count(diffs) > 0) {
      cout << vst[diffs] << " " << diffi << " " << cnt - vst[diffs] << "\n";
      break;
    }
    vst[diffs] = cnt, pre = diffs;
  } while (true);
}

Measured memory_bytes: 1268
N = int(input().strip())
A, B = [int(i) for i in input().strip().split()]
P = [int(i) for i in input().strip().split()]

a=[]
b=[]
c=[]

for num in P:
    if num<=A:
        a.append(num)
    elif num>=(A+1) and num<=B:
        b.append(num)
    else:
        c.append(num)
        
print(min(len(a), len(b), len(c)))

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

int main() {
int a,b;
  cin >> a >> b;
  int A=a%2;
  int B=b%2;
  if(A*B==1){
    cout << "Odd" << endl;
  }
    else{
      cout << "Even" << endl;
    }
}


Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 2e5 + 10;
bool a[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        char ch;
        cin >> ch;
        a[i] = ch == 'W';
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        cnt += a[i];
    }
    int ans = min(cnt, n - cnt);
    int cur = 0;
    for (int l = 1, r = n; l < r;) {
        if (!a[l]) {
            l++;
            continue;
        }
        if (a[r]) {
            r--;
            continue;
        }
        cur++;
        l++;
        r--;
    }
    ans = min(ans, cur);
    cout << ans << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> h(n+1);
    vector<bool> s(n+1);
    for(int i = 1;i <= n;i++){
        cin >> h[i];
        s[i] = true;
    }
    for(int i = 1;i <= m;i++){
        int a,b;
        cin >> a >> b;
        if(h[a] <= h[b]) s[a] = false;
        if(h[a] >= h[b]) s[b] = false;
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        if(s[i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3728
#include<stdio.h>

int main(void)
{

    int i;


    while(1==1){
        int x=0,y=0;
        scanf("%d %d",&x,&y);
        if(x==0 && y==0)break;
        if(x<=y) {
            printf("%d %d\n",x,y);
        }
        if(x>y){
            printf("%d %d\n",y,x);
        }}

    return 0;
}

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

int  main()
{
	ll a, v; cin >> a >> v;
	ll b, w; cin >> b >> w;
	ll t; cin >> t;

	if (v <= w)
	{
		cout << "NO" << endl;
		return 0;
	}
	else
	{
		ll s = v - w;
		if (s*t >= llabs(a-b))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return (0);
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <tuple>
using namespace std;

bool visited[51][51][51][51];
int h, w;
vector<string> L(50), R(50);
pair<int,int> gl, gr;

bool in_range(int a, int b){
  return a >= 0 && a < b;
}

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

void rec(pair<int,int> &l, pair<int,int> &r){
  stack<pair<pair<int,int>,pair<int,int>>> st;
  st.emplace(l,r);
  while(st.size()){
    tie(l,r) = st.top();
    st.pop();
    for(int i = 0; i < 4; ++i){
      pair<int,int> l_ = l, r_ = r;
      l_.first += dx[i], l_.second += dy[i];
      r_.first += dx[i], r_.second -= dy[i];

      if(!(in_range(l_.first,h) and in_range(l_.second,w)))
        l_ = l;
      if(!(in_range(r_.first,h) and in_range(r_.second,w)))
        r_ = r;

      if(L[l_.first][l_.second] == '#') l_ = l;
      if(R[r_.first][r_.second] == '#') r_ = r;

      if(visited[l_.first][l_.second][r_.first][r_.second]) continue;
      visited[l_.first][l_.second][r_.first][r_.second] = true;
      if(gl == l_ or gr == r_) continue;
      if(visited[gl.first][gl.second][gr.first][gr.second]) return;
      // rec(l_,r_);
      st.emplace(l_,r_);
    }
  }
}

int main(){
  while(cin >> w >> h, h&&w){
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
        for(int k = 0; k < h; ++k){
          for(int l = 0; l < w; ++l){
            visited[i][j][k][l] = false;
          }
        }
      }
    }
    for(int i = 0; i < h; ++i) cin >> L[i] >> R[i];
    pair<int,int> sl, sr;
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
        if(L[i][j] == '%') gl = {i,j};
        if(R[i][j] == '%') gr = {i,j};
        if(L[i][j] == 'L') sl = {i,j};
        if(R[i][j] == 'R') sr = {i,j};
      }
    }
    // cerr << sl.first << " " << sl.second << " " << sr.first << " " << sr.second << endl;
    // cerr << gl.first << " " << gl.second << " " << gr.first << " " << gr.second << endl;
    visited[sl.first][sl.second][sr.first][sr.second] = true;
    rec(sl,sr);
    if(visited[gl.first][gl.second][gr.first][gr.second]){
      puts("Yes");
    }else{
      puts("No");
    }
  }
}



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


int main() {

	int N;
	int mochi[110];
	int result = 0;

	cin >> N;
	for (int i = 0; i < N; i++)cin >> mochi[i];
	mochi[N] = 0;


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

	for (int i = 0; i < N; i++) {
		if (mochi[i] != mochi[i + 1]) result++;
	}

	cout << result;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
using namespace std;


int main() {
	long long n, a;
	cin >> n;
	
	vector<char> in(1000000001, false);
	for(long long i = 0; i < n; ++i){
		cin >> a;
		if(in[a]){
			cout << "NO";
			return 0;
		}
		in[a] = true;
	}
	cout << "YES";
}


Measured memory_bytes: 976768
//submitted by HimJ
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
const int mxn=1e5;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  int t=1;
  //cin>>t;
    while(t--){
            ll n, m;
            cin>>n>>m;
    if(n==1&&m==1)
    {
        cout<<1;
        return 0;
    }
    if(m<n)
        swap(m,n);
    if(n==1)
    {
        if(m==2)
        {
            cout<<0;
            return 0;
        }
        if(m>2)
        {
            cout<<m-2;
            return 0;
        }
    }
    if(n==2)
    {
        if(m==2)
        {
            cout<<0;
            return 0;
        }
        if(m>2)
        {
            cout<<0;
            return 0;
        }
    }
    ll ans=m*n;
    ans-=2*n;
    ans-=2*m;
    ans+=4;
    cout<<ans;

  }
  return 0;
  }



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

int main(){
  int n,k,r,s,p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  int dp[n+k+1][3]={};
  
  rep(i,n){
    if(t[i]=='r'){
      dp[i+k][0]=max(dp[i][1],dp[i][2]);
      dp[i+k][1]=max(dp[i][0],dp[i][2]);
      dp[i+k][2]=max(dp[i][0],dp[i][1])+p;
    }
    if(t[i]=='s'){
      dp[i+k][0]=max(dp[i][1],dp[i][2])+r;
      dp[i+k][1]=max(dp[i][0],dp[i][2]);
      dp[i+k][2]=max(dp[i][0],dp[i][1]);
    }
    if(t[i]=='p'){
      dp[i+k][0]=max(dp[i][1],dp[i][2]);
      dp[i+k][1]=max(dp[i][0],dp[i][2])+s;
      dp[i+k][2]=max(dp[i][0],dp[i][1]);
    }
  }
  int ans = 0;
  for (int i = n; i < n + k; i++) {
    ans += max({dp[i][0],dp[i][1],dp[i][2]});
  }
  cout << ans << endl;
}

Measured memory_bytes: 2688
A = int(input())
a = list(map(int, input().split()))
mx = max(a)
mn = min(a)

if mn >= 0:
    print(A-1)
    for i in range(1, A):
        print(i, i+1)
elif mx <= 0:
    print(A-1)
    for i in range(A, 1, -1):
        print(i, i-1)
else:
    print(A*2-1)
    if mx >= abs(mn):
        index = a.index(mx) + 1
        for i in range(1, A+1):
            print(index, i)
        for i in range(1, A):
            print(i, i+1)
    else:
        index = a.index(mn) + 1
        for i in range(1, A+1):
            print(index, i)
        for i in range(A, 1, -1):
            print(i, i-1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, r;
    cin >> n >> r;
    if (n >= 10)
        cout << r;
    else
        cout << r + 100 * (10 - n);
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc121/tasks/abc121_a

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

ll H, W, h, w;

int main()
{
  cin >> H >> W >> h >> w;

  cout << ((H - h) * (W - w)) << '\n';

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main{

	Scanner sc=new Scanner(System.in);;

	int INF=1<<28;
	double EPS=1e-9;

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

	// ----
	boolean[][] w1=new boolean[5][4];
	// |||||
	boolean[][] w2=new boolean[4][5];

	void run(){
		for(int i=0; i<9; i++){
			boolean[] w;
			if(i%2==0)
				w=w1[i/2];
			else
				w=w2[i/2];
			String s=sc.nextLine();
			for(int k=0; k<s.length(); k++){
				w[k]=s.charAt(k)=='1';
			}
		}
		solve();
	}

	void solve(){
		int x=0, y=0;
		int d=1;
		for(;;){
			for(d=(d+3)%4;; d=(d+1)%4){
				if(d==0&&up(x, y)){
					print("U");
					break;
				}else if(d==1&&right(x, y)){
					print("R");
					break;
				}else if(d==2&&down(x, y)){
					print("D");
					break;
				}else if(d==3&&left(x, y)){
					print("L");
					break;
				}
			}
			x+=dx[d];
			y+=dy[d];
			if((x|y)==0){
				break;
			}
		}
		println("");
	}

	boolean up(int x, int y){
		return y>0&&w2[y-1][x];
	}

	boolean down(int x, int y){
		return y<4&&w2[y][x];
	}

	boolean left(int x, int y){
		return x>0&&w1[y][x-1];
	}

	boolean right(int x, int y){
		return x<4&&w1[y][x];
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    if A[N - 1] == 0:
        print(0)
        quit()
    ans = 1
    maxvalue = 10 ** 18
    for a in A:
        ans *= a
        if ans > maxvalue:
            print(-1)
            quit()
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21584
N,K = map(int,input().split())
A = list(map(int,input().split()))

ans = float('inf')
for b in range(1<<(N-1)):
    mxa = A[0]
    k = 1
    cost = 0
    for i,a in enumerate(A[1:]):
        if b&(1<<i):
            c = max(0, mxa+1 - a)
            cost += c
            mxa = max(a, mxa+1)
            k += 1
        else:
            if mxa < a:
                mxa = a
                k += 1
    if k >= K:
        ans = min(ans, cost)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    rep(i, n)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    map<ll, bool> used;
    ll cnt = 0;
    rep(i,n){
        if(used[a[i]]==false){
            if(mp[a[i]]<a[i])
                cnt += mp[a[i]];
                if(mp[a[i]]>a[i])
                    cnt += mp[a[i]] - a[i];

                used[a[i]] = true;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int A, B;

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

  int K, X;
  cin >> K >> X;
  for(int i = -K + 1; i < K; ++i){
    cout << X + i << " ";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int k;
int main()
{
	cin>>s;
	cin>>k;
	int tmp=0;
	for(int i=0;i<s.size();i++)
	{
		int c=s[i]-'0';
		if(c==1)k--;
		else k-=c*5*1e15;
		if(k<=0)
		{
			printf("%d\n",c);
			return 0;
		}
	}
	return 0;
} 

Measured memory_bytes: 256
from collections import deque
h,w = map(int, input().split())
al = [input() for _ in range(h)]

inf = 10**9
f = [[inf]*w for _ in range(h)]
q = deque()
for hi in range(h):
    for wi in range(w):
        if al[hi][wi]=="#":
            f[hi][wi] = 0
            q.append((hi,wi))

while len(q)>0:
    hi,wi = q.popleft()
    c = f[hi][wi]

    for dh,dw in [[0,1],[1,0],[0,-1],[-1,0]]:
        nh = hi+dh
        nw = wi+dw
        if h>nh>=0 and w>nw>=0:
            if f[nh][nw]>c+1:
                f[nh][nw] = c+1
                q.append((nh,nw))

res = 0
for hi in range(h):
    for wi in range(w):
        res = max(res,f[hi][wi])
print(res)

Measured memory_bytes: 89052
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, K = (int(i) for i in input().split())
    WD = [[int(i) for i in input().split()] for j in range(N)]
    ma_w = 0
    ma_d = 0
    for w, d in WD:
        if ma_w < w:
            ma_w = w
        if ma_d < d:
            ma_d = d

    def is_ok(X):
        need = 0
        for i in range(N):
            if WD[i][0] <= X:
                need += ((X - WD[i][0]) // WD[i][1]) + 1
        if need >= K:
            return True
        else:
            return False

    def binary_search_meguru():
        ng = -1
        ok = ma_w + K * ma_d + 1
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(binary_search_meguru())


if __name__ == '__main__':
    main()


Measured memory_bytes: 55644