akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(x: "List[int]"):
    return x.index(0) + 1

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = [int(next(tokens)) for _ in range(5)]  # type: "List[int]"
    print(solve(x))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9172
N = int(input())
A=[0]*N
P=[0]*N


for i in range(N):
    A[i] = list(map(int,input().split()))
for i in range(N):
    P[i] = list(map(int,input().split()))

MAX=-1*(10**9)
for i in range(1,1024):
    t=format(i,"b")
    l=10-len(t)
    t="0"*l+t
    a=[0]*N
    for j in range(10):
        
        if(t[j]=="1"):
            for k in range(N):
                
                if(int(A[k][j])==int(t[j])):
                    a[k]+=1
    T=0
    for j in range(N):
        T+=P[j][a[j]]
    MAX=max(T,MAX)

print(MAX)





Measured memory_bytes: 43372
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
	

int main() {
	int n,k;
	cin >> n >> k;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}
	int x = k / 2;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (vec.at(i) <= x) {
			sum += vec.at(i) * 2;
		}
		else {
			sum += (k - vec.at(i)) * 2;
		}
	}
	cout << sum;

	return 0;
}










Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		int ans = N*2;

		if (s.equals(t)) {
			System.out.println(N);
			System.exit(0);
		}

		for (int i = 0; i < N; i++) {
			String sSub = s.substring(N-1-i, N);
			String tSub = t.substring(0, i+1);
			if (sSub.equals(tSub)){
				ans = (N-(i+1))*2 + i+1;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 9800
n = int(input())
a = list(map(int, input().split()))
cnt = 0

def selection_sort(a):
    global cnt
    for i in range(len(a)):
        min_idx = i
        for j in range(i + 1, len(a)):
            if a[j] < a[min_idx]:
                min_idx = j
                #cnt += 1
        if i != min_idx:
            a[i], a[min_idx] = a[min_idx], a[i]
            cnt += 1

selection_sort(a)
print(*a)
print(cnt)


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

struct Matrix {
  int low;
  int col;
};

int main() {
  int n; cin >> n;
  vector<Matrix> l(n);
  rep(i, n) {
    int a, b; cin >> a >> b;
    l.at(i).low = a;
    l.at(i).col = b;
  }

  vector<vector<int>> dp(n, vector<int>(n));
  rep(i, n) {
    dp.at(i).at(i) = 0;
  }

  for (int j = 1; j<n; j++) {
    int i = j-1;
    while (i>=0) {
      int k = i;
      int mi = 100000000;
      while (k < j) {
        mi = min(mi, (l.at(i).low * l.at(k).col * l.at(j).col) + dp.at(i).at(k) + dp.at(k+1).at(j));
        k++;
      }
      dp.at(i).at(j) = mi;
      i--;
    }
  }
  cout << dp.at(0).at(n-1) << endl;
}



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

using namespace std;
using ll = long long;

int N;
int L[101];
int main(){

    cin >> N;
    int tot = 0;
    for(int i = 0; i < N; i++){
        cin >> L[i];
        tot += L[i];
    }
    sort(L, L + N);
    int big = L[N - 1];
    tot -= big;
    if(tot > big){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
words = [ input() for _ in range(n) ]
ans = True
if len(set(words)) != n:
    ans = False
for i in range(n - 1):
    if words[i][-1] != words[i + 1][0]:
        ans = False
print(['No', 'Yes'][ans])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
// g++ -std=c++17 -Wshadow -Wall sol.cpp -o  s -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vvi = vector< vi > ;
using ld = long double;
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3fll;
template<typename T> T abs (T x) { return x < 0 ? -x : x; }
template<typename T> void max_self(T &a, T b) {  a = max(a, b); }
template<typename T> void min_self(T &a, T b) {  a = min(a, b); }

void solve(int tc) {
  int r;
  int n;
  cin >> n;
  unordered_map<int, int>cnt;
  for(int i = 0; i < n-1; ++i){
    cin >> r;
    cnt[r]++;
  }
  for(int i = 1; i <=n; ++i)cout << cnt[i] << "\n";
 }

int main() {
  int tc = 1;
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cin >> tc;
  for(int i = 1; i <= tc; ++i)solve(i);
  return 0;
}

Measured memory_bytes: 11472
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;



int main(){
	for(int n; cin >> n; ) {
		vi p(n + 1, 1);
		p[0] = p[1] = 0;
		int ans = 0;
		rep(i, n + 1) if (p[i]) {
			ans++;
			for (int j = i + i; j <= n; j += i) p[j] = 0;
		}
		cout << ans<< endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+1;
int m, n; map<int,int> bomb; vector<pair<int,int>> g[N]; 
vector<int> b, x, s; bool visited[N];
inline void read_bombs() {
	for (int a, b, i = 0; i < n; ++i) 
    	cin >> a >> b, bomb[a] = b;
	for (auto &q: bomb) 
		b.push_back(q.second), q.second = b.size()-1;
	b.push_back(0), x.push_back(b.front()), bomb[INT_MAX] = n;
	for (int i = 0, j = 1; i < n; i = j++) 
		x.push_back(b[j] != b[i]); }
inline void read_cord(int i) {
	int l, r; 
	cin >> l >> r, 
    l = bomb.lower_bound(l)->second, r = bomb.lower_bound(r+1)->second,
    g[l].emplace_back(i,r), g[r].emplace_back(i,l); }
int dfs(int u, int p = -1) {
	int t = x[u];
	visited[u] = true; 
	for (auto e: g[u]) 
    	if (e.second != p and not visited[e.second] and dfs(e.second,u)) 
    		s.push_back(e.first), t ^= 1;
	return t; }
inline void write_ans() {
    cout << s.size() << "\n";
    sort(s.begin(), s.end());
    for (auto cord: s) 
      cout << cord <<  ' '; }
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cin >> n >> m, read_bombs();
	for (int i = 1; i <= m; ++i) 
		read_cord(i);
	for (int i = 0; i <= n; ++i) 
    	if (not visited[i] and dfs(i)) 
    		cout << -1, exit(0);
    write_ans(); }

Measured memory_bytes: 19708
n=int(input())
s=[input() for i in range(n)]
cnt1=0
cnt2=0
cnt3=0
cnt4=0
for si in s:
    if si[0]=='B' and si[-1]=='A':
        cnt1+=1
    elif si[0]=='B':
        cnt2+=1
    elif si[-1]=='A':
        cnt3+=1
    for i in range(len(si)-1):
        if si[i]=='A' and si[i+1]=='B':
            cnt4+=1
if cnt2>=1:
    if cnt3>=1:
        print(cnt4+cnt1+min(cnt2, cnt3))
    else:
        print(cnt4+cnt1)
else:
    if cnt3>=1:
        print(cnt4+cnt1)
    elif cnt1>1:
        print(cnt4-1+cnt1)
    else:
        print(cnt4)

Measured memory_bytes: 47064
#include<iostream>

using namespace std;

int main()
{
	int n,m,tmp,tmp2;
    cin >> n >> m;
    int array[n+1];
    for(int i=1;i<n+1;i++){
        	array[i] = 0;
        }

    for(int i=0;i<m;i++){
    	cin >> tmp;
    	array[tmp]=array[tmp]+1;
    	cin >> tmp2;
    	array[tmp2]=array[tmp2]+1;
    }
    for(int i=1;i<n+1;i++){
    	cout<<array[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int N;
	int T[110];
	int M;
	int P[110];
	int X[110];
	cin >> N;
	int beforetime = 0;
	for (int i = 0; i < N; ++i) {
		cin >> T[i];
		beforetime += T[i];
	}
	cin >> M;
	int aftertime[110];
	for (int i = 0; i < M; ++i) {
		aftertime[i] = beforetime;
	}
	for (int i = 0; i < M; ++i) {
		cin >> P[i] >> X[i];
		aftertime[i] = (aftertime[i] - T[P[i]-1] + X[i]);
	}
	for (int i = 0; i < M; ++i) {
		cout << aftertime[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N , A[2][110];
int ans = 0;
/*==================================================*/
/*function*/

void dfs(int y, int x, int cnt){

    cnt += A[y][x];

    if(y == 1 && x == N-1){
        ans = max(cnt, ans);
        return;
    }

    int nx = x;

    if(y+1 < 2) dfs(y+1, x, cnt);
    if(x+1 < N) dfs(y, x+1, cnt);
}

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,2){
        REP(j,0,N){
            cin>>A[i][j];
        }
    }

    dfs(0,0,0);

    cout<<ans<<endl;

    return 0;
}


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

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

    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    
    if(s < t)   cout << "Yes" << endl;
    else        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF ( 1<<29 )
int N,M,L,K,A,H;
struct edge{
  int to,c;
};
struct state{
  int id,m,c;
  bool operator<(const state& s) const {
    return c > s.c;
  }
};
bool rf[111];
int mem[111][111];
vector<edge> G[111];

int solve(){
  priority_queue<state> q;
  q.push( (state){ A, M, 0 } );
  fill(mem[0],mem[N],INF);
  mem[A][M] = 0;
  while( !q.empty() ){
    state p = q.top(); q.pop();
    int id = p.id;
    int m = p.m;
    int c = p.c;
    if( mem[id][m+1] < c ) continue;
    if( id == H ) return c;
    if( rf[id] && M > m ) {
      if( mem[id][m+1] > c + 1 ){
	mem[id][m+1] = c + 1;
	q.push( (state){id,m+1,c+1} );
      }
    }
    for(int i=0;i<(int)G[id].size();i++){
      edge e = G[id][i];
      if( m-e.c<0 ) continue;
      if( mem[e.to][m-e.c] > c + e.c ){
	mem[e.to][m-e.c] = c + e.c;
	q.push( (state){ e.to, m-e.c, c+e.c} );
      }
    }
  }
  return -1;
}

int main(){
  while( cin >> N >> M >> L >> K >> A >> H && (N || M || L || K || A || H ) ){
    memset(rf,0,sizeof(rf));
    for(int i=0;i<L;i++){
      int a; cin >> a;
      rf[a] = true;
    }
    for(int i=0;i<K;i++){
      int x,y,t;
      cin >> x >> y >> t;
      G[x].push_back( (edge){y,t} );
      G[y].push_back( (edge){x,t} );
    }
    int res = solve();
    if( res == -1 ) cout << "Help!" << endl;
    else cout << res << endl;
    for(int i=0;i<N;i++) G[i].clear();
  }
}

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

public class Main {

    static final long INF = Long.MAX_VALUE / 10;

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        long x = sc.nextLong();

        for (int i = 0; i < 10000; i++) {
            for (int j = i; j < 10000; j++) {
                long a = calc(i);
                long b = calc(j);

                if (a < 0 || b < 0)
                    continue;

                if (a - b == x) {
                    System.out.println(i + " " + j);
                    return;
                } else if (a + b == x) {
                    System.out.println(i + " -" + j);
                    return;
                } else if (-a + b == x) {
                    System.out.println("-" + i + " -" + j);
                    return;
                }
            }
        }
    }

    static long calc(int a) {
        long t = a;
        for (int i = 1; i < 5; i++) {
            if (t > INF || t < 0)
                return -1;
            t *= a;
        }
        return t;
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int n; cin >> n&&n;) {
		vector<pair<int, int>> v(n);
		rep(i, 0, n) {
			cin >> v[i].second >> v[i].first;
		}
		sort(all(v));
		int cur = 0;
		bool flag = true;
		rep(i, 0, n) {
			cur += v[i].second;
			if (cur > v[i].first) {
				flag = false;
				break;
			}
		}
		if(flag)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n,a[N],las;
int main() {
  scanf("%d",&n);
  for (int i = 1 ; i <= n ; ++ i)
    scanf("%d",&a[i]);
  sort(a+1,a+n+1);
  for (int i = n ; i > 1 ; -- i) {
    if (a[i] == a[i-1]) {
      if (!las) {
	las = a[i];
	-- i;
      } else return 0 * printf("%lld\n",1ll * las * a[i]);
    }
  }
  puts("0");
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
using namespace std;
int n, w[210], res;
int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=2*n;i++)scanf("%d",&w[i]);
    sort(w+1,w+2*n+1);
    for(i=1;i<=n;i++)res += w[i*2-1];
    printf("%d\n",res);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

bool is_prime(Int N) {
    if (N == 1) return false;
    for (Int i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

bool judge(Int a){
    if(is_prime(a) && is_prime((a+1)/2)) return true;
    return false;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q; cin>>q;
    vector<int> ans(100010,0);
    int tmp=0;
    for(int i=1; i<=100000; i++){
        if(judge(i)){
            tmp++;
            ans[i]=tmp;
        }
        else ans[i]=tmp;
    }
    for(int i=0; i<q; i++){
        int l,r; cin>>l>>r;
        cout<<ans[r+1]-ans[l-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>

int main(){
	
	int x, y, z = 0;
	
	scanf("%d %d", &x, &y);
	
	if(y % 2 == 0){
		z = x + (y / 2);
	}
	
	printf("%d\n", z);
	
	return 0;
}

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

int main(){
    string S;
    cin >> S;
//    string al = 'abcdefghijklmnopqrstuvwxyz';
    string al = "abcdefghijklmnopqrstuvwxyz";
    bool flag;
    bool flagres = false;
    for(int i=0;i<26;i++){
        flag = true;
        for(int j=0;j<S.size();j++){
            if(S[j] == al[i]){
                flag = false;
                break;
            }
        }
        //最後までその文字がなかった場合、
        if(flag == true){
            cout << al[i] << endl;
            flagres = true;
            break;
        }
    }

    if(flagres == false){
        cout << "None" << endl;
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <array>

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

    long int n;

    while (std::cin >> n, n++) {
        long int age;
        std::array<long int, 7> arr{{}};

        for (; --n;) {
            std::cin >> age;
            age < 70 ? ++arr[age / 10] : ++arr[6];
        }
        
        for (const auto& cnt : arr) {
            std::cout << cnt << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1192
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
tasks = []
cnt = 0
for i in range(n):
    a,b = inpl()
    tasks.append([a,b,abs(a-b)])
tasks.sort(key=lambda x:x[1])

for task in tasks:
    cnt += task[0]
    if cnt > task[1]:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 46436
#include <iostream>
#include <vector>
using namespace std;
bool check(string S, string T){
  vector<int> C(26,-1);
  for(size_t i = 0; i < T.length(); ++i){
    int s = S[i] - 'a', t = T[i] - 'a';
    if(C[t] >= 0 && C[t] != s){
      return false;
    }
    C[t] = s;
  }
  return true;
}

int main(){
  string S, T;
  cin >> S >> T;
  bool f = check(S,T);
  swap(S,T);
  f &= check(S,T);
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1160
n = int(input())
a = list(map(int, input().split()))
ruiseki = [0] * (n + 1)

for i in range(n):
    ruiseki[i + 1] = ruiseki[i] + a[i]

ans = 10 ** 18
for i in range(1, n):
    ans = min(ans, abs(ruiseki[-1] - 2 * ruiseki[i]))
print(ans)

Measured memory_bytes: 76752
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		boolean ans = false;
		
		for(int i = a; i <= b; i++) {
			if(i % k == 0) {
				ans = true;
				break;
			}
		}

		System.out.println(ans ? "OK" : "NG");
		sc.close();
	}

}

Measured memory_bytes: 35820
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <time.h>

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void *)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

i32 main(void){
    while(1){
        i64 n,m;
        scanf("%lli%*c%lli%*c",&n,&m);
        if(n==0LL&&m==0LL) break;
        i64 *a=(i64 *)calloc(n,sizeof(i64));
        for(i64 i=0LL;i<n;++i) scanf("%lli%*c",&a[i]);
        i64 cur=0LL,p,ans=llinf;
        for(i64 i=0LL;i<m;++i){
            scanf("%lli%*c",&p);
            cur+=p;
            if(cur>=n-1LL){
                if(ans==llinf) ans=i+1LL;
                continue;
            }
            cur+=a[cur];
            if(cur>=n-1LL){
                if(ans==llinf) ans=i+1LL;
                continue;
            }
        }
        printf("%lli\n",ans);
    }
    return 0;
}



Measured memory_bytes: 2048
[a, b, c, k] = list(map(int, input().split()))
res = 0

x = min(a, k)
res += 1 * x
k -= x

x = min(b, k)
res += 0 * x
k -= x

x = min(c, k)
res += -1 * x
k -= x

print(res)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n);
	LL hs[n], maxH = 0, ans = 0;
	rep(i, 0, n) {
		hs[i] = scanLong();
		if(i == 0)	maxH = hs[i];
		else	maxH = max(maxH, hs[i]);
		if(hs[i] == maxH)	ans++;
	}
	cout << ans << endl;
}


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

namespace AtCoder.Contest.A
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int n = cin.nextInt();
			Console.WriteLine(n * n * n);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 27508
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=1000000007;
struct fenw{
  VI fw;
  in n;
  void ini(in pn){
    n=pn;
    fw.clear();
    fw.resize(n,0);
  }
  void ad(in l, in x){
    while(l<n){
      fw[l]+=x;
      l|=(l+1);
    }
  }
  in sm(in l){
    in r=0;
    while(l>=0){
      r+=fw[l];
      l&=(l+1);
      --l;
    }
    r%=mdl;
    return r;
  }
};
fenw tfw;
in a,b;
VI v;
VI tw;
in wy(){
  in n=sz(v);
  tw.resize(n);
  forn(i,n)
    tw[i]=0;
  tfw.ini(n);
  in nob=1;
  in nxt=0;
  in c;
  in lval=0;
  forn(i,n){
    if(i==0){
      tfw.ad(i,1);
      tw[i]=1;
      continue;
    }
    while(v[i]-v[nxt]>=b)
      ++nxt;
    c=tfw.sm(nxt-1)+nob;
    c%=mdl;
    tfw.ad(i,c);
    tw[i]=c;
    if(v[i]-v[i-1]<a){
      if(i>=2 && v[i]-v[i-2]<a)
	return 0;
      nob=0;
      for(in j=lval;j<i-1;++j){
	tfw.ad(j,-tw[j]);
	tw[j]=0;
      }
      lval=i-1;
    }
  }
  return (tfw.sm(n-1)+nob)%mdl;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n>>a>>b;
  if(a>b)
    swap(a,b);
  in w=1;
  in t;
  forn(z,n){
    cin>>t;
    if(v.empty() || t-v.back()<b)
      v.PB(t);
    else{
      w*=wy();
      w%=mdl;
      v.clear();
      v.PB(t);
    }
  }
  w*=wy();
  w%=mdl;
  cout<<w<<endl;
  return 0;
}


Measured memory_bytes: 2804
# Problem:https://atcoder.jp/contests/agc012/tasks/agc012_a
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(groupNumber, scoreList):
    allMenbar = 3 * groupNumber
    scoreList.sort()
#    print(scoreList)
    secondPositioner = scoreList[groupNumber:allMenbar:+2]
#    print(secondPositioner)
    result = sum(secondPositioner)
    # algorithm
    return result


if __name__ == "__main__":
    N = II()
    AI = LI()
    print("{}".format(solver(N, AI)))


Measured memory_bytes: 37084
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())

win = {"r":"p","s":"r","p":"s"}
point = {"r":r,"s":s,"p":p}

ans = []
sum = 0

for i in range(k):
    ans.append(win[t[i]])
    sum+=point[win[t[i]]]

for i in range(k,n):
    if win[t[i]] == ans[i - k]:
        ans.append(-1)
    else:
        ans.append(win[t[i]])
        sum+=point[win[t[i]]]
print(sum)

Measured memory_bytes: 53260
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
l, r = 0, 0
for i in range(n):
    if (i < x and a.count(i)): l += 1
    if (i > x and a.count(i)): r += 1
print(min(l, r))


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int pn[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43 ,47};
int primec[15] = {};

void divide(int n){
  int cp = n;
    REP(i, 15){
      while(n % pn[i] == 0){
          n /= pn[i];
          primec[i]++;
        }
        n = cp;
    }
  }

int main(){
  int N, ans;
  cin >> N;

  FOR(i,1,(N+1)) divide(i);

  int c[75] = {};
  REP(i, 15){
    REP(j, 75){
        if(primec[i] >= j) c[j]++;
      }
    }
    cout << endl;

    if(c[4] == 0) ans = 0;
    else ans = (c[2] - 2) * ((c[4]  * (c[4] - 1)) / 2) + c[24] * (c[2] - 1) + (c[4]-1) * c[14] + c[74];

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=(1<<16);
int n,m;
int cst[22][22];
int f[22][maxn],dp[22][maxn];
int fa[22];
inline int getfa(int x){return x==fa[x]?x:fa[x]=getfa(fa[x]);}
int check(int msk)
{
	int sum=0;
	for(int i=0;i<n;i++)fa[i]=i;
	for(int i=0;i<n;i++)if(msk>>i&1)
	{
		for(int j=i+1;j<n;j++)if((msk>>j&1)&&~cst[i][j])
		{
			int x=getfa(i),y=getfa(j);
			fa[x]=y;
			sum+=cst[i][j];
		}
	}
	int p=-1;
	for(int i=0;i<n;i++)if(msk>>i&1)
	{
		if(p==-1)p=getfa(i);
		else
		{
			if(p!=getfa(i))return -1;
		}
	}
	return sum;
}
int good[maxn];
inline void update(int &a,int b)
{
	if(a<b)a=b;
}
int main()
{
	memset(cst,-1,sizeof(cst));
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a--,b--;
		cst[a][b]=cst[b][a]=c;
	}
	memset(f,-1,sizeof(f));
	memset(good,-1,sizeof(good));
	for(int msk=0;msk<(1<<n);msk++)
	{
		good[msk]=check(msk);
		for(int i=0;i<n;i++)if(msk>>i&1)
		{
			f[i][msk]=good[msk];
		//	if(~f[i][msk])good[msk]=1;
	//		cout<<i<<" "<<msk<<" "<<f[i][msk]<<endl;
		}
	}
	
	//1
	memset(dp,-1,sizeof(dp));
	for(int msk=0;msk<(1<<n);msk++)
	{
		dp[0][msk]=f[0][msk];
	}
	for(int msk=0;msk<(1<<n);msk++)
	{
		for(int i=0;i<n;i++)if((msk>>i&1)&&(~dp[i][msk]))
		{
			int rmsk=((1<<n)-1)^msk;
			for(int s=rmsk;s;s=(s-1)&rmsk)if(~good[s])
			{
				for(int j=0;j<n;j++)if((s>>j&1)&&(~cst[i][j]))
				{
					update(dp[j][msk|s],dp[i][msk]+cst[i][j]+good[s]);
				}
			}
		}
	}
	
	int ans=inf;
	int sum=0;
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)if(~cst[i][j])sum+=cst[i][j];
	for(int msk=0;msk<(1<<n);msk++)
	{
		if(~dp[n-1][msk])
		{
			ans=min(ans,sum-dp[n-1][msk]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n" ; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
 
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define foe(i,x) for(auto& i: x)
#define ar array
#define pb push_back
#define vt vector
#define F first
#define S second

template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;}
template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {cin>>x;}
void read(double& d) {string t;read(t);	d=stod(t);}
void read(long double& d) {	string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) {	foe(a, x)read(a);}
int nxt(){int a;read(a);return a;}   // iota(all(v),0); genrate(all(v),nxt);

// no change 
const ll MOD = 1e9+7;  
int mx = 1e6+1;
void Titan(){
	ll n,k , m;
	read(n,k,m);

	ll a = n/m;
	if(n%m == 0)a--;
	ll b = (k)/m;
	ll ans = b-a;
	if(ans<0)ans = 0;
	cout << ans;
	

}

	

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
	//cin >> T;		//cmt if one test case
    fo(T){
		//cout << "Case #" << i+1 << ": " ;
		Titan();
	}
}
/*///////////////////////////////////////////////////////////
Important Notes : 
* check long long 
* check base cases
* do not loose Hope
* if case fails on 2nd test case maybe some cases are missing check them
* do not sit idle
* try to do it using pen/paper.
*/


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) (int)v.size()
//#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; 
#define prl cerr<<"called: "<< __LINE__<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 1e6 + 100;

int cnt[N];
int a[N];
int32_t main(){
  fastio;
  int n;
  cin>>n;
  int g = -1;
  for(int i=1;i<=n;i++){
    cin >> a[i];
    if(g == -1)g = a[i];
    else g = gcd(g,a[i]);
    cnt[a[i]]++;
  }
  bool bad=0;
  for(int i=2;i<N;i++){
    int tot=0;
    for(int j=i;j<N;j+=i)tot+=cnt[j];
    if(tot > 1){
      bad = 1;
      break;
    }
  }
  if(!bad)cout<<"pairwise coprime"<<endl;
  else if(g==1)cout<<"setwise coprime"<<endl;
  else cout <<"not coprime"<<endl;
  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

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

int rui(int,int);

int main(){

  int n,a,b,i,j,count,sum,sum2,sum3;
  cin>>n>>a>>b;
  vector<int> vec(5,0);
  count=0;

  for(j=0;j<n;j++){
    sum=n-j;
    sum3=n-j;
    for(i=4;i>=0;i--){
      vec.at(i)=sum/rui(10,i);
      sum-=vec.at(i)*rui(10,i);
    }
    sum2=0;
    for(i=0;i<=4;i++)
    sum2+=vec.at(i);
    if(sum2>=a&&sum2<=b)
    count+=sum3;
  }
  cout<<count<<endl;
}

int rui(int a,int b){

  int i,c;

  c=a;
  if(b==1)
  return a;
  else if(b==0)
  return 1;
  else{
    for(i=1;i<b;i++)
    a*=c;
    return a;
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_139
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long n = ReadLong();
            WriteLine(n * (n - 1) / 2);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define random_shuffle asdasdd

const int mod = (int) 1e9 + 7;

int s;
long long ans;

long long binpow(long long x, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) {
      res = (res * x) % mod;
      p--;
    } else {
      x = (x * x) % mod;
      p /= 2;
    }
  }
  return res % mod;
}

int subMod(int a, int b) {
  int res = a - b;
  return res < 0 ? res + mod : res;
}

int main() { 

  cin >> s;

  int r = 1; 
  int total = 1;
  int radd = 1, irem = 1;
  int pr = 10, pi = 10;
  for (int i = 1; i < 10 * 1000 *  1000; i++) {
    while (total < s) {
      r++;
      if (r % pr == 0) {
        radd++;
        pr *= 10;
      }
      total += radd;
    }
    if (total == s) {
      ans++;
    }
    if (i % pi == 0) {
      irem++;
      pi *= 10;
    }
    total -= irem;
  }

  for (int i = 1; i <= s / 8; i++) {
    if (s % i == 0) {
      long long num = 9ll * binpow(10, s / i - 1) % mod;
      num = subMod(num, i - 1);
      ans = (ans + num) % mod;
    } else {
      ans = (ans + 1) % mod;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(b, n*a) << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
	ll N;
	cin >> N;
	vll A(N);
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	ll max_idx=distance(A.begin(),max_element(A.begin(),A.end()));
	ll max_n=A[max_idx];

	vll B(A);
	B.erase(B.begin()+max_idx);
	ll max2_idx=distance(B.begin(),max_element(B.begin(),B.end()));
	ll max2_n=B[max2_idx];

	for(int i=0; i<N; i++){
		if(i==max_idx){
			cout << max2_n << endl;
		}else{
			cout << max_n << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 4736
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    unordered_map<string,int> m;
    vector<string> vs;
    int maxCount = 0;
    rep(i,N){
        string s;
        cin >> s;
        m[s]++;
        maxCount = max(maxCount,m[s]);
    }
    for(auto s:m){
        if(s.second==maxCount){
            vs.push_back(s.first);
        }
    }
    sort(All(vs));
    for(auto s:vs){
        cout << s << nn;
    }
    return 0;
}

Measured memory_bytes: 25284
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll x=0,y,z;
	ll n,h,i=1;
	cin>>h;
	while(h!=1)
	{
		x=x+i;
		i=2*i;
		h=h/2;
	}
	x=x+i;
	cout<<x;
	return 0;
}



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


int main(){
	set<int> bag;
	int n;
	cin >> n;
	for(int i=0; i < n; i++){
		int x;
		 cin >> x;
		 bag.insert(x);
	}
	if(bag.size() == n) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 9600
def main():
    import sys 
    input=sys.stdin.readline
    
    k=int(input())
    a,b =map(int ,input().split())
    
    for i in range(a,b+1):
        if i%k==0:
            print('OK')
            exit()
        
    print('NG')
    
    
if __name__=='__main__':
    main()
        
    

Measured memory_bytes: 9180
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int):
    counter = 0
    for i in range(len(str(N))-1, 0, -1):
        if i % 2 == 0:
            continue
        counter += 9*(10**(i-1))
    if len(str(N)) % 2 == 1:
        counter += N-10**(len(str(N))-1)+1
    print(counter)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
s;n,k,i,y;d['   '];c(int*z){i=*1[&z]-*z;}main(x){for(scanf("%*d");~scanf("%d%d",&n,&k);printf("%d\n",s)){for(i=n--;s=i;y=x)scanf("%d",&x),d[--i]=x-y;qsort(d,n,4,c);for(;n>=k;s+=d[--n]);}}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	while(n)
	{
		if(n%10==7)
		{
			cout<<"Yes";
			return 0;
		}
		n/=10;
	}
	cout<<"No";
	return 0;
}

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

using namespace std;

int main(){
    int N,M,C;
    cin>>N>>M>>C;
    int B[M];
    for(int i = 0; i < M; i++){
        cin>>B[i];
    }
    int A[N][M];
    int c = 0;
    for(int i = 0; i < N; i++){
        int res = C;
        for(int j = 0; j < M; j++){
            cin>>A[i][j];
            res += A[i][j]*B[j];
        }
        if(res > 0) c++;
    }
    cout<<c<<endl;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s; cin >> s;
  int n = s.size();
  vector<int> freqs(128, 0);
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    if (++freqs[s[i] - 'a'] > 1) {
      ok = false;
      break;
    };
  }
  printf("%s\n", ok ? "yes" : "no");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define read(n) scanf("%lld",&n)
#define write(x) printf("%lld",x)
#define F(i,n) for(int i = 0;i < n;i++)
#define ll long long
#define MX 100005
#define MOD 1000000007
#define INF 1000000009
#define set_dp(dp) memset(dp,-1,sizeof(dp))
using namespace std;
string s, t;
vector<unordered_map<char,ll> > jump;
int main(){
	cin>>s>>t;
	ll n = s.size();
	jump.resize(n);
	unordered_map<char,ll> cm;
	for(char c = 'a'; c <= 'z'; c++) cm[c] = -1;
	for(ll i = n - 1; i >= 0; i--){
		cm[s[i]] = i;
		jump[i] = cm;
	}
	for(char c:t){
		if(cm[c] == -1){
			cout<<-1<<endl;
			return 0;
		}
	}
	ll ans = 0, i = 0, j = 0, m = t.size();
	while(j < m){
		if(jump[i][t[j]] == -1){
			ans += n;
			i = 0;
		}
		else{
			i = jump[i][t[j++]] + 1;
			if(i == n){
				i = 0;
				ans += n;
			}
		}
	}
	ans += i;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 124672
#!/usr/bin/env python3
import sys
import collections
input = sys.stdin.readline
#s=list(input())
#n=int(input())
A= list(map(int,input().split()))
#a,b,c,d,e= map(int,input().split())
for i in range(5):
    if A[i]==0:
      print(i+1)
      sys.exit()

Measured memory_bytes: 9464
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	if N % 2 == 0:
		print(N // 2 - 1)
	else:
		print(N // 2)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int n; cin>>n;
    string s; cin>>s;
    ll rcnt=0;
    ll gcnt=0;
    ll bcnt=0;

    rep(i,n){
        if(s[i]=='R'){
            rcnt++;
            continue;
        }
         if(s[i]=='G'){
            gcnt++;
            continue;
        }
         if(s[i]=='B'){
            bcnt++;
            continue;
        }
    }

    ll big_sum=rcnt*gcnt*bcnt;
    ll ng_cnt=0;
    for(int i=1; i<=n-2; i++){
        for(int j=1; j<=min(i,n-i-1); j++){
            if((s[i]!=s[i+j])&&(s[i]!=s[i-j])&&(s[i+j]!=s[i-j])) ng_cnt++;
        }
    }
    cout<<big_sum-ng_cnt<<endl;
}

Measured memory_bytes: 3628