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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
    ll n,k;cin>>n>>k;
    vector<ll>v(n);
    for (int i = 0; i < n; ++i) {
        cin >>v[i];
    }
    vector<ll>ml;
    ll ans=0;
    for (int l = 0; l <=k; ++l) {
        for (int r = 0; r <= k-l; ++r) {
            if(l+r>n)continue;
            ll d=k-r-l;
            ll now=0;
            vector<ll>s;//取り出す集合
            for (int i = 0; i < l; ++i) {
                now+=v[i];
                s.push_back(v[i]);
            }
            for (int j = n-r; j <n ; ++j) {
                now+=v[j];
                s.push_back(v[j]);
            }
            sort(all(s));
            for (int m = 0; m < d; ++m) {
                if(s.size()<=m)break;
                if(s[m]>=0)break;
                now-=s[m];
            }
            ans=max(ans,now);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(void)
{
    int N, X;

    cin >> N >> X;

    vector<int> vec(N);
    for(int i = 0; i < N; i++)
    {
        cin >> vec.at(i);
        X -= vec.at(i);
    } 

    int min_value = *(min_element(vec.begin(), vec.end()));

    cout << X / min_value + N << endl;

    return 0;
}

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

int main()
{
  string s;
  int q = 0;

  cin >> s;
  for (int i = 0; i < s.size(); i++)
    q += s[i] - '0';
  cout << (stoi(s) % q == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h,w;
    cin>>h>>w;
    ll p=1000000007;
    ll dp[h][w];
    dp[0][0]=1;
    vector<string>v;
    string s;
    for(ll i=0;i<h;i++)
    {
        cin>>s;
        v.push_back(s);
    }
    for(ll i=1;i<w;i++)
    {
        if(v[0][i]=='#')
        {
            dp[0][i]=0;
        }
        else
        {
            dp[0][i]=dp[0][i-1];
        }
    }
    for(ll i=1;i<h;i++)
    {
        if(v[i][0]=='#')
            dp[i][0]=0;
        else
            dp[i][0]=dp[i-1][0];
    }
    for(ll i=1;i<h;i++)
    {
        for(ll j=1;j<w;j++)
        {
            if(v[i][j]=='#')
                dp[i][j]=0;
            else
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%p;
        }
    }
    cout<<dp[h-1][w-1];
}

Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  string s;
  cin >> s;

  int cnt = 0;
  REP(i, N){
    if(s[i] == 'R') cnt++;
    else cnt--;
  }

  if(cnt > 0) Yes;
  else No;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,n,m,k,i;
    while(T--)
    {
        cin>>n;
        ll t[n],a[n],x,y;
        FOR(i,0,n)  cin>>t[i]>>a[i];
        m = 1; k = 1;
        FOR(i,0,n)
        {
            ll z1 = ceil((long double)m/t[i]);
            ll z2 = ceil((long double)k/a[i]);
            ll z = max(z1,z2);
            x = t[i]*z-m;
            y = a[i]*z-k; 
            // cout<<x<<" "<<y<<endl;
            m +=x;
            k +=y;
        }
        ll ans=m+k;
        cout<<ans<<endl;
    }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    
    int n;
    ll ans = 0;
    cin >> n;
    int a[n + 5], cnt[n + 5] = {0};
    for(int i = 0; i < n; i++){
    	cin >> a[i];
    	ans += cnt[a[i]];
    	cnt[a[i]]++;
    }
    for(int i = 0; i < n; i++){
    	cout << ans - cnt[a[i]] + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
main(){
 char a,b;
 cin>>a;
 if(a=='H'){
  cin>>b;
  cout<<b<<endl;
 }
 else{
  cin>>b;
  if(b=='H')cout<<"D"<<endl;
  else cout<<"H"<<endl;
  }
 }

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

string IntToString(int number) {
     stringstream ss;
     ss << number;
     return ss.str();
}

bool comp(int n){
    string s = IntToString(n);
    string a = s;
    reverse(a.begin(), a.end());
    return a == s;
}

int main(){
    int n;
    cin >> n;
    for(int i=0; ; i++){
        if(comp(n-i)){cout << n-i << endl; break;}
        if(comp(n+i)){cout << n+i << endl; break;}
    }
}

Measured memory_bytes: 1224
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


class UnionFind(object):
    def __init__(self, N):
        self.tree = list(range(N))

    def root(self, i):
        if self.tree[i] == i:
            return i
        else:
            self.tree[i] = self.root(self.tree[i])
            return self.tree[i]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.tree[x] = y


def solve(N: int, K: int, L: int, p: "List[int]", q: "List[int]", r: "List[int]", s: "List[int]"):
    uf_train = UnionFind(N)
    uf_path = UnionFind(N)

    for i in range(K):
        uf_path.unite(p[i]-1, q[i]-1)
    for i in range(L):
        uf_train.unite(r[i]-1, s[i]-1)

    counter = Counter()
    for i in range(N):
        key = (uf_path.root(i), uf_train.root(i))
        counter[key] += 1

    for i in range(N):
        key = (uf_path.root(i), uf_train.root(i))
        if i != N-1:
            print(counter[key], end=" ")
        else:
            print(counter[key])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    p = [int()] * (K)  # type: "List[int]"
    q = [int()] * (K)  # type: "List[int]"
    for i in range(K):
        p[i] = int(next(tokens))
        q[i] = int(next(tokens))
    r = [int()] * (L)  # type: "List[int]"
    s = [int()] * (L)  # type: "List[int]"
    for i in range(L):
        r[i] = int(next(tokens))
        s[i] = int(next(tokens))
    solve(N, K, L, p, q, r, s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 66644
import sys
# DFSの再帰限界を増やす
sys.setrecursionlimit(10**6)

N = int(input())
nmax = 100001
# nmax = 10
# 第一成分にx,第二成分にyをぶち込んでいく。(二部グラフなので)
xys = [[[] for i in range(nmax)] for j in range(2)]

used = [[0 for i in range(nmax)] for j in range(2)]
# 読み込み
for _ in range(N):
    x, y = map(int, input().split())
    xys[0][x].append(y)
    xys[1][y].append(x)
# print(xys)

# 座標の切り替えをx = 1 or 0と1-xで行うのか、うまい！
# よく考えたらtrue/falseをひっくり返しているだけか。
def dfs(i, el=0):
    # el=0->x, el=1->y
    for i in xys[el][i]:
        if not used[1-el][i]:
            used[1-el][i] = True
            dfs(i, 1-el)
            cnt[1-el] += 1

ans = 0
for i in range(nmax):
    # まだ行ったことがなくて空じゃないところ
    if xys[0][i] != [] and used[0][i] == 0:
        used[0][i] = 1
        cnt = [1,0]
        dfs(i,0)
        ans += cnt[0]*cnt[1]
print(ans-N)


Measured memory_bytes: 96876
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i <(int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i,k,n) for (int i = (int)(n)-1; i >= k; i--)
#define INF 1LL<<61
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int o=0;
    map<char,int> m;
    rep(i,n){
        if(m.count(s[i])==0){
            o++;
            m[s[i]]=1;
        }else{
            m[s[i]]+=1;
        }
    }
    vector<int> v;
    for(auto x :m){
        v.push_back(x.second);
    }
    ll ans = 0;
    ll dp[100]={};
    rep(i,o){
        dp[i] = 1;
        rep(j,i){
            dp[i] += dp[j];
        }
        dp[i]*=v[i];
        dp[i]%=1000000007;
    }
    rep(i,o){
        ans+=dp[i];
        ans%=1000000007;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
	int n; cin >> n;
	vector<int> a(n * 3);
	for(int i = 0; i < n * 3; i++)cin >> a[i];
	sort(a.begin(), a.end(), greater<int>());
	a.resize(n * 2);
	ll sum = 0;

	for(int i = 1; i < n * 2; i += 2) {
		sum += a[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(x+r<=w && x-r>=0 && y+r<=h && y-r>=0){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3092
N, M = map(int,input().split())
li = [list(map(int,input().split())) for i in range(M)]
L = {li[i][0] for i in range(len(li)) }
R = {li[i][1] for i in range(len(li)) }


mL = max(L)
mR = min(R)

ans = mR - mL + 1
if ans <= 0: ans = 0
print(ans)

Measured memory_bytes: 38248
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type edge struct {
	node int
}

var g [][]edge
var n int
var m int
var dp [100100]float64

func rec(v int) int {
	if dp[v] != -1 {
		return int(dp[v])
	}

	res := 0.0
	for i := 0; i < len(g[v]); i++ {
		chmax(&res, float64(rec(g[v][i].node))+1)
	}
	dp[v] = res
	return int(dp[v])
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	m = nextInt()
	g = make([][]edge, n)
	for i := 0; i < n; i++ {
		g[i] = make([]edge, 0)
	}

	for i := 0; i < m; i++ {
		u, v := nextInt()-1, nextInt()-1
		g[u] = append(g[u], edge{v})
	}

	// 初期化
	for i := 0; i < n; i++ {
		dp[i] = -1
	}

	res := 0.0
	for i := 0; i < n; i++ {
		chmax(&res, float64(rec(i)))
	}
	fmt.Println(res)

}

func chmin(a *float64, b float64) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

func chmax(a *float64, b float64) bool {
	if *a < b {
		*a = b
		return true
	}
	return false
}


Measured memory_bytes: 12544
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
ll M;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    cin >> M;
    solve();
}

// 1 <= M
// M × 2 +1 <= N <= 100000

// ll N, ll M
// 以下の形式で M 行に出力せよ。i 行目には i 個目の対戦場に割り当てる二つの整数を出力せよ。
void solve(){
    if(N%2){
        rep(i,M){
            cout<<(i+1)<<' '<<(N-1-i)<<endl;
        }
    }else{
        rep(i,M){
            cout<<M-i<<' '<<M+1+i+(M+1+i-(M-i)>=N/2)<<endl;
        }
    }
}


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

vector<int>E[200000];

int dfs(int v,int p){
	int x=0;
	for(int u:E[v]){
		if(u==p)continue;
		x^=dfs(u,v);
	}
	if(v==0)return x;
	return x+1;
}
int main(){
	int n;scanf("%d",&n);
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	puts(dfs(0,-1)?"Alice":"Bob");
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#include <algorithm> //next_permutation

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;

int main(){

int n;
cin>>n;
vector <int> a(n);
for (int i=0; i<n;i++){
  cin>>a[i];
}
sort(a.begin(),a.end());

int temp=0;
string ans="YES";
for (int i=0; i<n;i++){
  if (temp==a[i]) ans="NO";
  temp=a[i];
}
cout<<ans;
}


Measured memory_bytes: 1024
function Main(input){
  for(var  i = 0; i < 10; i++){
    var re = new RegExp(String(i) + String(i) + String(i),'g');
    var arr = input.match(re);
    if(re.test(input)){
        console.log('Yes');
        return;
    }
  }
  console.log('No');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <stdio.h>

int main() {
	int A,B,K;
	scanf("%d %d %d",&A,&B,&K);
	int large=(A > B) ? A : B;
	int Common_div[large];
	int cnt=0;
	for (int i = 1; i <= large; i++) {
		if (A%i == 0 && B%i == 0) {
			Common_div[cnt] = i;
			cnt++;
		}
	}
	printf("%d\n",Common_div[cnt-1-(K-1)]);
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1e8
#define ALL(a) a.begin(), a.end()
#define MAXEL max_element
#define MINEL min_element
#define POW (long long)pow
#define BIT(i) (long long)pow(2, i)
typedef long long Lint;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  REP(i, n) {
    int a;
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long A, long long B){
  ll ans=0;
  ans=(N/(A+B))*A+((N%(A+B))>A?A:N%(A+B));
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


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

public class Main {	
	private static void solve(){
		//Implement solution here.
		int N = ni();
		int R = ni();
		System.out.println(N < 10 ? R + 100 * (10 - N) : R);
	}
	


	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 21204
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int mul(string s,int& i);
int bracket(string s,int& i);

int mul(string s,int& i){
	int ret=bracket(s,i);
	while(s[i]=='*'||s[i]=='^'){
		char op=s[i];
		i++;
		int res=bracket(s,i);
		if(op=='*')ret&=res;
		else ret^=res;
	}
	return ret;
}

int bracket(string s,int& i){
	if(s[i]=='1'||s[i]=='0'){
		return int(s[i++]-'0');
	}
	if(s[i]=='-'){
		++i;
		return 1-bracket(s,i);
	}
	i++;
	int ret=mul(s,i);
	i++;
	return ret;
}


int calc(string s){
	int n=16;
	int ans=0;
	rep(i,n){
		string t=s;
		rep(j,s.size()){
			if(t[j]=='a')t[j]='0'+((i>>3)&1);
			if(t[j]=='b')t[j]='0'+((i>>2)&1);
			if(t[j]=='c')t[j]='0'+((i>>1)&1);
			if(t[j]=='d')t[j]='0'+((i>>0)&1);
		}
		int k=0;
		int ret=mul(t,k);
		ans+=ret*(1<<i);
	}
	return ans;
}

vector<string> list;
vector<int> ans(65536,inf);
void add(string s){
	//cout<<s<<endl;
	int res=calc(s);
	if(s.size()>=ans[res])return;
	ans[res]=s.size();
	list.push_back(s);
	int m=list.size();
	rep(i,m-1){
		string t = '('+list[i]+'^'+s+')';
		if(t.size()>16)continue;
		string u= '('+list[i]+'*'+s+')';
		add(t);add(u);
	}
	s='-'+s;
	add(s);
}
int main(){
	add("1");add("0");
	add("a");add("b");add("c");add("d");
	string s;
	while(cin>>s){
		if(s[0]=='.')break;
		int ret=calc(s);
		cout<<ans[ret]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3388
#include <stdio.h>

int main(){
	int n, t, min = 1005, cost, time;

	scanf("%d %d", &n, &t);
	for(int i = 0; i < n; i++){
		scanf("%d %d", &cost, &time);
		if(time <= t)
			if(cost < min)min = cost;
	}
	if(min == 1005)
		printf("TLE\n");
	else
		printf("%d\n", min);
	return 0;
}


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

// 基本的には一番上の桁から下りながら, 1-9をそれぞれ調べていく.
// i桁目までの結果smallerだったテーブルは(i+1)はどうやってもsmaller.
// i桁目までsmallerではないつまりsameだった場合,
//      Nのi桁目より小さいものを選べば
//          i+1はsmaller
//      Nのi桁目と同じものを選べば
//          i+1はsame
//
// 初期条件は dp[0桁目][same][ng] = 1
// dp[i][smaller][ok] = i桁目まで見た時にsmallerでokだったものの数.

// 桁 / smaller(else: same) / ok
int dp[101][2][5];
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string N;
    int K;
    cin >> N >> K;
    int l = N.length();
    vector<int> n;
    for (auto c: N) {
        n.push_back(c - '0');
    }
    // 桁 smaller
    dp[0][0][0] = 1;
    for (int i = 0; i < l; i++) {
        for (int smaller = 0; smaller < 2; smaller++) {
            for (int k = 0; k <= K; k++) {
                for (int x = 0; x <= (smaller ? 9 : n[i]); x++) {
                    int next_smaller = (int)(smaller || x < n[i]);
                    int next_k = k + (int)(x != 0);
                    dp[i + 1][next_smaller][next_k] += dp[i][smaller][k];
                }
            }
        }
    }
    cout << dp[l][0][K] + dp[l][1][K] << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define BE(x) x.begin(), x.end()

int f(int n, int c, vector<vector<int>> a, vector<bool> b) {
    if (n == 0)
        return 1;
    int res = 0;
    int s = a[c].size();
    for (int i = 0; i < s; i++) {
        int tmp = a[c][i];
        if (b[tmp]) {
            vector<bool> d = b;
            d[tmp] = false;
            res += f(n-1, tmp, a, d);
        }
    }
    return res;
}

int main() {
    int n, m, x, y;
    cin >> n >> m;
    vector<vector<int>> a(n);
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        x--, y--;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    vector<bool> b(n, true);
    b[0] = false;
    cout << f(n-1, 0, a, b) << endl;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n; cout << (n + 1) / 2 << endl;
	return 0;
}

/*


*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll d,t,s;cin>>d>>t>>s;
    ll x=t*s;
    if(d<=x)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    int h[n+1];
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    int ans = 0;
    while(true){
        int l = -1;
        int r = -1;
        for(int i = 1; i <= n; i++){
            if(h[i] != 0){
                l = i;
                break;
            }
        }
        if(l == -1){
            break;
        }
        for(int i = l; i <= n; i++){
            if(h[i] == 0){
                break;
            } else {
                r = i;
            }
        }
        for(int i = l; i <= r; i++){
            h[i]--;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std;
const int maxn=10000+5;
int n,hd[maxn],to[maxn*2],nxt[maxn*2],w[maxn*2],cnt,maxdis[maxn],secdis[maxn];
inline void add(int s,int x,int y){
    w[cnt]=s;to[cnt]=y;nxt[cnt]=hd[x];hd[x]=cnt++;
}
inline void dfs(int root,int fa){
    for(int i=hd[root];i!=-1;i=nxt[i])
        if(to[i]!=fa){
            dfs(to[i],root);
            if(maxdis[to[i]]+w[i]>maxdis[root])
                secdis[root]=maxdis[root],maxdis[root]=maxdis[to[i]]+w[i];
            else if(maxdis[to[i]]+w[i]>secdis[root])
                secdis[root]=maxdis[to[i]]+w[i];
        }
}
inline void change(int root,int fa){
    for(int i=hd[root];i!=-1;i=nxt[i])
        if(to[i]!=fa){
            if(maxdis[root]==maxdis[to[i]]+w[i]){
                if(maxdis[to[i]]<secdis[root]+w[i])
                    secdis[to[i]]=maxdis[to[i]],maxdis[to[i]]=secdis[root]+w[i];
                else if(secdis[to[i]]<secdis[root]+w[i])
                    secdis[to[i]]=secdis[root]+w[i];
            }
            else{
                if(maxdis[to[i]]<maxdis[root]+w[i])
                    secdis[to[i]]=maxdis[to[i]],maxdis[to[i]]=maxdis[root]+w[i];
                else if(secdis[root]<secdis[root]+w[i])
                    secdis[to[i]]=maxdis[root]+w[i];
            }
            change(to[i],root);
        }
}
signed main(void){
    scanf("%d",&n);cnt=0;memset(hd,-1,sizeof(hd));
    for(int i=1,s,x,y;i<n;i++)
        scanf("%d%d%d",&x,&y,&s),add(s,x,y),add(s,y,x);
    memset(maxdis,0,sizeof(maxdis));memset(secdis,0,sizeof(secdis));
    dfs(0,-1);change(0,-1);
    for(int i=0;i<n;i++)
        printf("%d\n",maxdis[i]);
    return 0;   
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)4e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

int main(){
	int H, W;
	int whitesum = 0;
	cin>>H>>W;
	vector<vector<char> > m(H, vector<char>(W));
	vector<vector<int> > fast(H, vector<int>(W, INF));
	REP(y, H){
		REP(x, W){
			cin>>m[y][x];
			m[y][x]=m[y][x]=='.';
			whitesum+=m[y][x];
		}
	}
	int mx[]={1, 0, -1, 0}, my[]={0, 1, 0, -1};
	deque<PII> deq;
	deq.push_back({0, 0});
	fast[0][0]=0;
	while(!deq.empty()){
		PII d = deq.front();
		deq.pop_front();
		REP(i, 4){
			int ny = my[i] + d.first;
			int nx = mx[i] + d.second;
			if(ny<0||H<=ny||nx<0||W<=nx)continue;
			if(!m[ny][nx])continue;
			int ntime = fast[d.first][d.second] + 1;
			if(fast[ny][nx]>ntime){
				fast[ny][nx]=ntime;
				if(m[d.first][d.second])deq.push_back({ny, nx});
			}
		}
	}
	if(fast[H-1][W-1]==INF)cout << -1 << endl;
	else
		cout << whitesum - fast[H-1][W-1] - 1 << endl;
	return 0;
}


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

int main(){
	int inning_num;
	
	cin >> inning_num;
	for (int i = 0; i < inning_num; i++){
		int out = 0;
		unsigned char state = 0;
		int score = 0;
		while (out != 3){
			string in;
			cin >> in;
			if (in == "OUT"){
				out++;
			}
			else if (in == "HIT"){
				state <<= 1;
				state |= 0x0001;
			}
			else if (in == "HOMERUN"){
				state <<= 1;
				state |= 0x0001;
				state <<= 3;
			}
			for (unsigned char j = (1<<3); j; j <<= 1){
				if (state & j) {
					score++;
					state &= ~j;
				}
			}
		}
		cout << score << "\n";
	}
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, ans = 0;
	cin >> n;
	vector<int> d(n);
	for(int i=0;i<n;i++)
		cin >> d.at(i);

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ans += d.at(i) * d.at(j);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    ll sa = 0, sb = 0;
    vector<pair<ll, pair<ll, ll>>> C(N);
    rep(i, N) {
        C[i].first = - A[i] - B[i];
        C[i].second = mp(A[i], B[i]);
        
    }
    sort(all(C));
    rep(i, N) {
        if(i % 2 == 0) sa += C[i].second.first;
        else sb += C[i].second.second;
    }

        
    output(sa - sb);
    
    return 0;
}


Measured memory_bytes: 4224
// abc139_c
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> H;
	vector<int> H2;
	H.resize(N);
	H2.resize(N);

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

	for (int i = 0; i < N - 1; i++) {
		if (H[i] < H[i + 1]) {
			H2[i] = 1;
		}
		else {
			H2[i] = 0;
		}
		//cout << H2[i] << " ";
	}
	//cout << endl;
	int max = 0;
	int count = 0;
	for (int i = 0; i < N - 1; i++) {
		if (H2[i] == 1) {
			if (max < count) {
				max = count;
			}
			count = 0;
		}
		else {
			count++;
		}
	}
	if (max < count) {
		max = count;
	}

	cout << max << endl;

}

Measured memory_bytes: 1024
process.stdin.resume();
process.stdin.setEncoding('utf8');
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
var N = lines[0];
var H = lines[1];
var W = lines[2];
var line = N - H + 1;
var row = N - W + 1;
var res = line * row;
  console.log(res);
});

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

using namespace std;
using ll = long long;

void solve(long long A, long long B, long long C, long long D){
    ll total = B-A+1;
    ll cCount = B/C - (A-1)/C;
    ll dCount = B/D - (A-1)/D;
    ll lcm = ((C*D)/__gcd(C,D));
    ll both = B/lcm - (A-1)/lcm;
    cout << total - cCount - dCount + both << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
import math

d,g=map(int,input().split())
pclist=[]
templist=[]
for i in range(d):
	templist=[]
	templist=list(map(int,input().split()))
	templist.append(templist[0]*100*(i+1)+templist[1])
	pclist.append(templist)

promin=1000

for i in range(2**d):
    gsum=0
    prosum=0
    maxind=100
    
    for j in range(d):
        if (i >> j)& 1:
            gsum += pclist[j][2]
            prosum += pclist[j][0]
        else:
            maxind=j
            
    
    if gsum >= g:
        if prosum <= promin:
            promin=prosum
    elif (gsum + (maxind+1)*100*(pclist[maxind][0]-1))>= g:
        prosum += math.ceil((g-gsum)/((maxind+1)*100))
        if prosum <= promin:
            promin=prosum


print(promin)


Measured memory_bytes: 3064
import numpy as np

n, m, x = map(int, input().split())

c = []
score = []
for _ in range(n):
    inp = list(map(int, input().split()))
    c.append(inp[0])
    score.append(inp[1:])
c = np.array(c)
score = np.array(score)

ans = float('inf')
for i in range(2 ** n):
    scores = np.array([0] * m)
    cost = 0
    for j in range(n):
        if (i >> j) & 1:
            scores += score[j]
            cost += c[j]
    if all(scores >= x):
        ans = min(ans, cost)

if ans == float('inf'):
    print(-1)
else:
    print(ans)


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

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

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

    int count = 0;
    for(int i=1; i<n-1; i++){
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])){
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}

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

#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)


int32_t main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    ll n,w;
    cin>>n>>w;
    ll v[n],wt[n];
    fori(0,n)cin>>wt[i]>>v[i];

    ll maxval=n*1000;
    ll dp[n+1][maxval+1];

    fori(1,maxval+1)dp[1][i]=inf;
    dp[1][0]=0;
    dp[1][v[0]]=wt[0];

    for(int i=2;i<=n;i++)
        for(int j=0;j<=maxval;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(v[i-1]<=j)dp[i][j]=min(dp[i][j],wt[i-1]+dp[i-1][j-v[i-1]]);
        }

    ll ans=0;
    fori(0,maxval+1)if(dp[n][i]<=w)ans=i;

    cout<<ans<<"\n";



   
}
    

Measured memory_bytes: 81760
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100005];
bool vis[100005];
deque<int>dq;
void dfs1(int i){
	vis[i]=true;
	for(int j:adj[i]){
		if(!vis[j]){
			dq.push_front(j);
			dfs1(j);
			break;
		}
	}
}
void dfs2(int i){
	vis[i]=true;
	for(int j:adj[i]){
		if(!vis[j]){
			dq.push_back(j);
			dfs2(j);
			break;
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dq.push_back(1);
	dfs1(1);
	dfs2(1);
	cout<<dq.size()<<"\n";
	for(int i:dq) cout<<i<<" ";
}

Measured memory_bytes: 7040
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int num[10];
int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  int search=0,found=0;
  while(search<1000){
    int index[3]={search/100,(search/10)%10,search%10};
    int i=0,j=0,k=0;
    for(i;i<n;i++){
      if(s.at(i)==(index[0]+'0'))break;
    }
    for(j=i+1;j<n;j++){
      if(s.at(j)==(index[1]+'0'))break;
    }
    for(k=j+1;k<n;k++){
      if(s.at(k)==(index[2]+'0')){
        found++;
        break;
      }
    }
    search++;
  }
  cout<<found<<endl;
  return 0;
}




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

ll N, M, ans=0, tmp=0, a, b, c;
vector<ll> A;
priority_queue<pair<ll, ll>> Q;

signed main(){
    cin >> N >> M;
    for(int i=0;i<N;i++) {
        cin >> a;
        A.push_back(a);
    }
    for(int i=0;i<M;i++) {
        cin >> b >> c;
        Q.push(make_pair(c, b));
    }
    while(!Q.empty()) {
        if(tmp==N) break;
        pair<ll, ll> p = Q.top();
        Q.pop();
        for(int i=0;i<p.second;i++) {
            if(tmp==N) break;
            else A.push_back(p.first);
            tmp++;
        }
    }
    sort(A.begin(), A.end());
    //cout << "OK" << endl;
    for(int i=A.size()-1;i>=A.size()-N;i--) {
        ans += A[i];
        //cout << A[i] << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3952
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static final long MOD = 1_000_000_007;

    private static int nextUnitAmida(int x) {
        int mask1 = 1;
        int mask2 = 3;
        ++x;
        for (;;) {
            int ck = x & mask2;
            if (ck == mask1) {
                break;
            } else if (ck == mask2) {
                x += mask1;
            }
            mask1 <<= 1;
            mask2 <<= 1;
        }
        return x;
    }

    private static int[] createUnitAmida(int w) {
        List<Integer> uAmidas = new ArrayList<>();
        int x = 0;
        int limit = (1 << (w - 1));
        do {
            uAmidas.add(x);
            x = nextUnitAmida(x);
        } while (x < limit);

        int[] result = new int[uAmidas.size()];
        for (int i = 0; i < result.length; ++i) {
            result[i] = uAmidas.get(i);
        }
        return result;
    }

    private final int height;

    private final int width;

    private final int[] unitAmidas;

    private Main(int h, int w) {
        height = h;
        width = w;
        unitAmidas = createUnitAmida(w);
    }

    long countIt(int goal) {
        return countSub(height, 1, goal);
    }

    private long countSub(int h, int start, int goal) {
        if (Math.abs(start - goal) > h) {
            return 0;
        }
        if (h > 1) {
            final int h1 = h / 2;
            final int h2 = h - h1;
            long result = 0;
            if (h1 == h2 && start == goal) {
                for (int k = 0; k < width; ++k) {
                    long r1 = countSub(h1, start, k + 1);
                    result += r1 * r1;
                }
            } else {
                for (int k = 0; k < width; ++k) {
                    long r1 = countSub(h1, start, k + 1);
                    long r2 = countSub(h2, k + 1, goal);
                    result += r1 * r2;
                }
            }
            return (result < MOD ? result : result % MOD);
        }

        assert h == 0;

        final int rMask = (1 << (start - 1));
        final int lMask = (rMask >> 1);

        int rCase = 0;
        int lCase = 0;
        int mCase = 0;

        for (int unitAmida : unitAmidas) {
            if ((unitAmida & rMask) != 0) {
                ++rCase;
            } else if ((unitAmida & lMask) != 0) {
                ++lCase;
            } else {
                ++mCase;
            }
        }

        long result;
        if (start == goal) {
            result = mCase;
        } else if (start == goal - 1) {
            result = rCase;
        } else {
            result = lCase;
        }
        return result;
    }

    public static void main(String[] args) {
        try (
                Scanner in = new Scanner(System.in);
                PrintWriter out = new PrintWriter(System.out))
        {
            final int H = in.nextInt();
            final int W = in.nextInt();
            final int K = in.nextInt();

            long result = new Main(H, W).countIt(K);
            out.println(result);
        }
    }
}


Measured memory_bytes: 26388
use std::ops::Sub;
use std::ops::Div;
use std::ops::Mul;
use std::ops::Rem;
use std::ops::ShrAssign;
use std::ops::BitAnd;

const MOD: i64 = 1000000007;


fn main() {
    let n: i64 = read();
    let mut an: Vec<i64> = read_vec();

    if check(&mut an) {
        println!("{:?}", modpow(2, n / 2, MOD));
    } else {
        println!("{:?}", 0);
    }

}

fn check(seq: &mut Vec<i64>) -> bool {
    seq.sort();
    let mut init = 1;

    if seq.len() % 2 != 0 {
        if seq.remove(0) != 0 {
            return false
        }
        init = 2;
    }

    let mut i = 0;
    while i < seq.len() {
        if seq[i] == init && seq[i+1] == init {
            init += 2;
            i += 2;
        } else {
            return false
        }
    }

    true
}

pub fn modpow<T>(mut a: T, mut n: T, m: T) -> T
    where T: Sub<Output=T> + Div<Output=T> + Mul<Output=T> + Rem<Output=T> + ShrAssign + PartialOrd + BitAnd<Output=T> + Copy + From<u8>
{
    let zero = T::from(0);
    let one = T::from(1);
    let mut res = one;

    while n > zero {
        if (n & one) == one {
            res = res * a % m;
        }
        a = a * a % m;
        n >>= one;
    }

    res
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}




Measured memory_bytes: 6396
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
int A[105];
int main()
{
    int N;
    while(scanf("%d",&N)!=EOF)
    {
        int M,X;
        scanf("%d %d",&M,&X);
        int L=0,R=0;
        for(int i=0;i<M;i++)
        {
            int temp;
            scanf("%d",&temp);
            if(temp>X)
                R++;
            else
                L++;
        }
        if(R>L)
            printf("%d\n",L);
        else
            printf("%d\n",R);
    }
    return 0;
}


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

using namespace std;

void lSort(long long int &a, long long int &b)
{
    if(a > b)
    {
        b = a + b;
        a = b - a;
        b = b - a;
    }
}

bool isValid(long long int a, long long int b, long long int c)
{
    if(a==b)
        return false;
    else if(b==c)
        return false;
    else if(c==a)
        return false;
    lSort(a, b);
    lSort(a, c);
    lSort(b, c);

    if(c < a + b)
        return true;
    else
        return false;
}

int main()
{
    int N;
    cin >> N;
    int *sides = new int[N];
    for(int i = 0; i < N; i++)
        cin >> sides[i];

    long long int resultado = 0;
    for(int i = 0; i < N; i++)
        for(int j = i+1; j < N; j++)
            for(int k = j+1; k < N; k++)
                if(isValid(sides[i], sides[j], sides[k]) == true)
                    resultado++;

    cout << resultado;
    return 0;
}


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

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

    int count = 0;

    rep(i,s.size()) {
        if (s[i] == s[i+1]) {
            count++;
            int x = (s[i] + 1) % 2;
            s.replace(i + 1, 1, to_string(x));
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args){
    Scanner scan =new Scanner(System.in);
    String n=scan.next();
    
    if(n.equals("ABC")){
      System.out.println("ARC");
    }else if(n.equals("ARC")){
      System.out.println("ABC");
    }
  }
}

Measured memory_bytes: 35728
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int w;

	while ( cin >> w )
	{
		set<int> weights;

		for ( int i = 9; 0 <= i; i-- )
		{
			int weight = pow( 2, i );

			if ( weight <= w )
			{
				w -= weight;
				weights.insert( weight );
			}
		}

		for ( set<int>::iterator it = weights.begin(); it != weights.end(); )
		{
			cout << *it;

			if ( ++it == weights.end() )
			{
				cout << endl;
			}
			else
			{
				cout << ' ';
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
while 1:
    try:
        n=input()
        if n==0:break
        l=m=0
        for i in [1]*n:
            p,d1,d2=map(int,raw_input().split())
            d=d1+d2
            if d>m:l,m=p,d
        print l,m
    except SyntaxError:
        pass

Measured memory_bytes: 4272
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int x;
		int sec,min,hour;
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();

		sec = x % 60;
		x = x / 60;
		min = x % 60;
		x = x / 60;
		hour = x;

		System.out.println(hour +":"+ min + ":"+ sec);
		sc.close();
	}

}

Measured memory_bytes: 26164
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define NMAX 100000
#define INF 1e+6
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
ll k;
string s;
int main(){
  scan(s);scan(k);
  int j=0;
  while(s[j]=='1')j++;
  if(k<=j)prin(1);
  else prin(s[j]);

  
  return 0;
}


Measured memory_bytes: 256