akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  for(int i = 0; i < H; ++i) cin >> S[i];
  vector<vector<int>> cs(H+1,vector<int>(W+1));
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      cs[i+1][j+1] += S[i][j] - '0';
      cs[i+1][j+1] += cs[i+1][j];
    }
  }
  for(int i = 0; i < H; ++i)
    for(int j = 0; j <= W; ++j)
      cs[i+1][j] += cs[i][j];
  auto sum = [&](int t, int b, int l, int r){
               return cs[b][r] - cs[b][l] - cs[t][r] + cs[t][l];
             };
  int ans = 1e9;
  for(int i = 0; i < (1<<(H-1)); ++i){
    vector<int> B(1,0);
    for(int j = 0; j < H; ++j)
      if(i>>j&1) B.push_back(j+1);
    B.push_back(H);
    int cnt = B.size()-2;
    int l = 0;
    for(int r = 0; r < W; ++r){
      bool f = false;
      for(size_t j = 1; j < B.size(); ++j){
        if(f) break;
        int t = B[j-1], b = B[j];
        if(sum(t,b,l,r+1) > K){
          l = r;
          ++cnt;
          f = true;
          if(sum(t,b,l,r+1) > K){
            cnt = 1e9;
            break;
          }
        }
      }
      if(cnt >= 1e9) break;
    }
    // cerr << i << " " << cnt << endl;
    ans = min(ans,cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
"""
制約がヒントっぽいな。
桁DPで解ける

dp[i][j][k] => 2進数表記でa+bの左からi桁目まで見る。i桁目がjになるような場合の数。kは未満フラグ。配るDPで解く。

"""
L = input()
N = len(L)
mod = 10**9 +7
dp = [[[0]*2 for _ in range(2)]for _ in range(N)]
dp[0][1][0] = 2
for i in range(1,N):
    dp[i][1][1] = 2

for i in range(N-1):
    x = int(L[i+1])
    for j in range(2):
        for k in range(2):
            for l in range(2):
                if not k and l > x:
                    continue
                if k or l < x:
                    nxFlag = 1
                else:
                    nxFlag = 0
                if l == 0:
                    dp[i+1][l][nxFlag] += dp[i][j][k]
                else:
                    dp[i+1][l][nxFlag] += dp[i][j][k]*2
                dp[i+1][l][nxFlag]%=mod
ans = (sum(dp[-1][1])+sum(dp[-1][0])+1)%mod
print(ans)

Measured memory_bytes: 101776
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;



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

	cin >> N;
	map<string, priority_queue<int,vector<int>,greater<int>>>PQ;
	while (N--) {
		string s;
		cin >> s >> M;
		PQ[s].push(M);
	}
	cin >> M;
	int bef = 0;
	while (M--) {
		string s;
		cin >> s;
		while (!PQ[s].empty() && PQ[s].top() <= bef)PQ[s].pop();
		if (PQ[s].empty()) {
			cout << "No\n";
			return 0;
		}
		bef = PQ[s].top();
		PQ[s].pop();
	}
	cout << "Yes\n";
}


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

using namespace std;

int main()
{
    long long int n, w, v1, v2;

    vector<long long int> val, wt;

    cin >> n >> w;

    long long int dp[n + 1][w + 1];

    for (int i = 0; i < n; i++)
    {
        cin >> v1 >> v2;
        wt.push_back(v1);
        val.push_back(v2);
    }

    for (int i = 0; i < n + 1; i++)
    {
        for (int j = 0; j < w + 1; j++)
        {
            if (i == 0 || j == 0)
            {
                dp[i][j] = 0;
            }
            else if (wt[i - 1] <= j)
            {
                dp[i][j] = max(val[i-1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    // for(auto &x : dp) {
    //     for(int &y : x) {
    //         cout<<y<<" ";
    //     }
    //     cout<<endl;
    // }

    cout<<dp[n][w];

    return 0;
}

Measured memory_bytes: 82268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << max({a * c, a * d, b * c, b * d}) << endl;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if(s=="keyence") {cout << "YES" << endl; return 0;}
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= s.size(); ++j) {
            string temp = s;
            temp.erase(i,j);
            if(temp=="keyence"){
                cout << "YES" << endl;
                return 0;
            } 

        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int[][] count = new int[n][n];
			int[][] data = new int[n][n];
			
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					data[i][j] = sc.nextInt();
				}
			}
			
			for(int i = 0; i < n; i++){
				int min = Integer.MAX_VALUE;
				
				for(int j = 0; j < n; j++){
					if(min > data[i][j]){
						min = data[i][j];
					}
				}
				
				for(int j = 0; j < n; j++){
					if(min == data[i][j]){
						count[i][j]++;
					}
				}
			}
			
			for(int i = 0; i < n; i++){
				int max = Integer.MIN_VALUE;
				
				for(int j = 0; j < n; j++){
					if(max < data[j][i]){
						max = data[j][i];
					}
				}
				
				for(int j = 0; j < n; j++){
					if(max == data[j][i]){
						count[j][i]++;
					}
				}
			}
			
			//System.out.println(Arrays.deepToString(count));
			
			int max = Integer.MIN_VALUE;
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					if(count[i][j] >= 2 && max < data[i][j]){
						max = data[i][j];
					}
				}
			}
			
			if(max == Integer.MIN_VALUE){
				System.out.println(0);
			}else{
				System.out.println(max);
			}
		}

	}

}

Measured memory_bytes: 19424
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;

int main(){
  string str;
  while(cin >> str){
    string num[3] = {"","",""};
    int idx = 0;
    for(int i=0;i<str.size();i++){
      if(str[i] == '+' || str[i] == '=') idx++;
      else {
	num[idx] += str[i];
      }
    }
    int l1=num[0].size(),l2=num[1].size();
    if(l1<l2)swap(l1,l2),swap(num[0],num[1]);
    int flg = false;
    for(char c='0';c<='9';c++){
      if(c == '0'){
	if(num[0].size() > 1 && num[0][0] == 'X') continue;
	if(num[1].size() > 1 && num[1][0] == 'X') continue;
	if(num[2].size() > 1 && num[2][0] == 'X') continue;
      }
      string tmp[3] = {"","",""};
      for(int i=0;i<3;i++){
	for(int j=0;j<num[i].size();j++){
	  if(num[i][j] == 'X') tmp[i] += c;
	  else tmp[i] += num[i][j];
	}
      }
      for(int i=l1-1,j=l2-1;i>=0;i--,j--){
	if(j>=0) tmp[0][i]+=tmp[1][j]-'0';
	if(tmp[0][i]>'9'){
	  tmp[0][i]-=10;
	  if(i==0)tmp[0]="1"+tmp[0];
	  else tmp[0][i-1]++;
	}
      }
      if(tmp[0] == tmp[2]){
	cout << c << endl;
	flg = true;
	break;
      }
    }
    if(!flg) cout << "NA" << endl;
  }
}

Measured memory_bytes: 1192
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        long K = scanner.nextLong();

        long MOD = 7L % K;
        long R = 1L;

        HashSet<Long> C = new HashSet<>();
        while(MOD != 0L){
            MOD = ((MOD * 10) % K + 7L) % K;
            if (C.contains(MOD)){
                System.out.println(-1);
                return;
            }
            C.add(MOD);
            R++;
        }

        System.out.println(R);
    }

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


Measured memory_bytes: 134144
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    long long a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    long long half_a = a >> 1, half_b = b >> 1, half_c = c >> 1;
    long long ans = a * b * abs((c - half_c) - half_c);
    ans = min(ans, b * c * abs(half_a - (a - half_a)));
    ans = min(ans, c * a * abs(half_b - (b - half_b)));
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>


using namespace std;

int main() {
    string s;
    int n,q,i,dp[1000000];
    cin>>n>>q;
    cin>>s;
    int l[q],r[q];
    for(i=0;i<=q-1;i++){
        cin>>l[i]>>r[i];
    }
    for(i=0;i<=n-1;i++){
        if(i==0){
            dp[i]=0;
        }else if(i==1){
            if(s[i-1]=='A' && s[i]=='C'){
                dp[i]=1;
            }else{
                dp[i]=dp[i-1];
            }
        }else{
            if(s[i-1]=='A' && s[i]=='C'){
                dp[i]=dp[i-2]+1;
            }else{
                dp[i]=dp[i-1];
            }
        }
    }
    for(i=0;i<=q-1;i++){
        cout<<dp[r[i]-1]-dp[l[i]-1]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int inf=1e9+7;
signed main(){
    int n,m,v,p,a[100000];
    cin>>n>>m>>v>>p;
    map<int,int>mp;
    for(int i=0;i<n;i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(a,a+n);
    vector<int>V;
    for(auto&x:mp)
        V.push_back(x.first);
    int lb=-1,ub=V.size()-1;
    while(ub-lb>1){
        int mid=(lb+ub)/2;
        int tmp=V[mid];
        int k=upper_bound(a,a+n,tmp)-a-1;
        int b=n-p;
        int M=v-p-k;
        int sum=0;
        bool ok=1;
        for(int i=k+1;i<=b;i++){
            sum+=tmp-a[i]+m;
            if(tmp-a[i]+m<0)
                ok=0;
        }
        bool c=M*m<=sum||n-p<=k;
        (c&&ok?ub:lb)=mid;
    }
    int ans=0;
    for(int i=0;i<n;i++)
        if(a[i]>=V[ub])
            ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 8444
X, Y = map(int,input().split())

def get_money(X):
    if X == 1:
        return 300000
    elif X == 2:
        return 200000
    elif X == 3:
        return 100000
    else:
        return 0

def double_money(X, Y):
    if X == 1 and Y == 1:
        return 400000
    else:
        return 0

sum = get_money(X) + get_money(Y) +double_money(X, Y)

print(sum)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
int main()
{
    long N;
    std::cin >> N;
    std::vector<long> A;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        A.push_back(temp);
    }
    long rnow=-1;
    long bnow=-1;
    long gnow=-1;
    long result=1;
    for(long i=0; i<N; i++){
        long kouho=0;
        if(A[i]==rnow+1){
            kouho++;
        }
        if(A[i]==bnow+1){
            kouho++;
        }
        if(A[i]==gnow+1){
            kouho++;
        }
        if(A[i]==rnow+1){
            rnow++;
        }else{
            if(A[i]==bnow+1){
                bnow++;
            }else{
                if(A[i]==gnow+1){
                    gnow++;
                }else{
                    kouho=0;
                }
            }
        }
        result=result*kouho;
        result=result%1000000007;
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 1400
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
void dbg_out(){
	cerr<<endl;
}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){
	cerr<<' '<< H; 
	dbg_out(T...);
}

int main(){
	cin.tie(0),cin.sync_with_stdio(0),cout.tie(0),cout.sync_with_stdio(0);
	int n, k, ans;
	cin>>n>>k;
	ans=n;
	set<int> s;
	for(int i=0;i<k;i++){
		int x;
		cin>>x;
		for(int j=0;j<x;j++){
			int y;
			cin>>y;
			s.insert(y);
		}
	}
	cout<<n-(int)s.size();
}


Measured memory_bytes: 3620
def isCLKWISE(ph):
    return (ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) >= 0
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = []
for i in n:
    P.append([int(x) for x in input().split()])
      
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

Measured memory_bytes: 33824
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int c[3005][3005],s[3005][3005],p2[3000*3000+5],pp2[3005];
int main(){
	int n,p;
	scanf("%d%d",&n,&p);
	for(int i=0;i<=n;i++)
		for(int j=0;j<=i;j++)
			c[i][j]=(!j||j==i?1:c[i-1][j-1]+c[i-1][j])%p;
	s[0][0]=1;
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=i;j++)
			s[i][j]=(1ll*j*s[i-1][j]+s[i-1][j-1])%p;
	p2[0]=1; 
	for(int i=1;i<=n*n;i++)p2[i]=p2[i-1]*2%p;
	pp2[0]=2;
	for(int i=1;i<=n;i++)pp2[i]=1ll*pp2[i-1]*pp2[i-1]%p;
	int ans=0;
	for(int i=0;i<=n;i++){
		int res=0;
		for(int j=0;j<=i;j++)res=(res+1ll*s[i+1][j+1]*p2[(n-i)*j])%p;
		// printf("%d\n",res);
		ans=((ans+(i&1?-1ll:1ll)*c[n][i]*res%p*pp2[n-i])%p+p)%p;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 105856
// g++ -std=gnu++1y -O2 xxx.cpp

#include <bits/stdc++.h>
//#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,l,r)for(int i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31)) /*オーバーフローしない程度に大きい数*/
#define MOD 1000000007

int main() {
    int N,K; cin>>N>>K;
    vector<int> h(N+1);
    rep(i,1,N+1) cin>>h[i];
    
    int dp[N+1];
    memset(dp, 0, sizeof(dp));

    int ans;
    rep(i,2,N+1) {
        dp[i]=dp[i-1]+abs(h[i-1]-h[i]);
        rep(j,2,K+1) if(i-j>=1) dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
    }
    ans=dp[N];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
  double x[3], y[3]; double l[3], sum=0;
  rep(i,3) cin>>x[i]>>y[i];
  rep(i,3) l[i] = pow((x[(i+1)%3]-x[i]),2)+pow((y[(i+1)%3]-y[i]),2), l[i] = pow(l[i],0.5), sum+=l[i], cerr<<l[i] << ' ';
  cerr << endl;
  double s = 1.0/2.0*((x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0]));
  if(s<0) s = -s;
  cerr << s << endl;
  double r = 2*s/sum;
  cerr << r << endl;
  sort(l,l+3);
  double ans = r*l[2]/(2*r+l[2]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  multiset<int> s;
  set<int> se;
  int c=0;
  rep(i,n){
    cin >> a[i];
    s.insert(a[i]);
    se.insert(a[i]);
  }
  for(auto i : se){
    //    cout << i << endl;
    if(s.count(i)%2==0){
      c++;
    }
  }
  //  sort(a,a+n);
  //  rep(i,n) cout << a[i] << " ";
  //  cout << c << endl;
  cout << se.size() - (c%2) << endl;

  
  
  return 0;
    

}


Measured memory_bytes: 9984
n = int(input())
a_lst = list(map(int, input().split(" ")))

have_money = 1000
have_stack = 0

next_index = 1  # 高くなる波のスタートのindex
# 最初
# 高くなる波が来る前の中で一番安い日に買う
most_cheap = a_lst[0]
for i in range(1, n):
    if a_lst[i] > most_cheap:
        have_stack = have_money // most_cheap
        have_money = have_money % most_cheap
        break
    if i >= n:
        next_index += 1
        break
    most_cheap = a_lst[i]
    next_index += 1

# した二つを繰り返す
while next_index < n:
    # 高くなる波の中で一番高いところで売る
    most_expensive = a_lst[next_index]
    while next_index < n:
        if a_lst[next_index] < most_expensive or next_index == n - 1:
            have_money += have_stack * most_expensive
            have_stack = 0
            break
        most_expensive = a_lst[next_index]
        next_index += 1
    if next_index >= n - 1:
        break

    most_cheap = a_lst[next_index]
    while next_index < n:
        if a_lst[next_index] > most_cheap:
            have_stack = have_money // most_cheap
            have_money = have_money % most_cheap
            break
        most_cheap = a_lst[next_index]
        next_index += 1

print(have_money)


# 安くなる波の中で一番安い時に買う



Measured memory_bytes: 9096
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var A = cin.ReadLongArray(N);
			Console.WriteLine(A.LIS());
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		public static int LIS(this long[] X) {
			var minLast = new List<long>();
			foreach(var x in X) {
				var j = minLast.BinarySearch(x);
				if(j<0) {
					if((~j)>=minLast.Count) minLast.Add(x);
					else minLast[~j]=x;
				}
			}
			return minLast.Count;
		}
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}

}


Measured memory_bytes: 22720
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long x = in.nextLong();

            if (a == 0) {
                out.println(b / x + 1);
            } else {
                out.println(b / x - (a - 1) / x);
            }
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

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

    }

}


Measured memory_bytes: 30164
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long int n,arr[200001];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    if(n%2==0){
    for(int i=n-1;i>=0;i-=2)
        cout<<arr[i]<<" ";
    for(int i=0;i<n;i+=2)
        cout<<arr[i]<<" ";
    cout<<endl;
    }
    else
    {
        for(int i=n-1;i>=0;i-=2)
            cout<<arr[i]<<" ";
        for(int i=1;i<n;i+=2)
            cout<<arr[i]<<" ";
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<int, int> P;



int main() {
	int A, B;
	string S;
	cin >> A >> B >> S;
	rep(i, A) {
		if (S.at(i) < '0' || S.at(i) > '9') { 
			cout << "No" << endl;
			return 0;
		}
	}
	if (S.at(A)!='-')
	{
		cout << "No" << endl;
		return 0;
	}

	for (int i = A+1; i < S.size(); i++)
	{
		if (S.at(i) < '0' || S.at(i) > '9') {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 3628
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<math.h>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>
// 追加１
#include <fstream>



using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

    set<string> x;

    rep(i, N)
    {
        string s;
        cin >> s;

        x.insert(s);
    }

    cout << x.size() << endl;

    return 0;
}

Measured memory_bytes: 19228
import java.awt.*;
import java.util.*;
public class Main {
    Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        new Main().run();
    }
    void run() {
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] l = new int[n];
        for(int i = 0; i < n; ++i) {
            l[i] = sc.nextInt();
        }
        int a = 0;
        int c = 1;
        for (int j = 0; j < n; j++) {
            a += l[j];
            if (a <= x) {
                c++;
            }
        }
        System.out.println(c);
    }
}


Measured memory_bytes: 36032
x = int(input())

def sosu(x):
    sw = 1
    for i in range(x):
        amr = x % (i + 1)
    
        if 1 < (i + 1) < x: #１より大きい数で割ったとき
            if amr == 0: #余り０
                sw = 0
    return sw

while sosu(x) ==0:
    x += 1

print(x)


Measured memory_bytes: 2940
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a_vec: [i64; n],
    };

    let mut ans: i64 = 0;
    for i in 1..n {
        let dif = a_vec[i - 1] - a_vec[i];
        if dif > 0 {
            ans += dif;
            a_vec[i] += dif;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5492
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void d_m_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

char grid[1002][1002];

int power(int n, int x)
{
	if (x == 0)
		return 1;

	int small = power(n, x / 2) % mod;
	small = (small * small) % mod;

	if (1 & x)
		small = (n * small) % mod;

	return small;
}

bool isPowerOfTwo(int n)
{
	return n && (!(n & (n - 1)));
}

string solve(int *stones, int n, int k)
{
	bool dp[k + 1];
	memset(dp, 0, sizeof dp);

	for (int i = 1; i <= k; i++)
	{
		for (int move = 1; move <= n; move++)
			if (i - stones[move] >= 0)
				if (dp[i - stones[move]] == 0)
					dp[i] = 1;
	}

	if (dp[k])
		return "First";
	else
		return "Second";
}

int32_t main()
{
	//d_m_c();

	int n, k;
	cin >> n >> k;

	int stones[n + 1];

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

	cout << solve(stones, n, k);

	return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int a[2][26];
  int res = 0;
  for(int i = 0 ; i < s.size() ; i++){
    for(int j = 0 ; j < 26 ; j++){
      a[0][j] = a[1][j] = 0;
    }
    
    for(int j = 0 ; j < i ; j++){
      a[0][s[j]-'a']++;
    }
    for(int j = i ; j < s.size() ; j++){
      a[1][s[j]-'a']++;
    }
    int cnt = 0;
    for(int j = 0 ; j < 26 ; j++){
      if(a[0][j] > 0 && a[1][j] > 0)cnt++;
    }
    res = max(res,cnt);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
# import math
import collections
import sys
input = sys.stdin.readline

H,W,N = map(int,input().split())

ab = []

eff = collections.defaultdict(int)

for i in range(N):
    temp = list(map(int,input().split()))
    ab.append(temp)
    for j in range(3):
        for k in range(3):
            if (temp[0]-j >= 1) & (temp[0]-j <= H-2):
                if (temp[1]-k >= 1) & (temp[1]-k <= W-2):
                    eff[(temp[0]-j,temp[1]-k)] += 1

count = collections.Counter(eff.values())

count0 = (H-2) * (W-2) - sum(count.values())

print(count0)
for i in range(1,10):
    if i in count:
        print(count[i])
    else:
        print(0)


Measured memory_bytes: 199820
#include<bits/stdc++.h>
using namespace std;
int dpans(int a[],int n)
{
    int dp[n]={0};
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++)
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    return dp[n-1];
}
main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    cout<<dpans(a,n);
}


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

using namespace std;

int main(){
    int n = 0;
    cin >> n;
    vector<pair<int,int> > s(n+1);
    for(int i = 1;  i <= n; ++i){
        cin >> s[i].first;
        s[i].second = i;
    }
    sort(s.begin(),s.end());
    for(int i = 1; i <= n; ++i){
        cout << s[i].second << " ";
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1664
N = gets.to_i
d = gets.split(" ").map(&:to_i)
d.sort!
if d.size % 2 != 0
  c1 = c2 = d.size/2
else
  c1 = d.size/2 - 1
  c2 = d.size/2 
end

puts d[c2] - d[c1]

Measured memory_bytes: 21160
#include <iostream>
using namespace std;
int main(){
  int a, i;
  while(cin>>a){
    for(i=0;i<=9;i++){
      if(a&1<<i){
        cout<<(1<<i);
        if(a<2<<i)break;
        cout<<' ';
      }
    }
    cout<<endl;
  }
}

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

using namespace std;
using ll = long long;
const int INF = 1e9 + 5;

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

    int N, K; cin >> N >> K;

    vector<int> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];

    vector<int> dp(N, INF);
    dp[0] = 0;
    for (int i = 1; i < N; ++i)
        for (int j = i - 1; j >= i - K && j >= 0; --j)
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));

    cout << dp[N - 1] << "\n";

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll = long long;
string s, t;
int main()
{
	cin >> s >> t;
	int n = s.size(), m = t.size();
	int ans = 0;
	loop(i, 0, n - m + 1)
	{
		int cnt = 0;
		int j = i, k = 0;
		for (; k < m and j < n; j++, k++)
		{
			if (s[j] == t[k])cnt++;
		}
		ans = max(ans, cnt);
	}
	cout << m - ans;
}

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

int main() {   
  int N;
  while(cin >> N && N) {
    int x; cin >> x;
    stack<pair<int, int> > st; st.push(make_pair(1, x));
    for(int i=0; i<N-1; i++) {
      cin >> x;

      pair<int, int> p = st.top();
      if(p.second == x) {
        st.pop();
        st.push(make_pair(p.first + 1, x));
      }
      else if(i % 2) {
        st.push(make_pair(1, x));
      }
      else {
        st.pop();
        pair<int, int> q;
        if(!st.empty()) {
          q = st.top(); st.pop();
        }
        st.push(make_pair(p.first+q.first+1, x));
      }
    }
     
    int cnt = 0;
    for(;!st.empty();) {
      cnt += (st.top().second == 0)*st.top().first;
      st.pop();
    }
    cout << cnt << endl;
  }
   
  return 0;
}

Measured memory_bytes: 1200
N = input() 
Inp = list(input().split())
Inp = [int(i) for i in Inp]
Inp.sort()
ans = 0
for i in range(0,len(Inp),2) :
	kushi = [int(Inp[i]),int(Inp[i+1])]
	ans += min(kushi)
print(ans)

Measured memory_bytes: 3064
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TemplateHaskell #-}
--atcoder {-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NoImplicitPrelude #-}

import Prelude
import System.IO
import System.Environment
import System.Exit
import Data.List
import Data.Maybe
import qualified Data.Char as Char
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import qualified Control.Monad
--atcoder import qualified Data.Semigroup
import qualified Data.Map as Map
import qualified Data.Set as Set

readInt :: IO Int
--readInt = read <$> getLine
readInt = getLine >>= (return . read)

readInts :: IO [Int]
readInts = map (read :: String -> Int) <$> words <$> getLine

getList :: Int -> Int -> [Int]
getList l r = concat (map (\x -> map (\y -> mod (x*y) 2019) [(x+1) .. r]) [l .. r])


solve :: Int -> Int -> Int
solve l r = if r - l + 1 >= 2019
            then 0
            else minimum (getList l r)

main :: IO ()
main = do
    lr <- getLine >>= (return . words) >>= (return . map (read :: String -> Int))
    let l = lr !! 0
    let r = lr !! 1
    let ret = solve l r
    print ret

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP (i, N) cin >> A[i];
    sort(A.rbegin(), A.rend());
    vector<int> B(N);
    B[0] = A[0];
    int ans = 0, j = 1;
    FOR (i, 1, N) {
        if (2 * i < N) {
            B[2 * i] = A[i];
            ans += A[i - 1];
        } else {
            ans += min(B[(j + N - 1) % N], B[(j + 1) % N]);
            j += 2;
        }
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main(){
    int N, M; cin >> N >> M;
    vector<long long> A;
    long a; cin >> a;
    long tm =1, b = a;
    while(b%2==0){
        tm *= 2;
        b /= 2;
    }
    if(tm==1){
        cout << 0 << endl; 
        return 0;
    }
    A.push_back(b);

    for (int i = 1; i < N; i++)
    {
        cin >> a;
        if(a % tm != 0 || a % (tm*2) == 0) {
            cout << 0 << endl; 
            return 0;
        }
        A.push_back(a/tm);
    }


    M /= (tm/2);
    long long LCM = 1;
    for (int i = 0; i < N; i++)
    {
        LCM = LCM * A[i]/ __gcd(LCM, A[i]);
        if(LCM > M) {
            cout << 0 << endl; 
            return 0;
        }
    }

    int ans = 0;
    for (int i = 0; i < M; i++)
    {
        if(M>=LCM * ( 2 * i + 1 )) ans++;
        else break;
    }
    
    cout << (M - LCM) / (2*LCM) + 1 << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

char a[10][10];
bool vis[10][10];
int n, m;

int di[] = { 0, 1 };
int dj[] = { 1, 0 };

bool ok(int i, int j) {
	return i >= 0 && i < n && j >= 0 && j < m;
}

void dfs(int i, int j) {
	vis[i][j] = 1;
	if (i == n - 1 && j == m - 1)
		return;
	for (int d = 0; d < 2; d++) {
		int ni = i + di[d];
		int nj = j + dj[d];
		if (!ok(ni, nj) || vis[ni][nj] || a[ni][nj] == '.')
			continue;
		dfs(ni, nj);
		break;
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	dfs(0, 0);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[i][j] == '#' && !vis[i][j]) {
				puts("Impossible");
				return 0;
			}
		}
	}
	puts("Possible");
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())

N, x = inpl()
A = [0] + list(inpl())

ans = 0
for i in range(N):
    if A[i] + A[i+1] <= x:
        continue
    else:
        ans += -x + A[i] + A[i+1]
        A[i+1] = x - A[i]
print(ans)

Measured memory_bytes: 14540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9)+1;
const ll mod = ll(1e9)+7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans %= mod;
        ans *= power(i + 1, mod - 2);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll n,ma,mb;
    cin >> n >> ma >> mb;
    vector<ll> a(n),b(n),c(n);
    rep0(i, n)cin >> a[i] >> b[i] >> c[i];
    ll dp[n + 1][401][401];
    rep0(i, n+1)rep0(j, 401)rep0(k, 401)dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    rep0(i, n){
        rep0(j, 401){
            rep0(k, 401){
                if(dp[i][j][k] == INF)continue;
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                dp[i + 1][j + a[i]][k + b[i]] = min(dp[i][j][k] + c[i], dp[i + 1][j + a[i]][k + b[i]]);
            }
        }
    }
    ll ans = INF;
    rep0(i, 401)rep0(j, 401)if(ma * j == mb * i && i != 0 && j != 0)ans = min(ans,dp[n][i][j]);
    if(ans == INF)pf(-1);
    else pf(ans);
    return 0;
}



Measured memory_bytes: 51712
N, P = map(int, input().split())
alist = list(map(int, input().split()))

flg = True
for a in alist:
    if a % 2 != 0:
        flg = False
        break
if flg:
    if P == 0:
        print(2**N)
    else:
        print(0)
else:
    print(2**(N - 1))


Measured memory_bytes: 2940
//27
#include<iostream>
#include<queue>
#include<set>
#include<vector>
#include<algorithm>

using namespace std;

typedef pair<char,char> pcc;

struct S{
  vector<pcc> c;
  pcc p[3];
  char x,y,t;
  int tc()const{
    return x*100+y;
  }
  S(){
    p[0]=p[1]=p[2]=pcc(-1,-1);
  }
  bool operator<(S a)const{
    if(tc()!=a.tc()){
      return tc()<a.tc();
    }else if(c!=a.c){
      return c<a.c;
    }else{
      return lexicographical_compare(p,p+3,a.p,a.p+3);
    }
  }
  bool isc(int x,int y){
    return find(c.begin(),c.end(),pcc(x,y))!=c.end();
  }
  bool isp(int x,int y){
    return find(p,p+3,pcc(x,y))!=p+3;
  }
  bool isf(int x,int y){
    return !isc(x,y)&&!isp(x,y);
  }
};

struct cmp{
  bool operator ()(S a,S b)const{
    return a.t>b.t;
  }
};

int main(){
  for(int h,w;cin>>h>>w,h|w;){
    char g[10][10];
    S is;
    is.t=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>g[i][j];
	if(g[i][j]=='@'){
	  is.x=j;
	  is.y=i;
	}else if(g[i][j]=='w'){
	  *find(is.p,is.p+3,pcc(-1,-1))=pcc(j,i);
	}else if(g[i][j]=='c'){
	  is.c.push_back(pcc(j,i));
	}
      }
    }
    priority_queue<S,vector<S>,cmp> que;
    que.push(is);
    set<S> p;
    while(!que.empty()){
      S c=que.top();
      if(g[c.y][c.x]=='E')break;
      que.pop();
      if(!p.insert(c).second)continue;
      for(int i=0;i<4;i++){
	int d[]={0,1,0,-1,0};
	int xd=d[i];
	int yd=d[i+1];
	int ny=c.y+yd;
	int nx=c.x+xd;
	if(c.isc(nx,ny)){
	  S n=c;
	  n.c.erase(find(n.c.begin(),n.c.end(),pcc(nx,ny)));
	  do{
	    ny+=yd;
	    nx+=xd;
	  }while(n.isf(nx,ny)&&g[ny][nx]!='#');
	  if(n.isp(nx,ny)){
	    pcc *x=find(n.p,n.p+3,pcc(nx,ny));
	    *x=pcc(-1,-1);
	  }else{
	    n.c.push_back(pcc(nx-xd,ny-yd));
	  }
	  que.push(n);
	}else if(c.isf(nx,ny)&&g[ny][nx]!='#'){
	  S n=c;
	  n.x=nx;
	  n.y=ny;
	  n.t++;
	  que.push(n);
	}
      }
    }
    cout<<(que.empty()?-1:que.top().t)<<endl;
  }
  return 0;
}
	

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

using namespace std;

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    
    for(int i = 0; i <= N; ++i){
        for(int j = 0; j <= M; ++j){
            int temp = i * (M - j) + j * (N - i);
            if(temp == K){
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[200001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, A[200001], B[200001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d %d", &(A[i]), &(B[i]));
	
	int min, max;
	data d[200001];
	for (i = 0; i < N; i++) {
		d[i].key = A[i];
		d[i].id = i;
	}
	merge_sort(d, N);
	min = (N % 2 == 1)? d[N/2].key: d[N/2-1].key + d[N/2].key;
	for (i = 0; i < N; i++) {
		d[i].key = B[i];
		d[i].id = i;
	}
	merge_sort(d, N);
	max = (N % 2 == 1)? d[N/2].key: d[N/2-1].key + d[N/2].key;

	printf("%d\n", max - min + 1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 6416
A, B, K = map(int, input().split())
s1 = set()
s2 = set()

for i in range(1, A + 1):
    if A % i == 0:
        s1.add(i)

for j in range(1, B + 1):
    if B % j == 0:
        s2.add(j)

lst = sorted(list(s1 & s2), reverse=True)

print(lst[K-1])


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

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

    return cnt;
}

void solve() {
    int n;
    cin >> n;

    int a, min_div = 1e9;
    rep(0, n) {
        cin >> a;
        min_div = min(min_div, calc(a));
    }

    cout << min_div << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: i32
    }

    let ans = match n % 10 {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        _ => "bon",
    };

    println!("{}", ans);
}


Measured memory_bytes: 2120
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define rep(i, n) for(int i = 0; i < n; ++i) 
#define foreach(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) 

#define TRACE(x...) x
#define watch(x) TRACE(cout << #x" = " << x << endl)
#define watcharr(i, x) TRACE(cout << #x" = "); rep(i, sz(x)) cout << x[i] << " "; cout << endl

int N, M, Q;
int q[51][4];

int solve(vector<int> v) {
    int res = 0;
    vector<int> _v;
    
    if(sz(v) == N) {
        rep(i, Q) 
            if(v[q[i][1]-1] - v[q[i][0]-1] == q[i][2])
                res += q[i][3];
    }
    else if(sz(v) == 0) {
        for(int i = 1; i <= M; i++) {
            _v = v; _v.pb(i);
            res = max(res, solve(_v));
        }
    }
    else {
        for(int i = v[sz(v)-1]; i <= M; i++) {
            _v = v; _v.pb(i);
            res = max(res, solve(_v));
        }
    }
    
    return res;
}

int main() {
	
	ifstream infile("input.in");
	if(infile.good()) cin.rdbuf(infile.rdbuf());
	
    cin >> N >> M >> Q;

    memset(q, 0, sizeof q);
    rep(i, Q) rep(j, 4) cin >> q[i][j];

    vector<int> v;
    int res = solve(v);

    cout << res << endl;
	
	if(infile.good()) infile.close();
	return 0;
	
}



Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define f first
#define s second
#define inf 1000000007


ll N,M;
ll a[55];
ll b[55];
bool g[55][55];
bool visited[55];


ll check = 0;
void dfs(ll cur){
    visited[cur] = 1;
    check++;
    rep(i,55){
        if (g[cur][i] && !visited[i]){
            dfs(i);
        }
    }
    return;
}

int main() {
    cin >> N >> M;
    rep(i,M) {
        cin >> a[i] >> b[i];
        g[a[i]][b[i]] = 1;
        g[b[i]][a[i]] = 1;
    }
    ll ans = 0;
    rep(i,M){
        g[a[i]][b[i]] = 0;
        g[b[i]][a[i]] = 0;
        dfs(1);
        if (check != N) ans++;
        check = 0;
        rep(j,55) visited[j] = 0;
        g[a[i]][b[i]] = 1;
        g[b[i]][a[i]] = 1;
    }
    cout << ans << endl;
    return 0;
}


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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] n = sc.next().toCharArray();

		if (n[0] == '9' || n[1] == '9') {
			pr.println("Yes");
		} else {
			pr.println("No");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844