akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,d[100000],a[100000];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>d[i];
		a[d[i]-1]++;
	}
	for(int i=1;i<100000;i++)
	a[i]=a[i]+a[i-1];
	int l=-1,r=-1;
	for(int i=0;i<100000;i++)
	{
		if(a[i]==n/2&&l==-1)
		{
			l=i;
		}
		if(a[i]>n/2&&l==-1)
		{
			cout<<0;
			return 0;
		}
		if(a[i]>n/2&&r==-1)
		{
			r=i;
		}
	}
	cout<<r-l;
	return 0;
}

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

using namespace std;


int main()
{
    int n;
    cin>>n;
    vector<long long>v(n),nms(100005);
    long long ttl=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        nms[v[i]]++;
        ttl+=v[i];
    }
    int q;
    cin>>q;
    while(q--){
        long long b,c;
        cin>>b>>c;
        ttl-=nms[b]*b;
        ttl+=nms[b]*c;
        nms[c]+=nms[b];
        nms[b]=0;
        cout<<ttl<<'\n';
    }
    return 0;

}
/***
5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
3 4 730
60 90 120
80 150 80 150
*/


Measured memory_bytes: 4828
struct SegmentTreePURQ<T, F> {
    n: usize,
    a: Vec<T>,
    id: T,
    op: F,
}

impl <T: Copy, F: Fn (T, T) -> T> SegmentTreePURQ<T, F> {
    pub fn new (n: usize, id: T, op: F) -> SegmentTreePURQ<T, F> {
        let mut k = 1;
        while k < n {
            k *= 2;
        }
        SegmentTreePURQ {
            n: k,
            a: vec![id; 2 * k],
            id: id,
            op: op,
        }
    }
    pub fn update (&mut self, x: usize, v: T) {
        let mut k = self.n + x;
        let a = &mut self.a;
        a[k] = v;
        k >>= 1;
        while k > 0 {
            a[k] = (self.op) (a[2 * k], a[2 * k + 1]);
            k >>= 1;
        }
    }
    pub fn find (&self, mut l: usize, mut r: usize) -> T {
        let mut p = self.id;
        let mut q = self.id;
        l += self.n;
        r += self.n;
        while l < r {
            if (l & 1) == 1 {
                p = (self.op) (p, self.a[l]);
                l += 1;
            }
            if (r & 1) == 1 {
                r -= 1;
                q = (self.op) (self.a[r], q);
            }
            l >>= 1;
            r >>= 1;
        }
        (self.op) (p, q)
    }
}

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn gcd (mut a: u32, mut b: u32) -> u32 {
    if a == 0 || b == 0 {
        return a + b;
    }
    let mut r = a % b;
    while r > 0 {
        a = b;
        b = r;
        r = a % b;
    }
    b
}

fn run() {
    input! {
        n: usize,
        a: [u32; n],
    }
    let mut s = SegmentTreePURQ::new (n, 0, gcd);
    for i in 0..n {
        s.update (i, a[i]);
    }
    let mut ans = 0;
    for i in 0..n {
        s.update (i, 0);
        let v = s.find (0, n);
        ans = std::cmp::max (ans, v);
        s.update (i, a[i]);
    }
    println! ("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>

#include <stdio.h>

using namespace std;

int main(){

   int a, b;
   char op;

   vector<int> ans;

   cin >> a >> op >> b;

   while(op != '?'){
      if(op == '+'){
         ans.push_back(a+b);
      }
      else if(op == '-'){
         ans.push_back(a-b);
      }
      else if(op == '*'){
         ans.push_back(a*b);
      }
      else{
         ans.push_back(a/b);
      }
      cin >> a >> op >> b;
   }

   for(int i = 0; i < ans.size(); i++){
      cout << ans[i] << endl;
   }

   return 0;

}


Measured memory_bytes: 3132
N, K = map(int, input().split())
ans = 0

if K == 0:
    print(N ** 2)
else:
    # b を固定？
    for b in range(1, N + 1):
        if b - 1 < K: continue
        ans += (b - K) * (N // b)
        ans += max(N % b - K + 1, 0)
        # print(b, ans)

    print(ans)

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int A, B; cin >> A >> B;
	cout << max(2 * max(A, B) - 1, A + B) << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int x,y;
	y = 1;
	cin >> x; 
	for ( ; y<=x; y=y+1) {
		if (y % 3 == 0) {
			cout << " " << y ;
		}
		else if (y % 10 == 3) {
			cout << " " << y ;
		}
		else if (y%100/10 == 3 || y%1000/100 == 3 || y%10000/1000 == 3) {
			cout << " " << y;
		}
	}
	cout << endl;
}


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

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

    if (s>w) {
        cout << "safe" << endl;
    } else {
        cout << "unsafe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
a, b, n= gets.chomp.split.map(&:to_i)

# 1.upto(n) do |x|
#   f = (a*x/b).floor - a*(x/b).floor
#   p "xが#{x}のとき"
#   p f
# end

if b == 1
  puts 0
  exit
end

if a % b == 0
  c = a / b

  puts c * (b-1)

  # puts n * (a/b)
  exit
end

if n > b
  # if a % b ==0
    # puts a - 2
  # else
    puts a - 1
  # end
else
  f = ((a*n)/b).floor - a * (n/b).floor

  f = ((a*(n-1))/b).floor - a * ((n-1)/b).floor if f == 0
  puts f
end



Measured memory_bytes: 14300
#include <iostream>
using namespace std;
int main()
{
	int N;
	scanf("%d", &N);
	if (N < 3)
	{
		cout << 1 << endl;
		return 0;
	}
	int pre,curr,num=1; 
	int flag=0;//0:init 1:asc -1：des
	scanf("%d", &curr); N--;
	pre = curr;
	while (N>0)
	{
		scanf("%d", &curr);
		
		if (curr > pre)
		{
			if (flag == 0)
				flag=1;
			else if(flag==-1)
			{
				flag =0;
				num++;
			}
		}
		else if(curr<pre)
		{
			if (flag==0)
				flag=-1;
			else if(flag==1)
			{
				flag = 0;
				num++;
			}
		}
		pre = curr;
		N--;
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,m,H,M;
  cin>>h>>m>>H>>M;
  int k;
  cin>>k;
  int t=0;
  if(m<=M){
    t+=M-m;
    t+=60*(H-h);
  }else{
    t+=60+M-m;
    t+=60*(H-h-1);
  }
  cout<<t-k<<endl;
}

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


int main()
{
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	rep(i,tx-sx) cout<<"R";
	rep(i,ty-sy) cout<<"U";
	rep(i,tx-sx) cout<<"L";
	rep(i,ty-sy) cout<<"D";
	cout<<"D";
	rep(i,tx-sx+1) cout<<"R";
	rep(i,ty-sy+1) cout<<"U";
	cout<<"L"<<"U";
	rep(i,tx-sx+1) cout<<"L";
	rep(i,ty-sy+1) cout<<"D";
	cout<<"R"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int H, W, M; cin >> H >> W >> M;
    vector<int> X(W), Y(H);
    map<pair<int,int>, int> G;
    int mx = 0, my = 0;
    int xx, yy;
    vector<int> maxX, maxY;
    rep(i, M) {
        int h, w; cin >> h >> w;
        h--, w--;
        G[make_pair(h,w)]++;
        X[w]++;
        if (mx < X[w]) {
            mx = X[w], xx = w;
            maxX.clear();
            maxX.push_back(xx);
        } else if (mx == X[w]) maxX.push_back(w);
        Y[h]++;
        if (my < Y[h]) {
            my = Y[h], yy = h;
            maxY.clear();
            maxY.push_back(yy);
        } else if (my == Y[h]) maxY.push_back(h);
    }
    ll res = mx + my;
    bool found = false;
    for (auto x : maxX) {
        for (auto y : maxY) {
            if (G[{y,x}] > 0) continue; 
            found = true; break;
        }
        if (found) break;
    }
    if (!found) res--; 
    cout << res << endl;
}


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

int mp[2][100], N;
vector<int> ans(100);

int sum(int updown, int spos, int gpos) {
    int cnt = 0;
    for (int i = spos; i <= gpos; i++) {
        cnt += mp[updown][i];
    }
    return cnt;
}

int main(void) {
    cin >> N;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> mp[i][j];
        }
    }
    for (int pos = 0; pos <= N; pos++) {
        ans[pos] = sum(0, 0, pos) + sum(1, pos, N);
    }
    cout << *max_element(ans.begin(), ans.end()) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
			Scanner sc=new Scanner(System.in);
			int n=sc.nextInt();
			String s=sc.next();
			int max=0;
			int x=0;
			for (int i=0;i<n;i++){
				if(s.substring(i,i+1).equals("I")){
					x++;
					if(x>max){
						max=x;
					}
				}
				if(s.substring(i,i+1).equals("D")){
					x--;
				}
			}
			System.out.println(max);
	}

}


Measured memory_bytes: 9680
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll d[100000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin>>N>>M;
    ll X[M];
    priority_queue<ll> q;
    ll ans=0;
    rep(i,0,M){
        cin>>X[i];
    }
    sort(X,X+M);
    rep(i,0,M){
        if(i>0){
            d[i]=X[i]-X[i-1];
            ans+=d[i];
            q.push(d[i]);
        }
    }
    ll res=0;
    rep(i,0,N-1){
        if(!q.empty()){
            res+=q.top();
            q.pop();
        }
    }
    cout <<ans-res<<"\n";
}

Measured memory_bytes: 2680
a = [0]*3
for i in range(3):
  a[i] = list(map(int, input().split()))
n = int(input())
b = [0]*n
for i in range(n):
  b[i] = int(input())

  
  

  
  
for i in range(n):
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        a[j][k] = 0


for i in range(3):
  if sum(a[i]) == 0:
    print("Yes")
    exit()
    
for i in range(3):
  if a[0][i] + a[1][i] + a[2][i] == 0:
    print("Yes")
    exit()
if a[0][0] + a[1][1] + a[2][2] == 0:
  print("Yes")
  exit()
if a[0][2] + a[1][1] + a[2][0] == 0:
  print("Yes")
  exit()
print("No")

Measured memory_bytes: 62180
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m,x;
    cin>>n>>m>>x;
    
    vector<int> value(n);
    vector<vector<int>> book;
    for(int i=0;i<n;i++){
        int c;
        cin>>c;
        value[i]=c;
        vector<int> added;
        for(int j=0; j<m; j++){
            int e;
            cin>>e;
            added.push_back(e);
        }
        book.push_back(added);
    }
    
    int k = (int)pow(2, n);
    int ans = 2147483647;
    
    for(int i=1; i<k;i++){
        int index = n-1;
        vector<int> sum(m,0);
        int curr = 0;
        int f = i;
        while(f!=0){
            if(f%2){
                for(int j=0; j<m; j++){
                    sum[j]+=book[index][j];
                }
                curr+=value[index];
            }
            f/=2;
            index--;
        }
        bool valid = true;
        for(int j=0;j<m;j++){
            if(sum[j]<x){
                valid =false;
                break;
            }
        }
        if(valid){
            if(ans>curr)
                ans = curr;
               
        }
    }
    
    if(ans!=2147483647)
        cout<<ans<<endl;
    else
        cout<<-1<<endl;
    
    return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>
int main (void)
{
  long long int n,i,sum=0,buf;
  scanf("%lld",&n);
  //printf("%ld\n",n);


  for(i=1;i*(i+1)<n;i++){
    if(n%i==0) sum+=n/i-1;
      //printf("buf/i=%ld sum=%ld\n",buf/i,sum);
    }
    /*
    if(n-i == n%i) {
      sum+=i;
      printf("%ld ",i);
    }
    */


  printf("%lld\n",sum);



  return 0;
}

/*
       2499694746223
Answer=2499686339916

*/


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

using namespace std;


#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search  >
#define lower(arr,n,fixed) lower_bound(arr,arr+n,fixed)-arr  //Lower value search  >=
#define FOR(i,a,n) for(int i=a; i<(int)n; i++)
#define FORI(i,a,n) for(int i=a; i>=(int)n; i--)
#define pii pair<int,int>
#define vpii vector<pii>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(a) int((a).size())
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0)
#define endl "\n"
#define all(a) a.begin(), a.end()
#define MEMSET(p,i) memset(p,i,sizeof(p))

typedef long long LL;
typedef unsigned long long ULL;

ULL dp[410][410] = {0};
ULL v[410];


ULL sum(int x, int y)
{
	return x == 0 ? (v[y]) : (v[y] - v[x-1]);
}

int main(void)
{
	fastIO();
	
	int n;
	cin >> n;

	FOR(i,0,n)
		FOR(j,0,n)
			dp[i][j] = ULLONG_MAX;
	
	FOR(i,0,n){
		cin >> v[i];
		if(i != 0)
			v[i] += v[i-1];
		dp[i][i] = 0;
	}

	

	FOR(k,1,n){
		int a = 0;
		FOR(b,k,n){
			// intervalo [a,b]
			// cout << a+1 << " " << b+1 << endl;
			FOR(i,a,b){
				// cout << a+1 << " " << i+1 << " " << i+1+1 << " " << b+1 << endl;
				dp[a][b] = min(dp[a][b], sum(a,b) + dp[a][i] + dp[i+1][b]);
			}
			a++;
		}
	}

	/*FOR(i,0,n){
		FOR(j,0,n){
			if(dp[i][j] == ULLONG_MAX)
				cout << setw(5) << "-";
			else
				cout << setw(5) << dp[i][j];
		}
		cout << endl;
	}*/
	cout << dp[0][n-1] << endl;



	
}



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

int main(void)
{
    int K, X;
    cin >> K >> X;

    int i = max(-1000000, X - K + 1);
    while(i != min(1000001, X + K)){
        printf("%d ", i);
        i++;
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define repn(a,b,c) for(int a=b;a>=c;a--)
#define ll long long 
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))
#define ctz(x) __builtin_ctz(x)
#define clz(x) __builtin_clz(x)
#define popcount(x) __builtin_popcount(x)
#define parity(x) __builtin_parity(x)

int flag=0;


void solve(int x){
 


if(x==0){
	flag = 1;
}else if(x<0){
	//continue;
}else if(x>0){
  solve(x-7);
  solve(x-4);
}

}


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

   solve(x);

   if(flag){
   	cout<<"Yes"<<endl;
   }else{
   	cout<<"No"<<endl;
   }
   
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int a,b,c,d;
cin>>a>>b>>c>>d;
long long int ll=max(max(a*c,a*d),max(b*c,b*d));
cout<<ll;
//coutmax(a*c,max(a*d,max(b*c,b*d))));
return 0;
}

Measured memory_bytes: 3612
// Winding

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef pair<int, int> pii;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

namespace fastIO
{
	const UI BUFFER_SIZE = (UI) 1 << 15;
	char buffer[BUFFER_SIZE], *cur, *ed;

	inline char getc() { return *(cur == ed ? ed = buffer + fread(buffer, 1, BUFFER_SIZE, stdin), cur = buffer : cur)++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

template<typename T> inline T sqr(const T &val) { return val * val; }
template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }

// END tpl.

const int MAXN = 500;

int n;

int A[MAXN + 5][MAXN + 5], B[MAXN + 5][MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
		{
			if(i < j) A[i][j] = read<int>();
			if(i > j) B[j][i] = read<int>();
		}
}

inline void solve()
{
	static LL S0[MAXN + 5][MAXN + 5], pre[MAXN + 5][MAXN + 5], S[MAXN + 5][MAXN + 5][MAXN + 5];

	for(int len = 1; len <= n; ++len)
		for(int i = 1; i + len <= n; ++i)
		{
			int j = i + len;
			S0[i][j] = S0[i + 1][j] + S0[i][j - 1] - S0[i + 1][j - 1] + B[i][j];
		}

	for(int i = 1; i <= n; ++i)
	{
		pre[i][0] = 0;
		for(int j = 1; j <= n; ++j) pre[i][j] = pre[i][j - 1] + B[i][j];
	}

	for(int j = 1; j <= n; ++j) for(int k = j + 1; k <= n; ++k)
		for(int i = j; i >= 0; --i) S[i][j][k] = S[i + 1][j][k] + pre[i][k] - pre[i][j];

	static LL suf[MAXN + 5][MAXN + 5], S1[MAXN + 5][MAXN + 5];

	for(int i = 1; i <= n; ++i)
	{
		suf[0][i] = 0;
		for(int j = 1; j <= i; ++j) suf[j][i] = suf[j - 1][i] + A[j][i];
	}

	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			S1[i][j] = S1[i][j - 1] + suf[i][j];

	static LL f[MAXN + 5][MAXN + 5];

	for(int i = 1; i <= n; ++i) f[0][i] = S0[1][i];
	for(int k = 1; k <= n; ++k) for(int j = 1; j < k; ++j)
	{
		LL res = S0[j + 1][k] + S1[j][k];
		for(int i = 0; i < j; ++i)
			chkmax(f[j][k], res + f[i][j] + S[i + 1][j][k]);
	}

	LL sum = 0;
	for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j)
		sum += A[i][j] + B[i][j];

	LL ans = 0;
	for(int i = 0; i < n; ++i) chkmax(ans, f[i][n]);
	printf("%lld\n", sum - ans);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}




Measured memory_bytes: 977920
# -*- coding: utf-8 -*-


def main():
    n, a, b = map(int, input().split())
    value_max = 2 * (10 ** 5)
    com = [0 for _ in range(value_max + 1)]
    com[1] = n
    mod = 10 ** 9 + 7
    mod_inverse = [pow(i, mod - 2, mod) for i in range(1, value_max + 1)]
    ans = pow(2, n, mod)

    # KeyInsight:
    # 全体 - 条件を満たす場合
    # modの世界では割り算の代わりに逆元を使う
    # See:
    # https://www.youtube.com/watch?v=lzAMKPMLdtU&feature=youtu.be
    for i in range(2, min(n, value_max) + 1):
        if (n - i + 1) == 0:
            break

        com[i] = com[i - 1] * (n - i + 1)
        com[i] *= mod_inverse[i - 1]
        com[i] %= mod

    diff = (com[a] + com[b] + 1) % mod
    print((ans - diff) % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62896
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

const int MOD = 998244353;

i64 mod_pow(i64 x, i64 n = MOD - 2, i64 mod = MOD) {
	i64 ret = 1;
	
	while(n) {
		if(n & 1) (ret *= x) %= MOD;
		(x *= x) %= MOD;
		n >>= 1;
	}
	
	return ret;
}

std::vector<i64> fact(1e6 + 1, 1);
i64 comb(int n, int r) {
	if(n < r) return 0;
	
	return fact[n] * mod_pow(fact[r]) % MOD * mod_pow(fact[n - r]) % MOD;
}

int main() {
	for(i64 i = 0; i < 1e6; i++) fact[i + 1] = fact[i] * (i + 1) % MOD;
	i64 n, a, b, k; cin >> n >> a >> b >> k;
	
	i64 ans = 0;
	for(i64 i = 0; i <= n; i++) {
		i64 A = a * i;
		i64 B = k - A;
		if(B < 0 or B % b) continue;
		if(B / b > n) continue;
		
		ans += comb(n, i) * comb(n, B / b) % MOD;
		ans %= MOD;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8064
# -*- coding: utf-8 -*-
abc = ["A","B","C"]

def calculate(x,y, q1,q2):
    flag = 0
    ans = ""
    if x == 1 and y == 1:
        if q1 == q2:
            y -= 1
            x += 1
            ans = abc[q1[0]]

        elif q2 != "":
            t = set(q1) & set(q2)
            s = set(q1) - t
            #print(q2)
            #print(int(list(t)[0]),int(list(s)[0]))
            if int(list(t)[0]) < int(list(s)[0]):
                y -= 1
                x += 1
                ans = abc[q1[0]]
            else:
                x -= 1
                y += 1
                ans = abc[q1[1]]
        else:
            y -= 1
            x += 1
            ans = abc[q1[0]]

    elif x <= y:
        y -= 1
        x += 1
        #print(y)
        if y < 0:
            print("No")
            flag = 1
            return(x, y, ans, flag)
        ans = abc[q1[0]]
    else:
        x -= 1
        y += 1
        ans = ""
        #print(x)
        if x < 0:
            print("No")
            flag = 1
            return(x, y, ans, flag)
        ans = abc[q1[1]]
    return (x, y, ans, flag)

def main():
    N, A, B, C  =  [int(i) for i in input().split()]
    s = []
    for i in range(N):
        t = input()
        if t == "AB":
            s.append([0,1])
        if t == "AC":
            s.append([0,2])
        if t == "BC":
            s.append([1,2])
    #print(s)
    answers  = []
    for i, q1 in enumerate(s):
        ans = ""
        f = 0
        q2 = ""
        if i+1 != N:
            q2 = s[i+1]

        if q1 == [0,1]:
            #print(1)
            A, B, ans, f = calculate(A,B,q1,q2)
        if q1 == [1,2]:
            #print(2)
            B, C, ans,f  = calculate(B,C,q1,q2)
        if q1 == [0,2]:
            #print(3)
            A, C, ans,f  = calculate(A,C,q1,q2)
        answers.append(ans)
        if f == 1:
            return
    print("Yes")

    for a in answers:
        print(a)
if __name__ == "__main__":
    main()


Measured memory_bytes: 18692
S=input()
s=list(S)
 
odd=[]
even=[]
 
for i in range(len(s)):
  if i%2==0:
    odd.append(s[i])
  if i%2==1:
    even.append(s[i])
 
    
oddsum=0
evensum=0
 
for i in range(len(odd)):
  if odd[i]=="R" or odd[i]=="U" or odd[i]=="D":
    oddsum+=1
  else:
    oddsum+=0
 
for i in range(len(even)):
  if even[i]=="L" or even[i]=="U" or even[i]=="D":
    evensum+=1
  else:
    evensum=0
 
if oddsum==len(odd) and evensum==len(even):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
from itertools import accumulate as ac
n=int(input())
a,b=[],[]
for i in range(n):
    x,s=map(int,input().split())
    a.append(x)
    b.append(s)
r=[0]+list(ac(b))
l=r[:]
for i in range(n):
    r[i]+=-a[i]
    l[i+1]+=-a[i]
q,d=r[0],0
for i in range(1,n+1):
    d=max(l[i]-q,d)
    q=min(q,r[i])
print(d)

Measured memory_bytes: 34716
N = int(input())
nums = list(map(int, input().split()))
n_dict = {}
idx = 0
mod = ((N%2)+1)%2
while True:
  if 2*idx + mod > N:
    break
  else:
    n_dict[2*idx+mod] = 0
  idx += 1
for num in nums:
  if num in n_dict:
    n_dict[num] += 1
  else:
    print(0)
    exit()
for key, value in n_dict.items():
  if value != 2 and key != 0:
    print(0)
    exit()
print((2**(N//2))%(10**9+7))


Measured memory_bytes: 14688
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  if(s=="abc")cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
  deque<pair<ll, ll>> q;
  ll ans;
  set<ll> visited;
  q.push_back({0, 0});
  bool flag = true;
  ll memo[N];
  for (int i = 0; i < N; i++) {
    memo[i] = -1;
  }
  while (!q.empty()) {
    ll cur_i = q.front().first;
    ll cur_num = q.front().second;
    q.pop_front();
    if (flag && memo[cur_i] != -1) {
      flag = false;
      ll cnt = cur_num - memo[cur_i];
      cur_num += ((K - cur_num) / cnt) * cnt;
    }
    if (cur_num == K) {
      ans = cur_i + 1;
      break;
    }
    q.push_back({A[cur_i], cur_num + 1});
    memo[cur_i] = cur_num;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	int j,k;
	sort(a.begin(),a.end());
	j = a[0];
	reverse(a.begin(),a.end());
	k = a[0];
	cout << abs(j - k) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)2e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 2, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

PII operator+(const PII &a, const PII &b){
    return PII(a.first + b.first, a.second + b.second);
}

vector<vector<int> > xc(100001), yc(100001);

PII func(PII p){
    PII res(0, 0);
    if(!xc[p.first].empty()){
        vector<int> line = xc[p.first];
        xc[p.first].clear();
        ++res.first;
        for(auto &i:line){
            res = res + func(PII(p.first, i));
        }
    }
    if(!yc[p.second].empty()){
        vector<int> line = yc[p.second];
        yc[p.second].clear();
        ++res.second;
        for(auto &i:line){
            res = res + func(PII(i, p.second));
        }
    }
    return res;
}

signed  main(){
    int N;
    cin >> N;
    cout << N * 800 - N / 15 * 200 << endl;
    return 0;
}



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

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(long long e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e & 1) {a = (a * p) % mod; e--;}
            else {p = (p * p) % mod; e /= 2;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

constexpr int MOD = 1000000007;

int main() {
	int n, k;
	cin >> n >> k;
	
	int val = k;
	ModInt<MOD> ans = 1;
	for (int i = 0; i < n; i++) {
		ans *= k--;
	}
	
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 3116
#include<iostream>  
#include<algorithm>  
#include<string>  
#include<map>//ll dx[4]={0,0,-1,1};ll dy[4]={-1,1,0,0};  
#include<set>//  
#include<vector>  
#include<cmath>  
#include<stack>  
#include<string.h>  
#include<stdlib.h>  
#include<cstdio>  
#define mod 1e9+7  
#define ll long long
using namespace std;  
double y[1010];
double x[1010];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i)
		cin>>x[i];
	double s=0;
	if(n==1){
		printf("%.6f\n",2*x[0]);
		return 0;
	}
	y[0]=x[0];
	for(int i=1;i<n;++i){
		double g=sqrt((x[i]+x[i-1])*(x[i]+x[i-1])-(x[i]-x[i-1])*(x[i]-x[i-1]));
		double p=y[i-1]+g;
		for(int j=i-2;j>=0;--j){
			g=sqrt((p-y[j])*(p-y[j])+(x[i]-x[j])*(x[i]-x[j]));
			if(g<x[i]+x[j]){
				double h=sqrt((x[i]+x[j])*(x[i]+x[j])-(x[i]-x[j])*(x[i]-x[j]));
				p=max(p,y[j]+h);
			}
		}
		y[i]=max(p,x[i]);
	}
	double maxx=0;
	for(int i=0;i<n;++i){
		maxx=max(maxx,y[i]+x[i]);
	}
	printf("%.6f\n",maxx);
	return 0;
}

Measured memory_bytes: 1256
#include<algorithm>
#include<cmath>
#include<iostream>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
using namespace std;

int main()
{
	int i, j, k, l, m, n, sum, flag,A,B,C,D;
	sum = 0;
	flag = 0;
	cin >> A>>B;
	int N;
	N = B - A;
	cout << N * (N + 1) / 2 - B;
    return 0;
}



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

int main(){
  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  for(int i = 0; i < t; i++){
    cin >> a.at(i);
  }
  sort(a.rbegin(), a.rend());
  int ma = a.at(0);
  int za = k - ma;
  if(za >= ma - 1){
    cout << 0;
  }else{
    cout << ma - 1 - za;
  }
}

Measured memory_bytes: 256
k = int(input())
dp = [[] for _ in range(k)]
dp[0] = [1,2,3,4,5,6,7,8,9]

if k <= 9:
    print(k)
else:
    total = 0
    i = 0
    while total + len(dp[i]) < k:
        total += len(dp[i])
        for j in dp[i]:
            x = j%10
            if x == 0:
                dp[i+1].append(j*10)
                dp[i+1].append(j*10+1)
            elif x == 9:
                dp[i+1].append(j*10+8)
                dp[i+1].append(j*10+9)
            else:
                dp[i+1].append(j*10+x-1)
                dp[i+1].append(j*10+x)
                dp[i+1].append(j*10+x+1)
        i += 1
    print(dp[i][k-total-1])

Measured memory_bytes: 18820
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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 under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
void warshall_froid(int n, VV& D) {
	for (int k = 0; k < n; k++) { // 経由
		for (int i = 0; i < n; i++) { // 始点
			for (int j = 0; j < n; j++) { // 終点
				chmin(D[i][j], D[i][k] + D[k][j]);
			}
		}
	}
}
int main() {
	int h, w;
	cin >> h >> w;
	VV cost(10, V(10));
	rep(i, 10) rep(j, 10) {
		cin >> cost[i][j];
	}
	warshall_froid(10, cost);
	VV a(h, V(w));
	rep(i, h) rep(j, w) {
		cin >> a[i][j];
	}
	ll ans = 0;
	rep(i, h) rep(j, w) {
		if (a[i][j] != -1) ans += cost[a[i][j]][1];
	}
	cout << ans << endl;
	return 0;
}

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

int gcd(int n,int m){return m?gcd(m,n%m):n;}

int main(){
    int A,B,K;
    cin >> A >> B >> K;
    for(int i=gcd(A,B);i>=1;i--){
        if(A%i == 0 && B%i == 0) K--;
        if(K == 0){
            cout << i << endl;
            return 0;
        }
    }
    
}

Measured memory_bytes: 256
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
const ll mod = 1000000007;
const ll mod9 = 1000000009;

signed main(){
    mp::cpp_int x,k,d;
    cin>>x>>k>>d;
    mp::cpp_int maxt,mint;
    maxt = x+k*d;
    mint = x-k*d;
    mp::cpp_int ans;
    if(mint > 0) ans = mint;
    else if(maxt < 0) ans = abs(maxt);
    else{
        ans = min(min(abs(mint%(2*d)),abs(mint%(2*d)+2*d)),min(abs(maxt%(2*d)),abs(maxt%(2*d)-2*d)));
    } 
    cout<<ans<<endl;
}


Measured memory_bytes: 3684
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n ;
	vector<int>a(n);
	int ret = 0;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n-1) {
		if (a[i] == i + 1) {
			int tmp = a[i];
			a[i] = a[i + 1];
			a[i + 1] = tmp;
			ret++;
		}
	}
	if (a[n - 1] == n) {
		ret++;
	}
	print(ret);
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,x,ans=INT_MAX;
    cin>>n>>m>>x;
    int c[n],a[n][m];
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=0;j<m;j++)cin>>a[i][j];
    }
    for(int i=1;i<pow(2,n);i++){
        int cost=0,skill[m],count=0;
        for(int j=0;j<m;j++)skill[j]=0;
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                cost+=c[j];
                for(int k=0;k<m;k++)skill[k]+=a[j][k];
            }
        }
        for(int j=0;j<m;j++){
            if(skill[j]>=x)count++;
        }
        if(count==m){
            if(ans>cost)ans=cost;
        }
    }
    if(ans==INT_MAX)cout<<"-1"<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#include <queue>
#include <string.h>
#include <stdint.h>
#include <cmath>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define ull unsigned long long
#define ut uint64_t

#define pb push_back
#define ins insert
#define er erase

#define fi(i, b) for (int i=0;i<b;i++)
#define fll(i, b) for (ll i=0;i<b;i++)
#define fla(i,a,b) for (ll i=a;i<b;i++)

#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vb vector<bool>
#define vst vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvl vector<vector<ll>>


#define all(v) v.begin(), v.end()
#define lb lower_bound
#define ub upper_bound
#define mxe max_element
#define mne min_element

#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())

#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second

#define mii map<int, int>
#define mll map<ll, ll>
#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>

#define si set<int>
#define sll set<ll>
#define usi unordered_set<int>
#define usll unordered_set<ll>
#define spii set<pii>
#define spll set<pll>

#define pqi priority_queue<int>
#define pqll priority_queue<ll>

 #define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)

#define nl "\n"
#define sz(x)  (int)x.size()
using namespace std;

double PI = (acos(-1));

ll ma = 1000000007;
ll md = 998244353;

ll pw(ll a, ll b)
{
    ll c = 1, m = a;
    while (b){
        if (b & 1)c = (c * m);
        m = (m * m);
        b /= 2;
    }
    return c;
}

ll pwmd(ll a, ll b){
    ll c = 1, m = a;
    while (b){
        if (b & 1)
            c = ((c * m)) % md;
        m = (m * m) % md;
        b /= 2;
    }
    return c;
}


ll modinv(ll n)
{
    return pwmd(n, md - 2);
}
ll min(ll a,ll b){
    if(a>=b)return b;
    return a;
}
ll nc2(ll n)
{
    return (1ll * n * (n - 1)) / 2;
}
 
ll nsum(ll n)
{
    return (1ll * n * (n + 1)) / 2;
}

bool is(string r)
{
    string p = r;
    reverse(p.begin(), p.end());
    return (r == p);
}





//vst vect={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
/*ll lis;
ll vis;
int dfs(ll &x){
    vis[x]=1;
    if(x==n-1)return 0;
    else {
        return max()
    }
}*/
bool prime(ll a){
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }return true;
}

void solve(){
    ll n,k;cin>>n>>k;
    ll l[n];
    fi(i,n)cin>>l[i];
    sort(l,l+n);
    ll ans=0;
    fi(i,k)ans+=l[i];
    cout<<ans;
    //if(s>="a")cout<<"a";
    //else cout<<"A";
    
}


// AB DEKHO JAADU...

int main(){
    fast;
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    

    return 0;
    }

// KHATAM HO GAYA:)...

//656843682888290175



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

int main(){
    int n,A,B,C; cin >> n >> A >> B >> C;
    map<char,int> mp;
    mp['A'] = A; mp['B'] = B; mp['C'] = C;
    vector<char> ans(n);
    vector<string> sn(n);
    rep(i,n) cin >> sn[i];
    rep(i,n){
        string s = sn[i];
        char s0 = s[0];
        char s1 = s[1];

        if(mp[s0]==0 && mp[s1]==0){
            cout << "No" << endl;
            return 0;;
        }
        else if(mp[s0]==0){
            mp[s0]++; mp[s1]--;
            ans[i] = s0;
        }
        else if(mp[s1]==0){
            mp[s1]++; mp[s0]--;
            ans[i] = s1;
        }
        else if(i==n-1){
            ans[i] = s0;
        }
        else if(sn[i+1][0]==s0 || sn[i+1][1]==s0){
            mp[s0]++; mp[s1]--;
            ans[i] = s0;
        }
        else{
            mp[s0]--; mp[s1]++;
            ans[i] = s1;
        }
    }
    cout << "Yes" << endl;
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

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

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int a, b; cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

int main() {

  int A;
  int B;
  int C;

  std::cin >> A >> B >> C;

  if (B / A < C) {
    std::cout << B / A << std::endl;
  } else if (B / A >= C) {
    std::cout << C << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
data={}
for i in range(int(input())):
    data[input()]=False
f=False
for i in range(int(input())):
    key=input()
    if key in data:
        if f:
            print('Closed by',key)
            f=False
        else:
            print('Opened by',key)
            f=True
    else:
        print('Unknown',key)


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
const int tambahsimpan=9;
int simpan[20],arr[20],ukuranarr;
LL ans=0,pangkat[20],d;
void isisimpan(){
	for(int i=-9;i>=9;i++)
		simpan[i+tambahsimpan]=0;
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			int temp=i-j;
			simpan[temp+tambahsimpan]++;
		}
	}
}
void isipangkat(){
	pangkat[0]=1;
	for(int i=1;i<=18;i++)
		pangkat[i]=pangkat[i-1]*10LL;
}
int banyakcara(int angka){
	return simpan[angka+tambahsimpan];
}
int caratertentu(int i,int angka){				//kalau angka pertama nya di tentukian
	int j=i-angka;
	return (0<=j&&j<=9)?1:0;
}
int totaldigit(int angka){
	int digit=0;
	while(angka>0)
	{
		digit++;
		angka/=10;
	}
	return digit;
}
void hitungans(){
	LL kali=1;
	for(int i=1;i<=ukuranarr;i++)
	{
		if(i==1)
			kali*=(LL) banyakcara(arr[i])-caratertentu(0,arr[i]);
		else
			kali*=(LL) banyakcara(arr[i]);
	}
	/*cout<<"printing arr"<<endl;
	for(int i=1;i<=ukuranarr;i++)
		cout<<arr[i]<<" ";
	cout<<endl;
	cout<<"banyak caranya "<<kali<<endl;*/
	ans+=kali;
}
void buatsequence(int digit,int depth,LL target){
	//cout<<depth<<" "<<((digit>>1)+1)<<endl;
	if(depth==(digit>>1)+1)			//karena 1 base index
	{
		if(digit&1)
		{
			arr[depth]=0;
			ukuranarr=depth;
		}
		else
			ukuranarr=depth-1;
		
		if(target==0)
			hitungans();
		return;
	}
	LL pengali=pangkat[digit-(depth-1)-1]-pangkat[depth-1];
	//cout<<"pengali dari "<<digit<<" pada "<<depth<<" "<<pengali<<endl;
	int a=-10,b=-9;
	for(int i=-9;i<=9;i++)
	{
		if(pengali*LL(i)>=target)
			break;
		a++;b++;
	}
	
	if(a>=-9)
	{
		arr[depth]=a;
		buatsequence(digit,depth+1,target-pengali*LL(a));
	}
	if(b<=9)
	{
		arr[depth]=b;
		buatsequence(digit,depth+1,target-pengali*LL(b));
	}
}
int main()
{
	cin>>d;
	isisimpan();
	isipangkat();
	/*for(int i=-9;i<=9;i++)
		cout<<"banyak caranya dari "<<i<<" "<<banyakcara(i)<<endl;*/
	int digit=totaldigit(d);
	for(int i=digit;i<=2*digit;i++)
	{
		//cout<<"buat dengan banyak digit "<<i<<endl;
		buatsequence(i,1,-d);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "stdlib.h"
#include "stdio.h"

struct card{
    char suit;
    int value;
};

int N;
struct card C1[100]; 
struct card C2[100];


void swapCard1(int i, int j){
    C1[i].suit = C1[i].suit ^ C1[j].suit;
    C1[j].suit = C1[i].suit ^ C1[j].suit;
    C1[i].suit = C1[i].suit ^ C1[j].suit;
    C1[i].value = C1[i].value ^ C1[j].value;
    C1[j].value = C1[i].value ^ C1[j].value;
    C1[i].value = C1[i].value ^ C1[j].value;
}

void swapCard2(int i, int j){
    C2[i].suit = C2[i].suit ^ C2[j].suit;
    C2[j].suit = C2[i].suit ^ C2[j].suit;
    C2[i].suit = C2[i].suit ^ C2[j].suit;
    C2[i].value = C2[i].value ^ C2[j].value;
    C2[j].value = C2[i].value ^ C2[j].value;
    C2[i].value = C2[i].value ^ C2[j].value;
}

void printCard1(){
    int i;
    for(i=0; i<N-1; i++){
        printf("%c%d ", C1[i].suit, C1[i].value);
    }
    printf("%c%d\n", C1[N-1].suit, C1[N-1].value);
}

void printCard2(){
    int i;
    for(i=0; i<N-1; i++){
        printf("%c%d ", C2[i].suit, C2[i].value);
    }
    printf("%c%d\n", C2[N-1].suit, C2[N-1].value);
}

int isStable(){
    int i;
    for(i=0; i<N; i++){
        if(C1[i].suit != C2[i].suit) return 0;
    }
    return 1;
}
void BubbleSort(){
    int i, j;
    for(i=0; i<N; i++){
        for(j=N-1; j>i; j--){
            if(C1[j].value < C1[j-1].value){
                swapCard1(j, j-1);
            }
        }
    }
}

void SelectionSort(){
    int i, j;
    int minIndex;
    for(i=0; i<N; i++){
        minIndex = i;
        for(j=i+1; j<N; j++){
            if(C2[j].value<C2[minIndex].value){
                minIndex = j;
            }
        }
        if(minIndex != i){
            swapCard2(i, minIndex);
        }
    }
}

int main(){
    //freopen("D:\\zhouyu\\study\\codes\\StableSort.txt", "r", stdin);
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        getchar();
        scanf("%c%d", &C1[i].suit, &C1[i].value);
        C2[i] = C1[i];
    }
    BubbleSort();
    printCard1();
    printf("Stable\n");
    SelectionSort();
    printCard2();
    int i;
    int flag = 1; 
    if(isStable()) printf("Stable\n");
    else printf("Not stable\n");
    return 0;
}


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

int main(){
  int N, D;
  vector<vector<int>> X(10, vector<int>(10));
  
  cin >> N >> D;
  
  for(int i = 0;i < N;i++) for(int j = 0;j < D;j++) cin >> X.at(i).at(j);
  
  int ans = 0;
  for(int i = 0;i < N;i++){
    for(int j = i + 1;j < N;j++){
      int sum = 0;
      for(int k = 0;k < D;k++) sum += pow(X.at(i).at(k) - X.at(j).at(k), 2);
      for(int j = 1;j * j <= sum;j++) if(j * j == sum) ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
using namespace std;
const int N = 2e5+5;
int n;
ii t[N];
main() {
    cin >> n;
    for(int i=0; i<n; i++) {
        int a, b;
        cin >> a >> b;
        t[i] = {b, a};
    }
    sort(t, t+n);
    int cur = 0, ans = 1;
    for(int i=0; i<n; i++) {
        int a = t[i].second,
            b = t[i].first;
        cur += a;
        if(cur > b) {
            ans = 0;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 6712
#include<bits/stdc++.h>
#define N 1000
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> P;
int main(){
  int n;
  while(cin>>n,n){
    vector<pair<int,int> >g[1000],rg[1000];
    int s,t,m;
    cin>>s>>t;
    s--;t--;
    cin>>m;
    for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      a--;b--;
      g[a].push_back(P(b, i+1));
      rg[b].push_back(P(a, i+1));
    }
    pair<int,int> d[n][2];
    memset(d,-1,sizeof(d));
    for(int i=0;i<n;i++)
      for(int j=0;j<2;j++) d[i][j] = P(1e9,1e9);
    d[s][0]=mk(0,0);
    queue<pair<int,int> >q;
    q.push(mk(s,0));
    while(!q.empty()){
      pair<int,int>p=q.front();q.pop();
      int v=p.fi,used=p.se;
      int cost=d[v][used].fi;
      int edge=d[v][used].se;
       for(int i=0;i<g[v].size();i++){
     int nx=g[v][i].fi;
     P ncost = P(cost+1,edge);
     if(d[nx][used]>ncost ){
       d[nx][used]=ncost;
       q.push(mk(nx,used));
        }
       }
        if(!used)for(int i=0;i<rg[v].size();i++){
        int nx=rg[v][i].fi;
        P ncost = P(cost+1,rg[v][i].se);
      if(d[ nx ][1]>ncost){
        d[nx][1]=ncost;
        q.push(mk(nx,1));
      }
     }
    }
    P ans=min(d[t][0],d[t][1]);
    cout<<ans.fi<<' '<<ans.se<<endl;
  }
}

Measured memory_bytes: 3300
N, M = map(int, input().split())
C = [0]*(N+1)
for i in range(M):
    l, r = map(int, input().split())
    C[l-1] += 1
    C[r] -= 1
for i in range(N):
    C[i+1] += C[i]

ans = 0
for i in range(N):
    if C[i] == M:
        ans += 1
print(ans)

Measured memory_bytes: 6900
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

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

using namespace std;
using ll = long long;

int main() {
    ll A; cin >> A;
    ll B; cin >> B;
    ll C; cin >> C;
    ll K; cin >> K;

    ll ans = 0;

    int xa = min(A, K);
    K -= xa;

    int xb = min(B, K);
    K -= xb;

    int xc = min(C, K);

    cout << xa - xc << endl;
    return 0;
}


Measured memory_bytes: 3600