akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll mpow(ll x, ll n) { ll y = 1; for (; n; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    map<pair<ll, ll>, array<int, 4>> mp;
    int azero = 0, bzero = 0, abzero = 0;
    rep(i, N) {
        if (A[i] == 0 && B[i] == 0) abzero++;
        else if (A[i] == 0) azero++;
        else if (B[i] == 0) bzero++;
        else {
            int dim = 0;
            ll a = A[i], b = B[i];
            while (a < 0 || b < 0) {
                swap(a, b);
                a *= -1;
                dim++;
            }
            ll g = gcd(a, b);
            a /= g;
            b /= g;
            mp[pair(a, b)][dim]++;
        }
    }



    ll ans = 1;
    for (const auto& a : mp) {
        ll tmp = mpow(2, a.second[0] + a.second[2]) + mpow(2, a.second[1] + a.second[3]) - 1;
        tmp %= MOD;
        ans = ans * tmp % MOD;
    }
    ans = ans * (mpow(2, azero) + mpow(2, bzero) - 1) % MOD;
    ans = (ans + abzero - 1 + MOD) % MOD;
    write(ans);
}

Measured memory_bytes: 21908
def otoshidama(N,Y):
  ansi, ansj, ansk = -1, -1, -1
  if Y/10000 > N:
    return ansi, ansj, ansk
  for i in range(N+1):
    for j in range(N+1-i):
      k = N - i - j
      if i*1000 + j*5000 + k*10000 == Y:
        ansi, ansj, ansk = i, j, k
        return ansi,ansj,ansk
  return ansi,ansj,ansk
N,Y = [int(i) for i in input().split()]
ansi, ansj, ansk = otoshidama(N,Y)
print(ansk, ansj, ansi)

Measured memory_bytes: 9180
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int A[1000000], n;

int binalySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid])return 1;
		if (key > A[mid])left = mid+1;
		else if (key < A[mid])right = mid;
	}
	return 0;
}

int main() {
	int i, q, k, sum = 0;

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

	scanf("%d", &q);
	for (i = 0; i < q; i++){
		scanf("%d", &k);
		if (binalySearch(k))sum++;
	}
	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 2960
#include <iostream>
#include <cstdio>
#define int long long
#define N 5002
using namespace std;
const int mod=1000000007;
int head[N],ver[N*2],nxt[N*2],l;
int n,i,j,c[N],f[N][N],g[N][N],siz[N];
int read()
{
	char c=getchar();
	int w=0;
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0'){
		w=w*10+c-'0';
		c=getchar();
	}
	return w;
}
void insert(int x,int y)
{
	l++;
	ver[l]=y;
	nxt[l]=head[x];
	head[x]=l;
}
void dp(int x,int pre)
{
	siz[x]=f[x][1]=1;
	for(int i=head[x];i;i=nxt[i]){
		int y=ver[i];
		if(y!=pre){
			dp(y,x);
			for(int j=1;j<=siz[x];j++){
				for(int k=1;k<=siz[y];k++){
					g[x][j]=(g[x][j]-f[x][j]*f[y][k]%mod*c[k]%mod+mod)%mod;
					g[x][j+k]=(g[x][j+k]+f[x][j]*f[y][k]%mod)%mod;
				}
			}
			siz[x]+=siz[y];
			for(int j=1;j<=siz[x];j++) f[x][j]=g[x][j],g[x][j]=0;
		}
	}
}
signed main()
{
	n=read();
	for(i=1;i<n;i++){
		int u=read(),v=read();
		insert(u,v);insert(v,u);
	}
	for(i=2;i<=n;i+=2){
		c[i]=1;
		for(j=i-1;j>=1;j-=2) c[i]=c[i]*j%mod;
	}
	dp(1,0);
	int ans=0;
	for(i=1;i<=n;i++) ans=(ans+f[1][i]*c[i]%mod)%mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 181272
// Problem : A - Station and Bus
// Contest : AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

/*/ Author:Amar1503/*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define Mod 1000000007
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const double PI=3.1415926535897932384626433832;
//looping
#define For(i,a,b) for(int i=a;i<b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define trace(x) clog<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) clog<<#x<<": "<<x<<"     "<<#y<<" "<<y<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define printv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" "
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define itr(it, a) for(auto it = (a).begin(); it != (a).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ers(v)   sort(all(v)); (v).erase(unique(all(v)),(v).end())
#define printmatrix(a,n,m) for(int i=0;i<n;i++){ for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef pair <int, int> pii;
typedef vector < pair <int, int> > vpii;
// cout<<"\nTime Elapsed : " << 1.0*clock() /CLOCKS_PER_SEC << " s\n";
int dx[8]={1,1,1,-1,-1,-1,0,0};
int dy[8]={1,0,-1,1,-1,0,1,-1};
//#define int long long
/*/----------------------------Code begins----------------------------------/*/
int32_t main(){
fio;
string s;
cin>>s;
map<char,int> m;
For(i,0,s.size())
m[s[i]]++;
if(m.size()!=1)
cout<<"Yes";
else cout<<"No";


}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,i;
  cin >> N >> K;
  int x=1;
  
  for (i=0; i<N; i++){
    int y,z;
    y= x*2;
    z=x+K;
    
    if (y >=z){
      x=z;
    }
    else {
      x=y;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
char s[5001];
int main(){
    int n;
    cin >> n;
    scanf("%s",s);
    int k_max=0;
    loop(offset,n){
        int k_tmp=0,k_now=0;
        loop(i,n-offset){
            if(s[i]==s[i+offset])++k_now;
            else{
                k_tmp=max(k_tmp,k_now);
                k_now=0;
            }
        }
        k_tmp=max(k_tmp,k_now);
        k_max=min(offset,max(k_max,k_tmp));
    }
    cout << k_max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <cstdlib>
#include <utility>
#include <cmath>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end() 
#define ayacin ios::sync_with_stdio(false);
#define yukari 1000000000000000000LL
#define M_PI12 3.141592653
#define Parsee long double
#define reimu iterator 
#define mokou __builtin_popcount
#define __sum accumulate
#define rep(i,a,b) for(i=a;i<=b;i++)
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define ls rt<<1
#define rs rt<<1|1 
#define eps 1e-10  
#define zero(a) fabs(a)<eps  
#define x first
#define y second
using namespace std;
const int MAXN=1e5+5; 
int a[MAXN];
int main(){
	int m,n,i,j,k;
	scanf("%d%d",&m,&n);
	rep(i,1,m) scanf("%d",&a[i]);
	int mn=2e9+9,way=1,mx=0,mint=1;
	rep(i,1,m){
		if(a[i]<mn){
			mn=a[i];
		}
		if(abs(a[i]-mn)>mx){
			mx=abs(a[i]-mn);
			way=1;
		}
		else if(abs(a[i]-mn)==mx){
			way++;
		}
	}
	cout<<way<<endl;
}



Measured memory_bytes: 640
def main():
    n, m = map(int, input().split())
    # マイナスの場合は leader であり、同時にサイズ(*-1)を保持する
    uf = [-1] * (n+1)

    def uf_leader(a):
        if uf[a]<0:
            return a
        uf[a] = uf_leader(uf[a])
        return uf[a]
    def uf_unite(a, b):
        ua, ub = uf_leader(a), uf_leader(b)
        if ua==ub:
            return False
        if uf[ua] > uf[ub]:
            a, b = b, a
        uf[ua] += uf[ub]
        uf[ub] = ua
        return True
    def uf_leaders():
        return set([uf_leader(v) for v in range(1,n+1)])

    # print(uf[1:])
    for _ in range(m):
        a, b = map(int, input().split())
        uf_unite(a, b)
        # print(uf[1:])

    # print(uf_leaders())
    
    ans = len(uf_leaders())-1
    print(ans)

main()

Measured memory_bytes: 19008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n;cin>>n;
    string v;cin>>v;
    ll ans=0;
    rep(i,n-2){
        if(v[i]=='A'&&v[i+1]=='B'&&v[i+2]=='C')ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Scanner;
public class Main {
 
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	String a = scan.next();
	String b = scan.next();
	String c = scan.next();
	BigDecimal a0 = sqrt(new BigDecimal(a), 50);
	BigDecimal b0 = sqrt(new BigDecimal(b), 50);
	BigDecimal c0 = sqrt(new BigDecimal(c), 50);
        if(a0.add(b0).compareTo(c0)==-1)System.out.println("Yes\n");
	else System.out.println("No\n");
    }
    public static BigDecimal sqrt(BigDecimal a, int scale){
        BigDecimal x = new BigDecimal(
                Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);
        if(scale < 17) return x;

        BigDecimal b2 = new BigDecimal(2);
        for(int tempScale = 16; tempScale < scale; tempScale *= 2){
            x = x.subtract(
                    x.multiply(x).subtract(a).divide(
                    x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN));
        }
        return x;
    }
}


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

int main()
{
	ll x;
	cin >> x;
	if (x < 600)
	{
		cout << 8 << endl;
	}
	else if (x < 800)
	{
		cout << 7 << endl;
	}
	else if (x < 1000)
	{
		cout << 6 << endl;
	}
	else if (x < 1200)
	{
		cout << 5 << endl;
	}
	else if (x < 1400)
	{
		cout << 4 << endl;
	}
	else if (x < 1600)
	{
		cout << 3 << endl;
	}
	else if (x < 1800)
	{
		cout << 2 << endl;
	}
	else if (x < 2000)
	{
		cout << 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n,a,b,c,d; cin >> n >> a >> b >> c >> d;
    string s; cin >> s;
    for(int i=a-1; i<=c-2;i++){
        if(s[i]=='#' && s[i+1] == '#'){
        cout << "No" << endl;
        return 0;
        }
    }
    for(int i=b-1; i<=d-2;i++){
        if(s[i]=='#' && s[i+1] == '#'){
        cout << "No" << endl;
        return 0;
        }
    }
    if(c < d){
        cout << "Yes" << endl;
        return 0;
    }else{
        for(int i=b-1; i <= d-1;i++){
            if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }
    assert(0);
    return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>

int main() {
	std::string s;
	std::cin >> s;
	int flag = 0;
	for (int i = s.size() - 1;i > 5;) {
		if (s[i] == 'm') {
			if (s[i - 1] == 'a'&&s[i - 2] == 'e'&&s[i - 3] == 'r'&&s[i - 4] == 'd') {
				i -= 5;
			}
			else {
				flag = 1;
				break;
			}
		}
		else if (s[i] == 'e') {
			if (s[i - 1] == 's'&&s[i - 2] == 'a'&&s[i - 3] == 'r'&&s[i - 4] == 'e') {
				i -= 5;
			}
			else {
				flag = 1;
				break;
			}
		}
		else if (s[i] == 'r') {
			if (s[i - 1] == 'e'&&s[i - 2] == 'm'&&s[i - 3] == 'a'&&s[i - 4] == 'e'&&s[i-5]=='r'&&s[i-6]=='d') {
				i -= 7;
			}
			else if (s[i - 1] == 'e'&&s[i - 2] == 's'&&s[i - 3] == 'a'&&s[i - 4] == 'r'&&s[i - 5] == 'e') {
				i -= 6;
			}
			else {
				flag = 1;
				break;
			}
		}
		else {
			flag = 1;
			break;
		}
	}
	if (flag == 1) {
		std::cout << "NO" << std::endl;
	}
	else {
		std::cout << "YES" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
int K,n;
int a[300010];
void MAIN() {
	cin>>K>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int mx=a[0]+K-a[n-1];
	for(int i=0;i+1<n;i++)mx=max(mx,a[i+1]-a[i]);
	cout<<K-mx;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split(" "))
bridges = [list(map(int, input().split(" "))) for _ in range(M)]

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n
        self.rank = [0] * n
        
    def root(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]
        
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        
        if rx == ry:
            return
        elif self.rank[rx] > self.rank[ry]:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
            
        else:
            self.par[ry] += self.par[rx]
            self.par[rx] = ry
            if self.rank[rx] == self.rank[ry]:
                self.rank[ry] += 1
                
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

all_ptn = N * (N-1) // 2
ans = [all_ptn]
uf = UnionFind(N)
for i in range(M-1, 0, -1):
    x = bridges[i][0] - 1
    y = bridges[i][1] - 1
    if uf.same(x, y):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.count(x) * uf.count(y))
        uf.unite(x, y)
        
for i in range(M-1, -1, -1):
    print(ans[i])

Measured memory_bytes: 37348
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N, K;
    cin >> N >> K;

    if (K == 1) {
        cout << 0 << endl;
        return 0;
    }

    cout << N - K << endl;

    return 0;
}


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

string c;
int sum[maxn],a[maxn],d[maxn];
int n,K,ans=0;

int main(){
	cin>>n>>K>>c;
	for(int i=0;i<n;i++){
		if(c[i]=='1') d[i+1]=1;
		else d[i+1]=0;
	}
	for(int i=1;i<=n;i++) a[i]=d[i]^d[i-1];
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	int b=0,Max=0;
	for(int i=1;i<=n;i++){
		b^=a[i];
		int x=upper_bound(sum,sum+n+1,K*2-(!b)+sum[i])-sum;
		Max=max(x-i,Max);
	}
	printf("%d\n",Max);
	return 0;
} 

Measured memory_bytes: 1664
#include<stdio.h>

int main(){
  int N, i, j, k, l, key, A[100];
  
  scanf("%d", &N);

  for (i = 0; i < N; i++) scanf("%d", &A[i]);
  
  for(i = 0; i < N; i++){
    if(i != 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");

  for(j = 1; j <= N - 1; j++){
    key = A[j];
    k = j - 1;
    while(k >= 0 && A[k] > key){
      A[k + 1] = A[k];
      k--;
    }
    A[k + 1] = key;

    for(i = 0; i < N; i++){
      if(i != 0) printf(" ");
      printf("%d", A[i]);
    }
    printf("\n");

  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <climits>
#include <vector>
#include <queue>
 
#define MAX_V 1024
using namespace std;
 
void get_map();
void check();
struct edge
{
  int to;
  int weight;
};
 
 
const int INF = INT_MAX/4;
vector<edge> g[2000];
int graph[MAX_V][MAX_V];
int dist[MAX_V];
int numofedge;
int vertex;
int start;
int flag=0;
 
int main()
{
  get_map();
  check();
  //for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      //if(i==j)
        {
          if(graph[start][j]<INF/2 && graph[j][j]<0)
        {
          cout << "NEGATIVE CYCLE" <<endl;
          return 0;
        }
        }
    }
    }
   
    for(int i=0;i<vertex;i++)
      {
    if(graph[start][i]>=INF/2)
      {
        cout << "INF" << endl;
      }
    else
      {
    cout << graph[start][i] << endl;
      }
      }
  return 0;
}
 
int fastmin(int a, int b)
{
    int c = a-b;
  return (((c)>>31)&(c))+b;
}
 
void check()
{
  //  int next;
  //int here = start;
  //for(int i=0;i<vertex;i++)
   
  for(int k=0;k<MAX_V;k++)//v=4
    {
      for(int i=0;i<MAX_V;i++)
    {
      int gik= graph[i][k];
      for(int j=0;j<MAX_V;j++)
        {

          //if(graph[i][k] !=INF && graph[k][j]!=INF)
        {
          graph[i][j]= min(gik+graph[k][j], graph[i][j]);
        }
        }
    }
    }
   
}
 
void get_map()
{
  int edge, from ,to;
  cin >> vertex >> numofedge >> start;
   
  fill(graph[0], graph[vertex], INF);
   
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
      {
    if(i==j)
      {
        graph[i][j]=0;
      }
    /*else
      {
        graph[i][j]=INF;
        }*/
      }
    }
 
  /*for(int i=0;i<vertex;i++)
    {
      dist[i]=INF;
    }
  */
  for(int i=0;i<numofedge;i++)
    {
      cin>>from>>to;
      cin >> graph[from][to];
    }
 
  /*  for(int i=0;i<numofedge;i++)
    {
      int from, to, weight; 
      cin >> from >> to >> weight;
      g[from].push_back({to , weight});
   }
  */ 
 
  /*  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      cout << graph[i][j] << " ";
    }
      cout << endl;
      }*/
  // dist[start]=0;
   
  /*  cout << vertex << endl;
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      cout << graph[i][j] << " ";
    }  
      cout << endl;    
      }*/
   
 
}

Measured memory_bytes: 5312
import math
N, M = (int(x) for x in input().split(' '))

# 要するに、N個の中から2個＋M個の中から2個なので其れを計算する。
# 「n個からm個を選択する数」は「nCr」で計算する。
if N < 2:
  k = 0
else:
  k = math.factorial(N) / (math.factorial(N-2) * 2 )

if M < 2:
  g = 0
else:
  g = math.factorial(M) / (math.factorial(M-2) * 2 )

#出力
print(int(k+g))

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

int main() {
  int N, M, X, cost_l = 0, cost_r = 0; // ゴール、料金所の数、最初のマス
  cin >> N >> M >> X;
  int A[100]; // 料金所の場所
  for(int i = 0; i < M; ++i) {
    cin >> A[i];
    if(A[i] > X) ++cost_r;
    else ++cost_l;
  }

  if(cost_r > cost_l) cout << cost_l << endl;
  else cout << cost_r << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.typecons;

alias Tuple!(int,"x",int,"y") pair;

void main(){
  int n,w,h,s,t;
  string[] input;
  while(n=readln.split[0].to!int,n!=0){
    int[pair] memo;
    input=readln.split;
    w=input[0].to!int;
    h=input[1].to!int;
    for(int i=0;i<n;i++){
      input=readln.split;
      pair p;
      p.x=input[0].to!int-1;
      p.y=input[1].to!int-1;
      memo[p]=1;
    }
    input=readln.split;
    s=input[0].to!int;
    t=input[1].to!int;
    int count,maxCount=0;
    foreach(j;0..h-t+1){
      foreach(i;0..w-s+1){
	count=0;
	foreach(l;j..t+j){
	  foreach(k;i..s+i){
	    pair p;p.x=k;p.y=l;
	    if(p in memo){
	      count++;
	    }
	  }
	}
	if(maxCount<count){
	  maxCount=count;
	}
      }
    }
    writeln(maxCount);
  }
}

Measured memory_bytes: 2080
const MOD: usize = 1e9 as usize + 7;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let x: Vec<usize> = sc.vec(n);

    let mut stack = 0;
    let mut cur = 1;
    for x in x.into_iter() {
        if x < 2 * stack + 1 {
            cur *= stack + 1;
            cur %= MOD;
        } else {
            stack += 1;
        }
    }
    for i in 0..stack {
        cur *= i + 1;
        cur %= MOD;
    }
    println!("{}", cur);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int n;
int result = 0;
vector<int> num_list = {3,5,7};

int array_to_int(vector<int> v)
{
    int v_size = v.size();
    string string_num;
    for(int i = 0;i < v_size;i++)
    {
        string_num += v[i] + '0';    
    }
    return stoi(string_num);
}

void dfs(vector<int> v, int head, int n_size)
{
    if(head == n_size) 
    {
        vector<bool> check753(3,false);
        for(int i = 0;i < n_size;i++)
        {
            // check753配列の添字0を7,1を5,2を3が存在するかの真偽値が入るものとする
            switch(v[i])
            {
                case 7:
                    check753[0] = true;
                    break;
                case 5:
                    check753[1] = true;
                    break;
                case 3:
                    check753[2] = true;
                    break;
            }
        }
        if(check753[0] && check753[1] && check753[2]) result++;
    }
    else
    {
        for(int i = 0;i < 3;i++)
        {
            v[head] = num_list[i];
            
            int num = array_to_int(v);
            if(num > n) break;
            dfs(v,head + 1,n_size);
        }
    }
}

int main()
{
    cin >> n;
    int n_size = to_string(n).size();
    while(n_size > 2)
    {
        vector<int> v(n_size);
        dfs(v,0,n_size);
        n_size--;
    }
    
    cout << result << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    ll n;
    cin >> n;
    string s = "";
    while (n) {
        --n;
        s += 'a' + (n % 26);
        n /= 26;
    }
    reverse (s.begin(), s.end());
    cout << s << "\n";
}

Measured memory_bytes: 3564
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

struct Node {
    int key;
    Node *prev, *next;
};

Node *nil;

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->prev = nil;
    nil->next = nil;
}

Node* search(int num){
    Node *p = nil->next;
    while(p != nil && p->key != num){
        p = p->next;
    }
    return p;
}

void printAll(){
    Node *p = nil->next;
    int count = 0;
    while(p != nil){
        if(count > 0) printf(" ");
        printf("%d", p->key);
        p = p->next;
        count++;
    }
    printf("\n");
}

void insertNode(int num){
    Node *n = (Node *)malloc(sizeof(Node));
    n->key = num;
    n->next = nil->next;
    n->prev = nil;
    n->next->prev = n;
    nil->next = n;
}

void deleteNode(Node *n){
    if(n == nil) return;
    n->prev->next = n->next;
    n->next->prev = n->prev;
    free(n);
}

void deleteFirstNode(){
    deleteNode(nil->next);
}

void deleteLastNode(){
    deleteNode(nil->prev);
}

void deleteKey(int num){
    deleteNode(search(num));
}

int main() {
    int n;
    cin >> n;
    init();
    char command[20];
    int key;
    for (int i = 0; i < n; i++) {
        scanf("%s%d", command, &key);
        if(command[0] == 'i') insertNode(key);
        else if(strlen(command) <= 6) deleteKey(key);
        else if(command[6] == 'F') deleteFirstNode();
        else deleteLastNode();
    }

    printAll();
}


Measured memory_bytes: 34408
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i] += [sum(a[i])]

for i in range(r):
    print(*a[i])

a = list(zip(*a))

for i in range(c):
    print(sum(a[i]), end=' ')
print(sum(a[c]))



Measured memory_bytes: 6224
def buble_sort(cards)
  c  = cards
  cl = c.length
  (0).upto(cl-1) do |i|
    (cl-1).downto(i+1) do |j|
      if c[j-1][1] > c[j][1]
        c[j-1], c[j] = c[j], c[j-1]
      end
    end
  end
  c
end

def select_sort(cards)
  c  = cards
  cl = c.length
  for i in 0..cl-1
    min = i
    for j in i..cl-1
      if c[j][1] < c[min][1]
        min = j
      end
    end
    c[i], c[min] = c[min], c[i]
  end
  c
end

def stable?(origin, card_info)
  origin_info = []
  origin.map do |o|
    tmp = o.split ''
    origin_info << [tmp[0], tmp[1]]
  end

  for ci in card_info
    o_index = 0
    loop do
      if origin_info[o_index][1] == ci[1]
        if origin_info[o_index][0] != ci[0]
          return false
        end
        origin_info.delete origin_info[o_index]
        break
      end
      o_index += 1
    end
  end
  true
end

gets
origin = gets.split ' '
card_info1 = []
card_info2 = []
origin.map do |card|
  tmp = card.split ''
  card_info1 << [tmp[0], tmp[1]]
  card_info2 << [tmp[0], tmp[1]]
end

# Bubble Sort
puts buble_sort(card_info1).map{|m, n| [m, n].join ''}.join ' '
if stable? origin, card_info1 then puts 'Stable' else puts 'Not stable' end

# Select Sort
puts select_sort(card_info2).map{|m, n| [m, n].join ''}.join ' '
if stable? origin, card_info2 then puts 'Stable' else puts 'Not stable' end

Measured memory_bytes: 8892
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

#[allow(non_snake_case)]
fn solve(S: &Vec<char>, K: u64) -> i32 {
    let last = K.min(S.len() as u64) as usize;
    for i in 0..last - 1 {
        if S[i] != '1' {
            return S[i].to_string().parse::<i32>().unwrap();
        }
    }
    if S[last - 1] != '1' {
        return S[last - 1].to_string().parse::<i32>().unwrap();
    }
    1
}

#[allow(non_snake_case)]
fn main() {
    input! {
        S: String,
        K: u64,
    }
    let ret = solve(&S.chars().collect(), K);
    println!("{}", ret);
}


Measured memory_bytes: 2168
#include<stdio.h>
int main(void)
{
	int i,j;
	char a;
	a='x';
	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
			printf("%d%c%d=%d\n",i,a,j,i*j);
		}
	}
return 0;
}


Measured memory_bytes: 2536
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  lvector p(n);rep(i,n) cin>>p[i];
  sort(ALL(p));
  ll ans=0;
  rep(i,k) ans+=p[i];
  print(ans);
  return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <math.h>

typedef struct {
  int left_count_1;
  int right_count_1;
  int count_0;
} Count_1;

int main(void) {
  
  int N, K;
  char S[100001];
  
  int n = 0;
  Count_1 count_1[100001];
  
  scanf("%d %d", &N, &K);
  scanf("%s", &S);
  
  int current_count_1 = 0, current_count_0 = 0;
  int find_0 = 0, last_index_0;
  for(int i = 0; i < N; ++i) {
    
    if(S[i] == '0') {
      
      if(!find_0) {
        find_0 = 1;
        count_1[n].left_count_1 = current_count_1;
        current_count_1 = 0;
      } else {
        if(i - last_index_0 > 1) {
          count_1[n].count_0 = current_count_0;
          count_1[n].right_count_1 = current_count_1;
          ++n;
          current_count_0 = 0;
          count_1[n].left_count_1 = current_count_1;
          current_count_1 = 0;
        }
      }
      
      current_count_0++;
      last_index_0 = i;

    } else current_count_1++;
    
  }
  
  if(current_count_0 > 0 || current_count_1 > 0) {
    count_1[n].count_0 = current_count_0;
    count_1[n].right_count_1 = current_count_1;
  }
  
  int max_count_1 = 0;
  for(int i = 0; i <= n; ++i) {
    
    int total_count_1 = count_1[i].left_count_1;
    for(int j = 0; j < K && j + i <= n; ++j) {
      total_count_1 += count_1[i + j].count_0 + count_1[i + j].right_count_1;
    }
    
    if(max_count_1 < total_count_1) max_count_1 = total_count_1;
    
  }
  
  printf("%d\n", max_count_1);
  
  return 0;
  
}

Measured memory_bytes: 896
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

const int MAX_V = 100000;

struct edge {
  int to;
  ll cost;
};
vector<edge> g[MAX_V];

vector<ll> costs;

int N;
int Q, K;

void dfs(int v, ll c) {
  if (costs[v] != -1) {
    return;
  }
  costs[v] = c;

  for (int i = 0; i < g[v].size(); i++) {
    dfs(g[v][i].to, c + g[v][i].cost);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int ai, bi;
    ll ci;
    cin >> ai >> bi >> ci;
    ai--;
    bi--;
    g[ai].push_back(edge{bi, ci});
    g[bi].push_back(edge{ai, ci});
  }
  costs.resize(N, -1);

  cin >> Q >> K;
  K--;
  dfs(K, 0);

  for (int i = 0; i < Q; i++) {
    int xi, yi;
    cin >> xi >> yi;
    xi--;
    yi--;
    cout << costs[xi] + costs[yi] << endl;
  }
  return 0;
}

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

void solve(int h, int m, int s){
    int ts = 2*60*60 - ((h * 60 + m) * 60 + s);
    if(ts < 0) throw;

    h = ts / 3600;
    m = (ts % 3600) / 60;
    s = ts % 60;
    printf("%02d:%02d:%02d\n", h, m, s);

    ts *= 3;
    h = ts / 3600;
    m = (ts % 3600) / 60;
    s = ts % 60;
    printf("%02d:%02d:%02d\n", h, m, s);
}

int main(){
    int h, m, s;
    while(cin >> h >> m >> s){
        if(h == -1 && m == -1 && s == -1) break;
        solve(h, m, s);
    }
    return 0;
}

Measured memory_bytes: 1160
//in dp prefix suffix sum helps..
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include <iterator>
#include <map>
#include<list>
#include <fstream>
#include<unordered_map>
#include<set>
#include<queue>
#define int long long
#define double long double
#define pb   push_back
#define mp   make_pair
#define pii  pair<int,int>
#define pip vector<pair<int, pair<int, int> > >
#define viv vector<vector<int> >
#define vip vector<pair<int, int> >
#define vi vector<int>
#define mii  map<pair<int, int>, int>
#define li list<int>
#define qu queue<int>
#define set set<int>
#define stack stack<int>
#define fi first
#define se second
#define mem(x, y) memset(x, y, sizeof(x))
#define pq priority_queue<int>
#define pq1 priority_queue <int, vector<int>, greater<int> >
#define ps(x,y) fixed<<setprecision(y)<<x
// author :: Anurag Anand.
using namespace std;
int z= 1000000007;
//int z= 998244353;
int gcd(int a, int b){
    if(a==0)return b;
    if(b==0)return a;
    return gcd(b, a%b);
}
int power(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
		{
			res=(res*a)%z;
			b--;
		}
		else
		{
			a=(a*a)%z;
			b=b>>1;
		}
	}
	return res;
}
vi seg;
void arrange(int i, int v, int x, int lx, int rx){
	if(rx-lx==1){
		seg[x]+=v;
		return;
	}
	int mid= lx+(rx-lx)/2;
	if(i<mid) arrange(i, v, 2*x+1, lx, mid);
	else arrange(i, v, 2*x+2, mid, rx);
	seg[x]= seg[2*x+1]+seg[2*x+2];
}
int sum(int l, int r, int x, int lx, int rx){
	if(l>=rx||r<=lx) return 0;
	if(lx>=l&&rx<=r) return seg[x];
	int mid=(lx+rx)/2;
	int sl= sum(l, r, 2*x+1, lx, mid), sr= sum(l, r, 2*x+2, mid, rx);
	return (sl+sr);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);
	int t;
	t=1;
	//cin>>t;
	while(t--){
		string s;
		cin>>s;
		int l= s.length();
		if(s[l-1]=='s'){
			s+='e';
			s+='s';
		}
		else s+='s';
		cout<<s<<"\n";
	}
}

Measured memory_bytes: 3600
[N,Y]=list(map(int,input().split()))

for x in range(N+1):
  for y in range(N+1-x):
    z=N-x-y
    if 10000*x+5000*y+1000*z==Y:
      print(" ".join([str(item) for item in [x,y,z]]))
      exit()
print("-1 -1 -1")

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

constexpr int MOD = 998244353;

int64_t modpow(int64_t x, int64_t n) {
  int64_t ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= MOD;
    (x *= x) %= MOD;
    n >>= 1;
  }
  return ret;
}

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (auto& e : d) cin >> e;

    if (d[0] == 0) {
        d.erase(begin(d));
        d.shrink_to_fit();
        map<int64_t, int64_t> m;
        for (auto& e : d) m[e]++;

        int64_t pk = 0, pv = 1;
        bool f = true;
        int64_t ans = 1;
        for (auto& e : m) {
            if (pk + 1 != e.first) {
                f = false;
                break;
            }

            ans *= modpow(pv, e.second);
            ans %= MOD;
            pk = e.first;
            pv = e.second;
        }

        if (f) {
            cout << ans << endl;
        } else {
            cout << 0 << endl;
        }
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 6904
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
#include <map>
#include <vector>
#include <cstring>
using namespace std;

typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<int> nums(N);
	for (int i = 0; i < N; ++i)
		cin >> nums[i];
	int res = 0;
	int dir = 0;
	for (int i = 1; i < N; ++i)
	{
		int new_dir = 0;
		if (nums[i] > nums[i - 1])
			new_dir = 1;
		else if (nums[i] < nums[i - 1])
			new_dir = -1;
		if (new_dir != dir)
		{
			if (dir == 0)
				dir = new_dir;
			else if (new_dir == 0)
				new_dir = dir;
			else
			{
				++res;
				dir = 0;
			}
		}
	}
	++res;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int i,n,b,f,r,v;
	int house[5][4][11];
	for(b=0;b<5;b++){
		for(f=0;f<4;f++){
			for(r=0;r<11;r++){
				house[b][f][r]=0;
			}
		}
	}
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		house[b][f][r]+=v;
	}		
	for(b=1;b<5;b++){
		for(f=1;f<4;f++){
			for(r=1;r<11;r++){
				printf("%2d",house[b][f][r]);
			}
			printf("\n");
		}
		if(b!=4){
		printf("####################\n");
		}
	}
	return 0;
}

Measured memory_bytes: 620
#include<stdio.h>
int main()
{
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	if(b <= a)
		printf("delicious\n");
	else if((b <= a+x))
		printf("safe\n");
	else
		printf("dangerous\n");
	return 0;
}

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


using namespace std;


void security()
{
  string s;
  cin >> s;

  for (int i = 1; i < s.size(); ++i)
  {
    if (s[i - 1] == s[i])
    {
      cout << "Bad\n";
      return;
    }
  }
  cout << "Good\n";
}


void fifty_fify()
{
  string s;
  cin >> s;

  sort(s.begin(), s.end());

  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes\n";
  else cout << "No\n";
}


void dodecagon()
{
  int r;
  cin >> r;

  cout << 3 * r * r << "\n";
}


void harmony()
{
  int a, b;
  cin >> a >> b;

  if (a % 2 == b % 2) cout << (a + b) / 2 << "\n";
  else cout << "IMPOSSIBLE\n";
}


void transfer()
{
  int a, b, c;
  cin >> a >> b >> c;

  cout << max(0, c - (a - b)) << "\n";
}



int main()
{
  //security();
  //fifty_fify();
  //dodecagon();
  //harmony();
  transfer();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define pb push_back
typedef long double ld;
typedef vector<ll> vll;
typedef vector<pair<ll,ll>> vpl;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9+7;

// using only 1-d array
ll knap(ll n,ll W, vll wei,vll val){

    // dp[i] represents max total value of items with weight i;
    vll dp(W+1,0);
    repA(i,0,n-1){
        repD(weight_already,W-wei[i],0){
            dp[weight_already+wei[i]] = max(dp[weight_already+wei[i]],dp[weight_already]+val[i]);
        }
    }

    return dp[W];
}



// *****************************************//


//by using 2d array

ll knapsack(ll n,ll W,vll wei, vll val){
    vector<vll> dp(n+1,vll(W+1,0));

    // dp[i][w] represents max value we can get by using item till index 'i' for a weight 'w'
    repA(i,0,n){
        repA(w,0,W){
            if(i==0 or w==0)dp[i][w]=0;
            else if(wei[i-1]<=w) dp[i][w] = max(dp[i-1][w],dp[i-1][w-wei[i-1]]+val[i-1]);
            else dp[i][w] = dp[i-1][w];
        }
    }
    return dp[n][W];
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll n,W; cin >> n >> W;
        vll wei(n),val(n);
        rep(i,n) cin >> wei[i] >> val[i];


        // cout <<knapsack(n,W,wei,val) << endl; // using 2d array and Time o(n*W);

        cout << knap(n,W,wei,val) << endl;// using 1d array and Time o(n*W);
    }
}


Measured memory_bytes: 3948
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




ll n;

ll nadji(ll x){
    if(x == 1)return 0;
    ll pr = 1;
    ll br = 2;
    ll pomx = x;
    while(br * br <= x){
        if(pomx%br == 0){
            ll kol = 0;
            while(pomx%br == 0){
                pomx /= br;
                kol++;
            }
            pr *= (kol + 1);
        }
        br++;
    }
    if(pomx != 1){
        pr *= 2;
    }
    return (pr - 1);
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    ll res = 0;
    res += nadji(n - 1);
    for(ll i = 2; i*i <= n; i++){
        if(n%i != 0)continue;
        /// za i
        ll pomn = n;
        while(pomn%i == 0)pomn /= i;
        if(pomn%i == 1)res++;
        if(i == n/i)break;
        i = n/i;
        pomn = n;
        while(pomn%i == 0)pomn /= i;
        if(pomn%i == 1)res++;
        i = n/i;
    }
    cout << res+1 << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;

int main(int argc, char ** argv) {
	ll a, b;
	cin >> a >> b;
	if(a+b > 9) cout << "error" << endl;
	else cout << (a+b) << endl;
	return 0;
}



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

int main() {
    int S, h, m, s;
    cin >> S;
    h = S / 3600;
    m = (S-h*3600) / 60;
    s = S-h*3600-m*60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=1;i<=(n);i++)
#define rep3(i,i0,n) for(ll i=i0;i<(n);i++)
#define pb push_back
#define MOD 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool comparex(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<1>(a) < get<1>(b);
        
}
bool comparey(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<2>(a) < get<2>(b);
        
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

ll modpow(ll a,ll n, ll mod){
    ll res = 1;
    while(n>0){
        if(n&1){
            res= res*a%mod;
        }
        a = a*a%mod;
        n>>=1;
    }
    return res;
}

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


    cout << modpow(m,n,MOD)<<endl;
  
    return 0;
    

}



Measured memory_bytes: 3156
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aizu
{
	class Program
	{
		static void Main(string[] args)
		{
			var answers = new List<long>();
			while (true)
			{
				var firstLine = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
				var n = firstLine[0];
				var m = firstLine[1];

				if(n == 0 && m == 0)
				{
					break;
				}

				var codes = new int[m];
				for (var i = 0; i < m; i++)
				{
					codes[i] = int.Parse(ReadLine());
				}

				var signals = new int[n];
				for (var i = 0; i < n; i++)
				{
					signals[i] = int.Parse(ReadLine());
				}

				var sums = new long[n + 1, 256];
				for (var i = 0; i <= n; i++)
				{
					for (var j = 0; j < 256; j++)
					{
						sums[i, j] = long.MaxValue - 255 * 255;
					}
				}
				sums[0, 128] = 0;

				for (var i = 1; i <= n; i++)
				{
					for (var j = 0; j < 256; j++)
					{
						foreach (var code in codes)
						{
							var outputSignal = j + code;
							if (outputSignal < 0)
							{
								outputSignal = 0;
							}
							else if (outputSignal > 255)
							{
								outputSignal = 255;
							}

							sums[i, outputSignal] = Min(sums[i, outputSignal], sums[i - 1, j] + (long)Pow(outputSignal - signals[i - 1], 2));
						}
					}
				}

				var min = long.MaxValue;
				for (var i = 0; i < 256; i++)
				{
					min = Min(min, sums[n, i]);
				}
				answers.Add(min);
			}

			answers.ForEach(value => WriteLine(value));
		}
	}
}



Measured memory_bytes: 96096