akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair

int main(){
  int n; cin >> n;
  set<int> st;
  map<int, bool> m;
  rep(i, n){
    int a; cin >> a;
    if(st.count(a)) m[a] = true;
    st.insert(a);
  }

  int cnt = 0;
  for(int a : st){
    if(m[a]) continue;
    bool ok = true;
    REP(i, 1, 1000){
      if(i == a) continue;
      if(a % i == 0){
        if(st.count(i)) ok = false;
        if(i != 1 && st.count(a/i)) ok = false;
      }
    }
    if(ok) cnt++;
  }
  
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 22344
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var A = parseInt(input[1].split(" ")[0]);
  var B = parseInt(input[1].split(" ")[1]);
  P1 = new Array();
  P2 = new Array();
  P3 = new Array();
  tmp= input[2].split(" ");
  for(var i=0;i<N;i++){
    P=parseInt(tmp[i]);
    if(P<=A){
      P1.push(P);
    }else if(P<=B){
      P2.push(P);
    }else{
      P3.push(P);
    }
  }
  var ans = Math.min(P1.length,P2.length,P3.length);

  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var s, t string
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%s", &s)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%s", &t)

	if s == t {
		fmt.Println("Yes")
		return
	}
	ss := strings.Split(s+s, t)
	if len(ss) < 2 {
		fmt.Println("No")
		return
	}
	if ss[1]+ss[0] == t {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main(){
  string A, B, C;
  cin>>A>>B>>C;
  if(A[A.length()-1] == B[0] && B[B.length()-1] == C[0]){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    bool re = any_of(a.begin(), a.end(), [](int x) {return x == 2;});
    
    if (!re) {
        cout << -1 << endl;
    } else {
        int j = 1, count = 0;
        vector<int> che(n, 1);
        while (j != 2) {
            if (che[j - 1] == 1) {
                che[j - 1] = 0;
                j = a[j - 1];
                count++;
            } else {
                cout << -1 << endl;
                return 0;
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 4012
function Main(s){
  s = s.split("\n");
  s[0] = s[0].split(" ").map(a=>+a);
  var n = s[0][0];
  var c = s[0][1];
  var d = [], a = [];
  for(var i = 0; i < c; i++){
    d[i] = s[i+1].split(" ").map(a=>+a);
  }
  for(i = 0; i < n; i++){
    a[i] = s[i+1+c].split(" ").map(a=>+a-1);
  }
  var z = Array(3).fill(0).map(a=>Array(c).fill(0));
  for(i = 0; i < n; i++)
  for(var j = 0; j < n; j++){
    var t = (i + j) % 3;
    z[t][a[i][j]]++;
  }
  var ans = 9e9;
  for(i = 0; i < c; i++){
    for(j = 0; j < c; j++){
      if(i === j)continue;
      for(var k = 0; k < c; k++){
        if(i === k || j === k)continue;
        t = 0;
        for(var l = 0; l < c; l++){
          t += z[0][l] * d[l][i];
          t += z[1][l] * d[l][j];
          t += z[2][l] * d[l][k];
        }
        ans = Math.min(ans, t);
      }
    }
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 16400
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		Scanner scan = new Scanner(System.in);
		int n  = scan.nextInt();
		int m = scan.nextInt();
		int[] a = new int[m];
		int sum = 0;
		for(int i = 0; i < m; i++){
			a[i] = scan.nextInt();
			sum += a[i];
		}
		if(n >= sum){
			System.out.println(n- sum);
		} else{
			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 46412
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    for(int i=0;i<=n;i++){
        if(10000*i+5000*(n-i)<y) continue;
        for(int j=0;j<=n-i;j++){
            int k = n - i - j;
            if(10000*i+5000*j+1000*k==y){
                cout << i << " " << j << " " << k << endl; 
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int H, W;
  cin >> H >> W;

  vector<string> A(H);

  for (int i = 0; i < H; i++)
  {
    cin >> A.at(i);
  }
  
  for (int i = 0; i < H + 2; i++)
  {
    if (i == 0 || i == H + 1) {
      for (int j = 0; j < W + 2; j++)
      {
        cout << '#';
      }
      cout << endl;
    } else {
      cout << '#' << A.at(i - 1) << '#' << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define F first
#define S second
#define p_b push_back
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef pair<int, int> pa;
typedef vector<pair<int,int> > vepa;
typedef map<int, int> mp;
const ll N=1e5+5;
ll arr[N],A[N],ARR[N]  ;
bool visited[N]={};
ll cnt[N]={};
bool f;
 int main()
{
    string s;
    int count(0);
   cin>>s;
       for(int i=0;i<s.size()-1;i++)
       {
           if(s[i]=='1'&&s[i+1]=='1')
           {
               s[i+1]='0';
               count++;
               continue;
           }
           if(s[i]=='0'&&s[i+1]=='0')
           {
               s[i+1]='1';
               count++;
           }

       }
       cout<<count;
go;
}


Measured memory_bytes: 512
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        char[] input = Console.ReadLine().ToCharArray();
        int[] n = Array.ConvertAll(input, i => (int)Char.GetNumericValue(i));

        if (n.Length == 1)
        {
            Console.WriteLine(n.Sum());
            return;
        }
        else if (n.Length == 2)
        {
            Console.WriteLine(Math.Max(n.Sum(), n[0] - 1 + 9));
            return;
        }
        
        int lastIndex = n.Length - 1;
        for (int i = 2; i < lastIndex - 1; i++)
        {
            n[i] = 9;
        }

        if (n[0] + n[1] <= n[0] - 1 + 9)
        {
            n[0]--;
            n[1] = 9;
            if (lastIndex - 1 != 1)
            {
                if (n[lastIndex - 1] + n[lastIndex] < 9 + 9)
                {
                    n[lastIndex - 1] = 9;
                    n[lastIndex] = 9;
                }
            }
            else
                n[lastIndex] = 9;
        }
        else
        {
            if (n[lastIndex - 1] + n[lastIndex] < n[lastIndex - 1] - 1 + 9)
            {
                n[lastIndex - 1]--;
                n[lastIndex] = 9;
            }
        }
        Console.WriteLine(n.Sum());
    }
}

Measured memory_bytes: 13268
/*#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll a[100005],b[100005];
int main(){
	cin >> n;
	rep(i,n+1) { cin >> a[i]; }
	rep(i,n) { cin >> b[i]; }
	ll ans = 0;
	rep(i,n){
		{
			ans += min(a[i],b[i]);
			b[i] -= min(a[i],b[i]);
		}
		{
			ans += min(a[i+1],b[i]); int x = min(a[i+1],b[i]);
			b[i] -= x;
			a[i+1] -= x;
		}
	}
	cout << ans << endl;
}


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

int n, k;
vector <int> logs;

bool isPossible(int len) {
	int cuts = 0;
	for (int l : logs) {
		cuts += (l-1)/len;
	}
	return (cuts <= k);
}

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

	cin >> n >> k;

	logs.resize(n);
	for(int i = 0; i < n; ++i) cin >> logs[i];

	int l = 1, r = 1e9;
	while (l < r) {
		int m = l + (r-l)/2;
		if (isPossible(m)) {
			r = m;
		} else {
			l = m+1;
		}
	}

	cout << l << endl;
}


Measured memory_bytes: 3872
import sys
input = sys.stdin.readline
import bisect
from operator import itemgetter

N=int(input())
R=[tuple(map(int,input().split())) for i in range(N)]+[(1<<31,1<<31)]
R.sort(key=itemgetter(0))
RMAX=[x+y for x,y in R]

seg_el=1<<(N.bit_length())# Segment treeの台の要素数
SEG=[-1]*(2*seg_el)# 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

def update(n,x,seg_el):# A[n]をxへ更新（反映）
    i=n+seg_el
    SEG[i]=x
    i>>=1# 子ノードへ
    
    while i!=0:
        SEG[i]=max(SEG[i*2],SEG[i*2+1])
        i>>=1
        
def getvalues(l,r):# 区間[l,r)に関するmaxを調べる
    L=l+seg_el
    R=r+seg_el
    ANS=-1<<30

    while L<R:
        if L & 1:
            ANS=max(ANS , SEG[L])
            L+=1

        if R & 1:
            R-=1
            ANS=max(ANS , SEG[R])
        L>>=1
        R>>=1

    return ANS

for i in range(N-1,-1,-1):
    x=bisect.bisect_left(R,(RMAX[i],0))
    MAX=getvalues(i,x)
    if MAX==-1:
        update(i,x,seg_el)
    else:
        update(i,MAX,seg_el)

mod=998244353


DP=[0]*(N+1)
DP[0]=1

for i in range(N):
    DP[i+1]=(DP[i]+DP[i+1])%mod
    DP[getvalues(i,i+1)]=(DP[i]+DP[getvalues(i,i+1)])%mod

    #print(DP)
print(DP[-1]%mod)



Measured memory_bytes: 101952
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import bisect

N, M = list(map(int, input().split()))
a = [0]*M
for m in range(M):
    a[m] = int(input())
a = set(a)
MOD = 10**9 + 7

def main(): 
    dp = [0]*(N+2)
    dp[0] = 1
    for n in range(1,N+1):
        if n ==1:
            if n in a:
                dp[n] = 0
            else:
                dp[n] += dp[n-1]
                
        else:                        
            if n in a:
                dp[n] = 0
            else:
                dp[n] += dp[n-2] + dp[n-1]
                
    #print(dp)
    print(dp[N]%MOD)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()


Measured memory_bytes: 471288
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
N = int(input())
ca, cb = 0, 0
for _ in range(N):
    a, b = map(int, input().split())
    if ca == 0 and cb == 0:
        ca, cb = a, b
    else:
        r = int(math.ceil(max(Fraction(ca, a), Fraction(cb,b))))
        ca, cb = a*r, b*r

print (ca + cb)

Measured memory_bytes: 13532
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			long k = cin.Long();
			var a = cin.ArrayLong(n, -1);

			var rui = new long[n + 1];
			for (int i = 0; i < n; i++) {
				rui[i + 1] = (rui[i] + a[i]) % k;
			}

			long ans = 0;
			var counts = new Dictionary<long, int>();
			for (int i = 0; i < n + 1; i++) {
				if (i - k >= 0) {
					counts[rui[i - k]]--;
				}

				if (counts.ContainsKey(rui[i])) {
					ans += counts[rui[i]];
				} else {
					counts[rui[i]] = 0;
				}

				counts[rui[i]]++;
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 44800
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;
const MOD: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        k: usize,
        e: [(Usize1, Usize1);n-1],
    }

    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];

    for v in e {
        let (from, to) = v;
        graph[from].push(to);
        graph[to].push(from);
    }

    let mut seen: Vec<bool> = vec![false; n];

    let ans = dfs(0, &graph, &mut seen, k);
    println!("{}", ans);
}

fn dfs(i: usize, g: &Vec<Vec<usize>>, seen: &mut Vec<bool>, k: usize) -> usize {
    let mut seen_count = if i == 0 { 0 } else { 1 };
    let mut unseen_count = if i == 0 { 1 } else { 0 };

    seen[i] = true;

    let mut res = 1;

    // なんらかの処理(行きがけ順)
    for &next in &g[i] {
        if seen[next] {
            seen_count += 1;
            continue;
        }
        unseen_count += 1;
        res = res * dfs(next, g, seen, k) % MOD;
    }
    // なんらかの処理(帰りがけ順)
    for i in 0..unseen_count {
        res = res * (k - seen_count - i) % MOD;
    }

    res
}


Measured memory_bytes: 15604
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL n;
    cin >> n;
    vector<LL> a(n);
    LL ans=0;

    for(LL i=0; i<n; i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<LL>());
    if(n==2){
        ans=a[0];
    }else{
        ans=a[0];
        LL tmp=n/2;
        if(n%2!=0){
            for(LL i=1; i<tmp; i++){
                ans+=2*a[i];
            }
            ans+=a[tmp];
        }else{
            for(LL i=1; i<tmp; i++){
                ans+=2*a[i];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4756
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#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 sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
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;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    res += s[i][t[i]-1];
    lst[t[i]-1] = i;
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  return res;
}

int main(){
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,0);
  rep(d,D){
    rep(i,26){
      if(s[d][i]>s[d][t[d]]) t[d] = i;
    }
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3676
#include<iostream>

using namespace std;

class card
{
public:
	char s;
	int c;
};

bool operator==(const card a, const card b)
{
	if (a.c == b.c)
	{
		if (a.s == b.s)
		{
			return true;
		}
	}
	return false;
}

void swap(card& a, card& b)
{
	card v;
	v = a;
	a = b;
	b = v;
}

void print(card a[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		if (i)cout << " ";
		cout << a[i].s << a[i].c;
	}
	cout << endl;
}

int check(card a[], card b[], int n)
{
	int i, j, k, l;
	for (i = 0; i < n - 1; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			if (a[i].c == a[j].c)
			{
				for (k = 0; k < n - 1; k++)
				{
					for (l = k + 1; l < n; l++)
					{
						if (a[i] == b[l] && a[j] == b[k])
						{
							return 0;
						}
					}
				}
			}
		}
	}
	return 1;
}

void bprint(int a)
{
	if (a)cout << "Stable" << endl;
	else cout << "Not stable" << endl;
}

void bubble(card a[], int n)
{
	int i, j, flag = 0;
	for (i = 0; i < n; i++)
	{
		flag = 0;
		for (j = n - 1; j > i; j--)
		{
			if (a[j].c < a[j - 1].c)
			{
				swap(a[j], a[j - 1]);
				flag = 1;
			}
		}
		if (!flag)break;
	}
}

void select(card a[], int n)
{
	int i, j, min;
	for (i = 0; i < n; i++)
	{
		min = i;
		for (j = i + 1; j < n; j++)
		{
			if (a[j].c < a[min].c)
			{
				min = j;
			}
		}
		swap(a[i], a[min]);
	}
}

int main()
{
	int n, i;
	card a[36], b[36], c[36];
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a[i].s >> a[i].c;
		b[i].s = a[i].s;
		b[i].c = a[i].c;
		c[i].s = a[i].s;
		c[i].c = a[i].c;
	}
	bubble(b, n);
	print(b, n);
	bprint(check(a, b, n));
	select(c, n);
	print(c, n);
	bprint(check(a, c, n));
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void)
{
	int a[10][12] = {0};
	int n, i, j, k, count;

	while (scanf("%d", &n) != EOF)
	{
		if (n != 0)
		{
			for (j = 0; j < n; j++)
				scanf("%d", &a[0][j]);

			i = 0;
			while (1)
			{
				for (j = 0; j < n; j++)
				{
					count = 0;
					for (k = 0; k < n; k++)
						if (a[i][j] == a[i][k])
							count++;
					a[i+1][j] = count;
				}

				for (j = 0; j < n; j++)
					if (a[i][j] != a[i+1][j])
						break;
				if (j == n)
					break;

				i++;
			}

			printf("%d\n", i);
			for (j = 0; j < n; j++)
			{
				printf("%d", a[i][j]);
				if (j != n - 1)
					printf(" ");
				else
					printf("\n");
			}
		}
		else
			break;
	}

	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define input() for(int i=0;i<n;i++)cin>>a[i];
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int n, a, b, p[105], aa, bb, cc;
signed main() {
	cin >> n >> a >> b;
	rep(i, n) {
		cin >> p[i];
		if (p[i] <= a)aa++;
		if (p[i] > a && p[i] <= b)bb++;
		if (p[i] > b)cc++;
	}
	cout << min({ aa,bb,cc }) << endl;
	endre;
}

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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> A(N+1);
  for(int i=0; i<N; i++){
   cin >> A.at(i);  
  }
  
  sort(A.begin(),A.end());
  
  bool ans = true;
  
  for(int i=0; i<N; i++){
    if(A.at(i)==A.at(i+1)) ans = false;
  }
  
  if(ans==true) cout << "YES";
  else cout << "NO";
         
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
const int NN = 1e6+10;
typedef long long ll;

ll a,b,c;
int main(){
    cin>>a>>b>>c;
    if( c> (a-b)){
        cout<< c-(a-b)<<endl;
    }else{
        cout<<0<<endl;
    }

    return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

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

int main ()
{
    fastio
    lli x , t ;
    cin >> x >> t ;
    cout << (x - t > 0 ? x - t : 0) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
while True:
    H, W = map(int,input().split())
    if H==0 and W==0:
        break
    Y = 1
    while Y <= H:
        if Y % 2 == 1:
            X = 1
            while X <= W:
                if X % 2 == 1:
                    print('#', end="")
                else:
                    print('.', end="")
                X = X + 1
        else:
            X = 1
            while X <= W:
                if X % 2 == 1:
                    print('.', end="")
                else:
                    print('#', end="")
                X = X + 1
        Y = Y + 1
        print()
        
    print()


Measured memory_bytes: 7008
#include<iostream>
using namespace std;
#include<queue>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
bool b[2003];

#define REP(i, a) for(int i=0;i<a;i++)
	int N=(1<<20);
	int max=101;
		vector < pair<int,int> > A[100000];
int main()
{
	pair<int,int> f;
	priority_queue < pair < int,int > > PQ;
	int min,b,a,k,m,n ,e,p[101],d[100000],u,v; //u ?????????v????????¨
	bool color[10001];

	cin>>n;
	REP(i, n) {
		cin>>u>>k;
		REP(i, k) {
			cin>>a>>b;
			if(b==-1) b=N;
			A[u].push_back(make_pair(a,b));
		}
		color[i]=0;
		d[i]=N;
	}
	a=0;
	d[0]=0;
	PQ.push(make_pair(0,0));
	while(!PQ.empty()){
		f=PQ.top();
		PQ.pop();
		u=f.second;
		color[u]=1;
		REP(i,A[u].size()){
			v=A[u][i].first;
			if(color[v]==1){
			continue;
			}
				if(d[v]>A[u][i].second+d[u]){
					d[v]=A[u][i].second+d[u];
					PQ.push(make_pair(d[v]*-1,v));
				}
		}
	}
	REP(i,n){
		cout<<i<<" "<<(d[i] == N ? -1 : d[i])<<endl;
	
	}
	return 0;
}

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


def solve(n: int, a: "List[int]"):
    b = sorted(a)
    n = b[-1]
    c = [(min(bb, n-bb), bb) for bb in b[:-1]]
    return n, max(c)[1]


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    print(*solve(n, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

int main(){
	typedef long long ll;
	ll n,k;
	vector<ll> v;
	ll no = 0;
	cin >> n >> k;
	for(ll i=0;i<n;i++){
		ll a;
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	while(k>0 && v.size()>0){
		v.pop_back();
		k--;
	}
	if(v.empty())cout << 0;
	else{
		for(ll i = 0;i<v.size();i++){
			no+=v[i];
		}
		cout << no;
	}
	return 0;
}

Measured memory_bytes: 5300
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)*}
    };
}

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [(usize1, usize1); n - 1]
    }
    let mut t = vec![vec![]; n];
    for &(a, b) in &v {
        t[a].push(b);
        t[b].push(a);
    }
    let mut mem = vec![true; n];
    if dfs(0, 0, &t, &mut mem) || mem[0] {
        println!("First");
    } else {
        println!("Second");
    }
}

fn dfs(v: usize, p: usize, t: &Vec<Vec<usize>>, mem: &mut Vec<bool>) -> bool {
    let mut f = false;
    for &c in &t[v] {
        if c == p {
            continue;
        }
        if dfs(c, v, t, mem) {
            return true;
        }
        if mem[c] {
            if f {
                return true;
            }
            mem[v] = false;
            f = true;
        }
    }
    false
}


Measured memory_bytes: 12540
def solve():
    N, K = map(int, input().split()) 
    ab = []
    for i in range(N):
        ab.append( list(map(int, input().split())) )

    ab.sort()

    for (a, b) in ab:
        K -= b
        if K <= 0:
            print(a)
            return

solve()


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)3005;
int N, T, A[MAXN], B[MAXN];
int dp[MAXN][2];

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> T;
    for(int i=1; i<=N; i++)
    {
        cin >> A[i] >> B[i];
    }

    for(int i=0; i<=T; i++)
        for(int j=0; j<2; j++)
            dp[i][j] = 0;
    for(int i=0; i<=N; i++)
    {
        for(int j=T-1; j>=0; j--)
        {
            if(A[i] + j < T)
            {
                dp[j+A[i]][0] = max(dp[j+A[i]][0], dp[j][0] + B[i]);
                dp[j+A[i]][1] = max(dp[j+A[i]][1], dp[j][1] + B[i]);
            }
            dp[j][1] = max(dp[j][1], dp[j][0] + B[i]);
        }
    }

    cout << dp[T-1][1];;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
class UnionFind {
public:
  vector<ll> data;
  UnionFind(int size) : data(size, -1) {}

  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x != y) {
      if(data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }
  int size(int x) {
    return -data[find(x)];
  }
};

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

  cin >> n >> m;

  vector<P> v(m);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    v[i] = P(a, b);
  }

  UnionFind uf = UnionFind(n + 1);

  vector<ll> ans(m);
  for(int i=m-1; i>=0; i--) {
    P p = v[i];
    ll a = uf.size(p.first);
    uf.unite(p.first, p.second);
    ll b = uf.size(p.first);

    ans[i] = a * (b - a);
  }

  ll sum = 0;
  REP(i, m) {
    sum += ans[i];
    cout << sum << endl;
  }
}


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

struct Edge { int from, to, cost; };

int main() {
	int n, m, a, b, cost;
	while (cin >> n >> m, n) {
		vector<Edge> G;
		for (int i=0; i<m; ++i) {
			cin >> a >> b >> cost;
			G.push_back((Edge){ a, b, cost });
			G.push_back((Edge){ b, a, cost });
		}
		int ret = 0;
		bool used[100] = {};
		used[0] = true;
		while (1) {
			int k, mn = 1e5;
			for (int i=0; i<(int)G.size(); ++i) {
				if (used[G[i].from] && ! used[G[i].to] && G[i].cost < mn) {
					mn = G[i].cost;
					k = i;
				}
			}
			if (mn == 1e5) break;
			used[G[k].to] = true;
			ret += G[k].cost;
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		int d = 0;
		for (; d<N; d++) {
			String ss = s.substring(d);
			String tt = t.substring(0, N-d);
			if (ss.equals(tt)) break;
		}
		System.out.println(N+d);
		sc.close();
	}

}


Measured memory_bytes: 9684
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N;
    cin >> N;
    VLL A(N+1);
    ll sum=0;
    ll sum_p=0;
    rep(i,N){
        cin >> A[i];
        sum+=A[i];
        if((i+1)%2==0){
            sum_p+=A[i];
        }
    }
    VLL dam(N);
    dam[0]=sum-2*sum_p;
    cout << dam[0] << " ";
    for(int i=1; i<N; i++){
        dam[i]=2*A[i-1]-dam[i-1];
        cout << dam[i] << " ";
    }
    cout << endl;
}

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

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

    double ans = 0;
    for (int i = 1; i <= n; i++) {
        double a = 0, s = i;
        while (s < k) {
            s *= 2;
            a++;
        }
        ans += 1/(n * pow(2, a));
    }

    printf("%.12f\n", ans);
    return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (a >= 13){
		cout << b;
	}
	else if (a >= 6)
		cout << b / 2;
	else
		cout << 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int ex(int n,int sum,int num)
{
    if(n == 0&&sum == 0)return 1;
    if(n == 0||num == 10)return 0;
    return ex(n,sum,num + 1) + ex(n - 1,sum - num,num + 1);
}
int main()
{
    while(1)
    {
        int n,sum;
        scanf("%d%d",&n,&sum);
        if(n == 0&&sum == 0)break;
        printf("%d\n",ex(n,sum,0));
    }
    return 0;
}

Measured memory_bytes: 1028
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var X = ReadLong();
            var A = ReadLong();
            var B = ReadLong();
            return (X - A) % B;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27360
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    cin >> k;
    cout << (k % 2 == 0 ? k * k / 4 : k / 2 * (k / 2 + 1)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define M   1000000007 // 1e9 + 7
#define MAXN 400100
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,double> pdd;
inline int mod(int n, int m){int ret = n%m; if(ret < 0) ret += m; return ret;}
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }    else return mod(k*k,m);
}


int dp[3010][3010][2];
pii A[3010];
int n;
int solve(int id,int t,int flag){
	if(id==n+1)return 0;
	if(t<=0)return 0;
	if(dp[id][t][flag]!=-1)return dp[id][t][flag];
	
	if(flag==1){
		
		if(A[id].ff>t){
			return dp[id][t][flag] = solve(id+1,t,1);
		}else{
			return dp[id][t][flag] = max(solve(id+1,t,1),A[id].ss+solve(id+1,t-A[id].ff,1));
		}
		
	}else{
		
		if(A[id].ff>t){
			return dp[id][t][flag] = max(solve(id+1,t,0),solve(id+1,t,1)+A[id].ss);
		}else{
			return dp[id][t][flag] = max(solve(id+1,t,0),max(solve(id+1,t,1)+A[id].ss,solve(id+1,t-A[id].ff,0)+A[id].ss));
		}
		
	}
	
}

int32_t main(){
	fastio;
	int t;
	cin>>n>>t;
	t--;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++){
		cin>>A[i].ff>>A[i].ss;
	}
	cout<<solve(1,t,0)<<endl;
}

Measured memory_bytes: 141952
while True:
    h,w=list(map(int,input().split()))
    if h==w==0:
        break
    for i in range(h):
        for j in range(w):
            if j==w-1 or i==h-1 or i==0 or j==0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
const int mod = 1'000'000'007;
int mul(long long a, long long b){
	return a * b % mod;
}
int pwr(long long a, long long b){
	int r = 1;
	for(; b; b >>= 1, a = mul(a, a)) if(b&1) r = mul(r, a);
	return r;
}
const int maxn = 200200;
struct st {
	int c[3], mv;
	st(){
		c[0] = c[1] = c[2] = 0;
		mv = 0;
	}	
	st operator + (st oth){
		st ans;
		for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) {
			int d = mul(c[i], oth.c[j]);
			int ij = min(i + j, 2);
			ans.c[ij] += d;
			if(ans.c[ij] >= mod) ans.c[ij] -= mod;
		}
		return ans;
	}
	void shift(){
		c[0] += c[2];
		if(c[0] >= mod) c[0] -= mod;
		c[2] = 0;
	}
};
vector<int> e[maxn];
vector<st> f[maxn];
int cdep[maxn], dep[maxn];
int p2[maxn], ip2[maxn];
void init(){
	p2[0] = 1;
	for(int i = 1; i < maxn; i++) p2[i] = mul(p2[i - 1], 2);
	ip2[maxn - 1] = pwr(p2[maxn - 1], mod - 2);
	for(int i = maxn - 2; i >= 0; i--) ip2[i] = mul(2, ip2[i + 1]);
	for(int i = 0; i < maxn; i++) assert(mul(p2[i], ip2[i]) == 1);
}
void solve(int u){
	cdep[dep[u]]++;
	for(int v : e[u]) {
		dep[v] = dep[u] + 1;
		solve(v);
	}
	int best = -1;
	for(int v : e[u]) if(best == -1 || f[best].size() < f[v].size()) best = v;
	if(best != -1){
		swap(f[u], f[best]);
		int sz = f[u].size();
		int big = 0;
		for(int v : e[u]) if(v != best){
			int vsz = f[v].size();
			for(int i = 0; i < vsz; i++){
				f[u][sz - 1 - i] = f[u][sz - 1 - i] + f[v][vsz - 1 - i];
			}
			big = max(big, vsz);
		}
		for(int i = 0; i < big; i++) f[u][sz - 1 - i].shift();
	}
	st up;
	up.c[0] = up.c[1] = 1;
	f[u].push_back(up);
}
int main(){
	init();
	int n; cin >> n;
	for(int i = 1; i <= n; i++){
		int x; cin >> x;
		e[x].push_back(i);
	}
	solve(0);
	int ans = 0;
	int len = f[0].size();
	for(int i = 0; i < len; i++){
		ans += mul(p2[n + 1 - cdep[len - i - 1]], f[0][i].c[1]);
		if(ans >= mod) ans -= mod;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    string s;
    cin >> s;
    int l = s.size();
    string ss;
    ss = s.substr(0, (l-1)/2);
    bool t = true;
    rep(i,(s.size()-1)/2){
        if (s.at(i) != s.at(s.size() - 1 - i)){
            t = false;
            break;
        }
    }
    if (t){
        rep(j,(ss.size())/2){
            if (ss.at(j) != ss.at(ss.size() - 1 - j)){
                t = false;
                break;
            }
        }
        if (t){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
//library end
int h,w;
char c[30][30];
set<P>st;
queue<pair<P,int>>que;
vector<queue<pair<P,int>>>empty(200000);
int mx[]{-1,1,0,0},my[]={0,0,-1,1};
int bfs(P i){
    int d=0;
    que.push(make_pair(i,0));
    st.insert(i);
    while(!que.empty()){
        P p=que.front().F;
        int dis=que.front().S;
        que.pop();
        d=max(d,dis);
        rep(k,4){
            if(st.find(make_pair(p.F+mx[k],p.S+my[k]))==st.end()&&c[p.F+mx[k]][p.S+my[k]]=='.'){
                que.push(make_pair(make_pair(p.F+mx[k],p.S+my[k]),dis+1));
                st.insert(make_pair(p.F+mx[k],p.S+my[k]));
            }
        }
    }
    return d;
}
int ans=0;
int cnt=0;
signed main(){
    cin>>h>>w;
    rep(i,h+2){
        c[i][0]='#';
        c[i][w+1]='#';
    }
    rep(j,w+2){
        c[0][j]='#';
        c[h+1][j]='#';
    }
    rep(i,h){
        rep(j,w){
            cin>>c[i+1][j+1];
        }
    }
    int cnt=0;
    rep(sx,h){
        rep(sy,w){
            if(c[sx+1][sy+1]=='.'){
                int bf=bfs(make_pair(sx+1,sy+1));
                ans=max(ans,bf);
                st.clear();
                swap(que,empty[cnt]);
                cnt++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

int main()
{
    char str[5];
    cin >> str;
    int ans = 0;
    for(int i = 0;i < 4;i++)
    {
        if(str[i] ==  '+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];

  sort(v.begin(), v.end());

  double ans = v[0];
  for (int i = 1; i < n; ++i) {
    ans += v[i];
    ans /= 2;
  }

  printf("%.6lf\n", ans);
  return 0;
}



Measured memory_bytes: 256