akhauriyash/Code-Regression huggingface dataset:
#N = "?"*(100000)
N = input()
digit = len(N)
mod = 1000000007

# dp[i番目まで][未満かどうか][mod13], 計算量O(10**5 * 2 * 13 * 10)
dp = [[[0]*13 for _ in range(2)] for _ in range(digit+1)]
dp[0][0][0] = 1

d = 1/10
for i in range(digit-1,-1,-1):
  ii = digit-i-1
  d = int((d*10)%13)
  for j in range(2):
    for k in range(13):
      if N[i] == "?":
        for n in range(9+1):
          dp[ii+1][j][(k + n*d) %13] += dp[ii][j][k] %mod
      else:
        n = int(N[i])
        dp[ii+1][j][(k + n*d) %13] += dp[ii][j][k] %mod

print((dp[digit][0][5] + dp[digit][1][5]) %mod)
#print(dp[-10:])

Measured memory_bytes: 90332
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int res = 1;
    for (int i = 0; i < 3; ++i) {
        res *= n;
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
digit=[-1 for _ in range(n)]
for i in range(m):
    s,c=map(int,input().split())
    if(digit[s-1]==-1):
        digit[s-1]=c
    elif(digit[s-1]!=c):
        print(-1)
        sys.exit()

ans=""

if(n>1 and digit[0]==0):
    print(-1)
    sys.exit()
elif(n>1 and digit[0]==-1):
    digit[0]=1

for i in range(n):
    ans += str(digit[i]) if digit[i]!=-1 else "0"
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
#include <algorithm>
#define N 105
#define EPS 1e-8
#define reg register
typedef double real;
const real PI=3.1415926535897932384626433832795;
int n;
real x[N],y[N],d[N];
inline real abs(real a){return a<0?-a:a;}
inline real crm(real x1,real y1,real x2,real y2){return x1*y2-x2*y1;}
int main() {
	reg int i,j,m;
	reg char f;
	reg real dif;
	scanf("%d",&n);
	for(i=1;i<=n;++i) scanf("%lf%lf",x+i,y+i);
	if(n<=2) {
		for(i=1;i<=n;++i) printf("%.12lf\n",1.0/n);
		return 0;
	}
	for(i=1;i<=n;++i) {
		m=0;
		for(j=1;j<=n;++j) if(i!=j) d[m++]=atan2(y[j]-y[i],x[j]-x[i]);
		std::sort(d,d+m);
		d[m]=d[0]+2*PI;
		f=0;
		for(j=0;j<m;++j) {
			dif=d[j+1]-d[j];
			if(abs(dif)>PI-EPS) {
				f=1;
				printf("%.12lf\n",dif/(2*PI)-0.5);
				break;
			}
		}
		if(!f) puts("0.0");
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(void){
    char a[2];
    cin>>a[0]>>a[1];
    for(int i=0;i<2;i++){
        if(a[i]=='A')a[i]='0';
        if(a[i]=='B')a[i]='1';
        if(a[i]=='C')a[i]='2';
        if(a[i]=='D')a[i]='3';
        if(a[i]=='E')a[i]='4';
        if(a[i]=='F')a[i]='5';
    }
    if(a[0]>a[1]){
        cout<<'>'<<endl;
    }else if(a[0]<a[1]){
        cout<<'<'<<endl;
    }else{
        cout<<'='<<endl;
    }
}

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

int main(){
	vector<int> a(3);
	while(cin>>a[0]>>a[1]>>a[2],a[0]||a[1]||a[2]){
		int n;
		cin>>n;
		sort(a.begin(),a.end());
		double t=(double)a[0]*a[0]+a[1]*a[1];
		// cout<<t<<endl;
		for(int i=0;i<n;i++){
			int r;
			cin>>r;
			if(4*r*r>t) cout<<"OK\n";
			else cout<<"NA\n";
		}
	}
	return 0;
}

Measured memory_bytes: 1168
n = int(input())
p = [None] * (n + 1)
m = [[None for i in range(n+1)] for j in range(n+1)]

for i in range(1, n+1):
    p[i-1], p[i] = map(int, input().split())

for i in range(1, n+1):
    m[i][i] = 0

# print(p)
# print(m)

for l in range(2, n+1):  # lはchainの長さ。最終的にl = n。
    for i in range(1, n-l+2):  # i = チェーンの左側
        j = i + l - 1 # j = チェーンの右端
        m[i][j] = 1000000000

        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j])

print(m[1][n])



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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> hs(n);
  for_each(hs.begin(), hs.end(), [](auto &h) {
    cin >> h;
  });
  sort(hs.begin(), hs.end());
  int ans = 1000000007;
  for (int i = 0; i + k - 1 < n; i++) {
    ans = min(ans, hs[i + k - 1] - hs[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
s=input()
t=input()
n=len(s)
f=0
if s==t:
    f=1
for i in range(n):
    ans=0
    for j in range(i):
        
        if s[n+j-i]==t[j]:
            ans+=1
    for j in range(n-i):
        
        if s[j]==t[i+j]:
            
            ans+=1
    if ans==n:
        f=1
    
print("Yes" if f==1 else "No")
            

    


Measured memory_bytes: 9080
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int charmap[256];

int calc(const string &str, char suit, char suit2){
  int ret = charmap[str[0]];
  if(str[1] == suit) ret += 26;
  else if(str[1] == suit2) ret += 13;
  return ret;
}

int main(){
  charmap['2'] = 0; charmap['3'] = 1; charmap['4'] = 2;
  charmap['5'] = 3; charmap['6'] = 4; charmap['7'] = 5;
  charmap['8'] = 6; charmap['9'] = 7;
  charmap['T'] = 8;
  charmap['J'] = 9;
  charmap['Q'] = 10;
  charmap['K'] = 11;
  charmap['A'] = 12;

  string s;
  while(cin >> s, s != "#"){
    string c[4][13];
    int ans[2] = { 0, 0 };
    REP(i,4) REP(j,13) cin >> c[i][j];
    int oya = 0;
    const char suit = s[0];

    REP(i,13){
      vector<pair<int, int> > v;
      const char suit2 = c[oya][i][1];
      REP(j,4){
        v.push_back(make_pair(calc(c[(oya + j) % 4][i], suit, suit2),
                              (oya + j) % 4));
      }
      sort(v.rbegin(), v.rend());
      oya = v[0].second;
      ans[oya % 2]++;
    }

    if(ans[0] > ans[1]) printf("NS %d\n", ans[0] - 6);
    else printf("EW %d\n", ans[1] - 6);
  }
  return 0;
}

Measured memory_bytes: 0
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    h,n=map(int,readline().split())
    ab=np.array([list(map(int,readline().split())) for _ in range(n)],dtype=np.int64)
    a=ab[:,0]
    b=ab[:,1]

    dp=np.zeros(h+1,dtype=np.int64)
    for i in range(1,h+1):
        dp[i]=(dp[np.maximum(0,i-a)]+b).min()

    print(dp[h])

if __name__=="__main__":
    main()

Measured memory_bytes: 12608
a,b,n = map(int,input().split())
#(a*x)//b - a*(x//b) の最大値を求める
if b > n:
    # ax//b だけ考えればいい
    print(a*n//b)
else:
    # ax//b か　bより大きいx で探す
    x = 2*b-1
    first = a*(b-1)//b
    second = (a*x)//b - a*(x//b)
    print(first if first >= second else second)

Measured memory_bytes: 9024
import sys


input_array = list()
N, D = map(int, input().split())
if 1 <= N and N <= 2*10**5:
    for _ in range(N):
        input_array.append(map(int, input().split()))

count = 0
for x0, x1 in input_array:
    if 0 <= D and D <= 2*10**5:
        if abs(x0) <= 2*10**5 and abs(x1) <= 2*10**5:            
            if D >= (int(x0)**2 + int(x1)**2)**(1/2):
                count += 1
print(count)

Measured memory_bytes: 96572
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll a[maxn]; 

int gcd(int a,int b)
{
    return b>0?gcd(b,a%b):a;
}

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



Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 1e5+10;
int a[N];
int main(){
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5])
        cout <<"Yes\n";
    else
        cout <<"No\n";
    
    return 0;
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A = [int(i) for i in input().split()]

max_dist = A[0] + (K - A[-1])
for i in range(1, N):
    if A[i] - A[i-1] > max_dist:
        max_dist = A[i] - A[i-1]

print(K - max_dist)

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

int main(){
  int n;
  cin >> n;
  int x[100] = {};
  int y[100] = {};
  long long h[100] = {};
  int a;
  int b;
  long long c;
  int fl = 0;
  for(int i = 0; i < n ; i++){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i] != 0 && fl == 0){
      a = x[i];
      b = y[i];
      c = h[i];
      fl = 1;
    }
  }
  for(int i = 0; i <= 100; i++){
    for(int j = 0; j <= 100; j++){
      int flag = 0;
      long long height = abs(i-a)+abs(j-b)+c;
      for(int k = 0; k < n; k++){
        if((height < (h[k]+abs(x[k]-i)+abs(y[k]-j)) && h[k] >0) || height > (h[k]+abs(x[k]-i)+abs(y[k]-j))){
          flag = 1;
          break;
        }
      }
      if(flag == 0) cout <<i << " "<< j <<" " <<  height << endl;
    }
  }
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <time.h>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9

const double eps = 1e-10;


int main()
{
    int n;
    cin >> n;
    cout <<"ABC"<<n<<endl;
    return 0;
}



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

int main(){
  int N;
  cin >> N;
  map<string, int> S;
  string tmp;
  
  cin >> tmp;
  S[tmp] = 0;
  int n=1;
  for(int i=1; i<N; i++){
    cin >> tmp;
    if(!S.count(tmp)){
      S[tmp] = i;
      n++;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 19204
#include<stdio.h>
#include<string.h>
int main(void){
    while(1){
        char x[1000];
        int i,sum = 0;
        scanf("%s",&x);
        if(*x == '0') break;
        for(i = 0;i < strlen(x);i++){
            sum += x[i] - '0';
        }
    printf("%d\n",sum);
    }
    return 0;
}


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

#define rep(i, n) for(int i = 0;i < (n);++i)
using ll = long long;

struct P {
  std::string S;
  ll num;
};
bool P_comp(P& l, P& r) {
  return l.num > r.num;
}

int main(int argc, char** argv) {
  ll N;
  std::cin >> N;
  std::vector<std::string> S(N);
  rep(i, N) std::cin >> S[i];
  std::sort(S.begin(), S.end());
  std::string prev_s = "";
  std::vector<P> S_box;
  ll dim {-1};
  for (auto i = 0;i < N;++i) {
    if (prev_s != S[i]) {
      P tmp;
      tmp.S = S[i]; tmp.num = 1;
      prev_s = S[i];
      S_box.push_back(tmp);
      ++dim;
    } else {
      ++S_box[dim].num;
    }
  }
  std::sort(S_box.begin(), S_box.end(), P_comp);
  int max_num = S_box[0].num;
  std::vector<std::string> S_sorted;
  for (auto i = 0;i <= dim;++i) {
    if (S_box[i].num == max_num) S_sorted.push_back(S_box[i].S);
    else break;
  }
  std::sort(S_sorted.begin(), S_sorted.end());
  for (auto& e : S_sorted) std::cout << e << '\n';
}


Measured memory_bytes: 26088
#include<iostream>
using namespace std;
#define NIL -1
int n,ch[200],V[200][200],d[200],a;
void count(int x,int reach){
    d[x]=reach;
    for(int i=1;i<=ch[x];i++){
        int p=V[x][i];
        if(d[p]==NIL||d[p]>reach+1) count(p,reach+1);
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a>>ch[i];
        d[i]=NIL;
        for(int j=1;j<=ch[i];j++){
            cin>>V[i][j];
        }
    }
    count(1,0);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>
int INF = 1e9;
int main(){
    while(1){
        int N, M;
        std::cin >> N >> M;
        if(N == 0 && M == 0)break;
        std::vector<int> C(M), x(N);
        for(int i = 0; i < M; i++) std::cin >> C[i];
        for(int i = 0; i < N; i++) std::cin >> x[i];
        int dp[N + 1][256];
        for(int i = 0; i < N + 1; i++) for(int k = 0; k < 256; k++) dp[i][k] = INF;
        dp[0][128] = 0;
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                for(int k = 0; k < 256; k++){
                    if(k + C[j] > 255) dp[i + 1][255] = std::min(dp[i + 1][255], dp[i][k] + std::abs(255 - x[i])*std::abs(255 - x[i]));
                    else if(k + C[j] < 0) dp[i + 1][0] = std::min(dp[i + 1][0], dp[i][k] + std::abs(0 - x[i])*std::abs(0 - x[i]));
                    else dp[i + 1][k + C[j]] = std::min(dp[i + 1][k + C[j]], dp[i][k] + std::abs(k + C[j] - x[i])*std::abs(k + C[j] - x[i]));
                }
            }
        }
        int ans = INF;
        for(int j = 0; j < 256; j++) ans = std::min(ans, dp[N][j]);
        std::cout << ans << std::endl;
    }
}


Measured memory_bytes: 23144
n = gets.strip.to_i
nums = gets.strip.split(" ").map do |i|
  i.to_i
end
ans = 1
flag = true
ans = 0 if nums.include?(0)
n.times{|i|
  ans *= nums[i] if flag
  flag = false if ans!=-1 && ans > 10**18
  ans = -1 unless flag
}
puts ans if flag
puts (-1) unless flag


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

int main(){
	long long a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	long long combined = min(x,y);
	long long sum=0;
	sum+= min(2*combined*c,combined*(a+b));
	if (x>y) {
		sum+=min((x-y)*a,2*(x-y)*c);
	}
	else{
		sum+=min((y-x)*b,2*(y-x)*c);
	}
	cout << sum;
	
 }


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define inlien inline
#define retrun return
#define cpnst const
typedef long long ll;
cpnst ll mod=1e9+7;
ll fac[111111],inv[111111];
inline ll qpow(ll x,ll k)
{ll r=1;for(;k;k>>=1,(x*=x)%=mod)if(k&1)(r*=x)%=mod;return r;}
inline ll C(ll n,ll r)
{return fac[n]*inv[r]%mod*inv[n-r]%mod;}
inline ll inf(ll n)
{return inv[n]*fac[n-1]%mod;}
ll f[111111],s[111111];
int n,m,k;
inline void pre()
{
	register int i,ii;
	cpnst int v=1e5;
	fac[0]=1;
    for(i=1;i<=v;i++)fac[i]=fac[i-1]*i%mod;
	for(i=v-1,inv[v]=qpow(fac[v],mod-2);~i;i--)
		inv[i]=inv[i+1]*(i+1)%mod;
	for(i=1;i<=v;i++)
	{
		(f[i]+=qpow(k,i)+mod*mod)%=mod;
		for(ii=i*2;ii<=v;ii+=i)
			(f[ii]-=f[i])%=mod;
	}for(i=1;i<=v;i++)
		for(ii=i;ii<=v;ii+=i)
			(s[ii]+=f[i]*inf(i))%=mod;
}
struct edg
{int p,t;}e[222222];
int h[111111],tot=1;
inlien void build(int x,int y)
{e[++tot]=(edg){h[x],y},h[x]=tot;}
int dfn[111111],low[111111],dep,
stk[111111],stv[111111],top;
int col[111111],cnt,siz[111111],miz[111111];
inline int min(int x,int y)
{return(x<y)?x:y;}
void tarjan(int p=1,int f=-1)
{
	dfn[p]=low[p]=++dep;
	for(register int i=h[p];i;i=e[i].p)
	{
		if(i==(f^1))continue;
		int to=e[i].t;
		if(!dfn[to])
		{
			stk[++top]=p,stv[top]=to,tarjan(to,i);
			low[p]=min(low[p],low[to]);
			if(dfn[p]<=low[to])
			{
				cnt++;
				while(1)
				{
					miz[cnt]++;
					int x=stk[top],y=stv[top];
					if(col[x]!=cnt)col[x]=cnt,siz[cnt]++;
					if(col[y]!=cnt)col[y]=cnt,siz[cnt]++;
					top--;
					if(x==p&&y==to)break;
				}
			}
		}else if(dfn[p]>dfn[to])
			stk[++top]=p,stv[top]=to,low[p]=min(low[p],dfn[to]);
	}
}
int x[111111],y[111111];
int main()
{
	scanf("%d%d%d",&n,&m,&k),pre();
	register int i;
	for(i=1;i<=m;i++)
		scanf("%d%d",x+i,y+i),build(x[i],y[i]),build(y[i],x[i]);
	for(i=1;i<=n;i++)if(!dfn[i])tarjan(i);
	ll ans=1;
	for(i=1;i<=cnt;i++)
	{
		if(miz[i]==1)(ans*=k)%=mod;
		else if(siz[i]==miz[i])(ans*=s[miz[i]])%=mod;
		else(ans*=C(k+miz[i]-1,miz[i]))%=mod;
	}printf("%lld\n",ans);
}
/*
Giving the world a better yourself is giving yourself a better world. 
*/

Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define ll long long
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);
#define loop(n) for (int i = 0; i < n; i++)
#define double long double
#define mod 998244353
#define pi 3.1415926535897
#define F first
#define S second
#define pb push_back

using namespace std;

// string multiply(string num1, string num2)
// {
// 	int len1 = num1.size();
// 	int len2 = num2.size();
// 	if (len1 == 0 || len2 == 0)
// 		return "0";

// 	// will keep the result number in vector
// 	// in reverse order
// 	vector<int> result(len1 + len2, 0);

// 	// Below two indexes are used to find positions
// 	// in result.
// 	int i_n1 = 0;
// 	int i_n2 = 0;

// 	// Go from right to left in num1
// 	for (int i = len1 - 1; i >= 0; i--)
// 	{
// 		int carry = 0;
// 		int n1 = num1[i] - '0';

// 		// To shift position to left after every
// 		// multiplication of a digit in num2
// 		i_n2 = 0;

// 		// Go from right to left in num2
// 		for (int j = len2 - 1; j >= 0; j--)
// 		{
// 			// Take current digit of second number
// 			int n2 = num2[j] - '0';

// 			// Multiply with current digit of first number
// 			// and add result to previously stored result
// 			// at current position.
// 			int sum = n1 * n2 + result[i_n1 + i_n2] + carry;

// 			// Carry for next iteration
// 			carry = sum / 10;

// 			// Store result
// 			result[i_n1 + i_n2] = sum % 10;

// 			i_n2++;
// 		}

// 		// store carry in next cell
// 		if (carry > 0)
// 			result[i_n1 + i_n2] += carry;

// 		// To shift position to left after every
// 		// multiplication of a digit in num1.
// 		i_n1++;
// 	}

// 	// ignore '0's from the right
// 	int i = result.size() - 1;
// 	while (i >= 0 && result[i] == 0)
// 		i--;

// 	// If all were '0's - means either both or
// 	// one of num1 or num2 were '0'
// 	if (i == -1)
// 		return "0";

// 	// generate the result string
// 	string s = "";

// 	while (i >= 0)
// 		s += std::to_string(result[i--]);

// 	return s;
// }

bool isOverflow(long long a, long long b)
{
	// Check if either of them is zero
	if (a == 0 || b == 0)
		return false;

	long long result = a * b;
	if (a == result / b)
		return false;
	else
		return true;
}

signed main()
{
	fast;
	int test = 1;
	// cin >> test;
	for (int index = 0; index < test; index++)
	{
		ll n;
		cin >> n;
		vector<double> v(n);
		bool zero = 0;
		loop(n)
		{
			cin >> v[i];
			if (v[i] == 0)
			{
				zero = 1;
			}
		}
		if (zero)
		{
			cout << "0" << endl;
			continue;
		}
		// sort(v.begin(), v.end(), greater<int>());
		double ans = v[0];
		bool flag = 0;
		for (int i = 1; i < v.size(); i++)
		{
			if (isOverflow(ans, v[i]))
			{
				flag = 1;
				break;
			}
			ans *= v[i];
			if (ans > (unsigned long long int)1000000000000000000)
			{
				flag = 1;
				break;
			}
		}
		if (flag)
			cout << "-1" << endl;
		else
		{
			cout << (ll)ans << endl;
		}
	}
}


Measured memory_bytes: 4784
import re
S = input()
key = "keyence"
if re.fullmatch(r'(.*keyence)|(k.*eyence)|(ke.*yence)|(key.*ence)|(keye.*nce)|(keyen.*ce)|(keyenc.*e)|(keyence.*)', S):
    ans = True
else:
    ans = False



print("YES" if ans else "NO")

Measured memory_bytes: 3188
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(N):
    if A[i] >= BC[j][1]:
        break
    else:
        A[i] = BC[j][1]
        BC[j][0] -= 1
        if BC[j][0] == 0:
            j += 1
        if j >= M:
            break
print(sum(A))
    

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


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

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

    int count = 0;
    for (int i = 2; i < n; ++i) {
        int p1 = p[i - 2];
        int p2 = p[i - 1];
        int p3 = p[i];
        
        count += p2 != min({p1, p2, p3}) && p2 != max({p1, p2, p3}) ;
        
    }

    cout << count << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N,M; cin >> N >> M;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    sort(A.begin(),A.end(),greater<int>());
    int S = 0;
    for (auto a : A) S += a;
    int cnt = 0;
    if (4*M*A[M-1] >= S) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define NUM 205

struct Info{

	int W,H;
};

int V; //頂点数
vector<int> G[NUM];
int match[NUM];
bool used[NUM];
Info info[105];

void add_edge(int from,int to){
	G[from].push_back(to);
	G[to].push_back(from);
}

int dfs(int node_id){
	used[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		int adj_node_id = G[node_id][i],pair_id = match[adj_node_id];
		if((pair_id < 0)||
				(used[pair_id] == false && dfs(pair_id) == true)){

			match[node_id] = adj_node_id;
			match[adj_node_id] = node_id;
			return true;
		}
	}
	return false;
}


int bipartie_matching(){
	int ret = 0;
	for(int i = 0; i < V; i++)match[i] = -1; //ペアなしにしておく
	for(int node_id = 0; node_id < V; node_id++){
		if(match[node_id] < 0){ //node_idにペアがいない場合
			for(int i = 0; i < V; i++)used[i] = false;
			if(dfs(node_id)){ //増加パスが存在する場合
				ret++;
			}
		}
	}
	return ret;
}


int main(){

	int N;
	scanf("%d",&N);

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

		scanf("%d %d",&info[i].W,&info[i].H);
	}

	for(int from = 0; from < N; from++){
		for(int to = 0; to < N; to++){
			if((info[from].W < info[to].W && info[from].H < info[to].H) ||
					(info[from].H < info[to].W && info[from].W < info[to].H)){
				add_edge(from,N+to);
			}
		}
	}

	V = 2*N;

	printf("%d\n",N-bipartie_matching());

	return 0;
}



Measured memory_bytes: 3316
import sys 
from collections import deque
import numpy as np
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def Main():
    n,m,x = IL()
    table = np.zeros(m,dtype=int)
    c = deque()
    a = deque()
    for _ in range(n):
        tmp = deque(LI())
        c.append(tmp.popleft())
        a.append(tmp)

    ans = -1
    for bit in range(2**n):
        tmp = 0
        buff = np.zeros_like(table)
        for i in range(n):
            if (bit>>i)&1:
                tmp += c[i]
                buff += a[i]
        if np.all(buff>=x):
            if ans==-1 or tmp<ans:
                ans = tmp
    print(ans)
    return

if __name__=='__main__':
    Main()

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

int main(void){
    int N, K;
    cin >> N >> K;
    int a = 1;
    for(int n=0;n<N;n++){
        a = min(a * 2, a + K);
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a(int n){
  int b=0;
  for(int i=1; i<=n; i++){
    if(n%i == 0)
      b++;
  }
  return b;
}
int main(){
  int n; cin>>n;
  int ans=0;
  for(int i=1; i<=n; i+=2){
    if(a(i) == 8)
      ans++;
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#include <atcoder/mincostflow>

#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
#define INF2 100000000
//const long long MOD = 1000000007;
long long MOD = 998244353;

using namespace std;
using namespace atcoder;

char str[55][55];

void solve()
{
    int n, m;
    scanf("%d%d", &n, &m);
    int i, j;
    for (i = 0; i < n; i++) {
        scanf("%s", str[i]);
    }
#define POSI(i,j) ((i)*m+(j))

    int num = n * m;

    vector<int> v;
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            if (str[i][j] == 'o') v.push_back(POSI(i, j));
        }
    }

    int sizv = v.size();
    mcf_graph<int, long long> g(num + 2);
    int s = num, t = s + 1;
    const long long BIG = 1000;

    int k;
    for (k = 0; k < sizv; k++) {
        int i0 = v[k] / m;
        int j0 = v[k] % m;
        g.add_edge(s, v[k], 1, i0+j0);
    }
    for (i = 0; i < num; i++) {
        int i0 = i / m;
        int j0 = i % m;
        g.add_edge(i, t, 1, BIG-i0-j0);
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            if (str[i][j] == '#') continue;

            {
                int i2 = i + 1, j2 = j;
                if (i2 < n && str[i2][j2]!='#') {
                    g.add_edge(POSI(i, j), POSI(i2, j2), sizv, 0);
                }
            }
            {
                int i2 = i, j2 = j+1;
                if (j2 < m && str[i2][j2] != '#') {
                    g.add_edge(POSI(i, j), POSI(i2, j2), sizv, 0);
                }
            }
        }
    }

    auto result = g.flow(s, t, sizv);
    printf("%lld\n", sizv*BIG-result.second);

    return;
}

int main()
{
#if 1
    solve();
#else
    pre();

    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}



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

double Tm=380000.0; // 地球から月までの距離
double tk=1800.0+100.0; // 月の中心からかぐやまでの距離
double am=2.0*M_PI/(2500000.0/60.0); // 月の回る速度
double ak=2.0*M_PI/120.0; // かぐやの回る速度
double dt=0.01;
double nowt=0.0;
double anst=0.0;

int main(){
  double m,t;
  cin >> m >> t;
  double Tm0 = m*M_PI/180.0;
  while(nowt + dt < t){
    double xm=Tm*cos(am*nowt+Tm0);
    double ym=Tm*sin(am*nowt+Tm0);
    double zm=0;
    double xk=-tk*sin(ak*nowt)+xm;
    double yk=ym;
    double zk=tk*cos(ak*nowt)+zm;
    double a = xk*xk+yk*yk+zk*zk;
    double b = -(xm*xk+ym*yk+zm*zk);
    double c = Tm*Tm-1800.0*1800.0;
    double D = b*b-a*c;
    if(D >= 0.0){
      double s = (-b+sqrt(D))/a;
      if(s < 1.0) anst += dt;
    }
    nowt += dt;
  }
  cout << anst << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
const int mod = 998244353;
vector <int> v;
int mem[2][maxn][maxn][maxn];
int N, K;

int dp(int state, int cur, int moves, int need) {
  if(moves > K || moves > N) return 0;
  if(cur == v.size()) {
    return need == 0;
  }
  int &ans = mem[state][cur][moves][need];
  if(ans != -1) return ans;
  ans = dp(0, cur + 1, moves, need);
  if(state == 0) {
    ans += dp(1, cur, moves + 1, need + 1);
    ans %= mod;
    for(int i = 1; i <= v[cur] && i <= need; i++) {
      ans += dp(0, cur + 1, moves, need - i);
      ans %= mod;
    }
  } else {
    ans += dp(1, cur, moves + 1, need + 1);
    ans %= mod;
  }
  return ans;
}
int main() {
  string s;
  cin >> s >> K;
  N = s.size();
  int cnt = 0;
  for(auto i : s) {
    if(i == '0') {
      v.push_back(cnt);
      cnt = 0;
    }
    else cnt = cnt + 1;
  }
  v.push_back(cnt);
  memset(mem, -1, sizeof mem);
  cout << dp(0, 0, 0, 0) << endl;
  return 0;
}


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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll m = min({a, b, c, d, e});
  cout << 4 + (n + (m - 1)) / m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;
typedef long long ll;

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

int main(){
    int n,k;
    cin>>n>>k;
    cout<<n-k+1<<endl;
    
    
    return 0;
}



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

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};
#define PI 3.141592653589793238

bitset<5555> dp;
ll N, K;
VL a;

bool check(ll k) {
    dp.reset();
    dp.set(0);
    REP(j, N) {
        if(k == j) continue;
        dp |= dp << a[j];
    }
    FOR(val, max(K - a[k], 0LL), K) {
        if(dp.test(val)) {
            return true;
        }
    }
    return false;
}
signed main() {
    cin >> N >> K;
    a.resize(N);
    VECCIN(a);
    sort(All(a));
    ll lb = -1, ub = N;
    while(ub - lb > 1) {
        ll mid = (ub + lb) / 2;
        if(check(mid))
            ub = mid;
        else
            lb = mid;
    }
    cout << lb + 1 << "\n";
}


Measured memory_bytes: 256
I[]={17144357,278595846,67540999,117808793,117835935,0x92029d9c,285577363,16814339};unsigned char*C="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?",*strchr(),*L="68443586484588538455886888366866",*B=I;b,l;main(c){for(;c=getchar(),c+1;)if(c-10)for(c=strchr(C,c)-C,b=b<<(L[c]-48)|B[c],l+=L[c]-48;l>4;putchar(C[b>>l&31]))l-=5;else l&&putchar(C[(b<<=5-l)&31]),l=0,putchar(c);exit(0);}

Measured memory_bytes: 0
from collections import defaultdict
N, M = map(int, input().split())
H = list(map(int, input().split()))
adj = defaultdict(set)
for i in range(M):
    a, b = map(int, input().split())
    adj[a-1].add(H[b-1])
    adj[b-1].add(H[a-1])
ans = 0
for i in range(N):
    adj[i].add(-1)
    if H[i] > max(adj[i]):
        ans += 1
print(ans)

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

using namespace std;

typedef long long int ll;

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

  ll n, m;
  cin >> n >> m;
  int i = 1, j = 1 + m;
  vector < pair < ll, ll > > ans;
  while(i < j){
    ans.push_back({i, j});
    i++;
    j--;
  }
  i = 2 + m;
  j = 1 + 2 * m;
  while(i < j){
    ans.push_back({i, j});
    i++;
    j--;
  }

  for(auto i : ans) cout << i.first << " " << i.second << endl;
}


Measured memory_bytes: 5276
s=int(input())
a=[s]
temp=len(set(a))
for i in range(1,1000000):
    if a[i-1]%2:
        a.append(3*a[i-1]+1)
    else:
        a.append(a[i-1]/2)
        
    if temp!=len(set(a)):
        temp=len(set(a))
    else:
        break
print(len(a))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
  int INPUT;
  int A=0, B=0, C=0, D=0;
  cin >> INPUT;
  D = (INPUT % 10);
  C = ((INPUT-D) % 100) / 10;
  B = ((INPUT-D-C) % 1000) / 100;
  A = (INPUT - B - C - D) / 1000;

  if(A+B+C+D==7){
    cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
    goto END;
  }
  else if(A+B+C-D==7){
    cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
    goto END;
  }
  else if(A+B-C+D==7){
    cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
    goto END;
  }
  else if(A-B+C+D==7){
    cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
    goto END;
  }
  else if(A-B-C+D==7){
    cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
    goto END;
  }
  else if(A+B-C-D==7){
    cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
    goto END;
  }
  else if(A-B+C-D==7){
    cout << A << "-" << B << "+" << C << "-" << D << "=7"  << endl;
    goto END;
  }
  else if(A-B-C-D==7){
    cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
    goto END;
  }
END:
  return 0;
}


Measured memory_bytes: 256
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (trial (read))
         (as (make-array n :element-type 'uint32))
         (table (make-hash-table :test #'eq :size n)))
    (dotimes (i n)
      (setf (aref as i) (read-fixnum)))
    (let ((gain 0)
          (prevmin #xffffffff)
          (res 0))
      (declare (fixnum gain res prevmin))
      (sb-int:dovector (a as)
        (setf gain (max gain (- a prevmin))
              prevmin (min prevmin a)))
      (sb-int:dovector (a as)
        (when (gethash (- a gain) table)
          (incf res))
        (setf (gethash a table) t))
      (println res))))

#-swank (main)


Measured memory_bytes: 26088
# define _CRT_SECURE_NO_WARNINGS

# include <cstdio>

char field[12][12];

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

void dfs(int x, int y) {
	field[y][x] = '0';
	for (int i = 0; i < 4; ++i) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (0 <= nx&&nx < 12 && 0 <= ny&&ny < 12 && field[ny][nx] == '1') {
			dfs(nx, ny);
		}
	}
}

int solve() {
	int res = 0;
	for (int i = 0; i < 12; ++i) {
		for (int j = 0; j < 12; ++j) {
			if (field[i][j] == '1') {
				dfs(j, i);
				++res;
			}
		}
	}
	return res;
}

int main() {
	while (1) {
		bool flag = false;
		for (int i = 0; i < 12; ++i) {
			if (scanf("%s", field[i]) == EOF)
				flag = true;
		}
		if (flag)
			break;
		printf("%d\n", solve());
	}
	return 0;
}

Measured memory_bytes: 968
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<memory.h>
#include<ctime>
#include<cstdio>
#include<map>
#include<stack>

using namespace std;

int main()
{
	int n;
	long long ans=0;
	int num[205];
	cin>>n;
	for(int i=0;i<n*2;i++)
	{
		cin>>num[i];
	}
	sort(num,num+n*2);
	for(int i=0;i<n*2;i+=2)
	{
		ans+=num[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#081_D
n = int(input())
a = list(map(int, input().split()))
m = 0
for i in range(n):
    if abs(a[i]) > abs(m):
        m = a[i]
        m_idx = i
        
if m == 0:
    print(0)
elif m > 0:
    print(2 * n)
    for i in range(1, n+1):
        if i == 1:
            print(m_idx+1, 1)
            print(m_idx+1, 1)
        else:
            print(i-1, i)
            print(i-1, i)
else:
    print(2 * n)
    for i in range(n, 0, -1):
        if i == n:
            print(m_idx+1, n)
            print(m_idx+1, n)
        else:
            print(i+1, i)
            print(i+1, i)

Measured memory_bytes: 3064
#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++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    string s;
    cin >> s;
    int len = s.size();
    cout << s.front() << len - 2 << s.back();
    return 0;
}

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

int d[33];
int main()
{
int n,s=0;
cin>>n;
int a[n+1];
for(int i=0;i<n;i++)cin>>a[i];
s=accumulate(a,a+n,0);
for(int i=0;i<n;i++)if(s-a[i]<=a[i])return 0&puts("No");
puts("Yes");

}



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

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

    int n;
    cin >> n;
    vector<int> A(n);
    map<int, int> mp;

    int ma = 0;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        mp[A[i]]++;
        ma = max(ma, A[i]);
    }
    
    int sm = 0;
    for(auto x : mp){
        if(x.first != ma){
            sm = max(sm, x.first);
        }
    }

    for(int i = 0; i < n; i++){
        if(A[i] == ma){
            if(mp[A[i]] > 1){
                cout << A[i] << endl;
            }else{
                cout << sm << endl;
            }
        }else{
            cout << ma << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 7936
rs = list(input())


s_count = rs.count('S')
ans = 0

if s_count == 1:
    if rs[1] == 'S':
        ans = 1
    else:
        ans = 2
elif s_count == 2:
    ans = 1
elif s_count == 0:
    ans = 3
else:
    ans = 0
print(ans)



Measured memory_bytes: 9032
s = str(input()); n = len(s)
gx,gy = map(int,input().split())
Yoko = []; Tate = []
Flag = 0; cnt = 0
Max_x = 0; Max_y = 0
for i in range(n):
  if s[i] == "F":
    cnt += 1
    if i == n-1: #最後なら登録
      if Flag == 0:
        Max_x += cnt
        Yoko.append(cnt)
      else:
        Max_y += cnt
        Tate.append(cnt)      
  else: #T
    if Flag == 0:
      Max_x += cnt
      Yoko.append(cnt)
    else:
      Max_y += cnt
      Tate.append(cnt)
    cnt = 0
    Flag = Flag^1
#print(Yoko,Tate)
MAX_dpx = Max_x*2+1
dp = [0 for _ in range(MAX_dpx)]
dp[Max_x] = 1

for i,x in enumerate(Yoko):
  p = [0 for _ in range(MAX_dpx)]
  p,dp = dp,p
  for j in range(MAX_dpx):
    if i == 0: #i=0の時は右向きだけ
      if 0<=j+x<MAX_dpx:
        dp[j+x] = max(dp[j+x], p[j])
    else:
      if 0<=j+x<MAX_dpx:
        dp[j+x] = max(dp[j+x], p[j])
      if 0<=j-x<MAX_dpx:
        dp[j-x] = max(dp[j-x], p[j])
  #print(dp)
#print(dp)
#print(gx+Max_x,MAX_dpx)
if gx+Max_x >= MAX_dpx or gx+Max_x < 0 or dp[gx+Max_x] == 0:
  print("No");exit()

MAX_dpy = Max_y*2+1
dp = [0 for _ in range(MAX_dpy)]
dp[Max_y] = 1

for i,y in enumerate(Tate):
  p = [0 for _ in range(MAX_dpy)]
  p,dp = dp,p
  for j in range(MAX_dpy):
    if 0<=j+y<MAX_dpy:
      dp[j+y] = max(dp[j+y], p[j])
    if 0<=j-y<MAX_dpy:
      dp[j-y] = max(dp[j-y], p[j])
  #print(dp)
#print(dp)
if gy+Max_y >= MAX_dpy or gy+Max_y < 0 or dp[gy+Max_y] == 0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 91140
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!='+')or('+X'in e)*('+X='not in e)or('=X'in e)*(e[-1]==t):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')


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

int main() {
    string s;
    cin >> s;
    unsigned long ans{0}, now{0};
    for(const auto c : s)ans = max(ans, now = (c == 'A' || c == 'T' || c == 'C' || c == 'G' ? now + 1 : 0));
    cout << ans << endl;
    return 0;
}

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

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)

using namespace std;
using ll = long long;

int a[3005][3005];
ll dp[3005][3005][4];

int main() {
    int R, C, n;
    cin >> R >> C >> n;
    rep(i, n) {
        int r , c, v;
        cin >> r >> c >> v;
        a[r - 1][c - 1] = v;
    }

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

    ll ans = 0;
    rep(k, 4) chmax(ans, dp[R - 1][C - 1][k]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 320528
#include <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>

#define MAX_N 200005

int N;
int A[MAX_N];

long long sum = 0;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
		sum += A[i];
	}
	long long x = A[1], y, ans = LLONG_MAX;
	for (int i = 2; i <= N; i++) {
		y = sum - x;
		ans = std::min(ans, std::abs(x - y));
		x += A[i];
	}
	printf("%lld\n", ans);
	return 0;
}

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


int main() {
  int H,W;
  cin>>H>>W;
  string data[H];
  for(int i=0;i<H;i++){
    cin>>data[i];
  }
//空白の書き換え
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(data[i].at(j)=='.'){
        int x=0;
        if(i>0&&j>0){
          if(data[i-1].at(j-1)=='#'){
          x++;
          }
        }

        if(i>0){
          if(data[i-1].at(j)=='#'){
          x++;
          }
        }
        if(i>0&&j<W-1){
          if(data[i-1].at(j+1)=='#'){
          x++;
          }
        }
        if(j>0){
          if(data[i].at(j-1)=='#'){
          x++;
          }
        }
        if(j<W-1){
          if(data[i].at(j+1)=='#'){
          x++;
          }
        }
        if(i<H-1&&j>0){
          if(data[i+1].at(j-1)=='#'){
          x++;
          }
        }
        if(i<H-1){
          if(data[i+1].at(j)=='#'){
          x++;
          }
        }
        if(i<H-1&&j<W-1){
          if(data[i+1].at(j+1)=='#'){
          x++;
          }
        }
        char y='0'+x;

        data[i].at(j)=y;

      }
      
    }
  }

  for(int i=0;i<H;i++){
      cout<<data[i]<<endl;
    }
}


Measured memory_bytes: 256
while True:
    n=int(input())
    if n==0:
        break
    else:
        A=[0]*31
        A[0]=1
        A[1]=1
        A[2]=2
        for i in range(3,n+1):
            A[i]=A[i-1]+A[i-2]+A[i-3]
        print(A[n]//3650+1)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,n,t,i,j,k,x,y,m,p,s,mx,mn;
    cin>>t;
    char ar[t];
    c=1;
    for(i=0;i<t;i++)
    {
        cin>>ar[i];
    }
    for(i=0;i<t-1;i++)
    {
        if(ar[i]!=ar[i+1])
        {
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3708
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int left = 1, right = N;
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		}
		sc.close();
		// System.out.println(left + " <= " + right);
		System.out.println(left <= right ? right - left + 1 : 0);
	}
}

Measured memory_bytes: 63256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

while True:
 S = raw_input()
 if S == '0':break
 m = [1] + [0 for i in range(10)]
 diff = ans = 0
 even = 1
 S = reversed(S)
 for c in S:
  diff = (diff + int(c) * even) % 11  
  if int(c) != 0:
   ans += m[diff]
  m[diff] += 1
  even *= -1
 print ans


Measured memory_bytes: 5060
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
 
int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}
 
int32_t main()
{
	fast;

	int n, m;
	cin>>n>>m;
	vector<int> v1(n+1, 0);
	vector<int> v2(n+1, 0);

	for(int i=0;i<m;i++)
	{
		int a;
		cin>>a;
		string b;
		cin>>b;
		if(b=="AC")
		{
			v1[a]=1;
		}
		else
		{
			if(v1[a]!=1)
				v2[a]++;
		}
	}
	int a=0;
	int b=0;
	for(int i=0;i<n+1;i++)
	{
		if(v1[i]==1)
		{
			a++;
			b+=v2[i];
		}
	}
	cout<<a<<' '<<b<<endl;

	return 0;
}

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

int n, s, s2, mx = -2e9, a[105][15], b[105][15];
int main()
{
	int i, j, k, w;
	cin >> n;
	for (i = 0; i < n; i++) {
		for (j =0; j < 10; j++) {
			scanf ("%d", &a[i][j]);
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j <= 10; j++) {
			scanf ("%d", &b[i][j]);
		}
	}
	for (i = 1; i < 1024; i++) {
		s = 0;
		for (j = 0; j < n; j++) {
			w = i;
			s2 = 0;
			for (k =9; k >= 0; k--) {
				if (w % 2 == a[j][k] && w % 2 == 1) s2++;
				w /= 2;
			}
			s += b[j][s2];
		}
		mx = max(mx, s);
	}
	cout << mx;
    return 0;
}


Measured memory_bytes: 256