akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint i,n,bmin=0,bmax=mod;cin>>n;
	vector<int>a(n);
	for(i=0;i<n;i++){cin>>a[i];}
	while(bmax-bmin>1){
		int bgen=(bmax+bmin)/2;
		vector<int>rui(n+n+1);
		rui[n]=1;
		llint bas=n,now=1,cou=0;
		for(i=0;i<n;i++){
			if(a[i]<bgen){
				now-=rui[bas];
				bas--;
				rui[bas]++;
				cou+=now;
				now++;
			}else{
				bas++;
				now+=rui[bas];
				rui[bas]++;
				cou+=now;
				now++;
			}
		}
		//a[i]<=a[j]となる組み合わせがnum
		//if(bgen<40){cerr<<"bgen="<<bgen<<"cou="<<cou<<endl;}
		if(cou<((2+n*(n+1))/4)){bmax=bgen;}
		else{bmin=bgen;}
	}
	cout<<bmin<<endl;
	return 0;
}

Measured memory_bytes: 1420
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	n := func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()
	count := 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= n; j++ {
			for k := 1; k <= n; k++ {
				count++
			}
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 640
#pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, MAXN); \
                 auto rnd = bind(__dis, __gen);

const int MAXN = 1E6;

int32_t main() {
    fastIO();
    
    int n;
    cin >> n;
    
    cout << (n+1) / 2 << "\n";
    
    return 0;
}


Measured memory_bytes: 256
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ,mod = 1e9+7 ;

int n ,m ,u ,v ,s ,t ;
vector<int> adj[N] ;
bool vis[N] ;
long long dis[N][3] ;
int main(){
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&u,&v);
        adj[v].push_back(u);
    }
    scanf("%d%d",&s,&t);
    memset(dis,'?',sizeof dis);
    queue<pair<int,int>> q;
    q.push({t,0});
    dis[t][0] = 0 ;
    while(q.size()){
        int p = q.front().first ;
        int md = q.front().second ;
        q.pop() ;
        for(int ch:adj[p]){
            int d = dis[p][md] + 1 ;
            if(dis[ch][d%3] <= d) continue ;
            dis[ch][d%3] = d ;
            q.push({ch,d%3});
        }
    }
    if(dis[s][0]>1e9) return cout << -1,0 ;
    cout << dis[s][0]/3 ;
    return 0;
}


Measured memory_bytes: 8192
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //int n=Readint();
            //string[] str = Console.ReadLine().Split(' ');
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int h = int.Parse(str[2]);
            int m = int.Parse(str[3]);

            double cos = Math.Cos(Math.PI * ((double)h / 6 +(double)m/360- (double)m / 30));
            //Console.WriteLine(cos);


            double ans2 = (a * a + b * b - 2 * a * b * cos);
            Console.WriteLine((double)Math.Pow(ans2, 0.5));

            //ここまで
        }

        
        static int Readint()
        {
            return int.Parse(Console.ReadLine());
        }

        static long Readlong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int Min(int a,int b)
        {
            if (a < b) return a;
            return b;
        }

        static int Max(int a, int b)
        {
            if (a > b) return a;
            return b;
        }
        

    }

}


Measured memory_bytes: 28060
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    string s;
    cin >> s;
    if(s == "SSS"){
        cout << 0 << endl;
    }else if(s == "RRR"){
        cout << 3 << endl;
    }else if(s == "SRR" || s == "RRS"){
        cout << 2 << endl;
    }else{
        cout << 1 << endl;
    }
}


Measured memory_bytes: 3248
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    long A[]=new long[N];
    long ans =0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextLong();}
    Arrays.sort(A);
    int n =N%2;
    int K =N/2;
    if(n==0){
      for(int j=K;j<N;j++){
        ans =ans+2*A[j];}
      ans =ans-A[N-1];}
    else{
      for(int k=K;k<N;k++){
        ans =ans +2*A[k];}
      ans =ans -A[N-1]-A[K];}
    System.out.println(ans);
  }
}

Measured memory_bytes: 61052
// https://atcoder.jp/contests/abc101/tasks/abc101_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

int main(void) {
    string s;
    cin >> s;
    int ans = 0;
    for (auto &x : s) {
        if (x == '+')
            ans++;
        else
            ans--;
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
    int n, m; cin >> n >> m;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    vector<ll> s(n+1,0); rep(i,n) s[i+1] = (s[i] + a[i]) %m;

    map<int,int> mp;

    ll ans = 0;
    rep(i,n+1){
        ans += mp[s[i]];
        mp[s[i]]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4736
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    int[] stk;
    foreach (_; 0..N) {
        auto a = readln.chomp.to!int;
        if (stk.empty || stk[$-1] >= a) {
            stk ~=a;
            continue;
        }
        int l, r = stk.length.to!int-1;
        while (l+1 < r) {
            auto mid = (l+r)/2;
            if (stk[mid] < a) {
                r = mid;
            } else {
                l = mid;
            }
        }
        if (stk[l] < a) {
            stk[l] = a;
        } else {
            stk[r] = a;
        }
    }
    writeln(stk.length);
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    string x;
    cin>>x;
    int s,t;
    s=t=0;
    int garb=0;
    int isnows=1;
    rep(i,x.size()){
        if(x[i]=='S'){
            if(isnows){
                s++;
            }
            else{
                if(s>t){
                    s-=t;
                    t=0;
                }
                else{
                    garb+=t-s;
                    s=t=0;
                }
                isnows=1;
                s++;
            }
        }
        else{
            isnows=0;
            t++;
        }
    }
    if(s>t)garb+=(s-t);
    else garb+=(t-s);
    cout<<garb<<endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

public class Main
{
  public static long d[] = new long[123456];
  public static HashMap<Integer, ArrayList<Integer>> h = new HashMap<>();
  public static HashMap<Integer, ArrayList<Long>> hd = new HashMap<>();

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    int n = Integer.parseInt(r.readLine());

    System.out.println(n <= 1199 ? "ABC" : (n <= 2799 ? "ARC" : "AGC"));

  }

}

Measured memory_bytes: 21332
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    rrep(j, i + 1, n) {
      rrep(k, j + 1, n) {
        b = a[i];
        c = a[j];
        d = a[k];
        if (b + c > d && b + d > c && c + d > b && b != c && b != d && c != d)
          ans++;
      }
    }
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 3576
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<i32>();
    let (a, b) = (line[0], line[1]);

    if a <= b{
        println!("{}", a);
    }else{
        println!("{}", a-1);
    }
}


Measured memory_bytes: 4352
#include"bits/stdc++.h"
using namespace std;
int main ()
{
    int n;
    scanf("%d", &n);
    int a[n];
    int i = 0;
    while(i<n)
    {
        scanf("%d", &a[i]);
        i++;
    }
    int l = sizeof(a)/sizeof(a[0]);
    sort(a,a+l);
    long long p1 = 0,p2 = 0;
    i = n;
    int f = 0;
    while(i>0)
    {
        if(a[i] == a[i-1] )
        {
            p1 = a[i];
            f = i;
            break;
        }
        i-=1;
    }
    i = n;
    while(i>0)
    {
        if(a[i] == a[i-1] && i!=f && i!=f-1)
        {
            p2 = a[i];
            break;
        }
        i = i-1;
    }
    printf("%lld",p1*p2);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
  cin>>x;
  if(x>=1800 && x<=1999)
    cout<<1<<endl;
  else if(x>=1600 && x<=1799)
    cout<<2<<endl;
  else if(x>=1400 && x<=1599)
    cout<<3<<endl;
  else if(x>=1200 && x<=1399)
    cout<<4<<endl;
  else if(x>=1000 && x<=1199)
    cout<<5<<endl;
  else if(x>=800 && x<=999)
    cout<<6<<endl;
  else if(x>=600 && x<=799)
    cout<<7<<endl;
  else 
    cout<<8<<endl;
  
  
}

Measured memory_bytes: 3592
n = int(input())

ans = ''
i = 0
if(n == 0):
    print(0)
    exit()
while(abs(n) > 1):
    if(n % 2 ** (i+1) == 0): ans += '0'
    else:
        ans += '1'
        n -= (-2) ** i
    i += 1

print(ans[::-1])

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

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

    int n,m,ans = 0;
    cin >> n >> m;

    for(int i = n; i <= m; ++i){
        string s = to_string(i);
        if(s[0] == s[4] && s[1] == s[3]) ans++;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const LL INF = 1LL << 60;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
vector<P> T[100000];
LL depth[100000];
void calc(int v, int p, LL d) {
	depth[v] = d;
	rep(i, T[v].size()) {
		int to = T[v][i].first;
		int cost = T[v][i].second;
		if (to == p) continue;
		calc(to, v, d + cost);
	}
}
int main() {
	int N;
	cin >> N;
	rep(i, N - 1) {
		int a, b, c;
		cin >> a >> b >> c; a--; b--;
		T[a].push_back(P(b, c));
		T[b].push_back(P(a, c));
	}
	int Q, K;
	cin >> Q >> K;
	calc(K - 1, -1, 0);
	rep(i, Q) {
		int x, y;
		cin >> x >> y; x--; y--;
		cout << depth[x] + depth[y] << endl;
	}
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef pair<uint32_t,uint32_t> P;

int bitSearchReverse(uint32_t x){
    if(x==0)return -1;
    return 31-__builtin_clz(x);
}
struct RadixHeap{
    vector<P>v[33];
    uint32_t last,sz;
    RadixHeap(){
        last=sz=0;
    }
    void push(P p){
        assert(last<=p.first);
        sz++;
        v[bitSearchReverse(p.first^last)+1].push_back({p.first,p.second});
    }
    P top(){
        return pop(false);
    }
    P pop(bool f=true){
        assert(sz);
        if(!v[0].size()){
            int i=1;
            while(!v[i].size())++i;
            last=min_element(v[i].begin(),v[i].end())->first;
            for(P p:v[i])v[bitSearchReverse(p.first^last)+1].push_back(p);
            v[i].clear();
        }
        P r=v[0].back();
        if(f){
            sz--;
            v[0].pop_back();
        }
        return r;
    }
    int size(){
        return sz;
    }
    bool empty(){
        return sz==0;
    }
    void clear(){
        last=sz=0;
        for(auto a:v)a.clear();
    }
};
struct Graph{
    Graph(int n):E(n),d(n){}
    vector<vector<P>>E;
    vector<uint32_t>d;
    void add_edge(int a,int b,uint32_t c){
        E[a].emplace_back(b,c);
    }
    void dijkstra(int s){
        RadixHeap H;
        fill(d.begin(),d.end(),INF);
        H.push({d[s]=0,s});
        while(H.size()){
            P e=H.top();H.pop();
            if(e.first>d[e.second])continue;
            for(P& a:E[e.second]){
                uint32_t x=a.first,y=a.second+e.first;
                if(y<d[x])d[x]=y,H.push({y,x});
            }
        }
    }
};

main(){
    int N;
    cin>>N;
    Graph G(N);
    for(int i=0;i<N;++i){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;++j){
            int v,c;
            cin>>v>>c;
            G.add_edge(u,v,c);
        }
    }
    G.dijkstra(0);
    for(int i=0;i<N;++i)
        cout<<i<<' '<<G.d[i]<<endl;
}

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

referred
https://github.com/yosupo06/Algorithm/blob/master/datastructure/buf/RadixHeap.h

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

Measured memory_bytes: 7504
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 998244353

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

const ll sz = 300000;

ll fact[sz + 10];

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


ll nCr(ll n, ll r)
{
    if(r > n) return 0;

    if(n < mod)
    {
        ll z = ((power(fact[r], mod - 2, mod)) * (power(fact[n - r], mod - 2, mod))) % mod;
        return (fact[n] * z) % mod;
    }

    /// Lucas Theorem
    vector < ll > N, K;

    while(n) N.push_back(n % mod), n /= mod;

    while(r) K.push_back(r % mod), r /= mod;

    ll ret = 1;

    for(ll i = 0; i < K.size(); i++)
    {
        ret = (ret * nCr(N[i],K[i])) % mod;
    }

    return ret;
}

void precalc()
{
    fact[0] = 1;

    for(ll i = 1; i <= sz; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
    }
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

	precalc();

//    slld(testcase);

    while(cin >> n >> m >> k)
    {
		ans = 0;

		for(i = 0; i <= k; i++)
		{
			ll tmp = m;
			tmp = (tmp * nCr(n-1,i)) % mod;
			tmp = (tmp * power(m-1,n-1-i,mod)) % mod;

			ans = (ans + tmp) % mod;
		}

		cout << ans << '\n';
    }


}




Measured memory_bytes: 5972
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	int h, w, n;
	cin >> h >> w >> n;
	vector<int> x(n), y(n);
	vector<P> p(n);
	REP(i, n) {
		cin >> x[i] >> y[i];
		p[i].first = --x[i];
		p[i].second = --y[i];
	}
	sort(all(p));
	int res = h;
	int cnt = 0;
	REP(i, n) {
		if (p[i].first > p[i].second + cnt) {
			chmin(res, p[i].first);
		} else if (p[i].first == p[i].second + cnt) {
			cnt++;
		}
	}
	put(res);
	return 0;
}

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    long int x;
    cin >> x;
    long int ans = 0;
    long int memo = 0;
    ans += x / 500 * 1000;
    memo = x / 500;
    x = x - memo * 500;
    ans += x / 5 * 5;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long M;
  cin >> N >> M;
  vector<pair<long, long>> p(N);
  long cnt=0;
  long sum=0;
  for(int i=0; i<N; i++){
    cin >> p.at(i).first >> p.at(i).second;
  }
  sort(p.begin(), p.end());
  for(int i=0; i<N; i++){
    cnt = min(M, p.at(i).second);
    M -= cnt;
    sum += cnt * p.at(i).first;
    if(M<=0){
      break;
    }
  }
  cout << sum;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
using namespace std;

int main(){
    int n;
    while(cin>>n && n){
        vector<int> ok[31];
        for(int i=1;i<=n;i++){
            int f;cin>>f;
            for(int j=0;j<f;j++){
                int t;cin>>t;
                ok[t].push_back(i);
            }
        }
        vector<set<int>> met(n+1);
        for(int i=1;i<=n;i++){
            met[i].insert(i);
        }

        int ans=-1;
        for(int i=1;i<=30;i++){
            vector<set<int>> nmet(n+1);
            for(int j=1;j<=n;j++){
                nmet[j] = met[j];
            }
            set<int> s;
            for(int j=0;j<ok[i].size();j++){
                for(int x:met[ok[i][j]]){
                    s.insert(x);
                }
            }
            for(int j=0;j<ok[i].size();j++){
                nmet[ok[i][j]] = s;
            }

            // for(int j=1;j<=n;j++){
            //     printf(" met %d: ",j);
            //     for(int x: nmet[j]){
            //         cout << x << " ";
            //     }
            //     cout << endl;
            // }

            for(int j=1;j<=n;j++){
                if(nmet[j].size()==n){
                    ans = i;
                    break;
                }
            }
            if(ans!=-1)break;
            met = nmet;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1444
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int x;
  cin >> x;
  if (x >= 30) cout << "Yes\n";
  else cout << "No\n";
}

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

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

   if(a+b<=16){
    if(a<=8&&b<=8)
      cout<<"Yay!"<<endl;
    else
      cout<<":("<<endl;
    }
   else
    cout<<":("<<endl;
   
}

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

int main() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }

    std::vector<int> dp(n);
    for (int i = 1; i < n; i++) {
        dp[i] = 1000000010;
        for (int j = std::max(0, i - k); j < i; j++) {
            dp[i] = std::min(dp[j] + abs(h[i] - h[j]), dp[i]);
        }
    }

    std::cout << dp[n - 1] << std::endl;

    return 0;
}

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

using namespace std;

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

  string s;
  cin >> s;
  for (int i = 1; i < 10; ++i) { 
    if (s <= string(3, '0'+i)) {
      cout << string(3, '0'+i) << endl;
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;
ll n;
vll A,B;

int main() {
    cin >> n;
    A.resize(n+1);B.resize(n);
    rep(i,n+1) cin >> A[i];
    rep(i,n) cin >> B[i];
    // rep(i,n+1) cout << A[i] << endl;
    ll ans = 0;
    for(int i=n-1;i>=0;i--){
        int a = min(A[i+1],B[i]);
        ans+=a;
        B[i]-=a;
        a = min(A[i],B[i]);
        A[i]-=a;
        ans += a;
        // printf("ans:%lld i:%d Ai:%lld Ai+1:%lld\n",ans,i,A[i],A[i+1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int h,w,n; cin >> h >> w >> n;
  vector<pair<int,int> > a(n);
  rep(i,n) {
    pair<int,int> p;
    cin >> p.second;
    p.first = i + 1;
    a[i] = p;
  }

  int res[h][w];
  ll count = 0, row = 0;
  bool flag = true;
  for (auto itr : a) {
    for (int i = 0; i < itr.second; ++i) {
      res[row][count] = itr.first;
      if (flag) {
        count += 1;
        if (count >= w) {
          row += 1;
          count = w-1;
          flag = false;
        }
      } else {
        count -= 1;
        if (count < 0) {
          row += 1;
          count = 0;
          flag = true;
        }
      }
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cout << res[i][j] << " ";
    }
    END;
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int n;
	cin >> n;
	vi a(n);
	vll sum(n);
	rep(i, n) {
		cin >> a.at(i);
		if (i == 0) {
			sum.at(i) = a.at(i);
		}
		else {
			sum.at(i) = sum.at(i - 1) + a.at(i);
		}
	}
	ll s = 0 , r = 0;
	ll ans = LLONG_MAX;
	ll tmp;
	rep(i, n - 1) {
		s = sum.at(i);
		r = sum.at(n - 1) - sum.at(i);
		tmp = abs(s - r);
		if (ans > tmp)ans = tmp;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N; int a; int b;
	while(~scanf("%d%d%d", &N, &a, &b)) {
		-- a, -- b;
		vector<int> x(N);
		vector<int> y(N);
		map<ll, multimap<ll,int>> T, U;
		for(int i = 0; i < N; ++ i) {
			scanf("%d%d", &x[i], &y[i]);
			ll t = x[i] + y[i], u = x[i] - y[i];
			T[t].insert(make_pair(u, i));
			U[u].insert(make_pair(t, i));
		}
		ll d = abs(x[a] - x[b]) + abs(y[a] - y[b]);
		vector<int> que;
		vector<bool> vis(N);
		que.push_back(a);
		que.push_back(b);
		vis[a] = vis[b] = true;
		for(int qh = 0; qh != que.size(); ++ qh) {
			int i = que[qh];
			auto moveTo = [&vis,&que](map<ll, multimap<ll, int>> &P, ll p, ll qL, ll qR) {
				auto it = P.find(p);
				if(it == P.end()) return;
				auto &Q = it->second;
				auto jtL = Q.lower_bound(qL);
				auto jtR = Q.upper_bound(qR);
				for(auto jt = jtL; jt != jtR; ++ jt) {
					int j = jt->second;
					if(!vis[j]) {
						vis[j] = true;
						que.push_back(j);
					}
				}
				Q.erase(jtL, jtR);
			};
			ll t = x[i] + y[i], u = x[i] - y[i];
			moveTo(T, t + d, u - d, u + d - 1);
			moveTo(T, t - d, u - d + 1, u + d);
			moveTo(U, u - d, t - d, t + d - 1);
			moveTo(U, u + d, t - d + 1, t + d);
		}

		T.clear();
		U.clear();
		for(int i : que) {
			ll t = x[i] + y[i], u = x[i] - y[i];
			T[t].insert(make_pair(u, 0));
			U[u].insert(make_pair(t, 0));
		}
		rep(k, 2) for(auto &&p : k == 0 ? T : U) {
			int sum = 0;
			for(auto &&q : p.second)
				q.second = sum ++;
			p.second.insert(make_pair(INFL, sum));
		}
		ll ans = 0;
		for(int i : que) {
			auto moveTo = [&ans](map<ll, multimap<ll, int>> &P, ll p, ll qL, ll qR) {
				auto it = P.find(p);
				if(it == P.end()) return;
				auto &Q = it->second;
				auto jtL = Q.lower_bound(qL);
				auto jtR = Q.upper_bound(qR);
				ans += jtR->second - jtL->second;
			};
			ll t = x[i] + y[i], u = x[i] - y[i];
			moveTo(T, t + d, u - d, u + d - 1);
			moveTo(T, t - d, u - d + 1, u + d);
			moveTo(U, u - d, t - d, t + d - 1);
			moveTo(U, u + d, t - d + 1, t + d);
		}
		ans /= 2;
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 40952
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()

const ll inf=9e18;


int main(){
    int tt;
    cin>>tt;
    rep(i,tt){
        ll n,a,b,c,d; cin>>n>>a>>b>>c>>d;
        vector<pair<int,ll>> p;
        p.emplace_back(2,a);
        p.emplace_back(3,b);
        p.emplace_back(5,c);
        map<ll,ll> mp;
        mp[0]=0; mp[1]=d;
        function<ll(ll)> dfs=[&](ll x){
            if(mp.find(x)!=mp.end()){
                return mp[x];
            }
            ll ret=inf;
            if((long double)d* (long double)x <ret) ret=d*x;
            for(auto& v: p){
                int num=v.first;
                ll cost=v.second;
                ret=min(ret, dfs(x/num)+cost+d*(x%num));
                if(x%num!=0){
                    ret=min(ret,dfs(x/num+1)+cost+d*(num-x%num));
                }
            }
            return mp[x]=ret;
        };
        cout<<dfs(n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 4360
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
    int n , d, tempi, cnt = 0;
    vector<vector<int> > ans;
    cin >> n >> d;
    for(int i=0; i < n; ++i){
        vector<int> temp;
        for(int j = 0; j < d; ++j){
            cin >> tempi;
            temp.push_back(tempi);
        }
        ans.push_back(temp);
    }
    for(int i = 0;i < n-1; ++i){
        for(int j = i+1; j<n; ++j){
            double k = 0;
            for(int l = 0; l < d; ++l){
                k += (ans[i][l]-ans[j][l])*(ans[i][l]-ans[j][l]) ;
            }
            k = sqrt(k);
            if(floor(k)== k){
                ++cnt;
            }
        }
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

long long abs(long long a){
  if(a >= 0){
    return a;
  }
  else{
    return -a;
  }
}

int main(void){
  int n , k;
  scanf("%d %d",&n ,&k);

  long long x[n];
  int zero = -1;
  for(int i = 0;i < n;i ++){
    scanf("%lld",&x[i]);
    if(x[i-1] < 0 && x[i] >= 0){
      zero = i;
    }
  }
  
  if(zero == -1){
    if(x[n-1] < 0){
      zero = n;
    }
    else{
      zero = 0;
    }
  }

  int start , end;
  long long time , min = 1000000000000;
  for(int i = 0;i < n - k + 1;i ++){
    start = i;
    end = i + k - 1;
    if(i < zero && zero <= i + k ){
      time =  - x[start] + x[end];
      if(abs(x[start]) < abs(x[end])){
        time += abs(x[start]);
      }
      else{
        time += abs(x[end]);
      }
    }
    else if(i < zero){
      time = abs(x[start]);
    }
    
    else if(i >= zero){
      time = abs(x[end]);
    }
    //printf("%lld\n",time);
    if(min > time){
      min = time;
    }
  }

  printf("%lld\n",min);

  return 0;
}

Measured memory_bytes: 2484
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int a[20],b[20];
int main()
{
    int n,m,c;
    while(cin>>n>>m>>c){
    	int num=0;
    	memset(a,0,sizeof(a));
    	for(int i=0;i<m;i++) cin>>a[i];
    	while(n--){
    		int sum=0,x;
    		for(int i=0;i<m;i++){
    			cin>>x;
    			sum+=x*a[i];
    		}
    		sum+=c;
    		if(sum>0) num++;
    	}
    	cout<<num<<endl;
    }
    return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


long long N;
map<long long, int> MP;
vector<long long> A;

#ifdef DEBUG1
void printMP(){
	printf(" MP: ");
	for(auto itr = MP.begin(); itr != MP.end(); itr++){
		long long k = itr->first;
		int v = itr->second;
		printf("(%lld, %d), ", k, v);
	}
	printf("\n");
}
#endif

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

	cin >> N;
	for(int i=0; i<N; i++){
		long long a;
		cin >> a;
		A.push_back(a);
		if(MP.count(a) == 0){
			MP[a] = 1;
		}
		else{
			MP[a]++;
		}
	}
#ifdef DEBUG1
	printMP();
#endif
	if(A.size() == 1){
		printf("1\n");
		return 0;
	}

	if(A[0] == A[A.size()-1]){
		printf("0\n");
		return 0;
	}
	sort(A.begin(), A.end()); //ソートしておく

	for(auto itr = MP.begin(); itr != MP.end(); ++itr){
		long long k = itr->first;
		int v = itr->second;
		for(int i=2; ; i++){
			long long w = k * i;
			if(w > A[A.size() - 1]){
				break;
			}
			if(MP.count(w) != 0){
				MP[w] = -1;
			}
		}
	}

#ifdef DEBUG1
	printMP();
#endif

	int ans = 0;
	for(auto itr = MP.begin(); itr != MP.end(); ++itr){
		long long k = itr->first;
		int v = itr->second;
		if(v == 1){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 17328
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int c[13];
int cl[25];
int ans;

void dfs(int i){
  if(i == 13){
    int res = 24;
    int tmp = 1;
    for(int j = 1; j <= 24; j++){
      if(cl[j] > 0){
        res = min(res, tmp);
        tmp = 1;
      }else{
        tmp++;
      }
    }
    ans = max(res, ans);
    return;
  }
  if(c[i] == 0){
    dfs(i + 1);
  }else if(c[i] == 1){
    cl[i]++;
    dfs(i + 1);
    cl[i]--;
    if(i != 12){
      cl[24 - i]++;
      dfs(i + 1);
      cl[24 - i]--;
    }
  }else if(c[i] == 2){
    cl[i]++;
    cl[24 - i]++;
    dfs(i + 1);
  }else{
    cout << "ERROR" << endl;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int d[105];
  c[0]++;
  for(int i = 0; i < N; i++){
    cin >> d[i];
    c[d[i]]++;
  }
  bool zero = false;
  REP(i,13){
    if(i == 12 or i == 0){
      if(c[i] >= 2) zero = true;
    }else if(c[i] >= 3){
      zero = true;
    }
  }
  if(zero){cout << 0 << endl;
  }else{
    cl[0] = cl[24] = 1;
    ans = 0;
    dfs(1);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	string s;
	cin >> s;
	ll n = s.size();
	Vec cs(n + 1);
	repr(i, n){
		if (s[i] == '1') cs[i] = cs[i + 1] + 1;
		else
			cs[i] = max(0LL, cs[i + 1] - 1);
	}
	// co(cs);

	rep(m, 100){
		bitset<101> bits(0), range(0);
		rep(i, m + 1) bits.set(i);
		rep(i, m + 1) range.set(i);
		repr(i, n){
			bitset<101> nxt(0);
			if (s[i] == '0') nxt |= bits >> 1;
			else if(s[i] == '1')
				nxt |= bits << 1;
			else{
				nxt |= bits << 1;
				nxt |= bits >> 1;
			}
			nxt &= range;
			swap(nxt, bits);
			// co({i, (ll)bits.to_ullong()});
		}

		if (bits != bitset<101>(0)){
			co(m);
			return 0;
		}
	}

	ll l = -1, r = n;
	ll ans = n;
	while(r - l > 1){
		ll m = (l + r) / 2;
		ll p = 0, min = 0;
		bool flg = true;
		rep(i, n){
			if (s[i] == '1') ++p;
			else if(s[i] == '0')
				--p;
			else{
				if (p + 1 + cs[i + 1] <= m) ++p;
				else
					--p;
			}
			// co({s[i]});
			// co({m, i, p});
			if (p > m){
				flg = false;
				break;
			}
			chmin(min, p);
		}

		if(flg){
			chmin(ans, m - min);
			r = m;
		}else
			l = m;
	}
	// co(r);
	co(ans);

	return 0;
}


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

void solve()
{
    ll n,k;
    cin>>n>>k;
    ll a[n+5];
    for(ll i=1;i<=n;i++) cin>>a[i];
    vector<ll> path;
    set<ll> u;
    path.push_back(1ll); 
    u.insert(1ll);   
    ll ind=1;
    while(1)
    {
        if(u.find(a[ind])==u.end())
        {
            u.insert(a[ind]);
            path.push_back(a[ind]);
            ind=a[ind];
        }
        else
        {
            path.push_back(a[ind]);
            break;
        }
    }
    ll x=path.size(),y;
    y=x;
    ll cyclebeg=path[x-1];
    x=0;
    while(path[x]!=cyclebeg) x++;
    ll k1=k;
    k=k-x;
    if(k>=0)
    {
        ll cyclelen=y-1-x;
        ll ans=k%cyclelen;
        cout<<path[x+ans]<<"\n";
    }
    else cout<<path[k1]<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

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

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    string s;
    char C[5];

    cin >> a >> b;

    if(a-b>0) cout << a-b;
    else cout << 0;

    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<string> strs(2,"");
    cin>>strs[0]>>strs[1];
    // cout<<strs[0]<<" "<<strs[1]<<endl;
    string re;
    for(int i=0;i<2*n;i++){
        re.push_back(strs[i%2][i/2]);
    }
    cout<<re<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, K;
long long A[1 << 19];
int used[1 << 19];
vector<int> P;

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N; i++) used[i] = -1;

	int cx = 1; used[cx] = 0;
	long long val = -1, rec = -1;
	for (int i = 1; i <= N * 2; i++) {
		P.push_back(cx);
		cx = A[cx];
		if (used[cx] != -1) {
			val = used[cx];
			rec = (i - used[cx]);
			break;
		}
		used[cx] = i;
	}

	if (val > K) {
		cout << P[K] << endl;
	}
	else {
		long long R = (K - val) % rec;
		cout << P[val + R] << endl;
	}
	return 0;
}

Measured memory_bytes: 6644
#include<bits/stdc++.h>
#define ft(i,l,r) for(register int i=l;i<=r;i++)
#define fd(i,r,l) for(register int i=r;i>=l;i--)
using namespace std;
int n,a[233333];
int main()
{
    cin>>n;
    ft(i,1,n) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    ft(i,2,n)
      if(a[i]==a[i-1]) {cout<<"NO"<<endl;return 0;}
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let pi = std::f64::consts::PI;
    let a: f64 = read();
    let b: f64 = read();
    let h: f64 = read();
    let m: f64 = read();

    let rad1 = (h + m /60.) / 12. * pi * 2.;
    let rad2 = m / 60. * pi * 2.;

    let rad = rad2 - rad1;

    let ans = ((a).powi(2) + (b).powi(2) - 2.0 * a * b * rad.cos()).sqrt();

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


Measured memory_bytes: 3076
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    int n;
    cin >> n;
    vec<int> v(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> v[i];
    
    vec<int> ans(n + 1);

    for (int i = n; i > 0; --i)
    {
        int sum{};
        for (int j = i; j <= n; j += i)
        {
            sum += ans[j];
        }
        ans[i] = sum % 2 != v[i];
    }
    
    cout << accumulate(ans.cbegin(), ans.cend(), 0) << endl;

    for (int i = 1; i <= n; ++i)
    {
        if (ans[i] == 1)
        {
            cout << i;
            if (i != n)
                cout << " ";
        }
    }
    //cout << endl;

    //auto canmake = true;

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

    //    canmake &= sum % 2 == v[i];
    //}

    //if (canmake)
    //    cout << "Yes" << endl;
    //else
    //    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 2432
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        ArrayList<Integer> A1 = new ArrayList<>();
        ArrayList<Integer> A2 = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            A1.add(scanner.nextInt());
        }
        for (int i = 0; i < N; i++) {
            A2.add(scanner.nextInt());
        }
        scanner.close();

        int max = 0;
        int count1 = 0;
        for (int i = 0; i < N; i++) {
            count1 += A1.get(i);
            int count2 = count1;
            for (int j = i; j < N; j++) {
                count2 += A2.get(j);
            }
            if (max < count2) {
                max = count2;
            }

        }

        System.out.println(max);
    }
}

Measured memory_bytes: 21844