akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define pii pair<int, int>
#define pt(xx) cout << "\n" \
                    << xx << "\n"
#define debugv(x)               \
    cout << "\n"                   \
         << #x << ": ";            \
    rep(i, x.size()) cout << x[i] << " "; \
    cout << endl
#define debug2d(x)            \
    cout << "\n"                    \
         << #x << " is: \n";        \
    rep(i,x.size())     \
    {                               \
        rep(j,x[0].size()) \
        {                           \
            cout << x[i][j] << " "; \
        }                           \
        cout << endl;               \
    }
#define nl cout << endl

#define MOD 1000000007
using namespace std;

int N, M, K;
int Q;
int ans = 0;

signed main()
{

    string s;
    cin>>s;


    int a,b;
    map<char,int> m;
    rep(i,s.size()){
        m[s[i]]++;
        a = s[i];
    }


    bool ans = false;
    if (s[0]==s[1]){
        if (s[2]==s[3]){
           if (s[0] != s[2]){
               ans = true;
           } 
        }
    }
        if (s[1]==s[3]){
            if (s[2]==s[0] && s[0] != s[1])
            ans = true;
        }

    if (s[0] == s[3])
    if (s[1]==s[2])
    if (s[0]!=s[1]) ans = true;

cout<<(ans? "Yes":"No")<<endl;
    




    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main(){

    lli n,x;
    while(cin>>n>>x){
        if(n==0 && x==0)break;
        lli ans = 0;
        for(lli i=1;i<=n;i++){
            for(lli j=i+1;j<=n;j++){
                lli k = x-(i+j);
                if(k>j && k <= n)ans++;
            }
        }
        cout<<ans<<endl;
    }
 
    return 0;
}


Measured memory_bytes: 3088
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use proconio::{fastout, input};
use std::cmp::*;
use std::collections::*;
use std::mem::*;

#[fastout]
fn main() {
  input! {
    n:usize,
    s:usize,
    a:[usize;n],
  }
  let mut dp = vec![vec![0; s + 1]; n + 1];
  dp[0][0] = 1;
  // for i in 0..=n {
  //   dp[i][0] = 1;
  // }
  for i in 0..n {
    // dp[i + 1][a[i]] += 1;
    // for j in 0..=s {
    //   dp[i + 1][j] += dp[i][j];
    // }
    for j in 0..=s {
      dp[i + 1][j] = (dp[i + 1][j] + 2 * dp[i][j]) % MOD;
      if j + a[i] <= s {
        dp[i + 1][j + a[i]] = (dp[i + 1][j + a[i]] + dp[i][j]) % MOD;
      }
    }
  }
  // dbg!(&dp);
  println!("{}", (dp[n][s] + MOD) % MOD);
}
const MOD: usize = 998244353;


Measured memory_bytes: 72472
//
//  AOJ 0558 Chees
//
//  Created by TaoSama on 2015-02-20
//  Copyright (c) 2014 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

struct Point {
	int x, y;
	Point(int x = 0, int y = 0): x(x), y(y) {}
} c[15];
int n, m, k, dp[1005][1005];
int d[4][2] = { -1, 0, 1, 0, 0, 1, 0, -1};
char a[1005][1005];

int bfs(int x) {
	memset(dp, 0x3f, sizeof dp);
	queue <Point> q; q.push(c[x - 1]);
	dp[c[x - 1].x][c[x - 1].y] = 0;
	while(!q.empty()) {
		Point cur = q.front(); q.pop();
		for(int i = 0; i < 4; ++i) {
			Point nxt(cur.x + d[i][0], cur.y + d[i][1]);
			if(nxt.x < 1 || nxt.x > n || nxt.y < 1 || nxt.y > m
			        || a[nxt.x][nxt.y] == 'X') continue;
			if(dp[nxt.x][nxt.y] == INF) {
				dp[nxt.x][nxt.y] = dp[cur.x][cur.y] + 1;
				q.push(nxt);
			}
		}
	}
	return dp[c[x].x][c[x].y];
}
int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	while(cin >> n >> m >> k) {
		for(int i = 1; i <= n; ++i) {
			for(int j = 1; j <= m; ++j) {
				cin >> a[i][j];
				if(a[i][j] == 'S')
					c[0].x = i, c[0].y = j;
				if(isdigit(a[i][j]))
					c[a[i][j] - '0'].x = i, c[a[i][j] - '0'].y = j;
			}
		}
		int ans = 0;
		for(int i = 1; i <= k; ++i)
			ans += bfs(i);
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    char c;
    int n = 0, m = 0;
    while((c = getchar()) != EOF){
        if(c == 'A' || c == 'T' || c == 'G' || c == 'C'){
            n++;
            m = max(n, m);
        }
        else{
            n = 0;
        }
    }
    cout << m << endl;
}

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

int main(){
  int n; int k; cin >> n >> k;
  bool table[10];
  for(int i=0; i<10; i++) table[i] = false;

  for(int i=0; i<k; i++) {
    int d; cin >> d;
    table[d] = true;
  }

  for(; ; n++){
    string nstr = to_string(n);
    bool flag=false;
    for(int i=0; i<nstr.length(); i++){
      if(table[nstr[i]-'0']) {
        flag = true;
        break;
      }
    }
    if(!flag) break;
  }

  cout << n << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;



void Main(){

  int N;
  cin >> N;

  rep(i,N-1){
    reps(j,i+1,N){
      int x=i; int y=j;
      int z=x^y;
      rep(k,10){
        if(z>>k&1){
          cout << k+1 <<" ";
          break;
        }
      }
    }
    cout <<"\n";
  }
}


  //-----------------------------------
  int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
  }
  //-----------------------------------


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

int main() {
	vector<int> V(3);
	cin >> V[0] >> V[1] >> V[2];
	sort(V.begin(), V.end());
	if((V[1] == V[0] || V[1] == V[2]) && V[0] != V[2]) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin>>s;
    rep(i,s.size()){
        if(s[i]=='1') cout<<9;
        else if(s[i]=='9') cout<<1;
        else cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int arr[n][3],a[2],t=0,answer=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++)
  cin>>arr[i][j];
  }
  for(int i=n-2;i>=0;i--){
  for(int j=0;j<3;j++){
    t=0;
  for(int k=0;k<3;k++){
  if(j!=k){
    a[t]=arr[i+1][k];
    t++;
  }
  }
    arr[i][j]=max(arr[i][j]+a[0],arr[i][j]+a[1]);
  }
  }
  for(int i=0;i<3;i++){
  if(arr[0][i]>answer){
  answer=arr[0][i];
  }
  }
  cout<<answer;
  return 0;
}

Measured memory_bytes: 1408
#[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(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! 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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        w: usize,
        wv: [(usize, usize); n],
    }

    let maxv = n * 1000;
    let mut tbl = vec![vec![1_000_000_000_000_000; maxv + 1]; n + 1];
    tbl[0][0] = 0;

    for i in 0..maxv + 1 {
        for j in 0..n {
            let mut t = tbl[j][i];
            if i >= wv[j].1 {
                t = min(t, tbl[j][i - wv[j].1] + wv[j].0);
            } else {
                t = min(t, wv[j].0);
            }
            tbl[j + 1][i] = t;
        }
    }

    let mut ans = 0;
    for i in 0..maxv + 1 {
        if tbl[n][i] <= w {
            ans = i;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 106748
#include <iostream>
#include <cmath>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,n;
    cin>>a>>b>>n;
    ll t1,t2,ans;
    if(n<b)
    {
        ans=(a*n)/b-a*(n/b);
        cout<<ans<<endl;
    }
    else
    {
        t1=(b-1)*a/b;
        t2=n*a/b-a*(n/b);
        cout<<max(t1,t2)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

ll ans = 0;
vector<ll> r, g, b;

void solve(vector<ll> R, vector<ll> G, vector<ll> B){
    rep(i, R.size()){
        rep(j, G.size()){
            if(R[i] > G[j])continue;
            ans += B.end() - lower_bound(all(B), G[j]);
            if(binary_search(all(B), 2*G[j]-R[i]))ans--;
        }
    }
}
int main() {
    ll n;
    string s;
    cin >> n >> s;
    rep(i, n){
        if(s[i] == 'R')r.push_back(i);
        if(s[i] == 'G')g.push_back(i);
        if(s[i] == 'B')b.push_back(i);
    }
    solve(r, g, b);
    solve(r, b, g);
    solve(b, r, g);
    solve(b, g, r);
    solve(g, r, b);
    solve(g, b, r);
    cout << ans << endl;
}   

Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {
	static class Vertex {
		int number;
		int degree;
		Vertex neighbor[];
		Edge edge[];
		int cost;
		boolean mark;

		Vertex (int number, int n, int m) {
			this.number = number;
			this.degree = 0;
			neighbor = new Vertex[n];
			edge = new Edge[m];
			this.cost = Integer.MAX_VALUE;
			this.mark = false;
		}

		public void remake(Vertex v, Edge e) {
			neighbor[degree] = v;
			edge[degree] = e;
			this.degree++;
		}

		public String toString() {
			String s = "";
			for (int i = 0; i < degree; i++) {
				s += (neighbor[i].number + 1) + " ";
				if (edge[i].v1 == this) {
					s += edge[i].costFromV1 + " ";
				} else {
					s += edge[i].costFromV2 + " ";
				}
			}
			return s;
		}
	}

	static class Edge {
		int number;
		Vertex v1, v2;
		int costFromV1;
		int costFromV2;

		Edge (int number, Vertex v1, Vertex v2, int costFromV1, int costFromV2) {
			this.number = number;
			this.v1 = v1;
			this.v2 = v2;
			this.costFromV1 = costFromV1;
			this.costFromV2 = costFromV2;
		}
	}

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		Vertex vertex[];
		Edge edge[];

		n = sc.nextInt();
		m = sc.nextInt();
		vertex = new Vertex[n];
		edge = new Edge[m];
		for (int i = 0; i < n; i++) {
			vertex[i] = new Vertex(i, n, m);
		}
		for (int i = 0; i < m; i++) {
			String s[] = sc.next().split(",");
			int a = Integer.valueOf(s[0]) - 1;
			int b = Integer.valueOf(s[1]) - 1;
			int c = Integer.valueOf(s[2]);
			int d = Integer.valueOf(s[3]);
			edge[i] = new Edge(i, vertex[a], vertex[b], c, d);
			vertex[a].remake(vertex[b], edge[i]);
			vertex[b].remake(vertex[a], edge[i]);
		}
		String s[] = sc.next().split(",");
		int a = Integer.valueOf(s[0]) - 1;
		int b = Integer.valueOf(s[1]) - 1;
		int c = Integer.valueOf(s[2]);
		int d = Integer.valueOf(s[3]);
		int total = c;
		total -= minimumWay(vertex, edge, a, b);
		for (int i = 0; i < n; i++) {
			vertex[i].cost = Integer.MAX_VALUE;
			vertex[i].mark = false;
		}
		total -= d;
		total -= minimumWay(vertex, edge, b, a);
		System.out.println(total);
	}

	public static int minimumWay(Vertex v[], Edge e[], int start, int goal) {
		int n = v.length;
		int index = start;
		int minIndex;

		v[start].cost = 0;
		while (!v[goal].mark) {
			v[index].mark = true;
			for (int i = 0; i < v[index].degree; i++) {
				Vertex v1 = v[index].neighbor[i];
				Edge e1 = v[index].edge[i];
				if (!v1.mark) {
					if (e1.v1 == v[index]) {
						if (v[index].cost + e1.costFromV1 < v1.cost) {
							v1.cost = v[index].cost + e1.costFromV1;
						}
					} else {
						if (v[index].cost + e1.costFromV2 < v1.cost) {
							v1.cost = v[index].cost + e1.costFromV2;
						}
					}
				}
			}
			minIndex = -1;
			for (int i = 0; i < n; i++) {
				if (!v[i].mark && (minIndex == -1 || v[i].cost < v[minIndex].cost)) {
					minIndex = i;
				}
			}
			index = minIndex;
		}
		return v[goal].cost;
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    ll n; scll(n);
    ll ans = 0, tmp = 2*5;
    while (tmp <= n){
        ans += n / tmp;
        tmp *= 5ll;
    }
    if (n % 2) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
import math
def cmb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
count = 0
l_s =[]
for i in range(N):
    s = input()
    l = list(s)
    l.sort()
    s = ''.join(l)
    l_s.append(s)
d_s = collections.Counter(l_s)
for i in d_s.values():
        count+=cmb(i,2)
print(count)

Measured memory_bytes: 68696
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;



int MOD=1000000007;
int main(void){
	int N;
	cin >> N;
	if(N%2==0) cout << N/2-1 << endl;
	else cout << (N+1)/2-1 << endl;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

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

  return 0;
}

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

int main(int argc, char *argv[]){
  string s;
  int bh, bm, bs, eh, em, es;
  for (int i = 0; i < 3; i++) {
    getline(cin, s);
    sscanf(s.c_str(), "%d %d %d %d %d %d", &bh, &bm, &bs, &eh, &em, &es);
    int t = (eh*3600 + em*60 + es) - (bh*3600 + bm*60 + bs);
    std::cout << t/3600 << " ";
    t %= 3600;
    std::cout << t/60 << " ";
    t %= 60;
    std::cout << t << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1236
n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = input().rstrip()
if c < d:
    s = s[a:d]
    for c0, c1 in zip(s, s[1:]):
        if c0 == c1 == '#':
            print('No')
            break
    else:
        print('Yes')
else:
    ok = False
    for i in range(b - 1, d):
        if i + 2 < n and s[i] == s[i + 1] == s[i + 2] == '.':
            ok = True
            break
    else:
        print('No')
    if ok:
        s = s[a:c]
        for c0, c1 in zip(s, s[1:]):
            if c0 == c1 == '#':
                print('No')
                break
        else:
            print('Yes')

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
#define inff 100000


ll modo=1e9+7;



int main()
{
   faf;
   int n;
   cin>>n;
   double  ar[n];
   int i;
   double sum=0;
   for(i=0;i<n;i++)
   {
       cin>>ar[i];
       sum+=(1/ar[i]);
   }
   double  ans=1/sum;
   cout<<fixed;
   cout<<setprecision(6)<<ans;
   //cout<<ans;
   return 0;
}

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

int main() {
    string str;

    cin >> str;

    if(str.at(0) == str.at(1) && str.at(1) == str.at(2)){
        cout << "Yes";
    }else if(str.at(3) == str.at(1) && str.at(1) == str.at(2)){
        cout << "Yes";
    }else{
cout << "No";
    }
}


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

using lint = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<double> values(n);
	for (int i = 0; i < n; ++i) cin >> values[i];
	sort(values.begin(), values.end());
	int total = 0;
	for (int i = 0; i + 1 < n; ++i) {
		values[i+1] = (values[i] + values[i+1])/2;
	}
	cout << values[n-1] << '\n';
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    string s,t;
    cin>>s>>t;
    if(s.size()>t.size())cout<<"GREATER"<<endl;
    else if(s.size()<t.size())cout<<"LESS"<<endl;
    else{
        for(int i=0;i<s.size();i++){
            if(s[i]>t[i]){
                cout<<"GREATER"<<endl;
                return 0;
            }else if(s[i]<t[i]){
                cout<<"LESS"<<endl;
                return 0;
            }
        }
        cout<<"EQUAL"<<endl;
    }
}


Measured memory_bytes: 256
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7  
N = 2 * 10**5 #出力の制限
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

def modPow(a, n, mod):
    if n == 1:
        return a
    if n % 2 == 1:
        return (a * (modPow(a, n//2, mod) ** 2)) % mod
    else:
        return (modPow(a, n//2, mod) ** 2) % mod


def modInverse(a, p):
    # calculates the modular multiplicative of a mod m.
    # (assuming p is prime).
    return modPow(a, p-2, p)


def modBinomial(n, k, p):
    # calculates C(n,k) mod p (assuming p is prime).

    numerator = 1  # n * (n-1) * ... * (n-k+1)
    for i in range(k):
        numerator = (numerator * (n-i)) % p

    denominator = 1  # k!
    for i in range(1, k+1):
        denominator = (denominator * i) % p

    # numerator / denominator mod p.
    return (numerator * modInverse(denominator, p)) % p

n, k = map(int,(input().split()))

if n <= k:
    print(modBinomial(2*n-1,n,mod))
    exit()
ans = 0
if k != 1:
    ans += 1
for i in range(1,k+1):
    ans = (ans + cmb(n,i,mod) * cmb(n-1,i,mod)) % mod

print(ans)

Measured memory_bytes: 81136
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
typedef long long ll;
ll a[N];
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for(int x, i = 1; i <= n; ++i){
        cin >> a[i];
    }
    ll ans = 0;
    for(int i = 1; i <= n; ++i){
        ans += a[i]/2;
        a[i] %= 2;
        if(a[i]&& a[i+1])a[i+1]--, a[i]--, ans++;
    }
    cout << ans << '\n';
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  short a,b;
  cin>>a>>b;
  if(a<10&&b<10)cout<<a*b<<endl;
  else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int A=0;
  int B=0;
  cin>>A>>B;
  if(A+B>A*B&&A+B>A-B){
    cout<<A+B;
  }else if(A*B>A+B&&A*B>A-B){
    cout<<A*B;
  }
  else{
    cout<<A-B;
  }
}

Measured memory_bytes: 256
S = input()

S0 = "0"
S1 = "1"

S00 = ""
SA = ""

for i in range(len(S)):

    S00 += str(abs(int(S0) - (i % 2)))

for i in range(len(S)):

    SA += str(int(S[i]) ^ int(S00[i]))

print(min(SA.count("0"), SA.count("1")))

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

int main(){
  int N;
  multimap<long, long> BA;
  pair<long, long> p;
  cin >> N;
  long tempA, tempB;
  for(int i = 0; i < N; i++){
    cin >> p.second >> p.first;
    BA.insert(p);
  }
  long now = 0;
  long time, deadline;
  bool canFinish = true;
  for(auto x : BA){
    deadline = x.first;
//    cout << "dead = " << deadline << endl;
    time = x.second;
//    cout << "time = " << time << endl;
    now += time;
//    cout << "now = " << now << endl;
    if(now > deadline){
      canFinish = false;
      break;
    }
  }
  if(canFinish) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

struct q_t {
  q_t() : score(0), count(0), bonus(0), total(0), taken(false) {}
  int64_t score;
  int64_t count;
  int64_t bonus;
  int64_t total;
  bool taken;
};

int64_t calc(int64_t g, std::vector<q_t>& qs) {
  int64_t const d = qs.size();
  int64_t ret = INT64_MAX;
  for (int i = 0; i < (1 << d); ++i) {
    int64_t totalScore = 0;
    int64_t count = 0;
    for (int j = 0; j < d; ++j) {
      q_t& q = qs[j];
      q.taken = (1 << j) & i;
      if (q.taken) {
        totalScore += q.total;
        count += q.count;
      }
    }
    if (totalScore >= g) {
      ret = std::min(count, ret);
      continue;
    }
    for (int j = 0; j < d; ++j) {
      const q_t& q = qs[j];
      if (q.taken) {
        continue;
      }
      if (q.score * (q.count - 1) + totalScore < g) {
        continue;
      }
      ret = std::min(count + (g - totalScore + q.score - 1) / q.score, ret);
    }
  }
  return ret;
}

int main() {
  int64_t d;
  int64_t g;
  std::cin >> d >> g;
  g /= 100;
  std::vector<q_t> qs(d, q_t());
  for (int64_t i = 0; i < d; ++i) {
    auto& q = qs[i];
    q.score = i + 1;
    std::cin >> q.count >> q.bonus;
    q.bonus /= 100;
    q.total = q.score * q.count + q.bonus;
  }
  std::cout << calc(g, qs) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d,x;
    cin>>n>>d>>x;
    int ans=0;
    REP(i,n){
        int a;cin>>a;
        for(int i=1;i<=d;i+=a) ans++;
    }
    cout<<ans+x<<endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def count(x, k):
    res = 0
    while x:
        x //= k
        res += x
    return res
def solve():
    N = int(readline())
    if N == 0:
        return False
    write("%d\n" % min(count(N, 2), count(N, 5)))
    return True
while solve():
    ...



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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadInt;
            var Y = cin.ReadInt;
            for(int i = 0; i <= N; i++)
            {
              for(int j = 0; j <= N - i; j++)
              {
                int k = N - i - j;
                if(10000 * i + 5000 * j + 1000 * k == Y)
                {
                  Console.WriteLine($"{i} {j} {k}");
                  return;
                }
              }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}



Measured memory_bytes: 13268
n,k = gets.strip.split.map(&:to_i)
num = gets.strip.split.map(&:to_i)
i = n
while i >= n
  s = 0
  tu = i.to_s
  t = tu.chars.map(&:to_i)
  for j in 0..k-1
    if t.include?(num[j])
      s += 1
    end
  end
  if s == 0
    break
  end
  i += 1
end
puts i

Measured memory_bytes: 14252
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

ll dp[200][10];
ll se[10];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    se[0] = 1;
    se[1] = 1;
    se[2] = 2;
    se[3] = 3;
    se[4] = 5;
    se[5] = 8;
    se[6] = 13;
    se[7] = 21;
    int h, w, k;
    cin >> h >> w >> k;
    dp[0][1] = 1;
    for (int i = 0; i < h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * se[j - 1] % MOD * se[w - j]) % MOD;
            if (j - 1 >= 1) dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * se[j - 2] % MOD * se[w - j]) % MOD;
            if (j + 1 <= w) dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * se[j - 1] % MOD * se[w - j - 1]) % MOD;
        }
    }
    cout << dp[h][k];
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    int res;
    if (A == B) {
        res = A + B;
    } else {
        res = 2 * max(A, B) - 1;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int OO = (int) 2e9;
const double eps = 1e-9;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	int n;
	cin >> n;
	int cur = 0;
	for (int i = 0; i <= n; i++) {
		cur = (cur * 10 + 7) % n;
		if (cur % n == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3648
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans;
bool ispal(string &s,ll st,ll en)
{
    while(st<en)
    {
        if(s[st]!=s[en])
            return 0;
        st++;en--;
    }
    return 1;
}
void solve()
{
    string s,ss;
    cin>>ss;
    s+="!"+ss;
    if(ispal(s,1,ss.size())&&ispal(s,1,(ss.size()-1)/2)&&ispal(s,(ss.size()+3)/2,ss.size()))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

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

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> cons(N+1);
    vector<int> ans(N, 0);
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        cons[a].push_back(b);
    }

    rep(i, Q) {
        int p, x;
        cin >> p >> x;
        ans[p-1] += x;
    }

    for(int i=1; i<=N; i++) {
        rep(j, cons[i].size()) {
            ans[cons[i][j]-1] += ans[i-1];
        }
    }

    rep(i, N) {
        cout << ans[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 14080
#include<stdio.h>
typedef struct left_{
    int w;
    int e;
}left_t;
typedef struct right_{
    int w;
    int e;
}right_t;

int main(){
    int n;
    char str[500000];
    left_t left;
    right_t right;
    left.w=left.e=0;
    right.w=right.e=0;

    scanf("%d",&n);
    scanf("%s",str);
    for(int i=0;i<n;i++){
        if(str[i]=='W'){
            right.w++;
        }else{
            right.e++;
        }
    }
    int cnt=0;
    int min=99999999;
    for(int i=0;i<n;i++){
        cnt=0;
        //printf("right e:%d w:%d\n",right.e,right.w);
        //printf("left  e:%d w:%d\n",left.e,left.w);
        if(str[i]=='W'){
            right.w--;
            cnt+=right.e;
            cnt+=left.w;
            left.w++;
        }else{
            right.e--;
            cnt+=right.e;
            cnt+=left.w;
            left.e++;
        }
        if(min>cnt){
            min=cnt;
        }
        //printf("%d\n",min);
    }
    printf("%d\n",min);
    return 0;

}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#define MAX 200

void push(int);
int pop(void);

int top=0;
int stack[MAX];

int main(){

  int a,b,x;
  char s[100];
  while(scanf("%s",s)!=EOF){
      if(s[0]=='+') {
	b=pop();
	a=pop();
	a+=b;
	push(a);
      }
      else if(s[0]=='-'){
	b=pop();
	a=pop();
	a-=b;
	push(a);
      }
      else if(s[0]=='*'){
	b=pop();
	a=pop();
	a*=b;
	push(a);
      }
      else {
	x=atoi(s);
	push(x);
      }
    
  }
  printf("%d\n",stack[top]);

  return 0;
}

void push(int x){
  if(top >= MAX - 1) {
    printf("Stack overflow!\n");
    exit(2);
  }
  top++;
  stack[top] = x;
}

int pop(void){
  if(top == 0) {
    printf("Stack is empty!\n");
    exit(3);
  }
  top--;
  return stack[top+1];
}



Measured memory_bytes: 2108
import java.util.*;

public class Main {
    static Scanner scanner;
    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        
        int[] arr = new int[scanner.nextInt()];
        
        for(int i = 0; i < arr.length; ++i) {
            arr[i] = scanner.nextInt();
        }
        
        for(int i = arr.length - 1; i >= 0; --i) {
            System.out.print(arr[i] + (i != 0 ? " " : ""));
        }
        System.out.println();
    }
}




Measured memory_bytes: 26236
fn main() {
    let temp: i32 = read();
    if temp >= 30 {
        println!("Yes");
    } else {
       println!("No");
    }
}

use std::io::{self, BufRead, Read};
use std::vec::Vec;
fn read<T: std::str::FromStr>() -> T {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.lock().read_line(&mut buf).unwrap();
    T::from_str(&buf.trim()).ok().unwrap()
}

fn read_all<T: std::str::FromStr>(count: usize) -> Vec<T> {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    let mut result = Vec::<T>::with_capacity(count);
    for _ in 0..count {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();
        result.push(T::from_str(&buf.trim()).ok().unwrap());
    }
    result
}

Measured memory_bytes: 2120
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int N,W;
ll w[112],v[112];
ll dp[112345];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N>>W;
  repeat(i,N){
    cin>>w[i]>>v[i];
  }
  repeat(i,N){
    for(int j=W;j>=w[i];j--){
      dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
    }
  }
  cout << dp[W] << endl;
  return 0;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
c = 0
if k == 0:
  print(n**2)
  exit(0)
for b in range(k+1, n+1):
  c += (b-k)*(n//b) + [n-(n//b)*b-k+1, 0][(n//b)*b+k>n]
print(c)


Measured memory_bytes: 2940
//ysh_gpta
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;


#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define IN(i,l,r) (l<i&&i<r)   //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)


#define repf(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define repfe(i,L,R) for (int i = L; i <= R; i++)
#define repb(i,L,R) for (int i = L; i > R; i--)
#define repbe(i,L,R) for (int i = L; i >= R; i--)


typedef long long ll;
#define cerr if(false)cerr
#define vb vector<bool>
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define mkp make_pair
#define pb push_back
#define INF 1000000000000000
#define MOD 1000000007
#define ff first
#define ss second


#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


ll gcd( ll a, ll b ){if(b==0) return a; else return gcd( b, a%b );}
ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}


vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

ll N = 2e5+5;
vi t(2*N,0);
ll n;

void modify(ll p,ll value){
    for(t[p+=n] = value; p>1 ; p>>=1) t[p>>1] = max(t[p],t[p^1]);
}

ll query(ll l,ll r){
    ll res = 0;
    for(l+=n,r+=n;l<r;l>>=1,r>>=1){
        if(l&1) res = max(res,t[l++]);
        if(r&1) res = max(res,t[--r]);
    }
    return res;
}


int main(){
    FastIO
    cin>>n;
    vi h(n),a(n);
    repf(i,0,n)
    cin>>h[i];
    repf(i,0,n)
    cin>>a[i];
    vi dp(n,0);
    dp[0] = a[0];
    modify(h[0]-1,dp[0]);
    repf(i,1,n){
        dp[i] = query(0,h[i]) + a[i];
        modify(h[i]-1,dp[i]);
    }
    cout<<t[1];

    return 0;
}

Measured memory_bytes: 8064
#include<iostream>                                         
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
typedef long long ll;
using namespace std;

#define M 1046527
#define L 14

char H[M][L];

int getChar(char ch){
    if(ch=='A')
        return 1;
    else if(ch=='C') return 2;
    else if(ch=='G') return 3;
    else if(ch=='T') return 4;
    else return 0;
}

ll getKey(char str[]){
    ll sum=0,p=1,i;
    for(i=0;i<strlen(str);i++){
        sum+=p*(getChar(str[i]));
        p*=5;
    }
    return sum;
}

int h1(int key){
    return key % M;
}
int h2(int key){
    return 1+key%(M-1);
}

int find(char str[]){
    ll key,i,h;
    key=getKey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0)return 1;
        else if(strlen(H[h])==0)return 0;
    }    

    return 0;

}
int insert(char str[]){
    ll key,i,h;
    key=getKey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0)
            return 1;
        else if(strlen(H[h])==0){
            strcpy(H[h],str);
            return 0;
        }    
    }
}

int main(){
    int n,h;
    char str[L],com[9];
    for(int i=0;i<M;i++) 
        H[i][0]='\0';
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>com>>str;
        if(com[0]=='i')
            insert(str);
        else{
            if(find(str))
                cout<<"yes"<<"\n";
            else
                cout<<"no"<<"\n";
        }
    }
    return 0;

}                 


Measured memory_bytes: 17384
s=list(input())
a=[]
b=[]
for i in range(len(s)):
    if i%2==0:
        a.append("1")
        b.append("0")
    else:
        a.append("0")
        b.append("1")
a_count=0
b_count=0
for i in range(len(s)):
    if a[i]!=s[i]:a_count+=1
    if b[i]!=s[i]:b_count+=1
print(min(a_count,b_count))

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

typedef struct Cake
{
  int w;
  int d;
  Cake(int w=0, int d=0) : w(w), d(d) {};
  int size() { return (w * d);}
  pair<Cake, Cake> cut(int s) {
    s %= 2 * (w + d);

    pair<Cake, Cake> cutten;
    if (s < w) {
      cutten = make_pair(Cake(s, d), Cake(w - s, d));
    } else if ((s -= w) < d) {
      cutten = make_pair(Cake(w, s), Cake(w, d - s));
    } else if ((s -= d) < w) {
      cutten = make_pair(Cake(s, d), Cake(w - s, d));
    } else {
      s -= w;
      cutten = make_pair(Cake(w, s), Cake(w, d - s));
    }

    if (cutten.first.size() > cutten.second.size()) 
      swap(cutten.first, cutten.second);

    return cutten;
  } 
}Cake_t;

void solve(int n, int w, int d) {
  vector<Cake> cakes;
  cakes.push_back(Cake(w, d));

  for (int i = 0; i < n; ++i) {
    int p, s;
    cin >> p >> s;
    auto cutten = cakes[p - 1].cut(s);
    cakes.erase(cakes.begin() + p - 1);
    cakes.push_back(cutten.first);
    cakes.push_back(cutten.second);
  }

  sort(cakes.begin(), cakes.end(), 
       [](Cake a, Cake b) {return a.size() < b.size();});
  
  cout << cakes[0].size();
  for (auto i = 1; i < cakes.size(); ++i) {
    cout << " " << cakes[i].size();
  }
  cout << endl;
}

int main() {
  int n, w, d;
  while( cin >> n >> w >> d, n | w | d) {
    solve(n, w, d);
  }
  return 0;
}


Measured memory_bytes: 3080
import java.util.*;
class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long X = sc.nextLong();
        HashMap<Integer, Long> map = new HashMap<Integer, Long>();
        long Nlen = 5;
        map.put(1, Nlen);
        for(int i = 2; i <= N; i++) {
            Nlen = Nlen*2 + 3;
            map.put(i, Nlen);
        }

        long tabeta = havePatty(N,X,map);
        System.out.println(tabeta);
    }

    public static long havePatty(int N, long X, HashMap<Integer, Long> map) {
        if(X <= 1) return 0;
        if(N == 1) {
            if(X == 1) return 0;
            else if(X == 2) return 1;
            else if(X == 3) return 2;
            else if(X == 4 || X == 5) return 3;
        }
        //n>1
        long Nlen = map.get(N);
        long l = map.get(N-1);
        if(X == Nlen) {
            return 1 + 2 * havePatty(N-1, l, map);
	} else if(X >= Nlen/2+1){
            return 1 + havePatty(N-1, l, map) + havePatty(N-1, X-l-2, map);
        } else {
            return havePatty(N-1, X-1, map);
        }
    }
}

Measured memory_bytes: 23764