akhauriyash/Code-Regression huggingface dataset:
N, W = map(int, input().split())
MAX_V = 10**5+1
dp = [float('inf')] * MAX_V
dp[0] = 0
for _ in range(N):
    w, v = map(int, input().split())
    for sum_v in range(MAX_V)[::-1]:
        if sum_v >= v:
            dp[sum_v] = min(dp[sum_v - v] + w, dp[sum_v])
        else:
            dp[sum_v] = min(dp[sum_v], w)
ans = 0
for v in range(MAX_V)[:: -1]:
    if dp[v] <= W:
        ans = v
        break
print(ans)


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

int main() {
  int r,g,b;
  cin >>r>>g>>b;
  int kazu=g*10+b;
  if(kazu%4==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N;
    cin >> N;
    REP(i, 10)
    {
        int t = pow(2, i);
        if (t > N)
        {
            cout << pow(2, i - 1) << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 

const int N = 1e4 + 123;
const int M = 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int Sz = 501;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}

int a, b;

int calc(int a, int b) {
  if (a <= b) return b - a;
  return 2 * inf;
}

void solve() { 
  cin >> a >> b;
  cout << min({calc(-a, b) + 1, calc(a, b), calc(-a, -b) + 2, calc(a, -b) + 1}) << endl;
}
  
int main() {
  #ifdef wws
   freopen("in", "r", stdin);
   // freopen("in", "w", stdout);
  #endif 
  ios_base::sync_with_stdio(0);
  int tt = 1; 
  while(tt--) solve();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

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

    vector<int> P(n);
    for (int i = 0; i < n; i++) {
        cin >> P.at(i);
    }

    int cnt = 0;

    for(int i = 1; i < n - 1; i++) {
        int maxP = max(P.at(i - 1), max(P.at(i), P.at(i + 1)));
        int minP = min(P.at(i - 1), min(P.at(i), P.at(i + 1)));
        int middleP = P.at(i - 1) + P.at(i) + P.at(i + 1) - maxP - minP;

        if (P.at(i) == middleP) {
            cnt++;
        }
    }

    cout << cnt << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  string b;
  cin>>n>>b;
  string s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  int ans=0;
  for(int i=0;i<n;i++){
    bool f=0;
    for(int j=0;j<(int)s[i].size();j++){
      for(int k=1;k<=(int)s[i].size();k++){
	string a;
	for(int l=j;l<(int)s[i].size();l+=k){
	  a+=s[i][l];
	  f|=a==b;
	}
      }
    }
    ans+=f;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3180
//by azidoazideazide(c2n14)
#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
#define pb push_back
#define fi first
#define se second
#define INF 1e8

vector<pii> adj[100005];
priority_queue<pii, vector<pii>, greater<pii>> q;
bool vis[100005];
int mnw[100005], ans; //min weight of edge to v

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0,u,v,w;i<m;i++){
		cin>>u>>v>>w;
		adj[u].pb({v,w});
		adj[v].pb({u,w});
	}
	
	for(int i=1;i<=n;i++) mnw[i]=INF;
	mnw[0]=0;
	q.push({0,0});
	while(!q.empty()){
		int fd=q.top().fi, from=q.top().se;
		q.pop();
		if(fd!=mnw[from])  continue;

		vis[from]=1;
		ans+=mnw[from];
		
		for(pii x:adj[from]){
			int to=x.fi, w=x.se;
			if(!vis[to]&&w<mnw[to]){
				mnw[to]=w;
				q.push({mnw[to],to});
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 8336
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import Data.Ix



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readTuple4 :: IO (Int, Int, Int, Int)
readTuple4 = do
    [a, b, c, d] <- readInts
    return (a, b, c, d)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

data Hand = R | P | S deriving (Show, Eq,Ord, Ix)

winHand :: Char -> Hand
winHand 'r' = P
winHand 'p' = S
winHand 's' = R


main = do
    (k, s) <- readTuple2
    let ans = length $ do
            x <- [0..min k s]
            y <- [0..(s - x)]
            let z = s - x - y
            guard $ x <= k && y <= k && z <= k
            pure ()
    print ans


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

int main() {
	string s, p;
	getline(cin, s);
	getline(cin, p);
	string::size_type idx;
	bool b = false;
	for (int i = 0; i < s.size(); i++) {
		string temp = s.substr(i) + s.substr(0, i);
		idx = temp.find(p);
		if (idx != string::npos) {
			b = true;
			break;
		}
	}
	if (b) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


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

int main() {
  int N, count=1; cin >> N;
  
  vector<int> a(N);
  vector<int> b(N);
  for(int i=0; i<N; i++) cin >> a.at(i);
  
  if (a.at(0) == 2) cout << 1; 
  else{
    b.at(0) = a.at(0);
 	for (int i=1; i<N; i++){
      b.at(i) = a.at(b.at(i-1)-1);
 	  count++;
      if (b.at(i) == 2){
      	cout << count;
  	  	break;
      }
    }
  if(count == N) cout << -1;
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[500],stack[500],t;//t用来存出栈元素
    int top=0;//指针初始化0
    cin>>a;//读入
    for(int i=0;i<strlen(a);i++)
    {
        if(a[i]=='F'&&top==0)
        continue;//如果栈是空的且读到了F，就进行下一次循环
        else if(a[i]=='C')
        {      
        stack[top++]=a[i];//读到了C就进栈
        }
        else
        { 
            if(a[i]=='F')
            {
            t=stack[--top];//读到F就出栈
            break;//因为已经有一对CF了，所以后面没必要读下去，那么就跳出了
            }
        }
    }
    if(t=='C')
    cout<<"Yes"<<endl;//如果出来的是C就Yes
    else
    cout<<"No"<<endl;//否则No

}

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

int main(void) {
    long long x;
    scanf("%lld",&x);
    long long v=100;
    for(int i=1;;i++) {
        v+=v/100;
        if (v>=x) {
            printf("%d",i);
            return 0;
        }
    }
}

Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

int main() {
	int n, i, j;
	string s, k;
	bool flag;

	cin >> n;

	string a[n];

	cin >> s;
	a[0] = s;
	flag = false;
	for (i = 1; i < n; i++) {
		cin >> k;
		if (s[s.size() - 1] != k[0]) {
			flag = true;
		}
		a[i] = k;
		s = k;
	}
	if (flag) {
		cout << "No";
		return 0;
	}

	for (i = 0; i < n-1; i++) {
		for (j = i + 1; j < n; j++) {
			if (a[i] == a[j]) {
				cout << "No";
				return 0;
			}
		}
	}

	cout << "Yes";


	return 0;
}

Measured memory_bytes: 256
H,W = list(map(int,input().split()))
N = int(input())
a = list(map(int,input().split()))
ansline = []
for i in range(N):
    ansline += [i+1 for j in range(a[i])]
def split_list(l, n):
    for idx in range(0, len(l), n):
        yield l[idx:idx + n]
ans = list(split_list(ansline,W))
for i in range(1,H,2):
    ans[i].reverse()
for i in ans:
    print(*i)

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define int ll
#define tcase int t; cin>> t; for( ; t; --t)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;

int n;

int32_t main(){
	fastio;
	int m;
	cin>> n >> m;

	int a = 0;
	for(int i = 0; i<m; ++i){
		int aux;
		cin>> aux;
		a+=aux;
	}

	cout<< (a<=n? n-a : -1)<< endl;

	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>


using namespace std;
using ll = long long;

const ll mod = 1000000007;

int L, R;

int main()
{
	cin >> L >> R;
	if (R - L + 1 >= 2019)
	{
		cout << 0 << endl;
		return 0;
	}
	int l = 0, r = 0;
	l = L % 2019;
	r = R % 2019;
	if (r <= l)
	{
		cout << 0 << endl;
		return 0;
	}
	int ans = 100000;
	for (int i = l; i <=r; i++)
	{
		for (int j = i + 1; j <= r; j++)
		{
			ans = min(ans, (i * j) % 2019);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		String[] nums = sc.nextLine().split(" ");
		int cont = 1;
		int bump = Integer.parseInt(nums[0]);
		for(int i = 1; i < nums.length; i++ ) {
			if(Integer.parseInt(nums[i])<bump){
				bump = Integer.parseInt(nums[i]);
				cont++;
			}
		}	
		System.out.println(cont);
	}

}

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

int main()
{
    char c;
    cin >> c;
    char ans = c + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        mp[a]=1;
    }
    cout<<mp.size();
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String a = in.readLine();
    String b = in.readLine();
    String result = "";
    if(a.equals(b))
      result = "EQUAL";
    else if(a.length() > b.length())
      result = "GREATER";
    else if(a.length() < b.length())
      result = "LESS";
    else {
      if(a.compareTo(b) < 0)
        result = "LESS";
      else
        result = "GREATER";
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 32420
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()
inl = LI()
if len(set(inl)) == N:
    print('YES')
else:
    print('NO')


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



int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    int ans = a*b/2;
    cout << ans << endl;
    
    
    
    return 0;
}















































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

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

ll lcm(ll x, ll y)
{
  return x / gcd(x, y) * y;
}

int main()
{
  int a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
		    int H = sc.nextInt();
		    int W = sc.nextInt();
		    if (H == 0 && W == 0) break;
		    
		    for (int i = 1; i<=H; i++) {
		        for (int t= 1; t<=W; t++) {
		            if (t == 1 || i == 1 || i == H || t == W) {
		                System.out.print("#");
		            } else {
		                System.out.print(".");
		            }
		            
		        }
		    System.out.println("");
		    }
		    System.out.println("");
		}

		
    }
}


Measured memory_bytes: 34704
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n,q;
vl g[2*MAX];
ll a[2*MAX],ans[2*MAX];
ll dfs(ll u,ll p,ll sum){
	ans[u]=sum;
	for(auto v:g[u]){
		if(v!=p){
			dfs(v,u,sum+a[v]);
		}
	}
}

int main(){FAST;
cin>>n>>q;
for(ll i=1;i<=n-1;i++){
	ll u,v;cin>>u>>v;
	g[u].pb(v);
	g[v].pb(u);
}
for(ll i=1;i<=q;i++){
	ll u,w;cin>>u>>w;
	a[u]+=w;
}
dfs(1,0,a[1]);
for(ll i=1;i<=n;i++)cout<<ans[i]<<' ';
return 0;
}


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

int main(){
	int a,b;
	char op;
	while(1){
		cin>>a>>op>>b;

		if(op=='+'){
			cout<<a+b<<endl;
		}
		if(op=='-'){
			cout<<a-b<<endl;
		}
		if(op=='*'){
			cout<<a*b<<endl;
		}
		if(op=='/'){
			cout<<a/b<<endl;
		}
		if(op=='?'){
			break;
		}
	}
	return 0;

}



Measured memory_bytes: 3096
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    T, X = map(int, readline().split())

    print(T / X)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.nextInt()
    val a = sc.nextInt()

    println(abc130a(x, a))
}

private fun abc130a(x: Int, a: Int): Int {
    if (x < a) {
        return 0
    }

    return 10
}

Measured memory_bytes: 31400
#include<bits/stdc++.h>
using namespace std;
char s[200005];
int main()
{
    int n;
    int a,b,c,d;
    scanf("%d",&n);
    scanf("%d%d%d%d",&a,&b,&c,&d);
    scanf("%s",s+1);
    int flag=0;
    for(int i=a+1;i<=c-1;i++)
    {
        if(s[i]=='#'&&s[i-1]=='#') flag=-1;
    }
    for(int i=b+1;i<=d-1;i++)
    {
        if(s[i]=='#'&&s[i-1]=='#') flag=-1;
    }
    if(flag==-1) printf("No\n");
    else if(c<d) printf("Yes\n");
    else if(c==d) printf("No\n");
    else
    {
        for(int i=b;i<=d;i++)
        {
            if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.')
            {
                flag=1;
            }
        }
        if(flag==1) printf("Yes\n");
        else  printf("No\n");
    }
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline

N,K = map(int,input().split())
A = list(map(int,input().split()))

X = A * 2

Nextcount = [-1] * (2 * (10**5+1))
Nextind = [-1]*N

for i,x in enumerate(X):
    if 0 <= Nextcount[x] < N:
        Nextind[Nextcount[x]] = i

    Nextcount[x] = i

Repeatcount=0
NOW = 0

Repeatcount+=Nextind[NOW]-NOW+1
NOW=(Nextind[NOW]+1)%N

while NOW!=0:
    Repeatcount+=Nextind[NOW]-NOW+1
    NOW=(Nextind[NOW]+1)%N
    

Rep=(N*K)%Repeatcount
NOW=0

while True:
    if Nextind[NOW]-NOW+1<Rep:
        Rep-=Nextind[NOW]-NOW+1
        NOW=(Nextind[NOW]+1)%N

    else:
        break
    
#print(Rep,NOW)

from collections import Counter
C=Counter()
s=[]
for i in range(Rep):
    if X[(NOW+i)%N] in C:
        while X[(NOW+i)%N] in C:
            po=s.pop()
            C[po]-=1
            if C[po]==0:
                del C[po]

    else:
        s.append(X[(NOW+i)%N])
        C[X[(NOW+i)%N]]+=1

    #print(s,C)

print(*s)
        
            



Measured memory_bytes: 120528
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


constexpr lint inf = 9e18;

int n;
V<> a;

lint mn(int l, int r);
lint mx(int l, int r);

VV<lint> _mn;
lint mn(int l, int r) {
  if (l > r) return 0;
  if (_mn[l][r] != inf) return _mn[l][r];
  return _mn[l][r] = min(mx(l + 1, r) - a[l], mx(l, r - 1) - a[r]);
}

VV<lint> _mx;
lint mx(int l, int r) {
  if (l > r) return 0;
  if (_mx[l][r] != -inf) return _mx[l][r];
  return _mx[l][r] = max(a[l] + mn(l + 1, r), a[r] + mn(l, r - 1));
}

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  cin >> n;
  a.resize(n);
  assign(_mn, n, n, inf);
  assign(_mx, n, n, -inf);
  for (int i = 0; i < n; ++i) cin >> a[i];
  cout << mx(0, n - 1) << '\n';
}

Measured memory_bytes: 141312
#include<iostream>
using namespace std;
int field[1000][1000][4];
int main(){
  int m,n,k;
  cin >>m>>n>>k;
  for(int i=0; i<1000; i++) for(int j=0; j<1000; j++) for(int k=0; k<4; k++) field[i][j][k] = 0;
  for(int i=0; i<m; i++){
    string s;
    cin >>s;
    for(int j=0; j<n; j++){
      if(s[j] == 'J') field[i][j][0] = 1;
      if(s[j] == 'O') field[i][j][0] = 2;
      if(s[j] == 'I') field[i][j][0] = 3;
    }
  }
  for(int i=1; i<=3; i++){
    for(int x=0; x<m; x++){
      for(int y=0; y<n; y++){
	int z = 0;
	if(field[x][y][0] == i) z++;
	if(x>0) z+=field[x-1][y][i];
	if(y>0) z+=field[x][y-1][i];
	if(x>0 && y>0) z-=field[x-1][y-1][i];
	field[x][y][i] = z;
      }
    }
  }
  for(int i=0; i<k; i++){
    int a,b,c,d;
    cin >>a>>b>>c>>d;
    a--;b--;c--;d--;
    for(int j=1; j<=3; j++){
      int z = 0;
      z+=field[c][d][j];
      if(a>0) z-=field[a-1][d][j];
      if(b>0) z-=field[c][b-1][j];
      if(a>0 && b>0) z+=field[a-1][b-1][j];
      cout <<z;
      if(j<3) cout <<" ";
      else cout <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 16832
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

#define mod 1000000007
using namespace std;
typedef long long ll;

const int maxn = 1e8 + 8;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a*b%2==0)
    {
        printf("No");
    }
    else{
        printf("Yes");
    }





    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n;
int x[105];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>x[i];
    int ans=1000000000;
    for(int i=1;i<=100;i++){
        int sum=0;
        for(int j=1;j<=n;j++)
            sum+=(i-x[j])*(i-x[j]);
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss string
#define ull unsigned ll
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define For(i,j,k) for(int i = (int) j; i <= (int) k; i++)
#define Rep(i,j,k) for(int i = (int) j; i >= (int) k; i--)
const int N = 5e5;const int sult = 0;
int x;
void solve()
{
    cin >> x;
    cout << (x^1) << "\n";
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int T = 1;
    if(sult)cin >> T;
    for(;T;T--)solve();
}


Measured memory_bytes: 3684
//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")
    };
}

// ここまで

fn run() {
    input! {
        s: chars,
        t: chars,
    }
    let n = s.len();
    const P: usize = 26;
    let mut elem = [false; P];
    let mut a = vec![vec![2 * n + 2; 2 * n + 1]; P];
    for i in 0..n {
        let k = (s[i].to_digit(36).unwrap() - 10) as usize;
        a[k][n + i - 1] = 1;
        if i > 0 {
            a[k][i - 1] = 1;
        }
        elem[k] = true;
    }
    for i in 0..P {
        for j in (0..(2 * n)).rev() {
            a[i][j] = std::cmp::min(a[i][j], a[i][j + 1] + 1);
        }
    }
    for c in t.iter() {
        let k = (c.to_digit(36).unwrap() - 10) as usize;
        if !elem[k] {
            println!("-1");
            return;
        }
    }
    let mut now = n - 1;
    let mut ans = 0;
    for c in t {
        let k = (c.to_digit(36).unwrap() - 10) as usize;
        ans += a[k][now % n];
        now += a[k][now % n];
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 57596
n,m=map(int,input().split())
all_edge=[]
for i in range(m):
    a,b=map(int,input().split())
    all_edge.append([a-1,b-1])

def dfs(lst):
    visited=[None]*n
    visited[0]=1
    stack=[]
    for i in lst[0]:
        stack.append(i)
    while stack:
        new=stack.pop()
        if visited[new]==None:
            visited[new]=1
            for i in lst[new]:
                stack.append(i)
    if None in visited:
        return True
    else:
        return False

ans=0
for i in range(m): #橋の回数
    edge=[[] for _ in range(n)]
    for j in range(m): #1個除外する
        if i==j:
            continue
        a=all_edge[j][0]
        b=all_edge[j][1]
        edge[a].append(b)
        edge[b].append(a)
    if dfs(edge):
        ans+=1
print(ans)

Measured memory_bytes: 70668
#include <algorithm>
#include <climits>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> i_i;
int MOD = 1000000007;

vector<vector<int> > matmul(vector<vector<int> >& a, vector<vector<int> >& b) {
	int n = a.size();
	vector<vector<int> > c(n, vector<int>(n));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)
				c[i][j] = (c[i][j] + (ll)a[i][k] * b[k][j]) % MOD;
	return c;
}

vector<vector<int> > matpow(vector<vector<int> >& a, ll m) {
	int n = a.size();
	vector<vector<int> > b(n, vector<int>(n));
	for (int i = 0; i < n; i++)
		b[i][i] = 1;
	for (; m; m >>= 1) {
		if (m & 1) b = matmul(b, a);
		a = matmul(a, a);
	}
	return b;
}

int fib(int n) {
	vector<vector<int> > a(2, vector<int>(2));
	a[0][0] = 0; a[0][1] = 1;
	a[1][0] = 1; a[1][1] = 1;
	return matpow(a, n + 1)[1][1];
}

int main() {
	ll K; cin >> K; K--;
	ll lb = 0, ub = 1000000000;
	while (ub - lb > 1) {
		ll mid = (lb + ub) / 2;
		if (mid * (mid + 1) <= K) lb = mid;
		else ub = mid;
	}
	K -= lb * (lb + 1);
	int n = lb * 2;
	if (K >= lb + 1) {
		K -= lb + 1;
		n++;
	}
	int i;
	if (K * 2 <= n / 2) i = K * 2;
	else i = K * 2 - 1 + n % 2;
	int j = n - i;
	cout << (ll)fib(i) * fib(j) % MOD << endl;
}

Measured memory_bytes: 1208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n, q, m;
		int[] a;
		StringTokenizer st;

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

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}

		q = Integer.parseInt(br.readLine());

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < q; i++) {
			m = Integer.parseInt(st.nextToken());
			System.out.println(solve(a, 0, m) ? "yes" : "no");
		}
	}

	static boolean solve(int[] a, int p, int t) {
		boolean result = false;
		if (p == a.length) {
			result = false;
		} else {
			if (a[p] == t) {
				result = true;
			} else if (solve(a, p + 1, t - a[p])) {
				result = true;
			} else if (solve(a, p + 1, t)) {
				result = true;
			}
		}
		return result;
	}
	// 1 5 7 10 21
}

Measured memory_bytes: 19068
#include <stdio.h>
#include <stdlib.h>
int main(void){
	char a[1001],c[101],f[1001],m[1001];
	int b,d,e,i,j;
	scanf("%s",&a);
	scanf("%d",&b);
	for(i=0;i<b;i++){
		scanf("%s %d %d",&c,&d,&e);
		if(strcmp(&c,"print")==0){
			for(j=d;j<=e;j++)
				printf("%c",a[j]);
			printf("\n");}
		if(strcmp(&c,"replace")==0){
			scanf("%s",&f);
			for(j=d;j<=e;j++)
				a[j] = f[j-d];}
		if(strcmp(&c,"reverse")==0){
			for(j=d;j<=e;j++)
				m[j] = a[j];
			for(j=d;j<=e;j++)
				a[j] = m[d+e-j];}
	}
	return 0;
}
			

Measured memory_bytes: 576
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((int)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

void print(Vl v){
    rep(i, 0, sz(v)){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}

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


int main() {
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];
    ll ans[n];
    rep(i, 0, n) ans[i] = INF;
    rep(i, 0, n){
        *lower_bound(ans, ans + n, a[i]) = a[i];
    }
    // lower_bound(v, v+v.size(), n) : n以上となる要素の左端
    cout << lower_bound(ans, ans+n , INF) - ans << endl;

    return 0;
}



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

using namespace std;

int main (){

 long long a,b,r,c;
 
 cin>>a>>b;
 
 c = a*b;
 if (a<b) swap(a,b);
 r = a % b;
 while(r != 0){
  a = b;
  b = r;
  r = a % b;
 }
 cout<<c/b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
typedef long long ll;
int main()
{
    int N, M, L, sum = 0, ans = 0;
    cin >> N >> M;
    vector<int> A(N);
    
    
    rep(i, N){
        cin >> A[i];
        sum += A[i];
        //cout << A[i] << endl;
    }
    L = (sum - 1)/(4 * M);    
    rep(i, N){
        if (A[i] > L){
            ans++;
        }
    }
    //cout << sum << " " << L << " " << M << endl;
    if (ans >= M){
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
 long n,p,ans=1,st;
 cin >> n >> p;
 if(n==1)
 {
  cout << p << endl;
  return 0;
 }
 st = sqrt(p)+1;
 for(long i=2;i<st;i++)
 {
  while(p % long(pow(i,n))==0)
  {
   ans*=i;
   p = p/pow(i,n);
  }
 }
 cout << ans << endl;
 return 0;
}

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

int main() {

  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  
  int start = max(a,c);
  int end = min(b,d);
  
  cout<<max(0,end-start)<<endl;
 
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define SIZE 100000

typedef struct {
	int pref;
	int year;
	int id;
	int rank;
} city;

int comp_year(const void* a, const void* b) {
	return ((city*)a)->year - ((city*)b)->year;
}

int comp_id(const void* a, const void* b) {
	return ((city*)a)->id - ((city*)b)->id;
}

int main() {
	int n, m, i, r[SIZE];
	city c[SIZE];
	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) scanf("%d%d", &c[i].pref, &c[i].year);
	for (i = 0; i < m; i++) c[i].id = i;
	for (i = 0; i < n; i++) r[i] = 0;
	qsort(c, m, sizeof(c[0]), comp_year);
	for (i = 0; i < m; i++) c[i].rank = 1 + (r[c[i].pref - 1]++);
	qsort(c, m, sizeof(c[0]), comp_id);
	for (i = 0; i < m; i++) printf("%06d%06d\n", c[i].pref, c[i].rank);
	return 0;
}

Measured memory_bytes: 4964
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  vector<int> c(3);rep(i,3)cin>>c[i];
  sort(ALL(c));
  int ans = 3 - (c[0]==c[1]) - (c[1]==c[2]);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll MOD = 1000000007;
const int mod = 1000000007;
ll INF = 1LL << 60;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
   for (auto &v : vec)
      is >> v;
   return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
   os << "[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec)
{
   os << "deq[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{
   os << "(" << pa.first << "," << pa.second << ")";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
};
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
   fill((T *)array, (T *)(array + N), val);
}


ll a[202020];
int solve()
{
   ll n;
   cin >> n;
   //ll y = 0;
   for(int i=0; i < n; i++){
      cin >> a[i];
     // y += a[i];
   }
   ll y = accumulate(a, a + n, 0LL);
   ll ans = (1LL << 61) , x = 0;
   for(int i=0; i < n-1; i++){
      y -= a[i];
      x += a[i];
      ans = min(ans, abs(x - y));
   }
   cout << ans << endl;
   return 0;
}

int main()
{
   //cout.precision(10)
   ios::sync_with_stdio(false);
   cin.tie(0);

   solve();
}

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

int main(){
	int n;
	cin >> n;
	int x=0;
	for(int i=1; i<=n; i++){
		if(i*108/100 == n){
			x = i;
			break;
		}
	}
	if(x==0){
		cout << ":(" << endl;
		return 0;
	}else{
		cout << x <<endl;
		return 0;

	}
}


Measured memory_bytes: 256
#include <stdio.h>

int Partition(int A[],int p,int r)
{
  int i,j,x,tmp;

  x = A[r];
  i = p - 1;
  for(j = p;j < r;j++)
  {
    if(A[j] <= x)
    {
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;

  return i + 1;
}

int main()
{
  int i,n,A[100000],tmp,a;

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

  a = Partition(A,0,n - 1);

  for(i = 0;i < n;i++)
  {
    if(i > 0) printf(" ");
    if(i == a) printf("[");
    printf("%d",A[i]);
    if(i == a) printf("]");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2104
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// long t = System.currentTimeMillis();
		new Main().run();
		// System.err.println(System.currentTimeMillis() - t);
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		solver(sc.nextLong(), sc.nextLong());
	}

	void solver(long n, long a) {
		long ans = n;
		for (int m = 2; m <= 40; ++m) {
			long c = (long) Math.pow(n, 1.0 / m);
			for (long i = Math.max(c - 2, 2); i <= c + 2; ++i) {
				if (Math.log(i) * (m - 1) > 40 * Math.log(2))
					continue;
				for (int j = 0; j <= m - 1; ++j) {
					long res = a * (m - 1);
					res += j * i + (m - 1 - j) * (i + 1);
					long den = pow(i, j) * pow(i + 1, m - 1 - j);
					res += (n + den - 1) / den;
					ans = Math.min(ans, res);
				}
			}
		}
		System.out.println(ans);
	}

	long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a *= a) {
			if (n % 2 == 1) {
				ret *= a;
			}
		}
		return ret;
	}

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

}


Measured memory_bytes: 23764
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, P = MAP()

print((3*A+P)//2)


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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    sort(a.rbegin(),a.rend());
    ll ans=0;
    int cnt=n-1;
    rep(i,n){
        ans+=a[i],cnt--;
        if(cnt==0)break;
        if(i!=0)ans+=a[i],cnt--;
        if(cnt==0)break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4052
#include<stdio.h>
 
int main(){
    int a[100][100];
    int b[100][100];
    long int c[100][100]={0};
    int n,m,l;
    int i,j,k;
     
    scanf("%d %d %d",&n,&m,&l);
     
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(j=0;j<m;j++){
        for(k=0;k<l;k++){
            scanf("%d",&b[j][k]);
        }
    }
     
    for(i=0;i<n;i++){
        for(k=0;k<l;k++){
            for(j=1;j<=m;j++){
                c[i][k]+=(a[i][j-1]*b[j-1][k]);
            }
        }
    }
     
    for(i=0;i<n;i++){
        for(k=0;k<l;k++){
            printf("%ld",c[i][k]);
            if(k!=l-1)   printf(" ");
        }
        printf("\n");
    }
     
    return 0;
}

Measured memory_bytes: 764
import java.util.*;
import java.io.*;

public class Main {

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public float nextFloat() {
            return Float.parseFloat(next());
        }

        public double nextDouble() {
            return Float.parseFloat(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

    static InputReader sc;
    static PrintWriter pw;

    static int max;


    public static void main(String[] args) throws Exception {
        sc = new InputReader(System.in);
        pw = new PrintWriter(System.out);

        int n = sc.nextInt();

        Block[] blocks = new Block[n];

        for (int i = 0; i < n; i++) {
            blocks[i] = new Block(sc.nextInt(), sc.nextInt(), sc.nextInt());
        }

        Arrays.sort(blocks);

        max = 20123;

        long[] dp = new long[max + 1];

        for (Block block: blocks) {
            for (int i = Math.min(max - block.weight, block.solidness); i >= 0; i--) {
                dp[i + block.weight] = Math.max(dp[i + block.weight], dp[i] + block.value);
            }
        }

        long result = 0;

        for (int i = 0; i < max; i++) {
            result = Math.max(result, dp[i]);
        }

        pw.println(result);

        pw.close();
    }

    static class Block implements Comparable<Block> {
        int weight, solidness, value;

        Block(int weight , int solidness, int value) {
            this.weight = weight;
            this.solidness = solidness;
            this.value = value;
        }

        @Override
        public int compareTo(Block o) {
            return (this.weight + this.solidness) - (o.weight + o.solidness);
        }
    }
}




Measured memory_bytes: 34128
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,x; cin >> a >> b >> x;
    bool ok = true;
    if(a > x) ok = false;
    else if(a+b < x) ok = false;
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3632
x,y = map(int,input().split())
if x>=0 and y>=0:
    if y>=x:
        cnt = y-x
    elif y==0:
        cnt = 1+x
    else:
        cnt = x-y+2
elif x>=0 and y<0:
    if abs(y)>=x:
        cnt = abs(y)-x+1
    else:
        cnt = x-abs(y)+1
elif x<0 and y>=0:
    if y>=abs(x):
        cnt = 1+y-abs(x)
    elif y==0:
        cnt = abs(x)
    else:
        cnt = abs(x)-y+1
else:
    if abs(y)>=abs(x):
        cnt = abs(y)-abs(x)+2
    else:
        cnt = abs(x)-abs(y)
print(cnt)

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 N;
    cin >> N;
    vector<pair<int, int>> BA(N);
    rep(i, N) cin >> BA[i].second >> BA[i].first;
    sort(BA.begin(), BA.end());
    ll t = 0;
    string ans = "Yes";
    rep(i, N) {
        t += BA[i].second;
        if (t > BA[i].first) ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define ll long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
int k,a,b;
signed main() {
  IO;
  cin >> k >> a >> b;
  bool v = false;
  int now = k;
  while (now <= 1000000) {
    if (now >= a && now <= b) {
      v = true;
      break;
    }
    now += k;
  }
  if (v) cout << "OK" << '\n';
  else cout << "NG" << '\n';
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define Would
#define you
#define please

int main() {
	//おまじない
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int A, B, C, K;
	cin >> A >> B >> C >> K;

	int saidai = max(max(A, B), C);

	int kotae = saidai * pow(2, K);
	kotae += A + B + C - saidai;

	co(kotae);
	Would you please return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

    //入力の読み込み
    scanf("%d %d %d",&a,&b,&c);    

    //条件分岐
    if(a==b){
        printf("%d",c);
    }
    else if(a==c){
        printf("%d",b);
    }
    else{
        printf("%d",a);
    }
    
    return 0;
}

Measured memory_bytes: 128
from collections import namedtuple

class TreeWalk:
    def __init__(self, t):
        self.t = t

    def preParse(self, u):
        if u == -1:
            return 
        print("", str(u), end = "")
        self.preParse(self.t[u].l)
        self.preParse(self.t[u].r)

    def inParse(self, u):
        if u == -1:
            return 
        self.inParse(self.t[u].l)
        print("", str(u), end = "")
        self.inParse(self.t[u].r)

    def postParse(self, u):
        if u == -1:
            return 
        self.postParse(self.t[u].l)
        self.postParse(self.t[u].r)
        print("", str(u), end = "")
    
if __name__ == '__main__':
    n = int(input().rstrip())
    Node = namedtuple('Node', ['p', 'l', 'r'])
    t = [Node(-1, -1, -1)] * n
    root = -1
    for i in range(n):
        v, l, r = [int(i) for i in input().rstrip().split(" ")]
        t[v] = t[v]._replace(l = l, r = r)
        if l != -1:
            t[l] = t[l]._replace(p = v)
        if r != -1:
            t[r] = t[r]._replace(p = v)
    for i in range(n):
        if (t[i].p == -1):
            root = i

    x = TreeWalk(t)
    print("Preorder")
    x.preParse(root)
    print()
    print("Inorder")
    x.inParse(root)
    print()
    print("Postorder")
    x.postParse(root)
    print()

Measured memory_bytes: 8188
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 200005
using namespace std;
typedef long long ll;
int n;
int a[maxn],b[maxn],c[maxn],d[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int j=1;j<=n;j++)
		scanf("%d",&b[j]);

	int ans=0;

	for(int i=0;i<=29;i++)
	{
		int maxx=(1<<(i+1))-1;

		for(int j=1;j<=n;j++)
			c[j]=(a[j]&maxx),d[j]=(b[j]&maxx);

//		cerr<<"its c ";
//		for(int j=1;j<=n;j++)
//			cerr<<c[j]<<" ";
//		cerr<<endl;
//		cerr<<"its d ";
//		for(int j=1;j<=n;j++)
//			cerr<<d[j]<<" ";
//		cerr<<endl;

		sort(d+1,d+1+n);

		ll cnt=0;
		for(int j=1;j<=n;j++)
		{
			if((1<<i)&c[j])
			{
				int temp=(1<<(i+1))-c[j];
				cnt+=(lower_bound(d+1,d+1+n,temp)-d)-1;
//				cerr<<"its "<<(lower_bound(d+1,d+1+n,temp)-d)-1<<endl;
				temp=3*(1<<i)-c[j];
				cnt+=(n-(lower_bound(d+1,d+1+n,temp)-d)+1);
//				cerr<<"its "<<temp<<" "<<(lower_bound(d+1,d+1+n,temp)-d)<<endl;
			}
			else
			{
				int temp=(1<<i)-c[j];
				int nl=(lower_bound(d+1,d+1+n,temp)-d);
				temp=(1<<(i+1))-c[j];
				int nr=(lower_bound(d+1,d+1+n,temp)-d)-1;
				cnt+=(nr-nl+1);
			}
//			cerr<<cnt<<" ";
		}
//		cerr<<endl;
		if(cnt&1)
			ans|=(1<<i);
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int a,b,c,k,sum=0;
int main(){
	cin>>a>>b>>c>>k;
	if(k>a){
		k-=a;
		sum+=a;
		if(k>b){
			k-=b;
			cout<<sum-k;
		}
		else{
			cout<<sum;
		}
	}
	else{
		cout<<k;
	}
}

Measured memory_bytes: 3636