akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}

		ptr = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return buflen > 0;
	}

	private int readByte() {
		return hasNextByte() ? buffer[ptr++] : -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		long k = sc.nextLong();
		int n = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextLong();
		}

		long[] diff = new long[n];
		long diffSum = 0L;
		long diffMax = -1L;
		for (int i = 0; i < n; ++i) {
			diff[i] = (i < n - 1) ? a[i + 1] - a[i] : a[0] + k - a[n - 1];
			diffSum += diff[i];
			diffMax = Math.max(diffMax, diff[i]);
		}

		long ans = diffSum - diffMax;
		System.out.println(ans);
	}
}


Measured memory_bytes: 27732
x = int(input())
conf = list(map(int, input().split()))

conf.sort(reverse=True)

list=[]
list.append(conf[0])
conf.pop(0)
ans=0
re=1

for c in conf:
    ans+=list[0]
    list.append(c)
    re+=1
    if re==2:
        list.pop(0)
        re=0

print(ans)

Measured memory_bytes: 31684
s=input()
t=input()
score = 0
L = []
for i in range(len(s)-len(t)+1):
  k = s
  cut = k[i:i+len(t)]
  for j in range(len(t)):
    if cut[j] == t[j] or cut[j] =="?":
      score += 1
  if score == len(t):
    
    k = k[:i] + t + k[i+len(t):]
    L.append(k.replace("?","a"))
  score = 0
if L == []:
  print("UNRESTORABLE")
else:
  L = sorted(L)
  print(L[0])
    


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, m;
	cin >> n >> m;
	priority_queue<int> qu;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		qu.push(a);
	}
	for(int i = 0; i < m; i++){
		int a = qu.top();
		qu.pop();
		qu.push(a / 2);
	}
	long long int ans = 0;
	for(int i = 0; i < n; i++){
		ans += qu.top();
		qu.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 892
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    N=len(S)
    cnt = Counter(S)
    ans = 0
    for i,s in enumerate(S):
        cnt[s]-=1
        remain = N-i-1
        ans += remain - cnt[s]
    print(ans+1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 5968
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <stack>

using namespace std;

void main_(); signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  main_(); return 0;
}

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

void main_() {

  int N; cin >> N;
  stack<int> st;
  int ans = 0;  rep(i, N) {
    int a; cin >> a;
    if(!st.empty() && st.top() == a) { continue; }  // テゥツォツ佚」ツ?陛」ツ?古ゥツ?」テァツカツ堙」ツ?凖」ツつ凝」ツ?ョテ」ツ?ァテ」ツつケテ」ツδォテ」ツδシ
    if(st.empty() || st.top() < a) {
      st.push(a);
    }
    while(!st.empty() && st.top() > a) {
      st.pop(); ans ++;
    }
    if(st.empty() || st.top() != a) {
      st.push(a);
    }
  }
  
  cout << ans + st.size() << endl;

}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string num;
    int ans, digit;
    ans = 0;
    while(1){
        cin >> num;
        if(num == "0")  break;
        for (int i = 0; i < num.length(); ++i)
        {
            digit = num[i] -'0';
            ans += digit;
        }
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;

int n, a, b;

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	cin >> n >> a >> b;
}

void work ()
{
	// main work
	
	cout << max ( ( ( SC ( LL, n - 1 ) * b + a ) - ( SC ( LL, n - 1 ) * a + b ) + 1 ), 0LL ) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  string s;
  int n,k;
  cin >> n >> k >> s;
  s[k-1] += 32;
  cout << s;
  hinata;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

signed main() {
	IOS;
	int N,K;
	cin>>N>>K;
	vector<int> k(N);
	rep(i,K){
		int c;
		cin>>c;
		rep(j,c){
			int b;
			cin>>b;
			k[b-1]++;
		}
	}
	int cnt;
	cnt=0;
	rep(i,N){
		if(k[i]==0){
			cnt++;
		}
		
	}
	cout<<cnt<<endl;
	
		

}


Measured memory_bytes: 3664
N , K  = map(int,input().split())
S = [0 if s == "L" else 1 for s in input()]
def main():
    rep = 1
    pre = S[0]
    for s in S[1:]:
        if s != pre:
            rep += 1
        pre = s
    print(N - (rep - 2*K) if rep - 2*K > 0 else N - 1)
    return
main()


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

int main()
{
  int k;
  cin >> k;
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << v.at(k -1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
//言語は「C++14(GCC 5.4.1)」
//AtCoder Beginner Contest 156-B

int main(void)
{
	int i, N, K;
	int S=1;
	scanf("%d", &N);
	scanf("%d", &K);
	for (i = 0; i < 1000; i++)
	{
		S = S * K;
		if ((float)(N / S) < 1)
		{
			break;
		}
	}
	printf("%d", i+1);
  	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s < t) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int a[5];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    for(int i=1;i<=3;i++)a[i]=read();
    sort(a+1,a+4);
    if(a[2]==a[1] && a[2]!=a[3] || (a[1]!=a[2] && a[2]==a[3]))puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a<=b && a<=c && b<=c){
    cout<<a<<' '<<b<<' '<<c<<'\n';
  }else if(a<=b && a<=c && b>=c){
    cout<<a<<' '<<c<<' '<<b<<'\n';
  }else if(b<=a && b<=c && a<=c){
    cout<<b<<' '<<a<<' '<<c<<'\n';
  }else if(b<=a && b<=c && a>=c){
    cout<<b<<' '<<c<<' '<<a<<'\n';
  }else if(c<=a && c<=b && a<=b){
    cout<<c<<' '<<a<<' '<<b<<'\n';
  }else if(c<=a && c<=b && a>=b){
    cout<<c<<' '<<b<<' '<<a<<'\n';
  }
  return(0);
}



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

int main(){
  int N;
  cin >> N;
  
  vector<int> P(N);
  vector<int> M(N);
  int m = 2147483647;
  for(int i = 0; i < N; i++){
    cin >> P.at(i);
    m = min(m, P.at(i));
    M.at(i) = m;
  }
  
  int cnt = 0;
  for(int i =0; i < N; i++){
    if(M.at(i) == P.at(i)){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1792
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,t,a[200040];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>k>>n;
	for(;i<n;i++)cin>>a[i];
	sort(a,a+n);
	a[n]=a[0]+k;
	for(i=0;i++<n;)m=max(m,a[i]-a[i-1]);
	cout<<k-m;
}

Measured memory_bytes: 1792
# import bisect
# import heapq
# import math
# import random
# from fractions import gcd
# from collections import Counter, defaultdict, deque
# from decimal import Decimal
# from functools import lru_cache, reduce
# from itertools import combinations, combinations_with_replacement, product, permutations
# from operator import add, mul, sub, itemgetter
# import numpy as np

import sys
sys.setrecursionlimit(10000)

def read_int(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return int(read)

def read_int_n(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return [int(x) for x in read.split()]

def read_float(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return float(read)

def read_float_n(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return [float(x) for x in read.split()]

def read_str(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return str(read)

def read_str_n(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return [str(x) for x in read.split()]	
	
def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, K):
	if N+1 >= 2* K:
		ans = 'YES'
	else:
		ans = 'NO'
	return ans

def main():
	t = '''
	'''.splitlines()
	N, K = read_int_n()
	print(slv(N, K))

if __name__ == '__main__':
	main()

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

int main()
{
	int i,a[10],no1,no2,no3,x;
	no1=0; no2=0; no3=0;
	for(i=0;i<10;i++){
		cin>>a[i];
	}
	for(i=0;i<10;i++){
		if(no3<a[i]){ no3=a[i];}
		if(no2<no3){ x=no2; no2=no3; no3=x;}
		if(no1<no2){ x=no1; no1=no2; no2=x;}
	}
	cout<<no1<<endl<<no2<<endl<<no3<<endl;
}

Measured memory_bytes: 1160
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            double x = double.Parse(Console.ReadLine());
            int y = 1;
            double m = 100d;
            while(true){
                m += Math.Floor(m*0.01);
                if(x<=m){
                    Console.WriteLine(y);
                    return;
                }
                y++;
            }
        }
    }
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	string s; cin >> s;
	cout << s.front() << s.size()-2 << s.back() << endl;

	return 0;

}


Measured memory_bytes: 256
H,N = list(map(int, input().split()))
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]
 
# dp[damage] := モンスターに damage を与えるために必要な最小コスト
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
print(dp[-1]) 

Measured memory_bytes: 43996
#include <iostream>
#include <algorithm>

using namespace std;

const int NUM_MAX = 1001;
int dp[NUM_MAX][NUM_MAX];
int we[NUM_MAX], v[NUM_MAX];
int w, n;

void solve()
{
    int max_idx;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= w; j++) {
            if (j < we[i]) 
                dp[i + 1][j] = dp[i][j];
            else
                dp[i + 1][j] = max(dp[i][j], dp[i][j - we[i]] + v[i]);
        }
    }

    max_idx = 0;
    for (int j = 0; j <= w; j++)
        if (dp[n][j] == dp[n][w]) {
            max_idx = j;
            break;
        }
        
    cout << dp[n][w] << '\n' << max_idx << endl;
}

int main()
{
    int cas = 1;

    while (cin >> w, w) {
        char ch;

        cin >> n;
        for (int i = 0; i < n; i++)
            cin >> v[i] >> ch >> we[i];

        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= w; j++)
                dp[i][j] = 0;

        cout << "Case " << cas++ << ":\n";
        solve();
    }

    return 0;
}

Measured memory_bytes: 5080
#include <iostream>

using namespace std;

bool valid(int n) {
  for (int i=1; i<=9; i++) {
    if (n % i == 0 && n / i <= 9) return true;
  }
  return false;
}

int main() {
  int N; cin >> N;
  cout << (valid(N) ? "Yes" : "No") << endl;
}

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

#define _USE_MATH_DEFINES
#define reb(i,b,n)         for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n)           reb(i,0,n)
#define each(it,v)         for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v)        for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vsort(v)           sort((x).begin(), (x).end()
#define rvsort(v)          sort((x).rbegin(), (x).rend()
#define mp(a, b)           make_pair(a, b)
#define fi                 first
#define se                 second
#define pb                 push_back
#define dbg(x)             cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;
#define dbgArr(table, n)   rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define dbg2Arr(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}

using namespace std; using std::stringstream;

typedef long long       ll; typedef unsigned long long ull; typedef long double     ld;
typedef pair <int, int> P;  typedef pair <int, P>      PP;
typedef vector<int>     vi; typedef vector<vi>         vvi; typedef vector<ll>      vl;
typedef vector<P >      vP; typedef vector<char>       vc;  typedef vector<string>  vs;

static const int    INF  = 0x3f3f3f3f;
static const ll     INFL = 0x3f3f3f3f3f3f3f3fLL;
static const double EPS  = 1e-9;
static const ll     MOD  = 1000000007LL;

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

static bool isComp(const vi &v);

int N, M, X;
vi C;
vvi A;
ll ans = INFL;

static bool isComp(const vi &v) {
    bool ret = true;
    rep(i, M) {
        if (v[i] < X) ret = false;
    }
    return ret;
}

static void dfs(const int n_item, const int item_id, vi item, ll money) {
    // dbgArr(item, item.size());
    rep(i, M) {
        item[i] += A[item_id][i];
    }
    money += C[item_id];

    if (isComp(item)) {
        ans = min(ans, money);
        return;
    } else if (n_item == N) {
        return;
    }

    reb(i, item_id+1, N) {
        dfs(n_item+1, i, item, money);
    }
}

int main(int argc, char *argv[])
{
    cin >> N >> M >> X;

    C = vi(N);
    A = vvi(N, vi(M));

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

    rep(i, N) {
        dfs(0, i, vi(M, 0), 0);
    }

    if (ans == INFL) { ans = -1; }
    cout << ans << endl;

    return 0;
}


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

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

int main(){
    int n, t;
    cin >> n >> t;
    vector<P> ab;
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        ab.push_back(P(a,b));
    }
    sort(ab.begin(), ab.end());
    ll ans = 0;
    ll dp1[3005]={0};
    fill(dp1, dp1+3005, -1);
    dp1[0] = 0;
    ll dp2[3005];
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < t; j++)dp2[j] = dp1[j];
        for(int j = 0; j < t; j++){
            if(dp1[j]==-1)continue;
            if(j+ab[i-1].first >= t)ans = max(dp1[j]+ab[i-1].second, ans);
            else{
                dp2[j+ab[i-1].first] = max(dp1[j]+ab[i-1].second, dp1[j+ab[i-1].first]);
            }
        }
        for(int j = 0; j < t; j++)dp1[j] = dp2[j];
    }
    for(int i = 0; i < t; i++)ans = max(ans, dp1[i]);
    cout << ans << endl;
    return 0;
}

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

void search_plus(vector<long long> &a, vector<long long> &b, long long k) {
    long long asz = a.size(); long long bsz = b.size();
    long long left = 0; long long right = (long long) 1e18 + 10;
    auto count = [&](vector<long long> &v, long long c) {
        long long ret = 0;
        for (int i = 0; i < v.size(); i++) {
            long long d = v[i];
            if (d * d >= c) ret--;
            auto it = lower_bound(v.begin(), v.end(), (c+d-1) / d);
            ret += v.end() - it;
        }
        return ret / 2;
    };
    while (right - left > 1) {
        long long x = (right + left) / 2;
        long long up = count(a, x) + count(b, x);
        if (k <= up) left = x;
        else right = x;
    }
    cout << left << "\n";
    return;
}

void search_minus(vector<long long> &a, vector<long long> &b, long long k) {
    long long asz = a.size(); long long bsz = b.size();
    auto count = [&](vector<long long> &v, vector<long long> &w, long long c) {
        long long ret = 0;
        for (int i = 0; i < v.size(); i++) {
            long long d = v[i];
            auto it = lower_bound(w.begin(), w.end(), (c+d-1) / d);
            ret += w.end() - it;
        }
        return ret;
    };
    long long left = 0; long long right = (long long) 1e18 + 10;
    while (right - left > 1) {
        long long x = (right + left) / 2;
        long long up = count(a, b, x);
        if (k <= up) left = x;
        else right = x;
    }
    cout << -left << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long n, k; cin >> n >> k;
    k = n * (n-1) / 2 - k + 1;
    vector<long long> a, b; long long z = 0;
    for (int i = 0; i < n; i++) {
        long long c; cin >> c;
        if (c == 0) z++;
        else if (c > 0) a.emplace_back(c);
        else b.emplace_back(-c);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    long long asz = a.size(); long long bsz = b.size();
    long long plus = asz * (asz-1) / 2 + bsz * (bsz-1) / 2;
    if (k <= plus) search_plus(a, b, k);
    else {
        k -= plus;
        long long zero = z * (asz + bsz) + z * (z-1) / 2;
        if (k <= zero) cout << 0 << "\n";
        else {
            k -= zero;
            search_minus(a, b, asz * bsz - k + 1);
        }
    }
    return 0;
}

Measured memory_bytes: 2420
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <string>
#include <numeric>
#include <tuple>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<intmax_t> w(n);
  for (auto& wi: w) scanf("%jd", &wi);

  intmax_t left = 0;
  intmax_t right = std::accumulate(w.begin(), w.end(), 0);
  intmax_t res = right;
  for (size_t i = 0; i < n; ++i) {
    left += w[i];
    right -= w[i];
    res = std::min(res, std::abs(left-right));
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl

using namespace std;
typedef long long int ll;
typedef string::const_iterator State;
typedef pair<int,int> P;
class ParseError {};
const ll INF=1LL<<50;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-14;
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003



int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

/*struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
*/
//char c[520][520];
long long mod=1000000007;
long long pow(ll i,ll j){
	ll tmp=1;
	while(j){
		if(j%2) tmp=tmp*i%mod;
		i=i*i%mod;
		j/=2;
	}
	return tmp;
}

int expression(State&);
int term(State&);
int factor(State&);
int number(State&);
int expression(State &begin){
	int ret = term(begin);
	
	for(;;){
		if(*begin == '+'){
			begin++;
			ret += term(begin);
		}
		else if(*begin == '-'){
			begin++;
			ret -= term(begin);
		}
		else
			break;
	}
	return ret;
}

int term(State &begin){
	int ret = factor(begin);
	
	for(;;){
		if(*begin=='*'){
			begin++;
			ret *= factor(begin);
		}
		else if(*begin=='/'){
			begin++;
			ret /= factor(begin);
		}
		else
			break;
	}
	return ret;
}

int factor(State &begin){
	int ret;
	if(*begin == '('){
		begin++;
		ret = expression(begin);
		begin++;
	}
	else
	ret = number(begin);
	
	return ret;

}

int number(State &begin){
	int ret =0;
	
	while(isdigit(*begin)){
		ret*=10;
		ret+=*begin - '0';
		begin++;
	}
	return ret;
}




int main(void){

	
	ll x,a,b;
	ll ans=0;
	cin>>x>>a>>b;

	ans-=a;
	ans+=b;
	
	if(ans<=0){
		cout<<"delicious"<<endl;
	}
	else if(ans<=x){
		cout<<"safe"<<endl;
	}
	else
		cout<<"dangerous"<<endl;
		
}

Measured memory_bytes: 256
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    string s;
    cin >> s;
    rep(i, 0, 3)
    {
        if (s[i] == '7')
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
// 問題の URL を書いておく
// 

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif
const uint64_t Limit = 1000000000000000000;

int main(int, const char**)
{
    int n;
    cin >> n;
    auto a = InputVector<uint64_t>(n);
    uint64_t ans = 1;
    for(int i = 0; i < n; ++i)
    {
        if(a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < n; ++i)
    {
        auto nans = ans * a[i];
        if(nans / a[i] != ans)
        {
            cout << -1 << endl;
            return 0;
        }
        ans = nans;
        if(ans > Limit)
        {
//            cout << ans << endl;
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;
/*int dfs(vector<int> &T, vector<int> &C, int i, int sum, int g, int count){
   
}*/

int main(){
  int x, y, a, b, c, i;
  cin >> x >> y >> a >> b >> c;
  vector<int64_t>  P(a);
  vector<int64_t>  Q(b);
  vector<int64_t>  R(c);
  int s = x+y+c;
  vector<int>  A(s);
  rep(i, a) cin >> P[i];
  rep(i, b) cin >> Q[i];
  //rep(i, c) cin >> R[i];

  sort(P.begin(), P.end());
  sort(Q.begin(), Q.end());
  //sort(R.begin(), R.end());
  reverse(P.begin(), P.end());
  reverse(Q.begin(), Q.end());
  //reverse(R.begin(), R.end());
  int g = x+y;
  int64_t sum=0;
  for(i=0; i<x; i++){
    //sum += P[i];
    A[i] = P[i];
  }
  for(i=0; i<y; i++) {
    //sum += Q[i];
    int q = i + x;
    A[q] = Q[i];  
  }
  for(i=0; i<c; i++){
    int q = i + g;
    cin >> A[q];
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  //rep(i, s) cout << A[i] << endl;

  rep(i, g) sum += A[i];


  cout << sum << endl;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin >> a;
	double arr[a + 50];
	for(int i=1; i<=a; i++)
		cin >> arr[i];
	double dp[a + 5][a + 5];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for(int i=1; i<=a; i++)
	{
		for(int j=0; j<=i; j++)
		{
			int head = j, tail = i - j;
			if(head > 0) dp[head][tail] += dp[head - 1][tail] * arr[i];
			if(tail > 0) dp[head][tail] += dp[head][tail - 1] * (1 - arr[i]);
		}
	}
	double ans = 0;
	for(int i=a - (a / 2); i<=a; i++)
		ans += dp[i][a - i];
	printf("%.10lf",ans);
	return 0; 
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k, x, y;  
  cin >> n >> k >> x >> y;
  int price = 0;
  if(n>k){
  cout << x*k + y*(n-k) << endl;}
  else{
  cout << x*n << endl;}
}

Measured memory_bytes: 3564
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    private static Map<Integer, String> integerMap_ = new HashMap<Integer, String>();

    private static Map<String, Integer> stringMap_ = new HashMap<String, Integer>();;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        scan.close();

        integerMap_.put(1, "a");
        integerMap_.put(2, "b");
        integerMap_.put(3, "c");
        integerMap_.put(4, "d");
        integerMap_.put(5, "e");
        integerMap_.put(6, "f");
        integerMap_.put(7, "g");
        integerMap_.put(8, "h");
        integerMap_.put(9, "i");
        integerMap_.put(10, "j");

        stringMap_.put("a", 1);
        stringMap_.put("b", 2);
        stringMap_.put("c", 3);
        stringMap_.put("d", 4);
        stringMap_.put("e", 5);
        stringMap_.put("f", 6);
        stringMap_.put("g", 7);
        stringMap_.put("h", 8);
        stringMap_.put("i", 9);
        stringMap_.put("j", 10);

        List<String> list = func(n);

        Collections.sort(list);

        for (String s : list) {
            System.out.println(s);
        }

    }

    private static List<String> func(int n) {
        List<String> list = new ArrayList<String>();
        if (n == 1) {
            list.add("a");
        } else {
            List<String> prevList = func(n - 1);
            for (String s : prevList) {
                // 含まれていない文字の探索
                String last = "a";
                for (int i = 1; i <= 10; i++) {
                    if (!s.contains(integerMap_.get(i))) {
                        last = integerMap_.get(i);
                        break;
                    }
                }

                for (int i = 1; i <= stringMap_.get(last); i++) {
                    String newString = s + integerMap_.get(i);
                    list.add(newString);
                }
            }
        }
        return list;
    }

}


Measured memory_bytes: 53168
#include <iostream>

int main()
{
  int A, B, X;
  std::cin >> A >> B >> X;

  if (X >= A && X <= A + B ) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
  
  return 0;
}


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

using ll = long long;

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    priority_queue<int> que;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for(int i = 0; i < n; ++i) {
        cin >> b[i];
        que.push(a[i] - b[i]);
    }

    int ans = 0;
    ll sum = 0;
    for(int i = 0; i < n; ++i) {
        if(a[i] < b[i]) {
            while(sum < b[i] - a[i] && !que.empty()) {
                sum += max(0, que.top());
                que.pop();
                ans += 1;
            }
            if(sum < b[i] - a[i]) {
                ans = -1;
                break;
            }
            ans += 1;
            sum -= b[i] - a[i];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1660
N, M = map(int, input().split())
*H, = map(int, input().split())
good = [True] * N
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    good[a] &= H[a] > H[b]
    good[b] &= H[b] > H[a]
print(sum(good))

Measured memory_bytes: 20128
N=int(input())
B=list(map(int,input().split()))

ans=[]
while len(B):
  for i in range(len(B)-1,-1,-1):
    if i+1==B[i]:
      ans.append(B[i])
      del B[i]
      break
    if i==0:
      print(-1)
      exit()

ans=ans[::-1]
for a in ans:
  print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <stack>

using namespace std;

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

	cin >> n;
	cin >> a;
	cin >> b;


	cout << min(n*a,b) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        List<Integer> candidates = new ArrayList<>();
        for (int i = 0; i < M; i++) {
            candidates.add(scan.nextInt());
        }
        int[] match = {2,5,5,4,5,6,3,7,6};
        String[] dp = new String[N+10];
        for (int i = 0; i < N+10; i++) {
            dp[i] = "-";
        }
        dp[0] = "";
        for (int i = 0; i < N; i++) {
            if ("-".equals(dp[i])) {
                continue;
            }
            for (int a : candidates) {
                dp[i + match[a-1]] = max(dp[i + match[a-1]], dp[i] + a);
            }
        }
        System.out.println(dp[N]);
    }
    private String max(String a, String b) {
        if ("-".equals(a)) {
            a = b;
        }
        if (a.length() < b.length()) {
            return b;
        }
        if (a.length() > b.length()) {
            return a;
        }
        if (a.compareTo(b) < 0) {
            return b;
        }
        return a;
    }

}


Measured memory_bytes: 380600
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h,w;
    cin>>h>>w;

    char s[52][52];

    for (int i = 0; i < 52; i++){
            for (int j = 0; j < 52; j++){
                s[i][j] = '.';
            }
    }

    for (int i=1;i<h+1;i++) {
        for (int j=1;j<w+1;j++) {
            cin>>s[i][j];
        }
    }

    for (int i=1;i<h+1;i++) {
        for (int j=1;j<w+1;j++) {
            if(s[i][j]=='#'){
                cout<<s[i][j];
            }
            else {
                int count=0;
                for (int k=-1;k<=1;k++) {
                    for(int l=-1;l<=1;l++){
                        if(s[i+k][j+l]=='#'){
                            count++;
                        }
                    }
                }
                cout<<count;
            }
        }
        cout<<endl;
    }
}



Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
    input! {
        n:usize,
        a:[usize;n]
    }
    let mut max = a[0];
    let mut ans = 0;
    for i in a {
        ans += if i < max { max - i } else { 0 };
        max = std::cmp::max(max, i);
    }
    println!("{}", ans);
}


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

int main(){
	int i, j, k ,n,m,l,f;
	string a, b, c;
	cin >> a >> b >> c;
	cout << "A" << b[0] << "C" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N,W;
ll dp[110][100005];
int main(){
    cin >> N >> W;
    vector<ll> w(N+1),v(N+1);
    rep1(i,N) cin >> w[i] >> v[i];
    rep(i,100005) dp[0][i] = 1e9+100;
    dp[0][0] = 0;
    
    rep1(i,N) rep(j,100005){
        if(j >= v[i]) dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
        else dp[i][j] = dp[i-1][j];
    }
    
    rrep(i,100004) if(dp[N][i] <= W){ pr(i); return 0;}
}

Measured memory_bytes: 80128
using System;
class Program
{
	static void Main(string[] args)
	{
		int[] a = new int[5];
        int b = -1;
		string[] input = Console.ReadLine().Split(' ');
        for (int i = 0; i < input.Length; i++)
        {
			a[i] = int.Parse(input[i]);
            if (a[i] == 0)
            {
                b = i + 1;
            }
        }
        Console.WriteLine(b);
	}
}

Measured memory_bytes: 27552
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  int res = 0;
  while (n--) {
    int h; cin >> h;
    res += h >= k;
  }
  cout << res << '\n';
}


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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
constexpr int N_MAX = 1e5;

// 0 +繰越
// 1 -繰越
//
// dp[i][j] i番目において、
//   j 0 + carry
//     1 - carry
ll dp[N_MAX][2] = {0};

int main(int argc, char** argv) {
  for (int i=0; i<N_MAX; i++) {
    for (int j=0; j<2; j++) {
      dp[i][j] = -LINF;
    }
  }

  int N;
  cin >> N;
  vll A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }

  dp[0][0] = A[0];
  dp[0][1] = -A[0];

  for (int i=1; i<N; i++) {
    dp[i][0] = max({dp[i-1][0]+A[i], dp[i-1][1]-A[i]});
    dp[i][1] = max({dp[i-1][0]-A[i], dp[i-1][1]+A[i]});
  }

  cout << max({dp[N-2][0]+A[N-1], dp[N-2][1]-A[N-1]}) << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

vector<int>a,b;
int x,y;

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

  string s;cin>>s;
  cin>>x>>y;

  int i=0;
  int turn=0;
  while(i<s.size()){
    int c=0;
    while(i+c<s.size()&&s[i+c]=='F'){
      c++;
    }
    if(turn%2==0){
      a.push_back(c);
    }
    else{
      b.push_back(c);
    }
    i+=c+1;
    turn++;
  }

  if(false){
    cerr<<"a: ";
    rep(i,0,a.size()){
      cerr<<a[i]<<(i==a.size()-1?'\n':' ');
    }
    cerr<<"b: ";
    rep(i,0,b.size()){
      cerr<<b[i]<<(i==b.size()-1?'\n':' ');
    }
  }

  set<int>set_a;
  set_a.insert(a[0]);
  rep(i,1,a.size()){
    set<int>t;
    for(auto &d:set_a){
      t.insert(d+a[i]);
      t.insert(d-a[i]);
    }
    set_a=t;
  }

  if(false){
    for(auto d:set_a){
      cerr<<d<<endl;
    }
  } 

  set<int>set_b;
  set_b.insert(0);
  rep(i,0,b.size()){
    set<int>t;
    for(auto &d:set_b){
      t.insert(d+b[i]);
      t.insert(d-b[i]);
    }
    set_b=t;
  }
  if(false){
    for(auto d:set_b){
      cerr<<d<<endl;
    }
  } 

  if(set_a.count(x)&&set_b.count(y)){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
  return 0;
}


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

using namespace std;
int a[1002];
bool cmp(int a,int b){return a>b;}
int main(){
	int n,m;
	double sum = 0;
	cin>>n>>m;
	for(int i = 1 ; i <= n ; i++){
		cin>>a[i];
		sum+=a[i];
	}
//	cout<<sum<<endl;
	sum/=1.0*(4*m);
//	cout<<sum<<endl;
	int cnt = 0;
	sort(a+1,a+1+n);
	for(int i = 1 ; i <= n ; i++){
	//	cout<<a[i]<<endl;
		if(a[i] >= sum){
			cnt++;
///			puts("**");	
		}
	}
//	cout<<cnt<<endl;
	if(cnt>=m)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    for(int i=X;i>0;i--){
      if(isRui(i)){
        System.out.println(i);
        return;
      }
    }
  }
  
  public static boolean isRui(int n){
     boolean res = false;
    for(int i=1;i<=n;i++){
      for(int j=2;j<12;j++){
        if(Math.pow(i,j)==n){
          return true;
        }
      }
    }
    return res;
  }
  
}

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


using namespace std;

/*int main(){
    int N;
    cin >> N;
    vector<tuple<string,int,int>> tup;
    string s;
    int a;

    for(int i = 0; i < N; i++){
        cin >> s >>a ;
        get<0>(tup[i]) = s;
        get<1>(tup[i]) = a;
        get<2>(tup[i]) = i+1;
    }
    sort(tup.begin(),tup.end());

    for(int i = 0; i < N-1 ;i++){
        for(int j = i+1; j < N; j++){
            if(get<0>(tup[i]) == get<0>(tup[j])){
                if(get<1>(tup[i]) < get<1>(tup[j])){
                    tuple<string,int,int> temp;
                    temp = tup[i];
                    tup[i] = tup[j];
                    tup[j] = temp;
                }
            }
        }
    }

    for(int i = 0; i < N; i++){
        cout << get<2>(tup[i]) << endl;
    }
    return 0;

}*/

struct BOOK{
    string s;
    int point;
    int num;
};

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

    struct BOOK book[N];

    for(int i = 0; i < N; i++){
        cin >> book[i].s >> book[i].point;
        book[i].num = i+1;
    }

    for(int i = 0;i < N-1; i++){
        for(int j = i+1; j < N; j++){
            if(book[i].s > book[j].s){
                swap(book[i],book[j]);
            }else if(book[i].s == book[j].s){
                if(book[i].point < book[j].point){
                    swap(book[i],book[j]);
                }
            }
        }
    }
    
    for(int i = 0; i < N; i++){
        cout << book[i].num << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, W = [int(i) for i in input().split()]
weight = [0]
value = [0]
for _ in range(N):
    temp1, temp2 = [int(i) for i in input().split()]
    weight.append(temp1)
    value.append(temp2)

dp = [[0] * (W + 1) for N in range(N + 1)]
#%%
for i in range(1, N + 1):
    for j in range(1, W + 1):
        if weight[i] <= j:
            dp[i][j] = max(value[i] + dp[i - 1][j - weight[i]] , dp[i - 1][j])
        else:
            dp[i][j] = dp[i - 1][j]

print(dp[N][W])


Measured memory_bytes: 149672
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();
        
        if ((e - a) <= k) {
            System.out.println("Yay!");
            return;
        }
        
        System.out.println(":(");
    
        
        
    }
}


Measured memory_bytes: 21844
#include <iostream>

int main()
{
	std::string n;
	std::cin >> n;
	
	int sum = 0;
	for (auto e : n) {
		sum += e - '0';
		sum %= 9;
	}
	
	std::cout << (sum == 0 ? "Yes" : "No") << std::endl;
	
	return 0;
}


Measured memory_bytes: 3372