akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt(),b=scan.nextInt(),c=scan.nextInt();
		if(a==c) {
			System.out.println(b);
		}
		else if(a==b) {
			System.out.println(c);
		}
		else if(b==c) {
			System.out.println(a);
		}

	}

}

Measured memory_bytes: 35680
#include <iostream>

using namespace std;

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

    int A[N], i;
    for(i=0; i<N; i++) {
        cin >> A[i];
    }

    int max=A[1]-A[0], min=A[1]-A[0];

    for(i=2; i<N; i++) {
        if(A[i]-A[0]>max) {
            max = A[i] - A[0];
        }
        if(A[i]-A[0]<min) {
            min = A[i] - A[0];
        }
    }

    int ans;
    if(max>=0) {
        if(min<0) {
            ans = max - min;
        } else {
            ans = max;
        }
    } else {
        ans = -min;
    }

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

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int  len = S.length();
    int ma = INT_MIN;
    for(int i = 0; i < len; i++){
        int c = 0;
        for(int j = i; j < len; j++){
            if(S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T'){
                c++;
            }else{
                break;
            }
        }
        ma = max(ma,c);
    }
    cout << ma << endl;
}

Measured memory_bytes: 256
//AtCoder Beginner Contest 000 A問題
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	bool yes = true;
	int h,w;
	scanf("%d%d", &h,&w);
	char a[h][w];
	for(int i=0;i<h;i++){
		scanf("%s", a[i]);
	}
	int stend[h][2];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(a[i][j] == '#'){
				stend[i][0] = j;
				break;
			}
		}
		for(int j=w-1;j>=0;j--){
			if(a[i][j] == '#'){
				stend[i][1] = j;
				break;
			}
		}
	}
	for(int i=0;i<h-1;i++){
		if(stend[i][1] != stend[i+1][0]){
			yes = false;
		}
	}
	if(yes) printf("Possible\n");
	else printf("Impossible\n");
}

Measured memory_bytes: 256
A = []
for i in range(3):
    ai=list(map(int,input().split()))
    A.append(ai)
N = int(input())

bingo=[[0,0,0],[0,0,0],[0,0,0]]

for i in range(N):
    bi=int(input())
    for j in range(3):
        for k in range(3):
            a=A[j][k]
            if a==bi:
                bingo[j][k]=1

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

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int K=gi();
	    int X=gi();
	    int c=0;
	    System.out.print(X-K+1);
	    for(int i=1; i<2*K-1;i++) {
	    	System.out.print(" " + (X-K+1+i));
	    }
	   
        //System.out.print(c);
//        if (c<=2) {
//        	System.out.println("YES");
//        }else {
//        	System.out.println("NO");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 38352
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long n = sc.nextLong()-1;
		char[] c = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
		
		// 計算
		String result = "";
		StringBuilder sb = new StringBuilder();
		while(n >= 0){
		    long a = n%26;
		    sb.append(c[(int)a]);
		    n = n/26-1;
		}
		result = sb.reverse().toString();
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


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

int main() {
  
  int N, M, C; cin >> N >> M >> C; int ans = 0;
  
  vector<int> vecB(M);
  
  for (int i = 0; i < M; i++) cin >> vecB.at(i);
  
  for (int i = 0; i < N; i++) {
    
    int tmp = C;
    
    for (int j = 0; j < M; j++) {
      int A; cin >> A;
      tmp += A * vecB.at(j);
    }
    
    if (0 < tmp) ans++;
    
  }
  
  cout << ans << endl;
  
}

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

using namespace std;

const int maxn = 3002;
int N;
using ld = long double;

ld dp[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	dp[0] = 1.0;
	cin >> N;
	ld pi;
	for (int i = 0; i < N; i++) {
		cin >> pi;
		for (int j = N; j >= 0; j--) {
			dp[j] = dp[j] * (1-pi);
			if (j) dp[j] += dp[j-1]*pi;
		}
	}

	ld ans = 0.0;
	for (int i = (N+1)/2; i <= N; i++) {
		ans += dp[i];
	}
	cout << fixed << setprecision(12) << ans << endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    string s;
    cin >> s;
    long long w = 0;
    long long ans = 0;
    int l = s.length();
    for (int i = 0; i < l; ++i){
        if (s[i] == 'W'){
            ans += i - w;
            w++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1336
#include<bits/stdc++.h>
#define mi (l+r>>1)
const int N=200005;
using namespace std;
struct dat{
	int od,ev;
}f[N],b[N*4],now;
inline dat Max(dat a,dat b){
	return {max(a.od,b.od),max(a.ev,b.ev)};
}
int n,a[N],mx,v,al,cx,cy,hx,hy,tpc,tph;
bool h[N],fl;
void chk(int k,int l,int r){
	if(r>v){
		if(l>v)now=Max(now,b[k]);
		else chk(k<<1,l,mi),chk(k<<1|1,mi+1,r);
	}
}
void mdf(int k,int l,int r){
	if(l<r)v>mi?mdf(k<<1|1,mi+1,r):
	mdf(k<<1,l,mi),b[k]=Max(b[k<<1],b[k<<1|1]);
	else b[k]=now;
}
inline bool sol(){
	now={-N,0},fl=0;
	if((mx=cx-cy+al)>=0){
		v=hy,chk(1,1,n),
		fl=((mx&1)&&now.od>=mx||(mx&1^1)&&now.ev>=mx);
		//cerr<<mx<<"???\n";
	}
	swap(cx,cy),swap(hx,hy);
	//cerr<<now.od<<'&'<<now.ev<<":"<<fl<<endl;
	return fl;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",a+i),
	a[i]>mx?mx=a[i],h[i]=1,al++:0;
	for(int i=1;i<n*4;i++)b[i].od=-N;
	for(int i=n;i;i--){
		now={-N,0},v=a[i],chk(1,1,n);
		now.od+=h[i]+1,now.ev+=h[i]+1;
		if(!h[i])swap(now.od,now.ev);
		mdf(1,1,n);
	}
	for(int i=1;i<=n;i++){
		tpc=cx,tph=hx,al-=h[i];
		a[i]>hx?hx=a[i],cx++:0;
		v=a[i],now={0,0},mdf(1,1,n);
		//cerr<<"after "<<i<<":"<<cx<<','<<hx<<'|'<<cy<<','<<hy<<'('<<al<<endl;
		if(sol()|sol())putchar('0');
		else{
			if(i<2)return puts("-1"),0;
			putchar('1'),cx=tpc,hx=tph,
			a[i]>hy?hy=a[i],cy++:0;
		}
	}
}

Measured memory_bytes: 8576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
//		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	//	String line = br.readLine();

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int ab = a+b;
		int bc = c+b;
		int ca = a+c;
int d = Math.min(ab,bc);

		System.out.println(Math.min(d,ca));

}
}

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

int d,score,i,j,k,pscore,cscore,id;
int c[26],s[365][26],last[26],t[365];
int day1,day2,v1,v2,csize,f,check[4];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> d;
  for(i=0;i<26;i++) {
    cin >> c[i];
  }
  for(i=0;i<d;i++) {
    for(j=0;j<26;j++) {
      cin >> s[i][j];
    }
  }
  for(i=0;i<d;i++) {
    for(j=0;j<26;j++) {
      int tscore=s[i][j];
      for(int k=0;k<26;k++) {
        if(k==j) continue;
        tscore-=c[k]*(i+1-last[k]);
      }
      if(j==0) score=tscore;
      else if(tscore>score) {
        score=tscore;
        t[i]=j;
      }
    }
    last[t[i]]=i+1;
  }
  int cnt=800000;
  while(cnt--) {
    day1=rand()%d;
    v1=rand()%26;
    if(t[day1]==v1) continue;
    check[0]=t[day1];
    check[1]=v1;
    csize=2;
    f=0;
    if(cnt%10==0) {
      day2=rand()%d;
      v2=rand()%26;
      if(day1!=day2&&t[day2]!=v2) {
        f=1;
        if(t[day1]!=t[day2]&&v1!=t[day2]) {
          check[csize++]=t[day2];
        }
        if(t[day1]!=v2&&v1!=v2) {
          check[csize++]=v2;
        }
      }
    }
    pscore=0;
    cscore=0;
    for(i=0;i<csize;i++) last[check[i]]=0;
    for(i=0;i<d;i++) {
      pscore+=s[i][t[i]];
      last[t[i]]=i+1;
      for(j=0;j<csize;j++) {
        int id=check[j];
        pscore-=c[id]*(i+1-last[id]);
      }
    }
    for(i=0;i<csize;i++) last[check[i]]=0;
    for(i=0;i<d;i++) {
      if(day1==i) {
        cscore+=s[i][v1];
        last[v1]=i+1;
      }
      else if(f&&day2==i) {
        cscore+=s[i][v2];
        last[v2]=i+1;
      }
      else {
        cscore+=s[i][t[i]];
        last[t[i]]=i+1;
      }
      for(j=0;j<csize;j++) {
        id=check[j];
        cscore-=c[id]*(i+1-last[id]);
      }
    }
    if(pscore<cscore) {
      t[day1]=v1;
      if(f) t[day2]=v2;
    }
  }
  for(i=0;i<d;i++) {
    printf("%d\n",t[i]+1);
  }
}

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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n, t;
	cin >> n >> t;
	vector<vector<int>> dp(n + 1, vector<int>(t + 1, -1e9));
	dp[0][0] = 0;
	vector<pair<int, int>> a(n + 1, {0, 0});
	for (int i = 1; i <= n; ++i){
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());
	for (int i = 1; i <= n; ++i){
		int time = a[i].first, del = a[i].second;
		for (int j = 0; j <= t; ++j){
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (j != t) dp[i][min(t, j + time)] = max(dp[i][min(t, j + time)], dp[i - 1][j] + del);
		}
	}
	int ans = 0;
	for (int i = 0; i <= t; ++i){
		ans = max(ans, dp[n][i]);
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 35584
import sys
K = int(input())
anss = [[i for i in range(1,10)]]
count = 9
if K <= 9:
  print(K)
  sys.exit()
for i in range(1,15):
  ans = []
  # これは昇順に並んでいるはず
  origin = anss[i-1]
  for o in origin:
    s = str(o)
    for j in range(10):
      if abs(int(s[-1]) - j) <= 1:
        a = int(s+str(j))
        count += 1
        if count == K:
          print(a)
          sys.exit()
        ans.append(a)
  anss.append(ans)

Measured memory_bytes: 6980
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    string s;
    cin >> s;
    map<char, int> mp;
    for (auto c : s) {
        mp[c]++;
    }
    int cnt = 0;
    for (auto p: mp) {
        if (p.second % 2) {
            cnt++;
        }
    }
    // cout << (cnt + 1) / 2 << endl;
    cout << cnt / 2 << endl;
}

Measured memory_bytes: 3160
int main(void){
    int k,k1,k2;
    scanf("%d",&k);
    k1 = k/2;
    k2 = ((k+1)/2)*((k-1)/2);
    if(k%2==0){
        printf("%d",k1*k1);
    }else{
        printf("%d",k2);
    }
    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int         long long
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
using namespace std;

signed main(){
    tezz   
    
    int n;
    cin >> n;
    string s1,s2;
    cin >> s1 >> s2 ;
    for(int i=0; i<n; i++){
        cout << s1[i] << s2[i] ;
    }
    
    
    return 0;
}   


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    
    int x,y;
     
    while(1){
    scanf("%d %d",&x,&y);
    if(x==0 && y==0) break;
    else if(x>y){
        printf("%d %d\n",y,x);
    }
    else printf("%d %d\n",x,y);
    }
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

ll dp[3003][3003][5];
const ll INF=1e18;

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

  int R,C,K;
  cin>>R>>C>>K;
  vector<int> r(K),c(K);
  vector<ll> v(K);
  rep(i,K) cin>>r[i]>>c[i]>>v[i];

  vector<vector<ll>> A(R,vector<ll> (C,0));
  rep(i,K){
    r[i]--;c[i]--;
    A[r[i]][c[i]]=v[i];
  }

  rep(i,R+1) rep(j,C+1) rep(k,5) dp[i][j][k]=-INF;
  dp[0][0][0]=0;
  dp[0][0][1]=A[0][0];
  for(int i=0;i<R;i++) for(int j=0;j<C;j++) for(int k=0;k<=3;k++){
    ll val=dp[i][j][k];
    if(val==-INF) continue;
    if(i+1<R){
      chmax(dp[i+1][j][0],val);
      chmax(dp[i+1][j][1],val+A[i+1][j]);
    }
    if(j+1<C){
      chmax(dp[i][j+1][k],val);
      if(k<3) chmax(dp[i][j+1][k+1],val+A[i][j+1]);
    }
  }

  ll ans=0;
  rep(i,4) chmax(ans,dp[R-1][C-1][i]);
  cout<<ans<<endl;

  return 0;
}


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

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

  int startb=0, enda=0, inab=0;
  bool loop=true;
  for(int i=0; i<n; ++i){
    string s; cin>>s;
    int x=s.size();
    if(s[0]=='B'){
      ++startb;
      if(s[x-1]!='A')loop=false;
    }
    if(s[x-1]=='A'){
      ++enda;
      if(s[0]!='B')loop=false;
    }
    for(int j=0; j<x-1; ++j){
      if(s[j]=='A' && s[j+1]=='B')++inab;
    }
  }

  int ans=0;
  if(startb==enda && startb>0 && loop)ans=inab+startb-1;
  else ans=inab+min(startb, enda);
  cout<<ans<<endl; 
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long long a;
    string b;
    cin >> a >> b;

    long long c = 100 * stoi(b) + stoi(b.substr(b.find('.') + 1));

    cout << a * c / 100 << "\n";

    return 0;
}


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


int main(){
   int n,k ;
   scanf("%d",&n);
   scanf("%d", &k);

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

   for(int &num : nums){
       scanf("%d", &num);
   }


   std::vector<int>dp(n, INT_MAX);
    dp[0]= 0 ;
   for(int i = 0; i < n ; ++i ){
       for(int j = i + 1 ; j <= i +k ; j++){
           if(j < n){
                dp[j] = std::min(dp[j], dp[i]+ abs(nums[i]-nums[j]));
                //std::cout << dp[j] << std::endl;
           }
       }
   }
  
    std::cout << dp[n-1] << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a+b>=k&&a<=k){
    cout<<a<<endl;
    return 0;
  }
  if(a+b>=k&&a>k){
    cout<<k<<endl;
    return 0;
  }
  cout<<a-(k-a-b)<<endl;
}

Measured memory_bytes: 3604
s=int(input())
n1=s//100
n2=s%100
if 0<n1<=12 and 0<n2<=12:
    print('AMBIGUOUS')
elif 0<n2<=12:
    print('YYMM')
elif 0<n1<=12:
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 2940
//
//  main.cpp
//  D
//
//  Created by 黄宇凡 on 2017/3/18.
//  Copyright © 2017年 黄宇凡. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 5005;

int n,k;

int a[maxn];

bool pre[maxn][maxn];
long long suf[maxn][maxn];



int main(int argc, const char * argv[]) {
    cin >> n >> k;
    long long sum = 0;
    for(int i = 1;i <= n;i++){
        scanf("%d",a + i);
        sum += a[i];
    }
    memset(pre,false,sizeof(pre));
    memset(suf,false,sizeof(suf));
    pre[0][0] = true;
    suf[n + 1][0] = 1;
    for(int i = 1;i <= n;i++){
        //pre[i][j] = pre[i - 1][j];
        for(int j = k;j >= 0;j--){
            pre[i][j] |= pre[i - 1][j];
            if(j >= a[i])pre[i][j] |= pre[i - 1][j - a[i]];
        }
    }
    for(int i = n;i >= 1;i--){
        for(int j = k;j >= 0;j--){
            suf[i][j] = suf[i + 1][j];
            if(j >= a[i]) suf[i][j] |= suf[i + 1][j - a[i]];
        }
    }
    for(int i = n + 1;i >= 1;i--){
        for(int j = 0;j <= k;j++){
            if(j == 0) continue;
            suf[i][j] += suf[i][j - 1];
        }
    }
    /*
    for(int i = 0;i <= n + 1;i++){
        for(int j = 0;j <= k;j++){
            if(j == 0) continue;
            else {pre[i][j] |= pre[i][j - 1];suf[i][j] |= suf[i][j - 1];}
        }
    }*/
    int ans = n;
    for(int i = 1;i <= n;i++){
        bool flag = false;
        //bool f = false;
        for(int j = 0;j <= k - 1;j++){
            if(pre[i - 1][j] && ((suf[i + 1][k - 1 - j] - ((k - 1 - a[i] - j) >= 0 ? suf[i + 1][k - 1 - a[i] - j] : 0)) > 0)) {flag = true;}
               // cout << suf[i + 1][k - 1 - j] << endl;
               // cout << "!" << suf[i + 1][k - 1 - a[i] - j] << endl;
               // cout << i << " " << "keyi" << j << endl;}
        }
        //cout << flag << endl;
        //cout << flag << " " << f << endl;
        if(flag) ans--;
       // if(!f) ans++;
    }
    //if(sum < (long long)k) ans += n;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 220416
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>

#define INF 1001001001
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main(){
    int r; cin >> r ;
    cout << r*r << endl;
    
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1145141;
int n;
char s0[N],s1[N];
int pre[N],lst[133];
int g[N];
int ans,tmp;
int main()
{
	scanf("%d%s%s",&n,s0+1,s1+1);
	int k=0,nw=n;
	for(int i=n;i;i--)
	{
		tmp+=g[i+k];
		if(nw>i||(s0[nw]!=s1[i]))
		{
			while(nw>0&&(nw>i||(s0[nw]!=s1[i]))) nw--;
			if(nw==i) continue;
			if(nw<=0){puts("-1");return 0;}
			k++,tmp++;
			g[i+k-1]=0,g[nw+k-1]--;
		}
		ans=max(ans,tmp);
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
int main(){
    char s;
    cin >> s;
    bool isVowel = false;
    if(s=='a'|| s=='i'||s=='u'||s=='e'||s=='o') isVowel = true;
    cout << (isVowel ? "vowel" : "consonant") << endl;
}

Measured memory_bytes: 256
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
#define maxval 100005
int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    int n;
    int h[maxval];
    scanf("%d",&n);
    vector<int>dp(n + 1,0);
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i=2;i<n;i++){
        dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1],abs(h[i] - h[i-2]) + dp[i-2]);
    }
    printf("%d\n",dp[n-1]);
	return 0;
}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define LEN(s)      (string(s)).length()
#define NPOS        string::npos
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<class T>string join(const vector<T>& v,string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(LEN(d));}

template<class T>ostream& operator<<(ostream& o,const vector<T>& v)
{o<<"{";if(SZ(v))o<<join(v,", ");o<<"}";return o;}

template<class T,class U>ostream& operator<<(ostream& o,const pair<T,U>& p)
{o<<"(";o<<p.first<<", "<<p.second;o<<")";return o;}

template<class T>bool contain(const string& s,const T& v)
{return s.find(v)!=NPOS;}

template<class T,class U>string& replace(string& s,const T& f,const U& t)
{for(auto p=s.find(f);p!=NPOS;p=s.find(f,p+LEN(t)))s.replace(p,LEN(f),t);}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll H, W; cin >> H >> W;
    
    vector<ll> abc(26, 0);
    REP(i, H) REP(j, W) {
        char c; cin >> c;
        abc[c - 'a']++;
    }
    
    ll g1, g2, g4;
    if (H % 2 and W % 2) {
        g1 = 1;
        g2 = H / 2 + W / 2;
        g4 = (H / 2) * (W / 2);
    } else if (H % 2) {
        g1 = 0;
        g2 = W / 2;
        g4 = (H / 2) * (W / 2);
    } else if (W % 2) {
        g1 = 0;
        g2 = H / 2;
        g4 = (H / 2) * (W / 2);
    } else {
        g1 = 0;
        g2 = 0;
        g4 = (W / 2) * (H / 2);
    }
    
    if (g1) REP(i, 26) if (abc[i] % 2 == 1) {
        abc[i]--;
        g1 = 0;
        break;
    }
    
    while (g4 > 0) {
        bool ng = true;
        REP(i, 26) if (abc[i] >= 4) {
            abc[i] -= 4;
            g4--;
            ng = false;
            break;
        }
        if (ng) break;
    }
    
    while (g2 > 0) {
        bool ng = true;
        REP(i, 26) if (abc[i] >= 2) {
            abc[i] -= 2;
            g2--;
            ng = false;
            break;
        }
        if (ng) break;
    }
    
    if (g1 > 0 or g2 > 0 or g4 > 0) {
        cout << "No" << endl;
        return 0;
    }
    
    REP(i, 26) if (abc[i] != 0) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
n, m = gets.chomp.split(" ").map(&:to_i)
p = Array.new(n,0)
m.times do
  a, b = gets.chomp.split(" ").map(&:to_i)
  p[a-1] += 1
  p[b-1] += 1
end
p.each do |v|
  puts v
end

Measured memory_bytes: 1788
N,K= list(map(int, input().split())) 

ans = [0]*(N+1)

for i in range(K):
    d = int(input())
    A = list(map(int, input().split())) 
    for j in range(d):
        ans[A[j]] = 1

res = len(ans)-1-sum(ans)
print(res)
        
    

Measured memory_bytes: 9184
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

 void solve (vector <vector <pll>> &K,int x,ll kiek,ll sukiek,ll &liek) {
	 kiek=kiek%liek;
	 for (int i=0;i<(int)K[x].size();i++) {
		 if (K[x][i].second==sukiek) {K[x][i].first+=kiek; K[x][i].first=K[x][i].first%liek; return;}
		 }
		 K[x].push_back({kiek%liek,sukiek});return;
	 }
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,s;
    cin>>n>>s;
    vector <ll> A;
    vector <ll> D(n+1);
    ll liek=998244353;
    D[0]=1;
    ll d=2;
    for (int i=1;i<=n;i++) {D[i]=d; d=(2*d)%liek;}
    for (int i=0;i<n;i++) {
		int a;
		cin>>a;
		if (a<=s) {A.push_back(a);}
		}
	vector <ll> K(s+1);
	for (int i=0;i<(int)A.size();i++) {
		for (int k=s-A[i];k>=0;k--) {
			ll x;
			if (K[k]%2==0) {x=K[k]/2;}
			else {x=(K[k]+liek)/2;}
			K[k+A[i]]+=x;
			K[k+A[i]]=K[k+A[i]]%liek;
			}
			K[A[i]]+=D[n-1];
			K[A[i]]=K[A[i]]%liek;
		}

	cout<<K[s]<<endl;
    return 0;
}


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

string S;

int main() {
    cin >> S;
    
    deque<char> deq;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'B') {
            if (deq.size() > 0) {
                deq.pop_back();
            }
        }
        else {
            deq.push_back(S[i]);
        }
    }

    while (deq.size() > 0) {
        cout << deq.front();
        deq.pop_front();
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()
    


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

using namespace std;

template<typename T>
struct BIT {
  std::vector<T> node;
  BIT(int n) : node(n+1, 0) {}
  void add(int idx, T w) {
    for (int i = idx; i < node.size()-1; i |= (i + 1)) {
      node[i] += w;
    }
  }
  T sum(int r) {
    T ret = 0;
    for (int i = r-1; i >= 0; i = ((i & (i+1)) - 1) ) {
      ret += node[i];
    }
    return ret;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l);
  }
};

int main() {
  int n, q;
  string s;
  cin >> n >> s >> q;

  vector<BIT<int>> trees(26, BIT<int>(n+10));
  for (int i = 0; i < n; i++) { trees[s[i]-'a'].add(i, 1); }

  while (q--) {
    int type; cin >> type;
    if (type == 1) {
      int idx; char c; cin >> idx >> c;
      idx--;
      int prev_c = s[idx] - 'a';
      int next_c = c - 'a';
      trees[prev_c].add(idx, -1);
      trees[next_c].add(idx, 1);
      s[idx] = c;
    }
    if (type == 2) {
      int l, r; cin >> l >> r;
      int ret = 0;
      for (int i = 0; i < 26; i++) {
        ret += (trees[i].sum(l-1, r) != 0);
      }
      cout << ret << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<int> count('z'-'a'+1,(1 << 28));
	for (int q = 0; q < n; ++q) {
		string str;
		cin >> str;
		vector<int> now('z'-'a'+1,0);
		for (int i = 0; i < str.length(); ++i) {
			++now[str[i]-'a'];
		}
		for (int i = 0; i < count.size(); ++i) {
			count[i] = min(count[i],now[i]);
		}
	}

	for (int i = 0; i < count.size(); ++i) {
		for (int j = 0; j < count[i]; ++j) {
			cout << (char)('a'+i);
		}
	}
	cout << endl;

	return 0;
}


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

using namespace std;

int main(void)
{
  int tannka[5] = {5, 7, 5, 7, 7};
  
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    int w;
    vector<string> v;
    v.resize(n);
    
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }
    
    //?????????1~5??????  //??\???????????°
    pair<int,int> count = make_pair(0,0);
    for (int i = 0; i < n; i++) {
      string str = v[i];
      //?????????1?????????5????????\?????????
      if (tannka[count.first] >= str.size()) {
	w = i;
	//5????????????
	if (tannka[count.first] == str.size()) {
	  count.first++;
	  count.second = 0;
	}
	//5??????????????????
	else {
	  count.second += str.size();
	}
	
	//?????????1?????????2?????????5??????
	for (int j = i+1; j < n; j++) {
	  str = v[j];
	  if (tannka[count.first] - count.second > str.size()) {
	    count.second += str.size();
	  } else if (tannka[count.first] - count.second == str.size()) {
	    count.first++;
	    count.second = 0;
	  } else {
	    count = make_pair(0,0);
	    break;
	  }
	  //???????????´??£???
	  if (count.first == 5) {
	    cout << w+1 << endl;
	    break;
	  }
	}

	if (count.first == 5)
	  break;
	
      }
      //?????????1?????????5????????§??????
      else { }
    }
  }
  return 0;
}

Measured memory_bytes: 3028
#include <iostream>

using namespace std;

constexpr int N = 1000001, mod = 1000000007;

int64_t da[N], ans = 1, cv = 1;

int64_t prod(int64_t a, int64_t b) {return a * b % mod;}
int64_t mul(int64_t &a, int64_t b) {return (a *= b) %= mod;}
int64_t add(int64_t &a, int64_t b) {return (a += b) %= mod;}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        add(da[i + 3], add(cv, add(da[i], da[i - 1]))),
        add(ans, prod(cv, prod(n - 1, i == n? 1: n)));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;

int main(void){
    scanf("%d%d",&n,&k);
    int ans=1;
    for(int i=1;i<k;i++){
        ans+=2;
    }
    printf("%s\n",ans<=n?"YES":"NO");
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    bool flag = false;
    REP(i, 9) {
        if(n / (i + 1) < 10 && n % (i + 1) == 0) flag = true;
    }
    cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
n=int(input())
mod=10**9+7
edge=[[] for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)

inv2=[1]*(n+1)
t=pow(pow(2,n,mod),mod-2,mod)
for i in range(n,-1,-1):
    inv2[i]=t
    t*=2
    t%=mod
    
import sys
sys.setrecursionlimit(10**6)
dep=[-1 for i in range(n+1)]
ans=[0]
def f(a):
    return inv2[n-a]*(1-inv2[a])%mod
def dfs(s,d):
    dep[s]=d
    tmp=inv2[1]-inv2[n]
    y=0
    for i in edge[s]:
        if dep[i]==-1:
            x=dfs(i,d+1)
            tmp-=f(x)
            y+=x
    if y==0:
        return 1
    tmp-=f(n-y-1)
    ans[0]+=tmp
    ans[0]%=mod
    return y+1
dfs(1,0)
print(ans[0])

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

using namespace std;
//x % k = q nx % k = nq % k 
bool cmp(int a, int b)
{
	return a < b;
}
int L, R, ans1 = 100000000, ans2, ans3, ans4;
int main()
{
	cin >> L >> R;
	if(L <= 2019 && R <= 2019)
	{
		for(int i = L; i <= R; i++)
			for(int j = i+1; j <= R; j++)
			{
				int sum = (i * j) % 2019;
				if(sum <= ans1)
					ans1 = sum;
			}
	}
	else
	{
		int a = L % 2019, b = R % 2019;
		if(a >= b)
		{
			cout << '0';
			return 0;
		}
		else//a<b l<=2019n r>=2019n
		{
			if(R - L >= 2019)
			{
				cout << '0';
				return 0;
			}
			else
			{
				for(int i = a; i <= b; i++)
					for(int j = i+1; j <= b; j++)
					{
						int sum2 = (i * j) % 2019;
						if(sum2 <= ans1)
							ans1 = sum2;
					}
			}
		}
	}
	cout << ans1;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

void mergesort(long array[],int top,int end) //昇順にソート
{
  int mid;

  if(top >= end)
    {
      return;
    }

  mid = (end+top) / 2;

  mergesort(array,top,mid);

  mergesort(array,mid+1,end);

  long *left,*right,n1,n2,i,j,k;
  n1 = mid - top + 1;
  n2 = end - mid;
  left = (long *)malloc(sizeof(long)*(n1+1));
  right = (long *)malloc(sizeof(long)*(n2+1));
  
  j=0;
  for(i=top;i<=mid;i++)
    {
      left[j] = array[i];
      j++;
    }
  
  j=0;
  for(i=mid+1;i<=end;i++)
    {
      right[j] = array[i];
      j++;
    }
  
  left[n1] = LONG_MAX;
  right[n2] = LONG_MAX;
  
  i=0; j=0;
  for(k=top;k<=end;k++)
    {
      if(left[i] <= right[j])
	{
	  array[k] = left[i];
	  i++;
	}
      else
	{
	  array[k] = right[j];
	  j++;
	}
    }
  
  free(left);
  free(right);
}

int main(void)
{
  int n,m,i,j;
  scanf("%d %d",&n,&m);
  long x[n],y[n],z[n],sort[n];
  long max=0,temp1=0,tmpx,tmpy,tmpz;
  int bx[8]={1,1,1,1,-1,-1,-1,-1},by[8]={1,1,-1,-1,1,1,-1,-1},bz[8]={1,-1,1,-1,1,-1,1,-1};
  for(i=0;i<n;i++)
    {
      scanf("%ld %ld %ld",&x[i],&y[i],&z[i]);
    }
  for(i=0;i<8;i++)
    {
      for(j=0;j<n;j++)
	{
	  tmpx = bx[i]*x[j];
	  tmpy = by[i]*y[j];
	  tmpz = bz[i]*z[j];
	  sort[j] = tmpx+tmpy+tmpz;
	}
      mergesort(sort,0,n-1);

      /*for(j=0;j<n;j++)
	{
	  printf("%lld ",sort[j]);
	}
	printf("\n");*/
      temp1=0;
      for(j=0;j<m;j++)
	{
	  temp1 += sort[n-1-j];
	}
      //printf("%lld %lld\n\n",temp1,temp2);
      if(max < labs(temp1))
	{
	  max = labs(temp1);
	}
      //printf("max:%lld\n\n",max);
    }

  printf("%ld\n",max);
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
 
class Combination():
    # コンストラクタ
    def __init__(self, N:int, P:int):
        self.N = N
        self.P = P
 
        # fact[i] = (i! mod P)
        self.fact = [1, 1]   
        # factinv[i] = ((i!)^(-1) mod P)
        self.factinv = [1, 1]
        # factinv 計算用
        self.inv = [0, 1]    
 
        for i in range(2, N+1):
            self.fact.append((self.fact[-1] * i) % P)
            self.inv.append((-self.inv[P % i] * (P // i)) % P)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % P)
    
    # nCk (mod P)   (ただし、n<=N)
    def getComb(self, n:int, k:int):
        if (k < 0) or (n < k):
            return 0
        k = min(k, n - k)
        return self.fact[n] * self.factinv[k] * self.factinv[n-k] % self.P
 
def main():
    N,K = map(int,input().split())
    A = sorted([int(i) for i in input().split()])
 
    mod = 10**9+7
 
    COMB = Combination(N,mod)
 
    cmb = [0] * (N-K+1)
    for i in range(N-K+1):
        cmb[i] = COMB.getComb(i+(K-1),K-1)
 
    sum_max = 0
    for i in range(K-1,N):
        sum_max = (sum_max + cmb[i-(K-1)] * A[i]) % mod
 
    sum_min = 0
    for i in range(N-K,-1,-1):
        sum_min = (sum_min + cmb[(N-K)-i] * A[i]) % mod
 
    answer = sum_max - sum_min
    print(answer % mod)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 22552
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = uint_fast16_t; using ld = long double; using namespace std;
class CountOrder
{
	ll N{0};
	vector<ll> p, q;
	void inp( ) {
		iss >> N; p.resize(N); q.resize(N);
		rep(n, N) { iss >> p[n]; }
		rep(n, N) { iss >> q[n]; }
		//for_each(begin(p), end(p), [](auto x) { cout << x << "\n"; });
	}
	void change( ) {
		long long sa{0};
		if (p > q) swap(p, q);
		do {
			if (p == q) break;
			++sa;
		} while (next_permutation(begin(p), end(p)));
		p(sa);
	}
public:
	void procedures( ) {
		inp( );
		change( );
	}
};
//https://atcoder.jp/contests/abc145/tasks/abc145_c
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	cout << fixed << setprecision(15);
	class CountOrder a; a.procedures( );
}

Measured memory_bytes: 3628
#include<iostream>


#define maxn 100005
#define ll long long 
using namespace std;

ll DP[maxn];
int N;
int height[maxn];

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

ll cal(int pos) {
	if (pos == N - 1) return 0LL;


	ll& res = DP[pos];

	if (res != -1) return res;

	res = abs(height[pos] - height[pos + 1]) + cal(pos + 1);
	if (pos + 2 < N)
		res = min(res, abs(height[pos] - height[pos + 2]) + cal(pos + 2));
	return res;
}


int main() {

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

	for (int i = 0; i < maxn; i++) {
		DP[i] = -1;
	}

	cout << cal(0) << endl;



	return 0;
}

Measured memory_bytes: 4480
/* Simplicity and Goodness */
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;

void solve()
{
    int x, n;
    scn(x); scn(n);

    vector<int> used(200, 0);

    rep(i, 0, n) {
        int val;
        scn(val);

        used[val] = 1;
    }

    int mn = inf, mndf = inf;

    rep(i, 0, 200) {
        if(used[i])
            continue;

        if(abs(x - i) < mndf) {
            mndf = abs(x - i);
            mn = i;
        }
    }

    prin(mn);
}

int main()
{
    int t = 1;
    // scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    ll n;
    cin >> n;
    if (n & 1) {
        puts("0");
        return 0;
    }

    n >>= 1;
    ll ans = 0;
    while(n) {
        ans += n/5;
        n /= 5;
    }

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

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

using namespace::std;

int main()
{
    string s;
    cin >>s;
    int flag = 1; 

    for(int i=0; i<s.length();i++)
    {
        //cout << s[i] << "  and i is " <<i<<" ";
        if(i%2==1)
        {
            if(s[i]!='L' && s[i]!='U' && s[i]!='D')
            {
                //cout << s[i] << "  and i is " <<i<<" ";
                flag =0;
            }
        }
        if(i%2==0)
        {
            if(s[i]!='R' && s[i]!='U' && s[i]!='D')
            {
                //cout << s[i] << "  and i is " <<i<<" ";
                flag =0;
            }
        }
    }
    if(flag ==0)
    {
        cout << "No"<<endl;
    }
    else
        cout << "Yes" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define FIB_MAX 44
int fibbuf[FIB_MAX+1];

int fib(int n)
{
	if(n < 2){
		return(1);
	}else if(0 < fibbuf[n]){
		return(fibbuf[n]);
	}
	fibbuf[n] = fib(n - 1) + fib(n - 2);
	return(fibbuf[n]);
}

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d\n", fib(n));

	return(0);
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%mod)
#define mod 1000000007
#define pb push_back
#define STREAM_FAST ios::sync_with_stdio(false)
using namespace std;
int n, bx, xa, ba;
int main()
{
	scanf("%d", &n);
	int ans = 0;
	char s[20];
	for (int i = 1; i <= n; i++)
	{
		scanf(" %s", s);
		int L = strlen(s);
		for (int j = 0; j < L - 1; j++)
		{
			if (s[j] == 'A' && s[j + 1] == 'B') ans++;
		}
		if (s[0] == 'B' && s[L - 1] != 'A') bx++;
		else if (s[0] != 'B' && s[L - 1] == 'A') xa++;
		else if (s[0] == 'B' && s[L - 1] == 'A') ba++;
	}
	if (xa > 0 && bx > 0)
	{
		ans += (ba + 1);
		xa--; bx--;
		ans += min(xa, bx);
	}
	else if (xa == 0 && bx == 0) 
	{
		if (ba > 0)	ans += (ba - 1);
	}
	else 
	{
		ans += ba;
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

string s;
ll ans = 0;
int main() {
    cin>>s;

    int n = s.size();
    string x = "S"; //tekitou
    vi cumsum;
    cumsum.emplace_back(0);
    REP(i,n-1){
        if(s[i]=='B' && s[i+1]=='C'){
            x += "X";
            cumsum.emplace_back(cumsum.back()+1);
            i++;
        }else{
            x += s[i];
            cumsum.emplace_back(cumsum.back());
        }
    }
    cumsum.emplace_back(cumsum.back());

    //DEBUG(x);
    //DEBUG_VEC(cumsum);

    n = x.size();
    vi apos;
    REP(i,n){
        if(x[i]=='A'){
            apos.emplace_back(i);
            //continue;
        }

        if(x[i]=='B' || x[i]=='C' || i==n-1){
            REP(j,apos.size()){
                ans += cumsum[i] - cumsum[apos[j]];
            }
            apos.clear();
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3196
import Control.Applicative
import Data.List

main = do
    [n,m] <- sort . map read . words <$> getLine
    print $ solve n m

solve n m 
    | n == 1 && m == 1 = 1
    | n == 1 && m /= 1 = m-2
    | otherwise = (n-2)*(m-2)


Measured memory_bytes: 508
n, m= gets.chomp.split.map(&:to_i)
a = Array.new(n).map{Array.new(2)}
n.times do |i|
    a[i] = gets.chomp.split.map(&:to_i)
end

a.sort!
ans = 0
while m > 0 do
    
    if m > a[0][1] then
        ans += a[0][0] * a[0][1]
    else
        ans += a[0][0] * m
    end
   m -= a[0][1]
   a.shift
end

puts ans

Measured memory_bytes: 17684
N, K = [int(i) for i in input().split()]

if K == 0:
    print(N * N)
else:
    count = 0
    for i in range(K + 1, N + 1):
        amari = N % i
        warikiriru = N - amari

        count += warikiriru - int(warikiriru / i) - int(warikiriru / i) * (K - 1)
        # print("w", warikiriru - int(warikiriru / i) - int(warikiriru / i) * (K - 1))
        if amari >= K:
            count += amari - (K - 1)
            # print("a", amari - (K - 1))

    print(count)

Measured memory_bytes: 3064
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int n  = sc.nextInt();
        int[] h = new int[n];
        int ans = 1;
        for(int i = 0; i < n; i++){
          h[i] = sc.nextInt();
        }
        
        for(int i = 1; i < n; i++){
          int num = 0;
          for(int j = 0; j < i; j++){
            if(h[i] >= h[j]){
              num++;
            }
          }
          
          if(num == i){
            ans++;
          }
        }
      
        System.out.println(ans);
	}
}

Measured memory_bytes: 35692
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    vector<long long> A(N), B(N);
    long long a = 0, b = 0;
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    for ( int i = 0; i < N; i++ ) {
        cin >> B[i];
    }
    for ( int i = 0; i < N; i++ ) {
        if ( A[i] < B[i] ) { a += ( B[i]-A[i] )/2; }
        else if ( A[i] > B[i] ) { b += A[i]-B[i]; }
    }
    
    cout << ( a >= b ? "Yes" : "No" ) << endl;
    
    
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if(a == b) cout << "Draw" << endl;
  else if(a == 1) cout << "Alice" << endl;
  else if(b == 1) cout << "Bob" << endl;
  else if(a > b) cout << "Alice" << endl;
  else cout << "Bob" << endl;
}

Measured memory_bytes: 256