akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<tuple>
#include<vector>
#include<algorithm>
#include<iterator>
#include<cmath>
#include<functional>
#include<map>
using namespace std;

int main(){
    int N;
    cin >> N;
    map<int, int>  o, e;
    for(int i=0; i<N/2; i++){
        int ot, et;
        cin >> ot;
        cin >> et;
        o[ot]++;
        e[et]++;
    }
    int r = N;
    int ei = 0;
    int oi = 0;
    int so = 0;
    int se = 0;
    int me = 0;
    int mo = 0;
    for (auto it = o.begin(); it != o.end(); it++){
        if(mo < it->second){
            so = mo;
            mo = it->second;
            oi = it->first;
        }else if(so < it -> second){
            so = it->second;
        }
    }
    for (auto it = e.begin(); it != e.end(); it++){
        if(me < it->second){
            se = me;
            me = it->second;
            ei = it->first;
        }else if(so < it -> second){
            se = it->second;
        }
    }
    if(ei == oi){
        if (so == 0 && se == 0){
            r -= N/2;
        }else if(so > se){
            r -= so + me;
        }else{
            r -= se + mo;
        }
    }else{
        r -= me + mo;
    }
    cout << r << endl;
}



Measured memory_bytes: 8292
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn pw5(x: i64) -> i64 {
    x * x * x * x * x
}

fn func(a: i64, b: i64) -> i64 {
    a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b + b * b * b * b
}

fn main() {
    let x = read::<i64>();
    let mut max_i = 0;
    for i in 1.. {
        if pw5(i) > x {
            max_i = i - 1;
            break;
        }
    }

    for a in 0..max_i + 1 {
        for b in a..max_i + 1 {
            if pw5(a) + pw5(b) == x {
                println!("{} {}", a, -b);
                return;
            }
        }
    }

    /*
    let mut pairs = vec![];
    for i in 1.. {
        if i * i > x {
            break;
        }
        if x % i == 0 {
            pairs.push((i, x / i));
            pairs.push((x / i, i));
        }
    }
    */

    // debug!(pairs);
    for a in 0..1001 {
        for b in 0..a + 1 {
            if pw5(a) - pw5(b) == x {
                println!("{} {}", a, b);
                return;
            }
        }
    }
    /*
    let crite
    for (a_m_b, val) in pairs {
        let (ok, ng) = binary_search(0, 1000, criterion);
        /*
        for a in 0..x + 1 {
            if pw5(a) > 1000000000000000 {
                break;
            }
            let b = a - a_m_b;
            if b < 0 {
                continue;
            }
            if func(a, b) == val {
                println!("{} {}", a, b);
                return;
            }
            if pw5(a) - pw5(b) == x {
                println!("{} {}", a, b);
                return;
            }
        }
        */
    }
    */
}

fn binary_search<F>(lb: usize, ub: usize, criterion: F) -> (usize, usize)
where
    F: Fn(usize) -> bool,
{
    let mut ok = lb;
    let mut ng = ub;
    while ng - ok > 1 {
        let mid = (ng + ok) / 2;
        if criterion(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    (ok, ng)
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2140
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val ans = new Array[String](2*N+1)


  //
  val red = "Red"
  val blue = "Blue"

  def rev(color: String): String = {
    if (color == red)
      blue
    else
      red
  }

  def query(q: Seq[Int]): Unit = {
    println("? " + q.mkString(" "))
  }

  def input(): String = {
    val res = in.next()
    if (res == "-1")
      throw new RuntimeException()

    res
  }

  //
  query((1 to N).toArray)
  val left = input()


  //
  def check(i: Int): Boolean = {
    query((i-(N-1) to i).toArray)
    val res = input()

    res == rev(left)
  }

  // 条件を満たす最小の値を返す
  def binarySearch(min: Int, max: Int): Int = {
    val mid: Int = (max + min) / 2
      (max - min) match{
      case 0 | 1 =>
        check(min) match{
          case true  => min
          case false => max
        }
      case _ =>
        (check(mid)) match{
          case true  => binarySearch(min, mid)
          case false => binarySearch(mid, max)
        }
    }

  }


  //
  val r = binarySearch(N+1, 2*N)

  ans(r-N) = left
  ans(r) = rev(left)

  for (i <- 1 until r-N) {
    query(i +: ((r-N)+1 to r-1).toSeq)
    ans(i) = input()
  }
  for (i <- r+1 to 2*N) {
    query(i +: ((r-N)+1 to r-1).toList)
    ans(i) = input()
  }

  val hoge = (1 to (r-N)-1) ++ (r+1 to 2*N)
  for (i <- (r-N)+1 to r-1) {
    query(i +: hoge)
    ans(i) = input()
  }


  def format(color: String): String = {
    if (color == red) "R"
    else "B"
  }
  println("! " + ans.drop(1).map(format).mkString)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 31448
#include <iostream>
using namespace std;
typedef long long int ll;
const ll MOD = 1e9 + 7;


int main()
{
	int n; cin>>n; int sum=0;
	for(int i=0;i<n;i++){
		int x; cin>>x;
		sum += (x-1);
	}

	cout<<sum;
}

Measured memory_bytes: 256
def adjmatrices():
    n = int(input())
    for i in range(n):
        node_list = list(map(int, input().split()))
        matrix = [0]*n
        for j in node_list[2:]:
            matrix[j-1] = 1
        print(*matrix)

if __name__ == '__main__':
    adjmatrices()

Measured memory_bytes: 7644
#!/usr/bin/env python3
import sys


def solve(T: int, X: int):
    ret = T / X
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(T, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[109][109];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - 1; j++) {
			a[i][j] = (i + j + 1) % n + 1;
		}
	}
	if (n == 2) cout << -1 << endl;
	else {
		if (n % 2 == 0) {
			for (int i = 0; i < n / 2; i++) swap(a[i][0], a[i][n / 2 - 1]);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - 1; j++) {
				if (j) cout << ' ';
				cout << a[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

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

  long long sum = 0;

  for (int i = 1; i <= n; i++) {
    if (!(i % 3 == 0 || i % 5 == 0)) sum += i;
  }
  cout << sum;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 1), B(N);
    for (int i = 0; i <= N; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> B[i];
    }
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (A[i] <= B[i])
        {
            B[i] -= A[i];
            ans += A[i];
            A[i] = 0;
            if (A[i + 1] <= B[i])
            {
                ans += A[i + 1];
                A[i + 1] = 0;
            }
            else
            {
                A[i + 1] -= B[i];
                ans += B[i];
            }
        }
        else
        {
            A[i] -= B[i];
            ans += B[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
// const int MOD = 1000000007;
int M = 300010;
/*----------------------------------------------------------------*/
signed main(){

	int h,w,m;
	cin >> h >> w >> m;
	vector<pair<int,int>> H(M);
	vector<pair<int,int>> W(M);
	rep(i,M){
		H[i] = MP(0,i);
		W[i] = MP(0,i);
	}
	set<pair<int,int>> s;
	rep(i,m){
		int x,y;
		cin >> x >> y;
		x--;y--;
		H[x].first++;
		W[y].first++;
		s.insert(MP(x,y));
	}

	if(m <= 2){
		cout << m << endl;
		return 0;
	}

	sort(H.begin(),H.end(),greater<pair<int,int>>());
	sort(W.begin(),W.end(),greater<pair<int,int>>());

	
	int hmax = H[0].first;
	int wmax = W[0].first;
	int mch = 0;
	int mcw = 0;

	rep(i,300010){
		if(H[i].first == hmax)mch++;
		else break;
	}rep(i,300010){
		if(W[i].first == wmax)mcw++;
		else break;
	}

	cerr << hmax << endl;
	cerr << wmax << endl;
	cerr << mch << endl;
	cerr << mcw << endl;

	if(mch*mcw > m){
		cout << hmax+wmax << endl;
		return 0;
	}

	rep(i,mch){
		rep(j,mcw){
			int x = H[i].se;
			int y = W[j].se;
			if(s.find(MP(x,y)) == s.end()){
				cout << hmax+wmax << endl;
				return 0;
			}
		}
	}

	cout << hmax+wmax-1 << endl;



	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://abc174.contest.atcoder.jp/tasks/abc174_b
// rm -r -f test;oj d https://atcoder.jp/contests/abc176/tasks/abc176_a

Measured memory_bytes: 31488
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
a = reads()

def p2(x):
  res = 0
  while x & 1 == 0:
    x = x >> 1
    res += 1
  return res

ans = sum(p2(x) for x in a)
print(ans)

Measured memory_bytes: 4900
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX=1e6;
int dp[MAX];

signed main()
{
	int n;
	cin >> n;
	dp[0]=0;
	for (int i=1;i<=n;i++){
		dp[i]=(dp[i-1]*10+7)%n;
		if (dp[i]==0) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
	
}

Measured memory_bytes: 11404
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> a(n+1);
  vector<int> cou(n+1);
  for(int i=1;i<=n;i++)
  {
    cin>>a.at(i);
    cou.at(i)=0;
  }

  int cnt=0; //全体はcnt回だけ/2できる
  for(int i=1;i<=n;i++)
  {
    while(a.at(i)%2==0)
    {
      a.at(i)=a.at(i)/2;
      cnt++;
      cou.at(i)++;
    }
  }

  cout<<cnt<<endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String ans = "";

    for (int i = 0; i < 3; i++) {
      String s = sc.next();
      ans += s.charAt(i);
    }

    System.out.println(ans);

  }
}

Measured memory_bytes: 39096
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N;
  cin >> N;
  vector<int> b(N);
  REP(i, N) {
    cin >> b[i];
    b[i]--;
  }
  vector<int> ans;
  REP(i, N) {
    int idx = -1;
    REP(j, b.size()) {
      if (b[j] == j) idx = j;
    }
    if (idx < 0) {
      cout << -1 << endl;
      return 0;
    }
    ans.PB(idx + 1);
    b.erase(b.begin() + idx);
  }
  reverse(ALL(ans));
  REP(i, N) cout << ans[i] << endl;
  return 0;
}

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORR(i,a,b) for(ll i=b-1;i>=a;i--)

#define vl vector<ll>
#define pll pair<ll,ll>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
/*}}}*/

int main() {
  ll n;
  cin >> n;
  vl inp(n);
  REP(i,n) cin >> inp[i];
  sort(inp.begin(),inp.end());
  vl a;
  set<ll> dup;
  REP(i,inp.size()){
    if(i!=0 && inp[i]==inp[i-1]) {
      dup.insert(inp[i]);
      continue;
    }
    a.push_back(inp[i]);
  }
  //ll ans = -1 * dup.size();
  ll ans = 0;
  //for (auto itr = dup.begin(); itr != dup.end(); itr++){
  //  cout << *itr << endl;
  //}
  vector<bool> isDivisible(1e6+1,false);
  REP(i,a.size()){
    if(isDivisible[a[i]]) continue;
    for(ll j = a[i]; j<=1e6; j+=a[i]){
      isDivisible[j] = true;
    }
    if(dup.find(a[i])==dup.end()) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7260
A,B,C,X,Y = map(int,input().split())
addition = 0
if X > Y:
    addition = A
elif X < Y:
    addition = B
    
print(min(A*X + B*Y, 2*C*min(X,Y) + abs(X-Y)*addition, 2*C*max(X,Y)))

Measured memory_bytes: 3060
#include <cstdio>
#include <cctype>
#include <utility>
#include <unordered_map>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int n;
	unordered_map<string,int> m;
	while (scan(n)) {
		string b;
		scan(b);
		++m[b];
	}
	for (auto b: {"A", "B", "AB", "O"})
		out(m[b], '\n');
}


Measured memory_bytes: 2544
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {

	static int ans[];

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

		int n = Integer.parseInt(br.readLine());
		ans = new int[n];

		ArrayList<ArrayList<Edge>> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}

		for (int i = 0; i < n - 1; i++) {
			String str[] = br.readLine().split(" ");
			int u = Integer.parseInt(str[0]) - 1;
			int v = Integer.parseInt(str[1]) - 1;
			int w = Integer.parseInt(str[2]);

			list.get(u).add(new Edge(v, w));
			list.get(v).add(new Edge(u, w));
		}

		dfs(0, -1, 0, list);
		for (int i = 0; i < n; i++) {
			System.out.println(ans[i]);
		}
	}

	static void dfs(int v, int parent, int color, ArrayList<ArrayList<Edge>> edge) {
		ans[v] = color;

		for (Edge e : edge.get(v)) {
			if (e.to == parent)
				continue;
			if (e.cost % 2 == 0) {
				dfs(e.to, v, color, edge);
			} else {
				dfs(e.to, v, 1 - color, edge);
			}
		}
	}
}

class Edge implements Comparable<Edge> {
	int to;
	int cost;

	public Edge(int to, int cost) {
		this.to = to;
		this.cost = cost;
	}

	@Override
	public int compareTo(Edge e) {
		return this.cost - e.cost;
	}
}

Measured memory_bytes: 81428
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
int main(void)
{
	string s; cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>

using namespace std;

int main(void)
{
    int index;
    string s, t;
    cin >> s >> t;

    map<char, char> mp;

    for (int i = 0; i < s.length(); i++)
    {
        char from = s[i];
        char to = t[i];
        if (mp.count(from) > 0)
        {
            if (mp[from] != to)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            for (auto j : mp)
            {
                if (to == j.second)
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
            mp[from] = to;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
def main():
    import sys
    
    K = int(sys.stdin.readline())
    
    lunlun_list = [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
    
    if K <= 9:
        ans = lunlun_list[0][K - 1]
    else:
        count = 9
        n = 0
        while count < K:
            add_list = []
            for m in lunlun_list[n]:
                if m % 10 == 0:
                    m_1 = m * 10
                    add_list.append(m_1)
                    count += 1
                    if count == K:
                        ans = m_1
                        break
                    m_2 = m * 10 + 1
                    add_list.append(m_2)
                    count += 1
                    if count == K:
                        ans = m_2
                        break
                elif m % 10 == 9:
                    m_1 = m * 10 + 8
                    add_list.append(m_1)
                    count += 1
                    if count == K:
                        ans = m_1
                        break
                    m_2 = m * 10 + 9
                    add_list.append(m_2)
                    count += 1
                    if count == K:
                        ans = m_2
                        break
                else:
                    l = m % 10
                    m_1 = m * 10 + l - 1
                    add_list.append(m_1)
                    count += 1
                    if count == K:
                        ans = m_1
                        break
                    m_2 = m * 10 + l
                    add_list.append(m_2)
                    count += 1
                    if count == K:
                        ans = m_2
                        break
                    m_3 = m * 10 + l + 1
                    add_list.append(m_3)
                    count += 1
                    if count == K:
                        ans = m_3
                        break
            lunlun_list.append(add_list)
            n += 1
            
    print(ans)
                    
    
if __name__ == '__main__':
    main()
        

Measured memory_bytes: 7224
def main(n):
	a = list(map(int, input().split()))
	for i in range(n):
		v = a[i]
		j = i-1
		while j >= 0 and a[j] > v:
			a[j+1] = a[j]
			j -= 1
		a[j+1] = v
		print(" ".join(map(str,a)))
	return

main(int(input()))


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string a,b;
ll dp[3009][3009];

ll lcs(ll ai,ll bi){
    if(dp[ai][bi]!=-1) return dp[ai][bi];
    else if(ai>=a.size()||bi>=b.size()) return 0;
    else if(a[ai]==b[bi]){
        dp[ai][bi]=1+lcs(ai+1,bi+1);
        return dp[ai][bi];
    }
    else{
        dp[ai][bi]=max(lcs(ai+1,bi),lcs(ai,bi+1));
        return dp[ai][bi];
    }
}

void printlcs(ll ai,ll bi){
    if(ai>=a.size()||bi>=b.size()){
        cout<<endl;
        return ;
    }
    else if(a[ai]==b[bi]){
        cout<<a[ai];
        printlcs(ai+1,bi+1);
    }
    else{
        if(dp[ai+1][bi]>dp[ai][bi+1]){
            printlcs(ai+1,bi);
        }
        else{
            printlcs(ai,bi+1);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //ll t;
    //cin>>t;
    //while(t--){
        memset(dp,-1,sizeof(dp));
        cin>>a>>b;
        ll x=lcs(0,0);
        printlcs(0,0);
    //}
    return 0;
}


Measured memory_bytes: 71296
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   1000000000
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}



//=============================================ASIFAZAD==============================================//

const int N = 200010;
vi inp(N);
int n, k;

bool ok(ll mid)
{
    ll an = 0;
    for(int i = 0;i < n;i++)
        an += (inp[i] - 1)/mid;
    return an <= k;
}



int32_t main()
{
    io;
    int n, k;
    cin>>n>>k;
    vi a(n);
    for(int i= 0;i < n;i++)
        cin >>a[i];

    ll l = 1, h = 1000000000, mid, ans;
    while(l <= h)
    {
        mid = (l + h)/2;
        ll s = 0;
        for(int i = 0; i< n;i++)
            s += ceil(a[i]*1.0/mid) - 1;
        if(s <= k)
        {
            ans = mid;
            h = mid - 1;
        }
        else
            l = mid + 1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
int A,B,C,D,E,F;
int b1,b2,ok=0;
bool check (int i,int j){
    return(j*(b1+b2)>b1*(i+j));
}
bool have1(int s){
    if(s==0)
        return 1;
    for(int i=0;i<=s;i+=C){
        if((s-i)%D==0){
            return 1;
        }
    }
    return 0;
}
bool have2(int s){
    for(int i=0;i<=s;i+=A){
        if((s-i)%B==0)
            return 1;
    }
    return 0;
}
int main()
{
    cin>>A>>B>>C>>D>>E>>F;
    A*=100;
    B*=100;
    for(int i=100;i<=F;i+=100){
        if(have2(i)){
            for(int j=0;j<=(i/100)*E;j++){
                if(have1(j) && (i+j)<=F){
                    if(!ok){
                        ok=1;
                        b1=j;
                        b2=i;
                    }
                    else{
                        if(check(i,j)){
                       //     printf("%d aa %d\n",i,j);
                            b1=j;
                            b2=i;
                        }
                    }
                }
            }
        }
    }
    cout<<b1+b2<<" "<<b1;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max()/4 ;
const ll linf = numeric_limits<ll>::max()/4 ;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	int r,g;
	
    cin >> r >> g;

    P(2*g - r);
	return  0;
}

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

using Int = long long;
using ll = long long;

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}

int dp[52][52][1010];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int h,w;
  while(cin>>h>>w,h||w){
    vector<string> vs(h);
    for(int i=0;i<h;i++) cin>>vs[i];
    string st;
    cin>>st;

    memset(dp,-1,sizeof(dp));
    using T = tuple<int, int, int>;
    queue<T> que;
    dp[0][0][0]=0;
    que.emplace(0,0,0);

    int dy[]={0,0,1,-1};
    int dx[]={1,-1,0,0};
    auto in=[&](int y,int x){return 0<=y&&y<h&&0<=x&&x<w;};

    while(!que.empty()){
      T cur=que.front();que.pop();
      int y,x,p;
      tie(y,x,p)=cur;

      if(vs[y][x]==st[p]){
        int ny=y,nx=x,np=p+1;
        if(!in(ny,nx)) continue;
        if(~dp[ny][nx][np]) continue;
        dp[ny][nx][np]=dp[y][x][p]+1;
        if(np==(int)st.size()){
          cout<<dp[ny][nx][np]<<endl;
          break;
        }
        que.emplace(ny,nx,np);
      }

      for(int k=0;k<4;k++){
        int ny=y+dy[k],nx=x+dx[k],np=p;
        if(!in(ny,nx)) continue;
        if(~dp[ny][nx][np]) continue;
        dp[ny][nx][np]=dp[y][x][p]+1;
        que.emplace(ny,nx,np);
      }
    }
  }

  return 0;
}



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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a) {  // 10000円の枚数を 0 〜 N で調べる
        for (int b = 0; b + a <= N; ++b) {  // 5000円の枚数を 0 〜 N-a で調べる
            int c = N - a - b;  // 1000円の枚数は決まる
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {  // 答えが見つかったら
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }

    // 答えを出力 (見つかっていなくても -1 -1 -1 になるので OK です)
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

Measured memory_bytes: 3644
function main()
	n,m = parse.(split(readline()))
	x = zeros(Int, n)
	for i in 1:m
		a = parse.(split(readline()))
		x[a[1]] += 1
		x[a[2]] += 1
	end
	for i in 1:n
		println(x[i])
	end
end

main()

Measured memory_bytes: 122280
S = input()
mod = 10 ** 9 + 7
N = len(S)
table = [[0] * 13 for _ in range(N + 1)]
table[0][0] = 1

dd = 1

for i, char in enumerate(reversed(S)):
    c = char != '?'
    for j in range(13):
        for k in range(10):
            if c and int(char) != k:
                continue
            table[i+1][(j + dd * k)  % 13] += table[i][j]
            table[i+1][(j + dd * k)  % 13] %= mod
    dd = (dd * 10) % 13

print(table[N][5])


Measured memory_bytes: 61916
h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for _ in range(m)]
numh=[[i,0] for i in range(h)]
numw=[[i,0] for i in range(w)]
d=set(())
for hi,wi in hw:
  numh[hi-1][1]+=1
  numw[wi-1][1]+=1
  d.add((hi-1,wi-1))
numh.sort(key=lambda x:x[1])
numw.sort(key=lambda x:x[1])
ansh=numh[-1][1]
answ=numw[-1][1]
if ansh+answ==1:
  print(1)
  exit()
# 答えはansh+answまたはansh+answ-1
hk=set(())
while numh and numh[-1][1]==ansh:
  hk.add(numh.pop()[0])
wk=set(())
while numw and numw[-1][1]==answ:
  wk.add(numw.pop()[0])

for wi in wk:
  for hi in hk:
    if (hi,wi) not in d:
      print(ansh+answ)
      exit()
print(ansh+answ-1)

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    char x = 'a';
    while(1) {
        if (x == 'a') {
            if (a.size() == 0) {
                cout << "A" << endl;
                return 0;
            }
            x = a[0];
            a.erase(a.begin());
        } else if (x == 'b') {
            if (b.size() == 0) {
                cout << "B" << endl;
                return 0;
            }
            x = b[0];
            b.erase(b.begin());
        } else {
            if (c.size() == 0) {
                cout << "C" << endl;
                return 0;
            }
            x = c[0];
            c.erase(c.begin());
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

__int128 read_int128() {
  string s; cin >> s;
  __int128 res = 0;
  for(char c : s) {
    res = res * 10 + int(c - '0');
  }
  return res;
}

//ミョ(-ω- ?)
int main() {
    auto n = read_int128();
    vector<__int128> a(n,0);
    bool b = false;
    rep(i,n){
      a[i] = read_int128();
      if(a[i] == 0)b = true;
    }
    sort(a.begin(),a.end());
    if(b){
        cout << 0 << endl;
    }else{
        __int128 pro = 1;
        for(auto i : a){
            pro *= i;
            if(pro > 1000000000000000000){
                cout << -1 << endl;
                return 0;
            }
        }
        cout << (long long)pro << endl;
    }
    return 0;
}


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

bool check(string S){
  int N = S.size();
  bool flg = true;
  for(int i = 0; i < N/2; i++){
    flg = flg && (S[i] == S[N-i-1]);
  }
  return flg;
}

typedef long long ll;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  string s1 = S.substr(0, (N-1)/2 );
  string s2 = S.substr( (N+3)/2 -1, (N-3)/2+1);
  
  cerr << check("aka") << endl;
  cerr << check("akak") << endl;
  cerr << check("akka") << endl;
  cerr << S << " " << s1 << " " << s2 << endl;
  
  if(check(S) && check(s1) && check(s2) ){
    cout << "Yes" << endl;
  } else { 
    cout << "No" << endl;
  }
}

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

int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> v(n);
  cin >> v.at(0);
  int a = 0, b = 0;
  for(int i = 1; i < n; i++){
    cin >> v.at(i);
    if(v.at(i) > v.at(i-1)){
      a = max(a, b);
      b = 0;
    }
    else b++;
    if(i == n - 1)
      a = max(a, b);
  }
  cout << a << endl;
}


Measured memory_bytes: 1024
N = int(input())

t_prev=0
x_prev=0
y_prev=0

for i in range(N):
    t_i, x_i, y_i = map(int, input().split()) 

    if (x_i+y_i)> t_i:
        print("No")
        exit()
    elif (x_i+y_i) %2 != t_i%2 :
        print("No")
        exit()
    elif x_i-x_prev > t_i-t_prev or y_i-y_prev>t_i-t_prev:
        print('No')
        exit()

    t_prev=t_i
    x_prev=x_i
    y_prev=y_i

print("Yes")
    

Measured memory_bytes: 3060
n, m = map(int, input().split())
a = list(map(int, input().split()))
num = sum(a)
cnt = 0
for i in a:
    if i < num /(4 * m):
        continue
    else:
        cnt += 1

# print(n, m, a, num, cnt)
if cnt < m:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, A, B, C, ans = 1000000007;
    cin >> N >> A >> B >> C;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L.at(i);
    }
    int W = pow(4,N);
    for (int i = 0; i < W; i++) {
        vector<int> Al, Bl, Cl;
        int asum = 0, bsum = 0, csum = 0, MP = 0, Z = i;
        for (int j = 0; j < N; j++) {
            int a = Z % 4;
            if (a == 1) {
                Al.push_back(L.at(j));
            }
            else if (a == 2) {
                Bl.push_back(L.at(j));
            }
            else if (a == 3) {
                Cl.push_back(L.at(j));
            }
            Z /= 4;
        }
        if (Al.size() == 0 || Bl.size() == 0 || Cl.size() == 0) {
            continue;
        }
        for (int j = 0; j < Al.size(); j++) {
            asum += Al.at(j);
        }
        for (int j = 0; j < Bl.size(); j++) {
            bsum += Bl.at(j);
        }
        for (int j = 0; j < Cl.size(); j++) {
            csum += Cl.at(j);
        }
        MP += (Al.size() + Bl.size() + Cl.size() - 3) * 10;
        MP += abs(A - asum) + abs(B - bsum) + abs(C - csum);
        ans = min(ans, MP);
    }
    cout << ans << endl;
}


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

ll mod=1e9+7;
vector<vector<int> > adjl(maxn);
int vis[maxn];

void dfs(int n,int &ans){
    vis[n]=1;
    ans++;
    for(auto x: adjl[n]){
        if(!vis[x])
            dfs(x,ans);
    }
}
int main(){
    memset(vis,0,sizeof(vis));
int n,m;
cin>>n>>m;
map<int,map<int,int> > mp;
for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    if(mp[a][b]==1 || mp[b][a]==1)
        continue;
    adjl[a].push_back(b);
    adjl[b].push_back(a);
    mp[a][b]=1;
    mp[b][a]=1;
}

int ans=0;
for(int i=1;i<=n;i++){
    if(!vis[i]){
        int tans=0;
        dfs(i,tans);
    ans=max(ans,tans);
    }
}

cout<<ans<<endl;
}


Measured memory_bytes: 64380
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <bitset>
const int N = 100005;
using namespace std;
typedef long long ll;
int a[N];
int n;
bitset<4000010> f;
int main()
{
    int i,j,k=0;
    scanf("%d",&n);
    f[0]=1;
    for(i=1;i<=n;i++)
      {
       scanf("%d",&j);
       f=f|(f<<j);
       k+=j;
      }
    for(i=(k+1)/2;!f[i];i++);
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int main() {
    int n;
    int t, a;
    vi h;

    cin >> n;
    cin >> t >> a;
    h.resize(n);

    rep(i, n) {
        double in;
        cin >> in;
        h[i] = abs(1000*a - (1000*t - in * 6));
    };
    int ans = 0;
    int mn = h[0];
    rep(i, n){
        if (mn > h[i]) {
            ans = i;
            mn = h[i];
        }
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int N;
//隣接リスト
//目的地コスト
void dijk(int s, vector<vector<pair<ll, ll>>> &E, vector<ll> &D) {
    // E (destination, cost)
    int vis[101010];
    for(int i = 0; i < N; i++) {
        D[i] = INF;
        vis[i] = 0;
    }

    min_priority_queue<pair<long long, ll>> que;

    D[s] = 0;
    que.push({0, s});

    while(!que.empty()) {
        auto q = que.top();
        que.pop();

        auto cst = q.first;
        auto cu = q.second;

        if(vis[cu]) {
            continue;
        } else {
            vis[cu] = 1;
        }
        for(auto p : E[cu]) {
            long long cst2 = cst + p.second;
            ll to = p.first;

            if(D[to] > cst2) {
                D[to] = cst2;
                que.push({D[to], to});
            }
        }
    }
}

int main() {
    int M;
    cin >> N >> M;
    vector<ll> L(M), R(M), C(M);
    REP(i, M) {
        cin >> L[i] >> R[i] >> C[i];
        L[i]--;
        R[i]--;
    }
    //最短路の長さは単調増加列である
    //有向辺として頂点i+1からiへ長さゼロの辺を追加しても変化しない
    // LiからRiへの長さCiの辺を追加する
    // N+M-1本の有効辺があれば大丈夫
    vector<vector<pair<ll, ll>>> edge(N);
    REP(i, N - 1) { edge[i + 1].push_back(make_pair(i, 0)); }
    REP(i, M) {
        edge[L[i]].push_back(make_pair(R[i], C[i]));
        edge[R[i]].push_back(make_pair(L[i], C[i]));
    }
    vector<ll> dist(N, INF);
    dijk(0, edge, dist);
    if(dist[N - 1] != INF) {
        cout << dist[N - 1] << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 15736
#include <string.h>
#include <stdio.h>
#define MAXN 18

int main(void)
{

	char num[MAXN];
	int i,N,k,index,max,flag9;
	scanf("%s",num);
		
	flag9=1;
	N=strlen(num);
	for(i=1;i<N;i++)
		if(num[i]!='9'){
			flag9=0;
			break;
		}
	if(flag9)
		k=9*(N-1)+num[0]-'0';
	else
		k=9*(N-1)+num[0]-'0'-1;
	printf("%d\n",k);



	
	return 0;

}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] num = new long[100010];
		for(int i = 0 ; i < n ; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			num[a] += b;
		}
		for(int i = 0 ; i < 100010 ; i++) {
			if(k <= num[i]) {
				System.out.println(i);
				return;
			} else {
				k -= num[i];
			}
		}
	}
}


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

const int N = 100100;

int a[N], b[N];
int n, k;

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
	long long ans = 0;
	int res = 0;
        ++k;
	for (int x = 30; x >= 0; --x) {
		res ^= (1 << x);
		if (k & (1 << x)) {
			long long cur = 0;
			for (int i = 0; i < n; ++i) {
				if ((a[i] & res) == 0) cur += b[i];
			}
			res ^= (1 << x);
			ans = max(ans, cur);
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int parent[100001];
int p[100001];
int findparent(int x)
{
	if(parent[x]!=x)
		parent[x]=findparent(parent[x]);
	return parent[x];
}
void unionset(int a,int b)
{
	if((a=findparent(a))==(b=findparent(b)))
		return;
	parent[a]=b;
}
int main()
{
	int n,m,i,x,y,count=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		parent[i]=i;	
	}
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		unionset(p[x],p[y]);
	}
	for(i=1;i<=n;i++)
	{
		if(findparent(p[i])==findparent(i))
			count++;
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll H, N;
	cin >> H >> N;
	vll A(N), B(N);
	ll A_max = 0;
	rep(i, 0, N) {
		cin >> A[i] >> B[i];
		A_max = max(A_max, A[i]);
	}

	vll t(H + A_max + 1, ll_max);
	t[0] = 0;
	repeq(i, 1, H + A_max) {
		rep(j, 0, N) {
			if (A[j] <= i && t[i - A[j]]!=ll_max) {
				t[i] = min(t[i], t[i - A[j]] + B[j]);
			}
		}
	}

	ll ans = ll_max;
	repeq(i, 0, A_max) {
		ans = min(ans, t[H + i]);
	}

	cout << ans << endl;
	return 0;

}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int lb = 0, rw = 0;
  rep(i, n) if (s[i] == '.') ++rw;
  int ans = rw;
  rep(i, n) {
    if (s[i] == '#') ++lb;
    else --rw;
    ans = min(ans, lb + rw);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3748
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String S = sc.next();
            Str str = new Str(S);
            int Q = sc.nextInt();
            for (int q = 0; q < Q; q++) {
                int T = sc.nextInt();
                if (T == 1) {
                    str.flip();
                } else {
                    int F = sc.nextInt();
                    char C = sc.next().charAt(0);
                    if (F == 1) {
                        str.addFirst(C);
                    } else {
                        str.addLast(C);
                    }
                }
            }
            System.out.println(str.toString());
        }
    }
}

class Str {
    LinkedList<Character> list;
    boolean isReverse = false;

    public Str(String s) {
        list = new LinkedList<Character>();
        for (int i = 0; i < s.length(); i++) {
            list.add(s.charAt(i));
        }
    }

    public void flip() {
        isReverse = !isReverse;
    }

    public void addFirst(char c) {
        if (isReverse) {
            list.addLast(c);
        } else {
            list.addFirst(c);
        }
    }

    public void addLast(char c) {
        if (isReverse) {
            list.addFirst(c);
        } else {
            list.addLast(c);
        }
    }

    public String toString() {
        StringBuilder res = new StringBuilder();
        if (isReverse) {
            while (!list.isEmpty()) {
                res.append(list.pollLast());
            }
        } else {
            while (!list.isEmpty()) {
                res.append(list.pollFirst());
            }
        }
        return res.toString();
    }
}

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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

// -------------------------------------------




int main(){
  string n;
  cin>>n;
  int x = n[n.size()-1]-'0';
  if(x==2 or x==4 or x==5 or x==7 or x ==9)
    std::cout << "hon" << std::endl;
  else if(x==3) {
    std::cout << "bon" << std::endl;
  } else
    std::cout << "pon" << std::endl;
  return 0;
}


Measured memory_bytes: 3592