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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
using namespace std;

int main(){
	int cnt[100001];	memset( cnt, 0, sizeof(int) * 100001 );
	long long int sum = 0;
	int n;	cin >> n;
	int a[n];
	for( int i = 0; i < n; i++ ){
		cin >> a[i];
		cnt[ a[i] ]++;
		sum += a[i];
	}
	int q;	cin >> q;
	pair<int, int> bc[q];
	for( int i = 0; i < q; i++ ){
		cin >> bc[i].first >> bc[i].second;
	}

	for( int i = 0; i < q; i++ ){
		sum += (bc[i].second - bc[i].first) * cnt[ bc[i].first ];
		cnt[ bc[i].second ] += cnt[ bc[i].first ];
		cnt[ bc[i].first ] = 0;

		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n, m;
vector<int> color(MAX, NIL);
vector<vector<int>> M(MAX);

void dfs(int i, int id) {
  int size = M[i].size();
  color[i] = id;
  for (int j = 0; j < size; j++) {
    if (color[M[i][j]] == NIL) {
      color[M[i][j]] = id;
      dfs(M[i][j], id);
    }
  }
}

void assignColor() {
  int id = 1;
  for (int i = 0; i < n; i++) {
    if (color[i] == NIL) dfs(i, id++);
  }
}

int main() {
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int id, f;
    cin >> id >> f;
    M[id].push_back(f);
    M[f].push_back(id);
  }
  int qn;
  cin >> qn;
  vector<vector<int>> q(qn, vector<int>(2));
  for (int i = 0; i < qn; i++) {
    cin >> q[i][0] >> q[i][1];
  }

  assignColor();

  for (int i = 0; i < qn; i++) {
    if (color[q[i][0]] == color[q[i][1]]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}


Measured memory_bytes: 13904
import sys


def main() -> None:
    n = next_int()
    t = next_int()
    a = next_int()

    key = 0
    val = sys.maxsize

    for i in range(n):
        h = next_int()
        p = t - h * 0.006
        if val > abs(a - p):
            key = i + 1
            val = abs(a - p)

    print(key)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if(a < b && b < c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    } 
}


Measured memory_bytes: 26168
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

fn main() {
    input!{
        c_a: [[i64; 3]; 3],
    }

    // c_a の中から最も小さい値を探す
    let mut min_c_i = 0;
    let mut min_c_j = 0;
    let mut min_c = 100;
    for i in 0..3 {
        for j in 0..3 {
            if c_a[i][j] < min_c {
                min_c_i = i;
                min_c_j = j;
                min_c = c_a[i][j];
            }
        }
    }

    let mut a = [0; 3];

    // min_c から a[min_c_i] を決める
    'all: for a_min_c_i in 0..(min_c+1) {
        a[min_c_i] = a_min_c_i;
        let mut b = [0; 3];
        for j in 0..3 {
            // a[min_c_i] から各 b[j] を決める
            b[j] = c_a[min_c_i][j] - a[min_c_i];
        }

        // min_c_i 以外の行について、c[i][j] = a[i] + b[j] がなりたつ a[i] が存在するかを調べる
        for i in 0..3 {
            if i == min_c_i { continue; }
            a[i] = c_a[i][0] - b[0];
            for j in 1..3 {
                if a[i] != c_a[i][j] - b[j] {
                    // 成り立たない
                    continue 'all;
                }
            }
        }

        println!("Yes");
        return;
    }

    println!("No");
    return;
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
      if(n<=111) System.out.println(111);
      else if(n<=222) System.out.println(222);
      else if(n<=333) System.out.println(333);
      else if(n<=444) System.out.println(444);
      else if(n<=555) System.out.println(555);
      else if(n<=666) System.out.println(666);
      else if(n<=777) System.out.println(777);
      else if(n<=888) System.out.println(888);
      else System.out.println(999);
      
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>
using namespace std;

long int third_select(int i, int j, vector<int> c)
{
    int h = j - i;
    auto iter = lower_bound(c.begin(), c.end(), j);
    if (iter == c.end()) {
        return 0;
    }
    else {
        long int sum = 0;
        for ( ; iter < c.end(); iter++) {
            int l = *iter - j;
            if (l - h < 0) {
                sum++;
            }
            else if (0 < l - h) {
                sum += distance(iter, c.end());
                break;
            }
        }
        return sum;
    }
}

long int second_select(int i, vector<int> b, vector<int> c)
{
    long int sum = 0;
    auto iter = lower_bound(b.begin(), b.end(), i);
    for ( ;iter != b.end(); iter++) {
        sum += third_select(i, *iter, c);
    }
    return sum;
}

long int first_select(vector<int> a, vector<int> b, vector<int> c)
{
    long int sum = 0;
    for (int i : a) {
        sum += second_select(i, b, c);
        sum += second_select(i, c, b);
    }
    return sum;
}

void print_vec(vector<int> v)
{
    for (int x : v) {
        cout << x;
    }
    cout << endl;
}

int main (void)
{
    int n;
    cin >> n;
    vector<int> r, g, b;
    for (int i = 0; i < n; i++) {
        char x;
        cin >> x;
        if (x == 'R') {
            r.push_back(i);
        }
        else if (x == 'G') {
            g.push_back(i);
        }
        else {
            b.push_back(i);
        }
    }
    
    //print_vec(r);
    //print_vec(g);
    //print_vec(b);

    long int sum = 0;
    sum += first_select(r, g, b);
    //sum += first_select(r, b, g);
    sum += first_select(g, r, b);
    //sum += first_select(g, b, r);
    sum += first_select(b, r, g);
    //sum += first_select(b, g, r);

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3228
N, A, B = gets.strip.split.map(&:to_i)

a = Array.new(N){0}

res = 0
(1..N).each do |i|
  tmp = i.to_s.split('').map(&:to_i).inject(:+)
  res += i if (tmp >= A) && (tmp <= B)
end

puts res



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

int main(){
	list<int> a;
	list<int>::iterator it = a.end();
	int q, query, t, x;
	
	cin>>q;
	
	for(int i = 0; i < q; i++){
		cin>>query;
		if(query == 0){
			cin>>x;
			it = a.insert(it, x);
		} else if(query == 1){
			cin>>x;
			if(x>0) for(int i = 0; i < x; i++)it++;
			else    {
				x *= -1;
				for(int i = 0; i < x; i++)it--;
			}
		} else {
			it = a.erase(it);
		}//cout<<" "<<i<<endl;
	}
	
	for(it = a.begin(); it != a.end(); it++){
		cout<<*it<<endl;
	}
	
	return 0;
}



Measured memory_bytes: 18548
#include<iostream>
using namespace std;
int min(int a, int b, int c){
  if(a>=b){
		if(a<=c)
          	return a;
    	else if(b>=c)
          	return b;
   		else
          	return c;
  }
  else{
  	if(b<=c)
      	return b;
    else if(a>=c)
    	return a;
    else
      return c;
  }
}

int main(){
 int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
   int count =0;
   for(int i=1;i<n-1;i++){
   	if(arr[i] == min(arr[i], arr[i+1], arr[i-1]))
      count++;
   }
   cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
k,s=map(int,input().split())
ans=0
for i in range(k+1):
    tmp=s-i
    if tmp<0:
        continue
    if tmp<=k:
        ans+=tmp+1
    elif 2*k<tmp:
        pass
    else:
        tmp1=2*k-tmp
        ans+=tmp1+1
    # print(tmp)
print(ans)

Measured memory_bytes: 9052
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	string s;
	cin >> s;
	int start, end;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == 'A'){
			start = i;
			break;
		}
	}
	for(int i = s.length() - 1; i >= 0; i--){
		if(s[i] == 'Z'){
			end = i;
			break;
		}
	}
	cout << end - start + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <list>
#include <string>
using namespace std;
int main()
{
	ifstream fin("input.txt");
	long long A, B;
	cin >> A >> B;
	if (A == 1 && B != 1)
	{
		cout << "Alice" << endl;
		return 0;
	}
	if (A != 1 && B == 1)
	{
		cout << "Bob" << endl;
		return 0;
	}
	if (A > B)
	{
		cout << "Alice" << endl;
		return 0;
	}
		
	if (B > A)
	{
		cout << "Bob" << endl;
		return 0;
	}
		
	cout << "Draw" << endl;


}


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

#define int long long

using namespace std;

const int N = 2e5 + 123;
int n, k, ans, a[N];

main(){
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n - k; i++){
		ans += a[i];
	}
	cout << ans;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int H = sc.nextInt(), W = sc.nextInt(), D = sc.nextInt();
        int A[][] = new int[H * W + 1][2];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                int num = sc.nextInt();
                A[num][0] = i;
                A[num][1] = j;
            }
        }
        int Q = sc.nextInt();
        int[] L = new int[Q], R = new int[Q];
        for (int i = 0; i < Q; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        int[] costs = new int[H * W + 1];
        for (int i = H * W; i > 0; i--) {
            if (i + D > H * W) {
                costs[i] = 0;
            } else {
                costs[i] = costs[i + D] + Math.abs(A[i + D][0] - A[i][0]) + Math.abs(A[i + D][1] - A[i][1]);
            }
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(costs[L[i]] - costs[R[i]]);
        }
    }
}


Measured memory_bytes: 101028
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a + b >= c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, y;
    cin >> n >> y;
    
    for (int i = 0; i <=2000; i++){
        for (int j = 0; j <= 2000; j++){
            int k = n - i - j;
            if (k < 0 || 2000 < k) continue;
            if (10 * i + 5 * j + k == y / 1000){
                cout << i << " " << j << " " << k  << endl;
                return 0;
            }
        }
    }
    
    cout << -1 << " " << -1 << " " << -1 << endl;
}


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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

#define X real()
#define Y imag()

using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}


const double EPS = 1e-8;
const long long mod = 1e9+7;

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

const int N = 1e5 + 5;


int n ,arr[N],k;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
            cin>>arr[i];
    if(n == k){
        cout << 1<<'\n';
        return 0;
    }
    int idx;
    for(int i = 1; i <= n; ++i){
        if(arr[i] == 1){
                idx = i;
                break;
        }
    }
    int ans = 0;
    if(idx >= n/2){

        int i = idx;
        if(i < n){
            for(;;){
                ans++;
                
                i += (k - 1);
                if(i >= n)break;
            }
        }
        int x = 0;
        if(i>n){
            x = i - n;
        }
        
        idx -= x;
        i = idx;
        if(i > 1){
            for(;;){
                ans++;
                i-= (k-1);
                if(i<=1)break;
            }
        }


    }else{

            int i = idx;
        if(i > 1){
            for(;;){
                ans++;
                i-= (k-1);
                if(i<=1)break;
            }
        }
        int x = 0;
        if(i < 1){
            x = 1 - i;
        }
        idx += x;
        i = idx;
        if(i < n){
            for(;;){
                ans++;
                
                i += (k - 1);
                if(i >= n)break;
            }
        }
    }


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


Measured memory_bytes: 640
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 
#include <atcoder/all>

typedef long long ll;
typedef unsigned long long ull;
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;
using namespace atcoder;

char str[] = "ACL";
void solve()
{
    int K;
    scanf("%d", &K);
    int i;
    for (i = 0; i < K; i++) {
        printf("%s", str);
    }
    printf("\n");
    return;
}

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



Measured memory_bytes: 3720
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include<string>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);

int n;
vector<int> h;
vector<int> c;

int cost_i2j(int i, int j) {
	return abs(h[j] - h[i]);
}

int main(void) {
	cin >> n;
	h.resize(n + 1);
	c = vector<int>(n + 1, 0);
	for (int i = 1; i < n + 1; i++)
		cin >> h[i];
	c[2] = cost_i2j(1, 2);
	for (int i = 3; i < n + 1; i++) {
		c[i] = min(c[i - 1] + cost_i2j(i-1, i), c[i - 2] + cost_i2j(i - 2, i));
	}
	cout << c[n] << endl;
	return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;

	int count = 0;
	for(int i = 1; i <= N; i++){
		if(i < 10)
			count++;
		else if(100 <= i && i < 1000)
			count++;
		else if(10000 <= i && i < 100000)
			count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
diff = abs(abs(x)-abs(y))
 
if abs(x) < abs(y):
  if x < 0:
    diff += 1
  if y < 0:
    diff += 1
else:
  if x > 0:
    diff += 1
  if y > 0:
    diff += 1
print(diff)

Measured memory_bytes: 38256
#include<stdio.h>
int main(void){
  long long a,b,c,d;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  long long max=a*c;
  if(max<a*d)max=a*d;
  if(max<b*c)max=b*c;
  if(max<b*d)max=b*d;
  printf("%lld\n",max);
  return 0;
}

Measured memory_bytes: 1688
// https://atcoder.jp/contests/dp/tasks/dp_e
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
typedef vector<ll> vi;
typedef vector<vi> vii;
#define rep(i, k, n) for (ll i = k; i < (int)(n); i++)

int main()
{
    ll n, w;
    ll ans = 0;
    cin >> n >> w;
    vi ws(n + 1);
    vi vs(n + 1);
    ll totalVal = 0;
    rep(i, 1, n + 1)
    {
        cin >> ws[i] >> vs[i];
        totalVal += vs[i];
    }

    vii dp(n + 1, vi(totalVal + 1));
    // dp[i][j] denotes the least weight to get a value of  j from the first i objects
    dp[0][0] = 0;
    int INF = w + 1;
    rep(V, 1, totalVal + 1) dp[0][V] = INF; //arbitary large num thats impossible

    rep(N, 1, n + 1)
    {
        rep(V, 1, totalVal + 1)
        {
            dp[N][V] = (V < vs[N]) ? dp[N - 1][V] : min(dp[N - 1][V], dp[N - 1][V - vs[N]] + ws[N]);
            if (dp[N][V] <= w)
            {
                ans = max(ans, (ll)V);
            }
        }
    }

    cout << ans << endl;
}

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b) { cout << 0 << endl; return 0;}
    if(n==1 && a!=b) { cout << 0 << endl; return 0;}
    ll mx = b*(n-1) + a;
    ll mn = a*(n-1) + b;
    ll ans = mx-mn + 1;
    cout << ans << endl;
    return 0;
}

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

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o 

int main(){
 ll n,k;
 cin>>n>>k;
 ll a[n];
 for(int i=0;i<n;i++){
  cin>>a[i];
 }
 ll r=*max_element(a,a+n);
 ll l=1;
 while(l<r){
  ll mid=l+(r-l)/2;
  ll cuts=0;
  for(int i=0;i<n;i++){
   if(a[i]%mid)
    cuts+=(a[i]/mid);
   else
    cuts+=((a[i]-1)/mid);
  }
  if(cuts>k)
   l=mid+1;
  else{
   r=mid;
  }
  // cout<<l<<" "<<r<<"\n";
 }
 cout<<r<<"\n";
 return 0;
}


Measured memory_bytes: 5008
import java.util.Scanner;

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

        // 2人の間に存在するマス数
        int count = (b - a) - 1;

        if (count % 2 == 0) {
            System.out.println("Borys");
        } else {
            System.out.println("Alice");
        }
    }
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		int[] arr = new int[]{0, 3, 5, 7};
		HashSet<Long> set = new HashSet<>();
		for (int i = 1; ; i++) {
		    int x = i;
		    long base = 0;
		    while (x > 0) {
		        base *= 10;
		        base += arr[x % 4];
		        x /= 4;
		    }
		    if (base > n * 10) {
		        break;
		    }
		    if (base <= n && is753(base)) {
		        set.add(base);
		    }
		}
		System.out.println(set.size());
   }
   
   static boolean is753(long x) {
       int[] counts = new int[10];
       while (x > 0) {
           counts[(int)(x % 10)]++;
           x /= 10;
       }
       return (counts[0] == 0 && counts[3] != 0 && counts[5] != 0 && counts[7] != 0);
   }
}


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

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	ll max_f = 0;
	ll max_s = 0;
	ll max_f_index;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		if (max_f <= a[i]) {
			max_s = max_f;
			max_f = a[i];
			max_f_index = i;			
		}
		else if (max_s <= a[i]) {
			max_s = a[i];
		}
	}
	for (ll i = 0; i < n; i++) {
		if (i == max_f_index) {
			cout << max_s << endl;
		}
		else {
			cout << max_f << endl;
		}
	}
	return 0;
}

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

int main() {
int N;
cin >> N;
int a = 0;
  for ( int i = 0; i < N; i++ ) {
	string C;
    cin >> C;
    if (C == "Y") {
      a++;
    }
  }
  if ( a > 0 ) {
    cout << "Four" << endl;
  }  else cout << "Three" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    double t, x;
    cin >> t >> x;
    printf("%.10f\n", t / x);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
//#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

string s;

int main(){
	cin>>s;
	int f=0,l=0;
	bool ff=0,ll=0;
	f+=(s[0]-'0')*10;
	f+=(s[1]-'0');
	l+=(s[2]-'0')*10;
	l+=(s[3]-'0');
	if(1<=f&&f<=12)
		ff=1;
	if(1<=l&&l<=12)
		ll=1;
	
	if(ff&&ll)
		cout<<"AMBIGUOUS"<<endl;
	else if(ff)
		cout<<"MMYY"<<endl;
	else if(ll)
		cout<<"YYMM"<<endl;
	else
		cout<<"NA"<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class AtCoder {
  public static void Main() {
    var str = Console.ReadLine().Trim().Split().Select(x => long.Parse(x)).ToList();
    var N = str[0];
    var A = str[1];
    var B = str[2];
    
    var X = A + B;
    long ans = 0;
    ans = (N / X) * A;
    ans += Math.Min(N % X, A);
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13268
/**
 * Created by hiramekun at 18:47 on 2020-04-04.
 */

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll k, n;
    cin >> k >> n;
    vl a;
    rep(i, n) {
        ll tmp;
        cin >> tmp;
        a.eb(tmp);
    }
    ll ans = 0;
    ll minus = -ll_inf;
    for (ll i = 0; i < n - 1; ++i) {
        ans += a[i + 1] - a[i];
        minus = max(minus, a[i + 1] - a[i]);
    }
    ans += k - a.back() + a[0];
    minus = max(minus, k - a.back() + a[0]);
    cout << ans - minus << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 2420
N = int(input())
xa= 0
bx= 0
ba = 0
ans = 0
for i in range(N):
    s = input()
    ans += s.count("AB") # くっつけなくても見つかるABのカウント
    if s[-1] == "A" and s[0] == "B":
        ba += 1
    elif s[-1] == "A":
        xa+= 1
    elif s[0] == "B":
        bx+= 1

hoge  = "X"
PHASEA = 0
PHASEB = 1
phase  = 0
while ba != 0 or xa != 0 or bx != 0:
    if hoge[-1] == "X":
        if xa > 0:
            xa  -= 1
            hoge += "XA"
        elif ba > 0 :
            ba -= 1
            hoge += "BA"
        else:
            bx -= 1
            hoge += "BX"
    elif hoge[-1] == "A":
        if ba > 0 :
            ba -= 1
            hoge += "BA"
        elif bx > 0:
            bx  -= 1
            hoge += "BX"
        elif xa > 0:
            xa  -= 1
            hoge += "XA"

print(hoge.count("AB") + ans)




Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  vector<int> t(5);
  rep(i, 5) cin >> t[i];

  int mn = 10;
  rep(i, 5)
  {
    if (t[i] % 10 < mn && t[i] % 10 != 0)
      mn = t[i] % 10;
  }

  int sum = 0;
  rep(i, 5)
  {
    sum += (t[i] + 9) / 10;
  }
  sum *= 10;

  sum -= 10;
  sum += mn;

  cout << sum << endl;

  return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;

    a *= 10, b *= 10;
    int c = (a+b)/2;
    int d = 0;
    if (c%10 != 0) {
        d = 1;
    }

    cout << (c/10) + d << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string v;
void concatenar(string s,string d){
	for(int i=0;i<d.length();i++){
		v.push_back(d[i]);
		}
	for(int i=0;i<s.length();i++){
		v.push_back(s[i]);
		}
	}
int main(){
	string s,d;cin>>s>>d;
	int x=d.length()+s.length();
	concatenar(s,d);
	for(int i=0;i<x;i++)cout<<v[i];
	cout<<'\n';
	
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val % MOD : val % MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}

void solve() {
    string L;
    cin >> L;
    each(a, L)a -= '0';
    reverse(all(L));
    const int N = sz(L);

    vector<array<array<mint, 2>, 2>> dp(N + 1);
    dp[0][0][0] = 1;
    rep(i, N)rep(j, 2)rep(k, 2) {
        rep(a, 2)rep(b, 2) {
            int x = (a + b + j) % 2;
            int y = a ^ b;
            if (x == y) {
                int jj = (a + b + j) / 2;
                int kk = (k && L[i] == x) || x > L[i];
                dp[i + 1][jj][kk] += dp[i][j][k];
            }
        }
    }
    cout << dp[N][0][0] << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 2000
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int step=0;
	
	for(int i=1;i<s.length();i++)
	{
		if(s[i]==s[i-1])
		{
			if(s[i]=='1'){s[i]='0';}
			else{s[i]='1';}
			step++;
		}
	}
	cout<<step;
}
	

Measured memory_bytes: 512
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int[] V = new int[N];
		int[] C = new int[N];
		int ans = 0;
		for (int i = 0; i < N; i++) {
			V[i] = input.nextInt();
		}
		for (int i = 0; i < N; i++) {
			C[i] = input.nextInt();
		}
		for (int i = 0; i < N; i++) {
			if (V[i]-C[i]>0) ans+=V[i]-C[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;


int main(){
    ll N, P;
    ll res = 1;
    map<ll, ll> list;
    cin >> N >> P;
    for(ll i=2; i*i<=P; i++){
        while(P % i == 0){
            list[i]++;
            P/=i;
        }
    }
    if(P != 1) list[P]++;
    for(auto i : list){
        ll common = i.second / N;
        res *= pow(i.first, common); 
    }
    COUT(res);
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

int freq[64];
unsigned long long arr[100005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    unsigned long long k, a; cin >> n >> k;

    for(int i = 0; i < n; ++i){
        cin >> a;
        arr[i] = a;
        for(int p = 0; p < 63; ++p)
            if((a >> p) & 1)
                ++freq[p];
    }

    unsigned long long x = 0;

    for(int pos = 63; pos >= 0; --pos){
        //cout << pos << " " << freq[pos] * 2 << " " << n << endl;
        if(freq[pos] * 2 < n && (x | (1ULL << pos)) <= k){
            //cout << "SET BIT " << pos << endl;
            x |= 1ULL << pos;
        }

    }

    unsigned long long tot = 0;
    for(int i = 0; i < n; ++i)
        tot += x ^ arr[i];

    cout << tot << "\n";

    return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;

    if (13 <= A) {
        cout << B << endl;
    } else if (6 <= A && A <= 12) {
        cout << B / 2 << endl;
    } else if (A <= 5) {
        cout << 0 << endl;
    }
}


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

int main(void)
{
    int N;
    cin >> N;

    int count = 0;
    int i = 1;
    while(1)
    {
	i++;
	N--;
	if(i > N) break;

	count++;
    }
    

    cout << count << endl;

    return 0;
}


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

using namespace std;

using ll = long long;

const long long MOD = 1e9+7;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

class Mll
{
    public:
    ll x;

    Mll() : x(0){}
    Mll(ll x=0) : x((x%MOD+MOD)%MOD){}

    Mll operator-() const
    {
        return Mll(-x);
    }

    Mll& operator+=(const Mll& A)
    {
        if((x += A.x) >= MOD) x -= MOD;
        return *this;
    }
    Mll& operator-=(const Mll& A)
    {
        if((x += MOD - A.x) >= MOD) x -= MOD;
        return *this;
    }
    Mll& operator*=(const Mll& A)
    {
        (x *= A.x) %= MOD;
        return *this;
    }
    
    Mll operator+(const Mll& A)
    {
        Mll res(*this);
        return res+=A;
    }
    Mll operator-(const Mll& A)
    {
        Mll res(*this);
        return res-=A;
    }
    Mll operator*(const Mll& A)
    {
        Mll res(*this);
        return res*=A;
    }
    
    Mll pow(ll t) const // t乗
    {
        if(t==0) return 1;
        Mll A = pow(t>>1);
        A *= A;
        if(t&1) A *= *this;
        return A;
    }

    // for prime mod
    Mll inv() const
    {
        return pow(MOD-2);
    }
    Mll& operator/=(const Mll& A)
    {
        return (*this) *= A.inv();
    }
    Mll operator/(const Mll& A) const
    {
        Mll res(*this);
        return res/=A;
    }

    friend ostream& operator<<(ostream& os, const Mll& M)
    {
        os << M.x;
        return os;
    }
};

vector<Mll> ALLIN_MLL(ll N)
{
    vector<ll> numbers_ll(N);
    ALLIN1_NUMBER(numbers_ll);

    vector<Mll> numbers_Mll;
    for(ll i=0;i<N;i++)
    {
        Mll add(numbers_ll[i]);
        numbers_Mll.push_back(add);
    }

    return numbers_Mll;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

int main()
{
    ll K;
    cin >> K;

    ll number = 7;
    if(K==1 || K==7)
    {
        cout << '1' << endl;
        return 0;
    }
    bool TF = false;
    for(ll i=2;i<1e7;i++)
    {
        number = ((number%K)*10+7)%K;
        if(number==0)
        {
            cout << i << endl;
            TF = true;
            break;
        }
    }
    if(!TF)
    cout << "-1" << endl;

    return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

int main() {
  long long n, m;


  std::cin >> n >> m;
  vector<long long> l(m);
  vector<long long> r(m);
  for (int i = 0; i < m; i++) {
    std::cin >> l[i] >> r[i];
  }
  long long llim, rlim;
  llim = 1;
  rlim = n;

  for (int i = 0; i < m; i++) {
    if (llim < l[i]) {
      llim = l[i];
    }
    if (rlim > r[i]) {
      rlim = r[i];
    }
  }
  std::cout << max(0LL, rlim-llim+1) << std::endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int, int> ip;

char s[100002];
int n;

int main() {
	scanf("%s", &s[1]);
	n = strlen(&s[1]);
	if (s[1] != '1' || s[n - 1] != '1' || s[n] != '0') {
		puts("-1");
		return 0;
	}
	for (int i = 1; i <= n - 1; i++) {
		if (s[i] != s[n - i]) {
			puts("-1");
			return 0;
		}
	}
	vector<ip> res;
	int root = 1, cur = 2;
	//res.push_back(ip(root, cur++));
	for (int i = 1; i <= n - 1; i++) {
		res.push_back(ip(root, cur++));
		if (s[i] == '1') root = cur - 1;
	}
	for (int i = 0; i < res.size(); i++)
		printf("%d %d\n", res[i].first, res[i].second);
	return 0;
}

Measured memory_bytes: 2420
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class UnionFind(object):
    def __init__(self,n):
        self.__par=list(range(n))
        self.__rank=[0]*n
        self.__size=[1]*n

    def root(self,k):
        if(self.__par[k]==k): return k
        self.__par[k]=self.root(self.__par[k])
        return self.__par[k]

    def unite(self,i,j):
        i=self.root(i); j=self.root(j)
        par=self.__par; rank=self.__rank; size=self.__size
        if(i==j): return False
        if(rank[i]>rank[j]):
            par[j]=i
            size[i]+=size[j]
        else:
            par[i]=j
            size[j]+=size[i]
            if(rank[i]==rank[j]): rank[j]+=1
        return True

    def size(self,k):
        return self.__size[self.root(k)]

class RollingHash(object):
    __base1=1007; __mod1=10**9+9
    __base2=1009; __mod2=10**9+7

    def __init__(self,s):
        n=len(s)
        self.__s=s
        self.__n=n
        b1=self.__base1; m1=self.__mod1
        b2=self.__base2; m2=self.__mod2
        H1,H2=[0]*(n+1),[0]*(n+1)
        P1,P2=[1]*(n+1),[1]*(n+1)
        for i in range(n):
            H1[i+1]=(H1[i]*b1+ord(s[i]))%m1
            H2[i+1]=(H2[i]*b2+ord(s[i]))%m2
            P1[i+1]=P1[i]*b1%m1
            P2[i+1]=P2[i]*b2%m2
        self.__H1=H1; self.__H2=H2
        self.__P1=P1; self.__P2=P2

    def hash(self,l,r):
        m1=self.__mod1; m2=self.__mod2
        assert 0<=l<=r<=self.__n
        return ((self.__H1[r]-self.__P1[r-l]*self.__H1[l]%m1)%m1,
                (self.__H2[r]-self.__P2[r-l]*self.__H2[l]%m2)%m2)

def resolve():
    from math import ceil
    s=input()
    t=input()
    n=len(s)
    m=len(t)
    s=s*ceil(m/n)
    s=s*2

    ok=[0]*n
    uf=UnionFind(n)
    rhs=RollingHash(s)
    rht=RollingHash(t)
    t=rht.hash(0,m)
    for i in range(n):
        if(rhs.hash(i,i+m)==t):
            ok[i]=1
    for i in range(n):
        if(ok[i] and ok[(i+m)%n]):
            if(not uf.unite(i,(i+m)%n)):
                print(-1)
                return
    ans=0
    for i in range(n):
        if(ok[i]): ans=max(ans,uf.size(i))
    print(ans)
resolve()

Measured memory_bytes: 140560
#include<stdio.h>


int main(){
	int K,C,count;
	int i;
	K=1;
	C=0;
	count=0;
	scanf("%d",&K);
	while(K!=0){
		C=0;
		count=0;
		for(i=0;i<K*(K-1)/2;i++){
			scanf("%d",&C);
			count=count+C;
		}
		count=count/(K-1);
		printf("%d\n",count);
		scanf("%d",&K);
	}
	return 0;
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> b(n);
    for (int i = 1; i < n; i++) {
        cin >> b[i];
    }
    int sum = b[1] + b[n-1];
    for (int i = 1; i < n-1; i++) {
        sum += min(b[i], b[i+1]);
    }
    cout << sum;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

vector<pair<int, int>> v;
ll f[N], dp[N], c[N];
int h, w, n;

ll binpow (ll a, ll n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return (binpow (a, n - 1) * a) % mod;
	else {
		ll b = binpow (a, n / 2);
		return (b * b) % mod;
	}
}

ll path (int x, int y, int x1, int y1) {
	return f[x1 + y1 - x - y] * c[x1 - x] % mod * c[y1 - y] % mod;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		v.pb({x, y});
	}

	f[0] = 1;
	for (int i = 1; i < N; i++) {
		f[i] = (f[i - 1] * i) % mod;
	}

	for (int i = 0; i < N; i++) {
		c[i] = binpow (f[i], mod - 2);
	}

	ll sum = path (1, 1, h, w);

	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	for (int i = 0; i < n; i++) {
		int x = v[i].f, y = v[i].s;
		dp[i] = path (x, y, h, w);

		for (int j = 0; j < i; j++) {
			if (x <= v[j].f && y <= v[j].s)
				dp[i] = (dp[i] - dp[j] * path (x, y, v[j].f, v[j].s) % mod + mod) % mod;
		}
	}

	for (int i = 0; i < n; i++) {
		sum = (sum - dp[i] * path (1, 1, v[i].f, v[i].s) % mod + mod) % mod;
	}

	cout << sum;
}


Measured memory_bytes: 4608
# D - We Love ABC
import sys
readline = sys.stdin.readline

S = list(str(readline().rstrip()))
MOD = 10**9 + 7
a = 0
ab = 0
abc = 0
pat = 1
for s in S:
    if s == 'A':
        a = (a + pat) % MOD
    elif s == 'B':
        ab = (ab + a) % MOD
    elif s == 'C':
        abc = (abc + ab) % MOD
    else: # s == '?'
        tmpa = a
        tmpab = ab
        a = (3*a + pat) % MOD
        ab = (3*ab + tmpa) % MOD
        abc = (3*abc + tmpab) % MOD
        pat = (pat*3) % MOD

print(abc)

Measured memory_bytes: 77464
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, m;
	long long k;
	cin >> n >> m >> k;

	vector<long long> a(n+1, 0), b(m+1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	long long suma = 0, sumb = 0;
	for (int i = 1; i <= m; i++) {
		cin >> b[i];
		sumb += b[i];
	}

	int ans = 0;
	int ib = m;
	for (int ia = 0; ia <= n; ia++) {
		suma += a[ia];
		if (suma > k) {
			break;
		}
		while (ib > 0 && suma + sumb > k) {
			sumb -= b[ib];
			ib--;
		}

		ans = max(ans, ia + ib);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6028
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        scan.close();

        List<String> list = func(n);

        for (String s : list) {
            System.out.println(s);
        }

    }

    private static List<String> func(int n) {
        List<String> list = new ArrayList<String>();
        if (n == 1) {
            list.add("a");
        } else {
            List<String> prevList = func(n - 1);
            for (String s : prevList) {
                // 含まれている最大の文字を探索
                char max = 'a';
                for (int i = 0; i < s.length(); i++) {
                    if (max < s.charAt(i)) {
                        max = s.charAt(i);
                    }
                }

                for (char c = 'a'; c <= max + 1; c++) {
                    String newString = s + c;
                    list.add(newString);
                }
            }
        }
        return list;
    }
}


Measured memory_bytes: 53788
#include <bits/stdc++.h>
using namespace std;
int main() {
	int d;
	while(cin>>d){
		int ans;
		int temp=d;
		for(ans=0;d<600;d=d+temp){
			ans+=temp*pow(d,2);
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
}

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

long long DP[110][100010];
long long w[110];
long long v[110];
long long n,W;

long long rec(long long index,long long sisa)
{
	if (index > n) return 0;
	if (DP[index][sisa] != -1) return DP[index][sisa];
	long long ret = rec(index + 1,sisa);
	if (w[index] <= sisa)
	{
		// cout << index << " " << sisa << endl;
		ret = max(ret,v[index] + rec(index + 1,sisa - w[index]));
	}
	return DP[index][sisa] = ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(DP,-1,sizeof(DP));
	cin >> n >> W;
	for (long long i = 1 ; i <= n ; i++)
	{
		cin >> w[i] >> v[i];
	}
	long long ans = rec(1,W);
	cout << ans << endl;
}

Measured memory_bytes: 86400
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;
constexpr int BASE = 80 * 160 + 10;
constexpr int SIZE = BASE * 2 + 1;
using bitflg = bitset<SIZE>;

int main() {
	int h, w;
    cin >> h >> w;
    vector<vector<int>> d(h+1, vector<int>(w+1));
    for(int y=1; y<=h; y++) {
        for(int x=1; x<=w; x++) {
            cin >> d[y][x];
        }
    }
    for(int y=1; y<=h; y++) {
        for(int x=1; x<=w; x++) {
            int b;
            cin >> b;
            d[y][x] = abs(d[y][x] - b);
        }
    }
    vector<vector<bitflg>> b(h+1, vector<bitflg>(w+1));
    b[1][0].set(BASE);
    for(int y=1; y<=h; y++) {
        for(int x=1; x<=w; x++) {
            auto&& prev = b[y-1][x] | b[y][x-1];
            b[y][x] |= (prev << d[y][x]) | (prev >> d[y][x]);
        }
    }
    const auto& bt = b[h][w];
    int ans;
    for(int i=0; i<=BASE; i++) {
        if(bt[BASE+i] || bt[BASE-i]) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 21248
#include<bits/stdc++.h>
#define N 100005
#define LL long long
using namespace std;
int n,q;
LL sta[N];int top;
LL ti[N],ans[N];
map<LL,int,greater<LL>> mp;
map<LL,int,greater<LL>>::iterator itr; 
int main(){
	scanf("%d%d",&n,&q);
	sta[++top]=n;
	for(int i=1;i<=q;i++){
		LL t;
		scanf("%lld",&t);
		while(top>0&&sta[top]>=t) top--;
		sta[++top]=t;
	}
	for(int i=1;i<=top;i++)
		mp[sta[i]]=i;
	ti[top]=1;
	for(int i=top;i>=2;i--){
		LL k=sta[i]%sta[i-1],v;int id;ti[i-1]+=ti[i]*(sta[i]/sta[i-1]);
		while((itr=mp.lower_bound(k))!=mp.end()){
			v=(*itr).first;id=(*itr).second;
			ti[id]+=ti[i]*(k/v);k%=v;
		}
		ans[k]+=ti[i];
	}
	ans[sta[1]]+=ti[1];
	for(int i=n-1;i>=1;i--) ans[i]+=ans[i+1];
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define ll long long
#define str string
#define optimizator ios_base::sync_with_stdio(0);
using namespace std;
int main(){
	optimizator;
	int n,m;
	cin>>n>>m;
	int a[m];
	ll cnt=0;
	for(int i=0; i<m; i++){
		cin>>a[i];
		cnt+=a[i];
	}
	if(cnt>=n){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

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

using namespace std;
typedef long long ll;

const int N = int(1e5) + 7;

void init(){

}

void solve(){
    int x, k;
    scanf("%d%d", &k, &x);
    for(int i = x-k+1; i <= x+k-1; i++)
        printf("%d ", i);
}

int main(){
    int test_cases_number = 1;
//    scanf("%d", &test_cases_number);
    for(int i = 0; i < test_cases_number; i++)
        solve();
}


Measured memory_bytes: 256