akhauriyash/Code-Regression huggingface dataset:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
G=[[] for n in range(K)]

for n in range(N):
  G[n%K].append(T[n])

cnt=0
for g in G:
  r,s,p=True,True,True
  for g2 in g:
    if g2=='r':
      if p:
        p=False
        r,s=True,True
        cnt+=P
      else:
        r,s,p=True,True,True
    if g2=='s':
      if r:
        r=False
        p,s=True,True
        cnt+=R
      else:
        r,s,p=True,True,True
    if g2=='p':
      if s:
        s=False
        r,p=True,True
        cnt+=S
      else:
        r,s,p=True,True,True

print(cnt)

Measured memory_bytes: 18252
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
  ll n;
  cin>>n;
  ll a[n+1],f[n+1]={0},d[n+1]={0},sum=0;
  for(int i=1;i<=n;i++){
  	cin>>a[i];
  	f[a[i]]++;
	}
	ll flag[n+1]={0};
	for(int i=1;i<=n;i++){
		if(!flag[a[i]]){
			sum+=(f[a[i]]*f[a[i]]-f[a[i]])/2;
			d[a[i]]=(f[a[i]]*f[a[i]]-f[a[i]])/2;
			flag[a[i]]=1;
		}
	}
	for(int k=1;k<=n;k++){
		cout<<sum-d[a[k]]+(f[a[k]]-1)*(f[a[k]]-2)/2<<endl;
	}return 0;
}/*『你强归你强，Siyuan比你强』*/





Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;


int main() {
    string s; cin >> s;
    int n = sz(s);
    ll ans = 0;
    rep(i,1<<(n-1)) { //全探索
        ll tmp = s[0]-'0';
        rep(j,n-1) { //各位についてbitが立ってるかのチェック
            if (i & 1<<(n-2-j)) {
                ans += tmp;
                tmp = s[j+1]-'0';
            }
            else {
                tmp = 10*tmp + (s[j+1]-'0');
            }
        }
        ans += tmp;
    }
    cout << ans << endl;
} 

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


int main() {
int H,W;
cin>>H>>W;

vector<vector<long>> c(10,vector<long> (10));
vector<vector<long>> a(H,vector<long> (W));

for(int i=0;i<10;i++) for(int j=0;j<10;j++){
  cin>>c[i][j];
}
for(int i=0;i<H;i++) for(int j=0;j<W;j++){
  cin>>a[i][j];
}

vector<vector<long>> d(10,vector<long> (10));
for(int i=0;i<10;i++) for(int j=0;j<10;j++){
  d[i][j]=c[i][j];
}

for(int k=0;k<10;k++) for(int i=0;i<10;i++) for(int j=0;j<10;j++){
  d[i][j]= min(d[i][j], d[i][k]+d[k][j]);
}

long ans=0;
for(int i=0;i<H;i++) for(int j=0;j<W;j++){
  if(a[i][j]!=-1) ans+=d[a[i][j]][1];
}

cout<<ans<<endl;

}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    rep(i,3){
        if(n[i] == '1') n[i] = '9';
        else n[i] = '1';
    }
    cout << n << endl;;
    
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
 int a,s=0,f=0;
  for(int i=0;i<3;i++)
  {  cin>>a;
     if(a==7)
     {s++;}
     if(a==5)
     { f++;}
  } 
  if (s==1 && f==2)
  {cout<<"YES";}
  else
  {
    cout<<"NO";
  }
}

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

void main_()
{
    int64_t N, M;
    vector<pair<int64_t, int64_t>> drinks; // 価格,在庫

    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        int64_t a, b;
        cin >> a >> b;
        drinks.emplace_back(a, b);
    }

    sort(begin(drinks), end(drinks));

    int64_t bought_num = 0;
    int64_t cost = 0;
    for (auto&& drink : drinks) {
        auto buy = min(drink.second, M - bought_num);
        cost += buy * drink.first;
        bought_num += buy;
        if (bought_num == M) {
            break;
        }
    }

    cout << cost << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 2420
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        long maxLen = 1L;
        while (y >= x * (long) Math.pow(2, maxLen)) {
            maxLen++;
        }
        System.out.println(maxLen);
    }

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int a[m],sum=0;
	for(int i=0;i<m;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n){
		cout<<"-1";
	}
	else{
		cout<<n-sum;
	}
	return 0;
}

Measured memory_bytes: 3676
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数

int main() {
  ld W, H, x, y, a = 0;
  ci(W, H, x, y);
  sp(10);
  if(W / 2 == x && H / 2 == y){
    co(W * H / 2, 1);
  }
  else{
    co(W * H / 2, 0);
  }
}

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

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

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

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

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

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, c;
  cin >> a >> b >> c;
  if(c-a-b<0){
    if(double(2)*sqrt(a*b) < double(c - a - b)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }else{
    if(4 * a * b < (c - a - b) * (c - a - b)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


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

typedef vector<int> vi;
#define REP(i,n) for (int i = 0; i < n; i++)

const int MAX = 22;
int N;
vi D;

int main() {
    cin >> N;
    D = vi(N);
    REP (i, N) cin >> D[i];
    sort(D.begin(), D.end());
    cout << D[N/2] - D[N/2-1] << endl;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int N = s.length;
		
		System.out.println((s[0]==s[N-1])^(N%2==0) ? "Second" : "First");
		
		sc.close();
	}
}


Measured memory_bytes: 14000
#include<iostream>
using namespace std;
int main()
{
    int sum=0,Max=0;
    string s;
    cin>>s;
    for(int i=0; s[i]!='\0'; i++)
    {
        if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G')
    {
        sum=1;
        for(int j=i+1; s[j]!='\0'; j++)
            {
                if(s[j]=='A'||s[j]=='T'||s[j]=='C'||s[j]=='G')
                {
                    sum++;
                }
                else
                {
                    break;
                }
            }
            Max=max(sum,Max);
        }
    }
    cout<<Max<<endl;
    return 0;
}


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

#define len 1e5+1
#define maxwt 1e15

int main(){
    int n,k; cin>>n>>k;
    string s; cin>>s; s[k-1]=s[k-1]+32;
    for(int i=0; i<n; i++){
         cout<<s[i];
    }
    cout<<endl;
}








Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int d,t,s; cin >> d >> t >> s;
    if(t*s >= d) cout << "Yes" << endl;
    else cout <<"No" << endl;
}



Measured memory_bytes: 3596
N,K=map(int,input().split())
H=list(map(int,input().split()))
dp = [float("inf")]*N
dp[0]=0
for i in range(N-1):
    for j in range(1,min(K+1,N-i)):
        dp[i+j]=min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[-1])

Measured memory_bytes: 55136
#include<iostream>
using namespace std;
int main()
{
	int f,o,fi,target;
	cin>>f;
	cin>>o;
	cin>>fi;
	cin>>target;
	int res=0;
	for(int i=0;i<=f;i++)
	{
		for(int j=0;j<=o;j++)
		{
			for(int k=0;k<=fi;k++)
			{
				if(i*500+j*100+k*50==target)
				res++;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char* argv[])
{
    int n, i = 1;
    while(cin>>n,n) {
        cout << "Case " << i << ": " << n << endl;
        i++;
    }
}


Measured memory_bytes: 3088
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

int N, K;

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

  double ans = 0;
  for (int i = 1; i <= N; i++) {
    int num = 0;
    int v = i;
    while (v < K) {
      num++;
      v *= 2;
    }
    ans += pow(0.5, num);
  }

  cout << fixed << setprecision(10) << ans / N << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i;
  char c;
  char str[1200];

  fgets(str, 1200, stdin);
  for (i = 0; (c = str[i]) != '\0'; i++) {
    if ('A' <= c && c <= 'Z') {
      str[i] += 32;
    } else if ('a' <= c && c <= 'z') {
      str[i] -= 32;
    }
  }
  printf("%s", str);

  return 0;
}



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

int main(){
  int n;
  string s,t;
  cin >> n;
  cin >> s;
  cin >> t;

  string ans = "";
  for(int i = 0 ; i < n; i++){
    ans = ans + s.at(i);
    ans = ans + t.at(i);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
//0327 Alphametic
#include<iostream>
using namespace std;
bool b[12] = {};
int q[10]; int cnt = 0;
bool f1() { return (q[0] + q[2] + q[5] + (q[1] + q[4]) * 10 + q[3] * 100 == q[6] * 100 + q[7] * 10 + q[8]); }
void dfs(int k) {
	if (k == 9) {
		if (f1())cnt++;
		return;
	}
	if (q[k] != -1)dfs(k + 1);
	else for (int i = 1; i < 10; i++) {
		if (!b[i]) {
			q[k] = i;
			b[i] = true;
			dfs(k + 1);
			b[i] = false;
			q[k] = -1;
		}
	}
}
int main() {
	for (int i = 0; i < 9; i++) {
		cin >> q[i];
		if (q[i] != -1)b[q[i]] = true;
	}
	dfs(0);
	cout << cnt << endl;
	char ch; cin >> ch;
}


Measured memory_bytes: 3108
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <assert.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp
//#pragma comment(linker, "/STACK:1024000000,1024000000") 
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
const int MAX=5e5+10;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
const ll MOD=1e9+7;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
void open()
{
//    freopen("1009.in","r",stdin);
    freopen("out.txt","w",stdout);
}

const int N = 2020;
ll C[N][N];
void init() {
        for (int i = 0; i < N; i ++) C[i][0] = C[i][i] = 1;
        for (int i = 1; i < N; i ++) {
                for (int j = 1; j < i; j ++) {
                        C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
                }
        }
}
int a,b;
ll an,lin;
int main()
{
    init();
    scanf("%d%d",&a,&b);
    an=a+1;
    for(int i=1;i<=min(a,b-1);i++)//第一次向下的位置的横坐标
    {
        for(int j=0;j<i&&j+i<=a;j++)
        {
            lin=C[b-1][i]*C[i-1][j]%MOD*C[a-i-j+2][2]%MOD;
            an=(an+lin)%MOD;
        }
    }
    printf("%lld\n",an);

}
/*
8
11011011
*/


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

int main(){
	int N,W;
	int v[100],w[100];
	
	//input
	scanf(" %d %d", &N, &W);
	for(int i=0; i<N; ++i) scanf(" %d %d", &v[i], &w[i]);
	
	int dp[101][10001]={0};
	
	for(int i=0; i<N; ++i){
		for(int j=0; j<=W; ++j){
			if(j-w[i]>=0)
				dp[i+1][j] = max( dp[i][j-w[i]]+v[i], dp[i][j] );
			else dp[i+1][j] = dp[i][j];
		}
	}
	
	printf("%d\n", dp[N][W]);
}


Measured memory_bytes: 7172
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main(){

int H,W;
cin>>H>>W;
string s;
for(int i=0;i<H;i++){
    cin>>s;
    cout<<s<<endl;
    cout<<s<<endl;
}

    

 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,ll>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    vector<LP> ball(N);
    rep(i,N){
        cin>>ball.at(i).first>>ball.at(i).second;
    }
    set<LP> B;
    rep(i,N){
        B.insert(ball.at(i));
    }
    int ans=N;
    rep(i,50*50){
        int x,y;
        x=i/50;y=i%50;
        if(x==y)continue;
        if(x>=N || y>=N)continue;
        ll p=ball.at(x).first-ball.at(y).first,q=ball.at(x).second-ball.at(y).second;
        int now=0;
        rep(j,N){
            LP t=ball.at(j);
            t.first+=p;
            t.second+=q;
            if(!B.count(t))now++;
        }
        chmin(ans,now);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    double a,b,h,m;
    double pi = 3.1415926535897932384;
    cin >> a >> b >> h >> m;
    double r=min(360-abs(h*30.0-5.5*m),abs(h*30.0-5.5*m));
    cout << setprecision(15) << sqrt(a*a+b*b-2*a*b*cos(r/360.0*2.0*pi)) <<endl;
    return 0;
}


Measured memory_bytes: 3532
#include"bits/stdc++.h"
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (auto& e : v) {
		cin >> e;
	}
	sort(v.begin(),v.end());
	double result = v[0];
	for (int i = 1;i < n;i++) {
		result = (result + v[i]) / 2.0;
	}
	cout << result << endl;
	return 0;
}


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

AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(N)]

AB = sorted(AB, key=lambda x: -x[0])
CD = sorted(CD, key=lambda x: x[1])

ans  = 0
for a,b in AB:
    for key,val in enumerate(CD):
        c,d = val[0],val[1]
        if a < c and b < d:
            CD.pop(key)
            ans += 1
            break
print(ans)

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

int main(){
  vector<int> vec(3);

  for (int i = 0; i < vec.size(); i++){
    cin >> vec.at(i);
  }

  sort(vec.begin(),vec.end());

  if (vec.at(2) == vec.at(1) + vec.at(0)){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3580
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

vector<int> nums[2222];
int have[2222][2222];
int id[44][44];

int main() {
  const int K = 38;//in();
  const int N = K*(K-1)+1;

  for (int i = 0; i < K; ++i) {
    nums[N - 1].push_back(i);
  }

  const int R = K - 1;
  const int C = K;

  for (int r = 0; r < R; ++r) {
    for (int c = 0; c < C; ++c) {
      id[r][c] = r * C + c;
    }
  }

  int counter = 0;
  for (int c = 0; c < C; ++c) {
    for (int r = 0; r < R; ++r) {
      nums[id[r][c]].push_back(counter);
    }
    ++counter;
  }

  for (int r = 0; r < R; ++r) {
    nums[id[0][0]].push_back(counter);
    for (int c = 1; c < C; ++c) {
      nums[id[r][c]].push_back(counter);
    }
    ++counter;
  }
  for (int r = 1; r < R; ++r) {
    for (int k = 0; k < K - 1; ++k) {
      nums[id[r][0]].push_back(counter);
      int cc = k;
      for (int rr = 0; rr < R; ++rr) {
        nums[id[rr][cc + 1]].push_back(counter);
        (cc += r) %= (C - 1);
      }
      ++counter;
    }
  }

  // for (int i = 0; i < N; ++i) {
  //   for (const int v : nums[i]) have[i][v] = 1;
  // }
  // for (int i = 0; i < N; ++i) {
  //   for (int j = i+1; j < N; ++j) {
  //     int co = 0;
  //     for (const int v : nums[i]) co += have[j][v];
  //     if (co != 1) {
  //       cerr<<i<<' '<<j<<' '<<co<<endl;
  //       puts("NG"); return 0;
  //     }
  //   }
  // }
  // puts("OK");

  printf("%d %d\n", N, K);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < nums[i].size(); ++j) {
      printf("%d%c", nums[i][j] + 1, j + 1 == nums[i].size() ? '\n' : ' ');
    }
  }

  return 0;
}


Measured memory_bytes: 896
#import sys
#input = sys.stdin.readline
def main():
    a, b ,c, d = map( int, input().split())
    A = [a*c, a*d, b*c, b*d]
    if a < b:
        A.append((a+1)*c)
        A.append((b-1)*c)
        A.append((a+1)*d)
        A.append((b-1)*d)

    if c < d:
        A.append(a*(c+1))
        A.append(a*(d-1))
        A.append(b*(c+1))
        A.append(b*(d-1))

    if a < b and c < d:
        A.append((a+1)*(c+1))
        A.append((a+1)*(d-1))
        A.append((b-1)*(c+1))
        A.append((b-1)*(d-1))

    print(max(A))
        
            


if __name__ == '__main__':
    main()


Measured memory_bytes: 9116
#include<stdio.h>
int a[109];
int main(){
	int n;
	scanf("%d",&n);
	int min = 2000;
	int max = -1;
	for(int i = 0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]>max){
			max = a[i];
		}
		if(a[i]<min){
			min = a[i];
		}
	}
	printf("%d\n",max-min);
}

Measured memory_bytes: 128
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(n**0.5)+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
      
  if temp!=1:
    arr.append([temp, 1])
    
  if arr==[]:
    arr.append([n, 1])
    
  return arr

a = factorization(int(input()))
b = [1, 3, 6, 10, 15, 21, 28, 36, 45]

ans = 0

if len(a) == 1 and a[0][0] == 1:
  print(0)
  exit()
  
for i in a:
  for j in range(len(b)):
    if i[1] < b[j]:
      ans+=j
      break
    
print(ans)


Measured memory_bytes: 9464
#include<stdio.h>

#define MAX_N 100000
#define MAX_Q 50000

int main(){

  int i, j, key, sum, s_n, t_n, s[MAX_N], t[MAX_Q];

  scanf("%d",&s_n);
  for(i=0; i<s_n;i++){
    scanf("%d", &s[i]);
  }

  scanf("%d",&t_n);
  for(i=0; i<t_n;i++){
    scanf("%d", &t[i]);
  }

  sum = 0;
  for(i=0;i<t_n;i++){
    key = t[i];
    int left = 0;
    int right = s_n;
    while(left < right){
      int mid = (int)((left + right) / 2);
      
      if(key == s[mid]){
        sum++;
        break;
      } else if(key > s[mid]){
        left = mid + 1;
      } else {
        right = mid;
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 1184
n,m,x,y =map(int,input().split())
lx = list(map(int,input().split()))
ly = list(map(int,input().split()))
lx.append(x)
ly.append(y)
lx.sort()
ly.sort()
if lx[-1] < ly[0]:
    print("No War")
else:print("War")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int GCD(int a, int b) {
    return b == 0 ? a : GCD(b, a % b);
}
 
int main() {
    int n;
    cin >> n;
    int a[n], l[n], r[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
 
    l[0] = a[0];
    for (int i = 1; i < n; i++) {
        l[i] = GCD(l[i - 1], a[i]);
    }
 
    r[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        r[i] = GCD(r[i + 1], a[i]);
    }
 
    int res = max(l[n - 2], r[1]);
  	res = max(res, l[n - 1]);
    for (int i = 1; i <= n - 2; i++) {
        res = max(res, GCD(l[i - 1], r[i + 1]));
    }
 
    cout << res;
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int>d;

int main(){

	int N;

	scanf("%d",&N);

	int i;

	for(i=0;i<N;i++){
	int di;
	scanf("%d",&di);
	d.push_back(di);
	}

	sort(d.begin(),d.end());

	int ans=1;
	int prev=d[N-1];

	if(N==1){printf("1\n");}
	else{
	for(i=N-2;i>=0;i--){
		if(prev!=d[i]){ans++;}
		prev=d[i];
	}
	printf("%d\n",ans);
	}

return 0;
}

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

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

    int a, b;
    cin >> a >> b;

    cout << a*b << endl;
    return 0;
}

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

int main() {
	string s;
	cin>>s;
	bool ans=false;
	for(ll i=1;i<s.size();i++){
		if(s[i-1]==s[i]){
			ans=true;
		}
	}
	cout << (ans?"Bad":"Good");
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int n;
    cin>>n;
    
    if(n/100==n%10){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    return 0;
}






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

int frog(int a[], int b[], int i){
	if(b[i]!=-1)
	return b[i];
	else
	{
		b[i]=min(frog(a, b, i+1)+abs(a[i]-a[i+1]), frog(a, b, i+2)+abs(a[i]-a[i+2]));
	    return b[i];
	}	
}

int main() {
	int n;
	cin >> n;
	int a[n], b[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
		b[i]=-1;
	}
	b[n-1]=0;
	b[n-2]=abs(a[n-1]-a[n-2]);
	b[n-3]=abs(a[n-1]-a[n-3]);
	
	cout << frog(a, b, 0);
}

Measured memory_bytes: 4992
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

vector<vector<ll>> child;
vector<vector<ll>> par;
vector<ll> table;
//dp
ll dp(ll n){
  if(child.at(n).size()==0) return 0;
  if(table.at(n)>-INF) return table.at(n);
  
  for(auto ch:child.at(n)){
    chmax(table.at(n),dp(ch)+1);
  }
  
  return table.at(n);
}
  
int main()
{
  ll N,M; cin>>N>>M;
  child=vector<vector<ll>>(N,vector<ll>(0));
  par=vector<vector<ll>>(N,vector<ll>(0));
  table=vector<ll>(N,-INF);
  
  //入力
  rep(i,M){
    ll x,y; cin>>x>>y; x--; y--;
    child.at(x).push_back(y);
    par.at(y).push_back(x);
  }
  
  //dp
  vector<ll> vec(0);
  rep(i,N) if(par.at(i).size()==0) vec.push_back(i);
  
  ll ans=0;
  for(auto n:vec){
    chmax(ans,dp(n));
  }
  /*
  rep(i,N){
    if(i!=0) cout<<" ";
    cout<<table.at(i);
  }
  cout<<endl;
  */
  cout<<ans<<endl;
      
  return 0;
}


Measured memory_bytes: 38324
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m; int s, t; cin >> n >> m >> s >> t;
  vector<pair<int, long long>> u[n+1], v[n+1];
  for (int i = 0; i < m; i++) {
    int c, d; long long a, b; cin >> c >> d >> a >> b;
    u[c].push_back({d, a}); u[d].push_back({c, a});
    v[c].push_back({d, b}); v[d].push_back({c, b});
  }
  vector<long long> go(n+1, 1e18), back(n+1, 1e18);
  priority_queue<pair<long long, int> > q;
  q.push({0, s});
  while(!q.empty()) {
    long long c; int w; c = q.top().first; w = q.top().second;
    q.pop();
    if (go[w] < -c) continue;
    go[w] = -c;
    for (int i = 0; i < (int) u[w].size(); i++) {
      if (go[u[w][i].first] > go[w]+u[w][i].second){
        q.push({-(go[w]+u[w][i].second), u[w][i].first});
        go[u[w][i].first] = go[w]+u[w][i].second;
      }
    }
  }
  q.push({0, t});
  while(!q.empty()) {
    long long c; int w; c = q.top().first; w = q.top().second;
    q.pop();
    if (back[w] < -c) continue;
    back[w] = -c;
    for (int i = 0; i < (int) v[w].size(); i++) {
      if (back[v[w][i].first] > back[w]+v[w][i].second){
        q.push({-(back[w]+v[w][i].second), v[w][i].first});
        back[v[w][i].first] = back[w]+v[w][i].second;
      }
    }
  }
  vector<long long> ans(n+1);
  long long y = 1e15;
  for (int i = 1; i <= n; i++) {
    ans[i] = y - go[i] - back[i];
  }
  for (int i = n; i > 0; i--) {
    ans[i-1] = max(ans[i], ans[i-1]);
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i+1] << endl;
  }
  return 0;
}


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

long long sum(long long n){
    long long ans;
    if(n % 2 == 0){
        ans = (n % 4) / 2 + n;
    }
    else{
        if(n % 4 == 1) ans = 1;
        else if(n % 4 == 3) ans = 0;
    }
    return ans;
}

long long func(long long a, long long b){
    long long M = max(a, b);
    long long n = 1;
    long long ans = 0;
    while(true){
        int p, q;
        if(a % (2*n) >= n) p = 1;
        else p = 0;
        if(b % (2*n) >= n) q = 1;
        else q = 0;
        ans += ((p + q) % 2) * n;
        if(M > n) n *= 2;
        else break;
    }
    return ans;
}

int main(){
    long long A, B;
    cin >> A >> B;
    cout << func(sum(A-1), sum(B)) << endl;
}

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

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

  int ans = 0;
  if (S.at(0) == '+')
    ans++;
  else
    ans--;
  if (S.at(1) == '+')
    ans++;
  else
    ans--;
  if (S.at(2) == '+')
    ans++;
  else
    ans--;
  if (S.at(3) == '+')
    ans++;
  else
    ans--;

  cout << ans << endl;
}

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

int ctoi(char c)
{
  switch(c)
  {
    case '0' : return 0;
    case '1' : return 1;
    case '2' : return 2;
    case '3' : return 3;
    case '4' : return 4;
    case '5' : return 5;
    case '6' : return 6;
    case '7' : return 7;
    case '8' : return 8;
    case '9' : return 9;
    default : return 0;
  }
}

int modpow(int p, int q, int mod)
{
  int i;
  int r=1;
  while(q>0)
  {
    if(q%2>0) r=r*p%mod;
    p=p*p%mod;
    q/=2;
  }
  return r;
}

int main(void)
{
  char S[200000];
  int i,j,len,sum=0;
  int s[200000]={};
  int t[200001]={0};
  int u[2019]={1};
  int mod=2019;

  scanf("%s",S);

  j=0;
  for(i=strlen(S)-1;i>=0;i--)
  {
    s[j]=ctoi(S[i]);
    j++;
  }

  for(i=1;i<=strlen(S);i++)
  {
    t[i]=(t[i-1]+s[i-1]*modpow(10,i-1,mod))%mod;
    u[t[i]]++;
  }

  for(i=0;i<2019;i++)
  {
    if(u[i]==0) continue;
    sum+=u[i]*(u[i]-1)/2;
  }

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

  return 0;
}

Measured memory_bytes: 3424
import collections

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

c=[0 for _ in range(M+1)]

for i in a:
    if c[i] != 0:
        c[i] = 2
        continue 
    for j in range(i,M+1,i):
        c[j]+=1

answer = 0

for i in a:
    if c[i] == 1:
        answer+=1


print(answer)

Measured memory_bytes: 34196
import java.util.*;
import java.io.*;



public class Main{
    static int INFTY=Integer.MAX_VALUE;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
            
        String str = sc.nextLine();
        char[] arr= new char[4];
        arr[0]=str.charAt(0);
        arr[1]=str.charAt(1);
        arr[2]=str.charAt(2);
        arr[3]=str.charAt(3);

        boolean bool =false;
        if(arr[0]==arr[1]){
            if(arr[2]==arr[3]&&arr[0]!=arr[2]){
                bool=true;   
            }
        }
        if(arr[0]==arr[2]){
            if(arr[1]==arr[3]&&arr[0]!=arr[1]){
                bool=true;   
            }
        }
        if(arr[0]==arr[3]){
            if(arr[1]==arr[2]&&arr[0]!=arr[2]){
                bool=true;   
            }
        }
        if(bool==true){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

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

using ll = long long;
using P = pair<int,int>;

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int s, w;
    cin >> s >> w;

    if(w >= s){
        cout << "unsafe" << "\n";
    }else{
        cout << "safe" << "\n";
    }



    return 0;
}


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

vector<int> v[100010];
bool vis[100010];
int ans, n, m, dist[100010];

int dfs(int u)
{
    vis[u] = 1;
    int sum = 1, maxv = 0;
    for (int i = 0; i < v[u].size(); i++)
    {
        int val;
        if (dist[v[u][i]] == 0)
            val = dfs(v[u][i]);
        else
            val = dist[v[u][i]];
        maxv = max(maxv, val);
    }
    sum += maxv;
    dist[u] = sum;
    return sum;
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
    }
    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
        {
            ans = max(ans, dfs(i));
        }
    }
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 8192
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
m = 0
m2 = 0
var = 0
z = 0
for k in range(N):
  a = grid[k][0]
  if a > m:
    m2 = m
    m = a
    z = k
    if var > 0:
      var = 0
  elif a == m:
    var = var+1
  elif a > m2: 
    m2 = a
if var ==0:
  for k in range(N):
    if k == z:
      print(m2)
    else:
      print(m)
if var > 0:
  for k in range(N):
    print(m)

Measured memory_bytes: 47036
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
string str[40];
int* BubbleSort(int *a, int *b, int n) {
	rep(i,n) {
		for(int j = n - 1; j > i; --j) {
			if(a[j] < a[j-1]) {
				swap(a[j], a[j-1]);
				swap(b[j], b[j-1]);
			}
		}
	}
	return a;
}

int* SelectionSort(int *a, int *b, int n) {
	rep(i,n) {
		int Min = i;
		rep2(j,i,n) {
			if(a[j] < a[Min]) {
				Min = j;
			}
		}
		if(i != Min) {
			swap(a[i], a[Min]);
			swap(b[i], b[Min]);
		}
	}
	return a;
}

void init(int *b, int *c, int n) {	
	rep(i,n) {
		c[i] = str[i][1] - '0';
	}
	rep(i,n) {
		b[i] = i;
	}
}
void p(int *b, int *c, int n) {
	bool f = 1;
	rep(i,n) {
		rep2(j,i,n) {
			if(b[i] > b[j]) {
				if(c[i] == c[j]) f = 0;
			}
		}
	}
	rep(i,n) {
		cout << str[b[i]];
		if(i < n - 1) cout << " ";
	}
	cout << endl;
	if(f) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
}

int main() {
	int n, b[40], c[40];
	cin >> n;
	rep(i,n) {
		cin >> str[i];
	}

	init(b, c, n);
	BubbleSort(c, b, n);
	p(b, c, n);
	init(b, c, n);
	SelectionSort(c, b, n);
	p(b, c, n);

	return 0;
}

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

int main() {
  long long x;
  cin >> x;
  long long tmp = x / 500;
  long long ans = tmp * 1000;
  x %= 500;
  tmp = x / 5;
  ans += tmp * 5;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

int main(){

  string s;
  cin >> s;

  vec a;

  for(ll i=0;i<s.size();i++){
    if(s[i]=='0')a.push_back(0);
    else if(s[i]=='1')a.push_back(1);
    else if(a.size()!=0) a.pop_back();
//    for(ll j=0;j<a.size();j++)cout << a[j] << endl;
  }

  for(ll i=0;i<a.size();i++)cout << a[i] ;

}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005,mod=1000000000;
int n,b[N],c[N],s[100][100],xb[N],xc[N],a[N],ans;
signed main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		string r;
		cin>>r;
		int k=0,zh=0;
		int fl=0;
		for(auto c:r)
		{
			if(c=='.')
			{
				fl=1;
				continue;
			}
			k=k*10+c-'0';
			zh+=fl;
		}
		while(zh<9)
		{
			zh++;
			k*=10;
		}
		int y;
		y=k;
		while(y%2==0)
		{
			xb[i]++;
			y/=2;
		}
		y=k;
		while(y%5==0)
		{
			xc[i]++;
			y/=5;
		}
		s[xb[i]][xc[i]]++;
		if(k%mod==0)
			ans--;
	}
	for(int i=1;i<=n;i++)
		for(int j=max(18-xb[i],0LL);j<=70;j++)
			for(int k=max(18-xc[i],0LL);k<=70;k++)
				ans+=s[j][k];
	cout<<ans/2<<endl;
	return 0;
}


Measured memory_bytes: 6748
d[1001],c;
main(w,n,i,C,W,b){
  for(;scanf("%d%d",&w,&n),w;printf("Case %d:\n%d\n%d\n",++c,d[w],b),bzero(d,4004))
      for(;n--;)
          for(i=w,scanf("%d,%d",&C,&W);i>=W;i--)
              d[i]=fmax(d[i],d[i-W]+C),b=d[i]-d[w]?b:i;
}

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

bool find(vector<int> p, int x) {
  for (int v : p) {
    if (v == x) return true;
  }
  return false;
}

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int d = 0;
  while (true) {
    if (!find(p, x - d)) {
      cout << x - d << endl;
      return 0;
    }
    if (!find(p, x + d)) {
      cout << x + d << endl;
      return 0;
    }
    d++;
  }
  return 0;
}

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

#define reps(i, f, n)	for (int i = f; i < (int)(n); ++i)
#define rep(i, n)		reps (i, 0, n)

int main()
{
	int n, m;
	while(scanf("%d%d", &n, &m), n){
		int p[11] = {0};
		rep(i, n){
			int d, ps;
			scanf("%d%d", &d, &ps);
			p[ps] += d;
		}
		
		for(int i=10; i; --i){
			if(p[i] > m){
				p[i] -= m;
				m = 0;
			}
			else{
				m -= p[i];
				p[i] = 0;
			}
			if(m==0) break;
		}
		
		int ans = 0;
		rep(i, 11)
			ans += p[i] * i;
		
		printf("%d\n", ans);
			
	}
	return 0;
}

Measured memory_bytes: 1188
n = int(input())
a = list(map(int, input().split()))
a_sum = 0
s = []
ans = 0

for i in range(n):
    a_sum += a[i]
    s.append(a_sum)

for i, j in enumerate(a):
    ans += j * (s[n - 1] - s[i])

print(ans % (10 ** 9 + 7))


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

int main()
{
  //a青 b赤 ans青いボールの個数
  ll n, a, b, ans=0;
  cin >> n >> a >> b;

  ans += n / (a + b) * a;
  ll rem = n % (a + b);
  ans += min(rem, a);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}
for i in range(N):
    if i%2==0:#even
        if lv[i] in dev:
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
    else:#odd
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1

max1_ev=[0,0]
max2_ev=[0,0]
max1_od=[0,0]
max2_od=[0,0]
#for i in range(len(dev)):
for v in dev:#max even
    if dev[v]>max1_ev[1]:
        a=max1_ev
        max1_ev=[v,dev[v]]
        max2_ev=a
    elif dev[v]>max2_ev[1]:
        max2_ev=[v,dev[v]]
for v in dod:#max odd
    if dod[v]>max1_od[1]:
        a=max1_od
        max1_od=[v,dod[v]]
        max2_od=a
    elif dod[v]>max2_od[1]:
        max2_od=[v,dod[v]]
if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
else:
    print(min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int a, b;
    cin >> a >> b;
    if (a == 1) a = 14;
    if (b == 1) b = 14;

    if (a > b) cout << "Alice" << endl;
    else if (a < b) cout << "Bob" << endl;
    else cout << "Draw" << endl;
    return 0;
}



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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

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


Measured memory_bytes: 3112
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
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; }

int main(){
  int a,b;  cin >> a >> b;
  cout << 6-a-b;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String[] firstLine = input.readLine().split(" ");
        long A = Long.parseLong(firstLine[0]);
        String op = firstLine[1];
        long B = Long.parseLong(firstLine[2]);

        if (op.equals("+")) {
            System.out.println(A+B);
        } else {
            System.out.println(A-B);
        }
    }
}


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

int main(){
  long long W, H, x, y;
  cin >> W >> H >> x >> y;
  
  double area = (double)(W) * H / 2.0;
  bool flag = (2 * x == W && 2 * y == H);
  
  cout << area << " " << flag << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n1, n2;
  
  while ( 1 ) {
    scanf("%d %d", &n1, &n2);
    if ( n1 == 0 && n2 == 0 ) {
      break;
    }
    if ( n1 < n2 ) {
      printf("%d %d\n", n1, n2);
    } else {
      printf("%d %d\n", n2, n1);
    }
  }
  
  return 0;
}

Measured memory_bytes: 600
object Main {
  def main(args: Array[String]): Unit = {
    val (num, limit) = {
      val nw = io.StdIn.readLine().split(" ").map(_.toInt)
      (nw(0), nw(1))
    }
    val items = new Array[(Int, Int)](num)
    for (i <- 0 until num) {
      val vw = io.StdIn.readLine().split(" ").map(_.toInt)
      items(i) = (vw(0), vw(1))
    }

    val dp = solve(limit, items)
    println(dp(num)(limit))
  }

  def solve(limit: Int, items: Array[(Int, Int)]): Array[Array[Int]] = {
    val dp = Array.ofDim[Int](items.length + 1, limit + 1)

    items.zipWithIndex.foreach { case ((v, w), i) =>
      for (l <- 1 to limit) {
        if (w <= l && dp(i)(l) < dp(i + 1)(l - w) + v) {
          dp(i + 1)(l) = dp(i + 1)(l - w) + v
        } else {
          dp(i + 1)(l) = dp(i)(l)
        }
      }
    }
    dp
  }
}

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

int main(){
  
  int a,b;
  cin >> a >> b;
  
  if( a-1 >= b ){
    
    cout << 2*a-1 << endl;
    
  }
  
  else if( b-1 >= a ){
    
    cout << 2*b-1 << endl;
    
  }
  
  else{
    
    cout << a+b << endl;
    
  }
  
}


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

int main() {
    long x, a, b, t = 0;
    cin >> x;
    vector<pair<long, long>> temp;
    while(pow(t, 5) < 1e16) {
        temp.push_back(make_pair(pow(t, 5), t));
        temp.push_back(make_pair(-pow(t, 5), -t));
        t++;
    }
    bool flag = false;
    rep(i, temp.size()) {
        rep(j, temp.size()) {
            if(temp.at(i).first - temp.at(j).first == x) {
                a = temp.at(i).second;
                b = temp.at(j).second;
                flag = true;
                break;
            }
        }
        if(flag) break;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

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

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	int N;
	cin >> N;
	vi A(N);
	cin >> A;

	int c = 1;
	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 0) c *= 2;
	}

	cout << (int)pow(3, N) - c << endl;


	return 0;
}

Measured memory_bytes: 640