akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

ll N;
ll s[100];
int main(){
   cin >> N;
   ll sum = 0;
   ll flag = true;
   REP(i, N) {
      cin >> s[i];
      sum += s[i];
      flag = flag && (s[i] % 10 == 0);
   }
   if(sum % 10 != 0) cout << sum << endl;
   else if (flag) cout << 0 << endl;
   else{
      sort(s, s + N);
      REP(i, N){
         if(s[i] % 10 != 0) {
            cout << sum - s[i] << endl;
            return 0;
         }
      }
   }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

// cout << fixed << setprecision(12)

lint modpow(lint a, lint n, lint m = MOD){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a; 
    ans %= m;
    a *= a; 
    a %= m;
    n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = MOD){
  return modpow(a, m-2, m);
}

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

int main(){
  lint S; cin>>S;
  lint len = S/3;
  
  vi exc(3010,1);
  for(lint i=1; i<=3000; i++){
    lint tmp = exc[i];
    tmp *= i+1;
    tmp %= MOD;
    exc[i+1] = tmp;
  }
  
  lint ans = 0;
  
  for(lint i=1; i<=len; i++){
    lint SS = S - 3*i;
    
    lint tmp2 = exc[SS+i-1];
    tmp2 *= inv(exc[SS]);
    tmp2 %= MOD;
    tmp2 *= inv(exc[i-1]);
    tmp2 %= MOD;
    
    ans += tmp2;
    ans %= MOD;
  }
  
  cout << ans << endl;
}
    
    


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , M;
  cin >> N;
  M = N;
  int sum;
  
  for (int i = 0; i < 9; i++) {
    sum += N - 10*(N/10);
    N = N/10;
  }
  
  if (M%sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import math

n = int(input())
x = []
y = []

for i in range(n):
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)
dist = [[] for i in range(n)]

for i in range(n):
    for j in range(n):
        dist[i].append(math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2))

num = 1

for i in range(n):
    num *= (i + 1)

ans = 0

for i in range(n):
    for j in range(n):
        ans += dist[i][j] * (num / n)

ans /= num
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;


const int nmx = 110;
const int vmx = 1010;

int dp[3030][3030];
int path[3030][3030];

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

    rep(i,s.size()) {
        rep(j,t.size()) {
            // 左上 1
            // 上 2
            // 左 3
            if (s[i]==t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
                path[i+1][j+1] = 1;
            }
            else {
                if (dp[i+1][j]>dp[i][j+1]) {
                    dp[i+1][j+1] = dp[i+1][j];
                    path[i+1][j+1] = 3;
                } 
                else {
                    dp[i+1][j+1] = dp[i][j+1];
                    path[i+1][j+1] = 2;
                }
            }
        }
    }
    string ans = "";
    
    //rep(i,s.size()+1) {
    //    rep(j,t.size()+1) {
    //        cout << path[i][j] << " ";
    //    }
    //    cout << endl;
    //}
    int i = s.size();
    int j = t.size();
    while (i > 0 && j > 0) {
        if (path[i][j]==1) {
            --i; --j;
            ans += s[i];
        } 
        else if (path[i][j]==2) --i;
        else --j;
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}




















Measured memory_bytes: 71936
let NMK = readLine()!.split(separator: " ").compactMap { Int($0) }
let k = NMK[2]
let AN = readLine()!.split(separator: " ").compactMap { Int($0) }
let BM = readLine()!.split(separator: " ").compactMap { Int($0) }

var sumAN: [Int] = [0]
for i in 0..<AN.count {
    sumAN.append(sumAN[i] + AN[i])
}
var sumBM: [Int] = [0]
for i in 0..<BM.count {
    sumBM.append(sumBM[i] + BM[i])
}

var bIndex = sumBM.count - 1

// Caluculate maximized count on each sumA
let maxCountList = sumAN.enumerated().map { sumA -> Int in
    while sumA.element + sumBM[bIndex] > k {
        if bIndex == 0 {
            return 0
        } else {
            bIndex -= 1
        }
    }
    return sumA.offset + bIndex
}
print(maxCountList.max() ?? 0)


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

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    vector<int> color(9,0);
    rep(i,n){
        if(a[i]<=399) color[0]++;
        else if(a[i]<=799) color[1]++;
        else if(a[i]<=1199) color[2]++;
        else if(a[i]<=1599) color[3]++;
        else if(a[i]<=1999) color[4]++;
        else if(a[i]<=2399) color[5]++;
        else if(a[i]<=2799) color[6]++;
        else if(a[i]<=3199) color[7]++;
        else if(a[i]>=3200) color[8]++;
    }
    
    int cnt = 0;
    
    rep(i,8){
        if(color[i]!=0) cnt++;
    }
    
    if(cnt == 0) cout << 1 << " ";
    else cout << cnt << " ";
    cout << color[8] + cnt << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  

int main() {
    int N;
    cin >> N;
    char S[110];
    rep(i,N) cin >> S[i];
    
    string res;
    if (find(begin(S), end(S), 'Y') == end(S)) res = "Three";
    else res = "Four";

    cout << res << endl;
    return 0;
}


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

/*                        [Template]                        */
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define let auto
#define of :
#define all(y) y.begin(), y.end()
#define present( x, y ) x.find( y ) != x.end()
#define _matrix(T) vector<vector<T>>
template<class T>
auto matrix( int r, int c, T v ){
	return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
int mod = (int)1e9 + 7 ;

/************************************************************/
vector<int> vis ;
vector<vector<int>> g ;
int nodes, edges ;

void addEdge( int f, int t ){
	g[f].push_back( t ) ;
	g[t].push_back( f ) ;
}

int cnt = 0 ;

void dfs( int itr ){
	vis[itr] = true ;
	cnt++ ;
	for( int v : g[itr] ){
		if( !vis[v] ){
			dfs( v ) ;
		}
	}
}


signed main(){
	cin >> nodes >> edges ;
	g.resize( nodes + 1 ) ;
	vis.resize( nodes + 1 ) ;
	vis.assign( nodes + 1, false ) ;
	int f, t ;
	for( int e = 1 ; e <= edges ; e++ ){
		cin >> f >> t ;
		g[f].push_back(t) ;
		g[t].push_back(f) ;
	}
	int mx = 0 ;
	for( int i = 1 ; i <= nodes ; i++ ){
		cnt = 0 ;
		dfs( i ) ;
		mx = max(mx, cnt) ;
	}
	cout << mx ;
	return 0 ;
}

Measured memory_bytes: 21924
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

	char buf[101],result[1100],ch;
	int p,limit;

	while(scanf("%s",buf)!=EOF){
		p = 0;
		for(int i=0; buf[i] != '\0';){
			if(buf[i] == '@'){
				ch = buf[i+2];
				limit = buf[i+1] - '0';
				for(int k = 0; k < limit; k++){
					result[p++] = ch;
				}
				i += 3;
			}else{
				result[p++] = buf[i];
				i++;
			}
		}
		result[p] = '\0';
		printf("%s\n",result);
	}

	return 0;
}

Measured memory_bytes: 2572
s=input()
i=0
ans=[0]*len(s)
while i<len(s):
  cnt=0
  while s[i]=='R':
    cnt+=1
    i+=1
  ans[i-1]+=cnt//2+cnt%2
  ans[i]+=cnt//2
  i+=1
i=len(s)-1
while i>=0:
  cnt=0
  while s[i]=='L':
    cnt+=1
    i-=1
  ans[i+1]+=cnt//2+cnt%2
  ans[i]+=cnt//2
  i-=1
for i in ans:
  print(i, end=' ')

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

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

int main()
{
    ll n;
    cin >> n;
    map<ll,ll> m;
    vector<ll> v;
    ll ans = -1;
    for(ll i = 0; i < n; i++)
    {

        ll x;
        cin >> x;
        v.pb(x);
        m[x]++;
    }
    for(ll i = 0; i < v.size(); i++)
    {

        ll x = v[i];
        ll a = m[x]+m[x-1]+m[x+1];
        ans = max(ans,a);
    }
    cout << ans;
}


Measured memory_bytes: 7028
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    ll n, d;
    cin >> n >> d;
    int ans = 0;
    rep(i, n)
    {
        ll x, y;
        cin >> x >> y;
        if(x * x + y * y <= d * d)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main (){
  int n, r, valor, classificacao;
  scanf("%d%d", &n, &r);

  if(n<10){
    valor= 100*(10-n);
    valor+r;
    printf("%d\n", valor+r);
  }
  else{
    printf("%d\n", r);
  }
  
return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		String s = scn.next();
		
		
		int count = 0;//count of ABC
		for(int i=0 ;i < n-2;i++) {
			if(s.charAt(i) == 'A' && s.charAt(i+1) == 'B' && s.charAt(i+2) == 'C') {
				count++;
			}
		}
		
		System.out.println(count);
	}
}	

Measured memory_bytes: 27092
#include <iostream>
using namespace std;
typedef long long ll;
ll n, s[400], l[400], p[400], dp[400], m, w[400];
const ll INF = -1000000000000000000;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) cin >> s[i] >> l[i] >> p[i];
    for (ll i = 1; i <= 393; i++) dp[i] = INF;
    for (ll i = 1; i <= 393; i++) {
        for (ll j = 0; j < n; j++) {
            for (ll k = s[j]; k <= l[j]; k++) {
                if (k > i || dp[i - k] == INF) continue;
                dp[i] = max(dp[i], dp[i - k] + p[j]);
            }
        }
    }
    cin >> m;
    for (ll i = 0; i < m; i++) {
        cin >> w[i];
        if (dp[w[i]] == INF) {
            cout << -1 << endl;
            return 0;
        }
    }
    for (ll i = 0; i < m; i++) {
        cout << dp[w[i]] << endl;
    }
}



Measured memory_bytes: 3080
#include<stdio.h>
#include<algorithm>
 using namespace std;
 int main()
 {
 char s[10];
 scanf("%s", s);
 sort(s, s + 4);
 printf((s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) ? "Yes\n" : "No\n");
 }


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int N,M;
int A[222222];
int B[222222];
int f1[222222];
int f2[222222];
int main()
{
	scanf("%d%d",&N,&M);
	for(int i=0;i<M;i++){
		scanf("%d%d",&A[i],&B[i]);
		if(A[i]==1){
			f1[B[i]]=1;
		}
		if(B[i]==1){
			f1[A[i]]=1;
		}
		if(A[i]==N){
			f2[B[i]]=1;
		}
		if(B[i]==N){
			f2[A[i]]=1;
		}
	}
	for(int i=2;i<N;i++){
		if(f1[i]==1&&f2[i]==1){
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100011;
int n,a[N],r=0,l=0;
int c[N*10],s[N<<1  ];
void add(int x)
{
	while(x<=N*2)
	  c[x]++,x+=x&(-x);
}
ll ask(int x)
{
	ll ans=0;
	while(x)
	{
		ans+=c[x];
		x-=x&(-x);
	}
	return ans;
}
bool check(int x)
{
	for(int i=1;i<=2*N;i++) c[i]=0;
	s[0]=0;
	for(int i=1;i<=n;i++)
	  s[i]=s[i-1]+(a[i]>=x?1:-1);
	ll sum=0;
	for(int i=0;i<=n;i++)
    {
       sum+=ask(s[i]+N);
       add(s[i]+N);
	} 
	return sum>=(ll)n*(n+1)/4;
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]),r=max(r,a[i]);
  while(l<=r)
  {
  	int mid=(l+r)>>1;
  	if(check(mid)) 
	  l=mid+1;
	else r=mid-1;
  }
  printf("%d\n",r); 
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int a[10],i,j,c;
    for(i=0;i<10;i++)
    {
        scanf("%d",&a[i]);
    }
    for(j=0;j<9;j++)
    {
        for(i=0;i<9-j;i++)
        {
            if(a[i]<a[i+1])
            {
                c=a[i];
                a[i]=a[i+1];
                a[i+1]=c;
            }
        }
    }
    for(i=0;i<3;i++)
    {
        printf("%d\n",a[i]);
    }
    return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void)
{
    int x,  y;
    scanf("%d%d", &x, &y);
    if (x==1 || x==3 || x==5 || x==7 || x==8 || x==10) {
        if(y==3 || y==5 || y==7 || y==8 || y==10 || y==12) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    } else if (x==4 || x==6 || x==9) {
        if ( x==6 || x==9 || x==11) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }  else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
const int maxn=305;
int n,m;
int f[maxn][maxn];
int d[maxn],vst[maxn],Pos[maxn];
void Update(){
	for(int i=1;i<=n;++i)
		if(vst[f[i][Pos[i]]]){
			while(vst[f[i][Pos[i]]]){
				Pos[i]++;
			}
			if(Pos[i]<=m)d[f[i][Pos[i]]]++;
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			scanf("%d",&f[i][j]);
	for(int i=1;i<=n;++i){
		d[f[i][1]]++;Pos[i]=1;
	}
	int Ans=0x7fffffff/2;
	for(int i=1;i<=m;++i){
		int bj=0,maxx=0;
		for(int j=1;j<=m;++j){
			maxx=max(maxx,d[j]);
		}
		if(Ans>maxx)Ans=maxx;
		maxx=0;
		for(int j=1;j<=m;++j)
			if(d[j]>maxx){
				maxx=d[j];
				bj=j;
			}
		vst[bj]=1;d[bj]=0;
		Update();
		maxx=0;
	}
	printf("%d",Ans);
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;


int main()
{
	int s,t;
	cin >> s >> t;
	int cnt = 0, tmp = 1;
	while(tmp < t){
		tmp+=s-1;
		cnt++;
	};
	cout << cnt;
	return 0;

}

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


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    string s;
    char s2;
    int q,t,f,now = 1,cnt=0;
    cin>>s>>q;
    deque<char> ans;
    for(auto c:s)
        ans.push_back(c);

    for(int i = 0 ; i < q ; i ++){
        cin>>t;
        
        if(t == 1){
            now =!now;
            //cout<<"now:"<<now<<'\n';
            cnt++;
        }
        else{
            cin>>f>>s2;
            if(now){
                if(f==1){
                    ans.push_front(s2);
                }else{
                    ans.push_back(s2);
                }
            }
            else{
                if(f==2){
                    ans.push_front(s2);
                }else{
                    ans.push_back(s2);
                }                
            }
            
        }
    }
    if(cnt%2==0){
       while(!ans.empty()){
           cout<<ans.front();
           ans.pop_front();
       }
    }else{
       while(!ans.empty()){
           cout<<ans.back();
           ans.pop_back();
       } 
    }

 
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


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

  int n;
  ll z;
  cin>>n>>z;

  vector<ll> w(n);
  vector<ll> v(n);
  rep(i,n){
    cin>>w[i]>>v[i];
  }

  vector<ll> v0;
  vector<ll> v1;
  vector<ll> v2;
  vector<ll> v3;
  rep(i,n){
    if(w[i]==w[0]) v0.pb(v[i]);
    if(w[i]==w[0]+1) v1.pb(v[i]);
    if(w[i]==w[0]+2) v2.pb(v[i]);
    if(w[i]==w[0]+3) v3.pb(v[i]);
  }

  int s0=v0.size();
  int s1=v1.size();
  int s2=v2.size();
  int s3=v3.size();

  sort(all(v0));
  reverse(all(v0));
  sort(all(v1));
  reverse(all(v1));
  sort(all(v2));
  reverse(all(v2));
  sort(all(v3));
  reverse(all(v3));

  repo(i,s0) v0[i]+=v0[i-1];
  repo(i,s1) v1[i]+=v1[i-1];
  repo(i,s2) v2[i]+=v2[i-1];
  repo(i,s3) v3[i]+=v3[i-1];

  ll ans=0;
  rep(i,s0+1){
    rep(j,s1+1){
      rep(k,s2+1){
        rep(l,s3+1){
          if(i+j+k+l>n) continue;
          if(i*w[0]+j*(w[0]+1)+k*(w[0]+2)+l*(w[0]+3)>z) continue;
          ll g0=0,g1=0,g2=0,g3=0,sum=0;
          if(i!=0) g0=v0[i-1];
          if(j!=0) g1=v1[j-1];
          if(k!=0) g2=v2[k-1];
          if(l!=0) g3=v3[l-1];
          sum=g0+g1+g2+g3;
          chmax(ans,sum);
        }
      }
    }
  }


  cout << ans << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  std::vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  int sum = 0;
  rep(i, k) sum += v[i];
  cout << sum << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
 
int main(void){
    int i, n, count;
    long min, max, sum;
    max = -1000000;
    min = 1000000;
    sum = 0;
    scanf("%d", &count);
    for (i = 0; i < count; i++){
        scanf("%d",&n);
        if (max < n) max = n;
        if (min > n) min = n;
        sum += n;
    }
    printf("%ld %ld %ld\n",min,max,sum);
    return 0;
}

Measured memory_bytes: 2752
N = int(input())
p = list(map(int, input().split()))

res = False
for i in range(N):
    for j in range(i, N):
        flg = True
        p[i], p[j] = p[j], p[i]
        for k in range(N - 1):
            if p[k] > p[k + 1]:
                flg = False
        if flg:
            res = True
            break
        p[i], p[j] = p[j], p[i]

print(['NO', 'YES'][res])

Measured memory_bytes: 9192
s = input()

s1 = s[:2]
s2 = s[2:]

MM = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']

s1MM = False
s2MM = False

if s1 in MM:
    s1MM = True

if s2 in MM:
    s2MM = True


if s1MM & s2MM:
    print('AMBIGUOUS')
elif s1MM:
    print('MMYY')
elif s2MM:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
    if(m>=n){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
      
    }
}


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

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
			inv[i]=ppow(fact[i],MOD-2);
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};
ll dp[2000000];
int main(){
	Fact fac(1e6);
	int n,h,d;cin>>n>>h>>d;
	ll x=0;
	for(int i=1;i<=n;i++)(x+=fac.get(i))%=MOD;
	dp[0]=1;
	ll sum=1;
	for(int i=1;i<=h;i++){
		dp[i]=sum*x%MOD;
		(sum+=dp[i])%=MOD;
		if(i-d>=0)(sum+=MOD-dp[i-d])%=MOD;
	}
	cout<<dp[h]*fac.get(n)%MOD*ppow(x,MOD-2)%MOD<<endl;
}

Measured memory_bytes: 39680
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 5e5 + 20 , base = 735 , mod = 1e9 + 7 ;
int n , h[N] , pw[N] ;
bool bad[N] ;
string s ;

inline int get (int l , int r) {
	return (h[r] - 1ll * h[l] * pw[r - l] % mod + mod) % mod ;	
}

inline void check_n () {
	bool ok = 1 ;

	for (int i = 1 ; i < n ; i ++) ok &= (s[i] == s[0]) ;

	if (ok) {
		cout << n << "\n1\n" ;
		exit(0) ;
	}
}

inline void check_1 () {
	for (int i = 1 ; i < n ; i ++) {
		if (n % (n - i)) continue ;
		if (get(0 , i) == get(n - i , n)) return ;
	}

	cout << "1\n1\n" ;
	exit(0) ;
}

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

	for (int i = pw[0] = 1 ; i < N ; i ++) pw[i] = 1ll * pw[i - 1] * base % mod ;
	
	cin >> s ;

	n = _sz(s) ;

	for (int i = 0 ; i < n ; i ++) h[i + 1] = (1ll * base * h[i] + s[i]) % mod ;
	
	check_n() ;
	check_1() ;

	bad[n - 1] = 1 ;

	for (int d = 1 ; d <= n ; d ++) {
		for (int a = 2 ; a * d <= n ; a ++) {
			if (get((a - 1) * d , a * d) != get(0 , d)) break ;
			bad[a * d - 1] = 1 ;
		}
	
		for (int a = 2 ; a * d <= n ; a ++) {
			if (get(n - a * d , n - (a - 1) * d) != get(n - d , n)) break ;
			bad[n - a * d - 1] = 1 ;
		}
	}

	cout << "2\n" ;

	int ans = 0 ;
	for (int i = 0 ; i < n ; i ++) ans += !bad[i] ;

	cout << ans << '\n' ;
}


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

//Returns the maximum value that can be put in a knapsack of capacity W
long long knapSack(long long W, long long wt[], long long val[], int n)
{
  // Base Case
  if (n == 0 || W == 0)
      return 0;

  // If weight of the nth item is more than Knapsack capacity W, then
  // this item cannot be included in the optimal solution
  if (wt[n-1] > W)
      return knapSack(W, wt, val, n-1);

  // Return the maximum of two cases:
  // (1) nth item included
  // (2) not included
  else return max( val[n-1] + knapSack(W-wt[n-1], wt, val, n-1),
                   knapSack(W, wt, val, n-1)
                 );
}

// A Dynamic Programming based solution for 0-1 Knapsack problem


// A utility function that returns maximum of two integers
//int max(int a, int b) { return (a > b)? a : b; }

// Returns the maximum value that can be put in a knapsack of capacity W
long long knapSackst(long long W, long long wt[], long long val[], int n)
{
   int i;
    long long w;
   long long K[n+1][W+1];

   // Build table K[][] in bottom up manner
   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= W; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }

   return K[n][W];
}
main()
{
  long long *wt,*val;
  int N;
  long long W;
cin>>N>>W;
wt = new long long[N];
val = new long long[N];
for(int i=0;i<N;i++)
{
  cin>>wt[i]>>val[i];
}

cout<<knapSackst(W,wt,val,N);

}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

char S[40];
char s[2][40] = {"ABC", "ARC"};
ll i, j, k;
int main(){
    scanf("%s", S);
    if(S[1]=='B'){
        printf("ARC");
    }else{
        printf("ABC");
    }
    return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <iomanip>
using ll = long long;
using namespace std;
//#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = 0; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int i = n; i >= 0; i--)
int factorical(int n) {
	int sum = 1;
	for (int i = 1; i <= n; ++i)
	{
		sum *= i;
	}
	return sum;
}

vector<int> divisors(int n) {
	vector<int> res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}
vector<ll> divisors_ll(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}


void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}



int main() {
	int n, k;
	int res = 1;
	cin >> n >> k;
	while (true) {
		if (n / k < 1)break;
		n = n / k;
		res += 1;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

    int x = n % 500;

    if (x <= a) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

}


Measured memory_bytes: 23764
use scanner::Scanner;

fn main() {
    let mut sc = Scanner::new();
    let a: usize = sc.read();
    let b: usize = sc.read();
    let h: usize = sc.read();
    println!("{}", ((a + b) * h) / 2)
}

mod scanner {
    pub struct Scanner<'a> {
        s: String,
        words: ::std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new() -> Scanner<'a> {
            let s = String::new();
            let words = unsafe { ::std::mem::transmute(s.split_whitespace()) };
            Scanner { s: s, words: words }
        }

        pub fn read<T: ::std::str::FromStr>(&mut self) -> T {
            match self.words.next() {
                Some(x) => x.parse().ok().unwrap(),
                None => {
                    self.load();
                    self.read()
                }
            }
        }

        fn load(&mut self) {
            self.s.clear();
            ::std::io::stdin().read_line(&mut self.s).unwrap();
            self.words = unsafe { ::std::mem::transmute(self.s.split_whitespace()) };
        }
    }
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// // assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm vi st gin

typedef int Weight;
typedef int Flow;
struct Edge {
    int s, d; Weight w; Flow c;
    Edge() {};
    Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void addArc(Graph &g, int s, int d, int w = 1) {
    g[s].push_back(Edge(s, d, w));
}
void addEdge(Graph &g, int a, int b, int w = 1) {
    addArc(g, a, b, w);
    addArc(g, b, a, w);
}

bool dfs(Graph &g, vi &state, vi &used, int pos, int num)
{
    //cout << pos << " " << num << endl;
    used[pos] = true;
    state[pos] = num;
    bool ret = true;
    rep(i, g[pos].size()) {
        if (!used[g[pos][i].d]) {
            ret &= dfs(g, state, used, g[pos][i].d, -num);
        } else if (state[g[pos][i].d] == num) {
            //    cout << "finish in : " << i << endl;
            return false;
        }
    }
    return ret;
}

bool is_binary_graph(Graph &g, vi &state)
{
    int n = g.size();
    state = vi(n, 0);
    vi used(n, false);
    /*
    rep(i, n) {
        if (!used[i]) {
            if (!dfs(g, state, used, i, 1LL)) {
                cout << "finish in : " << i << endl;
                return false;
            }
        }
    }*/
    return dfs(g, state, used, 0, 1);
}

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int2(n, m);
    Graph g(n);
    for (int i = 0; i < m; i++) {
        int tmpx, tmpy;
        cin >> tmpx >> tmpy;
         tmpx--; tmpy--;
        addEdge(g, tmpx, tmpy );
    }

    vi state;

    if (is_binary_graph(g, state)) {
        int yui = 0;
        rep(i, n) {
            yui += (state[i] == 1) ? 1 : 0;
        }
        cout << (yui * (n - yui)) - m << endl;
    } else {
        cout << n * (n-1) / 2 - m << endl;
    }

    return 0;
}


Measured memory_bytes: 14464
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
D = LIST()
M = INT()
T = LIST()

d = Counter(D)
t = Counter(T)

S = set(T)
for s in S:
    if d[s] >= t[s]:
        continue
    else:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 68380
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	size_t x;

	scanf("%zu", &x);

	puts(x < 1200 ? "ABC" : "ARC");

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	ll N,K,X,Y;
	cin>>N>>K>>X>>Y;
	cout<<X*min(N,K)+Y*max(0LL,N-K)<<endl;
	return 0; 
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
ll a,b,c,ans=0;
int main()
{
	cin>>a>>b>>c;
	if(c<b) re(c*a/b)
	rep(i,c/b)
	{
		ans=max(ans,(b-1+b*i)*a/b-i*a);
	}
	ans=max(ans,c*a/b-c/b*a);
	re(ans)
	return 0;}

Measured memory_bytes: 3636
N,M = map(int,input().split())
lst_l=[]
lst_r=[]
for i in range(M):
    l,r = map(int,input().split())
    lst_l.append(l)
    lst_r.append(r)
ans = min(lst_r)-max(lst_l)+1
if ans >=0:print(ans)
else:print(0)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;

int main() {
  int x,n; cin>>x>>n;
  vector<int> p(n);
  rep(i, n) cin>>p[i];
  
  for(int i = 0; ; i++) {
    if (!contains(p, x-i)) {
      cout << x-i;
      return 0;
    } else if (!contains(p, x+i)) {
      cout << x+i;
      return 0;
    }
  }
}


Measured memory_bytes: 3620
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    d: usize,
    g: i64,
    ps: [(i64, i64); d],
  }
  let mut ans = 1 << 30;
  for pat in 0 .. 1 << d {
    let mut score = 0;
    let mut solve = 0;
    for (i, &(p, c)) in ps.iter().enumerate() {
      if (pat >> i) & 1 != 0 {
        solve += p;
        score += p * (i as i64 + 1) * 100 + c;
      }
    }
    let rest = g - score;
    if rest > 0 {
      if let Some((i, &(p, _))) = ps.iter().enumerate().rev().find(|&(i, _)| (pat >> i) & 1 == 0) {
        let s = (i as i64 + 1) * 100;
        let n = (rest + s - 1) / s;
        if n >= p {
          continue;
        }
        solve += n;
      }
    }
    ans = cmp::min(ans, solve);
  }

  puts!("{}\n", ans);
}


Measured memory_bytes: 4352
ss = input()
t = input()
sl = len(ss)
tl = len(t)
min = "UNRESTORABLE"

for i in range(sl-tl+1):
    for j, tj in enumerate(t):
        if not(ss[i+j] == tj or ss[i+j] == "?"):
            break
        if j == tl-1:
            s = ""
            for k, sk in enumerate(ss):
                if i <= k and k < i+tl:
                    s += t[k-i]
                elif sk == "?":
                    s += "a"
                else:
                    s += sk
            if min == "UNRESTORABLE":
                min = s
            elif min > s:
                min = s

print(min)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i, k) for (auto &i : k)
#define all(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main()
{
	int h, w;
	cin >> h >> w;
	vector<vector<int>> c(10, vector<int>(10));
	int a;
	REP(i, 10)
	{
		REP(j, 10)
		{
			cin >> c[i][j];
		}
	}
	REP(k, 10)
	{
		REP(i, 10)
		{
			REP(j, 10)
			{
				if (c[i][j] > c[i][k] + c[k][j])
				{
					c[i][j] = c[i][k] + c[k][j];
				}
			}
		}
	}
	int ans=0;
	REP(i, h)
	{
		REP(j, w)
		{
			cin >> a;
			if (a >= 0)
			{
				ans+=c[a][1];
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    ll n,ans = 0;cin >> n;
    for(ll i = 1;i<=n;i++) {
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans;
}



Measured memory_bytes: 3620
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    a=LI()
    S=[0]*(N+1)
    
    for i in range(N):
        S[i+1]=S[i]+a[i]
        
    ans=10**20
    for i in range(1,N):
        sn=S[i]
        ar=S[-1]-sn
        temp=abs(sn-ar)
        ans=min(ans,temp)
        
    print(ans)

main()



Measured memory_bytes: 76956
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <map>
using namespace std;

#define MAXN 5024288
#define INF 0x3f3f3f3f
long long A[MAXN], SM[MAXN], SB[MAXN];
// binary index tree
int BIT[MAXN<<1];
void modify(int x, int v, int L) {
	while(x <= L) {
		BIT[x] = max(BIT[x], v);
		x += x&(-x);
	}
}
int query(int x) {
	int ret = - INF;
	while(x) {
		ret = max(ret, BIT[x]);
		x -= x&(-x);
	}
	return ret;
}
int main() {
	string s;
	cin>>s;
	s='>'+s;
	int ans = s.length()-1;
	for(int i = 1;i<s.length()-1;i++) {
        if(s[i]!=s[i+1]) {
            ans = min(ans,max(i,(int)s.length()-i-1));
        }
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#define REF(n, m) for(int j = n; j < m; j++)

int main()
{
	int a, count, max = 0;
	std::string b;
	std::cin >> a >> b;
	for(int i = 1; i < a; i++)
	{
		count = 0;		
		for(char c = 'a'; c <= 'z'; c++)
		{
			bool left = false, right = false;
			REF(0, i)
			{
				if(b[j] == c)
					left = true;
			}
			REF(i, a)
			{
				if(b[j] == c)
					right = true;
			}
			if(left && right)
				count++;
		}
		if(max < count)
			max = count;
	}
	std::cout << max << std::endl;
}

Measured memory_bytes: 256
/*---------------------------------------------------------------------*/
/*                   -------------------------------------             */
/*                   -----------MEHEDI HASAN--------------             */
/*                   -----CSE,JAHANGIRNAGAR UNIVERSITY----             */
/*                   -------------------------------------             */
/*---------------------------------------------------------------------*/
#include<bits/stdc++.h>
//#include <cassert>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
/*---------------------------------------------------------------------*/
#define FAST        ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define cc(x)       cout<<#x<<"="<<x<<" ";
#define ccc(x)      cout<<#x<<"="<<"("<<x.ff<<" "<<x.ss<<") ";
#define CC(x)       cout<<"["<<#x<<"] = ";for(auto xx: x) cout<<xx<<" ";
#define CCC(x)      cout<<"["<<#x<<"] = ";for(auto xx: x) cout<<"("<<xx.ff<<" "<<xx.ss<<") ";
#define MARK(x)     cout<<x<<" ";
#define ee          cout<<"\n";
#define OK          cout<<"Ok till line "<<__LINE__<<"\n";
/*---------------------------------------------------------------------*/
#define ff          first
#define ss          second
#define ll          long long
#define ull         unsigned long long
#define pii         pair<int,int>
#define mp          make_pair
#define ps          push
#define psb         push_back
#define psf         push_front
#define pp          pop
#define ppb         pop_back
#define ppf         pop_front
#define all(x)      x.begin(),x.end()
#define TESTS       int t;cin>>t;for(int tcase=1;tcase<=t;tcase++)
#define ordered_set tree< int, null_type, less_equal< int >, rb_tree_tag, tree_order_statistics_node_update>
/*---------------------------------------------------------------------*/
#define MAX (int) (5e5+88)

int main()
{
    FAST
    int n;cin>>n;
    vector<int> cnt(n+1,0);
    for(int i=2;i<=n;i++)
    {
        int x;cin>>x;
        cnt[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<cnt[i]<<endl;
    }
    return 0;
}
/*--------------------------------------------------------------------*/
/*
>Check Corner Cases (n==1 or T==1)
>Overflow issues?
>LB / UB !!not found!! check?
*/
/*--------------------------------------------------------------------*/
/* ---INPUT---
--------(1)------
4
3
AAB
5
AABAA
1
B
4
BABA
-------(2)-------
5
5
AAAAA
6
BBAAAA
1
A
2
BA
10
AAAAAAAAAB


-------(3)-------


-------(4)-------



--------------
*/
/*--------------------------------------------------------------------*/


//https://codeforces.com/contest/466/problem/C try again


Measured memory_bytes: 3992
import Control.Applicative
import Data.Function
import Control.Monad
import Data.List

f xs = xs ++ [sum xs]

g :: [[Int]] -> [[Int]]
g ss =
    let a = map f ss
        b = [map (sum) (transpose a)]
    in a ++ b

main = do
    [r,c] <- map read . words <$> getLine
    ss <- replicateM r $ map read . words <$> getLine
    mapM_ (putStrLn <$> unwords . map show) (g ss)


Measured memory_bytes: 6440
fn main() {
    proconio::input! {
        k: usize,
        s: String,
    }
    let n=s.as_bytes().len();
    let mut a=0;
    let mut c=1;
    for i in n..=n+k {
        let t=c*f(25,i-n)%MOD*f(26,n+k-i)%MOD;
        a=(a+t)%MOD;
        c=c*i%MOD*f(i-n+1,MOD-2)%MOD;
    }
    println!("{}",a);
}
const MOD: usize=1000000007;
fn f(mut i: usize, mut n: usize) -> usize {
    let mut x=1;
    while n>0 {
        if n&1==1 {
            x=x*i%MOD;
        }
        i=i*i%MOD;
        n>>=1;
    }
    x
}

Measured memory_bytes: 3936
# Python template 
from collections import defaultdict 
import sys
import math 

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())
a = get_array()

ans = 0
maxi = a[0]
for i in range(1,n):
    if maxi>a[i]:
        ans+=(maxi-a[i])
    else:
        maxi = a[i]
print(ans)


Measured memory_bytes: 33644
s = list(input())
t = list(input())
s = sorted(s)
t = sorted(t, reverse=True)
s1, t1 = "", ""
for i in range(len(s)):
    s1 += s[i]
for i in range(len(t)):
    t1 += t[i]

if s1 < t1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int len = sc.nextInt();
        MyData[] d = new MyData[len];

		for (int i = 0; i < len; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
            d[i] = new MyData(a+b, a-b);
        }
        Arrays.sort(d);
		int ans = 0;
		int cur = -1000000000;
		for (int i = 0; i < len; i++) {
			if (d[i].b >= cur) {
				cur = d[i].a;
				ans++;
            }
        }
		
//		for (int i = 0; i < len; i++) {
//			System.out.println(d[i].getB() + " " + d[i].getA());
  //      }
		System.out.println(ans);
    }
  
	public static class MyData implements Comparable<MyData> {
		int a, b;
		public MyData(int a, int b) {
			this.a = a;
            this.b = b;
        }
        public int compareTo(MyData other) {
            if (this.a == other.a) {
                return this.b - other.b;
            } else {
                return this.a - other.a;
            }
        }
    }
}

Measured memory_bytes: 65012