akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
int main()
{
	struct data
	{
		char s[201];
		int m;
		int*h;
	} dat[10];
	int num;
	for(int i = 0;; i++)
	{
		std::cin >> dat[i].s;
		if(dat[i].s[0] == '-')
		{
			num = i;
			break;
		}
		std::cin >> dat[i].m;
		dat[i].h = new int[dat[i].m];
		for(int j = 0; j < dat[i].m; j++)
		{
			std::cin >> dat[i].h[j];
		}
	}
	for(int i = 0; i < num; i++)
	{
		int length;
		for(int j = 0;; j++)
		{
			if(dat[i].s[j] == '\0')
			{
				length = j;
				break;
			}
		}
		int sum_h = 0;
		for(int j = 0; j < dat[i].m; j++)
		{
			sum_h += dat[i].h[j];
		}
		sum_h %= length;
		for(int j = sum_h; j < length; j++)
		{
			std::cout << dat[i].s[j];
		}
		for(int j = 0; j < sum_h; j++)
		{
			std::cout << dat[i].s[j];
		}
		std::cout << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3104
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize
    }
    let d = 1000000007;
    let mut sq = 1;
    while sq * sq <= n {
        sq += 1;
    }
    sq -= 1;
    let m = n / (sq + 1);
    let len = sq + m;
    let mut c = vec![0; m];
    for i in 0..m {
        c[i] = (n / (m - i) - n / (m + 1 - i)) % d;
    }
    let mut dp = vec![vec![0; len]; k + 1];
    dp[0][0] = 1;
    for i in 1..k + 1 {
        let mut ac = vec![0; len];
        ac[0] = dp[i - 1][0];
        for j in 1..len {
            ac[j] = (ac[j - 1] + dp[i - 1][j]) % d;
        }
        for j in 0..sq {
            dp[i][j] = ac[len - j - 1];
        }
        for j in 0..m {
            dp[i][sq + j] = c[j] * ac[n / (n / (m - j)) - 1] % d;
        }
    }
    println!("{}", dp[k].iter().fold(0, |ac, x| (ac + x) % d));
}


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

using namespace std;

stack <int> top_sort;

vector <int> adj[100001];

long long int dist[100001];

bool visit[100001];

void dfs(int u){
	
	int l = adj[u].size();
	
	for(int i=0; i<l; i+=1){
		
		int v = adj[u][i];
		
		if(visit[v] == 0){
			
			visit[v] = 1;
			
			dfs(v);
		}
	}
	
	top_sort.push(u);
	
	return;
}

int main(){
	
	ios_base::sync_with_stdio(0);
	
	cin.tie(0);
	
	cout.tie(0);
	
	int n,m;
	
	cin>>n>>m;
	
	for(int i=0; i<m; i+=1){
		
		int u,v;
		
		cin>>u>>v;
		
		adj[u].push_back(v);
	}
	
	for(int i=0; i<=n; i+=1){
		
		dist[i] = 0;
	}
	
	for(int i=1; i<=n; i+=1){
		
		if(visit[i] == 0){
			
			visit[i] = 1;
			
			dfs(i);
		}
	}
	
	while(!top_sort.empty()){
		
		int u = top_sort.top();
		
		top_sort.pop();
		
		int l = adj[u].size();
		
		for(int i=0; i<l; i+=1){
			
			int v = adj[u][i];
			
			dist[v] = max(dist[v],dist[u]+1);
		}
	}
	
	long long int ans = 0;
	
	for(int i=1; i<=n; i+=1){
		
		if(dist[i] >= ans){
			
			ans = dist[i];
		}
	}
	
	cout<<ans;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int white = 0;
    int black = 0;
    // cout << S.size() << endl;
    for (int i = 0; i < S.size(); i++)
    {
        if (i % 2 == 0)
        {
            if (S[i] == '1')
            {
                white++;
            }
            else
            {
                black++;
            }
        }
        else
        {
            if (S[i] == '1')
            {
                black++;
            }
            else
            {
                white++;
            }
        }
    }
    // cout << black << white << endl;
    cout << min(black, white) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
int main(){
	long long n,b,a;
	cin>>n>>a>>b;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	sort(h.begin(),h.end(),greater<int>());
	int high=1000000000,low=0;
	long diff=a-b;
    while(high-low>1){
		int cnt=0;
		bool ok=true;
        int center=(low+high)/2;
        for(int i=0;i<n;i++){
			long long tmp=h[i]-b*center;
			if(tmp<=0)continue;
			cnt+=(tmp+diff-1)/diff;
			if(cnt>center){
				ok=false;
				break;
			}
		}
		if(ok)high=center;
		else low=center;
    }
	int ans=high;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, c, no_working = 0;
    cin >> n >> m >> c;
    int b_terms[m];
    for (int i = 0; i < m; i++) {
        cin >> b_terms[i];
    }
    for (int i = 0; i < n; i++) {
        int curr_sum = 0;
        for (int j = 0; j < m; j++) {
            int x;
            cin >> x;
            curr_sum += b_terms[j] * x;
        }
        if (curr_sum + c > 0) {
            no_working++;
        }
    }
    cout << no_working;
}



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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll n, m, a, b, c, now;
	ll ans = 0;

	cin >> n >> m >> c;

	vector<ll> v(m, 0);

	REP(i, m) {
		cin >> b;
		v[i] = b;
	}

	REP(i, n) {
		now = c;

		REP(j, m) {
			cin >> a;
			now += a * v[j];
		}

		if (now > 0) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long X=1000000000+7;

int main() {
  int h,w;
  cin>>h>>w;
  string W="";
  rep(i,w+2) W+="#";
  cout<<W<<endl;
  rep(i,h){
    string s;
    cin>>s;
    cout<<"#"<<s<<"#"<<endl;
  }
  cout<<W<<endl;
}


Measured memory_bytes: 256
S = input()

dp = [[0,0,0,0,0,0,0,0,0,0,0,0,0] for i in range(len(S) + 2)]
INF = 10**9 + 7
for num, dig in enumerate(S):
    if num == 0:
        if dig == '?':
            dp[num] = [1,1,1,1,1,1,1,1,1,1,0,0,0]
        else:
            dp[num] = [0,0,0,0,0,0,0,0,0,0,0,0,0]
            dp[num][int(dig)] = 1

    elif dig == '?':
        for j in range(10):
            for i in range(13):
                dp[num][(i * 10 + j) % 13] += dp[num - 1][i] % INF
                dp[num][(i * 10 + j) % 13] %= INF

    else:
        for i in range(13):
            dp[num][(i*10 + int(dig))%13] += dp[num - 1][i] % INF
            dp[num][(i * 10 + int(dig)) % 13] %= INF

print(dp[len(S)-1][5])

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

int main(void){
   int n, i, j, k, l;

   scanf("%d", &n);

   int a[n];

   for(i = 0; i < n; i++) {
      scanf("%d", &a[i]);
   }


   l = 0;

   for(i = 0; i < n; i++) {
      if (a[i] < 4||a[i] % 2 == 1){
      if (a[i] == 3||a[i] % 3 != 0){

   k = 0;
   for(j = 1; j <= sqrt(a[i]); j++) {
      if (a[i] % j == 0){
         k++;
      }
   }
      if (k == 1){
         l++;
      }
      }
      }
   }

   printf("%d\n", l);

   return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n,a;
  cin>>n>>a;
  int ans=n % 500;
  if(ans<=a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#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.at(i);
  }

  bool flag = true;
  int cnt = 0;
  while (flag)
  {
    flag = false;
    for (int i = N - 1; i >= 1; i--)
    {
      if (A.at(i) < A.at(i - 1))
      {
        swap(A.at(i), A.at(i - 1));
        flag = true;
        cnt++;
      }
    }
  }
  for (int i = 0; i < N; i++)
  {
    if (i)
    {
      cout << " ";
    }
    cout << A.at(i);
  }
  cout << endl;

  cout << cnt << endl;
}


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

typedef long long ll;
const int N = 1e5 + 5;
vector<int> edge[N];
int col[N];
int a[3];
int n, m;
bool bp;

void DFS(int u) {
    for (int v: edge[u]) {
        if (col[v] != -1) {
            if ((col[v]^col[u]) != 1) bp = false;
        } else {
            col[v] = col[u]^1;
            DFS(v);
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i=1; i<=m; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    memset(col, -1, sizeof(col));
    for (int i=1; i<=n; ++i) {
        if (col[i] != -1) continue;
        if (edge[i].size() == 0) { col[i] = 0; a[0]++; }
        else {
            col[i] = 0;
            bp = true;
            DFS(i);
            if (bp) a[1]++;
            else a[2]++;
        }
    }
    ll ans = 0;
    for (int i=1; i<3; ++i) {
        for (int j=1; j<3; ++j) {
            if (i == 1 && j == 1) ans += (ll)a[i]*a[j]*2LL;
            else ans += (ll)a[i]*a[j];
        }
    }
    ans += (ll)a[0]*(n-a[0])*2LL+(ll)a[0]*a[0];
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 9088
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> prices;
    int n, price;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> price;
        prices.push_back(price);
    }
    
    int maxProfit = INT_MIN;
    int minPrice = prices[0];

    for (int i = 1; i < prices.size(); i++) {
        int profit = prices[i] - minPrice;
        maxProfit = max(maxProfit, profit);
        minPrice = min(minPrice, prices[i]);
    }

    cout << maxProfit << endl;

    return 0;
}



Measured memory_bytes: 3844
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;

int per[100010];
int dis[100010];

void init(int n){
	rep(i,n){
		per[i+1]=i+1;
		dis[i+1]=0;
	}
}

int find(int a){ 
	if(per[a]==a){
		return a;
	}
	else {
		int f= per[a];
		per[a] = find(per[a]);
		dis[a] += dis[f];
		return per[a];
	}
}

int main(){
	int NNN,MMM;
	cin >> NNN >> MMM;
	int templ,tempr,tempd;
	init(NNN);
	int l;
	int r;
	rep(i,MMM){
		cin >> templ >>tempr >> tempd;
		l = find(templ);
		r = find(tempr);
		if(r==l){
			if(abs(dis[templ]-dis[tempr])!=tempd){
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			per[l] = r;
			dis[l] = dis[tempr] - dis[templ] + tempd;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1024
a, b, x = gets.chomp.split(" ").map(&:to_f);

height = x/(a*a)
rest   = b - height

if rest*2 <= b
  puts Math.atan(rest*2/a)*180/Math::PI
else
  c = x/a/b*2
  puts Math.atan(b/c)*180/Math::PI
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }


signed main()
{
    int N,K; cin>>N>>K;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    
    vector<int> dp(K+1);
    dp[0]=0;

    for(int i=1;i<=K;i++){
        for(int j=0;j<N;j++){
            if(i-a[j]>=0 and !dp[i-a[j]]) dp[i]=1;
        }
    }
    cout<<(dp[K]? "First":"Second")<<endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

typedef pair<int, int> p_ii;

int main() {
  int N; cin >> N;
  p_ii pos[N]; rep(i,N) { int x; cin >> x; pos[i] = make_pair(i,x-1); }

  queue<int> part;
  sort(pos,pos+N,[](const p_ii &x, const p_ii &y){ return x.second<y.second; });
  for (auto x: pos) rep(i,x.first) part.push(x.first);
  // reverse(pos,pos+N);
  for (auto x: pos) rep(i,(N-1)-x.first) part.push(x.first);
  // while(!part.empty()) { cout << part.front() << " "; part.pop(); } cout << endl;

  // reverse(pos,pos+N);
  // rep(i,N) cout << pos[i].first << "->" << pos[i].second << endl;
  int ipos = 0;
  int result[N*N];
  int count[N] = {};
  rep(i,pow(N,2)) {
    if (pos[ipos].second==i) {
      if (pos[ipos].first==count[pos[ipos].first]) {
        result[i] = pos[ipos].first+1;
        count[pos[ipos].first]++;
        ipos++;
      }
      else {
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      result[i] = part.front()+1;
      count[part.front()]++;
      part.pop();
    }
  }
  cout << "Yes" << endl;
  rep(i,pow(N,2)) cout << result[i] << " "; cout << endl;
  return 0;
}

Measured memory_bytes: 3200
import sys
import math
from functools import reduce
from operator import mul
sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, sys.stdin.readline().split(' ')))
def In(): return int(sys.stdin.readline())
def InS(): return sys.stdin.readline()

S = InS()[:-1]

N = len(S)
T = S[:(N-1)//2]
if S[:(N-1)//2] == T[::-1]:
    T2 = S[(N+1)//2::]
    if S[(N+1)//2::] == T2[::-1]:
        if T == T2[::-1]:
            print('Yes')
            sys.exit()

print('No')

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m), a(m);
  rep(i, m) cin >> b[i];
  int ans = 0;
  rep(i, n){
    int sum = c;
    rep(j, m){
      cin >> a[j];
      sum += a[j] * b[j];
    }
    if (sum > 0) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3608
#ABC088C
C=[]
for _ in range(3):
	C.append(list(map(int,input().split())))
for i in range(3):
	m=min(C[i])
	for j in range(3):
		C[i][j]-=m
for i in range(3):
	if C[0][i]!=C[1][i] or C[1][i]!=C[2][i]:
		print('No')
		exit()
print('Yes')

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

const int max_n = 1e5 + 5;
const int mod = 1e9 + 7;

int n;
VI v;
lint dp[405][405];
const lint INF = 1e9*1LL*1e9;

int main () {
	read(n);
	readv(v, n);
	FOR(i,0,n) dp[i][i] = 0;
	FOR(d,1,n) {
		FOR(i,0,n) {
			if (i+d>=n) break;
			lint best = INF;
			lint sum = 0;
			FOR(u,i,i+d+1) sum += v[u];
			FOR(u,0,d) {
				best = min(dp[i][i+u]+dp[i+u+1][i+d], best);
			}
			dp[i][i+d] = best + sum;
		}
	}
	printf("%lld\n", dp[0][n-1]);
}	





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

int main() {
    int n;
    double a,sum;
    cin >> n;
    sum = .0;
    for (int i = 0; i < n; i++) {
        cin >> a;
        sum += (1.0 / a);
    }
    cout << 1.0 / sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>

using namespace std;
typedef long long ll;

ll sign(ll x){
    if(x > 0){
        return 1;
    }else if(x < 0){
        return -1;
    }else{
        return 0;
    }
}

void move_y(ll y1, ll y2, ll x, vector<array<ll, 4>>& moves){
    ll cy = y1;
    while(cy != y2){
        array<ll, 4> tmp = {cy, x, cy + sign(y2 - cy), x};
        moves.push_back(tmp);
        cy += sign(y2 - cy);
    }
}

void move_x(ll x1, ll x2, ll y, vector<array<ll, 4>>& moves){
    ll cx = x1;
    while(cx != x2){
        array<ll, 4> tmp = {y, cx, y, cx + sign(x2 - cx)};
        moves.push_back(tmp);
        cx += sign(x2 - cx);
    }
}

void calc_move(
    ll y1, ll x1, ll y2, ll x2,
    vector<array<ll, 4>>& moves
){
    bool y1e = (y1 % 2 == 0);
    bool y2e = (y2 % 2 == 0);
    bool x1le = (x2 >= x1);
    if((y1e && x1le) || (!y1e && !x1le)){
        move_x(x1, x2, y1, moves);
        move_y(y1, y2, x2, moves);
    }else if((y1e && !y2e && !x1le) || (!y1e && y2e && x1le)){
        move_y(y1, y2, x1, moves);
        move_x(x1, x2, y2, moves);
    }else{
        move_y(y1, y1 + 1, x1, moves);
        move_x(x1, x2, y1 + 1, moves);
        move_y(y1 + 1, y2, x2, moves);
    }
}

int main(){
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> a.at(i).at(j);
        }
    }

    vector<pair<ll, ll>> odds;
    for(int y = 0; y < h; ++y){
        if(y % 2 == 0){
            for(int x = 0; x < w; ++x){
                if(a.at(y).at(x) % 2 == 1){
                    odds.push_back(make_pair(y, x));
                }
            }
        }else{
            for(int x = w - 1; x >= 0; --x){
                if(a.at(y).at(x) % 2 == 1){
                    odds.push_back(make_pair(y, x));
                }
            }
        }
    }

    vector<array<ll, 4>> moves;
    for(int k = 0; k + 1 < odds.size(); k += 2){
        calc_move(
            odds.at(k).first, odds.at(k).second,
            odds.at(k + 1).first, odds.at(k + 1).second,
            moves);
    }

    cout << moves.size() << endl;
    for(array<ll, 4>& t : moves){
        cout << t.at(0) + 1 << ' ' << t.at(1) + 1 << ' ' <<
            t.at(2) + 1 << ' ' << t.at(3) + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 13676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int sum = 0;
    for(int i = 0; i < k; i++) {
        sum += a[i];
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    int dp[4][1000] = {};
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                dp[3][(j*100) + (k*10) + (s[i]-'0')] = dp[2][(j*10) + k];
            }
        }
        for(int j = 0; j < 10; j++){
            dp[2][(j*10) + (s[i]-'0')] = dp[1][j];
        }
        dp[1][(s[i]-'0')] = dp[0][0];
    }
    int ans = 0;
    for(int i=0;i<1000;i++){
        if(dp[3][i] == 1) {
            ans ++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前
sort()
sorted(reverse=true)
配列の初期化
配列名=[a]*n+[b]*m
Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys

d = [int(s) for s in stdin.readline().rstrip().split()]
res = int(d[0]/d[1])*d[2]
if d[0] % d[1] != 0:
    res += d[2]
print(res)


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

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

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(c - a) <= d) {
    cout << "Yes" << endl;
  } else if (abs(c - b) <= d && abs(b - a) <= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};



int main(){
    int a,b;cin >> a >> b;
    cout << (a + b - 1) / b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

int main(){
    int N,K,e,r;
    cin >> N >> K;
    int x[N];
    rep(i,N){
        cin >> x[i];
    }
    int a = N-K+1;
    int mini = 1000000000;
    int sum;
    rep(i,a){
        e = abs(x[i+K-1]);
        r = abs(x[i]);
        sum = x[i+K-1] - x[i] + min(e,r);
        chmin(mini,sum);
    }
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        var sum1 = 0L;
        var sum2 = 0L;

        for(int i=0; i<s.Length; i++) {
            var c = s[i] - '0';
            if (c != i % 2) sum1++;
            if (c == i % 2) sum2++;
        }
        return Math.Min(sum1, sum2);
    }
}

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

using namespace std;

using ll = long long;

int main() {
   ios_base::sync_with_stdio(false);
   int N;
   cin >> N;
   vector<int> A(N + 1, -1);
   for (int i = 0; i < N; ++i) cin >> A[i];
   auto __assert = [&](bool z) { if (!z) { cout << "-1\n"; exit(0); } };
   __assert(A[0] == 0);
   ll ans = 0;
   for (int i = 1; i <= N; ++i) {
      __assert(A[i] <= A[i - 1] + 1);
      if (A[i] <= A[i - 1]) ans += A[i - 1];
   }
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 1024
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))

cnt=[0 for _ in range(3)]
for pi in p:
    if pi<=a:
        cnt[0]+=1
    elif pi<=b:
        cnt[1]+=1
    else:
        cnt[2]+=1

print(min(cnt))

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

int main() {
  int n;
  cin >> n;
  vector<int> pi(n);
  for (int i = 0; i < n; i++) cin >> pi.at(i);
  
  vector<int> sorted(n);
  for (int i = 0; i < n; i++) sorted.at(i) = i+1;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (pi.at(i) != sorted.at(i)) count++;
  }
  if (count <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++) {
        cin >> L.at(i);
    }
    sort(L.begin(),L.end());
    reverse(L.begin(),L.end());
    int length = 0;
    for(int i = 1; i < N; i++) {
        length += L.at(i);
    }
    if(L.at(0) >= length) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////



int main() {

	ll A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	double nd = -1;
	ll sw;
	ll sugar;

	rep(i, 31) {
		rep(j, 31) {
			if (i == 0 && j == 0) { continue; }

			ll w = 100 * A*i + 100 * B*j;
			if (w > F) { continue; }
			ll s = min(F - w, E*(A*i + B * j));

			for (ll k = 0; k*C <= s; k++) {
				ll l = (s - k * C) / D;

				ll ss = k * C + l * D;
				double d = (double)ss / (double)(w+ss);
				
				if (d > nd) {
					nd = d;
					sw = w +ss;
					sugar = ss;
				}
			}

		}
	}

	cout << sw << " " << sugar;

	system("PAUSE");

	

}


Measured memory_bytes: 504
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++)
			A[i] = sc.nextInt();

		int[] count = new int[200000];
		for (int i = 0; i < N; i++)
			count[A[i] - 1]++;
		int ans = 0;
		Arrays.sort(count);
		for (int i = 0; i < 200000 - K; i++)
			ans += count[i];

		System.out.println(ans);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 25668
#include<bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
#define P pair<int, int>
#define L first
#define R second
const int N = 3e5 + 233;
int n, m, ans = 0;
int sum[233333];
P p[233333];
int Max;
vector<int> vec[N];
priority_queue<int, vector<int>, greater<int> > q;
multiset<int> s;

main(void) {
  read(n); read(m);
  fo(i, n) {
    read(p[i].L), read(p[i].R);
    vec[p[i].L].push_back(p[i].R);
    s.insert(p[i].R);
  }
  for(int i = 0; i <= m + 1; i ++)
    sort(vec[i].begin(), vec[i].end(), greater<int>());
  int L = 1;
  for(int i = 1; i <= m; i ++) {
    for(auto u: vec[i]) {
      if(L <= i) {
	L ++;
	q.push(u);
      }
      else {
	if(q.top() < u)
	  q.pop(), q.push(u);
      }
    }
  }
  int ans = L - 1;
  while(!q.empty()) 
    s.erase(s.lower_bound(q.top())), q.pop();
  while(L <= m && s.size()) {
    auto it = s.upper_bound(L);
    if(it != s.begin()) {
      -- it;
      s.erase(it);
    }
    L ++;
  }
  cout << s.size() << "\n";
}


Measured memory_bytes: 22908
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

//10進数を2進数に変換_63個の要素を持つ配列
vector<int> Convert10to2(ll n) {
	vector<int> ans(63);
	rep(i, 63) {
		ans[i] = n % 2;
		n -= n % 2;
		n /= 2;
	}
	return ans;
}
//2進数を10進数に変換_63個の要素を持つ配列
ll Convert2to10(vector<int> a) {
	ll ans = 0;
	ll j = 1;
	rep(i, a.size()) {
		ans += a[i] * j;
		if (i != a.size() - 1) {
			j *= 2;
		}
	}
	return ans;
}
//XORを計算
vector<int> CalcXOR2to2(vector<int> a, vector<int> b) {
	rep(i, 63) {
		if (a[i] != b[i]) {
			a[i] = 1;
		}
		else {
			a[i] = 0;
		}
	}
	return a;
}

//最大公約数
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a%b);
}

int VectorSum(vector<int> x) {
	int ans = 0;
	rep(i, x.size()) {
		ans += x[i];
	}
	return ans;
}

class UnionFind {
public:
	vector<int> Parent;

	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0) {
			return A;
		}
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {
		return -Parent[root(A)];
	}

	bool connect(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B) {
			return false;
		}
		if (size(A) < size(B)) {
			swap(A, B);
		}
		Parent[A] += Parent[B];
		Parent[B] = A;
	}
};





int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	reverse(a);
	reverse(b);
	UnionFind UF(n);
	
	vector<ll> ans(m);
	ans[0] = (ll)n*(n - 1) / 2;
	for (int i = 1; i < m; i++) {
		if (UF.root(a[i-1]) != UF.root(b[i-1])) {
			ans[i] = ans[i - 1] - (ll)UF.size(a[i-1])*UF.size(b[i-1]);
			UF.connect(a[i-1], b[i-1]);
		}
		else {
			ans[i] = ans[i - 1];
		}
	}

	//vector<ll> ans;
	//ans.push_back((ll)n*(n - 1) / 2);
	//int i = 0;
	//while (ans.size() < m) {
	//	if (UF.root(a[i]) != UF.root(b[i])) {
	//		ans.push_back(*(--ans.end()) - (ll)UF.size(a[i])*UF.size(b[i]));
	//		UF.connect(a[i], b[i]);
	//		i++;
	//	}
	//	else {
	//		ans.push_back(*(--ans.end()));
	//	}
	//}

	reverse(ans);
	rep(i, m) {
		cout << ans[i] << endl;
	}

	return 0;



}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int a[1010],b[1010];
char s[1010][1010];
int main()
{
	int n,m,i,j;
	scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	memset(a,0,sizeof(a));
	for(i=1; i<=n; i++)
	{
		scanf("%s",s[i]+1);
		for(j=1; j<=m; j++)
			if(s[i][j]=='.')
			{
				a[i]++;
				b[j]++;
			}
	}
	for(i=1; i<=n; i++)
	{
		if(a[i]==m) continue;
		for(j=1; j<=m; j++)
			if(b[j]!=n) cout<<s[i][j];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
d,m=1e9+7,l,dp[10001][2][100];
char s[11111];
f(i,k,t,x,L)
{
	int*r=dp[i][t]+k;
	*r=i-l?*r:!k;
	if(!~*r)
	{
		*r=0;
		L=t?9:s[i]-48;
		for(x=0;x<=L;*r%=m)*r+=f(i+1,(k+x++)%d,t|x<L);
	}
	return*r;
}
main()
{
	scanf("%s%d",s,&d);
	memset(dp,-1,sizeof dp);
	l=strlen(s);
	printf("%d",(f(0,0,0)-1+m)%m);
}

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

ll dp[3005][3005];

int main()
{
    string a,b;
    cin>>a>>b;
    a=' '+a;
    b=' '+b;
    ll sa=a.size();
    ll sb=b.size();
    int dp[sa+5][sb+5];
    for(ll i=0; i<sa; i++)
        for(ll j=0; j<sb; j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
                continue;
            }
            if(a[i]==b[j])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }

    int i=sa-1,j=sb-1;
    string ans="";
    while(i>0 && j>0){
        if(a[i]==b[j]){
            ans=a[i]+ans;
            i--;
            j--;
        }
        else{
            if(dp[i-1][j]>dp[i][j-1]){
                i--;
            }
            else{
                j--;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 38888
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;


//dp[i][j]は左i右j削られた後のX-Y
vector<vector<ll>> dp(3001, vector<ll>(3001, INF));
ll N;
vector<ll> a(3001,0);

ll F(ll x,ll y){
    if(dp[x][y]!=INF)return dp[x][y];
    if(x+y==N){return dp[x][y]=0;}


    //Taroから
    if((x+y)%2==0){
        ll ans;
        ans=max(a[x]+F(x+1,y),a[N-y-1]+F(x,y+1));
        return dp[x][y]=ans;
    }
    //Jiroから
    else{
        ll ans;
        ans=min(-a[x]+F(x+1,y),-a[N-y-1]+F(x,y+1));
        return dp[x][y]=ans;
    }

}

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

    cout<<F(0,0)<<endl;

    return 0;
}


Measured memory_bytes: 70912
def solve(a,b):
  if a==b:
    return (a-1)+(b-1)
  elif a+1==b or b+1==a:
    return (min(a,b)-1)*2
  else:
    cnt=(a*b)**(1/2)
    if cnt==int(cnt):
      cnt=int(cnt)-1
    else:
      cnt=int(cnt)
    if cnt*(cnt+1)>=a*b:
      return int(cnt)*2-2
    else:
      return int(cnt)*2-1

Q=int(input())

for i in range(Q):
  a,b=map(int,input().split())
  print(solve(a,b))


Measured memory_bytes: 3188
n = int(input())

def dfs(s, mx):
    if len(s) == n:
        print(s)
    else:
        for i in range(0, mx +1):
            c = chr(ord('a')+i)
            dfs(s+c, mx +1) if i == mx else dfs(s+c, mx)

dfs('', 0)

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(0,c-(a-b)) << endl;
    return 0;
}

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

vector<pair<int, int>> primeFactorization(int n) {
    vector<pair<int, int>> res;

    for (int p = 2; p * p <= n; p++) {
        if (n % p != 0) continue;

        int cnt = 0;
        while (n % p == 0) {
            n /= p;
            cnt++;
        }

        res.push_back(make_pair(p, cnt));
    }

    if (n != 1) res.push_back(make_pair(n, 1));

    return res;
}

const int mod = 1e9 + 7;
vector<long long> fac, finv, inv;

void initCombination(const int n) {
    fac.resize(n, 1);
    finv.resize(n, 1);
    inv.resize(n, 1);

    rep(i, 2, n) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long combination(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

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

    auto vp = primeFactorization(m);
    initCombination(1e6);   //1e7まで

    long long ans = 1;
    for (auto e : vp) {
        (ans *= combination(e.second + n - 1, n - 1)) %= mod;
    }

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

Measured memory_bytes: 23680
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int a = vs[0];
			int b = vs[1];
			int c = vs[2];
			int k = int.Parse(Console.ReadLine());

			for (int i = 0; i < k; i++) {
				if (a > b && a > c) {
					a *= 2;
				} else if (b > a && b > c) {
					b *= 2;
				} else {
					c *= 2;
				}
			}
			int ans = a + b + c;
			Console.WriteLine(ans);

		}
	}
}


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

int N, M;
vector<int> p(100001);
vector<string> S(100001);

void solve(){
    vector<bool> ac(N + 1, false);
    vector<int> wa(N + 1, 0);
    for(int i = 1; i <= M; ++i){
        if(S[i] == "AC") ac[p[i]] = true;
        else if(!ac[p[i]]) wa[p[i]]++;
    }
    int acn = 0;
    int wan = 0;
    for(int i = 1; i <= N; ++i){
        if(ac[i]) { acn++; wan += wa[i]; }
    }
    cout << acn << " " << wan;
}
int main(){
    cin >> N >> M;
    for(int i = 1; i <= M; ++i){
        cin >> p[i] >> S[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 6528
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;string s,t;cin>>s>>t;
	   cout << t<< s << endl;
	return 0;
}


Measured memory_bytes: 256
#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 q;
  cin >> q;
  while(q--) {
    int b, m, e;
    cin >> b >> m >> e;
    rotate(a.begin()+b, a.begin()+m, a.begin()+e);
  }
  for(int i = 0; i < n; ++i) cout << a[i] << " \n"[i==n-1];
  return 0;
}



Measured memory_bytes: 3112
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
typedef long long int llint;
int main() {
	char s[200010];
	cin >> s;
	llint ans = 0;
	llint cnt = 0;
	for (llint i = 0;i < strlen(s);i++) {
		if (s[i] == 'W') {
			ans += i - cnt;
			cnt++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream> 
#include <algorithm> 
#include <cstring> 
#include <cstdio>
#include <vector> 
#include <queue> 
#include <cstdlib> 
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime> 
#include <map> 
#include <set> 
using namespace std; 
#define lowbit(x) (x&(-x)) 
#define max(x,y) (x>y?x:y) 
#define min(x,y) (x<y?x:y) 
#define MAX 100000000000000000 
#define MOD 1000000007
#define pi acos(-1.0) 
#define ei exp(1) 
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
vector<pair<int,int> >v[100006];
ll dis[100005];
int n,k,x,y,w,q;
bool vis[100005];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(!vis[v[x][i].first])
        {
            dis[v[x][i].first]=dis[x]+v[x][i].second;
            dfs(v[x][i].first);
        }
    }
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(vis,0,sizeof(vis));
        memset(dis,0,sizeof(dis));
        for(int i=0;i<=n;i++)
            v[i].clear();
        for(int i=0;i<n-1;i++)
        {
            scanf("%d%d%d",&x,&y,&w);
            v[x].push_back(make_pair(y,w));
            v[y].push_back(make_pair(x,w));
        }
        scanf("%d%d",&q,&k);
        dfs(k);
        while(q--)
        {
            scanf("%d%d",&x,&y);
            printf("%lld\n",dis[x]+dis[y]);
        }
    }
    return 0;
}

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

int main() {
  int N, count;
  count=0;
  cin >> N;
  vector<int> vec(N);
  
  for (int i=0; i<N; i++) {
    cin >> vec.at(i);
  }

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

  if (N%2==0) {
    for (int j=0; j<N; j+=2) {
      count=count+vec.at(j)-vec.at(j+1);
    }
  }

  else if (N%2!=0) {
    for (int j=0; j<N-1; j+=2) {
      count=count+vec.at(j)-vec.at(j+1);
    }
    count=count+vec.at(N-1);
  }

  cout << count << endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t int64;
typedef int64_t ll;

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

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

using namespace std;


class C {
	int n;
	vector<int> b;
public:
	C()
	{
		cin >> n;
	}
	void solve()
	{
		int ans{ 0 };

		int last;
		int current;

		cin >> last;
		ans = last;

		if (n > 2)
			REP(i, n - 1)
			{
				cin >> current;

				ans += min(last, current);

				last = current;
			}
		
		else
		{
			ans += last;
		}

		cout << ans << endl;
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

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(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
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]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-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 );
}

ll n;
ll a[100100];
multiset<ll> s1;
ll ans=1;
int main(){
	cin>>n;
	REP(i,n){
		cin>>a[i];
	}
	s1.insert(a[0]);
	for(ll i=1;i<n;i++){
		auto it=s1.lower_bound(a[i]);
		if(it==s1.begin()){
			s1.insert(a[i]);
			ans++;
		}else{
			s1.erase(--it);
			s1.insert(a[i]);
		}
		//cout<<ans<<endl
	}
	cout<<s1.size()<<endl;
	return 0;
}

Measured memory_bytes: 5760