akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define ggr getchar();getchar();return 0;
using namespace std;
int n,k,a[110];
int dp[110][100010];
signed main(){
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    rep(i,k+1)dp[0][i]=1;
    for(int i=1;i<=n;i++){
        rep(j,k+1){
            if(j-a[i-1]-1>=0)dp[i][j]=(dp[i-1][j]-dp[i-1][j-a[i-1]-1]+moder*(ll)100)%moder;
            else dp[i][j]=dp[i-1][j];
        }
        rep(j,k+1){
            if(j)dp[i][j]+=dp[i][j-1];
            dp[i][j]%=moder;
        }
    }
    cout<<(dp[n][k]-dp[n][k-1]+moder)%moder<<endl;
    ggr;
}

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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

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

int n, a[N];

ll f(int x) {
    ll res = 0;
    For (i, 1, n) {
        res += abs(a[i] - x - i);
    }
    return res;
}

int main () {
	cin >> n;
	For (i, 1, n) {
	    cin >> a[i];
	}
	
	int l = -inf, r = inf;
	ll res = INF;
	while (l + 5 <= r) {
	    int md = (l + r) >> 1;
	    if (f(md) > f(md + 1)) {
	        l = md;
	        res = min(res, f(l));
	    } else {
	        r = md + 1;
	        res = min(res, f(r));
	    }
	}
	For (i, l, r)
	    res = min(res, f(i));
	
	cout << res;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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;
}

signed main() {
  ll N;
  cin >> N;
  ll currentNode = 1;
  ll nodecount = 0;


  vector<int> A(N+1);
  int sum = 0;
  rep(i, N+1) { cin >> A[i]; sum += A[i];}
  rep(i, N) {
    int leaf = A[i];
    if (currentNode <= leaf) {
      cout << -1 << endl;
      return 0;
    }
    sum -= A[i];
    nodecount += currentNode;
    
    currentNode = min(2 * (currentNode - leaf), sum);
  }
  if (currentNode < A[N]) {
    cout << -1 << endl;
    return 0;
  }
  nodecount += A[N];
  cout << nodecount << endl;
}

Measured memory_bytes: 3992
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())
s = [stdin.readline().rstrip() for _ in range(n)]

final = s[0]
for i in s:
    for j in final:
        if j not in i:
            final = final.replace(j,"")
        elif final.count(j) > i.count(j):
            final = list(final)
            for k in range(final.count(j)-i.count(j)):
                final.remove(j)
            final = "".join(final)
final = list(final)
final.sort()

print("".join(final))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int bpc(int i) {
    return __builtin_popcount(i) % 2;
}

bool bit(int n, int i) {
    return (n >> i) & 1;
}

int search_x(int a, int b) {
    rep(i, 32) {
        if (bit(a, i) != bit(b, i)) return i;
    }
    __throw_runtime_error("konaidene");
}


vector<int> rec(vector<int> &v, set<int> &old_x, int a, int b) {
    assert(bpc(a) != bpc(b));
    assert(find(v.begin(), v.end(), a) != v.end());
    assert(find(v.begin(), v.end(), b) != v.end());

    if (v.size() == 2) return {a, b};

    int x = search_x(a, b);
    old_x.insert(x);

    vector<int> u1, u2;
    u1.push_back(a);
    for (int i : v) {
        if (i == a || i == b) continue;
        if (bit(i, x) == bit(a, x)) u1.push_back(i); else u2.push_back(i);
    }
    u2.push_back(b);

    {
        for (ll l : u1) assert(bit(l, x) == bit(a, x));
        for (ll l : u2) assert(bit(l, x) == bit(b, x));
    }

    assert(u1.size() == u2.size());

    P p = [&] {
        for (int l1 : u1) {
            if (l1 == a) continue;
            if (bpc(a) == bpc(l1))continue;

            for (int l2 : u2) {
                if (l2 == b) continue;
                if (bpc(l2) == bpc(b))continue;
                int xx = 1 << x;

                assert(bit(l1, x) != bit(l2, x));

                if ((l1 | xx) == (l2 | xx)) {
                    return P(l1, l2);
                }
            }
        }
        __throw_runtime_error("konaide");
    }();

    auto t1 = rec(u1, old_x, a, p.first), t2 = rec(u2, old_x, p.second, b);
    for (int k : t2) t1.push_back(k);
    old_x.erase(x);
    return t1;

}

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

    if (bpc(a) % 2 == bpc(b) % 2) {
        cout << "NO" << endl;
        ret();
    }

    cout << "YES" << endl;

    vector<int> v(1 << n);
    rep(i, 1 << n) v[i] = i;

    set<int> old_x;
    auto ans = rec(v, old_x, a, b);

    for (int i : ans) cout << i << ' ';
    cout << endl;

}


Measured memory_bytes: 2892
#include<stdio.h>

int main()
{
    int a, b,c;

    scanf("%d%d%d", &a, &b, &c);

    if ((a < b) && (b < c))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
using namespace std;

typedef long long ll;

int main() {
  ll l, r;

  while (cin >> l >> r) {
    bool used[2019];
    fill(used, used + 2019, false);
    for (ll i = l; i <= r && i <= l + 2019; i++) {
      used[(int)(i % 2019LL)] = true;
    }
    int mn = INT_MAX;
    for (int i = 0; i < 2019; i++) {
      if (!used[i]) continue;
      for (int j = i + 1; j < 2019; j++) {
        if (!used[j]) continue;
        mn = min(mn, (i * j) % 2019);
      }
    }
    cout << mn << endl;
  }
}


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

long long a[200010];

long long retabs(long long x,long long y){
    if(x>y)return x-y;
    else return y-x;
}

int main(){
    int n;
    cin>>n;
    long long sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        if(i>0){
            a[i]+=a[i-1];
        }
    }
    long long min=retabs(a[0],sum-a[0]);
    for(int i=1;i<n-1;i++){
        if(min>retabs(a[i],sum-a[i]))min=retabs(a[i],sum-a[i]);
    }
    cout<<min<<endl;
    return 0;
}

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


int main()
{
    int n ;
    cin>>n;
    int p[n];
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
    }
    int m = INT_MAX;
    int ans =0;
    for(int i=0;i<n;i++)
    {
        m = min( m , p[i]);
        if( m == p[i] )
        {
            ans++;
        }
    }
    cout<<ans;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var temp = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int k = temp[0];
            int n = temp[1];
            var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
            a.Add(a[0]);
            a.Insert(0, a[a.Count - 2]);
            int min = int.MaxValue;
            for (int i = 1; i < a.Count - 1; i++)
            {
                int rightDist = a[i - 1] - a[i];
                rightDist += rightDist < 0 ? k : 0;
                int leftDist = a[i] + k - a[i + 1];
                min = Math.Min(min, Math.Min(rightDist, leftDist));
            }
            System.Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 34652
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long int ll;
using namespace std;

int n;
int l[2000];

int main(){
  cin >> n;
  for(int i=0;i<n;i++) cin >> l[i];
  sort(&l[0], &l[n]);
  int ans = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int idx = lower_bound(&l[0], &l[n], l[i] + l[j]) - &l[0];
      ans += idx - (j + 1);      
    }
  }
  cout << ans << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <stack>
#include <string>

using namespace std;

int main(){
	stack<int> st;
	int a,b;
	string s;

	while(cin>>s)
		if(s[0]=='+'){
			a=st.top();
			st.pop();

			b=st.top();
			st.pop();

			st.push(a+b);
		}else if(s[0]=='-'){
			a=st.top();
			st.pop();

			b=st.top();
			st.pop();

			st.push(b-a);
		}else if(s[0]=='*'){
			a=st.top();
			st.pop();

			b=st.top();
			st.pop();

			st.push(a*b);
		}else{
			st.push(atoi(s.c_str()));
		}

	cout<<st.top()<<endl;
}

Measured memory_bytes: 3176
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	h := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	h[n] = -1

	max_step := 0
	for i := 0; i < n; i++ {
		count := 0
    var j int
		for j = i; h[j] >= h[j+1] && h[j+1] != -1; j++ {
			count++
		}
		if max_step < count {
			max_step = count
		}
    i = j
	}

	fmt.Println(max_step)
}


Measured memory_bytes: 5504
#include<stdio.h>

int main(void)
{
   int n,d,x,a[101],i,j,s=0;

   scanf("%d%d%d",&n,&d,&x);
   for(i=0;i<n;i++)
      scanf("%d",&a[i]);

   for(i=0;i<n;i++){
      for(j=1;j<=d;j+=a[i])
         s++;
   }
   printf("%d\n",s+x);
   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric> 
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1e9 + 5;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
///////////////////////////////////////////////////////////////////////

map<pair<int, int>, ll> memo;

ll helper(vector<int>& a, int i, int j) {
    if (memo.count({i, j}) != 0) return memo[{i, j}];
    if (i > j) return 0;
    if (i == j) return a[i];
    ll res = max(a[i] + min(helper(a, i + 2, j), helper(a, i + 1, j - 1)), a[j] + min(helper(a, i + 1, j - 1), helper(a, i, j - 2)));
    memo[{i, j}] = res;
    return res;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int& x : a) scanf("%d", &x);

    ll res = helper(a, 0, a.size() - 1);
    ll total = 0;
    for (int x : a) total += x;
    printf("%lld\n", 2 * res - total);
}

Measured memory_bytes: 141056
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer)
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) } ; }
#[allow(dead_code)]
fn main() {
    input!{
        n: usize,
        s: chars,
        t: chars,
    }
    let mut same = 0;
    for i in 0..n {
        //debug!(s[i]);
        //debug!(t[n-i-1]);
        if s[i..n] == t[0..n-i] {
            same = n-i;
            break;
        }
    }
    println!("{}", 2 * n - same);
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <numeric>
using namespace std;


int main()
{
    string S;
    std::cin >> S;
    // std::cout << S.size() << "\n";
    
    int num = S.size();
    string S_coll1(num, '0');
    string S_coll2(num, '0');
    for (int i = 0; i < S.size(); ++i)
    {
        // std::cout << i << "\n";
        if (i%2 == 0)
        {
            S_coll2[i] = '1';
        }else{
            S_coll1[i] = '1';
        }
    }
    // std::cout << S_coll1<< "\n";
    // std::cout << S_coll2<< "\n";
    
    int cnt1 = 0;
    int cnt2 = 0;
    
    for (int i = 0; i < num; ++i)
    {
        if(S[i] != S_coll1[i]) ++cnt1;
        if(S[i] != S_coll2[i]) ++cnt2;
    }
    if(cnt1 > cnt2){
        std::cout << cnt2 << "\n";
    }else{
        std::cout << cnt1 << "\n";
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010]={0,1,2,3,4,5,6,7,8,9}; 
int main()
{
	int k,id=1;scanf("%d",&k);
	for(int i=10; i<=k; )
	{
		ll x=a[id]*10,y=a[id++]%10;
		if(y==0)
		{
			a[i++]=x;
			a[i++]=x+1;
		}
		else if(y==9)
		{
			a[i++]=x+8;
			a[i++]=x+9;
		}
		else
		{
			a[i++]=x+y-1;
			a[i++]=x+y;
			a[i++]=x+y+1;
		}
	}
	printf("%lld\n",a[k]);
	return 0;
}


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

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define ll long long

int main(void)
{
    int arr[101],a,i;
    scanf("%d",&a);
    for(i=0;i<a;i++)
        scanf("%d",arr+i);
    for(i=a-1;i>=0;i--)
        printf("%d%c",*(arr+i),(i>0)?' ':'\n');
    return 0;
}




Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  int64_t K, M;
  cin >> K;
  M = max(K + 1, (int64_t) 10);
  vector<int64_t> ans(M);

  vector<vector<string>> a, b;
  a = { {"0"}, {"1"}, {"2"}, {"3"}, {"4"}, {"5"}, {"6"}, {"7"}, {"8"}, {"9"} };
  for (int64_t i = 1; i < 10; i++) {
    ans.at(i) = i;
  }

  int64_t n = 9;
  int64_t keta = 1;
  int64_t c;
  bool finished = false;
  while (n < K) {
    b = {{}, {}, {}, {}, {}, {}, {}, {}, {}, {}};
    for (int64_t i = 0; i < 10; i++) {
      for (int64_t k = -1; k < 2; k++) {
        if ((i == 0 && k == -1) || (i == 9 && k == 1)) {
          continue;
        }
        for (int64_t j = 0; j < a.at(i + k).size(); j++) {
          c = i * (int64_t) pow(10, keta) + stoll(a.at(i + k).at(j));
          b.at(i).push_back(to_string(c));
          if (i != 0) {
            n++;
            ans.at(n) = c;
          }
          if (n >= K) {
            finished = true;
            break;
          }
        }
        if (finished) {
          break;
        }
      }
      if (finished) {
        break;
      }
    }
    if (finished) {
      break;
    }
    a = b;
    keta++;
  }
  cout << ans.at(K) << endl;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int ll

int h, w, n, k, ans;

int pot[50*50];

int query(int y1, int y2, int x1, int x2)
{
	cout << "? " << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	int ans;
	cin >> ans;
	return ans;
}

void solve(int y1, int y2, int x1, int x2, int cnt, int split)
{
	if(cnt==0)
		return;

	if(cnt==(y2-y1+1)*(x2-x1+1))
	{
		for(int i = y1; i <= y2; ++i)
		{
			for(int j = x1; j <= x2; ++j)
			{
				ans += pot[i*w+j];
				ans %= k;
			}
		}

		return;
	}

	if(y1!=y2)//split)
	{
		int m = (y1+y2)/2;
		int h = query(y1, m, x1, x2);
		solve(y1, m, x1, x2, h, split^1);
		solve(m+1, y2, x1, x2, cnt-h, split^1);
	}
	else
	{
		int m = (x1+x2)/2;
		int h = query(y1, y2, x1, m);
		solve(y1, y2, x1, m, h, split^1);
		solve(y1, y2, m+1, x2, cnt-h, split^1);
	}
}

int32_t main()
{
	cin >> h >> w >> n >> k;

	pot[0] = 1;

	for(int i = 1; i < 50*50; ++i)
	{
		pot[i] = pot[i-1]*2%k;
	}

	for(int j = 0; j < w; j += 3)
	{
		solve(0, h-1, j, min(j+2, w-1), query(0, w-1, j, min(j+2, w-1)), 1);
	}

	/*for(int i = 0; i < h; i += 5)
	{
		for(int j = 0; j < w; j += 5)
		{
			solve(i, i+4, j, j+4, query(i, i+4, j, j+4), 1);
		}
	}*/

	//solve(0, h-1, 0, w-1, n, 1);

	cout << "! " << ans << endl;
}

Measured memory_bytes: 720
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)
typedef pair<double,int> pdi;


vector<int> G[150000];
double val[150000];
double ans[150000];
int deg[150000];

double dfs(int cur, int prev){
    double ret = 0;
    int c=0;
    
    for(auto e:G[cur]){
        if(e==prev)continue;
        c++;
        ret+=1+dfs(e,cur);
    }
    if(c!=0)ret/=c;
    return val[cur] = ret;
}


double dfs2(int cur, int prev, double d_par){
    vector<pdi> v;
    for(auto e:G[cur]){
        if(e==prev)v.pb(pdi(d_par+1,e));
        else v.pb(pdi(val[e]+1,e));
    }
    
    double ave = 0;
    rep(i,v.size())ave+=v[i].first;
    ave/=deg[cur];
    
    
    for(auto e:G[cur]){
        if(e==prev)continue;
        if(deg[cur]==1)dfs2(e,cur,0);
        else dfs2(e,cur,(ave*deg[cur]-(val[e]+1))/(deg[cur]-1));
    }
    
    return ans[cur] = ave;
}

int main(){
    int n;
    cin>>n;
    
    rep(i,n-1){
        int u,v;
        cin>>u>>v;
        u--,v--;
        deg[u]++;
        deg[v]++;
        G[u].pb(v);
        G[v].pb(u);
    }
    
    dfs(0,-1);
    
    dfs2(0,-1,0);
    
    rep(i,n){
        printf("%.20lf\n",ans[i]);
    }
    
}

Measured memory_bytes: 29952
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner num = new Scanner(System.in);
        int H = 0;
        int W = 0;

        while((H = num.nextInt()) != 0 && (W = num.nextInt()) != 0){
            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 35836
#include<bits/stdc++.h>
#define il inline
#define vd void
#define mod 1000000007
typedef long long ll;
il int gi(){
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int f[310][310][310];
struct pr{int l,x;};
std::vector<pr>A[310];
il bool check(int x,int a,int b){
	for(int i=0;i<A[x].size();++i)
		if(1+(a>=A[x][i].l)+(b>=A[x][i].l)!=A[x][i].x)
			return 0;
	return 1;
}
int main(){
	int n=gi(),m=gi(),l,r,x;
	for(int i=1;i<=m;++i)l=gi(),r=gi(),x=gi(),A[r].push_back((pr){l,x});
	f[0][0][0]=1;
	for(int i=0;i<n;++i)
		for(int j=0;j<=i;++j)
			for(int k=0;k<=i;++k){
				if(check(i+1,j,k))(f[i+1][j][k]+=f[i][j][k])%=mod;
				if(check(i+1,i,k))(f[i+1][i][k]+=f[i][j][k])%=mod;
				if(check(i+1,i,j))(f[i+1][i][j]+=f[i][j][k])%=mod;
			}
	int ans=0;
	for(int i=0;i<=n;++i)
		for(int j=0;j<=n;++j)
			(ans+=f[n][i][j])%=mod;
	printf("%d\n",ans);
	return 0;
}


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

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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    rep(i, A+1) rep(j, B+1) rep(k, C+1) {
        int tmp = 500*i + 100*j + 50*k;
        if (tmp == X) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans=0;
  for (int i=0; i<N; i++) {
    int cnt=0;
    for (char c='a'; c<='z'; c++) {
      bool x=false, y=false;
      for (int j=0; j<i; j++) {
        if (S[j]==c) {
          x=true;
        }
      }
        for (int j=i; j<N; j++) {
          if (S[j]==c) {
            y=true;
          }
        }
          if (x&&y) {
            cnt++;
          }
        ans=max(ans,cnt);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
def main():
    a, b, k = [int(s) for s in input().split()]
    for i in range(k):
        if i % 2 == 0:
            if a % 2 == 1:
                a -= 1
            a = a // 2
            b += a
        else:
            if b % 2 == 1:
                b -= 1
            b = b // 2
            a += b
    print("%s %s" % (a,b))
main()

Measured memory_bytes: 3060
h, w = map(int, input().split())
ma = [list(str(input())) for _ in range(h)]
row = [0] * h
column = [0] * w 

for i in range(h):
    if ma[i] == ['.'] * w:
      row[i] = 1

j = 0
while j < w:
    count = 0
    for i in range(h):
        if ma[i][j] == '.':
            count += 1
        if count == h:
            column[j] = 1
    j += 1

for i in range(h):
    if row[i] == 1:
        for j in range(w):
            ma[i][j] = ''

for j in range(w):
    if column[j] == 1:
        for i in range(h):
            ma[i][j] = ''

for i in range(h):
    if ma[i].count('') == len(ma[i]): 
        continue
    else:
        print(''.join(ma[i]))

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


#define MOD 1000000007

using namespace std;

long long int accum[2048][2048] = {};

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> S, T;
  S.push_back(0);
  T.push_back(0);
  
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    S.push_back(tmp);
  }

  for (int i = 0; i < M; i++) {
    int tmp;
    cin >> tmp;
    T.push_back(tmp);
  }

  N++;
  M++;

  accum[0][0] = 1;

  for (int s = 1; s < N; s++) {
    accum[s][0] = 1;
  }

  for (int t = 1; t < M; t++) {
    accum[0][t] = 1;
  }


  for (int s = 1; s < N; s++) {
    for (int t = 1; t < M; t++) {
      if (S[s] == T[t]) {
        accum[s][t] = (accum[s-1][t] + accum[s][t-1]) % MOD;
      } else {
        accum[s][t] = (accum[s-1][t] + accum[s][t-1] - accum[s-1][t-1] + MOD) % MOD;
      }
    }
  }

  cout << accum[N-1][M-1] << endl;
  return 0;
}

Measured memory_bytes: 33024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d1 = sc.nextInt();
		int d2 = sc.nextInt();
		int d3 = sc.nextInt();
		int d4 = sc.nextInt();
		int d5 = sc.nextInt();
		int d6 = sc.nextInt();
		String str = sc.next();
		String[] strArray = str.split("");
		int dir = strArray.length;
		int tmp = 0;

		for(int i=0; i<dir; i++){
			if(strArray[i].equals("E")){
				tmp = d1;
				d1 = d4;
				d4 = d6;
				d6 = d3;
				d3 = tmp;
			}else if(strArray[i].equals("N")){
				tmp = d1;
				d1 = d2;
				d2 = d6;
				d6 = d5;
				d5 = tmp;
			}else if(strArray[i].equals("S")){
				tmp = d1;
				d1 = d5;
				d5 = d6;
				d6 = d2;
				d2 = tmp;
			}else if(strArray[i].equals("W")){
				tmp = d1;
				d1 = d3;
				d3 = d6;
				d6 = d4;
				d4 = tmp;
			}
		}
		System.out.println(d1);
	}
}


Measured memory_bytes: 26188
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  char x, y; cin >> x >> y;
  auto ans = x == y ? "=" : x > y ? ">" : "<";
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

def abc161e(n, k, c, s):
    num_cluster_f = 0
    start = []
    cursor = 0
    while cursor < n:
        if s[cursor] == "x":
            cursor += 1
            continue
        else:
            num_cluster_f += 1
            start.append(cursor)
            cursor += c+1

    if k < num_cluster_f:
        return []

    num_cluster_b = 0
    end = []
    cursor = n-1

    while 0 <= cursor:
        if s[cursor] == "x":
            cursor -= 1
            continue
        else:
            num_cluster_b += 1
            end.append(cursor)
            cursor -= c+1

    if k < num_cluster_b:
        return []

    ans = []
    if num_cluster_b < num_cluster_f:
        num_cluster_f = num_cluster_b
    for s, e in zip(start, end[::-1]):
        if s == e:
            ans.append(s+1)

    return ans

###
# main
if(__name__ == '__main__'):
    # input
    n, k, c = map(int, input().split(" "))
    s = input()
    
    ans = abc161e(n, k, c, s)
    
    # output
    for a in ans:
        print(a)
# else:
    # do nothing


Measured memory_bytes: 28784
def examA():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x

    def lcm(x, y):
        return x * y // gcd(x, y)
    N, M = LI()
    S = SI()
    T = SI()
    L = lcm(N,M)
    for i in range(N):
        if i*M%N!=0:
            continue
        cur = i*M//N
        #print(i,cur)
        if S[i]!=T[cur]:
            L = -1
            break
    print(L)
    return

def examB():
    class combination():
        # 素数のmod取るときのみ　速い
        def __init__(self, n, mod):
            self.n = n
            self.mod = mod
            self.fac = [1] * (n + 1)
            self.inv = [1] * (n + 1)
            for j in range(1, n + 1):
                self.fac[j] = self.fac[j - 1] * j % mod

            self.inv[n] = pow(self.fac[n], mod - 2, mod)
            for j in range(n - 1, -1, -1):
                self.inv[j] = self.inv[j + 1] * (j + 1) % mod

        def comb(self, n, r):
            if r > n or n < 0 or r < 0:
                return 0
            return self.fac[n] * self.inv[n - r] * self.inv[r] % self.mod
    N = I()
    A = LI()
    C = combination(N,mod)
    ans = 0
    cnt = 0
    for i in range(N):
        cnt += C.fac[N]*pow(i+1,mod-2,mod)
        cnt %= mod
        #print(cnt)
    #print(cnt)
    ans += cnt*A[0]
    for i in range(1,N):
        cnt = cnt + C.fac[N]*pow(i+1,mod-2,mod) - C.fac[N]*pow(N-i+1,mod-2,mod)
        cnt += mod
        cnt %= mod
        a = A[i]
        ans += cnt*a
        ans %= mod
        #print(cnt)
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

using namespace std;

int main() {
  double base,altura;
  cin>>base>>altura;
  double cx,cy;
  cin>>cx>>cy;
  cout<<fixed;
  cout<<setprecision(10);
  cout<<(base*altura)/2<<" ";
  if(cx==base/2&&cy==altura/2){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint a(n);
  int max=0;
  vint count(n+1,0);
  rep(i,n){
    cin>>a[i];
    count[a[i]]++;
  }
  ll copy;
  ll ans=0;
  rep(i,n+1){
    copy=count[i];
    while(copy!=0){
      copy--;
      ans+=copy;
    }
  }
  REP(i,1,n+1){
    copy=ans;
    if(count[a[i-1]]<1){
    }
    else{
      copy-=(count[a[i-1]]-1);
    }
    cout<<copy<<'\n';
  }
  return(0);
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

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

	vector<ll> points(N, K-Q);
	rep(i, Q) {
		points[A[i]-1]++;
	}

	rep(i, N) {
		if(points[i]>0) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second 
using namespace std;
const LL INF = (LL) 1e9 + 5;
const LL MOD = (LL) 1e9 + 7;
const int MAXN = 200005;

vector<int> lps; // longest prefix suffix, 0-based
vector<int> match(const vector<int> &text, const vector<int> &pat) {
	/* Find all match */
	lps.resize(pat.size());	
	/* DP */
	lps[0]=0;
	for (int i=1; i<pat.size(); i++) {
		int len=lps[i - 1];
		while(len>0 && pat[len]!=pat[i]) len=lps[len - 1];
		lps[i] = pat[len]==pat[i] ? len+1 : 0;
	}	
	/* Match */
	int i = 0, j = 0;
	vector<int> occ;
	while (i < text.size()) {
		if (text[i] == pat[j]) {
			i++;
			j++;
			if (j == pat.size()) {
				// Find one pattern at text[i-j...i)
				occ.push_back(i - j);
				j = lps[j - 1];
			}
		}
		else if (j == 0) i++;
		else j = lps[j - 1];
	}
	return occ;
}

int n, a[MAXN], b[MAXN];
vector<int> text, pat;

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

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 2 * (n - 1); i++) {
		text.push_back(a[i % n] ^ a[(i + 1) % n]);
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		if (i) {
			pat.push_back(b[i] ^ b[i - 1]);
		}
	}
	
	vector<int> occ = match(text, pat);
	for (int pos : occ) {
		cout << pos << " " << (a[pos] ^ b[0]) << '\n'; 
	}

	return 0;
}

Measured memory_bytes: 10096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int h, w;
char maze[401][401] = {};
bool reached[401][401] = {};
ll black = 0, white = 0;

void dfs(int x, int y, char last_color) {
    if (x < 0 || h <= x || y < 0 || w <= y) return;
    if (reached[x][y]) return;
    if (maze[x][y] == last_color) return;

    reached[x][y] = true;
    if (maze[x][y] == '#') black++;
    else white++;
    last_color = maze[x][y];
    dfs(x + 1, y, last_color);
    dfs(x - 1, y, last_color);
    dfs(x, y + 1, last_color);
    dfs(x, y - 1, last_color);
}

int main() {
    cin >> h >> w;
    rep(i, 0, h) {
        rep(j, 0, w) {
            cin >> maze[i][j];
        }
    }

    ll ans = 0;
    rep(i, 0, h) {
        rep(j, 0, w) {
            if (maze[i][j] == '#') {
                char last_color = '.';
                dfs(i, j, last_color);
                ans += black * white;
                black = 0;
                white = 0;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n, k;
vv<pii> ab;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    ll cnt = 0;
    cin >> n >> k;
    rep(i, 0, n) {
      int a, b;
      cin >> a >> b;
      ab.pb(mp(a, b));
    }
    sort(ALL(ab));
    rep(i, 0, n) {
      cnt += ab[i].second;
      if (cnt >= k) {
        cout << ab[i].first << endl;
        return 0;
      }
    }
    return 0;
}



Measured memory_bytes: 1400
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto S = '0' ~ readln.chomp;
    auto N = S.length.to!int - 1;

    if (S.back == '1') {
        writeln(-1);
        return;
    }
    if (S[1] == '0') {
        writeln(-1);
        return;
    }

    bool line = true;
    foreach (i; 1..N) if (S[i] == '0') line = false;
    if (line) {
        foreach (i; 0..N-1) {
            writeln(i+1, " ", i+2);
        }
        return;
    }

    int[][] ans;
    ans ~= [0, 1];
    int cur = 1;
    int cnt = 1;

    foreach (i; 1..N) {
        if (S[i] != S[N-i]) {
            writeln(-1);
            return;
        }
        if (i == 1) {
            continue;
        }
        if (S[i] == '1') {
            ans ~= [cur, ++cnt];
            cur = cnt;
        } else {
            ans ~= [cur, ++cnt];
        }
    }

    foreach (i; 0..N-1) {
        writeln(ans[i][0] + 1, " ", ans[i][1] + 1);
    }
}


Measured memory_bytes: 8344
import java.util.Scanner;

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

        String s = stdIn.next();
        char[] cs = s.toCharArray();

        if(cs[2] == cs[3] && cs[4] == cs[5]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23252
#include<cstdio>


int main(void)
{
	int a, b, c;

	while(scanf("%d%d%d", &a, &b, &c)==3)
	{
		int ans=((a==b)&&(b==c));
		printf("%s\n", ans?"Yes":"No");
	}

	return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

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

	void run() {
		solver();
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int[] B = Arrays.copyOf(A, A.length);
		Arrays.sort(B);
		long ans = 0;
		for (int i = 0; i < N; i++) {
			int idx = Arrays.binarySearch(B, A[i]);
			if (Math.abs(idx - i) % 2 == 1)
				ans++;
		}
		System.out.println(ans / 2);

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 23876
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int n = s.length();
        long ans = 0;

        for(int b=0; b<(1<<n-1); b++) {
            long tmp = 0;
            for(int i=0; i<n; i++) {
                tmp *= 10;
                tmp += s.charAt(i) - '0';
                if((b >> i & 1) == 0) {
                    ans += tmp;
                    tmp = 0;
                }
            }
            ans += tmp;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35692
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a,b,c,d ; cin >> a >> b >> c >> d;
	int m = max(a,c);
	int M = min(b,d);
	cout << max(0, M - m) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  string s;
  getline(cin,s);
  rep(i,s.size()){
    if(s[i]>='a'&&'z'>=s[i])cout<<(char)(s[i]-'a'+'A');
    else cout<<s[i];
  }
  cout<<endl;
}

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

int main() {
	int N, M; 
	cin >> N >> M;

	vector<vector<int> > vec(M);

	for (int i = 0; i < M; ++i) {
		int k; 
		cin >> k;
		vec[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> vec[i][j];
			--vec[i][j];
		}
	}

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

	int ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id=0;id<vec[j].size();id++) {
				if ((i >> vec[j][id]) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++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 repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

vll primes;

void generate_lunlun(string s) {
    if (primes.size() >= 2e6 || s.size() == 100) return;
    if (s[0] != '0') primes.push_back(stoll(s));

    ll num = s[0] - '0';
    if (num > 0) generate_lunlun(to_string(num - 1) + s);
    generate_lunlun(to_string(num) + s);
    if (num < 9) generate_lunlun(to_string(num + 1) + s);
}

int main()
{
    queue<string> q;
    ll k; cin >> k; k--;
    rep(i, 10) q.push(to_string(i));

    while (q.size()) {
        if (primes.size() > 2e6) break;
        string s = q.front(); q.pop();
        if (s[0] != '0') primes.push_back(stoll(s));

        ll num = s[0] - '0';
        if (num > 0) q.push(to_string(num - 1) + s);
        q.push(to_string(num) + s);
        if (num < 9) q.push(to_string(num + 1) + s);
    }

    sort(all(primes));
    cout << primes[k] << endl;
    return 0;
}

Measured memory_bytes: 238820
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = []
    n_best = 0
    best = 0
    best2 = 0
    for i in range(n):
        a = ri()
        la.append(a)
        if best < a:
            best2 = best
            best = a
            n_best = 1
        elif best == a:
            n_best += 1
        else:
            best2 = max(best2, a)
    for a in la:
        if a < best:
            print(best)
        else:
            if n_best > 1:
                print(best)
            else:
                print(best2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12512