akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int num = s.nextInt();
        while(num!=0){
            int max = 0;
            int out = 0;
            char[][] data = new char[num][num];
            for(int i=0 ; i<num ; i++){
                String in = s.next();
                for(int j=0 ; j<num ; j++)
                    data[i][j] = in.charAt(j);
            }
            boolean one = false;
            for(int k=0 ; k<num ; k++){
                for(int l=0; l<num; l++){
                    if(data[k][l]=='.'){
                        one = true;
                        int m = 0;
                        while((l+m)<(num-1) && data[k][l+m]=='.')
                            m++;
                        if((m+k)>=num)
                            m = num - k - 1;
                        for(out=m ; out>=0 ; out--){
                            boolean flag = false;                            
                            for(int o=0 ; o<=out ; o++){
                                for(int p=0 ; p<=out ; p++){
                                    if(data[k+o][l+p]=='*'){
                                        flag = true;
                                        break;
                                    }
                                }
                                if(flag)
                                    break;                                    
                            }
                            if(!flag)
                                break;
                        }
                        if(out>max)
                            max = out; 
                    }      
                }
            }
            if(one)
                System.out.println(max+1);
            else
                System.out.println("0");
            num = s.nextInt();
        }
    }
}

Measured memory_bytes: 14000
let line = readLine()!
let abcd = line.split(separator: " ").map { Int($0)! }
var a = abcd[0]; var b = abcd[1]; var c = abcd[2]; var d = abcd[3]

while true { 
  c -= b
  if c <= 0 {
    print("Yes")
    break
  }
  a -= d
  if a <= 0 {
    print("No")
    break
  }
}

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

const int MAXH=100005;
const int MAXW=100005;

ll A[MAXH+MAXW];

ll mod_pow(ll x,ll p){
    ll res=1;
    while(p){
        if(p&1) res=res*x%mod;
        x=x*x%mod;
        p>>=1;
    }
    return res;
}

ll F2(ll x){
    return mod_pow(x,mod-2);
}

ll F(ll h,ll w){
    return A[h+w-2]*F2(A[h-1])%mod*F2(A[w-1])%mod;
}

int main(){
    for(int i=A[0]=1;i<MAXH+MAXW;i++){
        A[i]=A[i-1]*i%mod;
    }
    ll H,W,A,B,ans=0;
    cin>>H>>W>>A>>B;
    for(int i=B+1;i<=W;i++){
        (ans+=F(H-A,i)*F(A,W-i+1)%mod)%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, l) = listOfInt()
    println(Array(n){next()}.sorted().joinToString(separator = ""))
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const int INF = 1001001001;
const ll mod = 998244353;
const ll INFL = 1001001001001001000;


int main() {
    int n; cin >> n;
    vector<pair<int, int>> p;
    int keyx[n];
    int keyy[n];
    rep(i,n) {
        int x,y; cin >> x >> y;
        x--; y--;
        p.push_back({x,y});
        keyx[x] = i;
        keyy[y] = i;
    }
    sort(all(p));
    dsu d(n);
    set<int> Set;
    Set.insert(p[0].second);
    for (int i = 1; i < n; i++) {
        int ps = p[i].second;
        auto itr = Set.lower_bound(ps);
        if (itr != Set.begin()) {
            vector<int> c;
            while (itr != Set.begin()) {
                itr--;
                int now = (*itr);
                c.push_back(now);
            }
            int m = INF;
            for (auto ci : c) {
                Set.erase(ci);
                d.merge(keyy[ci], keyy[ps]);
                m = min(m,ci);
                //printf("%d\n", ci);
            }
            Set.insert(m);
        } else {
            Set.insert(ps);
        }
    }
    //printf("\n");
    rep(i,n) {
        cout << d.size(i) << endl;
    }
    return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if (c >= a && c <= b){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N,M;
	cin>>N>>M;
	ll ans=N-M+M*19;
	for(int i=0;i<M;i++){
		ans*=2;
	}
	ans*=100;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

x = I()
for i in range(-100, 100):
    for j in range(-100, 100):
        if i ** 5 - j ** 5 == x:
            print(i, j)
            exit()

for k in range(1, 10000):
    for l in range(10000):
        if (l + k) ** 5 - l ** 5 == x:
            print(l + k, l)
            exit()
        if (l + k) ** 5 - l ** 5 > x:
            break






Measured memory_bytes: 83180
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(num,init,name) vector<int> name((num),(init));

int main(){
    int n;
    cin>>n;
    vec(n,0,x);
    vec(n,0,y);
    rep(i,n){
        cin>>x[i];
        y[i]=x[i];
    }
    sort(all(x));
    int k=(n)/2;
    rep(i,n){
        if(y[i]<=x[k-1])cout<<x[k]<<endl;
        else cout<<x[k-1]<<endl;
    }
    return 0;

}


Measured memory_bytes: 3712
using System;

namespace AtCoder
{
	class Programs
	{
		static void Main ()
		{
			var s = Console.ReadLine ();
			int ans = 0;
			for (int i = 0; i < s.Length; i++) {
				if (s [i] == '+')
					ans++;
				else
					ans--;
			}
			Console.WriteLine (ans);
		}
	}
}

Measured memory_bytes: 11092
#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,K; cin>>A>>B>>C>>K;

    while(K--){
        if(A>=B){
            B *=2; continue;
        }
        if(B>=C){
            C *=2; continue;
        }
    }

    if(A<B && B<C){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main()
{
  string s;
  cin >> s;
  
  string com = s;
  reverse(com.begin(),com.end());
  int ans = 0;
  int n = s.size();
  for(int i = 0; i < n/2; i++){
    if(s[i] != com[i]){
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

int bitCount(unsigned int x){
	x = (x>>1 & 0x55555555)+(x & 0x55555555);
	x = (x>>2 & 0x33333333)+(x & 0x33333333);
	x = (x>>4 & 0x0f0f0f0f)+(x & 0x0f0f0f0f);
	x = (x>>8 & 0x00ff00ff)+(x & 0x00ff00ff);
	return (x>>16)+(x & 0x0000ffff);
}

int dp[1024][512];
int main(){
	dp[0][0]=1;
	for(int i=0;i<(1<<10)-1;i++){
		for(int j=0;j<512;j++){
			if(dp[i][j]==0)continue;
			for(int k=0;k<10;k++){
				if(i>>k&1)continue;
				dp[i|1<<k][j+(bitCount(i)+1)*k] += dp[i][j];
			}
		}
	}
	int n,s;
	while(cin>>n>>s){
		if(!n){
			cout<<!s<<endl;
			continue;
		}
		if(512<s){
			cout<<0<<endl;
			continue;
		}
		int ans=0;
		int comb = (1 << n) - 1;
		while (comb < 1 << 10) {
  			int x = comb & -comb, y = comb + x;
  			ans += dp[comb][s];
			comb = ((comb & ~y) / x >> 1) | y;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() {
  int64_t a, b, x;
  cin >> a >> b >> x;
  if (b == 0) {
    cout << 1 << endl;
    return 0;
  }

  if (a == 0) cout << b/x + 1 << endl;
  else cout << b/x - (a-1)/x << endl;
  return 0;
}


Measured memory_bytes: 256
/*令L(i),R(i)表示第i轮过后的最小人数和最大人数。

令X(i)和Y(i)表示区间[L(i),R(i)]中最小的a[i]倍数和最大的a[i]倍数。

L(i-1)=X(i)，R(i-1)=Y(i)+a[i]-1。

X(i)=L(i)/a[i]（上取整），Y(i)=R(i)/a[i]（下取整）。

答案为L(0),R(0)。*/
#include<cstdio>
int n,a[100010];
long long L=2,R=2;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=n;i>=1;i--){
        L=((L-1)/a[i]+1)*a[i];
        R=R/a[i]*a[i]+a[i]-1;
    }
    if(L>R)printf("-1");
    else printf("%lld %lld",L,R);
    return 0;
}

Measured memory_bytes: 512
### main

loop do
  r, c, q = gets.split.map(&:to_i)
  break if (r | c | q) == 0

  rows = []
  cols = []

  orders = q.times.map{gets.split.map(&:to_i)}

  count = 0

  while ! orders.empty?
    ai, bi, oi = orders.pop

    if ai != 0
      if rows[bi].nil?
        rows[bi] = true
        count += r if oi != 0
        c -= 1
      end
    else
      if cols[bi].nil?
        cols[bi] = true
        count += c if oi != 0
        r -= 1
      end
    end
  end

  puts count
end

Measured memory_bytes: 12564
//بسم الله الرحمن الرحيم
//* In The Name 0f ALLAH *//* The Most Beneficent *//* The Most Merciful *//*
#include<bits/stdc++.h>
using namespace std;
#define el << endl
typedef long int li;
typedef long long ll;
typedef long long int lli;
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)


int main()
{
    int a,b;
    cin >> a >> b;
    cout << a*b el;
    //LOL -_-;
    return 0;
}

///////////*  N A Y E M  *///////////

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 1e5+5;

int h[maxn];
int dp[maxn];

int main()
{
	int n, k; scanf("%d %d", &n, &k);
	for(int i = 1; i<= n; i++) scanf("%d", &h[i]);
	dp[n] = 0;
	for(int i = n-1; i>= 1; i--)
	{
		dp[i] = 1e9;
		for(int j = 1; j<= k && i+j<= n; j++)
		{
			dp[i] = min(dp[i], dp[i+j]+abs(h[i]-h[i+j]));
		}
	}
	printf("%d\n", dp[1]);
}

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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	int a, b, c;
	cin >> a >> b >> c;


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



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

	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

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

using namespace std;

int main(){

    long long n, x, y;
    cin >> n;
    cin >> x;
    cin >> y;

    x -= 1;
    y -= 1;

    long long G[n][n];
    for(long long i=0;i<n;i++){
        for(long long j=0;j<n;j++){
            G[i][j] = i<j ? j-i : i-j;
        }
    }
    
    G[x][y] = 1;
    G[y][x] = 1;

    long long res[n];
    for(long long i=0;i<n;i++){
        for(long long j=0;j<n;j++){
            G[i][j] = (G[i][j] < G[i][x]+G[x][j])? G[i][j] : G[i][x]+G[x][j];
            G[i][j] = (G[i][j] < G[i][y]+G[y][j])? G[i][j] : G[i][y]+G[y][j];
        }
        res[i] = 0;
    }

    for(long long i=0;i<n;i++){
        for(long long j=0;j<n;j++){
            G[i][j] = (G[i][j] < G[i][x]+G[x][j])? G[i][j] : G[i][x]+G[x][j];
            G[i][j] = (G[i][j] < G[i][y]+G[y][j])? G[i][j] : G[i][y]+G[y][j];
        }
        res[i] = 0;
    }

    for(long long i=0;i<n;i++){
        for(long long j=0;j<n;j++){
            res[G[i][j]]++;
        }
    }

    for(long long i=1;i<n;i++){
        res[i] /= 2;
        cout << res[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 31488
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long LL;
LL arr[100];

int C(int n, int m) {
	if(n < m) return 0;
	if(m == n) return 1;
	if(m > n - m) m = n - m;
	
	LL ca = 1, cb = 1, ans = 1;
	for(int i = 0; i < m; i++) {
		ca *= n - i;
		cb *= i + 1;
	}
	
	ans = ca / cb;
	return ans;
}
LL CC[51][51];
void comb_table(int N) {
	for(int i = 0; i <= N; ++i) {
		for(int j = 0; j <= i; ++j) {
			if(j == 0 || j == i) {
				CC[i][j] = 1LL;
			}else {
				CC[i][j] = CC[i - 1][j - 1] + CC[i - 1][j];
			}
		}
	}
}
void run() {
	int N, A, B;
	while(cin >> N >> A >> B) {
		for(int i = 1; i <= N; ++i)
			cin >> arr[i];
		comb_table(N);
		sort(arr + 1, arr + 1 + N, std::greater<LL>());
		LL flag, index;
		flag = arr[A];
		LL m = 0, n = 0;
		
		for(int i = 1; i <= N; ++i) {
			if(arr[i] == arr[A]) {
				n++;
				if(i <= A) {
					m++;
				}
			}
		}
		LL sums = 0;
		
		for(int i = 1; i <= A; i++) {
			sums += arr[i];
		}
		
		double mean = 1.0 * sums / A;
		cout.precision(20);
		cout << fixed << mean << endl;
		
		//cout << "n = " << n << " m = " << m << endl;
		LL c = 0LL;
		if(A == m) {
			for(int m = A; m <= B; m++)
				c += CC[n][m];
		}
		else{
			c += CC[n][m];
		}
		
		cout << c << endl;
		
		
	}
}
int main(int argc, char *argv[]) {
	//freopen("data.txt", "r", stdin);
	run();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> grid;
  string whi(w,'.');
  string tmp;
  for(int i=0; i<h; i++){
    cin >> tmp;
    if(tmp==whi){continue;}
    else{grid.push_back(tmp);}
  }
  for(int i=0; i<grid.size(); i++){
    for(int j=0; j<w; j++){
      if(grid.at(i).at(j)=='#'){
        //cout << "debug" << endl;
        whi.at(j)='#';
      }
    }
  }
  //cout << whi << endl;
  for(int i=0; i<grid.size(); i++){
    for(int j=0; j<w; j++){
      if(whi.at(j)=='#'){
        cout << grid.at(i).at(j);
      }
    }
    cout << endl;
  }
  return 0;
}
  

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

int main() { int N; cin >> N; int ans;
 
 if (N % 2 == 0){
      ans = N;
    }
  
 else{
      ans = N * 2;
    }
  
  
   cout << ans << endl;
  return 0;
 
}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
int n, k;

int bit[33], a[maxn], b[maxn];

int main(){
    for(int i=0;i<30;i++)bit[i]=1<<i;
    while(~scanf("%d %d", &n, &k)){
        LL ans=0;
        for(int i=0;i<n;i++){
            scanf("%d%d", &a[i], &b[i]);
            if((a[i]&k)==a[i])ans+=b[i];
        }
        for(int i=0;i<30;i++){
            if(bit[i]&k){   //当前位有1
                int tmp=(bit[i]^k)|(bit[i]-1);
                LL tans=0;
                for(int j=0;j<n;j++){
                    if((a[j]&tmp)==a[j])tans+=b[j];
                }
                ans=max(ans, tans);
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}



Measured memory_bytes: 1152
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>

#define MAX 5000

using namespace std;

void input();

int table[MAX + 1][MAX + 1];
int lose[MAX + 1];
int n, m, w, l;
queue<int> q;

int main() {

	bool yse = false;
	memset(table, 0, sizeof(table));
	input();

	for (int i = 1; i <= n; i++) {

		int t, cnt = 0;
		for (int j = 1; j <= n; j++) {
			if (lose[j] == 0) {
				t = j;
				cnt++;

			}
		}
		if (cnt >= 2) yse = true;
		lose[t] = 5000 + 1;
		q.push(t);
		for (int j = 1; j <= n; j++) if (table[j][t] == -1) lose[j]--;

	}
	for (int i = 0; i < n; i++) {
		int ans = q.front();
		cout << ans << endl;
		q.pop();
	}
	if (yse == true) cout << 1 << endl;
	else cout << 0 << endl;

	//cin >> n;
	return 0;
}

void input() {

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> w >> l;
		table[w][l] = 1;
		table[l][w] = -1;
		lose[l]++;

	}
}



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

int main(void){
    int N;
    vector<ll> a;
    cin >> N;
    rep(i, N){
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    int cnt=0;
    rep(i, N){
        if((a[i] % 2) == 0) continue;
        if((i+1)%2 == 0) continue;
        cnt++;
    }
    cout << cnt << endl;
}

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


void judging(int x, int y)  //start,end
{
    int count = 0;  //count the number of non-leap-year
    for (int j = x; j <= y; j++) {
        if (j % 400 == 0) {
            std::cout << j << std::endl;
        } else if (j % 100 == 0) {
            count++;
        } else if (j % 4 == 0) {
            std::cout << j << std::endl;
        } else {
            count++;
        }
    }
    if (count == y - x + 1) {
        std::cout << "NA" << std::endl;
    }
    return;
}


int main()
{
    std::vector<std::pair<int, int>> year(100);  //start,end(size of vector is temporary)
    int size = 0;                                //current array subscript
    std::cin >> year[size].first >> year[size].second;
    while (year[size].first != 0 || year[size].second != 0) {
        size++;
        std::cin >> year[size].first >> year[size].second;
    }
    for (int i = 0; i < size - 1; i++) {
        judging(year[i].first, year[i].second);
        std::cout << std::endl;
    }
    judging(year[size - 1].first, year[size - 1].second);
    return 0;
}

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


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

    int A[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        sum += x;
        A[i] = x;
    }

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (A[i] >= (float)sum/(4*m)) {
            cnt++;
        }
    }

    if (cnt >= m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

template <typename T>
T ipow(T b, long long e) {
    if (e == 0) {
        return 1;
    } else if (e % 2 == 0) {
        return ipow(b * b, e / 2);
    } else {
        return ipow(b * b, e / 2) * b;
    }
}

template <typename T>
T combination(int n, int r) {
    T ans = 1;
    for (int i = 0; i < r; i++) {
        ans *= n - i;
        ans /= (i + 1);
    }
    return ans;
}

int main() {
    int N, P;
    cin >> N >> P;
    int cntodd = 0, cnteven = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a % 2 == 0)
            cnteven++;
        else
            cntodd++;
    }
    long long ans = 0;
    if (P == 0) {  // 偶数枚食べる
        // 偶数枚の袋を任意の袋数、奇数枚の袋を偶数袋
        for (int i = 0; i <= cntodd; i += 2) {
            ans += combination<long long>(cntodd, i);
        }
    } else {  // 奇数枚食べる
        // 偶数枚の袋を任意の袋数、奇数枚の袋を奇数袋
        for (int i = 1; i <= cntodd; i += 2) {
            ans += combination<long long>(cntodd, i);
        }
    }
    ans *= ipow<long long>(2, cnteven);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>
#include <iomanip>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;


int main(){
    int n;
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> q;
    rep(i,n){
	int temp;
	cin >> temp;
	q.push(temp);
    }
    double ans = 0;
    ans = (double)q.top();
    q.pop();
    while(!q.empty()){
	ans = (double)(ans + q.top())/(double)2;
	q.pop();
    }
    cout << fixed << setprecision(5) << ans << endl;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#define REP(i, a, b) for(int i = a; i < b; i++)

int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int main(void){
    int n,m;
    scanf("%d%d",&n,&m);
    int a[m],b[m],count[n];
    REP(i, 0, m) {
        scanf("%d%d",&a[i],&b[i]);
    }
    REP(i, 0, n) {
        count[i] = 0;
    }
    REP(i, 0, m) {
        count[a[i] - 1]++;
        count[b[i] - 1]++;
    }
    REP(i, 0, n) {
        printf("%d\n",count[i]);
    }
    return 0;
}

Measured memory_bytes: 128
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int N, count, ans = 0 ;
  cin >> N ;
  if(N < 600){
    cout << 8 << endl ;
  }  
  else if(N < 800){
    cout << 7 << endl ;
  }  
  else if(N < 1000){
    cout << 6 << endl ;
  }  
  else if(N < 1200){
    cout << 5 << endl ;
  }  
  else if(N < 1400){
    cout << 4 << endl ;
  }  
  else if(N < 1600){
    cout << 3 << endl ;
  }  
  else if(N < 1800){
    cout << 2 << endl ;
  }  
  else{
    cout << 1 << endl ;
  }  
  return 0 ;
}  

Measured memory_bytes: 3628
s = list(raw_input())
count = 0
i,j = len(s), len(s)
# traverse to find b with i,
# j indicates the right continuous B, which menas that s[j-1]=W and s[j:] will be B
while j-1>=0 and s[j-1] == 'B': 
    j -= 1
#s[j-1] will be 'W'
i = j -1
while i>=0:
    ## 
    while i>=0 and s[i] == 'W': i-=1
    # find a 'B', then switch i, j-1
    if i>=0:
        count += (j-i-1)
        s[i],s[j-1] = s[j-1],s[i] #BW to WB
    # *BWWWWBBBB  *WWWWBBBBB
    j -= 1
    i -= 1
print(count)

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int a;
cin>>a;
cout<<a+pow(a,2)+pow(a,3)<<endl;
return  0;
}






Measured memory_bytes: 4212
#include<stdio.h>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(b==1)
		printf("0\n");
	else
	{
		if(b<=a)
		{
			printf("1\n");
		}
		else
		{
			b-=a;
			if(b%(a-1)==0)
				printf("%d\n",b/(a-1)+1);
			else
			{
				printf("%d\n",b/(a-1)+2);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> submit = new ArrayList<Integer>();
			for (int i = 0; i < 28; i++) {
				submit.add(sc.nextInt());
			}

		int cnt = 2;
		for (int i = 1; i <= 30 && cnt > 0; i++) {
			if (!submit.contains(i)) {
				System.out.println(i);
				cnt--;
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 26148
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemA solver = new ProblemA();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int x = in.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
			}
			Arrays.sort(a);
			int ans = 0;
			for (int i = 0; i < n; i++) {
				int t = Math.min(x, a[i]);
				if (i == n - 1) {
					t = x;
				}
				x -= t;
				if (t == a[i]) {
					++ans;
				}
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



Measured memory_bytes: 22740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Long.parseLong;
import static java.lang.Integer.parseInt;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = parseInt(in.readLine());
      long[] seq = new long[n];

      for(int i=0; i<n; i++)
        seq[i] = parseLong(in.readLine());

      Arrays.parallelSort(seq);

      long[] resU = new long[n];  // /\/\Pattern
      long[] resD = new long[n];  // \/\/Pattern

      int l = n-1;
      resU[0] = -1;
      resD[0] =  1;
      for(int i=1; i<l; i++) {
        resU[i] = (i&1) == 0 ? -2 :  2;
        resD[i] = (i&1) == 0 ?  2 : -2; 
      }
      resU[l] = (n&1) == 0 ?  1 : -1;
      resD[l] = (n&1) == 0 ? -1 :  1;

      Arrays.parallelSort(resU);
      Arrays.parallelSort(resD);

      long sumU=0,sumD=0;
      for(int i=0; i<n; i++) {
        sumU += seq[i] * resU[i];
        sumD += seq[i] * resD[i];
      }

      System.out.println(Math.max(sumU, sumD));
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 36612
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    else:
        tmp = 7
        digits = 1
        while tmp % k != 0:
            tmp = (tmp * 10 + 7) % k
            digits += 1
        print(digits)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8972
a1_list = list(map(int, input().split()))
a2_list = list(map(int, input().split()))
a3_list = list(map(int, input().split()))
a1_list.extend(a2_list)
a1_list.extend(a3_list)

n = int(input())
nums = []
for _ in range(n):
  x = int(input())
  nums.append(x)
  
result = "No"
patterns = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
for p in patterns:
  if a1_list[p[0]] in nums and a1_list[p[1]] in nums and a1_list[p[2]] in nums:
    result = "Yes"
    break
print(result)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (n, t) = readLine()!!.split(' ').map { it.toInt() }
    val xs = readLine()!!.split(' ').map { it.toInt() }

    var cnt = 0
    var min = xs.first()
    var max = xs.first()
    var profit = 0

    for (a in xs.slice(1..xs.lastIndex).plus(-1)) {
        if (a < min) {
            val p = max - min

            if (p == profit) {
                cnt++
            } else if (p > profit) {
                cnt = 1
                profit = p
            }

            min = a
            max = a
        }
        max = Math.max(max, a)
    }

    println(cnt)
}


Measured memory_bytes: 51736
#include<stdio.h>
int main()
{
    int A,B;
    int K;
    scanf("%d %d",&A,&B);
    //K=(A+B)/2;
    if(((A%2==1) && (B%2==0)) || ((B%2==1) &&(A%2==0)))

        {printf("IMPOSSIBLE");}
    else

            {K=(A+B)/2;
            printf("%d",K);}
    return 0;
}


Measured memory_bytes: 1696
#include <iostream>
#include <vector>
#include <algorithm>

int main(void){

	int N, lowwer, upper;
	double a;
	std::vector<double> gpa, s;

	std::cin >> N;

	for(int i=0; i<N; i++){
		std::cin >> a;
		gpa.push_back(a);
		s.push_back(gpa[i]);
	}
	std::sort(s.begin(), s.end());

	for(int i=0; i<N; i++){
		lowwer = std::lower_bound(s.begin(), s.end(), gpa[i]) - s.begin();
		upper = std::upper_bound(s.begin(), s.end(), gpa[i])
			    - std::lower_bound(s.begin(), s.end(), gpa[i]) - 1;

		std::cout << lowwer*3 + upper << std::endl;
	}

	return 0;
}



Measured memory_bytes: 4648
s=input()
q=int(input())
for i in range(q):
    a=input().split()

    if a[0]=="replace":
        tmp=str()
        for j in range(0,int(a[1])):
            tmp+=s[j]
        tmp+=a[3]
        for j in range(int(a[2])+1,len(s)):
            tmp+=s[j]
        s=tmp

    elif a[0]=="reverse":
        tmp=str()
        for j in range(0,max(0,int(a[1]))):
            tmp+=s[j]
        for j in reversed(range(int(a[1]),int(a[2])+1)):
            tmp+=s[j]
        for j in range(int(a[2])+1,len(s)):
            tmp+=s[j]
        s=tmp

    else:
        ans=str()
        for j in range(int(a[1]),int(a[2])+1):
            ans+=s[j]
        print(ans)



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll h[200010];

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    rep(i, n){
        cin >> h[i];
    }
    sort(h, h + n);
    reverse(h, h + n);
    rep(i, n){
        if (i < k) continue;
        else ans += h[i];
    }

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


Measured memory_bytes: 5096
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    cin >> N;
    vi data(N);
    for (int i = 0; i < N; i++) {
        cin >> data[i];
    }
    int ans = 0;
    int num = 1;
    for (int i = 0; i < N; i++) {
        if (data[i] == num) {
            num++;
        }
        else {
            ans++;
        }
    }
    if (num == 1) {
        ans = -1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4020
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<ll> T(N);
    for(int i=0; i<N; i++) cin >> T[i];
    vector<ll> A(N); 
    for(int i=0; i<N; i++) cin >> A[i];

    vector<bool> Tsure(N,false);
    vector<bool> Asure(N,false);
    Tsure[0] = true;
    Asure[N-1] = true;
    for(int i=1; i<N; i++) {
        if(T[i] > T[i-1]) Tsure[i] = true;
    }
    for(int j=N-2; j>=0; j--) {
        if(A[j] > A[j+1]) Asure[j] = true;
    }

    ll ans = 1;
    for(int i=0; i<N; i++) {
        if(Tsure[i] == true && Asure[i] == true) {
            if(T[i] != A[i]) {
                cout << 0 << endl;
                return 0;
            }
        } else if(Tsure[i] == true) {
            if(T[i] > A[i]) {
                cout << 0 << endl;
                return 0;
            }
        } else if(Asure[i] == true) {
            if(T[i] < A[i]) {
                cout << 0 << endl;
                return 0;
            }
        } else {
            ans *= min(T[i],A[i]);
            ans %= mod;
        }
    }

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

Measured memory_bytes: 1792
#include<iostream>
#include<cinttypes>

int main() {
	std::uint32_t a, b;
	std::cin >> a >> b;

	auto p = [](auto x) {
		for (int i{}; i < 32; ++i) {
			int index = 31 - i;
			std::cout << ( x >> index & 1 ? 1 : 0);
		}std::cout << "\n";
	};

	p(a&b);
	p(a|b);
	p(a ^ b);
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n, m;
	cin>>n>>m;
	vi x(n);
	map<int,int> mp;
	rep(i, n){
		cin>>x[i];
		mp[x[i]]++;
	}
	vi v(1e5+10), p(1e5+10);
	for(auto i : mp){
		v[i.fi%m]+= i.se;
		p[i.fi] = i.se / 2;
	}
	// rep(i, 10){
	// 	cout<<" "<<i<<" "<<v[i]<<endl;
	// }
	int ans = 0;
	for(int i = 1; i < m / 2; i++){
		int k = min(v[i], v[m-i]);
		//cout<<"  "<<i<<"  "<<k<<endl;
		ans += k;
		v[i] -= k;
		v[m-i] -= k;
	}
	if(m % 2 == 0){
		ans += v[m/2]/2;
		v[m/2] = 0;
	}
	else{
		int k = min(v[m/2], v[m-m/2]);
		ans += k;
		v[m/2] -= k;
		v[m-m/2] -= k;
	}
	ans += v[0]/2;
	v[0] = 0;
	rep(i, 1e5 + 10){
		if(p[i] > 0 && v[i % m] >= 2){
			int k = min(p[i], v[i % m] / 2);
			ans += k;
			v[i % m] -= k * 2;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;
typedef pair<int, int> ii;

int n;

const int MOD = (int)1e9 + 7;
long long seg[800002];
int heigth[200004], beauty[200002];


long long upt;
void update(int idx, int l, int r, int index = 1) {

    if(l == r) {
        seg[index] = upt;
        return;
    }
    // cout << idx << " " << l << " " << r << "\n";

    int mid = (l+r)>>1;

    if(idx <= mid) {
        update(idx, l, mid, 2*index);
    } else {
        update(idx, mid + 1, r, 2*index + 1);
    }
    seg[index] = max(seg[2*index], seg[2*index + 1]);
}

long long getMax(int L, int l, int r, int index = 1) {
    if(L > r) return 0;
    if(l == r) {
        return seg[index];
    }
    int mid = (l + r)>>1;

    long long cur = 0;
    if(L <= mid) {
        cur = getMax(L, l, mid, 2*index);
    } else {
        return getMax(L, mid + 1, r, 2*index + 1);
    }
    return max(cur, seg[2*index + 1]);
}

int main() {
    cin >> n;
    

    for(int i = 0; i < n; ++i) cin >> heigth[i+1];

    for(int i = 0; i < n; ++i) cin >> beauty[i+1];

    for(int i = n; i > 0; --i) {
        long long cc = getMax(heigth[i] + 1, 1, n);
        cc += beauty[i];
        upt = cc;
        update(heigth[i], 1, n);
    }

    cout << seg[1];

}

Measured memory_bytes: 6400
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

int main() {

	const int N = read_item();
	vector<int> As(N + 1);
	for(auto i : range(N + 1)) {
		As[i] = read_item();
	}

	i64 total = 0;

	for(auto a : As) {
		total += a;
	}

	i64 ans = 0;
	i64 cur = 1;
	i64 rem = total;

	for(auto depth : range(N + 1)) {

		auto a = As[depth];
		rem = rem - a;

		dbg(depth, a, rem, ans, cur);

		ans += cur;
		if(cur < a) {
			ans = -1;
			break;
		}
		cur = min((cur - a) * 2, rem);
	}

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

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

int n;
ll a[100009], t[100009];
bool ba[100009], bt[100009];

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

    cin >> n;

    rep(i, n) {
        cin >> a[i];
        if(!i || a[i - 1] < a[i]) ba[i] = true;
    }
    rep(i, n) cin >> t[i];
    FORR(i, n) if(t[i] > t[i + 1]) bt[i] = true;

    ll ans = 1;

    rep(i, n) {
        if(ba[i] && bt[i])
            ans *= (a[i] == t[i]);
        else if(ba[i])
            ans *= (a[i] <= t[i]);
        else if(bt[i])
            ans *= (t[i] <= a[i]);
        else
            ans = ans * min(t[i], a[i]) % mod;
    }

    cout << ans << endl;

    return 0;
}

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

#define MAX 5002

int n;

vector<pair<int, int> > v;

bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first + a.second < b.first + b.second;
}
long long int dp[MAX][MAX];

int main() {
	cin >> n;	
	for (int i = 0; i < n; i++) {
		int h, p;
		scanf("%d%d", &h, &p);
		v.push_back(make_pair(h, p));
	}
	sort(v.begin(), v.end(), cmp);
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	int mx = 0;
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j <= i; j++) {
			if (dp[i][j] == -1)continue;
			if (dp[i + 1][j] == -1 || dp[i + 1][j] > dp[i][j]) {
				dp[i + 1][j] = dp[i][j];
				mx = max(mx, j);
			}
			if (dp[i][j] <= v[i].first) {
				long long int nex = dp[i][j] + v[i].second;
				if (dp[i + 1][j+1] == -1 || dp[i + 1][j+1] > nex) {
					dp[i + 1][j + 1] = nex;
					mx = max(mx, j + 1);
				}
			}
		}
	}
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 195840
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	bool d=false;
	REP(i,n+1) {
		REP(j,m+1) {
			if(i*j+(n-i)*(m-j)==k) d=true;
		}
	}
	if(d) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]
ab.sort(key=lambda x:x[1])
ans=[[ab[0][1]-1,ab[0][1]]]
ab.pop(0)
for i in range(m-1):
    if ans[-1][0]>=ab[i][0]:
        continue
    else:
        ans.append([ab[i][1]-1,ab[i][1]])
print(len(ans))

Measured memory_bytes: 64600
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vs=vector<string>;
using vvi =vector<vector<int>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
int main(){
    int n,m;
    cin>>n>>m;
    vector<P>ab(n);
    rep(i,n)cin>>ab[i].first>>ab[i].second;
    sort(ab.begin(),ab.end());
    ll ans=0;
    rep(i,n){
        
        if(m-ab[i].second<=0){
            ans+=(ll)ab[i].first*m;
            break;
        }
        else ans+=(ll)ab[i].first*ab[i].second;
        m-=ab[i].second;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;


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

    double S = 0.5 * a * b * sin(C*M_PI/180);
    double c = sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*cos(C*M_PI/180));
    double L = a + b + c;
    double h = 2*S/a;

    printf("%f\n", S);
    printf("%f\n", L);
    printf("%f\n", h);

    return 0;
}




Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

long long dp[3001][3001][4];
long long v[3001][3001];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R, C, K;
    cin >> R >> C >> K;
    for(int i = 0; i < R + 1; i++)
        for(int j = 0; j < C + 1; j++)
            v[i][j] = 0;
    for(int i = 0; i < K; i++) {
        int r, c;
        cin >> r >> c;
        cin >> v[r][c];
    }
    for(int i = 0; i < R + 1; i++) {
        for(int j = 0; j < C + 1; j++) {
            for(int k = 0; k <= 3; k++) {
                dp[i][j][k] = 0;
            }
        }
    }
    for(int i = 1; i < R + 1; i++) {
        for(int j = 1; j < C + 1; j++) {
            for(int k = 0; k <= 3; k++) {
                dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]);
                if(v[i][j] > 0)
                    dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][k] + v[i][j]);
                dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
                if(k > 0 && v[i][j] > 0)
                    dp[i][j][k] =
                        max(dp[i][j][k], dp[i][j - 1][k - 1] + v[i][j]);
            }
        }
    }
    long long ans = 0;
    for(int k = 0; k <= 3; k++)
        ans = max(ans, dp[R][C][k]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 355320
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> vi;
	for(int i=0;i<n-1;i++)
	{
		int a;
		cin>>a;
		vi.push_back(a);
	}
	int sum = 0;
	for(int i=0;i<vi.size()-1;i++)
	{
		if(i == 0)
		{
			sum+=vi[0];
			sum+=min(vi[0],vi[1]); 
		}
		else
			sum+=min(vi[i],vi[i+1]);
	}
	if(vi.size() == 1)
	{
		cout<<vi[0]*2<<endl;
		return 0;
	}
	sum+=vi[vi.size()-1];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto N = readln.chomp.to!int;
    int[] cs, ss, fs;
    foreach (i; 0..N-1) {
        int C, S, F;
        readf("%d %d %d\n", &C, &S, &F);
        cs ~= C;
        ss ~= S;
        fs ~= F;
    }
    foreach (i; 0..N-1) {
        long t = 0;
        foreach (j; i..N-1) {
            t = max(t, ss[j]);
            t += (fs[j] - t % fs[j]) % fs[j];
            t += cs[j];
        }
        writeln(t);
    }
    writeln(0);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n, a, x[100], dp[60][60][6000];
//[maisuu][dokomade][kazu]
int main(void){
    cin >> n >> a;
    for(int i=0;i<60;++i) for(int j=0;j<60;++j) for(int k=0;k<6000;++k) dp[i][j][k] = 0;
    for(int i=0;i<n;++i) cin >> x[i+1];
    long long cnt = 0;
    dp[0][0][0] = 1;
    for(int i=0;i<=n;++i){
        for(int j=1;j<=n;++j){
            for(int k=0;k<6000;++k){
                if(i >= 1 && k-x[j] >= 0) dp[i][j][k] += dp[i-1][j-1][k-x[j]];
                dp[i][j][k] += dp[i][j-1][k];
            }
        }
    }
    for(int i=1;i<=n;++i) cnt += dp[i][n][a*i];
    cout << cnt << endl;
}

Measured memory_bytes: 168960