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

string S;
string table = "ABC";

bool solve(){
    while(S.size() > 3){
        set<char> s;
        int n = S.size();
        string t = "";
        vector<string> vt;
        for(int i=0; i<n; i++){
            bool ok = true;
            for(int j=0; j<3; j++){
                if(i+j >= n || S[i+j] != table[j])
                    ok = false;
            }
            
            if(ok){
                i += 2;
                vt.push_back(t);
                t = "";
            }else{
                t += S[i];
                s.insert(S[i]);
            }
        }
        vt.push_back(t);
        
        if(s.size() != 2)
            return false;
        if(vt.size() == 1)
            return false;
        
        char c = '\0';
        for(int i=0; i<3; i++)
            if(s.find(table[i]) == s.end())
                c = table[i];
            
        S = "";
        for(int i=0; i<vt.size(); i++){
            S += vt[i];
            if(i != vt.size()-1)
                S += c;
        }
    }
    return "ABC" == S;
}

int main(){
    cin >> S;
    cout << (solve()? "Yes": "No") << endl;
    return 0;
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll bi[514514];
void add(ll n,ll i,ll x){
	for(;i<=n;i+=i&-i)bi[i]+=x;
}
ll sum(ll i){
	ll num=0;
	for(;i>0;i-=i&-i)num+=bi[i];
	return num;
}
ll c[514514],g[514514],ans[514514];
int main(){
	ll n,q;
	cin>>n>>q;
	vector<vector<ll>>v(n+1),w(n+1);
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=0;i<q;i++){
		ll l,r;
		cin>>l>>r;
		v[r].push_back(l);
		w[r].push_back(i);
	}
	for(int i=1;i<=n;i++){
		if(g[c[i]])add(n,g[c[i]],-1);
		add(n,i,1);
		g[c[i]]=i;
		ll cnt=0;
		for(ll p:v[i]){
			ans[w[i][cnt]]=sum(i)-sum(p-1);
			cnt++;
		}
	}
	for(int i=0;i<q;i++)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 62664
import java.util.*;
public class Main {
	static ArrayList<Long> max;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long array[] = new long[num];
		for(int i = 0; i < num; i ++) {
			array[i] = sc.nextLong();
		}
		max = new ArrayList<>();
		for(int i = 0; i < num; i ++) {
			int index = bisect(array[i]);
			if(index == max.size()) {
				max.add(array[i]);
			}else {
				max.set(index, array[i]);
			}
		}
		System.out.println(max.size());
	}

	static int bisect(long key) {
		int ng = -1;
		int ok = max.size();
		while (Math.abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			if(isOK(mid, key)) {
				ok = mid;
			}else {
				ng = mid;
			}
		}
		return ok;
	}
	static boolean isOK(int index, long key) { return max.get(index) < key; }
}

Measured memory_bytes: 56728
N = int(input())
A = list(map(lambda x:int(x),input().split(" ")))
B = list(map(lambda x:int(x),input().split(" ")))
C = list(map(lambda x:int(x),input().split(" ")))

sat = 0
prev_a = N
for i in range(N):
  a = A[i]
  sat += B[a-1]
  if prev_a+1==a:
    sat += C[a-2]
  prev_a = a

print(sat)

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

ll lcm(ll x, ll y){
    if(x == 0 || y == 0)
        return 0;
    return (x * y / __gcd(x, y));
}
 
int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    
    ll ans = B - A + 1;
    // Cの倍数
    ans -= B/C - A/C;
    if(A%C == 0)
        ans--;
    // Dの倍数
    ans -= B/D - A/D;
    if(A%D == 0)
        ans--;
    // C*Dの倍数
    ans += B/(lcm(C, D)) - A/(lcm(C, D));
    if(A%(C*D) == 0)
        ans++;
    
    cout << ans << endl;

}

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

using namespace std;

int main() {
	int N, A, B;	cin >> N >> A >> B;
	int plan1, plan2;

	plan1 = A*N;
	plan2 = B;

	if (plan1 < plan2) {
		cout << plan1 << endl;
		return 0;
	}
	else if (plan1 > plan2) {
		cout << plan2 << endl;
		return 0;
	}

	cout << plan1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int S = 0;
  int n = N;
  while(n){
    S += n % 10;
    n /= 10;
  }
  if(N % S) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ret;
    if (a > b) ret = 0; 
    else if (n == 1) ret = (a==b) ? 1 : 0;
    else {
        ret = (n-1)*b+a;
        ret -= (n-1)*a+b;
        ret += 1;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char s[11]; scanf("%s",s);
	
	int l=strlen(s);
	int a[11],i,j,c=(1<<(l-1));
	long long sum,t;
	for(i=0;i<l;i++)a[i]=s[i]-'0';
	sum=0;
	for(i=0;i<c;i++){
		t=a[0];
		for(j=0;j<l;j++)
		{
			if(j==l-1||i&1<<j)
			{
				sum+=t;t=0;if(j==l-1)break;
			}
			t*=10;
			t+=a[j+1];
		}
	}
	printf("%lld",sum);
}

Measured memory_bytes: 128
program sample
    implicit none
    
    integer(8) :: i,j,m,n
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    allocate(x(n))
    read(*,*)x
    m=x(1)
    do i=1,n-1
        if(x(i+1)>x(i))then
            m=m+x(i+1)-x(i)
        end if
    end do
    write(*,*)m
    stop
end program sample
  



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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    ll taro=0,hanako=0;
    rep(i,n){
        string s,t; cin>>s>>t;
        if(s==t){
            taro++;
            hanako++;
        }else if(s<t) hanako+=3;
        else taro+=3;
    }
    cout<<taro<<" "<<hanako<<endl;
    return 0;
}


Measured memory_bytes: 3152
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> cnts(n + 123, 0);

    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        cnts[l] += 1;
        cnts[r + 1] -= 1;
    }

    long long sum = 0;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        sum += cnts[i];
        if (sum == m) {
            ++res;
        }
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;

int main(){
fastIO;
#ifdef LOCAL
     freopen("in.txt", "r", stdin);
#endif

int n;
cin>>n;
//cout<<n/100<<endl;
//cout<<n%100<<endl;
int aux1 = n/100;
int aux2 = n%100;
if(aux1>=1 && aux1<=12){
    //MMYY || Ambi
    if(aux2>=1 && aux2<=12){
        cout<<"AMBIGUOUS"<<endl;
    }else{
        cout<<"MMYY"<<endl;
    }
}else{
    //YYMM || NA
    if(aux2>=1 && aux2<=12){
        cout<<"YYMM"<<endl;
    }else{
        cout<<"NA"<<endl;
    }
}
}


Measured memory_bytes: 3624
#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<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
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++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

int n, m;
vector<ll> a;

bool can(ll x) {
	ll cur = 1;
	rep(i, m-2) {
		int id = lower_bound(a.begin(), a.end(), cur) - a.begin();
		ll add = 0;
		if (id != n) {
			add= max((ll)1, x-(a[id] - cur));
		}
		if (id != 0) {
			add = max(add, max((ll)1, x-(cur - a[id - 1])));
		}
		cur += add;
	}
	//cout << cur << endl;
	return cur + x <= a[n - 1];
}
void solve() {
	while (cin >> n >> m, n) {
		a.clear();
		a.resize(n);
		rep(i, n) {
			cin >> a[i];
		}
		int le = -1, ri = 2000000;
		while (ri - le > 1) {
			int mid = (ri + le) / 2;
			if (can(mid))le = mid;
			else ri = mid;
		}
		if (1 + le <= a[0])le = -1;
		cout << le << endl;
		//cout << can(le+1)<<" hello?" << endl;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 3964
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            char[] c = sc.nextLine().toCharArray();
            if(c[0] == '0') break;
            int sum = c[0] - '0';
            for(int i = 1,l = c.length;i < l;++i) sum += c[i] - '0';
            System.out.println(sum);
        }

    }

}

Measured memory_bytes: 26692
package main

import (
	"fmt"
)

func main() {
	var bs []byte
	fmt.Scan(&bs)
	switch bs[len(bs)-1] {
	case '2', '4', '5', '7', '9':
		fmt.Println("hon")
	case '0', '1', '6', '8':
		fmt.Println("pon")
	case '3':
		fmt.Println("bon")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1752
"use strict";
function main(arg) {
    const inputs = arg.split("\n")
    const N = parseInt(inputs[0].split(" ")[0])
    const K = parseInt(inputs[0].split(" ")[1])
    const list = inputs.slice(1,N+1).map((x)=>parseInt(x)).sort((a,b)=>{return a-b})
    let i, sa = []
    for(i=0; i<N-K+1; ++i)
        sa.push(list[i+K-1] - list[i])
    console.log(Math.min(...sa))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 31912
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
#define dist(a,b)(((a)<(b))?(b)-(a):(a)-(b))
#define df 0

int magic(vector<int> a,vector <int> l,int n,int trial){
  std::vector<int> count(4,0);
  std::vector<int> sum(4,0);
  for(int i=0;i<n;i++){
    int x=trial%4;
    count[x]++;
    sum[x]+=l[i];
    trial/=4;
  }
  int s=0;
  for(int i=0;i<3;i++){
    if(count[i]==0)return -1;
    s+=dist(a[i],sum[i]);
    s+=10*(count[i]-1);
  }
  return s;
}
void debug(vector<int> a,vector <int> l,int n,int trial);
int main(){
  int n; cin >> n;
  std::vector<int> a(3);
  for(int i=0;i<3;i++) cin >> a[i];
  std::vector<int> l(n);
  for(int i=0;i<n;i++) cin >> l[i];
  int min=4000;
  for(int i=0,end=std::pow(4,n);i<end;i++){
    int x=magic(a,l,n,i);
    if(x>=0 && x<min){
      if(df){
	cout << i << ":" << x << "\n";
	debug(a,l,n,i);
      }      
      min=x;
    }
  }
  cout << min; 
}

void debug(vector<int> a,vector <int> l,int n,int trial){
  std::vector<int> count(4,0);
  std::vector<int> sum(4,0);
  cout << "try" << trial << "\n";
  for(int i=0;i<n;i++){
    int x=trial%4;
    cout << "[" << i << "(" << l[i] << ")->" << x << "] ";
    count[x]++;
    sum[x]+=l[i];
    trial/=4;
  }
  cout << "\n";
  int s=0;
  for(int i=0;i<3;i++){
    cout << "dist(" << a[i] << "," << sum[i] << ")="
	 << dist(a[i],sum[i]) << "\n";
  }
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

struct edge
{
    int to; ll cost;
    edge(int to, ll cost) : to(to), cost(cost) {}
};

vector<ll> dijkstra(const vector<vector<edge>> &g, int s)
{
    using P = pair<ll, int>;

    priority_queue<P, vector<P>, greater<P>> q;
    vector<ll> dist(g.size(), linf);

    dist[s] = 0; q.emplace(0, s);
    while (!q.empty()) {
        ll d; int now;
        tie(d, now) = q.top(); q.pop();
        if (dist[now] < d) continue;
        for (auto &e: g[now]) {
            if (dist[e.to] > d + e.cost) {
                dist[e.to] = d + e.cost;
                q.emplace(dist[e.to], e.to);
            }
        }
    }
    return move(dist);
}

int main()
{
    int v, e, r; cin >> v >> e >> r;

    vector<vector<edge>> g(v);
    for (int i = 0; i < e; i++) {
        int s, t, d; cin >> s >> t >> d;
        g[s].emplace_back(t, d);
    }

    auto dist = dijkstra(g, r);

    for (int i = 0; i < v; i++) {
        if (dist[i] >= linf) cout << "INF" << '\n';
        else cout << dist[i] << '\n';
    }
    return 0;
}



Measured memory_bytes: 19476
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    string S;
    cin>>S;
    char c[1000]={0};
    int ci=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='0') c[ci++]='0';
        if(S[i]=='1') c[ci++]='1';
        if(S[i]=='B'&&ci!=0) c[--ci]=0;
    }
    cout<<c<<endl;
}


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

Measured memory_bytes: 1024
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    boolean[] colorUnder3200 = new boolean[9];
    int rate = 0;
    int numOver3200 = 0;
    boolean allOver3200 = true;
    String[] data = br.readLine().split(" ");
    for(String score: data){
      rate = Integer.parseInt(score)/400;
      if(rate<8) {
        colorUnder3200[rate] = true;
        allOver3200 = false;
      } else {
        numOver3200++;
      }
    }
    int base = 0;
    for(boolean b: colorUnder3200){
      if(b) base++;
    }
    int max = base + numOver3200;
    int min = base==0 ? 1 : base;
    System.out.println(min + " " + max);
  }
}


Measured memory_bytes: 21204
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

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

	int c = t / a * b;

	cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int a = in(),b = in();
    string as = "",bs = "";
    REP(i,b)as += a+'0';
    REP(i,a)bs += b+'0';
    cout << (a < b ? as : bs) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main() {

	int k, s;
	int cnt = 0;
	
	cin >> k >> s;
	
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
				if (s - (x + y) <= k && s - (x + y) >= 0)
						cnt++;
			}
	}
	
	cout << cnt << endl;

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n], k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int dist = 2 * a[n - 1];
    for (int i = 0; i < n - 1; i++) {
        if (abs(2 * a[i] - a[n - 1]) < dist) {
            dist = abs(2 * a[i] - a[n - 1]);
            k = a[i];
        }
    }
    cout << a[n - 1] << ' ' << k;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;

int main(){
    int x = 9;
    vector<int> a(x);
    for(int i = 0; i < x; i++){
        cin >> a[i];
    }
    int n;
    cin >> n;
    vector<int> f(n);
    for(int i = 0; i < n; i++){
        cin >> f[i];
        for(int j = 0; j < x; j++){
            if(f[i] == a[j]){
                a[j] = 0;
            }
        }
    }
    if((a[0]==0&&a[1]==0&&a[2]==0)||(a[0]==0&&a[4]==0&&a[8]==0)||(a[3]==0&&a[4]==0&&a[5]==0)||(a[6]==0&&a[7]==0&&a[8]==0)||(a[0]==0&&a[3]==0&&a[6]==0)||(a[1]==0&&a[4]==0&&a[7]==0)||(a[2]==0&&a[5]==0&&a[8]==0)||(a[2]==0&&a[4]==0&&a[6]==0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }        
}

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

ll b[100][100];
ll sum[110][110];

ll S(int x1, int y1, int x2, int y2) {
	return sum[y2 + 1][x2 + 1] - sum[y2 + 1][x1] - sum[y1][x2 + 1] + sum[y1][x1];
}

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

	int n;
	cin >> n;

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin >> b[i][j];
		}
	}

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			sum[i + 1][j + 1] = sum[i + 1][j] + b[i][j];
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			sum[i + 1][j] += sum[i][j];
		}
	}

	ll ans = -1e18;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			for(int k = i; k < n; k++) {
				for(int l = j; l < n; l++) {
					ans = max(ans, S(j, i, l, k));
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3260
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
typedef long long ll;

int n;
int m;

int main() {
	bool w[9][9] = {false};
	ll ans = 0;
	cin >> n >> m;
	vector<int> a(30), b(30);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		w[a[i]][b[i]] = true;
		w[b[i]][a[i]] = true;
	}
	vector<int> per(n);
	rep(i, n) per[i] = i + 1;
	do {
		if (per[0] != 1) break;
		bool exist = true;
		for (int i = 1; i < n && exist; i++) {
			if (!(w[per[i - 1]][per[i]])) exist = false;
		}
		if (exist) ans++;
	} while (next_permutation(per.begin(), per.end()));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

void solve(int n,int m){
	int in,cup,ans=INF;
	vector<vector<stack<int>>> s(2,vector<stack<int>>(3));
	rep(i,3){
		s[0][i].push(0);
		s[1][i].push(0);
		cin>>in;
		rep(j,in){
			cin>>cup;
			s[0][i].push(cup);
			s[1][i].push(cup);
		}
	}
	int l,r;
	rep(i,2){
		rep(j,m){
			//cout<<s[i][0].size()<<" "<<s[i][1].size()<<" "<<s[i][2].size()<<endl;
			if(s[i][1].top()==0&&(s[i][0].top()==0||s[i][2].top()==0)){
				ans=min(ans,j);
				j+=m;
				continue;
			}
			int k=((i+j)%2);
			l=s[i][k].top();
			r=s[i][k+1].top();
			if(l>r){s[i][k].pop();s[i][k+1].push(l);}
			else {s[i][k+1].pop();s[i][k].push(r);}
		}
		if(s[i][1].top()==0&&(s[i][0].top()==0||s[i][2].top()==0)){
			ans=min(ans,m);
		}
	}
	cout<<((ans==INF?-1:ans))<<endl;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m,n){
		solve(n,m);
	}
}



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

int main() {
  std::string s;
  std::cin >> s;

  int x, y;
  std::cin >> x >> y;

  int pos = s.size();
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'F') {
      x--;
    } else {
      pos = i;
      break;
    }
  }

  std::vector<int> x_a, y_a;

  int count = 0;
  bool flag = true;
  for (int i = pos; i < s.size(); i++) {
    if (s[i] == 'F') {
      count++;
    } else {
      if (flag && count != 0) {
        x_a.push_back(count);
      } else if (!flag && count != 0) {
        y_a.push_back(count);
      }
      flag = !flag;
      count = 0;
    }
  }

  if (flag && count != 0) {
    x_a.push_back(count);
  } else if (!flag && count != 0) {
    y_a.push_back(count);
  }

  const auto x_r = std::accumulate(x_a.cbegin(), x_a.cend(), 0)
    - std::abs(x);
  const auto y_r = std::accumulate(y_a.cbegin(), y_a.cend(), 0)
    - std::abs(y);

  if (x_r % 2 != 0 || x_r < 0) {
    std::cout << "No" << std::endl;
    return 0;
  }
  if (y_r % 2 != 0 || y_r < 0) {
    std::cout << "No" << std::endl;
    return 0;
  }

  std::vector<bool> x_f(x_r / 2 + 1, false), y_f(y_r / 2 + 1, false);
  x_f[0] = y_f[0] = true;

  for (const auto i : x_a) {
    for (int j = 0; j < x_f.size(); j++) {
      if (x_f[j]) {
        if (i + j < x_f.size()) {
          x_f[i + j] = true;
        }
      }
    }
  }
  for (const auto i : y_a) {
    for (int j = 0; j < y_f.size(); j++) {
      if (y_f[j]) {
        if (i + j < y_f.size()) {
          y_f[i + j] = true;
        }
      }
    }
  }

  if (x_f.back() && y_f.back()) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)























int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &v[i]);
    }
    
    int ans = 0;
    for(int i = 0; i <= min(k, n); i++){
        for(int j = 0; j <= min(k - i, n - i); j++){
            priority_queue<int, vector<int>, greater<int>> que;
            int sum = 0;
            for(int l = 0; l < i; l++){
                que.push(v[l]);
                sum += v[l];
            }
            for(int l = n - 1; l > n - 1 - j; l--){
                que.push(v[l]);
                sum += v[l];
            }
            int cnt = 0, tmp;
            while(cnt < k - i - j && !que.empty() && (tmp = que.top()) < 0){
                sum -= tmp;
                que.pop();
                cnt++;
            }
            ans = max(ans, sum);
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    deque<char> S;
    int q;
    int r_cnt=0;
    string s;
    cin >> s >> q;
    rep(i,s.size()){
        S.push_back(s[i]);
    }

    rep(i,q){
        int a;
        cin >> a;
        if(a == 1) r_cnt++;
        else{
            int c; char d;
            cin >> c >> d;
            if(c == 1){
                if(r_cnt%2 == 0) S.push_front(d);
                else S.push_back(d);
            }
            else{
                if(r_cnt%2 == 1) S.push_front(d);
                else S.push_back(d);
            }
        }
    }
    if(r_cnt%2 == 1) reverse(S.begin(),S.end());
    rep(i,S.size()){
        cout << S[i];
    }
    cout << endl;
}

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

int main(){
  
  int n;
  string s;
  int cnt = 0;
  cin >> n;
  
  for(int i = 0; i < n; i++){
    cin >> s;
    if(s == "Y"){
     cnt++;
    }       
  }
  if(cnt > 0)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}
    

Measured memory_bytes: 256
#include<stdio.h>
	int main(){
		int n,mo,ye,t,x,y,sur,mem,i,j,max;
		double r;
		scanf("%d",&t);
		while(t-->0){
			max=0;
			scanf("%d",&mo);
			scanf("%d",&ye);
			scanf("%d",&n);
			for(i=0;i<n;i++){
				scanf("%d %lf %d",&x,&r,&y);
				sur=0;
				mem=mo;
				if(x==0){
					for(j=0;j<ye;j++){
						sur=sur+mem*r;
						mem-=y;
					}
					mem+=sur;
					if(mem>max)
						max=mem;
				}
				else {
					for(j=0;j<ye;j++)
						mem=mem+mem*r-y;
					
					
					if(mem>max)
						max=mem;
					
					
				}
			}
			printf("%d\n",max);
		}
		return 0;
}

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

int main(){
  int n; cin >> n;
  int tmp = 0, tmp2 = 0;
  for(int i = 1; i < n + 1; i++){
    int a; cin >> a;
    if(i != a){
      if(tmp == 0){
        tmp = a;
      }else{
        if(i != tmp){
          cout << "NO";
          return 0;
        }
      }
    }    
  }
  cout << "YES";
}


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

#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

//#define max(a,b) a>b?a:b
//#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int sum() { return 0; }

template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }




const int MOD = 1e9+7;
char a[1005][1005];
int dp[1005][1005];


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	REP(i,n)REP(j,m) cin>>a[i][j];
	REP(i ,n){
		 if(a[i][0] != '#')dp[i][0] = 1;
		 else break;
	 }
	REP(j, m) {
		if(a[0][j] != '#') dp[0][j] = 1;
		else break;
	}

	for (int i = 1; i < n; ++i)
	{
		for (int j = 1; j < m; ++j)
		{
			if(a[i][j] != '#') dp[i][j] = (dp[i-1][j]+dp[i][j-1]) % MOD;
		}
	}
	cout<<dp[n-1][m-1] % MOD;
	return 0;
}


Measured memory_bytes: 8408
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,string> > vpii;
typedef map<int, int> mii;
const ll N=2*1e5+5;
ll arr[N],A[N]  ;
bool visited[N]={} , cnt[N]={};
bool f=0;
int main()
{

 int a,b,c,d;
 cin>>a>>b>>c>>d;
 int x=c-a , y=d-b;
 cout<<c-y<<" "<<d+x<<" "<<a-y<<" "<<b+x;


 go;
}


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

//int gcd(int a, int b) {
//	if (b != 0)
//		return gcd(b, a%b);
//	return a;
//}
//
//int lcm(int a, int b) {
//	return a * b / gcd(a, b);
//}

int main() {
	int N, K, x, ans = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> x;
		if (x <= K - x) {
			ans += x * 2;
		}
		else
			ans += (K - x) * 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(all(a));
    if(a[0]==5&&a[1]==5&&a[2]==7) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#! /usr/bin/env python3

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
import math

N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = Counter(prime_factorize(math.factorial(N)))

ret = 1
for key, item in c.items():
    ret = ret * (item+1)
print(ret % (10**9 +7))

Measured memory_bytes: 10520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll INF = LLONG_MAX/3;
const int MAXV = 100010;

int main(){
    int n,W;
    cin >>n >>W;
    vector<int> w(n),v(n);
    rep(i,n) cin >>w[i] >>v[i];

    vector<ll> dp(MAXV, INF);
    dp[0] = 0;
    rep(i,n){
        for(int j=MAXV-1; j>=0; --j)if(dp[j]<INF){
            int nj = j+v[i];
            dp[nj] = min(dp[nj], dp[j]+w[i]);
        }
    }

    int ans = MAXV-1;
    while(dp[ans] > W) --ans;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

string s;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    if (s[0] == 'S') {
        if (s[1] == 'A') cout << 1 << E;
        else cout << 7 << E;
    }
    else if (s[0] == 'M') {
        cout << 6 << E;
    }
    else if (s[0] == 'T') {
        if (s[1] == 'U') cout << 5 << E;
        else cout << 3 << E;
    }
    else if (s[0] == 'W') {
        cout << 4 << E;
    }
    else cout << 2 << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double N = Double.parseDouble(sc.next());

        int[] X = new int[(int)N];

        for (int i = 0 ; i < N; i++) {
            X[i] = sc.nextInt();
        }

        double average = 0;

        for (int i = 0 ; i < N; i++) {
            average += X[i];
        }

        average = average / N;


        int sum = 0;

        for (int i = 0 ; i < N; i++) {
            sum += Math.pow((X[i] - Math.round(average)),2);
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, sum = 0;
  cin >> N;
  int N_ori = N;
  
  for (int i = 0; i < 8; i++) {
    int N_i = N;
    N_i %= 10;
    sum += N_i;
    N = (N - N_i) / 10;
  }
  
  if (N_ori % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

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


long long int_pow(long long a, long long b, const int& mod) {
    long long ans(1);
    while (b) {
        if (b % 2) ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}

void pre_calc(const int& n, vector<int>& g) {
    //bool* is_c = new bool[n + 1];
  vector<bool> is_c(n + 1);
    vector<int> p;
    //vector<int> g(n + 1);
    //g = new int[n + 1];
  g.resize(n + 1);
    g[1] = 1;

    for (int i = 2; i <= n; ++i) {
        if (!is_c[i]) {
            p.push_back(i);
            // phi: i-1, mu: -1, lcm: i - i * i
            g[i] = i - 1;
        }
        
        for (int j = 0; j < p.size() && p[j] * i <= n; ++j) {
            is_c[i * p[j]] = true;
            // for mobius function: 
            // g[i] * (i % p[j] ? g[p[j]] : 0)
            g[i * p[j]] = g[i] * (i % p[j] ? g[p[j]] : p[j]);
            if (i % p[j] == 0) break;
        }
    }

    //delete[] is_c;
}

int main() {
    // time :k log(n)
    // space k
    int n, k;
    cin >> n >> k;
    const int mod(1000000007);
    long long ans(0);
  vector<int> g;
    pre_calc(k, g);
    //for (int i = 0; i <= n; ++i) cout << g[i] << ' ';

    //cout << endl;
    for (int i = 1; i <= k; ++i)
        ans = (ans + int_pow(k / i, n, mod) * g[i] % mod) % mod;
    //delete[] g;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3852
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
    int ans=0;
    string str;
    cin >>str;
    for(int i=0;i<=3;i++) 
    {
        if (str[i]=='+')ans++;
        else ans--;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
// finish date: 2019/2/9

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
//#define input(name)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    string S;
    cin>>S;
    int N = S.length();
    rep(i,N){
        cout<<"x";
    }
    cout<<endl;


    return 0;
}


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

a,b,c = map(int, input().split())
x = int(input())

count = 0

while b<=a:
  b *= 2
  count += 1

while c<=b:
  c *= 2
  count += 1

if count<=x:
  print('Yes')
else:
  print('No')

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int dp[4][300][300] = {};
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < 4; k++) {
          dp[k][i][j] = s[j] == '1';
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dp[0][i][j] == 0) continue;
        if (i > 0) dp[0][i][j] += dp[0][i - 1][j];
        if (j > 0) dp[1][i][j] += dp[1][i][j - 1];
        if (i > 0 && j > 0) dp[2][i][j] += dp[2][i - 1][j - 1];
        if (i > 0 && j + 1 < n) dp[3][i][j] += dp[3][i - 1][j + 1];
        ans = max(ans, dp[0][i][j]);
        ans = max(ans, dp[1][i][j]);
        ans = max(ans, dp[2][i][j]);
        ans = max(ans, dp[3][i][j]);
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

ll n;

// dfs(string s) := s を接頭辞とする753数の数
ll dfs(string s){
    if(stoll(s) > n) return 0;

    ll res = 0;
    int a = 0, b = 0, c = 0;
    rep(i, s.size()){
        if(s[i] == '3') ++a;
        if(s[i] == '5') ++b;
        if(s[i] == '7') ++c;
    }
    if(a>0 && b>0 && c>0) ++res;

    res += dfs(s + '3');
    res += dfs(s + '5');
    res += dfs(s + '7');
    return res;
}

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

    cin >> n;
    cout << dfs("0") << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
 
K = int(input())
 
lis = []
def dfs(nowD, maxD, x):
    if nowD == maxD:
        lis.append(x)
        if len(lis) >= K:
            print(lis[K-1])
            exit()
    else:
        y = x%10
        x *= 10
        if y-1 >= 0:
            dfs(nowD+1, maxD, x+y-1)
        dfs(nowD+1, maxD, x+y)
        if y+1 <= 9:
            dfs(nowD+1, maxD, x+y+1)
 
for d in range(1, 11):
    for x in range(1, 10):
        dfs(1, d, x)

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

using namespace std;

int main() {
	int h, n;
	cin >> h >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}
	if (sum >= h) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  if(n==1){
    cout << 0 << endl;
    return(0);
  }
  
  ll ans=0;
  ll cnt=0;
  for(int i=1;i<n;i++){
    ans += a.at(cnt);
    if(i%2 == 1){
      cnt++;
    }
  }
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 4832
use std::io;
use std::str::FromStr;
use std::cmp::max;

static MOD: u64 = 1_000_000_007;

fn input_tuple() -> (usize, usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}

fn binary_power(x: u64, n: u64) -> u64 {
    if n == 0 {
      return 1;
    }
    if n % 2 == 0 {
      return (binary_power(x, n / 2) % MOD).pow(2) % MOD;
    } else {
      return binary_power(x, n - 1) % MOD * x % MOD;
    }
}

fn main() {
    let (h, w, k) = input_tuple();
    if w == 1 {
        println!("1");
        return;
    }
    let mut dp = vec![vec![0; w]; h+1];

    let mut amidas: Vec<Vec<bool>> = Vec::new();
    for bit in 0..1<<(w-1) {
        let mut flag = false;
        let mut prev = false;
        let mut amida = vec![false; w-1];
        for k in 0..w-1 {
            if bit & (1<<k) != 0 {
                if prev {
                    flag = true;
                    break;
                }
                amida[k] = true;
                prev = true;
            } else {
                prev = false;
            }
        }
        if !flag {
            amidas.push(amida);
        }
    }
    // println!("{:?}", amidas);
    dp[0][0] = 1;
    for i in 1..(h+1) {
        for j in 0..w {
            let mut from_left = 0;
            let mut from_center = 0;
            let mut from_right = 0;
            for amida in &amidas {
                if j > 0 {
                    if amida[j - 1] {
                        from_left += 1;
                    }
                } else {
                    if !amida[j] {
                        from_center += 1;
                    }
                }
                if j < w-1 {
                    if amida[j] {
                        from_right += 1;
                    }
                } else {
                    if !amida[j-1] {
                        from_center += 1;
                    }
                }
                if j > 0 && j < w-1 && !amida[j-1] && !amida[j] {
                    from_center += 1;
                }
            }
            // println!("j = {}", j);
            // println!("{}, {}, {}", from_left, from_center, from_right);
            if j > 0 {
                dp[i][j] += dp[i-1][j-1] * from_left;
                dp[i][j] %= MOD;
            }
            dp[i][j] += dp[i-1][j] * from_center;
            dp[i][j] %= MOD;
            if j < w-1 {
                dp[i][j] += dp[i-1][j+1] * from_right;
                dp[i][j] %= MOD;
            }
        }
    }
    // println!("{:?}", dp);
    println!("{}", dp[h][k - 1]);
}


Measured memory_bytes: 2116
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int X = s.nextInt();
		int Y = s.nextInt();
		boolean juge = false;
		for(int x=0; x<=X; x++) {
			for(int y=0; y<=X; y++) {
				if(x+y == X && 2*x + 4*y == Y) {
					juge =true; break;
				}
			}
			if(juge) {break;}
		}
		if(juge) {System.out.println("Yes");}
		else {System.out.println("No");}
	}

}


Measured memory_bytes: 35756
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  string S; cin >> S;
  int ans = 0;
  for(auto &p:S) {
    if(p == '0') ans++;
    else ans--;
  }
  cout << (int)S.size() - abs(ans) << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    string s;
    while (cin >> s)
    {
        if (s == "0")
        {
            break;
        }
        ll sum = 0;
        repi(i,s.length(),0){
            sum += s.at(i) - '0';
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <string>
 
int main(){
  int N;
  std::cin >> N;
  if(N%10 == 3){
    std::cout << "bon";
  }
  else if(N%10 == 0||N%10 == 1||N%10 == 6||N%10 == 8){
     std::cout << "pon";
  }
  else{
    std::cout << "hon";
  }
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int h;
    cin >> h;
    int ans = 0;
    int now = 1;
    while (true)
    {
        ans += now;
        now *= 2;
        if (h == 1)
        {
            break;
        }
        h /= 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256