akhauriyash/Code-Regression huggingface dataset:
D, G = [int(x) for x in input().split()]
P, C = [], []
for _ in range(D):
    p, c = [int(x) for x in input().split()]
    P.append(p)
    C.append(c)

ans = 1000
for b in range(2**D):
    score = 0
    solve = 0
    unsolved = []
    for i in range(D):
        if (b >> i) & 1:
            score += C[i] + 100 * (i + 1) * P[i]
            solve += P[i]
        else:
            unsolved.append(i)
    if G > score:
        resprbs = []
        unsolved.reverse()
        for i in unsolved:
            resprbs += [100 * (i + 1)] * (P[i] - 1)
        for j in range(len(resprbs)):
            score += resprbs[j]
            solve += 1
            if G <= score:
                break
    if G <= score:
        ans = min(ans, solve)

print(ans)

Measured memory_bytes: 9248
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=100000+10;
int n;
int a[maxn];
int partition(int a[],int p,int r)
{
   int x=a[r];
   int i=p-1;
   for(int j=p;j<r;j++)
   {
       if(a[j]<=x)
       {
           i++;
           swap(a[i],a[j]);
       }
   }
   swap(a[i+1],a[r]);
   return i+1;
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int res=partition(a,0,n-1);
    for(int i=0;i<n;i++)
    {
        if(i) printf(" ");
        if(i==res) printf("[");
        printf("%d",a[i]);
        if(i==res) printf("]");
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 3484
n ,a, b  =map(int, input().split())
S = list(input())
threshold = a + b
rank = 1
bnum = 1
for p in S:
    if p == "a" or p == "b":
        if rank <= threshold:
            if p == "b" and bnum <= b:
                print("Yes")
                bnum += 1
                rank += 1
            elif p == "b" and bnum > b:
                print("No")
                bnum += 1
            else:
                print("Yes")
                rank += 1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 9812
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;

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


#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

const int N = pow(10,6);

vector<bool> isp(N+1, true);

void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=N; i++) {
    if (isp[i]) for(int j=2; i*j<=N; j++) isp[i*j] = false;
  }
}

int main(){
    int x;
    cin >> x;

    sieve();
    for(int i = x;; ++i){
        if(isp[i]){
            cout << i << endl;
            return 0;
        }
    }
}

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

int main()
{
  string s, t;
  cin >> s >> t;
  rep(i, 3){
    if(s[i] != t[2 - i]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
              
                                                                                               
                                                                                               
  
  return 0;
}


Measured memory_bytes: 3492
n, m = map(int, input().split())
heights = list(map(int, input().split()))
tonari = [set() for i in range(n)]
for i in range(m):
  temp = list(map(int, input().split()))
  tonari[temp[0] - 1].add(temp[1] - 1)
  tonari[temp[1] - 1].add(temp[0] - 1)
res = 0
for i in range(n):
  if len(tonari[i]) == 0:
    res += 1
  elif heights[i] > heights[max(tonari[i], key=lambda x: heights[x])]:
    res += 1
print(res)

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

int n,i,j,k,x,set,a[50000],b[50000],c[50000];

int main(){
	while(scanf("%d",&n)*n){
		set++;
		for(i=1;i<n;i++)if(a[(i*i)%n]!=set)a[(i*i)%n]=set;
		for(i=0,j=0;i<n;i++){
			if(a[i]==set){
				b[j]=i;
				j++;
			}
		}
		k=j;
		for(i=0;i<k-1;i++){
			for(j=i+1;j<k;j++){
				x=b[j]-b[i];
				if(x>n/2)x=n-x;
				c[x]+=2;
			}
		}
		for(i=1;i<=n/2;i++){
			printf("%d\n",c[i]);
			c[i]=0;
		}
	}
	return 0;
}

Measured memory_bytes: 692
import java.util.Scanner;

// https://atcoder.jp/contests/abc154/tasks/abc154_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String u = sc.next();
		sc.close();

		if(s.equals(u)) {
			a = a - 1;
		}else {
			b = b - 1;
		}
		System.out.println(a + " " + b);
	}

}


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

int main(){
 int n,count=0;
 cin>>n;
 int a[n+1];
 for(int i=1;i<=n;i++)
 cin>>a[i];
 
 for(int i=1;i<=n;i++){
 	if(i%2!=0 && a[i]%2!=0)
	 count++;
 }

  cout<<count;
}

Measured memory_bytes: 3584
#include <stdio.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
#define SUIT 4
#define RANK 13

int main(void){
	int n;/*cards you have*/
	int rank;
	int i,j;
	char mark;
	char *sp = "SHCD";

	int cards[SUIT][RANK] = {FALSE};

	scanf("%d", &n);

	if(n > 52){
		return 0;
	}

	/*check cards you have*/
	for(i = 0;i < n;i++){
		scanf("%s %d", &mark, &rank);
		if(rank >= 1 && rank <= RANK){
			for(j = 0;j < SUIT;j++){
				if(mark == *(sp + j)){
					cards[j][rank - 1] = TRUE;
					break;
				}
			}
		}else{
			return 0;
		}
	}

	/*output cards you dont have*/
	for(i = 0;i < SUIT;i++){
		for(j = 0;j < RANK;j++){
			if(cards[i][j] == FALSE){
				printf("%c %d\n", *(sp + i), j + 1);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 596
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var iii = ReadLine().Split(' ');
        var num = int.Parse(iii[0]);
        var k = long.Parse(iii[1]);
        var ar = Input.arL;
        var dp = new long[55, 2];
        for (var i = 0; i < 55; i++)
            for (var j = 0; j < 2; j++)
                dp[i, j] = -1;
        dp[50, 0] = 0;
        for (var i = 50; i >= 0; i--)
        {
            var ct = 0;
            var mask = 1L << i;
            for (var j = 0; j < num; j++)
                if ((1&ar[j]>>i) == 1) ct++;
            if (dp[i + 1, 1] != -1)
                dp[i, 1] = dp[i + 1, 1] + mask * Max(num - ct, ct);
            if (dp[i + 1, 0] != -1)
            {
                if ((1 & k >> i) == 1)
                {
                    dp[i, 0] = dp[i + 1, 0] + (num - ct) * mask;
                    dp[i, 1] = Max(dp[i, 1], dp[i + 1, 0] + ct * mask);
                }
                else
                    dp[i, 0] = dp[i + 1, 0] + ct * mask;

            }
        }
        WriteLine(Max(dp[0, 0], dp[0, 1]));
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 30300
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n;
    std::cin>>n;
    std::vector<int> a(n + 1);
    for(int i = 1;i <= n;i++){
        std::cin>>a[i];
    }

    int cnt = 0;
    int j = 1;
    for(int i = 1;i <= n;i++){
        j = a[j];
        ++cnt;
        if(j == 2){
            break;
        }
    }
    std::cout<<(cnt == n ? -1 : cnt)<<std::endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<string> S(N);
  map<string, int> cnts;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    sort(S[i].begin(), S[i].end());
    cnts[S[i]]++;
  }
  ll res = 0;
  for (auto itr = cnts.begin(); itr != cnts.end(); itr++) {
    res += 1LL * itr->second * (itr->second - 1) / 2;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 16640
<?php
$a = fgets(STDIN);
$b = fgets(STDIN);
$c = fgets(STDIN);
$x = fgets(STDIN);
$result = 0;
for ($i = 0; $i <= $a; $i++) {
    for ($j = 0; $j <= $b; $j++) {
        for ($k = 0; $k <= $c; $k++) {
            if (500 * $i + 100 * $j + 50 * $k == $x) {
                $result++;
            }
        }
    }
}
echo $result;
?>

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

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times

string rotate(string s){
    return s[s.size()-1] + s.substr(0,s.size()-1);
}

int main(){
    string S,T;
    cin>>S>>T;
    REP(i,T.size()){
        S = rotate(S);
        if(S==T){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n,a[1001],i;
  cin >> n;
  int ans=0;
  for(i=0;i<n;i++){
  cin >> a[i];
    if(a[i]%2 == 0){
    if(a[i]%3 != 0 && a[i]%5 != 0){
    ans++;
    }
    }
  }
  if(ans != 0){
  cout << "DENIED" << endl;
  }else{
  cout << "APPROVED" << endl;
  }
}

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

#define INF 1000000010
#define INFLL ((1LL<<62)-5)
#define FO(i,a,b) for (int (i) = (a); (i) < (b); ++(i))
#define sz(v) int(v.size())

using namespace std;
//PAIRS:
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pii;
typedef long long ll;

/*~~~~TEMPLATE END~~~~*/

int N, M, a[105];


int main() {
    scanf ("%d %d", &N, &M);
    FO (i,0,M) scanf ("%d", &a[i]);
    FO (i,1,M-1) {
        if (a[i]%2) {
            if (a[0]%2 == 0) {
                for (int j = i-1; j >= 0; j--) {
                    swap (a[j],a[j+1]);
                }
            } else if (a[M-1]%2 == 0) {
                FO (j,i,M-1) {
                    swap (a[j],a[j+1]);
                }
            } else {
                printf ("Impossible\n");
                return 0;
            }
        }
    }
    FO (i,0,M) printf ("%d ", a[i]);
    printf ("\n");
    if (M == 1) {
        if (a[0] == 1) printf ("1\n1\n");
        else printf ("2\n%d 1\n", a[0]-1);
        return 0;
    }
    if (a[0] == 1) {
        printf ("%d\n", M-1);
    } else {
        printf ("%d\n", M);
        printf ("%d ", a[0]-1);
    }
    FO (i,1,M-1) printf ("%d ", a[i]);
    printf ("%d\n", a[M-1]+1);
    return 0;
}



Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = pow(10,9)+7
bunbo = 1
bunshi = 1
ans = pow(2, n, mod)

for i in range(a):
    bunshi = (bunshi*(n-i)) % mod
    bunbo = (bunbo*(i+1)) % mod

ans =(ans-bunshi*pow(bunbo, -1,mod)) % mod

for i in range(a, b):
    bunshi = (bunshi*(n-i)) % mod
    bunbo = (bunbo*(i+1)) % mod

ans = (ans-bunshi*pow(bunbo, -1,mod)) % mod

print(ans-1)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int dp[100010];
    int n;cin>>n;
    fill(dp,dp+n,INF);
    vector<int>V(n);rep(i,n)cin>>V[i];
    reverse(all(V));
    rep(i,n){
        int x=V[i];
        *upper_bound(dp,dp+n,x)=x;
    }
    cout<<lower_bound(dp,dp+n,INF)-dp<<endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

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

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n; cin >> n;
		vector<int> num(n);
		int cnt = 1;
		rep (i, n) {
			char tmp; cin >> tmp;
			num[i] = tmp - '0';
		}
		int tmp = num[0];
		for (int i = 1; i < n; ++i) {
			if (tmp != num[i]) {
				tmp = num[i];
				++cnt;
			}
		}
		cout << cnt << endl;
    return;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
    
int main(){
    int A,B;
    cin >> A >> B;
    bool flag=false;
    for (int i = 1; i <=1250; i++){
        int a=(i*8)/100,b=i/10;
        if(a==A&&b==B){
            cout << i;
            flag=true;
            break;
        }
    }
    if(flag==false){
        cout << -1;
    }
    
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

int MOD = 998244353;
// int MOD = 1000000007;

set<ll> G1[1001];
set<ll> G2[1001];
set<ll> G3[1001];
ll d[1001];
ll n,m;
void bfs(int s,int g){
	queue<ll> q;
    rep(i,n) d[i] = INF;
    q.push(s);
    d[s] = 0;
    while(q.size()){
        ll p = q.front();
        q.pop();
        if(p == g) break;

        for(auto nx:G2[p]){
            if(d[nx] > d[p]+1){
                q.push(nx);
                d[nx] = d[p]+1;
            }
        }
    }
}

void con(vll &r,ll s,ll g){
	int now = g;
	while(now != s){
		r.pb(now);
		for(auto nx:G3[now]){
			if(d[nx] == d[now]-1){
				now = nx;
				break;
			}
		}
	}
	r.pb(s);
}


//----------------------------------------------------------------
signed main(){

	cin >> n >> m;

	rep(i,m){
		int a,b;
		cin >> a >> b;
		a--;b--;
		G1[a].insert(b);
		G2[a].insert(b);
		G3[b].insert(a);
	}

	vector<ll> ans(1011);


	rep(g,n){
		for(auto s:G1[g]){
			G2[g].erase(s);
			G3[s].erase(g);
			vector<ll> r;
			
			bfs(s,g);
			// rep(i,n) cerr << d[i] <<  " ";cerr << endl;
			if(d[g] != INF){
				// cerr << "(" << s << "," << g << ") : " << d[g] << endl;
				con(r,s,g);
				if(r.size() < ans.size())ans = r;
			}
			G2[g].insert(s);
			G3[s].insert(g);
		}
	}

	if(ans.size() == 1011){
		cout << -1 << endl;
		return 0;
	}

	cout << ans.size() << endl;
	for(auto x:ans)cout << x+1 << endl;
 

	return 0;
}

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

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc142.contest.atcoder.jp/tasks/abc142_b

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
double pi = 3.1415926535;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;

signed main(){
    int a,b;
    cin >> a >> b;
    int ns = 1;
    int ans = 0;
    while(ns<=b){
        ns *= 2;
        int s = a%ns;
        int t = b%ns;
        int u = a/ns;
        int v = b/ns;
        if(s!=0){
            u++;
        }
        int judge = (v-u)*(ns/2);
        if(v-u<0){
            judge = 0;
            if(s>=(ns/2)){
                judge += (t-s)+1;
            }
            else{
                judge += max((int)0,t-(ns/2) + 1);
            }
        }
        else{
            if(s!=0){
                judge += min(ns - s,ns/2);
            }
            judge += max(t - (ns/2)+1,(int)0);
        }
        if(judge%2 == 1){
            ans += ns/2;
        }
    }
    print(ans);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
  fio;
  int x,y;
  cin>>x>>y;
  int ans=0;
  if (y > x*4)
  {
    cout<<"No"<<endl;
    
  }
  else if (y < x*2)
  {
    cout<<"No"<<endl;
  }
  else if ( y%2==1)
  {
    cout<<"No"<<endl;
  }
  else
  {
    cout<<"Yes"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[0].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int n[3] = {3, 5, 7};
    int M = 3;
    vec n753(0);
    REP(d, 10){
        REP(i, M){
            vector<bool> used(3, false);
            int tmp = 0, M0 = i;
            REP(k, d + 1){
                int i0 = M0 % 3;
                M0 /= 3;
                used[i0] = true;
                tmp = tmp * 10 + n[i0];
            }
            if(used[0] && used[1] && used[2]){
                //cout << tmp << endl;
                n753.push_back(tmp);
            }
        }
        M *= 3;
    }

    int N; cin >> N;
    int ans = 0;
    REP(i, n753.size()) if(n753[i] <= N) ans++;
    cout << ans;

    
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream& operator<<(ostream& out, vector<T> &v){
  for (int i = 0; i < (int)v.size(); i++) {
    out<<v[i]<<' ';
  }
  return out;
}

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

  ll n; cin >> n;
  ll s = 100;
  ll ans = 0;
  while(s < n){
    s += s * 0.01;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
    int d1, d2, d3;
    cin >> d1 >> d2 >> d3;
    int x1=d1+d2;
    int x2=d1+d3;
    int x3=d2+d3;
    int menor=0;
    menor=min({x1,x2,x3});
    cout << menor;
    return 0;
}

Measured memory_bytes: 3552
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {
	
	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			long a = sc.scanLong();
			long b = sc.scanLong();
			long res = getXor(b);
			if(a > 0)
				res ^= getXor(a-1);
			System.out.println(res);
		}
		
		private long getXor(long till){
			long modVal = till%4;
			if(modVal == 0){
				return till;
			}
			if(modVal == 1){
				return 1;
			}
			if(modVal == 2){
				return till+1;
			}
			return 0;
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


Measured memory_bytes: 32268
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	string S,ans="-1";
	bool ansflg = false;
	cin >> S;

	FOR(i, 0, 26) {
		char now = 'a' + i;
		if (count(S.begin(), S.end(), now) == 0) {
			ans = now;
			break;
		}
	}
	if (ans == "-1")
		cout << "None";
	else
		cout << ans;
	cout << endl;

	return 0;
}


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

int main() {
    int n;cin >> n;
    string s;cin >>s;
    bool flag = false;
    if (n%2==0) {
        int half = n/2;
        for (int i=0;i<half;i++) {
            if (s[i]!=s[i+half]) {
                break;
            }
            if (i==half-1) {
                flag = true;
            }    
        }
    }
    cout << (flag ? "Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
use std::collections::VecDeque;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }

    let mut queries = vec![];
    let q: usize = sc.read();
    for _ in 0..q {
        let v = sc.read::<usize>() - 1;
        let d: usize = sc.read();
        let color: usize = sc.read();
        queries.push((v, d, color));
    }

    let mut height = vec![0; n];
    let mut v_color = vec![0; n];
    let mut q = VecDeque::new();
    for (start, dist, color) in queries.into_iter().rev() {
        if v_color[start] == 0 {
            v_color[start] = color;
        }
        if height[start] >= dist {
            continue;
        }
        q.push_back((start, dist, color));
        while let Some((v, dist, color)) = q.pop_front() {
            for &next in graph[v].iter() {
                if v_color[next] == 0 {
                    v_color[next] = color;
                }
                if height[next] >= dist - 1 {
                    continue;
                }
                height[next] = dist - 1;
                q.push_back((next, dist - 1, color));
            }
        }
    }
    for c in v_color.into_iter() {
        sc.write(format!("{}\n", c));
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 23696
package main

import "fmt"

func main() {
	var A,life,AttackCnt int
	fmt.Scan(&life)
	fmt.Scan(&A)

	for {
		life = life - A
		AttackCnt ++
		if life <= 0 {
			break
		}
	}
	fmt.Println(AttackCnt)
}


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

int main() {
  int A, B ,C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  } else if (A + B == C + D) {
    cout << "Balanced" << endl;
  } else if (A + B < C + D) {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 200005
#define maxm 500005
#define pii pair <int,int>
#define Task ""
using namespace std;
int a[3];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(".inp", "r",stdin);
    FOR(i,0,2) cin >> a[i];
    sort(a,a+3);
    cout << 10 * a[2] + a[0] + a[1];
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

struct UnionFind {
	vector<int> parent;
	int size;
	UnionFind(int n) :parent(n, -1), size(n) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)return false;
		if (sizeOf(x) < sizeOf(y))swap(x, y);
		parent[x] += parent[y]; parent[y] = x; size--;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
	int sizeOf(int x) { return -parent[root(x)]; }
};

void run(){
    int n,m;
    cin>>n>>m;
    vi a(m),b(m);
    rep(i,m)cin>>a[i]>>b[i],a[i]--,b[i]--;
    UnionFind uf(n);
    vi ans(m);
    ans[m-1]=n*(n-1)/2;
    int s=0;
    rev(i,m){
        if(!i)break;
        int sa=uf.sizeOf(a[i]);
        int sb=uf.sizeOf(b[i]);
        uf.unite(a[i],b[i]);
        int ss=uf.sizeOf(a[i]);
        if(sa==ss&&sb==ss)ans[i-1]=ans[i];
        else ans[i-1]=ans[i]+sa*(sa-1)/2+sb*(sb-1)/2-ss*(ss-1)/2;
    }
    rep(i,m)cout<<ans[i]<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        for(int j = i+1; j < n; ++j)
        {
            if(i == j)
            {
                continue;
            }
            ans += v[i] * v[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout<<s,0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}
const int N = 2e5 + 9;
int memL[N], memR[N], n, k, c;
string s;
int solveR(int idx) {
	if (idx >= n)
		return 0;
	int &rt = memR[idx];
	if (~rt)
		return rt;
	rt = (s[idx] == 'o');
	rt = max(rt, solveR(idx + 1));
	if (s[idx] == 'o')
		rt = max(rt, 1 + solveR(idx + c + 1));
	return rt;
}

int solveL(int idx) {
	if (idx < 0)
		return 0;
	int &rt = memL[idx];
	if (~rt)
		return rt;
	rt = (s[idx] == 'o');
	rt = max(rt, solveL(idx - 1));
	if (s[idx] == 'o')
		rt = max(rt, 1 + solveL(idx - c - 1));
	return rt;
}
int main() {
	run();
	memset(memR, -1, sizeof(memR));
	memset(memL, -1, sizeof(memL));
	cin >> n >> k >> c >> s;
	for (int i = 0; i < n; i++) {
		if (solveL(i - 1) + solveR(i + 1) < k)
			cout << i + 1 << endl;
	}
}


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

const ll INF = 1LL << 60;

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

    // 後ろから削る
    vector<string> target = {"dream", "dreamer", "erase", "eraser"};

    reverse(S.begin(), S.end());
    rep(i, target.size()) {
        reverse(target[i].begin(), target[i].end());
    }
    // rep(i, target.size()) {
    //     cout << target[i] << endl;
    // }
    while (true) {
        // scan
        bool found = false;
        rep(i, target.size()) {
            if (S.find(target[i]) == 0) {
                // erase
                S = S.substr(target[i].size());
                found = true;
                break;
            };
        }

        if (!found) {
            cout << "NO" << endl;
            return 0;
        }

        if (S.size() == 0) {
            cout << "YES" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 512
from collections import Counter

N = int(input())
A = list(map(int,input().split()))

cnt = Counter(A)

s = sum(c*(c-1)//2 for c in cnt.values())

for a in A:
    c = cnt[a]
    print(s-(c-1)*c//2 + (c-2)*(c-1)//2)

Measured memory_bytes: 87884
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n;cin>>n;
	map<string,int> a;
	rep(i,0,n){
		string s; cin>>s;
		a[s]++;
	}
	int m; cin>>m;
	rep(i,0,m){
		string t; cin>>t;
		a[t]--;
	}
	int ans=-1*MOD;
	for(auto c: a){
		ans=max(ans,c.second);
	}
	ans=max(0,ans);
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    cin>>n;
    vector<pair<int,int>>a(n),b(n);
    for (int i = 0; i < n; i++)
    {
        int x,y;
        cin>>x>>y;
        b[i].first=x;
        b[i].second=y;
    }
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        a[i].first = x;
        a[i].second = y;
    }
    sort(ALL(a));
    vector<bool>c(n,false);
    int cnt=0;
    for (int i = 0; i < n; i++)
    {
        int maxy=-1;
        int index = -1;
        for (int j = 0; j < n; j++)
        {
            if( b[j].first < a[i].first && b[j].second < a[i].second && b[j].second>maxy && !c[j]){
                index = j;
                maxy = b[j].second;
            }
        }
        if(index!=-1){
            c[index]=true;
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace program{

	class workspace{

		static void Main(){
			//string S = Console.ReadLine();
			string[] str = Console.ReadLine().Split(' ');
			//Console.Write(str[0].Length-1, str[1][0], str[1][0].Length-1, str[2][0]);
			if((str[0][str[0].Length-1] == str[1][0])&&(str[1][str[1].Length-1] == str[2][0])){
				Console.Write("YES");
			}else{
				Console.Write("NO");
			}

			//Console.Write(str[0][str[0].Length-1]);


		}

	}

}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define lint long long
//#define P pair<int, int>

int main(){
    string S;
    cin >> S;
    int m, d;
    m = stoi(S.substr(5, 2));
    d = stoi(S.substr(8, 2));
    
    if(m >= 5){
        cout << "TBD" << endl;
        return 0;
    }
    cout << "Heisei" << endl;
    return 0;
    
}


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

int d,c[26],s[366][26];
int t[366];

ll score(int *t){
    ll ans=0;vector<int>cnt(26,0);
    REP(i,d){
        cnt[t[i]]=-1;
        ans+=s[i][t[i]];
        REP(j,26)cnt[j]++,ans-=cnt[j]*c[j];
    }
    return ans;
}

void solve()
{
    cin>>d;
    REP(i,26)cin>>c[i];
    REP(i,d)REP(j,26)cin>>s[i][j];
    REP(i,d)cin>>t[i],t[i]--;
    int m;cin>>m;
    REP(i,m){
        int d,q;cin>>d>>q;
        t[d-1]=q-1;
        cout<<score(t)<<endl;
    }
}

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << (n - (k - 1)) - 1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> mp;
    rep(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    ll ans = 0;
    for(auto p : mp){
        ll now = p.second;
        if(now<=1) continue;
        ans += now*(now-1)/2;
    }
    rep(i,n){
        ll nans = ans;
        ll now = mp[a[i]];
        if(now<=1){
            cout << nans << endl;
            continue;
        }
        ll x = now*(now-1)/2;
        ll y = (now-1)*(now-2)/2;
        nans = nans - x + y;
        cout << nans << endl;
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  //cout << n << endl;
  
  vector <int> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
    //cout << S.at(i) << endl;
  }
  
  int count = 0;
  for (int j = 0; j < n - 2; j++) {
    if (S.at(j+1) > S.at(j) && S.at(j+1) < S.at(j+2)) {
      count ++;
    }
    else if (S.at(j+1) < S.at(j) && S.at(j+1) > S.at(j+2)) {
      count ++;
    }
    else {
      continue;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    string S; cin >> S;
    bool ans = true;
    if(N % 2 == 0){
        REP(i, N / 2) if(S[i] != S[i + N / 2]) ans = false;
    }else ans = false;
    Ans(ans, "Yes", "No");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define y first
#define x second

using namespace std;
typedef unsigned long long ll;

int main()
{
    string s;
    cin >> s;
    int n = (int)s.size();
    int r, p;
    r = p = 0;
    int ans = 0;
    fr(i, 0, n){
        if(p + 1 > r){
            r ++;
            if(s[i] == 'p') ans --;
        }
        else{
            if(s[i] == 'p') p ++;
            else p ++, ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512