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

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int N = sc.nextInt();
        int A[] = new int[N];
        int sum = 0;
        for(int i=0;i<N;i++)
        {
            sum = sum + sc.nextInt();
        }
        if(sum >= H)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 50552
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
int ai[maxn];
int n;

inline int chk(int ps) {
    LL tot=ai[ps];
    REP(i,1,n) if(i!=ps) {
        if(ai[i]<=2*tot) tot+=ai[i];
        else return 0;
    } return 1;
}

int main() {
    read(n);
    REP(i,1,n) read(ai[i]);
    sort(ai+1,ai+n+1);
    int l=1,r=n;
    while(l<r) {
        int mid=(l+r)>>1;
        if(chk(mid)) r=mid;
        else l=mid+1;
    } printf("%d\n",n-l+1);
    return 0;
}

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

int n,k;
int d[110] = {} ;
int dp[110][4][4] = {} ;

int f( int day , int p , int pp ){
	if( day == n ) return 1 ;
	if( dp[day][p][pp] != 0 ) return dp[day][p][pp] ;
	
	int ans = 0 ;
	for( int i=1 ; i<=3 ; i++ ){
		if( p == pp && p == i ){}
		else {
			if( d[day+1] == 0 || d[day+1] == i ){
				ans += f( day+1 , i , p ) ;
				ans %= 10000 ;
			}
		}
	}
	
	return dp[day][p][pp] = ans ;
}

int main(){
	
	cin >> n >> k ;
	
	int a,b ;
	for( int i=0 ; i<k ; i++ ){
		cin >> a >> b ;
		d[a] = b ;
	}
	
	
	int ans2 = 0 ;
	for( int i=1 ; i<=3 ; i++ ){
		if( d[1] == 0 || d[1] == i ){
			ans2 += f( 1 , i , 0 ) ;
			ans2 %= 10000 ;
		}
	}
	
	cout << ans2 << endl ;
	
return 0;
}

Measured memory_bytes: 1176
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
signed main(){
	string S;
	cin>>S;
	int ans=0;
	for(int i=0;i<S.length()/2;i++){
		if(S[i]!=S[S.length()-1-i])
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/* You got a dream , you gotta protect it . */
/* You got a dream , you gotta protect it . */
/* You got a dream , you gotta protect it . */
#include <bits/stdc++.h>
#define lp(i , N) for(ll i = 0; i < ll (N) ; i++)
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define debug(x) cout<<" [ " << #x << " is: " << x << " ] "<<endl;
using namespace std;
typedef long long ll;
typedef long double ld;
const long double EPS = 1e-6;
const long double pi = acos(-1);
const long long MOD = 1e9 + 7;
int main(){
    FAST
    ld a , b;
    cin >> a >> b;
    for(ll i = 1; i <= 1000; i++){
        bool b1 = false , b2 = false;
        for(ld c = 0.8 , g = 1; g <= 1000; g++ , c/=10){
        ll res = c * i;
        if(res == a) b1 = true;
        }
        for(ld c = 0.1 , g = 1; g <= 1000; g++ , c/=10){
        ll res = c * i;
        if(res == b) b2 = true;
        }
        if(b1 && b2){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}
/*
[#]=============================================================[#]
         ___    ____              ____          ___ _
        |_ _|  / ___|__ _ _ __   |  _ \  ___   |_ _| |_
         | |  | |   / _` | '_ \  | | | |/ _ \   | || __|
         | |  | |__| (_| | | | | | |_| | (_) |  | || |_
        |___|  \____\__,_|_| |_| |____/ \___/  |___|\__|
                     it's just about time

[#]=============================================================[#]
*/


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


int main(){
    string S,T;
    cin >> S;
    cin >> T;
    bool flag = true;
    rep(i,S.size()){
        if(S[i] != T[i]) flag = false;
    }
    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;

int main()
{
    int n;
    std::cin >> n;

    std::vector<int> v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
    }

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
        if (v[i] == v[i + 1]) {
            count++;
            i++;
        }
    }

    std::cout << count << std::endl;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  int a[M]={},b[M]={};
  for(int i=0; i<M; i++) cin >> a[i] >> b[i];
  int load[N] = {};
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
      if(a[j]==i+1) load[i]++;
      if(b[j]==i+1) load[i]++;
      }
    cout << load[i] << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int K, A, B, n = 0;
  scanf("%d %d %d", &K, &A, &B);
  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      n += 1;
    }
  }
  if (n >= 1) {
    printf("OK");
  }
  else {
    printf("NG");
  }
  return 0;
}

Measured memory_bytes: 1728
//Author:- Yatin Patel
//Mail:- yatinpatel.gt@gmail.com

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FILEIN ifstream fin;fin.open("input.txt");
#define FILEOUT ofstream fout;fout.open("output.txt");

using namespace std;
using namespace __gnu_pbds;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "  ";
    err(++it, args...);
}

#define FAST ios::sync_with_stdio(false);ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define MOD 1000000007
#define INF LONG_MAX
#define MINF LONG_MIN

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll power(ll x, unsigned ll y){
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

//#define fin cin
//#define fout cout

int main(){

    FAST;
    ll n;
    cin>>n;
    vector<ll> v[n];
    for(ll i=0;i<n-1;i++){
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    vector<ll> val(n);
    for(ll i=0;i<n;i++){
        cin>>val[i];
    }
    sort(val.begin(),val.end());
    reverse(val.begin(),val.end());

    vector<bool> visited(n,false);

    vector<ll> ans(n);
    ll sum = 0;

    queue<ll> qu;
    qu.push(0);
    visited[0] = true;
    ll cnt = 0;
    while(qu.size()!=0){
        ll y = qu.front();
        qu.pop();
        visited[y] = true;
        ans[y] = val[cnt];
        sum += ans[y];
        cnt++;
        for(ll i=0;i<v[y].size();i++){
            if(!visited[v[y][i]]){
                qu.push(v[y][i]);
            }
        }
    }
    cout<<sum-val[0]<<endl;
    for(auto i:ans){
        cout<<i<<" ";
    }

    return 0;
}






Measured memory_bytes: 1152
MOD = 2019  # これなにげに3の倍数だからいつも見たいなMODの演算が通用しない笑
L, R = list(map(int, input().split()))

# このコーナーケースに注意
if (R - L) >= MOD:
    print(0)
    exit()

# Lをなるべく0に近づける
L %= MOD
# RをなるべくLに近づけてみる
R %= MOD
if R <= L:
    R += MOD

# print(L, R)
ans = 2019
for i in range(L, R):  # i<jが成り立つ範囲に注意
    for j in range(i + 1, R + 1):
        ans = min(ans, (i * j) % MOD)
print(ans)


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

#define ll long long
#define ld long double

using namespace std; 
void solve(); 
int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
    int t = 1; 
    // cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 

void solve() 
{ 
	int n, a, b;
    string s;

    cin >> n >> a >> b >> s;

    int passed = 0;
    int count = 0;
    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == 'b') {
            count++;
        }

        if (s[i] == 'a' && passed < a + b) {
            cout << "Yes\n";
            passed++;
        } else if (s[i] == 'b' && passed < a + b && count <= b) {
            cout << "Yes\n";
            passed++;
        } else {
            cout << "No\n";
        }
    }
}


Measured memory_bytes: 848
#include<stdio.h>
int M[101][101];
int d[101];
int f[101];
int n,t=0;

void search(s){
    int i;

    d[s]=++t;
    for(i=1;i<=n;i++){
	if(M[s][i]==0) continue;
	if(d[i]>0) continue;

	search(i);
    }
    f[s]=++t;
}

int main(void){
    int u,k,v;
    int i,j;

    scanf("%d",&n);
    for(i=0;i<n;i++){
	scanf("%d%d",&u,&k);
	for(j=0;j<k;j++){
	    scanf("%d",&v);
	    M[u][v]=1;
	}
    }

/*
    for(i=1;i<=n;i++){
	for(j=1;j<=n;j++){
	    printf("%d",M[i][j]);
	}
	printf("\n");
    }
*/
    for(i=1;i<=n;i++){
	if(d[i]==0) search(i);
    }

    for(i=1;i<=n;i++){
	printf("%d %d %d\n",i,d[i],f[i]);
    }

    return 0;
}

Measured memory_bytes: 636
h,w = [int(i) for i in input().split()]

grid = [[1 if i == '#' else 0 for i in input()] for _ in range(h)]

total = 0
for i in grid:
  total += sum(i)
  
  
if total == (h+w-1):
  print('Possible')
else:
  print('Impossible')

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e9+7;
int main()
{
	int h;
	int n;
	cin>>h>>n;
	int dp[10101];
	for(int i=0; i<=h; i++){
		dp[i]=INF;
	}
	int a[1010], b[1010];
	for(int i=0; i<n; i++){
		cin>>a[i]>>b[i];
	}
	dp[0]=0;
	for(int i=0; i<n; i++){
		for(int j=0; j<h; j++){
			dp[min(h, j+a[i])]=min(dp[min(h, j+a[i])], dp[j]+b[i]);
		}
	}
	cout<<dp[h]<<endl;
	return 0;
}


Measured memory_bytes: 256
/**
 *	@file: B.cpp
 *	@author: Huy Le
 *	@created: 08-17-2020 10:29:18
**/


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

#define ll long long
#define ld long double
#define sz(x) (int)(x).size()
const char newl = '\n';

int ts;
int r,c,k;
const int mxN=3005;
ll a[mxN][mxN];
ll dp[mxN][mxN][4];

void solve() {
	cin >> r >> c >> k;
	memset(a,0,sizeof(a));
	for(int i=0; i<k; ++i) {
		int x,y;
		cin >> x >> y;
		--x;--y;
		cin >> a[x][y];
	}
	memset(dp, 0, sizeof(dp));
	dp[0][0][1] = a[0][0];
	for(int i=0; i<r; ++i)
		for(int j=0; j<c; ++j) {
			if(i>0) {
				for(int k=0; k<=3; ++k) {
					dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k]);
					dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][k] + a[i][j]);
				}	
			}
			if(j>0) {
				for(int k=0; k<=3; ++k) {
					dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k]);
					if(k>0)
						dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + a[i][j]);
				}
			}
		}
	ll ans=0;
	for(int i=0; i<=3; ++i) {
		ans=max(ans, dp[r-1][c-1][i]);
	}
	cout << ans << newl;
}

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

	//cin >> ts;
	//while(ts--)
		solve();
}


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

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

int table[10][10];
int ans = 0;
bool flag = 0;

int ssn(string s){
  while(s.size() < 4) s = '0' + s;
  assert(s.size() >= 4);
  int ret = 0;
  ret = table[ret][s[0] - '0'];
  ret = table[ret][s[1] - '0'];
  ret = table[ret][s[2] - '0'];
  ret = table[ret][s[3] - '0'];
  return ret;
}


void check(int tar){
  string tars = to_string(tar);
  while(tars.size() < 4) tars = '0' + tars;
  int e = ssn(tars);
  tars = tars + char(e+'0');
  string orig = tars;
  rep(i,4){
    swap(tars[i],tars[i+1]);
    if(tars != orig && table[ssn(tars)][tars[4]-'0'] == 0) flag = 1;
    swap(tars[i],tars[i+1]);
  }
  rep(i,5)rep(j,10){
    string tt = orig;
    tt[i] = j + '0';
    if(tt != orig && table[ssn(tt)][tt[4] - '0'] == 0) flag = 1;
  }
  assert(tars == orig);
  //cerr << tars << endl;
  //if(flag)cerr << tar << endl;
}


int main(){
  rep(i,10)rep(j,10) cin >> table[i][j];
  rep(i,10000){
    flag = 0;
    check(i);
    ans += flag;
  }
  cout << ans << endl;
  //cerr<< ssn("2016111") << endl;
}



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


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

  bool ok;
  int n;
  cin >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  
  if(a[0]==a[n-1]){
    if(a[0]==n-1 || a[0]<=n/2) ok=true;
    else ok=false;
  }
  else{
    int min_a=a[0];
    int k;
    rep(i,n){
      if(a[i]!=a[0]){
	k=i;
	break;
      }
    }
    if(k==n-1){
      ok =false;
    }
    else if((n-k)/2+k>=a[n-1] && a[0]>=k) ok=true;
    else ok=false;      
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
    

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define show(x) cerr << #x << " = " << x << ", "
#define showln(x) cerr << #x << " = " << x << "\n"
typedef long long ll;
bool fexists(const char *filename) {
  std::ifstream ifile(filename);
  return (bool)ifile;
}
int	a[500];
int main() {
	int n, x;
	cin >> n >> x;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; ++i) {
		if (x - a[i] < 0)
			cout << i - 1, exit(0);
		x -= a[i];
	}
	cout << n - (x != 0);
	return 0;
}

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

struct Problem {

	void Solve() {
		UL N; cin >> N;
		if (N == 2) { cout << "1 2" << endl; return; }
		vector<vector<UL>> E(N);
		rep(i, N - 1) {
			UL a, b; cin >> a >> b; a--; b--;
			E[a].push_back(b);
			E[b].push_back(a);
		}
		UL r = 0;
		vector<UL> D(N);
		{
			vector<UL> L(N); rep(i, N) L[i] = E[i].size() - 1;
			queue<UL> Q;  rep(i, N) if (L[i] == 0) Q.push(i);
			while (Q.size()) {
				UL p = Q.front(); Q.pop();
				r = max(r, D[p]);
				for (UL e : E[p]) {
					if (L[e] == 0) continue;
					D[e] = max(D[e], D[p] + 1);
					L[e]--;
					if (L[e] != 0) continue;
					Q.push(e);
				}
			}
		}
		UL Cs = 0; rep(i, N) if (D[i] == r) Cs++;
		queue<UL> Q;
		rep(i, N) if (D[i] == r) Q.push(i);
		while (Q.size()) {
			UL p = Q.front(); Q.pop();
			for (UL e : E[p]) {
				if (D[e] < D[p]) Q.push(e);
				if (D[e] > D[p]) D[p] = D[e] - 1;
			}
		}
		vector<UL> d(r + 1);
		rep(i, N) d[D[i]] = max(d[D[i]], (UL)E[i].size());
		ULL ans = 1;
		for (UL i = 1; i < r; i++) { ans *= (d[i] - 1); }
		if (Cs == 2) ans *= (d[r] - 1) * 2; else ans *= d[r];
		//rep(i, D.size()) cout << D[i] << " "; cout << endl;
		//rep(i, d.size()) cout << d[i] << " "; cout << endl;
		if (Cs == 1) {
			UL C = 0; rep(i, N) if (D[i] == r) C = i;
			for (UL v : E[C]) {
				queue<UL> Q; Q.push(C); Q.push(v);
				vector<UL> D2 = D;
				D2[v] = r;
				while (Q.size()) {
					UL p = Q.front(); Q.pop();
					for (UL e : E[p]) {
						if (D2[e] < D2[p]) Q.push(e);
						if (D2[e] > D2[p]) D2[p] = D2[e] - 1;
					}
				}
				vector<UL> d2(r + 1);
				rep(i, N) d2[D2[i]] = max(d2[D2[i]], (UL)E[i].size());
				ULL ansbuf = 1;
				for (UL i = 1; i < r; i++) { ansbuf *= (d2[i] - 1); }
				ansbuf *= (d2[r] - 1) * 2;
				//rep(i, D2.size()) cout << D2[i] << " "; cout << endl;
				//rep(i, d2.size()) cout << d2[i] << " "; cout << endl;
				ans = min(ans, ansbuf);
			}
		}
		cout << (r + 1) << " " << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  vi a(n), b(n), c(n-1);
  rep(i, n) {
    cin >> a[i];
  }

  rep(i, n) {
    cin >> b[i];
  }

  rep(i, n-1) {
    cin >> c[i];
  }

  ll ans = 0;
  rep(i, n) {
    ans += b[i];
    if (i != 0) {
      if (a[i] == a[i-1] + 1) {
        ans += c[a[i-1]-1];
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]
B = sorted(A[:], reverse=True)

MAX_A = max(A)
MAX_A_CNT = A.count(MAX_A)

Second_MAX_A = B[1]
if MAX_A_CNT >= 2:
    for i in range(N):
        print(MAX_A)
else:
    for i in range(N):
        if A[i] == MAX_A:
            print(Second_MAX_A)
        else:
            print(MAX_A)


Measured memory_bytes: 14876
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int H, A;
	cin >> H >> A;
	cout << (H + A - 1) / A << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	static int h,w;
	static int[][] p=new int[9][9];
	static int c, size;
	
	static void dfs1(int[][] cpp,int count) {
		int[][] cp=new int[9][9];
		for(int i=1; i<=6; i++) {
			if(count==5 && i!=c) continue;
			if(i==cpp[1][1]) continue;
			for(int x=1; x<=h; x++) {
				for(int y=1; y<=w; y++) {
					cp[x][y]=cpp[x][y];
					//System.out.print(cp[x][y]);
				}
				//System.out.println();
			}
			//System.out.println();
			if(count==6) {
				dfs(cp, 1,1,cp[1][1], 0);
			}
			else {
				//System.out.println(cp[1][1]+" "+i);
				dfs(cp, 1,1,cp[1][1],i);
			}
			if(count==6) {
				int sum=0;
				for(int x=1; x<=h; x++) {
					for(int y=1; y<=w; y++) {
						if(cp[x][y]==0) {
							sum++;
						}
					}
				}
				size=Math.max(sum, size);
				//System.out.println("size="+size);
				return;
			}
			dfs1(cp, count+1);
		}
	}
	
	static void dfs(int[][] cp, int x, int y, int c1, int c2) {//c1変化前　c2変化後
		if(x>=1 && x<=h && y>=1 && y<=w) {
			if(cp[x][y]==c1) {
				cp[x][y]=c2;
				dfs(cp, x+1, y, c1, c2);
				dfs(cp, x-1, y, c1, c2);
				dfs(cp, x, y+1, c1, c2);
				dfs(cp, x, y-1, c1, c2);
			}
		}
	}
	
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				h=sc.nextInt();
				w=sc.nextInt();
				c=sc.nextInt();
				if(h+w+c==0) break;
				
				for(int i=1; i<=h; i++) {
					for(int j=1; j<=w; j++) {
						p[i][j]=sc.nextInt();
					}
				}
				size=0;
				dfs1(p, 1);
				System.out.println(size);
			}



		}
	}
}


Measured memory_bytes: 161492
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int N, M;
  cin >> N;
  map<string, int> A;
  map<string, int> B;
  rep(i, N){
    string a;
    cin >> a;
    A[a] += 1;
  }
  cin >> M;
  rep(i, M){
    string b;
    cin >> b;
    B[b] += 1;
  }
  int max = -9999;
  for(auto x : A){
    string aa = x.first;
    int a = x.second;
    //auto iter = B.find(x.first);
    auto iter = B.find(aa);
    int b;
    if(iter != B.end()){
      b = iter->second;

    }else{
    b = 0;
    }
    if(max < a-b){
      max = a-b;
    }
    }
  if(max < 0) max = 0;
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 384
import math


class Point:
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = y


def koch(n, p1, p2):
    if n == 0:
        return
    s, t, u = [Point() for _ in range(3)]
    s.x = (2 * p1.x + p2.x) / 3
    s.y = (2 * p1.y + p2.y) / 3
    t.x = (p1.x + 2 * p2.x) / 3
    t.y = (p1.y + 2 * p2.y) / 3
    a = math.radians(60)
    u.x = (t.x - s.x) * math.cos(a) - (t.y - s.y) * math.sin(a) + s.x
    u.y = (t.x - s.x) * math.sin(a) + (t.y - s.y) * math.cos(a) + s.y

    koch(n - 1, p1, s)
    print(s.x, s.y)
    koch(n - 1, s, u)
    print(u.x, u.y)
    koch(n - 1, u, t)
    print(t.x, t.y)
    koch(n - 1, t, p2)


p1 = Point(0, 0)
p2 = Point(100, 0)
n = int(input())
print(p1.x, p1.y)
koch(n, p1, p2)
print(p2.x, p2.y)



Measured memory_bytes: 5788
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}
ll g = 1e18;

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	IOS;
	 
    int n; cin>>n;
    ll a[n],b[n];
    forn(i,n) cin>>a[i]>>b[i];
    sort(a,a+n); sort(b,b+n);
    if(n&1)
    {
        ll g = a[n/2], h = b[n/2];
        if(g>h) swap(g,h);
        cout<<h-g+1<<'\n';
        return 0;
    }
    ll g1 = a[n/2-1], g2 = a[n/2];
    g1 = (g1+g2);
    ll h1 = b[n/2-1], h2 = b[n/2];
    h1 = (h1+h2);
    if(g1>h1) swap(g1,h1);
    cout<<h1-g1+1;
    
	return 0;
}


Measured memory_bytes: 6784
c,t,d[4010]={1};char s[4010];i;main(j){for(gets(s);i<(t+=s[i]?2:0);d[j]=!++i)for(j=c+=s[i]%3;j>i+c-t&&~j;d[j--]%=998244353)d[j]+=d[j-1];printf("%d",d[c]);}

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

typedef long long ll;
typedef pair<int, int> pii; 
const int N = 1e9+5, mod = 1e9+7;

void solve() {
    string s; cin >> s;

    int ans = 0;
    bool m = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'R') {
            ++ans;
            m = 1;
        }
        if (m && s[i] == 'S') {
            break;
        }
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1; 
    while (t--) solve();
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    // insert code here...

    int x,y,z;
    double n,n1,n2,rad;
    double PI = acos(-1);
    scanf("%d %d %d",&x,&y,&z);
    rad=z*(PI/180);
    n=(x*y)*sin(rad)*1/2;
    n1=x+y+sqrt((x*x)+(y*y)-(2*x*y*cos(rad)));
    n2=y*sin(rad);
    printf("%f %f %f\n",n,n1,n2);
    return 0;
}



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

int main(){
    int h , w ;
    cin >> h >> w ;

    vector<vector<char>> data(h,vector<char>(w)) ;

    for (int i = 0; i < h; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++)
        {
            data.at(i).at(j) = s.at(j) ;
        }
        
    }
	vector<string> vec(h);
  
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            for (int k = 0; k<h; k++)
            {
                if(data.at(k).at(j) == '#'){
                    break;
                }
                if(k == h-1){
                    data.at(i).at(j) ='x';
                }
            }
            for (int k = 0; k<w; k++)
            {
                if(data.at(i).at(k) == '#'){
                    break;
                }
                if(k == w-1){
                    data.at(i).at(j) ='x';
                  	vec.at(i) = "xx" ;
                }
            }
            
        }
        
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(data.at(i).at(j) != 'x'){
                cout << data.at(i).at(j) ;
            }
        }
        if(vec.at(i)!="xx"){
          cout << endl;
        }        
    }
    
    
    
}

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

int N;
int A[210];

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int res = 0;

  while (true) {
    bool exist_odd = false;
    for (int i =0; i < N; ++i) {
      if (A[i] % 2 != 0) exist_odd = true;
    }

    if (exist_odd) break;

    for (int i = 0; i < N; ++i) {
      A[i] /= 2;
    }
    ++res;
  }

  cout << res << endl;
}

Measured memory_bytes: 256
S = input()
if(S=="SUN"):
	print(7)
elif(S=="MON"):
	print(6)
elif(S=="TUE"):
	print(5)
elif(S=="WED"):
	print(4)
elif(S=="THU"):
	print(3)
elif(S=="FRI"):
	print(2)
elif(S=="SAT"):
	print(1)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
vp adj[100001];
bool visited[100001];
lli paint[100001];
void dfs(lli v,lli dis){
	visited[v]=true;
	paint[v]=dis%2;
	//cout<<v<<" "<<dis<<endl;
	for(lli i=0;i<adj[v].size();i++){
		if(!visited[adj[v][i].fi])dfs(adj[v][i].fi,dis+adj[v][i].se);
	}


}

int main(){
 	ios::sync_with_stdio(0);
    cin.tie(0);
    lli n;
    cin>>n;
    for(lli i=0;i<=n;i++)visited[i]=false;
    for(lli i=0;i<n-1;i++){
    	lli a,b,c;
    	cin>>a>>b>>c;
    	adj[a].pb(mp(b,c));
    	adj[b].pb(mp(a,c));
    }
    dfs(1,0);
   for(lli i=1;i<=n;i++)cout<<paint[i]<<endl;
	return 0;
 }

Measured memory_bytes: 10368
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main{
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		long[][] dp = new long[31][50];
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			for(int day = 0; day < 31; day++){
				Arrays.fill(dp[day], 0);
			}
			
			for(int i = 0; i < n; i++){
				dp[0][i] = 1L << i;
			}
			
			ArrayList<Set<Integer>> list = new ArrayList<Set<Integer>>();
			for(int day = 0; day < 31; day++){
				list.add(new HashSet<Integer>());
			}
			
			for(int i = 0; i < n; i++){
				final int m = sc.nextInt();
				
				for(int j = 0; j < m; j++){
					final int day = sc.nextInt() - 1;
					
					list.get(day).add(i);
				}				
			}
			
			boolean flag = false;
			for(int day = 1; day < 31; day++){
				for(int person = 0; person < n; person++){
					if(!list.get(day - 1).contains(person)){
						dp[day][person] = dp[day - 1][person];
					}else{
						for(int arrival : list.get(day - 1)){
							dp[day][person] |= dp[day - 1][arrival];
						}
					}
					
					if(dp[day][person] == (1L << n) - 1){
						System.out.println(day);
						flag = true;
						break;
					}
				}
				
				if(flag){
					break;
				}
			}
			
			if(!flag){
				System.out.println(-1);
			}
		}
		
	}
}

Measured memory_bytes: 100212
def insertion_sort(array, n)
  1.upto(n-1) do |i|
    current = array[i]
    j = i - 1

    while j >= 0 && array[j] > current
      array[j+1] = array[j]
      j -= 1
    end

    array[j+1] = current
    trace(array)
  end
end

def trace(array)
  puts array.join(' ')
end

n = $stdin.gets.chomp.to_i
array = $stdin.gets.chomp.split(' ').map(&:to_i)

trace(array)
insertion_sort(array, n)

Measured memory_bytes: 8648
def main():
    n = int(input())
    A = list(map(int, input().split()))

    filled = [0]*(n+1)
    ans = []
    for i in range(n-1, -1, -1):
        if sum(filled[::i+1][1:]) % 2 != A[i]:
            filled[i+1] = 1
            ans.append(i+1)
    print(len(ans))
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 20792
#include <cstdio>

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	int a0,v0=-1;
	rep(i,n){
		int a,v; scanf("%d%d",&a,&v);
		if(v0<v || v0==v && a0>a) a0=a, v0=v;
	}
	printf("%d %d\n",a0,v0);

	return 0;
}

Measured memory_bytes: 1028
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

		var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long M = inputArray[1];

			//犬と猿の数が2以上異なると、要件を満たせない
			if (Math.Abs(N - M) > 1) {
				Console.WriteLine(0);
				return;
			}


			long mod = 1000000000 + 7;
			var nPattern = Factorial(N, mod);
			var mPattern = Factorial(M, mod);

			//入れ替え可能かどうか
			var irekae = N == M;
			var combination = (nPattern * mPattern) % mod;


			//答えの出力
			var ans = irekae ? (combination*2) %mod : combination;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// 階乗を返す
		/// </summary>
		/// <param name="n"></param>
		/// <param name="mod"></param>
		/// <returns></returns>
		private static long Factorial(long n,long mod) {

			if (n == 0) {
				return 1;
			}


			long ans = 1;

			for (long i = 1; i <= n; i++) {
				ans *= i;
				ans = ans % mod;
			}

			return ans;
		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 13396
use proconio::input;

fn main() {
    input! {
        n: i32,
        a: [i64; n],
    }
    let max = 1000001;

    let mut counter: Vec::<i64> = vec![0; max];

    for num in &a {
        let mut base = *num as usize;
        if counter[base] > 0 {
            counter[base] += 1;
            continue;
        }
        while base < max {
            counter[base] += 1;
            base += *num as usize;
        }
    }
    println!("{}", a.iter().filter(|n| counter[**n as usize] == 1).count());
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define ar2 array<int,2>
typedef long long LL;
const LL P = 1e9+7;
const LL INF = 1e18;
const int N = 1e5+5;
mt19937 rng(time(0));
 
int n, cnt[51][21];
char str[100];

int main(){
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%s",str+1);
		int m = strlen(str+1), dot = m;
		LL x = 0;
		rep(j,1,m){
			if(str[j]!='.')
				x = x * 10 + str[j] - '0';
			else
				dot = j;
		}
		
		rep(j,1,9+dot-m) x *= 10;
		int n2 = 0, n5 = 0;
		while(x%2==0) x/=2, n2++;
		while(x%5==0) x/=5, n5++;
		cnt[n2][n5]++;
		//cout<<(str+1)<<" "<<n2<<" "<<n5<<endl;
	}
	
	LL ans = 0;
	rep(i1,0,50) rep(j1,0,20){
		if(i1*2>=18 && j1*2>=18)
			ans += 1ll * cnt[i1][j1] * (cnt[i1][j1]-1);
		rep(i2,0,50) rep(j2,0,20) if(i1!=i2 || j1!=j2) {
			if(i1+i2>=18 && j1+j2>=18)
				ans += 1ll * cnt[i1][j1] * cnt[i2][j2];
		} 
	}
	
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 3688
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())
broken = set(int(input()) for _ in range(M))

dp = [0] * (N + 1)
dp[0] = 1

for i in range(1, N + 1):
    if i not in broken:
        dp[i] = dp[i - 1] + (dp[i - 2] if i - 2 >= 0 else 0)
        dp[i] %= (10 ** 9 + 7)

print(dp[-1])



Measured memory_bytes: 52828
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
using namespace std;

int main()
{
#ifdef LOCAL
	assert(freopen("in.in","r",stdin));
#endif
	int n;cin>>n;
	vector<int> arr(n);
	for(auto& i:arr)cin>>i;
	vector<int> dp(n);
	dp[1]=abs(arr[1]-arr[0]);
	for(auto i=2;i<=n;i++){
		dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]) , dp[i-2]+abs(arr[i]-arr[i-2])) ;
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
pair<string,int> D[1000000];
int n,q,b[100000];string s[100000];
int main(){
	scanf("%d%d",&n,&q);
	int cnt=0,t=0;
	for(int i=0;i<n;i++){
		cin>>s[i]>>b[i];
		D[cnt]=make_pair(s[i],b[i]);cnt++;
	}
	for(int i=0;i<cnt;i++){
		if(D[i].second>q){
			t+=q;
			D[cnt]=make_pair(D[i].first,D[i].second-q);
			cnt++;
		}
		else{
			t+=D[i].second;
			cout<<D[i].first<<' '<<t<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 22160
def resolve():
  ans = 0
  s = input()
  n = len(s)-1
  for i in range(1<<n):
    eq = ""
    for j in range(len(s)):
      eq += s[j]
      if (j < n and ((i>>j) & 1)):
        eq += "+"
    ans += eval(eq)
  print(ans)
  return

if __name__ == "__main__":
  resolve()


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

def query(m):
    q = ' '.join(['?']+[str(i+1) for i in range(m,N+m)])
    print(q)
    return input()[0]

init = query(0)
l = 0
r = N
m = N//2
for i in range(10):
    res = query(m)
    if res == init:
        l = m
    else:
        r = m
    m = (l+r)//2
if res == init:
    even = [str(i+1) for i in range(m+1,m+N)]
    l = m+1
    r = m+N-1
else:
    even = [str(i+1) for i in range(m,m+N-1)]
    l = m
    r = m+N-2

ans = [0]*(2*N)
for i in range(2*N):
    if i<l or r<i:
        q = ' '.join(['?']+even+[str(i+1)])
        print(q)
        ans[i] = input()[0]


even = [str(i+1) for i in range(l-1)]+[str(i+1) for i in range(r+2,2*N)]
for i in range(l,r+1):
    q = ' '.join(['?']+even+[str(i+1)])
    print(q)
    ans[i] = input()[0]

print(' '.join(['!',''.join(ans)]))

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

typedef long long ll;

int n, m, sum;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> m;
        sum += m - 1;
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3660
import itertools

N, M = [int(s) for s in input().split()]

edge = [[int(s) - 1 for s in input().split()] for _ in range(M)]
graph = [[] for _ in range(N)]
for i, j in edge:
    graph[i].append(j)
    graph[j].append(i)

result = 0
for path in itertools.permutations(range(1, N)):
    cnt = 0
    for p1, p2 in zip([0] + list(path[:-1]), list(path)):
        cnt += p2 in graph[p1]
    result += cnt == (N - 1)

print(result)


Measured memory_bytes: 3064
/* Coached by Dukkha */
#include <stdio.h>

int first(int n) {
	return n < 10 ? n : first(n / 10);
}

int main() {
	static int kk[10][10];
	int n, x, y, ans;

	scanf("%d", &n);
	while (n) {
		x = first(n);
		y = n % 10;
		kk[x][y]++;
		n--;
	}
	ans = 0;
	for (x = 1; x <= 9; x++)
		for (y = 1; y <= 9; y++)
			ans += kk[x][y] * kk[y][x];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
import sys,functools
if sys.version_info[0]>=3:
	maketrans=str.maketrans
else:
	from string import maketrans

O=lambda a:lambda b:a|b
A=lambda a:lambda b:a&b
X=lambda a:lambda b:a^b
while True:
	s=sys.stdin.readline().rstrip().translate(maketrans('+*^[]','OAX()'))
	if s=='.': break
	for c in 'abcd': s=s.replace(c,'(%s)'%c)
	s=s[1:-1]
	n=int(sys.stdin.readline())
	r=eval(s.translate(maketrans('abcd','%04d'%n)))
	print('%d %d'%(r,sum(r==eval(s.translate(maketrans('abcd','%04d'%i))) for i in range(10000))))


Measured memory_bytes: 5012
#include <iostream>
#include <algorithm>
#include <assert.h>
using i64 = long long;
using namespace std;

class ModInt {
public:
  int value;
  static const int mod = 1e9 + 7;
  ModInt(int value = 0) {
    this->value = normalize(value);
  }  
  ModInt& operator+=(const ModInt& other) {
      this->value = (*this + other).value;
      return *this;
  }
  ModInt& operator-=(const ModInt& other) {
      this->value = (*this - other).value;
      return *this;
  }
  ModInt& operator*=(const ModInt& other) {
      this->value = (*this * other).value;
      return *this;
  }
  ModInt& operator/=(const ModInt& other) {
      this->value = (*this / other).value;
      return *this;
  }
  int inverse(int a) const {
    int m = mod;
    int u = 0, v = 1;
    while (a != 0) {
        int t = m / a;
        m -= t * a; swap(a, m);
        u -= t * v; swap(u, v);
    }
    assert(m == 1);
    return u;
  }
  ModInt operator+(const ModInt &R) const {
    return ModInt(ModInt::normalize(this->value + R.value));
  } 
  ModInt operator-(const ModInt &R) const {
    return ModInt(ModInt::normalize(this->value - R.value));
  } 
  ModInt operator*(const ModInt &R) const {
    return ModInt(ModInt::normalize((i64) this->value * R.value));
  } 
  ModInt operator/(const ModInt &R) const {
    return ModInt(ModInt::normalize((i64) this->value * inverse(R.value)));
  }
  int normalize(i64 value) const {
    while (value < 0) value += mod;
    value %= mod;
    return value;
  }
};

ostream& operator<<(ostream& os, ModInt const &m) {
  os << (m.value);
  return os;
}

istream& operator>>(istream& is, ModInt& r) {
    is >> r.value;
    r.value = r.normalize(r.value);
    return is;
}

const int maxn = 1e5;
ModInt dp[maxn + 1][100][2] = {0};
int main() {
  string s;
  int d;
  cin >> s >> d;
  reverse(s.begin(), s.end());
  dp[0][0][0] = 1;
  dp[0][0][1] = 1;
  for (int i = 1; i <= s.size(); i++) {
    for (int rem = 0; rem < d; rem++) {
      for (int limit = false; limit <= 1; limit++) {
        int max_digit = limit ? s[i - 1] - '0' : 9;
        for (int j = 0; j <= max_digit; j++) {
          int new_rem = (rem + j) % d;
          int new_limit = limit ? j == max_digit : false;
          dp[i][rem][limit] += dp[i - 1][new_rem][new_limit];
        }
      }
    }
  }
  
  cout << dp[s.size()][0][1] - 1 << '\n';
}

Measured memory_bytes: 78336
fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    val tds = (1..q).map { readLine()!!.split(" ") }


    fun simulate(pos: Int): Int {
        var now = pos
        for ((t, d) in tds) {
            if (s[now].toString() != t) {
                continue
            }
            if (d == "L") {
                now--
            } else {
                now++
            }
            if (now < 0) {
                return -1
            } else if (now >= n) {
                return 1
            }
        }
        return 0
    }


    var low = -1
    var high = n
    while (Math.abs(high - low) > 1) {
        val mid = (high + low) / 2
        if (simulate(mid) == -1) {
            low = mid
        } else {
            high = mid
        }
    }
    var left = high

    low = -1
    high = n
    while (Math.abs(high - low) > 1) {
        val mid = (high + low) / 2
        if (simulate(mid) == 1) {
            high = mid
        } else {
            low = mid
        }
    }
    val right = low

    println(right - left + 1)
}

Measured memory_bytes: 150352
#include <bits/stdc++.h>
using namespace std;
#define ffo(i,s,e) for(int i=s;i<e;i++)
#define rfo(i,s,e) for(int i=s;i>=e;i--)
#define ll long long
#define deb(x)	cout <<#x <<" "<< x <<"\n"
#define ff              first
#define ss              second
#define ll             	long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int k;
    cin >> k;
    cin.ignore();
    string s;
    cin >> s;
    cin.ignore();
	if (k < (int)s.length()){
		s = s.substr(0,k);
		s.append("...");
		cout << s;
	}
	else
		cout << s;
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

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



Measured memory_bytes: 3640
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    if nt<t or na<a:
        r = max(-(-t//nt), -(-a//na))
        nt *= r
        na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int h, n;
    cin >> h >> n;
    ll count = 0;
    rep(i, n) {
        int a;
        cin >> a;
        count += a;
    }
    if(count >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636