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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2003;
const ll MOD=998244353;

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

ll comb(ll a,ll b){
    ll ans=1;
    for(ll i=a;i>a-b;i--){
        ans=ans*i%MOD;
    }
    for(ll i=1;i<=b;i++){
        ans=(ans*rui(i,MOD-2))%MOD;
    }
    return ans;
}

int main(){
    
    ll N,A,B,K;cin>>N>>A>>B>>K;
    ll ans=0;
    vector<ll> X(N+1),Y(N+1);
    X[0]=1;Y[0]=1;
    for(ll i=1;i<=N;i++){
        X[i]=(X[i-1]*i)%MOD;
        Y[i]=rui(X[i],MOD-2)%MOD;
      //cout<<X[i]<<" "<<Y[i]<<endl;
    }
    for(ll i=0;i<=N;i++){
        if((K-i*A)%B!=0) continue;
        ll j=(K-i*A)/B;
        if(j<0||j>N) continue;
        ans+=(X[N]*Y[i]%MOD)*Y[N-i]%MOD*X[N]%MOD*Y[j]%MOD*Y[N-j]%MOD;
        ans=ans%MOD;
    }
    cout<<ans<<endl;
    
}



Measured memory_bytes: 4992
import java.util.Scanner;

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

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            if (k <= h[i]) count++;
        }

        System.out.println(count);
       
    }
}

Measured memory_bytes: 59100
#include <bits/stdc++.h>
using namespace std;
signed main(){
  string a,b;
  cin>>a;
  cin >>b;
  
 string s =" ";
  if (a.size() >b.size()){
  for(int i = 0; i< b.size() ;i++){
    
      s += a[i];
      s += b[i];
  }
    s+= a[a.size()-1];
      cout << s << endl;
  }
  else{
    
  for(int i = 0; i< b.size() ;i++){
    
      s += a[i];
      s += b[i];
  }
    
  cout << s << endl;
}
}

Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++)
    {
        s = (s[s.size() - 1] + s);
        s.pop_back();
        if (s == t)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;
int main() {
	int n;
	cin >> n;
	vector<ll> vec(n);

	for (int i = 0; i < n; i++)
	{
		cin >> vec[i];
	}
	
	ll minx = LLONG_MAX;

	ll ans = 0;
	
	for (int i = 0; i < n; i++)
	{
		minx = min(vec[i], minx);
		if (minx >= vec[i]) {
			ans++;
		}
	}
	

	cout << ans << endl;


}


Measured memory_bytes: 1792
object Main extends App {
  var a = readLine.split(" ").map(_.toInt)
  var b = 0
  var sum = 0
  for(i <- 0 to a.max) {
    if(Math.abs(a(0)-i) == Math.abs(a(1)-i)) {
      b = 1
      sum = i
    }
  }
  print(if(b != 1) {"IMPOSSIBLE"} else {sum})
}

Measured memory_bytes: 27324
def f(x):
    a,b=0,0
    for e in x:
        if e>a: a=e
        elif e>b: b=e
        else: return 0
    return 1

n=input()
for i in range(n):
    D = map(int, raw_input().split())
    s = ["NO","YES"][f(D)]
    print s

Measured memory_bytes: 4212
N, K = map(int,input().split())
a = []
for i in range(N):
    a.append(int(input()))
a.sort()
ans = 10**9 + 7
for i in range(N-K+1):
    if ans > a[K-1+i] - a[i]:
        ans = a[K-1+i] - a[i]
print(ans)

Measured memory_bytes: 50392
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println(Math.min(a, b) + Math.min(c, d));
	}
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        int a[n];
        int money = 1000;
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<n-1;i++)
        {
            if(a[i+1]<a[i])continue;
            int j = i+1;
            int now = money/a[i];
            money = money%a[i];
            while(j<n && a[j]>=a[j-1])j++;
            money += now*a[j-1];
            i = j-1;
        }
        cout<<money<<endl;
    }
    return 0;
}


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

int main()
{
    int n, c, k;
    std::cin >> n >> c >> k;

    std::vector<int> t(n);

    for (int i = 0; i < n; i++) {
        std::cin >> t[i];
    }

    std::qsort(&t[0], t.size(), sizeof(int), [](const void* a, const void* b)
    {
        int arg1 = *static_cast<const int*>(a);
        int arg2 = *static_cast<const int*>(b);

        if (arg1 < arg2) return -1;
        if (arg1 > arg2) return 1;
        return 0;
    });

    int result = 1;
    int count = 1;
    int t_max = t[0] + k;

    for (int i = 1; i < n;) {
        if (t[i] <= t_max && count < c) {
            count++;
            i++;
        }
        else {
            result++;
            count = 0;
            t_max = t[i] + k;
        }
    }


    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 1020
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void debug(vec &v) {
	int n = v.size();
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << v[i];
	}
	cout << endl;
}

int trans(char t) {
	if (t == 'r') {
		return 2;
	}
	else if (t == 's')return 0;
	else return 1;
}
void solve() {
	int n, k, s[3];
	cin >> n >> k;
	rep(i, 3)cin >> s[i];
	string t; cin >> t;
	int sum = 0;
	rep(i, k) {
		P score = { 0,0 };
		score.second = s[trans(t[i])];
		for (int j = i + k; j < n; j += k) {
			P nex = { 0,0 };
			nex.first = max(score.first,score.second);
			nex.second = score.first + s[trans(t[j])];
			if (t[j] != t[j - k]) {
				nex.second = max(nex.second, score.second + s[trans(t[j])]);
			}
			score = nex;
		}
		//cout << max(score.first, score.second) << endl;
		sum += max(score.first, score.second);
	}
	cout << sum << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> vc;
    
    for(int i = 0; i < 10; i++){
        int x;
        cin >> x;
        vc.push_back(x);
    }
    
    sort(vc.begin(), vc.end(), greater<int>());
    
    for(int i = 0; i < 3; i++){
        cout << vc[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int R,C,K;
int dp[3010][3010][4];
int num[3010][3010];

signed main(){
	cin>>R>>C>>K;
	REP(i,K){
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		num[a][b]=c;
	}
	REP(i,3010)REP(j,3010)REP(k,4){
		dp[i][j][k]=-INF;
	}
	dp[0][0][0]=0;
	REP(i,R){
		REP(j,C){
			for(int k=2;k>=0;k--){
				if(dp[i][j][k]>=0){
					dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+num[i][j]);
				}
			}
			REP(k,4){
				if(dp[i][j][k]>=0){
					if(i+1<R){
						dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
					}
					if(j+1<C){
						dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
					}
				}
			}
		}
	}
	int ans=-INF;
	REP(k,4){
		ans=max(ans,dp[R-1][C-1][k]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 357240
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int H,W;
  cin>>H>>W;
  vector<string> c(H);
  vector<vector<bool>> passed(H,vector<bool>(W,false));
  for(int i=0;i<H;i++){
    cin>>c[i];
  }
  ll ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(passed[i][j]||c[i][j]=='.') continue;
      //printf("(%d,%d)\n",i,j);
      ll black=0,white=0;
      queue<pair<int,int>> q;
      passed[i][j]=true;
      q.push({i,j});
      while(!q.empty()){
        pair<int,int> pos=q.front();
        q.pop();
        int y=pos.first,x=pos.second;
        //printf("%d,%d\n",y,x);
        bool is_black=(c[y][x]=='#');
        if(is_black) black++;
        else white++;
        for(int k=0;k<4;k++){
          if(y+dy[k]>=0&&y+dy[k]<H&&
          x+dx[k]>=0&&x+dx[k]<W&&!passed[y+dy[k]][x+dx[k]]&&c[y+dy[k]][x+dx[k]]==((is_black)?'.':'#')){
            
            passed[y+dy[k]][x+dx[k]]=true;
            q.push({y+dy[k],x+dx[k]});
          }
        }
      }
      //printf("(%d,%d) %d\n",i,j,black*white);
      ans+=black*white;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

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

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


int main(void){
    int n;
    int a[50];
    int i;
    int cnt = 0;
    int mov[200];
    int head = 0;
    int max = -1000000, min = 1000000;
    int maxi, mini;
    int absmax, absmaxi;

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

    for (i = 0; i < n; i++){
        if (max<a[i]){
            max = a[i];
            maxi = i;
        }

        if (min>a[i]){
            min = a[i];
            mini = i;
        }
    }

    absmax = abs(min)>abs(max)?abs(min):abs(max);
    if (absmax == max){
        absmaxi = maxi;
    }else{
        absmaxi = mini;
    }

    for (i = 0; i < n; i++){
        a[i] += a[absmaxi];
        mov[head] = absmaxi;
        head++;
        mov[head] = i;
        head++;
        cnt++;
    }

    if (a[absmaxi] >= 0){
        for (i = 1; i < n; i++){
            a[i] += a[i-1];
            mov[head] = i-1;
            head++;
            mov[head] = i;
            head++;
            cnt++;
        }
    }

    if (a[absmaxi] < 0){
        for (i = n - 2; i >= 0; i--){
            a[i] += a[i+1];
            mov[head] = i+1;
            head++;
            mov[head] = i;
            head++;
            cnt++;
        }
    }

    printf("%d\n", cnt);
    for (i = 0; i < cnt*2; i++){
        printf("%d ", mov[i]+1);
        if (i % 2 == 1){
            printf("\n");
        }
    }

    printf("\n");



    

    return 0;
}

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

int main() {
    int x,y;
    scanf("%d%d",&x,&y);
    ll ans = 0;
    if(x == 3) ans += 100000;
    else if(x == 2) ans += 200000;
    else if(x == 1) ans += 300000;
    if(y == 3) ans += 100000;
    else if(y == 2) ans += 200000;
    else if(y == 1) ans += 300000;
    if(x == 1 && y == 1) ans += 400000;
    printf("%ld\n",ans);
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	var t, l uint64
	fmt.Scan(&N)
	fmt.Scan(&t)
	l = t
	for i := 0; i < N-1; i++ {
		fmt.Scan(&t)
		l = lcm(l, t)
	}
	fmt.Println(l)

}

func gcd(a, b uint64) uint64 {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b uint64) uint64 {
	if a == b {
		return a
	}
	//return a * b / gcd(a, b)
	return a  / gcd(a, b) * b
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long a[100];
int main() {
	string s;
	cin >> s;
	long long n = s.size();
	long long ans = 0, co = 0;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'A') {
			co++;
		}
		else if (s.substr(i, 2) == "BC") {
			ans += co;
			i++;
			continue;
		}
		else {
			co = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
use std::cmp;
use std::io;

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

fn main() {
    let (a, b, c, d): (usize, usize, usize, usize);
    input!(a);
    input!(b);
    input!(c);
    input!(d);
    p(cmp::min(a, b) + cmp::min(c, d));
}

Measured memory_bytes: 4352
N, M = map(int, input().split())
A = []
ans = 0
for i in range(N):
    A.append(list(map(int,input().split())))
for i in range(2):
    for j in range(2):
        for k in range(2):
            a, b, c = (-1)**i, (-1)**j, (-1)**k
            tmp = [x[0]*a+x[1]*b+x[2]*c for x in A]
            tmp.sort(reverse=True)
            ans = max(ans, sum(tmp[:M]))
print(ans)

Measured memory_bytes: 3360
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int n;
    scan(n);

    int ma;
    int ans;

    foreach (i ; 0 .. n) {
        int ai, bi;
        scan(ai, bi);
        if (ai > ma) {
            ma = ai;
            ans = ai + bi;
        }
    }

    writeln(ans);
}














void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 1276
N = int(input())
W = input().split()
W = [int(s) for s in W]
list=[]
Smin=100000
for i in range(N):
    S1 = sum(W[0:i])
    S2 = sum(W[i:])
    S = abs(S1-S2)
    if Smin > S:
        Smin=S
print(Smin)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long  
#define PI   3.14159265358979323846 
#define spd  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

 void solve(){
  char a;  cin>>a;
  if(a > 'Z') cout << "a\n";
  else cout << "A\n";
}
int main()
{
     solve();
     return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<char>a(n);
    vector<char>b(n);
    for(int i=0; i<n; i++){
        a[i]=s[i];
        b[i]=s[n-1-i];
    }

    for(int i=0; i<n; i++){
        if(a[i]!=b[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    reverse(a.begin(),a.begin()+n/2);

    for(int i=0; i<n/2; i++){
        if(a[i]!=b[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3604
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    V = LI()
    V = sorted(V)
    cur = V[0]
    for i in range(1, len(V)):
        cur = (cur + V[i])/2
    print(cur)
        

main()



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

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


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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve() {
    ll n, m;
    cin >> n >> m;
    ll ans;
    if (n == 1 or m == 1) {
        ans = 1;
    } else {
        ans = (ll(n) / 2) * m;
        if (n & 1) {
            ans += (m + 1) / 2;
        }
    }
    cout << ans << endl;
}

int main() {
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1100;
const int INF = 0x3f3f3f3f;

struct Node{
	int to, cap, rev;
};

vector<Node> v[N];
bool used[N];

void add_Node(int from, int to, int cap){
	v[from].push_back((Node) { to, cap, v[to].size() });
	v[to].push_back((Node) { from, 0, v[from].size() - 1 });
}

int dfs(int s, int t, int f){
	if (s == t)
		return f;
	used[s] = true;
	for (int i = 0; i<v[s].size(); i++)	{
		Node &tmp = v[s][i];
		if (used[tmp.to] == false && tmp.cap>0){
			int d = dfs(tmp.to, t, min(f, tmp.cap));
			if (d>0){
				tmp.cap -= d;
				v[tmp.to][tmp.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	while (true) {
		memset(used, false, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)
			return flow;
		flow += f;
	}
}

int n, m, l;
int a[N][N], b[N], c[N];

int main(){
	while (~scanf("%d%d%d", &n, &m, &l)) {
		int s = n * 2 + 1, t = n * 2 + 2;
		memset(v, 0, sizeof(v));
		memset(a, 0x3f, sizeof(a));
		for (int i = 0; i < N; i++)
			a[i][i] = 0;
		for (int i = 0; i < N; i++)
			v[i].clear();
		for (int i = 0, x, y, d; i < m; i++) {
			scanf("%d%d%d", &x, &y, &d);
			a[x][y] = a[y][x] = min(d, a[x][y]);
		}
		for (int k = 1; k <= n; k++)
			for (int i = 1; i <= n; i++)
				for (int j = 1; j <= n; j++)
					a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
		for (int i = 1; i <= n; i++)
			scanf("%d", &b[i]);
		for (int i = 1; i <= n; i++)
			scanf("%d", &c[i]);
		for (int i = 1; i <= n; i++)
			add_Node(s, i, b[i]), add_Node(n + i, t, c[i]);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				if (a[i][j] < l)
					add_Node(i, n + j, b[i]);
		printf("%d\n", max_flow(s, t));
	}
}

Measured memory_bytes: 28520
#include <bits/stdc++.h>
#define ll long long int
#define n 100005
using namespace std;
ll dp[n];
ll height[n];
ll solve(int N, int k)
{
    dp[1] = 0;
    for (int i = 2; i <= N; i++) {
        dp[i] = INT_MAX;
        for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
            ll opt1 = abs(height[i] - height[j]) + dp[j];
            dp[i] = min(dp[i], opt1);
        }
    }
    return dp[N];
}

int main()
{
    memset(dp, 0, sizeof dp);
    memset(height, 0, sizeof height);
    int N, k;
    cin >> N >> k;
    for (int i = 1; i <= N; i++) {
        cin >> height[i];
    }
    cout << solve(N, k);
}

Measured memory_bytes: 5204
import sys
readline = sys.stdin.readline

DIV = 998244353
N,S = map(int,readline().split())
A = list(map(int,readline().split()))

# ある数の取り得る状態は以下
# (1)Lの区間がまだ開始していない
# (2)L-Rの区間に含まれ、和に使われている
# (3)L-Rの区間に含まれ、和に使われていない
# (4)Rの区間が終了している

# dp[i][j][k] = i - 1個目まで処理したときに、区間の開始状況がjで、総和がkになっている個数
dp = [[[0] * (S + 1) for j in range(3)] for i in range(N + 1)]
dp[0][0][0] = 1

for i in range(N):
  for k in range(S + 1):
    # (1)まだ区間が開始していない場合
    dp[i + 1][0][k] += dp[i][0][k]
    dp[i + 1][0][k] %= DIV

    # (2)区間に含まれ、和に使われている
    if k + A[i] <= S:
      dp[i + 1][1][k + A[i]] += dp[i][0][k]
      dp[i + 1][1][k + A[i]] += dp[i][1][k]
      dp[i + 1][1][k + A[i]] %= DIV

    # (3)区間に含まれ、和に使われていない
    dp[i + 1][1][k] += dp[i][0][k]
    dp[i + 1][1][k] += dp[i][1][k]
    dp[i + 1][1][k] %= DIV

    # (4)区間が終了している
    dp[i + 1][2][k] += dp[i][2][k]
    dp[i + 1][2][k] += dp[i][1][k]
    dp[i + 1][2][k] %= DIV

print((dp[-1][1][-1] + dp[-1][2][-1]) % DIV)


Measured memory_bytes: 287132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

bool is_prime(ll x){
    if(x == 2){ return true; }
    if(x % 2 == 0){ return false; }
    for(ll d = 3; d * d <= x; d += 2){
        if(x % d == 0){
            return false;
        }
    }
    return true;
}

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    REP(i, n){
        ll x;
        cin >> x;
        ans += is_prime(x);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        String s = next();
        int[] q = new int[n];
        for (int i = 0; i < n; i++) {
            q[i] = (s.charAt(i) == 'x') ? 1 : 0;
        }
        for (int a = 0; a < 2; a++) {
            for (int b = 0; b < 2; b++) {
                int x = a;
                int y = b;
                for (int i = 0; i < n; i++) {
                    int z = (x + y + q[i]) % 2;
                    x = y;
                    y = z;
                }
                if (x == a && y == b) {
                    for (int i = 0; i < n; i++) {
                        out.print(y == 1 ? "W" : "S");
                        int z = (x + y + q[i]) % 2;
                        x = y;
                        y = z;
                    }
                    out.println();
                    return;
                }
            }
        }
        out.println(-1);

    }

    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

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

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

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 24260
import java.util.*;

public class Main {
    private static final int INF = 1001001001;
    private static int dist[][] = new int[100005][3];

    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Integer> to[] = new ArrayList[n];
        for (int i=0;i<n;i++) {
            to[i] = new ArrayList<>();
        }

        for (int i = 0; i < m; i++) {
            int u = sc.nextInt();
            int v = sc.nextInt();
            u--;
            v--;
            to[u].add(v);
        }

        int s = sc.nextInt();
        int t = sc.nextInt();
        s--;
        t--;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                dist[i][j] = INF;
            }
        }

        // BSF
        Queue<Pair<Integer, Integer>> q = new LinkedList<>();

        q.add(new Pair<>(s, 0));
        dist[s][0] = 0;
        while (!q.isEmpty()) {
            int v = q.peek().first;
            int l = q.peek().second;
            q.poll();
            for (int u : to[v]) {
                int nl = (l + 1) % 3;
                if (dist[u][nl] != INF) continue;
                dist[u][nl] = dist[v][l] + 1;
                q.add(new Pair<>(u, nl));
            }
        }
        int ans = dist[t][0];
        if (ans == INF) ans = -1;
        else ans /= 3;
        System.out.println(ans);
    }

    static class Pair<F, S> {
        public final F first;
        public final S second;

        Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }
}

Measured memory_bytes: 105520
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll N, ll mod){
  if (N == 0) return 1;
  else{
    if (N % 2 == 0) return Pow(A * A % mod, N / 2, mod) % mod;
    else return (A % mod) * Pow(A * A % mod, N / 2, mod) % mod;
  }
}

int main(){
  int N, P; cin >> N >> P;
  string S; cin >> S;

  if (P == 2 || P == 5){
    ll ans = 0;
    for (ll i = 0; i < N; i++){
      int now = S[i] - '0';
      if (now % P == 0){
        ans += i + 1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  ll DP[N + 1] = {};
  
  for (int i = N - 1; i >= 0; i--){
    ll now = S[i] - '0';
    now *= Pow(10, N - 1 - i, P);
    DP[i] = (DP[i + 1] + now) % P;
  }

  ll cnt[P] ={};
  for (int i = 0; i < N; i++){
    cnt[DP[i]]++;
  }

  ll ans = 0;
  for (int i = 0; i < P; i++){
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  ans += cnt[0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2180
a, b, c, d=map(int, input())
p, m='+', '-'
def f(x):
  s=a
  out=str(a)
  if x&1:
    s+=b
    out+=p
  else:
    s-=b
    out+=m
  out+=str(b)
  if (x>>1)&1:
    s+=c
    out+=p
  else:
    s-=c
    out+=m
  out+=str(c)
  if (x>>2)&1:
    s+=d
    out+=p
  else:
    s-=d
    out+=m
  out+=str(d)+'=7'
  return [s, out]

for i in range(8):
  if f(i)[0]==7:
    print(f(i)[1])
    break

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K, Q = MAP()
A = LIST()

ans = INF
# 使う要素の最小値とする値xを全探索
for x in A:
    # 数列Aをx未満の値で区切った数列Bを作る
    B = []
    tmp = []
    for i in range(N):
        if A[i] >= x:
            tmp.append(A[i])
        else:
            B.append(tmp)
            tmp = []
    B.append(tmp)
    # 数列B内の各数列から、使える要素を集める
    C =  []
    for li in B:
        m = len(li)
        if m-K+1 >= 1:
            li.sort()
            C += li[:m-K+1]
    # 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y
    C.sort()
    if len(C) < Q:
        continue
    y = C[Q-1]
    ans = min(ans, y - x)
print(ans)


Measured memory_bytes: 52188
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int A[4]={0},ans=0;
	scanf("%d%d%d",&A[1],&A[2],&A[3]);
	sort(A+1,A+4);
	ans+=A[3]-A[2];
	A[1]+=A[3]-A[2];
	A[2]=A[3];
	if(A[1]==A[3]){
		printf("%d\n",ans);
		return 0;
	}
	ans+=(A[3]-A[1])/2;
	A[1]+=(A[3]-A[1])/2*2;
	if(A[1]==A[3]){
		printf("%d\n",ans);
		return 0;
	}
	ans+=2;
	printf("%d\n",ans);
}


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

using namespace std;

int main() {
  map<string,int> mp;
  int n,m;
  cin>>n;
  while (n--) {
    string x; cin>>x;
    mp[x]++;
  }
  cin>>m;
  while(m--) {
    string x; cin>>x;
    mp[x]--;
  }
	int best = 0;
  for (auto p: mp) {
    best = max(best, p.second);
  }
  cout<<best<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
 
    int input1 = scan.nextInt();
 
    Tree main = new Tree(-2147483648);
 
    for(int loopCount = 0; loopCount < input1; loopCount++) {
      char[] s = scan.next().toCharArray();
      if(s[0]=='i') main.insert(scan.nextInt());
      else if(s[0]=='p') {
        if(main.right != null) {
          main.right.printMiddle();
          System.out.println();
          main.right.printFirst();
          System.out.println();
        }
      }
    }
  }
}
 
class Tree{
  int key;
  Tree left,right;
 
  Tree(int _key) {
    this.key = _key;
  }
 
  void insert(int _num) {
    if(key<_num) {
      if(right == null) {
        right = new Tree(_num);
      }else {
        right.insert(_num);
      }
    }else if(key>_num) {
      if(left == null) {
        left = new Tree(_num);
      }else {
        left.insert(_num);
      }
    }
  }
 
  String find(int _num) {
    if(key == _num) return "YES";
    else {
      if(key > _num) return left.find(_num);
      if(key < _num) return right.find(_num);
      return "NO";
    }
  }
 
  void printFirst() {
    System.out.print(" "+key);
    if(left!=null) left.printFirst();
    if(right!=null) right.printFirst();
  }
 
  void printMiddle() {
    if(left!=null) left.printMiddle();
    System.out.print(" "+key);
    if(right!=null) right.printMiddle();
  }
}



Measured memory_bytes: 230156
#include <iostream>
using namespace std;
int main (){
//declaring 
int A,B,S,T,P;
//input
cin>>A>>B;
//process
S=A+B;

T=A-B;
P=A*B;

  
if (S>T&&S>P){
  cout<<S;
}else if (T>S&&T>P){
  cout<<T;
}else if(P>S&&P>T) {
  cout<< P;
}else if (S==T){cout<<S;

  }else if(S==P){cout<<S;


  }else if(T==P){cout<<T;
}

  
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,ll> P;

vector<P> g[100010];
ll vis[100010],d[100010];

void dfs(int x,ll s){
	vis[x]=1;
	d[x]=s;
	int n=g[x].size();
	REP(i,n){
		if(vis[g[x][i].first]==0){

			dfs(g[x][i].first,s+g[x][i].second);
		}
	}

}

int main(void){
	          int i;

	          int N;
	          cin >> N;
	          for(i=0;i<=N-2;i++){
	        	  ll a,b,c;
	        	  cin >> a >> b >> c;
	        	  a--; b--;
	        	  g[a].push_back(P(b,c));
	        	  g[b].push_back(P(a,c));
	          }

	          int Q,K;
	          cin >> Q >> K;
	          K--;
	          dfs(K,0LL);
	          d[K]=0;
	          for(i=0;i<Q;i++){
	        	  int x,y;
	        	  cin >> x >> y;
	        	  x--;
	        	  y--;
	        	  cout << d[x]+d[y] << endl;
	          }

	          return 0;
}


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

int main() {
  int N, x, n;
  cin >> N;
  x = 0;
  n = N;
  for (int i = 8; i >= 0; i--) {
    int a, p;
    p = 1;
    for (int j = 0; j < i; j++) {
      p *= 10;
    }
    a = n / p;
    n -= p * a;
    x += a;
  }
  if (N % x == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
package main

import "fmt"

var k int
var lun [][]int
var lunlun []int

func main() {
	fmt.Scan(&k)
	lun = make([][]int, 60)
	lunlun = make([]int, 0, k)
	lun[0] = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	lunlun = append(lunlun, lun[0]...)
	dx := []int{-1, 0, 1}

	for dig := 0; len(lunlun) < k; dig++ {
		for _, x := range lun[dig] {
			for _, d := range dx {
				last := x % 10
				if 0 <= last+d && last+d <= 9 {
					num := x*10+last+d
					lun[dig+1] = append(lun[dig+1], num)
					lunlun = append(lunlun, num)
				}
			}
		}
	}
	fmt.Println(lunlun[k-1])
}


Measured memory_bytes: 12800
def main():
    N = int(input())
    cs = list(input())

    l = 0
    r = N - 1

    cnt = 0
    while l < r:
        while l <= N - 1 and cs[l] == 'R':
            l += 1

        while 0 <= r and cs[r] == 'W':
            r -= 1

        if l >= r:
            break

        cs[l], cs[r] = cs[r], cs[l]
        cnt += 1

    print(cnt)

main()


Measured memory_bytes: 10768
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;



template<typename Mono,typename Ope>
struct LazySegmentTree{
    using F = function<Mono(Mono,Mono)>;
    using G = function<Mono(Mono,Ope)>;
    using H = function<Ope(Ope,Ope)>;
    int n,height;
    F f; G g; H h; Mono tu; Ope eu;
    vector<Mono> node;
    vector<Ope> lazy;

    LazySegmentTree(F f,G g,H h,Mono tu,Ope eu):f(f),g(g),h(h),tu(tu),eu(eu){}

    void init(vector<Mono> v){
        int n_ = (int)(v.size());
        n = 1;height = 0;
        while(n < n_) n <<= 1,++ height;
        node.assign(2*n,tu);
        lazy.assign(2*n,eu);
        for(int i=0;i<n_;i++) node[i+n] = v[i];
        for(int i=n-1;i>0;i--) node[i] = f(node[i<<1],node[i<<1|1]);
    }

    Mono eval(int k){
        return (lazy[k]==eu)?node[k]:g(node[k],lazy[k]);
    }

    void prop(int k){
        if(lazy[k]==eu) return;
        lazy[k<<1] = h(lazy[k<<1],lazy[k]);
        lazy[k<<1|1] = h(lazy[k<<1|1],lazy[k]);
        node[k] = eval(k);
        lazy[k] = eu;
    }

    void prop_above(int k){
        for(int i=height;i>0;i--) prop(k>>i);
    }

    void recalc_above(int k){
        while(k>0){
            k >>= 1;
            node[k] = f(eval(k<<1),eval(k<<1|1));
        }
    }

    void set_val(int k,Mono x){
        k += n;
        prop_above(k);
        node[k] = x;
        lazy[k] = eu;
        recalc_above(k);
    }

    void update(int l,int r,Ope x){
        if(l >= r) return;
        l += n;r += n-1;
        prop_above(l);
        prop_above(r);
        int a = l,b = r;
        ++ r;
        while(l < r){
            if(l&1) lazy[l] = h(lazy[l],x), ++l;
            if(r&1) --r, lazy[r] = h(lazy[r],x);
            l >>= 1;r >>= 1;
        }
        recalc_above(a);
        recalc_above(b);
    }

    Mono query(int l,int r){
        if(l >= r) return tu;
        l += n;r += n-1;
        prop_above(l);
        prop_above(r);++r;
        Mono vl = tu,vr = tu;
        while(l < r){
            if(l&1) vl = f(vl,eval(l)), ++l;
            if(r&1) --r, vr = f(eval(r),vr);
            l >>= 1;r >>= 1;
        }
        return f(vl,vr);
    }
};

int main(){
    auto f = [](pll a,pll b){return pll(a.first+b.first,a.second+b.second);};
    auto g = [](pll a,ll y){return pll(a.first+a.second*y,a.second);};
    auto h = [](ll x,ll y){return x+y;};
    LazySegmentTree<pll,ll> seg(f,g,h,pll(0,1),0);

    int n;
    cin >> n;
    vector<pll> a(n,pll(0,1));
    seg.init(a);

    int q;
    cin >> q;
    while(q--){
        int t;
        cin >> t;
        if(t==0){
            int l,r;
            ll x;
            cin >> l >> r >> x;
            --l;--r;
            seg.update(l,r+1,x);
        }else{
            int i;
            cin >> i;
            --i;
            cout << seg.query(i,i+1).first << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 12072
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int a, b;
    cin >> a >> b;
    int mid = (a+b)/2;
    if(abs(a-mid)==abs(b-mid)){
        cout << mid;
    }
    else{
        cout << "IMPOSSIBLE";

    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll x;
ll A[MAX_N];

void solve() {
	cin >> N >> x;
	rep(i, 0, N) cin >> A[i];
	sort(A, A + N);
	rep(i, 0, N) {
		if(x < A[i]) {
			cout << i << "\n";
			return;
		}
		else x -= A[i];
	}
	if(x == 0) cout << N << "\n";
	else cout << N - 1 << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){

unsigned int a,b,n;

scanf("%u %u %u",&a,&b,&n);

int i;
for(i = 0;i < n/2; i++){

if(a%2 == 1) a -= 1;

b += a/2;
a -= a/2;

if(b%2 == 1) b -= 1;

a += b/2;
b -= b/2;
}

if(n % 2 == 1){

if(a%2 == 1)a -= 1;

b += a/2;
a -= a/2;
}

printf("%u %u",a,b);

return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  int n, m, x1, y1, x, y, len;
  char dir;
  int grid[21][21];
  while(cin >> n, n){
    memset(grid, 0, sizeof(grid));
    x = 10; y = 10;
    grid[y][x] = 1;
    for(int i = 0 ; i < n ; i++){
      cin >> x1 >> y1;
      grid[y1][x1] = 5;
    }

    /*for(int a = 0 ; a < 21 ; a++){
  for(int b = 0 ; b < 21 ; b++){
    cout << grid[b][a];
  }
  cout << endl;
  }*/

    cin >> m;
    for(int i = 0 ; i < m ; i++){
      cin >> dir >> len;
      if(dir == 'N'){
	for(int j = 0 ; j < len ; j++){
	  grid[++x][y] = 1;
	}
      }
      if(dir == 'E'){
	for(int j = 0 ; j < len ; j++){
	  grid[x][++y] = 1;
	}
      }
      if(dir == 'S'){
	for(int j = 0 ; j < len ; j++){
	  grid[--x][y] = 1;
	}
      }
      if(dir == 'W'){
	for(int j = 0 ; j < len ; j++){
	  grid[x][--y] = 1;
	}
      }

      /* for(int a = 0 ; a < 21 ; a++){
  for(int b = 0 ; b < 21 ; b++){
    cout << grid[b][a];
  }
  cout << endl;
  }*/
    }
    bool flag=0;
    for(int i = 0 ; i < 21 ; i++){
      for(int j = 0 ; j < 21 ; j++){
	if(grid[i][j] == 5) flag = 1;
      }
    }
    if(flag == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

#include <utility>
using namespace std;

#define REP(i, n) for ( int i = 0; i < (n); i++ )
const int INF = 1e9;
using Pii = pair<int, int>;

const int con_type = 26;
int D = 365;
int C[con_type];
int S[365][con_type];
vector<int> ans;
int last[con_type];

struct State {
  int cost;
  vector<int> ans;
  vector<int> last;

  State() {
    cost = 0;
    last = vector<int>(26, -1);
  }

  State(int cost, vector<int> ans, vector<int> last):
    cost(cost), ans(ans), last(last) {};

  bool operator<( const State& s ) const {
    return cost < s.cost;
  }

  bool operator>( const State& s ) const {
    return cost > s.cost;
  }
};

void solve() {
  priority_queue<State> Q;
  Q.push(State());
  REP(d, D) {
    priority_queue<State> nQ;
    while ( !Q.empty() ) {
      State now = Q.top(); Q.pop();
      vector<Pii> add_cost;
      int sum = 0;
      int type_cost[26];
      REP(i, con_type) {
        sum += (d-now.last[i])*C[i];
        type_cost[i] = (d-now.last[i])*C[i];
      }
      REP(i, con_type) {
        add_cost.emplace_back(Pii(S[d][i]+(d-now.last[i])*C[i]-sum, i));
      }
      sort(add_cost.begin(), add_cost.end(), greater<Pii>());
      REP(i, 6) {
        int id = add_cost[i].second;
        State next = now;
        next.cost += S[d][id];
        next.cost -= sum;
        next.cost += type_cost[id];
        next.ans.emplace_back(id);
        next.last[id] = d;
        nQ.push(next);
      }
    }
    Q = priority_queue<State>();
    REP(i, min(1400, (int)nQ.size())) {
      Q.push(nQ.top()); nQ.pop();
    }
  }

  ans = Q.top().ans;
}

void input() {
  cin >> D;
  REP(i, con_type) {
    cin >> C[i];
    last[i] = -1;
  }
  REP(i, D) REP(j, con_type) cin >> S[i][j];
}

void output() {
  REP(i, D) cout << ans[i]+1 << endl;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  input();
  solve();
  output();

  return 0;
}


Measured memory_bytes: 18696
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N, K):
    if N % K == 0:
        return 0
    N = N % K
    return min(N, K-N)


if __name__ == "__main__":

    # N K
    #
    N, K = map(int, input().split())
    ans = solv(N, K)

    print(ans)


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

int main() {
    int n,m;
    cin >> n >> m;
    long long mod=1e9+7;

    bool a[n+1];
    for(int i=0;i<=n;i++) a[i]=true;
    for(int i=0;i<m;i++){
        int aa;
        cin >> aa;
        a[aa]=false;
    }
    long long dp[n+1];
    for(int i=0;i<=n;i++) dp[i]=0;
    if(a[1]) dp[1]=1;
    if(a[1]&&a[2]) dp[2]=2;
    if(!a[1]&&a[2]) dp[2]=1;
    for(int i=3;i<=n;i++){
        if(a[i-2]) dp[i]+=dp[i-2];
        if(a[i-1]) dp[i]+=dp[i-1];
        dp[i]=dp[i]%mod;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
#define inf 99999999
int n,m;
int coin[50001];
int dp[21][50001];
void print(){
  for(int i=0;i<m;i++){
    for(int j=0;j<n+1;j++){
      cout<<dp[i][j]<<" ";;
    }
    cout<<"\n";
  }
  cout<<"\n";
}
void init(){
  for(int i=0;i<m+1;i++){
    for(int j=0;j<n+1;j++){
      dp[i][j]=inf;
    }
  }
  for(int i=0;i<=n;i++){
    dp[0][i]=i;
  }
}
void solve(){
  for(int i=0;i<m;i++){
    for(int j=0;j<n+1;j++){
      if(coin[i]>j){
        dp[i+1][j]=dp[i][j];
      }else{
        dp[i+1][j]=min(dp[i][j],dp[i+1][j-coin[i]]+1);
      }
    }
  }
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>coin[i];
  }
  init();
  solve();
  //print();
  cout<<dp[m][n]<<"\n";
}



Measured memory_bytes: 7180
s=str(input())
#if(s=="2019/04/30"):
year=[]
month=[]
date=[]

for i in range(4):
	year.append(s[i])

for i in range(5,7):
	if(s[5]!=0):
		month.append(s[i])
	elif(s[5]==0):
		month.append(s[i])

for i in range(8,10):
	if(s[8]!=0):
		date.append(s[i])
	else:
		date.append(s[9])

year=int(''.join(year))
month=int(''.join(month))
date=int(''.join(date))
#print(year,month,date)

if(year<=2019 and month<=4 and date<=30):
	print("Heisei")
elif(year>=2019 and month>=5 and date>=1):
	print("TBD")



Measured memory_bytes: 3064