akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int H,W;
        String work[] = new String[2];
 
        while(true){
 
            try {
                work = br.readLine().split("[\\s]+");
 
                if(work[0].equals("0") && work[1].equals("0"))break;
 
                H = Integer.parseInt(work[0]);
                W = Integer.parseInt(work[1]);
 
                for(int row = 0; row < H; row++){
                    for(int col = 0; col < W; col++){
                        if((row+col)%2 == 0){
                            System.out.printf("#");
                        }else{
                            System.out.printf(".");
                        }
                    }
                    System.out.printf("\n");
                }
 
                System.out.printf("\n");
 
 
            } catch (IOException e) {
 
                e.printStackTrace();
            }
        }
    }
}


Measured memory_bytes: 60688
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());

		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;

		for (int i = 0; i < n; i++) {
			String s = sc.next();
			if (s.equals("AC")) {
				ac++;
			}
			if (s.equals("WA")) {
				wa++;
			}
			if (s.equals("TLE")) {
				tle++;
			}
			if (s.equals("RE")) {
				re++;
			}

		}

		System.out.println("AC x " + ac);
		System.out.println("WA x " + wa);
		System.out.println("TLE x " + tle);
		System.out.println("RE x " + re);

	}
}


Measured memory_bytes: 58856
#include<bits/stdc++.h>
#define sc(v) v.size()
#define eb push_back
#define pb pop_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define TC() int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define mk make_pair
#define fi first
#define se second
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
using namespace std;

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

const int N = 1e5 + 5;
int ar[3][N];
int main()
{
	int n;
	cin>>n;
	f(i,0,n) {
		cin>>ar[0][i]>>ar[1][i]>>ar[2][i];
	}
	f(i,1,n) {
		f(j,0,3) {
			int ma = 0;
			f(k,0,3) {
				if (j == k) continue;
				ma = max(ma, ar[k][i - 1]);
			}
			ar[j][i] += ma;
		}
	}
	cout<<max(max(ar[0][n - 1], ar[1][n - 1]), ar[2][n - 1]);
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll N;
string S;
ll ans = 0;

void dfs(ll count, ll now, ll total){
    if(count == N){
        // cout << total + now << endl;
        ans = ans+total+now;
    }
    else{
        ll a = S[count]-'0';
        dfs(count+1, a, total+now);
        dfs(count+1, now*10+a, total);
    }
}

int main()
{
    cout << fixed << setprecision(15);
    cin >> S;

    N = S.length();
    dfs(0, 0, 0);

    cout << ans/2 << endl;

    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

long long N, K;
long long P[5005];
long long C[5005];
pair<long long, long long> memo[5005];

long long cal(long long start) {
	long long cur = start;
	long long cost = 0;
	long long ans = LONG_MIN;
	bool canskip = true;
	
	rep(i, N + 5)memo[i] = make_pair(-1, -1);

	long long i = 0;
	long long rest = K;
	while(rest>0) {
		if(canskip && memo[cur].first != -1) {
			long long pasti = memo[cur].first;
			long long pastcost = memo[cur].second;

			long long interval = i - pasti;
			long long loopcost = cost - pastcost;
			long long numloop = rest / interval;
			numloop = max(0LL, numloop - 2);

			if(pastcost >= cost) {
				return ans;
			} else {
				cost += numloop * loopcost;
				rest -= interval * numloop;
			}
			canskip = false;
		} else {
			memo[cur] = make_pair(i, cost);
			cost += C[cur];
			ans = max(ans, cost);
			cur = P[cur];
			i++;
			rest--;
		}
	}
	return ans;
}


int main(){
	cin >> N >> K;

	rep(i, N) {
		cin >> P[i];
		P[i]--;
	}

	rep(i, N){
		cin >> C[i];
	}

	long long ans = LONG_MIN;
	rep(i, N) {
		long long tmp = cal(i);
		ans = max(ans, tmp);
	}
	cout << ans << endl;

}

Measured memory_bytes: 3804
use std::io;
use std::vec::Vec;
use std::str::FromStr;
fn main() {
    let mut number_count = String::new();
    io::stdin().read_line(&mut number_count).unwrap();
    number_count.pop();
    let mut numbers = String::new();
    io::stdin().read_line(&mut numbers).unwrap();
    numbers.pop();
    let numbers: Vec<u32> = numbers.split(' ').map(|s| u32::from_str(&s).unwrap()).collect();
    for number in numbers {
        if number % 2 == 0 {
            if !(number % 3 == 0 || number % 5 == 0) {
                println!("DENIED");
                return;
            }
        }
    }
    println!("APPROVED");
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a;i < b;i++)
#define rrep(i,a,b) for(int i = a;i >= b;i--)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << #x << ": " << x << endl;
typedef long long ll;
using namespace std;

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

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

   int n;
   cin >> n;

   cout << 1110 - n << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;

int main (void) {
  string s;
  cin >> s;
  int ans=0;
  int l=s.length();
  for (int i=0; i<=l; i++) {
    if (s[i]=='1') ans=ans+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
gets;
X=$<.map{_1.split.map &:to_i};
A,B=[0,1].map{|i|c=X.map{_1[i]}.tally.sort_by{_2};c.filter{_2==c[-1][1]}};
Y=X.tally;
p A[0][1]+B[0][1]-(A.size*B.size<4e5&&A.all?{|a,|B.all?{|b,|Y[[a,b]]}}?1:0)


Measured memory_bytes: 112976
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    ll n,ans=0;cin>>n;

    vector<ll> a(n),b(n),c(n);
    for(int i=0;i < n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i < n;i++)
    {
        cin>>b[i];
    }
    for(int i=0;i < n;i++)
    {
        cin>>c[i];
    }

    sort(a.begin(),a.end());
    sort(c.begin(),c.end());

    for(int i=0;i < n;i++)
    {
        ll x=(lower_bound(all(a),b[i])-a.begin());
        ll y=n-(upper_bound(all(c),b[i])-c.begin());
        
        ans+=x*y;
    }
    cout<<ans<<endl;
}
// 2 3 14 

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

void ans(int i,int last,int n,int m,int q,int &ma,int a[],pair<pair<int,int>,pair<int,int>> p[]){
	if(i==n){
		int ha=0;
		for(int j=0;j<q;j++){
			if(a[p[j].first.second-1]-a[p[j].first.first-1]==p[j].second.first)
			ha+=p[j].second.second;
		}
		ma=max(ha,ma);
		return;
	}
	for(int j=last;j<=m;j++){
		a[i]=j;
		ans(i+1,j,n,m,q,ma,a,p);
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		ll n,m,q;
		cin>>n>>m>>q;
		pair<pair<int,int>,pair<int,int>> p[q];
		for(int i=0;i<q;i++)
		cin>>p[i].first.first>>p[i].first.second>>p[i].second.first>>p[i].second.second;
		int a[n];
		memset(a,0,sizeof(a));
		int ma=0;
		ans(0,1,n,m,q,ma,a,p);
		cout<<ma;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
 int a,b,c;
 cin >> a >> b >> c;
 if (
  a*a==b*b+c*c ||
  b*b==a*a+c*c ||
  c*c==a*a+b*b
  )
  cout << "YES" << endl;
 else 
  cout << "NO" << endl;
 }
return 0;
}

Measured memory_bytes: 3028
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    ll n;
    cin>>n;
    string s[n];
    rep(i,n)
    {
        cin>>s[i];
    }
    unordered_map<string,ll> m;
    rep(i,n)
    {
        m[s[i]]++;
    }
    ll AC=0,WA=0,TLE=0,RE=0;
    for(auto x:m)
    {
        if(x.first=="AC")
        AC=x.second;
        else if(x.first=="WA")
        WA=x.second;
        else if(x.first=="TLE")
        TLE=x.second;
        else
        RE=x.second;
    }
    cout<<"AC"<<" x "<<AC<<endl<<"WA"<<" x "<<WA<<endl<<"TLE"<<" x "<<TLE<<endl<<"RE"<<" x "<<RE<<endl;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n;
    cin >> n;
    ll ans = 1;
    for(int i = 1; i * i <= n; i++){
        ans = i * i;
    }
    cout << ans << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if(a == b)
    cout << "Draw" << endl;
  else if(a == 1)
    cout << "Alice" << endl;
  else if(b == 1)
    cout << "Bob" << endl;
  else if(a > b)
    cout << "Alice" << endl;
  else
    cout << "Bob" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
 char ch;
 scanf("%c",&ch);
 ch=tolower(ch);
 if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
    printf("vowel\n");
 else
    printf("consonant\n");

}


Measured memory_bytes: 3168
from itertools import permutations

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

i = 0
a = 0
b = 0
for s in permutations(range(1, n+1)):
    for j in range(n):
        if p[j] != s[j]:
            break
    else:
        a = i
    for j in range(n):
        if q[j] != s[j]:
            break
    else:
        b = i
    i += 1

print(abs(a-b))


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

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

Measured memory_bytes: 256
package main

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

type Card struct{ Number, Stock int }
type Cards []Card

func (c Cards) Len() int           { return len(c) }
func (c Cards) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c Cards) Less(i, j int) bool { return c[i].Number > c[j].Number }

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	var sum int64
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
		sum += int64(as[i])
	}
	sort.Ints(as)
	var cs Cards = make([]Card, m)
	for i := range cs {
		sc.Scan()
		cs[i].Stock, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		cs[i].Number, _ = strconv.Atoi(sc.Text())
	}
	sort.Sort(cs)
	var p int
lb:
	for _, v := range cs {
		for i := 0; i < v.Stock; i++ {
			if p >= len(as) || v.Number < as[p] {
				break lb
			}
			sum += int64(v.Number - as[p])
			p++
		}
	}
	fmt.Println(sum)
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    string s;
    int n;
    cin >> n >> s;
    int r = count(all(s), 'R');
    int w = count(s.begin(), s.begin() + r, 'W');
    cout << w << endl;

    return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    set<int> A;
    rep(i,n){
        int Ai; cin >> Ai;
        A.insert(Ai);
    }
    int m; cin >> m;
    set<int> B;
    rep(i,m){
        int Bi; cin >> Bi;
        B.insert(Bi);
    }
    // 和集合
    set<int> C;
    for(auto Ai: A){
        if(!B.count(Ai)) C.insert(Ai);
    }
    for(auto Ci: C){
        cout << Ci << endl;
    }
}


Measured memory_bytes: 31220
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


m,k = LI()

if k >= 2**m:
    print(-1)
    quit()
if m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
elif m == 1:
    if k == 0:
        ans = [i for i in range(2**(m+1))]
        ans = [i//2 for i in ans]
        print(*ans)
    else:
        print(-1)
else:
    ans = [i for i in range(2**m) if i != k]
    ans = ans + [k] + ans[::-1] + [k]
    print(*ans)

Measured memory_bytes: 69360
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import           Unsafe.Coerce

main :: IO ()
main = do
    s <- B.getLine
    t <- B.getLine
    putStrLn . bool "No" "Yes" $ solve s t

solve :: B.ByteString -> B.ByteString -> Bool
solve s t = f s == f t
  where
    f x = L.sort . map B.length . B.group $ B.sort x


Measured memory_bytes: 1532
#include <iostream>

using namespace std;

int main() {
	int cards[4][13] = { 0 }, i, j, n, rank;
	char suit;
	cin >> n;
	for (i = 1; i <= n; i++) {
		cin >> suit >> rank;
		switch (suit){
		case 'S':
			cards[0][rank - 1] = 1;
			break;
		case 'H':
			cards[1][rank - 1] = 1;
			break;
		case 'C':
			cards[2][rank - 1] = 1;
			break;
		case 'D':
			cards[3][rank - 1] = 1;
			break;
		}
	}
	for (i = 0; i <= 3; i++) {
		for (j = 0; j <= 12; j++) {
			if (cards[i][j] == 0) {
				if (i == 0) cout << 'S' << " " << j + 1;
				else if (i == 1) cout << 'H' << " " << j + 1;
				else if (i == 2) cout << 'C' << " " << j + 1;
				else            cout << 'D' << " " << j + 1;
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

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

    vector<int> dsumn(n+1, 0);
    vector<int> p(m);
    for(int i=0; i<m; i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i=0; i<m-1; i++){
        int l = p[i];
        int u = p[i+1];
        if(l>u) swap(l,u);
        dsumn[l]++;
        dsumn[u]--;
    }
    for(int i=0; i<n; i++){
        dsumn[i+1] += dsumn[i];
    }

    long long int ans = 0;
    for(int i=0; i<n-1; i++){
        long long int a,b,c;
        cin >> a >> b >> c;
        if(a*dsumn[i] < c+b*dsumn[i]){
            ans += a*dsumn[i];
        }else{
            ans += c+b*dsumn[i];
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    if(n%10 == 3)cout << "bon" << endl;
    else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8)cout << "pon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n,m;
  	
  	n=sc.nextInt();
  	m=sc.nextInt();
  	
  	int[] s=new int[m];
  	char[] c=new char[m];
  	for(int i=0;i<m;i++){
  		s[i]=sc.nextInt();
  		c[i]=sc.next().charAt(0);
  	}
  	int f=0,g=0;
  	if(n==1){
  		for(int i=0;i<10;i++){
  			int e=0;
  			for(int j=0;j<m;j++){
  				String is=Integer.toString(i);
  				char[] ic=is.toCharArray();
  				if(ic[s[j]-1]==c[j]){
  					e++;
  				}else{
  					e=0;
  				}
  			}
  			if(e==m){
  				f++;
  				g=i;
  				break;
  			}
  		}
  	}else{
  		for(int i=(int)(Math.pow(10,n-1));i<(int)(Math.pow(10,n));i++){
  			int e=0;
  			for(int j=0;j<m;j++){
  				String is=Integer.toString(i);
  				char[] ic=is.toCharArray();
  				if(ic[s[j]-1]==c[j]){
  					e++;
  				}else{
  					e=0;
  				}
  			}
  			if(e==m){
  				f++;
  				g=i;
  				break;
  			}
  		}
  	}
  	if(f==0){
  		System.out.print(-1);
  	}else{
  		System.out.print(g);
  	}
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=10005;
int a[N],b[N];
void GG(){
	puts("No"); exit(0);
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	int n=read();
	For(i,1,n)a[i]=read();
	For(i,1,n)b[i]=read();
	ll sum=0,s=0;
	For(i,1,n)if(a[i]>b[i]){
		s+=a[i]-b[i]; b[i]=a[i];
	}
	For(i,1,n)if(a[i]<b[i]){
		int t=min(((ll)b[i]-a[i])/2,s);
		s-=t; a[i]+=t;
	}
	//cout<<sum<<" "<<s<<endl;
	if(s)GG();
	puts("Yes");
}

Measured memory_bytes: 3624
from heapq import heappush, heappop


def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
    # graph[v_from] = [(cost, v_to), ...]
    dist = [INF] * n

    dist[v_s] = 0
    heap = [(0, v_s)]  # heap = [(dist[v], v), ...]
    while heap:
        dist2v, v_from = heappop(heap)
        if dist[v_from] < dist2v:
            continue
        for cost, v_to in graph[v_from]:
            dist_cand = dist2v + cost
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist


n, m, s = map(int, input().split())

MAX_SILVER = 5005
n2 = MAX_SILVER * n
graph = [[] for _ in range(n2)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    for k in range(a, MAX_SILVER):
        graph[u * MAX_SILVER + k].append((b, v * MAX_SILVER + k - a))
        graph[v * MAX_SILVER + k].append((b, u * MAX_SILVER + k - a))
for i in range(n):
    c, d = map(int, input().split())
    for k in range(MAX_SILVER - 1):
        graph[i * MAX_SILVER + k].append(
            (d, i * MAX_SILVER + min(k + c, MAX_SILVER - 1)))

dist = dijkstra(graph, n2, 0 + min(s, MAX_SILVER - 1))

for i in range(1, n):
    ans_i = 10**20
    for k in range(MAX_SILVER):
        ans_i = min(ans_i, dist[i * MAX_SILVER + k])
    print(ans_i)


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

const int MOD = 1e9+7;
const int mxN = 300005;

int mat[100][100];

int countPairs(int N,int D)
{
    int count = 0;

    for(int i = 0; i < N - 1; i++)
    {
        for(int  j = i + 1; j < N ; j++)
        {
            int norm = 0;

            for(int k = 0; k < D; k++)
            {
                int d = abs(mat[i][k] - mat[j][k]);
                norm += (d*d);
            }

            bool flag = false;

            for(int k = 0; k <= norm; k++)
            {
                if(k*k == norm)
                    flag = true;
            }

            if(flag)
                count++;
        }
    }

    return count;
}

void solve()
{
    int N,D;
    cin>>N>>D;

    for(int i = 0; i < N ; i++)
    {
        for(int j = 0; j < D; j++)
        {
            cin>>mat[i][j];
        }
    }

    cout<<countPairs(N,D)<<endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// How to use 「map」
/*
  - 宣言
    map<{key_type}, {value_type}> salary;
  - 要素の挿入
    salary["Alice"] = 1000;
  - 要素の取得 O(logn)
    salary.at("Alice");
  - 要素の削除
    salary.erase("Alice");
  - キー検索
    salary.find("Alice"); -> true
    salary.find("Bob");   -> false
  - イテレーション
    for(auto& [key, value] : salary) {...}
 */
// -------------------------------------


// How to use 「lower_bound」, 「upper_bound」
/*
  vector<int> a = {1, 2, 3, 4, 5};
  auto iter1 = lower_bound(all(a), 3);  <- 第二引数「以上」の最小イテレータが返る
  auto iter2 = upper_bound(all(a), 3);  <- 第二引数「より大きい」最小のイテレータが返る
 */
// -------------------------------------


// How to use 「struct sort」
/*
  struct Person {
    string name;
    int age;

    Person(string _name, int _age) {
      name = _name;
      age = _age;
    }

    bool operator<(const Person &another) const {
      return age < another.age;
    }
  };

  vector<Person> people;
  people.pb(Person("Alice", 20));
  people.pb(Person("Bob", 19));
  people.pb(Person("John", 40));
  people.pb(Person("Chris", 30));
  sort(all(people));
 */
 // -------------------------------------

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



int main() {
  string s;
  cin >> s;

  map<char, int> c;
  rep(i, 4) {
    if(c.count(s[i]) != 0) c[s[i]]++;
    else c[s[i]] = 0;
  }

  int cnt = 0;
  for(auto a : c) {
    cnt++;
  }

  if(cnt == 2) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a,b) printf(a,b);
#define o(s) cout<< s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int a,b; cin>>a>>b;
    o((a-1)*(b-1));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, a;
    cin >> n;
    int bg[n], nd[n];
    fore(i,0,n) {
        cin >> a;
        bg[i] = a-1;
        nd[i] = a+1;
    }
    sort(bg, bg+n);
    sort(nd, nd+n);
    int i = 0, j = 0, mx = 0, cnt = 0;
    while (i < n && j < n) {
        if (bg[i] <= nd[j]) {
            i++;
            cnt++;
            mx = max(mx, cnt);
        } else {
            j++;
            cnt--;
        }
    }
    cout << mx << endl;
}


Measured memory_bytes: 1024
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n;
vector<ll> a;

void solve() {
    ll ans = 0;
    rep(i, n) {
        ans += a[i] / 2;
        if (i != n - 1 && a[i] != 1 && a[i] % 2 != 0) a[i + 1]++;
    }
    cout << ans << endl;
}

int main() {
    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];
    solve();
    return 0;
}

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

const int N =1e5+5;
long long frr[N];

int main()
{
    int n;
    cin>>n;
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        frr[a]++;
        sum+=a;
    }
    int q;
    cin>>q;
    while(q--)
    {
        long long a,b;
        cin>>a>>b;
        long long k=frr[a];
        frr[a]=0;
        sum-=(k*a);
        frr[b]+=k;
        sum+=(k*b);
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 4392
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 998244353
#define F first
#define S second

int A[1<<20], num, N, Q, B, C;
ll sum = 0;

int main() {

 //freopen("input.in","r",stdin);
 //freopen("output.out","w",stdout);

 cin>>N;
 rep(i, N) {cin>>num;sum+=num;A[num]++;}cin>>Q;
 while(Q--) {
   cin>>B>>C;
   sum -= 1LL*B*A[B];
   sum += 1LL*C*A[B];
   A[C] += A[B];
   A[B] = 0;
   cout<<sum<<endl;
 }

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

ll N,K; 
vector<ll> v_m,v_p;
ll num_m, num_p;
ll num_z = 0;

bool check_k_m(ll mid){
  ll num = 0;
  REP(i,num_p){
    ll x_div_a = (mid - v_p[i] + 1)/v_p[i];
    num += upper_bound(ALL(v_m),x_div_a)-v_m.begin();
  }
  return num>=K;
}

bool check_k_p(ll mid){
  ll num = 0;
  REP(i,num_m){
    ll x_div_a = mid/v_m[i];
    ll t = upper_bound(ALL(v_m),x_div_a)-v_m.begin();
    if(i<t){ --t;}
    num += t;
  }
  REP(i,num_p){
    ll x_div_a = mid/v_p[i];
    ll t = upper_bound(ALL(v_p),x_div_a)-v_p.begin();
    if(i<t){ --t;}
    num += t;
  }
  num /= 2;
  return num>=K;
}

int main(){
  cin>>N>>K;
  REP(i,N){
    ll a; cin>>a;
    if(a<0){ v_m.push_back(a); }
    else if(a>0){ v_p.push_back(a); }
    else{ ++num_z;}
  }
  num_m = v_m.size();
  num_p = v_p.size();
  
  ll num_mp = num_m * num_p;
  ll num_zp = num_z *(N - num_z) + num_z*(num_z-1)/2;
  if(K<=num_mp){
    sort(ALL(v_m));
    ll l = -1e18-1;
    ll u = 0;
    while(u-l>1){
      ll mid = (l+u)/2;
      if(check_k_m(mid)){
        u = mid;
      } else{
        l = mid;
      }
    }
    cout << u <<"\n";
  }else if(K<=num_mp+num_zp){
    cout << "0\n";
  }else{
    K -= (num_mp+num_zp);
    REP(i,num_m){ v_m[i] *= (-1); }
    sort(ALL(v_m));
    sort(ALL(v_p));
    ll l = -1;
    ll u = 1e18;
    while(u-l>1){
      ll mid = (l+u)/2;
      if(check_k_p(mid)){
        u = mid;
      }else{
        l = mid;
      }
    }
    cout << u <<"\n";
  }
}

Measured memory_bytes: 2420
#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

bool solve(int x) {
	if (x == 2) {
		return true;
	}

	if (x % 2 == 0) {
		return false;
	}

	for (int i = 3; i * i <= x; i += 2) {
		if (x % i == 0) {
			return false;
		}
	}

	return true;
}

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

	int n;
	int ans = 0;
	while (cin >> n) {
		ans += solve(n);
	}

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

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

int main() {
	ll n;
	cin >> n;
	ll all = 1;
	ll odd = 1;
	for (ll i = 0; i < n; ++i) {
		ll a;
		cin >> a;
		if (a % 2) {
			odd *= 1;
			all *= 3;
		}
		else {
			odd *= 2;
			all *= 3;
		}
	}
	cout << all - odd << endl;
}


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

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

    if(a<b) cout << "a < b" << endl;
    else if(a>b) cout << "a > b" << endl;
    else cout << "a == b" << endl;

    return 0;
}


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

int getsum();


int main()
{
    // 整数の入力
    int n, y;
    cin >> n >> y;

    int cnt = 0;
    int i, j, k;
    int tt = 0;
    int ft = 0;
    int th = 0;


    for(i = n; i >= 0; i--){
        
        for(j = n - i; j >= 0; j--){
            
            k = n - i - j;  
            if(10000 * k + 5000 * j + 1000 * i == y){
                tt = k;
                ft = j;
                th = i;

                if(tt + ft + th == n){
                    cnt++;
                }
                break;
            }
        }        
    }
    
    // 出力
    if(cnt != 0){
        cout << tt << " " << ft << " " << th << endl;
    }
    else{
        cout << -1 << " " << -1 << " " << -1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(void) {
    int a;
    int count[100] = {};
    int max = 0;
    while(std::cin >> a) {
        count[a - 1]++;
    }
    for (int i = 0; i < 100; i++) {
        if (count[i] > max) {
            max = count[i];
        }
    }

    for (int i = 0; i < 100; i++) {
        if (count[i] ==  max) {
            std::cout << i + 1 << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2988
#include <stdio.h>
int main(){
  int flag,n,i,a[100],key,c;

  c=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  
  flag=1;
  while(flag){
    flag = 0;
    for(i=n-1;i>=1;i--){
      if(a[i]<a[i-1]){
	key = a[i];
	a[i] = a[i-1];
	a[i-1] = key;
	c++;
	flag=1;
      }
      
    
    }
  }

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



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

using namespace std;

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 1, i = 1;
	for (int i = 1; i < n; ++i) {
		ans++;
		if (s[i - 1] == s[i]) ans--;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

int N,K;
int P[SIZE];
int BIT[SIZE];

void add(int loc,int value){

	BIT[loc] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

int getSum(int loc){

	int sum = BIT[loc];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}

int main(){

	scanf("%d %d",&N,&K);

	for(int i = 0; i < N; i++){

		scanf("%d",&P[i]);
	}

	if(K == N){

		int start;

		for(int i = 0; i < N; i++){

			if(P[i] == 1){

				start = i;
				break;
			}
		}

		bool FLG = true;

		for(int i = 1; i <= N; i++){

			int loc = (start+(i-1))%N;
			if(P[loc] != i){
				FLG = false;
				break;
			}
		}

		if(FLG){

			printf("Yes\n");

		}else{

			printf("No\n");
		}

	}else{

		if(K%2 == 0){

			printf("Yes\n");
			return 0;
		}

		ll rev_num = 0;

		for(int i = 0; i <= N; i++)BIT[i] = 0;

		for(int i = 0; i < N; i++){
			rev_num += i-getSum(P[i]);
			add(P[i],1);
		}

		if(rev_num%2 == 0){

			printf("Yes\n");
		}else{

			printf("No\n");
		}
	}

	return 0;
}



Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define pb push_back
#define F first
#define S second
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)

# define M_PIl          3.141592653589793238462643383279502884L /* pi */

const ll M=1e9+7;
const int MaxM=100005;


void SieveOfEratosthenes(int n)                                   //all prime <= n
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}


bool isPowerOfTwo (int x)
{
    return x && (!(x&(x-1)));
}



bool comp(pair<int,int> a,pair<int,int> b){
  if(a.F==b.F){
    return a.S>b.S;
  }
  return a.F<b.F;
}








void solve(){

  int n,k;
  cin>>n>>k;
int a[n],b[n];
for(int i=0;i<n;i++){
  cin>>a[i]>>b[i];
}

ll dp[n+1][k+1];
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++){
      for(int j=1;j<=k;j++){

      if(a[i-1]<=j){ dp[i][j]=max(b[i-1]+dp[i-1][j-a[i-1]],dp[i-1][j]);}
      else{dp[i][j]=dp[i-1][j];}

}
}
cout<<dp[n][k];
}

int main(){


   int t=1;
//  cin>>t;
   while(t--){
      solve();
       }

 }


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

int main(){
    int n,A[100];
    cin >> n;

    for(int i=0;i<n;i++) cin >> A[i];

    int flag = 1;
    int x=0;
    while(flag){
        flag = 0;
        for(int j=n-1;j>0;j--){
            int v = A[j];
            if(A[j]<A[j-1]) {
              swap(A[j],A[j-1]);
              flag = 1;
              x++;
        }
    }

    }
    for(int i=0;i<n;i++){
        if(i==0)cout << A[i];
        else cout << " " << A[i];
    }
    cout << endl;
    cout << x << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#define il inline
#define ri register
#define Size 300050
using namespace std;
int a[Size];
bool is[Size];
il void read(int&);
int main(){
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	int n,len(0);read(n),is[0]=is[n+1]=1;
	for(int i(1);i<=n;++i)read(a[i]),is[i]=i==a[i];
	for(int i(1),j,k,l,i1,i2;i<=n;){
		for(j=i;!is[j];++j);
		if(is[j-1]||is[j+1])++len,i=j+1;
		else{
			for(k=j+2;k<=n&&is[k]&&!is[k+1];k+=2);
			i=k,len+=k-j+1;
			for(l=j-1;l<k;++l)
				if(a[l]<j-1||a[l]>=k)return puts("No"),0;
			for(l=j-1,i1=i2=0;l<k;l+=2)
				if(a[l]<l){
					if(a[l]<i1)return puts("No"),0;
					else i1=a[l];
				}
				else{
					if(a[l]<i2)return puts("No"),0;
					else i2=a[l];
				}
		}
	}if(len^n)return puts("No"),0;
	return puts("Yes"),0;
}
il void read(int&x){
	x^=x;ri char c;while(c=getchar(),c<'0'||c>'9');
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}



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

int n,m;
long long dis[1001];//起点到各个点的距离 
struct edge{//边 
	int from;
	int to;
	long long w;
}e[500000];
bool jud[1001];//标记负圈上的点 

void BellmanFord(int p){
	for(int i = 1;i<=n;i++) dis[i] = 1e16;
	dis[p] = 0;
	for(int i = 1;i<n;i++){//无环,最多经过n-1条边，所以遍历n-1次 
		for(int j = 0;j<m;j++){
			int a = e[j].from;
			int b = e[j].to;
			long long w = e[j].w;
			if(dis[a]!=1e16&&dis[a]+w<dis[b]){
				dis[b] = dis[a]+w;
			}
		}
	}
	//判断是否存在负圈且标记负圈上的点 
	memset(jud,false,sizeof(jud)); 
	for(int i = 0;i<m;i++){
		int a = e[i].from;
		int b = e[i].to;
		long long w = e[i].w;
		if(dis[a]!=1e16&&dis[a]+w<dis[b]){
			jud[b] = true;//如果第n次还可以更新,则在负圈上 
		}
		if(jud[a]) jud[b] = true;//如果起点在负圈上,那么终点也在负圈上 
	}
}

int main(){
	int a,b;
	long long c;
	
	cin >> n >> m;
	for(int i = 0;i<m;i++){
		cin >> a >> b >> c;
		e[i].from = a;
		e[i].to = b;
		e[i].w = -c;//求最长路,将权值取相反数求最短路
	}
	BellmanFord(1);
	if(jud[n]) cout << "inf" << endl;//如果n在负圈上 
	else cout << -dis[n] << endl;
} 

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main(){
  priority_queue<int> pq;

  string a;
  int b;
  
  cin >> a;
  while(a != "end"){
    if(a == "insert"){
      cin >> b;
      pq.push(b);
    }
    if(a == "extract"){
      cout << pq.top() << endl;
      pq.pop();
    }
    cin >> a;
  }

  return (0);
}

Measured memory_bytes: 7012
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int MX=2005;

int g[MX][MX],ev[MX][MX],eh[MX][MX],v[MX][MX];
int n,m,q;
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++){
		static char t[MX];
		scanf("%s",t+1);
		for(int j=1;j<=m;j++)
			g[i][j]=t[j]-'0';
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			v[i][j]=v[i-1][j]+v[i][j-1]-v[i-1][j-1]+g[i][j];
	for(int i=2;i<=n;i++)
		for(int j=1;j<=m;j++)
			ev[i][j]=ev[i-1][j]+ev[i][j-1]-ev[i-1][j-1]+(g[i][j]&g[i-1][j]);
	for(int i=1;i<=n;i++)
		for(int j=2;j<=m;j++)
			eh[i][j]=eh[i-1][j]+eh[i][j-1]-eh[i-1][j-1]+(g[i][j]&g[i][j-1]);
	for(int i=1;i<=q;i++){
		int X1,Y1,X2,Y2;
		scanf("%d%d%d%d",&X1,&Y1,&X2,&Y2);
		printf("%d\n",
		(v[X2][Y2]-v[X1-1][Y2]-v[X2][Y1-1]+v[X1-1][Y1-1])
		-(ev[X2][Y2]-ev[X1][Y2]-ev[X2][Y1-1]+ev[X1][Y1-1])
		-(eh[X2][Y2]-eh[X1-1][Y2]-eh[X2][Y1]+eh[X1-1][Y1])
		);
	}
	return 0;
}


Measured memory_bytes: 64640
def main():
    N, T = map(int, input().split())
    C = []
    max_A = 0
    for _ in range(N):
        A, B = map(int, input().split())
        max_A = max(max_A, A)
        C.append((A,B))

    C.sort()

    dp = [[0] * (T + max_A) for _ in range(N+5)]
    for i in range(N):
        for t in range(T):
            dp[i+1][t+C[i][0]] = max(dp[i+1][t+C[i][0]], dp[i][t] + C[i][1])
            dp[i+1][t] = max(dp[i+1][t], dp[i][t])        

    ans = 0
    for i in range(N+1):
        ans = max(ans, max(dp[i]))

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 180824
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()

void Main()
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;

    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main() {
int64_t A,B,C,D,E,distance,s;
cin>>A>>B>>C>>D>>E;
distance=max(A,C)-min(A,C);
s=B-D;
 if(distance<=E*s){
cout  <<  "YES"<< endl;
 }
 else{
cout <<"NO"<<endl;
 }
}

Measured memory_bytes: 3592
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut b = Vec::with_capacity(n + 1);
    b.push((0, 0));
    for i in 0..n {
        b.push((a[i], i + 1));
    }
    b.sort();
    let mut ans = vec![0; n + 1];
    let mut index = b[n].1;
    for i in (1..(n + 1)).rev() {
        index = std::cmp::min(index, b[i].1);
        ans[index] += (b[i].0 - b[i - 1].0) * (n + 1 - i);
    }
    for i in 1..(n + 1) {
        writeln!(out, "{}", ans[i]).unwrap();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 11260