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

void	init(int *array, int len, int val)
{
	for (int i = 0; i < len; ++i)
		array[i] = val;
}

void	copy(int *dst, int *src, int len)
{
	for (int i = 0; i < len; ++i)
		dst[i] = src[i];
}

void	add(int *lhs, int *rhs, int len)
{
	for (int i = 0; i < len; ++i)
		lhs[i] += rhs[i];
}

int	get_max(int *array, int len)
{
	return *max_element(array, array + len);
}

int	main()
{
	int	H, W, K;
	cin >> H >> W >> K;
	vector<string>	table(H);
	for (int i = 0; i < H; ++i)
		cin >> table.at(i);
	int	min_split = H * W + 1;
	for (int i = 0; i < (1 << (H - 1)); ++i) {
		bitset<9>	h_split(i);
		int	num_layer = h_split.count() + 1;
		if (min_split < num_layer)
			continue;
		int	cnt_1layer[10] = {0};
		int	cnt_1layer_1col[10] = {0};
		int	num_split = 0;
		int	num_v_split = 0;
		int	h_idx = 0;
		bool	is_feasible = true;
		for (int j = 0; j < W; ++j) {
			init(cnt_1layer_1col, num_layer, 0);
			h_idx = 0;
			for (int k = 0; k < H; ++k) {
				if (table.at(k).at(j) == '1')
					cnt_1layer_1col[h_idx] += 1;	
				if (k < H - 1 && h_split.test(k))
					++h_idx;
			}
			if (get_max(cnt_1layer_1col, num_layer) > K) {
				is_feasible = false;
				break;
			}
			add(cnt_1layer, cnt_1layer_1col, num_layer);
			if (get_max(cnt_1layer, num_layer) > K) {
				++num_v_split;
				copy(cnt_1layer, cnt_1layer_1col, num_layer);
			}
		}
		if (!is_feasible)
			continue;
		num_split = num_layer - 1 + num_v_split;
		if (min_split > num_split) min_split = num_split;
	}
	cout << min_split << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
const int INF=1e9+7;
const int mod=1e9+7;
struct poi{
	int X;int Y;int Z;
  bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
//ACACACACACACACACACACACAC//
//WAWAWAWAWAWAWAWAWAWAWAWA//
//CECECECECECECECECECECECE//
//RERERERERERERERERERERERE//
//TLETLETLETLETLETLETLETLE//
//
int main(){
	int N;
	int P[100000];
	cin>>N;
	FOR(i,0,N){
		cin>>P[i];
		P[i]--;
	}
	int ans=0;
	FOR(i,0,N){
		if(i<N-1&&P[i]==i&&P[i+1]==i+1){
			ans++;
			swap(P[i],P[i+1]);
		}else if(P[i]==i){
			ans++;
			swap(P[i],P[i+1]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 768
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define forabr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int INF = 1e9;
const int N = 20;

string field[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int cnt = 0;
    forn(i, sz(s) / 2) cnt += (s[i] != s[sz(s) - i - 1]);
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
long long LCM(long long a, long long b)
{
    long long g = __gcd(a, b);
    return a / g * b;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C, D; cin >> A >> B >> C >> D;
    A--;
    ll E = LCM(C, D);

    ll a1 = A / C;
    ll a2 = A / D;
    ll a3 = A / E;

    ll b1 = B / C;
    ll b2 = B / D;
    ll b3 = B / E;

    ll s = (A - a1) + (A - a2) - (A - a3);
    ll t = (B - b1) + (B - b2) - (B - b3);
    cout << t - s << endl;
    return 0;
}



Measured memory_bytes: 256
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
x,n=input2()
p=sorted(input_array())
q=[0]*102
result=[10000,-1]
for i in range(n):
	q[p[i]]=1
for i in range(102):
	if q[i]==0:
		num=abs(i-x)
		if num<result[0]:
			result=[num,i]
print(result[1])

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

public class Main {
    void run() {
        StringBuilder sb = new StringBuilder(read());
        int N = readInt();
        for (int i = 0; i < N; i++) {
            String q = read();
            int a = readInt();
            int b = readInt();
            if (q.equals("print")) {
                sysout.println(sb.substring(a, b + 1));
            }
            else if (q.equals("reverse")) {
                String rev = new StringBuilder(sb.substring(a, b + 1)).reverse().toString();
                sb.replace(a, b + 1, rev);
            } else {
                String t = read();
                sb.replace(a, b + 1, t);
            }
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int w, a, b;
  cin >> w >> a >> b;
  if (a > b) {
    swap(a, b);
  }

  int r1 = w + a, r2 = w + b;
  cout << max(0, b - r1) << '\n';
  return 0;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n, m;
  cin >> n >> m;
  string str;
  cin >> str;
  if (str[0] == 'B') {
    for (int i = 0; i < m; i++) {
      if (str[i] == 'R') {
        str[i] = 'B';
      } else {
        str[i] = 'R';
      }
    }
  }
  while (!str.empty() && str.back() == 'R') {
    str.pop_back();
  }
  if (str.empty()) {
    vector<int> dp(n);
    int sum = 0;
    for (int i = 1; i < n; i++) {
      dp[i] = (i + 1 + sum) % p;
      if (i) {
        sum = (sum + dp[i - 1]) % p;
      }
    }
    cout << (dp[n - 1] + 1) % p << endl;
  } else {
    int limit = INT_MAX, last = -1;
    for (int i = 0; i < str.size(); i++) {
      if (str[i] == 'B') {
        int len = i - last - 1;
        if (len & 1) {
          limit = min(limit, len);
        } else if (-1 == last) {
          limit = min(limit, len + 1);
        }
        last = i;
      }
    }
    vector<int> dp(n);
    int sum_0 = 0, sum_1 = 0;
    for (int i = 1; i < n; i++) {
      if (i & 1) {
        if (i <= limit) {
          dp[i] = i + 1;
        }
        dp[i] = (dp[i] + sum_1) % p;
        sum_0 = (sum_0 + dp[i - 1]) % p;
      } else {
        dp[i] = (dp[i] + sum_0) % p;
        sum_1 = (sum_1 + dp[i - 1]) % p;
      }
      if (i - limit - 1 > 0) {
        if (i - limit - 1 & 1) {
          sum_1 = (sum_1 - dp[i - limit - 1] + p) % p;
        } else {
          sum_0 = (sum_0 - dp[i - limit - 1] + p) % p;
        }
      }
    }
    cout << dp[n - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1428
N, M = map(int, input().split())

if M == 0:
    print(1)
    exit()

group_list = []
group_index = [0] * N

for _ in range(M):
    a, b = map(int, input().split())
    if group_index[a-1] == 0 and group_index[b-1] == 0:
        group_index[a-1] = len(group_list) + 1
        group_index[b-1] = len(group_list) + 1
        group_list.append(set([a, b]))

    elif group_index[a-1] == 0:
        group_index[a-1] = group_index[b-1]
        group_list[group_index[b-1] - 1].add(a)

    elif group_index[b-1] == 0:
        group_index[b-1] = group_index[a-1]
        group_list[group_index[a-1] - 1].add(b)

    elif group_index[a-1] != group_index[b-1]:
        if len(group_list[group_index[a-1] - 1]) > len(group_list[group_index[b-1] - 1]):
            group_id_b = group_index[b-1] - 1
            for p in group_list[group_id_b]:
                group_index[p-1] = group_index[a-1]
                group_list[group_index[a-1] - 1].add(p)
            group_list[group_id_b] = set()
        else:
            group_id_a = group_index[a-1] - 1
            for p in group_list[group_id_a]:
                group_index[p-1] = group_index[b-1]
                group_list[group_index[b-1] - 1].add(p)
            group_list[group_id_a] = set()

print(max([len(g) for g in group_list]))

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

int main(){
  std::string hitachi;
  std::cin >> hitachi;
  std::string type_hitachi;
  for(int i = 0; i < hitachi.size()/2; ++i){
    type_hitachi += "hi";
  }
  if(hitachi == type_hitachi){
    std::cout << "Yes" << std::endl;
  }else{
    std::cout << "No" << std::endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;

#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
#define in cin
#define out cout

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

	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++) {
		cin >> v[i];
	}
	int cnt = 1;
	vector<int> d(n + 1);
	for(int i = 0; i < n; i++) {
		d[v[i]] = i + 1;
	}
	for(auto i: d) {
		if(i != 0)
		cout << i << " ";
	}

}



Measured memory_bytes: 3976
N, K = map(int, input().split())
stone = list(map(int, input().split()))
dp = [False]*(K+1)
for i in range(1,K+1):
    for k in range(N):
        if i >= stone[k]:
            if not dp[i-stone[k]]:
                dp[i] = True
print('First' if dp[K] else 'Second')

Measured memory_bytes: 41708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, c; cin>>n>>m>>c;
    int a[25][25],b[25];
    rep(i, m) cin>>b[i];
    rep(i, n){
        rep(j, m){
            cin>>a[i][j];
        }
    }
    int cnt = 0;
    rep(i, n){ 
        int tmp =0;
        rep(j, m){
            tmp += (a[i][j]*b[j]);
        }
        if(tmp+c>0) cnt++;
    }  
    cout << cnt <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    ll k,n;
    cin >> k >> n;
    vector<ll> a(n+1,0);
    rep(i,n)cin >> a.at(i);
    ll max_dist = k-a[n-1] + a[0];
    rep(i,n-1){
        ll d = abs(a[i] - a[i+1]);
        max_dist = max(max_dist,d);
    }
    cout << k - max_dist << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	
	int N,i,j;
	float d[10];
	signed int x[10], y[10];
	
	float result=0;
	float result1=0;
	scanf("%d",&N);
	i=0;
	int K = N;
	while (K>0)
	{
	scanf("%d %d",&x[i],&y[i]);
	i++;
	K=K-1;
	}
	
	for (i=0;i<N;i++)
	{
	    for (j=i+1;j<N;j++)
	    {
	     d[i] = abs(sqrt(pow(abs(x[i]-x[j]),2) + pow(abs(y[i]-y[j]),2)));
	     result = result +d[i];
	    }
	}
    result1 = result/N;
    if (N==2)
    {
    	printf("%f",result);
    }
    else
    {
    	
    
    printf("%f",result1*2);
    
    }
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define F first
#define S second
#define pb push_back
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(std::unique(all(x)) - (x).begin())
#define roflan ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ld long double
#define int long long

vector <int> g[100500];
map <pii, int> mp;
void dfs(int v, int par = -1) {
	int ccol = 0;
	for (auto u : g[v]) {
		if (par != -1) {
			if (mp[make_pair(min(par, v), max(par, v))] == ccol)
				ccol++;
		}
		if (u == par) continue;
		mp[make_pair(min(u, v), max(u, v))] = ccol++;
		dfs(u, v);
	}
}
void SOLVE() {
	int n;
	cin >> n;
	vector <pii> edges;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		edges.pb({ v, u });
		g[v].pb(u);
		g[u].pb(v);
	}
	int mx = 0;
	for (int i = 0; i < n; i++) {
		mx = max(mx, (int)g[i].size());
	}
	dfs(0);
	cout << mx << '\n';
	for (auto now : edges) {
		int v = now.first, u = now.second;
		cout << mp[make_pair(min(u, v), max(u, v))] + 1 << '\n';
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int Q = 1;
	//cin >> Q;
	while (Q--)
		SOLVE();

	return 0;
}
/*
*/

Measured memory_bytes: 16372
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    d = {"M":0,"A":0,"R":0,"C":0,"H":0}
    for _ in range(N):
        s = input().rstrip("\r\n")
        if s[0] in d.keys():
            d[s[0]] += 1
    dv = []
    for v in d.values():
        if v != 0:dv.append(v)
    ans = 0
    if len(dv) >= 3:
        for i in range(len(dv)-2):
            for j in range(i+1,len(dv)-1):
                for k in range(j+1,len(dv)):
                    ans += dv[i]*dv[j]*dv[k]
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 40684
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTA(a,n) sort(a,a+n)
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int n,k;
    cin >> n >> k;
  	int ans = 1;
    //処理
  	REP(i,0,n){
    	ans = min(2*ans,ans+k);
    }
    //出力
    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 256
ary=$stdin.readlines
od=Array.new
ev=Array.new
n = ary[0].to_i
array=ary[1].split.map!(&:to_i)
p=0
while p<n
  od.push(array[p]) if p%2==0
  ev.push(array[p]) if p%2==1
  p+=1
end

  sd_n_ns_od = od.group_by{|i| i}.sort_by{|k,v| v.size}
  sd_n_ns_ev = ev.group_by{|i| i}.sort_by{|k,v| v.size}



if sd_n_ns_od.size == 1 && sd_n_ns_ev.size == 1
  if sd_n_ns_od.last.first == sd_n_ns_ev.last.first
    answer = n/2
  else
    answer= 0
  end
else
most_n_od = sd_n_ns_od.last.first
most_n_ev = sd_n_ns_ev.reject{|k,v| k == most_n_od}.last.first
answer1=0
answer1+=od.reject{|i| i==most_n_od}.size
answer1+=ev.reject{|i| i==most_n_ev}.size

most_n_ev = sd_n_ns_ev.last.first
most_n_od = sd_n_ns_od.reject{|k,v| k== most_n_ev}.last.first
answer2=0
answer2+=ev.reject{|i| i==most_n_ev}.size
answer2+=od.reject{|i| i==most_n_od}.size

 answer = (answer1 <= answer2)?  (answer1):(answer2)

 if  sd_n_ns_od.size == 1
   answer=answer1
 end

 if  sd_n_ns_ev.size == 1
   answer=answer2
 end
 end
puts answer


Measured memory_bytes: 25600
import sys
import math

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

def lcm(a, b):
  return (a * b) // gcd(a, b)

  
a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
if c == d:
  fgh = (b // c) - ((a - 1) // c)
  n = e - fgh
  print(n) 
else:
  f = (b // c) - ((a - 1) // c)
  g = (b // d) - ((a - 1) // d)
  cd = lcm(c, d) 
  h = (b // cd) - ((a - 1) // cd)
  n = e - f - g + h
  print(n)


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

int main(){
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    if((x-a)*(x-a)>(x-b)*(x-b)){
        printf("B\n");
    }
    if((x-b)*(x-b)>(x-a)*(x-a)){
        printf("A\n");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,arr[1000],sum1=0,sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(int i=n-1;i>=0;i--)
    {
    if(i%2==1){sum+=arr[i];}
else{sum1+=arr[i];}
    }
n=abs(sum-sum1);
cout<<n<<endl;
}


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

int getIndex(int x) {
  if(x < 10) return 0;
  if(x < 20) return 1;
  if(x < 30) return 2;
  if(x < 40) return 3;
  if(x < 50) return 4;
  if(x < 60) return 5;
  return 6;
}

int main() {
  for(int n; cin >> n && n;) {
    vector<int> v(7);
    for(int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      ++v[getIndex(x)];
    }
    for(int i = 0; i < 7; ++i) {
      cout << v[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ll long long
using namespace std;

int dp[100002][3];

int main(){
    int n;
    cin>>n;
    int a[n][3];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin>>a[i][j];
        }
    }
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j == 0){
                dp[i+1][1] = max(dp[i+1][1], dp[i][j] + a[i + 1][1]);
                dp[i+1][2] = max(dp[i+1][2], dp[i][j] + a[i + 1][2]);
            }
            else if(j == 1){
                dp[i+1][0] = max(dp[i+1][0], dp[i][j] + a[i + 1][0]);
                dp[i+1][2] = max(dp[i+1][2], dp[i][j] + a[i + 1][2]);
            }
            else{
                dp[i+1][0] = max(dp[i+1][0], dp[i][j] + a[i + 1][0]);
                dp[i+1][1] = max(dp[i+1][1], dp[i][j] + a[i + 1][1]);
            }
        }
    }
    cout<<max(dp[n-1][0], max(dp[n-1][1],dp[n-1][2]));
    return 0;
}



Measured memory_bytes: 2560
function main(input) {
   input = input.trim();
  const a = input.split(" ").map(Number);
 
 console.log(a[0]==a[1]?a[2]
		    :a[0]==a[2]?a[1]
		    :a[0]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

int main() {
    string s;
    cin >> s;
    int count = 0;
    if(s[0] == 'R') count++;
    for(int i = 1; i <= 2; i++) {
        if(s[i] == 'R') {
            if(s[i -1] == s[i]) {
                count++;
            } else {
                count = 1;
            }
        }
    }
    cout << count;
    return 0;
}

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

const int N = (1e5) + 5;
char s[N];
char t[N];
vector<int> pos[26 + 5];

int main() { // claudio van
  scanf("%s", s);
  scanf("%s", t);
  int len_s = strlen(s);
  for (int i = 0; i < len_s; ++i) {
    pos[s[i] - 'a'].emplace_back(i);
  }
  int len_t = strlen(t);
  int p = -1;
  ll ans = 0;
  int i = 0;
  while (i < len_t) {
    int search = t[i] - 'a';
    if ((int) pos[search].size() == 0) {
      printf("-1\n");
      return 0;
    }
    int up = upper_bound(pos[search].begin(), pos[search].end(), p) - pos[search].begin();
    if (0 <= up and up < (int) pos[search].size()) {
      p = pos[search][up];
      ++i;
    } else {
      ans += len_s;
      p = -1;
    }
  }
  printf("%lld\n", ans + p + 1);
  return 0;
}

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

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

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

	int d[5],k;

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

	cin >> k;

	if(d[4]-d[0] <= k) cout << "Yay!" << endl;
	else cout << ":(" << endl;

	return 0;

}


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

#define show(x) cout << #x << " = " << x << endl

typedef pair<int,int> P;
typedef pair<int,P> PP;
typedef vector<int> vec;
typedef vector<vec> mat;

const int INF = 1 << 28;

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

void solve (int R, int C) {
    int sx, sy, gx, gy;
    vector<string> g(R);

    for (int i = 0; i < R; i++){
        cin >> g[i];
        for (int j = 0; j < C; j++) {
            if (g[i][j] == 'S') {
                sx = i;
                sy = j;
            } else if (g[i][j] == 'G') {
                gx = i;
                gy = j;
            }
        }
    }

    mat d(R, vec(C, INF));
    d[sx][sy] = 0;

    priority_queue<PP, vector<PP>, greater<PP> > que;
    que.push(PP(0, P(sx, sy)));

    while (que.size()) {
        PP pp = que.top();
        que.pop();
        int x = pp.second.first;
        int y = pp.second.second;
        int cost = pp.first;

        if (g[x][y] == 'G' || d[x][y] < cost) continue;

        //show(g[x][y]);

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (0 <= nx && nx < R && 0 <= ny && ny < C) {
                if (g[nx][ny] == 'x' || g[nx][ny] == '#') continue;
                int cost_ = cost + (g[nx][ny] != 'o' ? 2 : 1);
                if (d[nx][ny] > cost_) {
                    que.push(PP(cost_, P(nx,ny)));
                    d[nx][ny] = cost_;
                }
            }
        }


        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 3; j++) {
                int nx = x + dx[i] * j;
                int ny = y + dy[i] * j;

                if (0 <= nx && nx < R && 0 <= ny && ny < C) {
                    int gg = g[nx][ny];
                    if (gg == '#') break;

                    int cost_ = cost + 2 + j;

                    if (d[nx][ny] > cost_) {
                        que.push(PP(cost_, P(nx,ny)));
                        d[nx][ny] = cost_;
                    }
                }
            }
        }

    }

    cout << d[gx][gy] << endl;


}


int main(){
    int R,C;
    while(cin >> R >> C){
        solve(R,C);
    }
}

Measured memory_bytes: 1232
#include <stdio.h>
#define N 45
void makeFibonacci(int n);
int F[N];
int main(){
  int n;
  scanf("%d",&n);
  makeFibonacci(n);
  printf("%d\n",F[n]);
  return 0;
}
void makeFibonacci(int n){
  int i;
  F[0]=F[1]=1;
  for(i=2;i<=n;i++) F[i]=F[i-2]+F[i-1];
}

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


int main(void){
    string str;
    char c, prev;
    int N;
    cin >> N;
    cin >> c;
    str += c; prev = c;
    for (int i = 1; i < N; i++) {
        cin >> c;
        if (c != prev) {
            prev = c;
            str += c;
        }
    }
    cout << str.size() << endl;
    return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <set>
int main()
{
    int N;
    std::cin >> N;
    std::set<char> S;
    char c;
    for (int i = 0; i < N; i++) {
        std::cin >> c;
        S.insert(c);
    }

    if (S.size() == 3) {
        std::cout << "Three" << std::endl;
    }
    else {
        std::cout << "Four" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 2768
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

int main()
{

    string s, t;

    cin >> s >> t;

    int dp[3001][3001];
    P f[3001][3001];

    memset(dp, 0, sizeof(dp));
    memset(f, 0, sizeof(f));

    for (int i = 1; i <= s.size(); i++)
        for (int j = 1; j <= t.size(); j++)
        {
            if (s[i - 1] == t[j - 1])
            {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                f[i][j] = make_pair(i - 1, j - 1);
            }

            if (dp[i][j] < dp[i - 1][j])
            {
                dp[i][j] = dp[i - 1][j];
                f[i][j] = make_pair(i - 1, j);
            }

            if (dp[i][j] < dp[i][j - 1])
            {
                dp[i][j] = dp[i][j - 1];
                f[i][j] = make_pair(i, j - 1);
            }
        }

    string res = "";

    P pos = make_pair(s.size(), t.size());

    while (pos.first > 0 && pos.second > 0)
    {
        if (s[pos.first - 1] == t[pos.second - 1])
            res = s[pos.first - 1] + res;

        pos = f[pos.first][pos.second];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 105856
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];


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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    ll p;
    cin>>n>>p;
    vector<ll> v(n);
    rep(i,n) {
        cin>>a;
        if(a%2) f=1;
    }

    if(!f){
        if(p){
            cout<<0<<endl;
        }else {
            sum=1;
            rep(i,n) sum*=2;
            cout<<sum<<endl;
        }
    }else{
                    sum=1;
            rep(i,n-1) sum*=2;
            cout<<sum<<endl;
    }
    return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,char>> sc(m);
    for (int i = 0; i < m; i++){
        cin >> sc[i].first >> sc[i].second;
    }
    string a;
    bool flag;
    for (int i = 0; i < 1000; i++){
        flag = true;
        a = to_string(i);
        if (a.size() != n){
            continue;
        }
        for (int j = 0; j < m; j++){
            if (a[sc[j].first-1] != sc[j].second){
                flag = false;
            }
        }
        if (flag){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 1001001001001001000;

int main() {
    int a,b; cin >> a >> b;
    if (a >= 10 || b >= 10) cout << -1 << endl;
    else cout << a*b << endl;
    return 0;
}

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

n = int(input())
a = list(map(int, input().split()))

def func(n, a):
    a[0] -= 1
    for i in range(1, n):
        diff = a[i] - a[i-1]
        if diff > 0:
            a[i] -= 1
        elif diff < 0:
            return "No"
    return "Yes"

print(func(n, a))

Measured memory_bytes: 14224
#include <cstdio>
#include <queue>
#include <map>

using namespace std;

const int MAX_N = 1000;
const int MAX_P = 76543210;
const int INF = 1000000000;

int N = 0;
int problem[MAX_N][8];
map<int, int> table;
queue<int> que;

int pow10(int x){
  int answer = 1;
  for(int i = 0; i < x; i++){
    answer = answer * 10;
  }
  return answer;
}

void receiveInput(){
  for(int n = 0; n < MAX_N; n++){
    N += 1;
    for(int i = 0; i < 8; i++){
      if(scanf("%d", &problem[n][i]) == EOF) {
        N -= 1;
        return;
      }
    }
  }
  return;
}

int encode(int n){
  int p = 0;
  for(int i = 0; i < 8; i++){
    p += problem[n][i] * pow10(7 - i);
  }
  return p;
}

int whereIsZero(int p){
  int answer = 7;
  for(int i = 0; i < 8; i++){
    if(p % 10 == 0){
      return answer;
    }
    answer -= 1;
    p = p / 10;
  }
  return answer;
}

int swap(int p, int k, int h){
  int tenk = pow10(7 - k);
  int tenh = pow10(7 - h);
  int pk = (p / tenk) % 10;
  int ph = (p / tenh) % 10;
  return p + (ph - pk) * tenk + (pk - ph) * tenh;
}

void addNeighbor(int p){
  int k = whereIsZero(p);
  if(k != 0 && k != 4){
    int neighbor = swap(p, k, k - 1);
    if(table.count(neighbor) == 0 || table[p] + 1 < table[neighbor]){
      table[neighbor] = table[p] + 1;
      que.push(neighbor);
    }
  }
  if(k - 4 >= 0){
    int neighbor = swap(p, k, k - 4);
    if(table.count(neighbor) == 0 || table[p] + 1 < table[neighbor]){
      table[neighbor] = table[p] + 1;
      que.push(neighbor);
    }
  }
  if(k != 3 && k != 7){
    int neighbor = swap(p, k, k + 1);
    if(table.count(neighbor) == 0 || table[p] + 1 < table[neighbor]){
      table[neighbor] = table[p] + 1;
      que.push(neighbor);
    }
  }
  if(k + 4 < 8){
    int neighbor = swap(p, k, k + 4);
    if(table.count(neighbor) == 0 || table[p] + 1 < table[neighbor]){
      table[neighbor] = table[p] + 1;
      que.push(neighbor);
    }
  }
  return ;
}

void searchMove(){
  if(que.empty()){
    return;
  }
  int p = que.front();
  que.pop();
  addNeighbor(p);
  searchMove();
  return ;
}

void makeTable(){
  table[1234567] = 0;
  que.push(1234567);
  searchMove();
  return ;
}

int solve(int n){
  int p = encode(n);
  return table[p];
}

int main(){
  receiveInput();
  makeTable();
  for(int n = 0; n < N; n++){
    printf("%d\n", solve(n));
  }
  return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N, M;
  cin >> N >> M;
  vector<PLL> v(M);
  rep(i,M) {
    cin >> v[i].first >> v[i].second;
    v[i].first = N - v[i].first;
  }
  ll l = 0, r = 9;
  if (N == 2) { l = 10;  r = 99; }
  if (N == 3) { l = 100; r = 999; }
  for (ll x = l; x <= r; x++) {
    bool ok = true;
    for (auto p : v) {
      if((x / (ll)pow(10,p.first))%10 != p.second)
        ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }

  cout << -1 << endl;
}


Measured memory_bytes: 256
//Code by Enderturtle
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define repe(i,a) for(register int i=head[a];i;i=e[i].nxt)
#define il inline
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
typedef long long ll;
using namespace std;
il void filejudge(){
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
il int read(){
	int x=0;bool f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=0;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?x:-x;
}
/*----- head end -----*/
const int N=4010,mod=924844033;
bool vis[N],ed[N];
int cnt=0,n,k,ls;
ll f[N][N][2],fac[N],ans;

il void add(ll &x,ll y){
	if(y<0) y+=mod;
	x+=y;
	if(x>=mod) x-=mod;
}

il void dfs(int u){
	if(vis[u]) return;
	vis[u]=1;cnt++;
	if(u>n){
		if(u-n-k>=1) dfs(u-n-k);
		if(u-n+k<=n) dfs(u-n+k);
	}else{
		if(u-k>=1) dfs(u+n-k);
		if(u+k<=n) dfs(u+n+k);
	}
}
int main(){
	n=read();k=read();
	fac[0]=1;
	rep(i,1,n) fac[i]=fac[i-1]*i%mod;
	rep(i,1,2*n){
		cnt=0;
		dfs(i);
		ed[ls+cnt]=1;
		ls+=cnt;
	}
	ed[0]=1;
	f[0][0][0]=1;
	rep(i,1,2*n){
		rep(j,0,n){
			if(ed[i-1]){
				add(f[i][j][0],f[i-1][j][0]);
				add(f[i][j][0],f[i-1][j][1]);
				continue;
			}
			if(f[i-1][j][0]){
				add(f[i][j+1][1],f[i-1][j][0]);
				add(f[i][j][0],f[i-1][j][0]);
			}
			if(f[i-1][j][1])
				add(f[i][j][0],f[i-1][j][1]);
		}
	}
	rep(i,0,n){
		ll res=0;add(res,f[2*n][i][0]);add(res,f[2*n][i][1]);
		if(i&1) add(ans,-(res*fac[n-i]%mod));
		else add(ans,res*fac[n-i]%mod);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 249728
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] A = ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(A);
            WriteLine(A[2] - A[0]);
        }
    }
}

Measured memory_bytes: 13268
package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

func main() {
	for {
		var n int
		fmt.Scan(&n)

		if n == 0 {
			return
		}

		arr := make([]complex128, n)

		for i := 0; i < n; i++ {
			var x, y float64

			fmt.Scanf("%f%f", &x, &y)

			arr[i] = complex(x, y)
		}

		max := 1
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				sub := arr[j] - arr[i]

				if cmplx.Abs(sub) >= 2 {
					continue
				}
				sum := arr[j] + arr[i]

				v := 1
				{
					halfd := cmplx.Abs(sub / 2)

					center := sum/2 + sub*cmplx.Rect(math.Sqrt(1-halfd*halfd)/cmplx.Abs(sub), float64(v)*math.Pi/2)

					counter := 0
					for k := 0; k < n; k++ {
						if i == k || j == k || cmplx.Abs(arr[k]-center) <= 1 {
							counter++
						}
					}
					if max < counter {
						max = counter
					}
				}

				v = -1
				{
					halfd := cmplx.Abs(sub / 2)

					center := sum/2 + sub*cmplx.Rect(math.Sqrt(1-halfd*halfd)/cmplx.Abs(sub), float64(v)*math.Pi/2)

					counter := 0
					for k := 0; k < n; k++ {
						if i == k || j == k || cmplx.Abs(arr[k]-center) <= 1 {
							counter++
						}
					}
					if max < counter {
						max = counter
					}
				}

			}
		}

		fmt.Println(max)
	}
}



Measured memory_bytes: 1632
{-# LANGUAGE MultiWayIf #-}
import Control.Applicative ((<$>))

main = do
  x <- read <$> getLine :: IO Int
  let (a,m) = x`divMod`11

  print $ if | m == 0 -> a*2
             | m < 7 -> a*2+1
             | otherwise -> a*2+2


Measured memory_bytes: 508
H, W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
b =[0]*(H*W)
k = 0
for i in range(N):
    for j in range(a[i]):
        b[k] = i + 1
        k += 1
x, y = 0, 0
ans =[[0]*W for i in range(H)]
for i in range(H*W):
    ans[y][x] = b[i]
    if (x == 0 and y%2 == 1) or (x == W - 1 and y%2 == 0):
        y += 1
    elif y%2 == 0:
        x += 1
    else:
        x -= 1
for _ in range(H):
    print(*ans[_])

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main()
{
  int N, K; cin >> N >> K;
  vector<int> height(N);
  vector<int> dp(N, INT_MAX);

  for (int &i: height)
    cin >> i;

  dp[0] = 0;
  for (int i = 0; i < N; i++)
    for (int j = 1; j <= K && i+j < N; j++)
    {
      int diff = abs(height[i] - height[i+j]);
      if (dp[i] + diff < dp[i+j])
        dp[i+j] = dp[i] + diff;
    }

  cout << dp[N-1] << '\n';
}


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

int main(){
  ll n,m,k; cin >>n >>m >>k;
  vector<int> a(n), b(m);
  rep(i,n) cin >>a[i];
  ll total = 0;
  rep(i,m){
    cin >>b[i];
    total += b[i];
  }
  int ans = 0;
  int j = m;
  rep(i,n+1){
    while(j>0 && total>k){
      j--;
      total -= b[j];
    }
    if(total > k) break;
    ans = max(ans, i+j);
    if(i==n) break;
    total += a[i];
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 4832
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  int k, a, b;
  scanf("%d%d%d", &k, &a, &b);
  if (b - a > 2) {
    if (a - 1 > k)
      printf("%d\n", k + 1);
    else {
      k -= a - 1;
      ll ans = a;
      ans += (b - a) * (ll)(k / 2);
      k &= 1;

      printf("%lld\n", ans + k);
    }
  } else
    printf("%d\n", k + 1);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApp1
{
    class Program
    {
        //最大公約数
        static long lcm(long a, long b)
        {
            return a * b / god(a, b);
        }
        //最小公倍数
        static long god (long a, long b)
        {
            if (a < b)
            {
                long tmp = a;
                a = b;
                b = tmp;
            }

            // ユークリッドの互除法
            long r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;

        }

        // a～bまでにcの倍数がいくつあるかを返す
        static long calc(long a, long b, long c)
        {
            long n = b - a + 1;
            long ans = b / c - (a-1) / c;

            return ans;
        }
        static void Main(string[] args)
        {
            long[] inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);

            long a = inp[0];
            long b = inp[1];
            long c = inp[2];
            long d = inp[3];


            long n1 = calc(a, b, c);
            long n2 = calc(a, b, d);
            long n3 = calc(a, b, lcm(c, d));

            long ans = (b - a + 1) + n3 - n1 - n2;

            Console.WriteLine(ans);
        }
    }
}
/////END

Measured memory_bytes: 13140
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int n,m,a[200],h,g,i,j,temp;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>h>>g;
		a[i]=h*60+g;
	}
	cin>>m;
	for(i=n;i<n+m;i++){
		cin>>h>>g;
		a[i]=h*60+g;
	}
	for(i=0;i<n+m-1;i++){
		for(j=i+1;j<n+m;j++){
			if(a[i]>a[j]){
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
	for(i=0;i<n+m-1;i++){
		if(a[i]!=a[i+1]){
			printf("%d:%02d ",a[i]/60,a[i]%60);
		}
	}
	printf("%d:%02d\n",a[n+m-1]/60,a[n+m-1]%60);
	return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
map<LL,LL>m;
priority_queue<LL,vector<LL> >que;

int main(){
	int T;
	cin>>T;
	REP(i,T){
		m.clear();
		LL N,A,B,C,D;
		cin>>N>>A>>B>>C>>D;
		//1から5をたし引きして2倍or3倍or5倍
		que.push(N);
		while(que.empty()==false){
			LL a=que.top();
			que.pop();
			REP(i,9){
				LL ans=m[a];//現在の値
				LL now=a+i-4;//ずらした値
				ans+=D*abs(i-4);
				if(now<0)continue;
				if(now%2==0){
					if(now/2<a){
						if(m[now/2]==0){
							m[now/2]=ans+A;
							que.push(now/2);
						}else{
							m[now/2]=min(m[now/2],ans+A);
						}
					}
				}
				if(now%3==0){
					if(now/3<a){
						if(m[now/3]==0){
							m[now/3]=ans+B;
							que.push(now/3);
						}else{
							m[now/3]=min(m[now/3],ans+B);
						}
					}
				}
				if(now%5==0){
					if(now/5<a){
						if(m[now/5]==0){
							m[now/5]=ans+C;
							que.push(now/5);
						}else{
							m[now/5]=min(m[now/5],ans+C);
						}
					}
				}
			}
		}
		LL ans=1e18;
		for(auto it:m){
			if(1e17/D<it.first)continue;
			//cout<<it.first<<" "<<m[it.first]+it.first*D<<endl;
			ans=min(m[it.first]+it.first*D,ans);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 6552
"use strict";

function main(input) {
  var lines = input.split('\n');
  var S = lines[0];
  var K = parseInt(lines[1]);
  var l = Math.min(K, S.length);

  for (var i = 0; i < l; i++) {
    if (S[i] !== '1') {
      console.log(S[i]);
      return;
    }
  }

  console.log('1');
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}

int main(){
  int n,c,k;
  cin >> n >> c >> k;
  vector<int> t(n);
  rep(i,n)
    cin >> t.at(i);
  sort(all(t));
  int hito=0;
  int now=0;
  int ans=0;
  while(hito<n){
    int ninzu=1;
    while(hito<n&&t.at(hito)<=now&&ninzu<c){
      hito++;
      ninzu++;
    }
    if(hito==n)break;
    now=t.at(hito)+k;
    hito++;
    ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

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

    string s;
    cin >> s;

    auto mid = s.length() - 1;
    long long total = 0;
    for (unsigned long i = 0; i < 1 << mid; ++i) {
        unsigned long pre = 0;
        long long sub_total = 0;
        for (unsigned long j = 0; j < mid; j++) {
            if ((i >> j) % 2 == 1) {
                sub_total += stoll(s.substr(pre, j + 1 - pre));
                pre = j + 1;
            }
        }
        if (pre <= mid) sub_total += stoll(s.substr(pre));
        total += sub_total;
    }

    cout << total << '\n';

    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    p = list(map(int, input().split()))

    count = 0
    for i in range(1, n-1):
        if p[i-1] < p[i] and p[i] < p[i+1]:
            count += 1
        if p[i-1] > p[i] and p[i] > p[i+1]:
            count += 1
    print(count)
    
if __name__ == '__main__':
    main()


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

struct BipartiteGraph {
	struct Edge {
		const int from;
		const int to;
		Edge(const int from, const int to) :
			from(from),
			to(to)
			{}
	};
	const int V;
	vector<vector<Edge>> G;
	vector<int> color;
	BipartiteGraph(const int V) :
		V(V),
		G(vector<vector<Edge>>(V, vector<Edge>())),
		color(vector<int>(V, -1))
		{}
	void addEdge(const int from, const int to) {
		G[from].emplace_back(from, to);
		G[to].emplace_back(to, from);
	}
	bool dfs(const int from, const int col) {
		color[from] = col;
		bool ret = true;
		for(Edge e : G[from]) {
			if(color[e.to] == -1) {
				ret &= dfs(e.to, col ^ 1);
			}
			if(color[e.to] == col) {
				return false;
			}
		}
		return ret;
	}
	int bipart() {
		if(not dfs(0, 0)) throw "NOT Bipartite Graph";
		int ret = 0;
		for(int i : color) ret += i;
		return ret;
	}
};

struct UnionFind {
	const int V;
	// par[x] := xのroot
	vector<int> par;
	// sz[x] := xを含む集合のサイズ
	vector<int> sz;
	UnionFind(const int V) :
		V(V),
		par(vector<int>(V)),
		sz(vector<int>(V, 1))
		{
			for(int i = 0; i < V; ++i) par[i] = i;
		}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(same(x, y)) return false;
		if(y < x) swap(x, y);
		par[y] = x;
		sz[x] += sz[y];
		return true;
	}
	int root(int x) {
		if(par[x] == x) return x;
		return (par[x] = root(par[x]));
	}
	bool same(int x, int y) {
		return (root(x) == root(y));
	}
	int size(int x) {
		return sz[root(x)];
	}
};

int dp[5010][5010];
int main() {
	const int MOD = 1e9 + 7;
	int n, m; cin >> n >> m;
	int a[n];
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		--a[i];
	}
	UnionFind uf(n);
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			if(a[i] > a[j]) uf.unite(i, j);
		}
	}
	vector<int> edge[n];
	for(int i = 0; i < n; ++i) {
		edge[uf.root(i)].push_back(i);
	}
	vector<int> color[2];
	for(int i = 0; i < n; ++i) {
		int nn = edge[i].size();
		if(nn == 0) continue;
		BipartiteGraph bg(nn);
		for(int j = 0; j < nn; ++j) {
			for(int k = j + 1; k < nn; ++k) {
				if(a[edge[i][j]] > a[edge[i][k]]) {
					bg.addEdge(j, k);
				}
			}
		}
		try {
			int x = bg.bipart();
			color[0].push_back(x);
			color[1].push_back(nn - x);
		}
		catch(...) {
			cout << 0 << endl;
			return 0;
		}
	}
	int sz = color[0].size();
	dp[0][0] = 1;
	for(int i = 1; i <= sz; ++i) {
		for(int j = 0; j <= n; ++j) {
			for(int k = 0; k < 2; ++k) {
				if(j - color[k][i - 1] >= 0) {
					dp[i][j] += dp[i - 1][j - color[k][i - 1]];
				}
				dp[i][j] %= MOD;
			}
		}
	}
	int ans = 0;
	for(int j = 0; j <= n; ++j) {
		if(max(j, n - j) > m) continue;
		ans += dp[sz][j];
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 101312