akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG


int main() {
  ll N;
  cin >> N;
  vector<ll> a(4);
  
  for (ll i = 0; i<N; i++){
    string tmp;
    cin >> tmp;
    if(tmp == "AC"){
      a[0]++;
    }else if(tmp == "WA"){
      a[1]++;

    }else if(tmp == "TLE"){
      a[2]++;

    }else{
      a[3]++;
    }

  }
  
  cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
  cout << "RE x " << a[3] << endl;

  return 0;
}


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

struct food {
  ll type;
  ll point;
};

bool operator< (food s, food t) {
  return s.point < t.point;
}

bool operator> (food s, food t) {
  return s.point > t.point;
}

ll N = 0;
ll K;
ll tmp;
ll ret = 0;
vector<ll> cnt(ARRAY, 0);
priority_queue<food> stock;
priority_queue<food, vector<food>, greater<food>> eated;


void input() {
  IN(N);
  IN(K);
  REP(i, N) {
    ll t, d;
    IN(t);
    IN(d);
    food f = {t, d};
    stock.push(f);
  }
}

void solve() {
  ll score = 0;
  ll type_num = 0;
  REP(i, K) {
    food f = stock.top();
    stock.pop();
    eated.push(f);
    if (cnt[f.type] == 0) {
      type_num++;
    }
    cnt[f.type] += 1;
    score += f.point;
  }
  ret = score + type_num*type_num;

  while(!stock.empty()) {
    food f = stock.top();
    stock.pop();
    if (cnt[f.type] > 0) {
      //種類数が増えないので追加しない
      continue;
    } else {
      while(!eated.empty()) {
        food e = eated.top();
        eated.pop();
        if (cnt[e.type] == 1) {
          // ユニークな寿司は除かない
          continue;
        } else {
          // 2個以上ある種類のものなので、除く
          cnt[e.type] -= 1;
          score -= e.point;
          // 新しい種類の追加
          cnt[f.type] += 1;
          score += f.point;
          type_num += 1;
          ret = max(ret, score + type_num * type_num);
          break;
        }
      }
      if (eated.empty()) {
        break;
      }
    }
  }

  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 5616
n, total = [int(x) for x in input().split()]

def calc_total(yukichi, ichiyo, hideyo):
  return 10000 * yukichi + 5000 * ichiyo + 1000 * hideyo

result_string = ""
for yukichi in range(n + 1):
  for ichiyo in range(n + 1):
    hideyo = n - yukichi - ichiyo
    if hideyo < 0:
      continue
      
    if (calc_total(yukichi, ichiyo, hideyo) == total) and (yukichi + ichiyo + hideyo == n):
      result_string = "{} {} {}".format(yukichi, ichiyo, hideyo)
      break
        
if len(result_string) == 0:
  print("-1 -1 -1")
else:
  print(result_string)

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int A,B;
	scan(A>>B);
	prin(max(0,A-2*B));
	return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

S = s()
if S[-1] == 's':
    print(S+'es')
else:
    print(S+'s')

Measured memory_bytes: 72660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0 && c>0){
		c-=b;
		if(c<=0)break;
		a-=d;
	}	
	if(a>0)puts("Yes");
	else puts("No");
	return 0; 
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  string s;
  string t;
  cin>>s;
  cin>>t;
  int n = s.size();
  int m = t.size();
  int sdsum[n];
  int tdsum[m];
  REP(i,n){
    if(i==0){
      if(s[i]=='A'){
        sdsum[i] = 1;
      }else{
        sdsum[i] = 2;
      }
    }else{
      if(s[i]=='A'){
        sdsum[i] = 1 + sdsum[i-1];
      }else{
        sdsum[i] = 2 + sdsum[i-1];
      }
    }
  }
  
  REP(i,m){
    if(i==0){
      if(t[i]=='A'){
        tdsum[i] = 1;
      }else{
        tdsum[i] = 2;
      }
    }else{
      if(t[i]=='A'){
        tdsum[i] = 1 + tdsum[i-1];
      }else{
        tdsum[i] = 2 + tdsum[i-1];
      }
    }
  }
  
  int q;
  cin>>q;
  int a,b,c,d;
  REP(i,q){
    cin>>a>>b>>c>>d;
    a--;b--;c--;d--;
    int from_, to_;
    if(a==0){
      from_ = sdsum[b];
    }else{
      from_ = sdsum[b] - sdsum[a-1];
    }
    if(c==0){
      to_ = tdsum[d];
    }else{
      to_ = tdsum[d] - tdsum[c-1];
    }
    if(from_%3 == to_%3){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}


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

int main(){
  ll K; cin>>K;
  string S; cin>>S;
  if(S.size()<=K) cout<<S<<endl;
  else{
    string X=S.substr(0, K);
    cout<<X<<"..."<<endl;
  }
}


Measured memory_bytes: 3632
#include <stdint.h>
#include <array>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <limits>
#include <tuple>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

int main() {
  int N;
  int K;
  cin >> N >> K;
  vector<char> D(K);
  REP(i, K) {
    cin >> D[i];
  }
  FOR(i, N, 1000000) {
    string s = to_string(i);
    bool ok = true;
    REP(j, K) {
      if (s.find(D[j]) != string::npos) {
        ok = false;
        break;
      }
    }
    if (ok) {
      std::cout << i << std::endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for(i = 0 ; i < strlen(str) ; i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M - 1));}

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i = 0 ; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i = 0 ; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for(i = 0 ; i < M ; i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%s %s", com, str);

    if(com[0] == 'i'){
      insert(str);
    }
    else{
      if(find(str)){
        printf("yes\n");
      }
      else printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 14916
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm


signed main(){
  string s,t;
  cin >> s >> t;
  int ls = s.size(),lt = t.size();
  
  bool ok = true;
  int ct = 0;
  string ans = s;
  
  repreq(i,ls,lt){
    ok = true;
    ans = s;
    repeq(j, 1, lt){
      
      if(ans[i-1-(j-1)]==t[lt-j] || ans[i-1-(j-1)]=='?'){
        ans[i-1-(j-1)] = t[lt-j];
        continue;
      }
      else {
        ok = false;
      }
      
    }
    
    if(ok) {
      rep(k,0,ls){
        if(ans[k]=='?') ans[k] = 'a';
      }
      cout << ans << endl;
      return 0;
    }
    
  }
  cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  
  for(int i = 0;i<=x;i++){
    for(int j = 0;j<=x;j++){
      if(i+j==x){
        if(i*2+j*4==y){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  
  cout << "No" << endl;
  
 
}

Measured memory_bytes: 3600
import math
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
amax = max(A)
B = list(filter(lambda x: x > amax, B))
B.sort()
ans = 0
while H > 0:
    if B:
        H -= B.pop()
    else:
        ans += math.ceil(H / amax)
        break
    ans += 1
print(ans)


Measured memory_bytes: 11768
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n,k=map(int,input().split())
    A=list(map(int,input().split()))

    for i in range(k):
        B=[0]*(n+1)

        for j in range(n):
            val=A[j]
            B[max(0,j-val)]+=1
            B[min(n,j+val+1)]-=1
        
        for k in range(n):
            B[k+1]+=B[k]
        A=B[:-1]

        if A==[n]*(n):
            break
    
    

    print(*A)    
    
resolve()

Measured memory_bytes: 221004
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException{
        List<String> list;
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            br.readLine();
            list = Arrays.stream(br.readLine().split(" ")).collect(Collectors.toList());
        }
        Collections.reverse(list);
        System.out.println(String.join(" ", list));
    }
}


Measured memory_bytes: 30760
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
i=0
ans=0
hand_dic={'r':'p','s':'r','p':'s'}
point_dic={'r':R,'s':S,'p':P}

for i in range(K):
  _T=T[i::K]
  before=''
  _ans=0
  for t in _T:
    if before != hand_dic[t]:
      _ans+=point_dic[hand_dic[t]]
      before=hand_dic[t]
    else:
      before=''
  ans+=_ans
print(ans)

Measured memory_bytes: 3316
#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 cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//どっか動画で見たことがあるが実際知らずに解けるのかは

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


	int H, W;
	cin >> H >> W;
	string S[500];
	rep(i, H) cin >> S[i];

	bool R[500][500] = {}, B[500][500] = {};
	rep(i, H) {
		if (i % 2) {
			rep(j, W) R[i][j] = 1;
		}
		else {
			rep(j, W) B[i][j] = 1;
		}
		R[i][0] = 1;
		R[i][W - 1] = 0;
		B[i][W - 1] = 1;
		B[i][0] = 0;
	}

	rep(i, H) {
		rep(j, W) {
			if (S[i][j] == '#' || R[i][j]) cout << '#';
			else cout << '.';
		}
		cout << "\n";
	}
	cout << "\n";
	rep(i, H) {
		rep(j, W) {
			if (S[i][j] == '#' || B[i][j]) cout << '#';
			else cout << '.';
		}
		cout << "\n";
	}


	Would you please return 0;
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var strs = Console.ReadLine().Split();
            var A = int.Parse(strs[0]);
            var B = int.Parse(strs[1]);

            Console.WriteLine(Math.Max(A + B, Math.Max(A - B, A * B)));
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

ll poww(ll t,ll n)
{
    if(n==0)return 1;
    return t*poww(t,n-1)%mod;
}

main()
{
    int n; cin>>n;
    bool isOdd=n%2;
    set<int> s;
    bool f=true;
    int cntz=0;
    rep(i,n)
    {
        int a;
        cin>>a;
        s.insert(a);
        if(isOdd&&a%2==1)f=false;
        if(!isOdd&&a%2==0)f=false;
        if(a==0)cntz++;
    }
    if(!f)
    {
        cout<<0<<endl;
        return 0;
    }
    if(cntz>1)
    {
        cout<<0<<endl;
        return 0;
    }


    ll ans=poww(2,n/2);
    ans=ans%mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int A, B;
    cin >> A >> B;
    int ans = (A < 10 && B < 10) ? A * B : -1;
    cout << ans << endl;
}


Measured memory_bytes: 256
s = input()

l = list(s)
n = len(s)

dp = [0] * 2019
dp[0] = 1
x = 0

for i in range(n):
    x = ((int(l.pop()) * pow(10, i, 2019)) + x) % 2019
    dp[x] += 1
answer = 0

for i in range(2019):
    answer += dp[i] * (dp[i] - 1) / 2
print(int(answer))

Measured memory_bytes: 10388
#include <iostream>
#include <algorithm>
using namespace std;
int N, K;
int main() {
	cin >> N >> K;
	long long ret = 0;
	if (K != 0) {
		for (int i = K + 1; i <= N; i++) {
			ret += N - (N / i * K + min(N % i + 1, K) - 1);
		}
	}
	else ret = 1LL * N * N;
	cout << ret << "\n";
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().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(S):
    return 'ABC' if S != 'ABC' else 'ARC'


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 76760
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto i:a)
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
ll dp[100010];
void solve()
{
	IN(n)IN(k);
	vl v;
	FOR(i, 0, n)
	{
		IN(in);
		v.pb(in);
	}
	dp[0] = 0;
	FOR(i, 1, n)
	{
		dp[i] = MAX;
		FOR(j, 1, k+1)
		{
			if(i-j>=0)
				dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j]));
		}
	}
	cout << dp[n - 1];
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 4740
#create date: 2020-08-07 07:31

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()

    ans = [0] * (10**8 + 1)
    for x in range(1, 10**2+1):
        for y in range(1, 10**2+1):
            for z in range(1, 10**2+1):
                k = x**2 + y**2 + z**2 + x*y + y*z + z*x
                ans[k] += 1
    for k in range(1, n+1):
        print(ans[k])

if __name__ == "__main__":
    main()

Measured memory_bytes: 790304
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cstring>
#include <queue>
#include <algorithm>
#include <climits>
#include <string>
#include <cstdlib>
#include <sstream>
#include <cmath>
#include <cassert>
#include <iomanip> // cout << setprecision(9) << fixed;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;

#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue

string S = "CODEFESTIVAL2016";

int main() {
    string s;
    cin >> s;
    int count = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != S[i]) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

const ll INF = 1LL << 50;

ll dp[303][303];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> H(N + 1);
    H[0] = 0;
    rep(i, 1, N + 1) cin >> H[i];
    rep(i, 0, N + 1) rep(j, 0, N + 1) {
        dp[i][j] = INF;
    }
    dp[0][0] = 0;
    rep(i, 1, N + 1) rep(j, 1, N + 1) {
        rep(k, 0, i) {
            dp[i][j] = min(dp[i][j], dp[k][j - 1] + max(0LL, H[i] - H[k]));
        }
    }
    ll ans = INF;
    rep(i, 0, N + 1) {
        ans = min(ans, dp[i][N - K]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int answer = 0;
    int times = 0;
    int number_of_one = 0;
    int all_clear_max = 1000000000;
    bool flag_all_clear = 0;
    bool same = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
        if (a.at(i) == 1)
        {
            number_of_one++;
        }
        if (i != 0 && a.at(i) != a.at(i - 1))
        {
            same = 0;
        }
    }
    sort(a.begin(), a.end());
    if (same)
    {
        answer = a.at(0);
    }
    else if (number_of_one > 1)
    {
        answer = 1;
    }
    else
    {
        for (int i = a.at(1); i > 0; i--)
        {
            for (int j = 0; j < n; j++)
            {
                if (a.at(j) % i != 0)
                {
                    times++;
                }
                if (times == 2)
                {
                    break;
                }
            }
            if (times == 1)
            {
                answer = i;
                break;
            }
            if (times == 0 && flag_all_clear == 0)
            {
                all_clear_max = i;
                flag_all_clear = 1;
            }
            times = 0;
        }
    }
    if (answer == 0)
    {
        answer = all_clear_max;
    }
    cout << answer << endl;
    return 0;
}


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


char field[1000][1000];
long long result[1000][1000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  int h, w;
  cin >> h >> w;
  int startx, endx, starty, endy;
  cin >> startx >> starty >> endx >> endy;
  --startx;
  --starty;
  --endx;
  --endy;
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) cin >> field[i][j];

  set<pair<long long, pair<int, int>>> S;
  S.insert({0, make_pair(startx, starty)});
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) result[i][j] = LLONG_MAX / 4;

  result[startx][starty] = 0;

  while (!S.empty()) {
    auto [dist, point] = *S.begin();
    S.erase(S.begin());
    if (point.first == endx && point.second == endy) break;
    for (int i = point.first - 2; i <= point.first + 2; ++i) {
      for (int j = point.second - 2; j <= point.second + 2; ++j) {
        if (i == point.first && j == point.second) continue;
        if (i < 0 || i >= h) continue;
        if (j < 0 || j >= w) continue;
        if (field[i][j] == '#') continue;

        int kek = abs(i - point.first) + abs(j - point.second);
        long long to = 0;
        if (kek == 1) {
          to = 1;
        } else {
          to = 100000000;
        }
        if (result[point.first][point.second] + to < result[i][j]) {
          S.erase({result[i][j], make_pair(i, j)});
          result[i][j] = result[point.first][point.second] + to;
          S.insert({result[i][j], make_pair(i, j)});
        }
      }
    }
  }
  if (result[endx][endy] == LLONG_MAX / 4) cout << -1;
  else cout << (result[endx][endy] / 100000000);
  return 0;
}


Measured memory_bytes: 12536
from heapq import heappop,heappush,heapify
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = list(map(int, input().split()))
a_minus = [-x for x in a]
heapify(a_minus)

pop = lambda: -heappop(a_minus)
push = lambda x: heappush(a_minus,-x)

for _ in range(m):
    x = pop()
    push(x//2)

print(-sum(a_minus))


Measured memory_bytes: 14204
n = int(input())

count = 0
o = []
e = []

for x in input().split():
	if count%2 == 0:
		o.append(x)
	else:
		e.append(x)
	count += 1

if n%2 == 0:
	tmp = list(reversed(e)) + o
else:
	tmp = list(reversed(o)) + e

ans = ' '.join(x for x in tmp)

print(ans)

Measured memory_bytes: 28176
#include<cstdio>
#include<queue>
using namespace std;
bool vis[100005];
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int k;
	scanf("%d", &k);
	deque<pair<int, int> >q;
	q.push_back(make_pair(1, 1));
	for(;;) {
		pair<int, int> now = q.front();
		q.pop_front();
		if(vis[now.first]) continue;
		else vis[now.first] = true;
		if(now.first == 0) {
			printf("%d", now.second);
			return 0;
		}
		pair<int, int> next = make_pair((now.first * 10) % k, now.second);
		q.push_front(next);
		next = make_pair((now.first + 1) % k, now.second + 1);
		q.push_back(next);
	}
	return 0;
}


Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AISing2020A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] LRd = Console.ReadLine().Split(' ');
            int L = int.Parse(LRd[0]);
            int R = int.Parse(LRd[1]);
            int d = int.Parse(LRd[2]);
            int count = 0;
            int baisuu = d;
            while (baisuu <= 100)
            {
                if (L <= baisuu & baisuu <= R)
                {
                    count += 1;
                }
                baisuu += d;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27312
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>

#define BIG 998244353
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;


int main() {
    int n;
    cin >> n;
    vector<long> a(n,0);
    vector<long> x(n,0);
    vector<long> y(n,0);
    for(int i = 0;i < n;++i)cin >> x[i];
    for(int i = 0;i < n;++i)cin >> y[i];

    for(int i = 0;i < n;++i)a[i] = x[i] - y[i];
    sort(a.begin(),a.end(),greater<long>());
    long sum = 0;
    for(int i = 0;i < n;++i){
        if(a[i] <= 0)break;
        sum += a[i];
    }
    cout << sum;

}





Measured memory_bytes: 888
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

int main(){
  int N, A, B, C;
  scanf("%d", &N);
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  std::queue<char > queue;
  bool result = true;
  std::vector<std::string > s(N);
  std::vector<std::string > next(N);
  next[N-1]="AB";
  for (int i=0; i<N; i++){
    std::cin >> s[i];
  }
  std::string cand = s[N-1];
  for (int i=N-2; i>0; i--){
    next[i]=cand;
    if (s[i-1]!=s[i]) cand=s[i];
  }
  next[0]=cand;

  for (int i=0; i<N; i++){
    if (s[i]=="AB"){
      if (A==B && next[i]=="BC"){
        B++;
        A--;
        queue.push('B');
      } else if (A==B && next[i]=="AC"){
        A++;
        B--;
        queue.push('A');
      } else if(A>B) {
        A--;
        B++;
        queue.push('B');
      } else {
        A++;
        B--;
        queue.push('A');
      }
      if (A<0 || B<0){
        result = false;
      }
    } else if (s[i]=="BC"){
      if (B==C && next[i]=="AC"){
        C++;
        B--;
        queue.push('C');
      } else if (B==C && next[i]=="AB"){
        B++;
        C--;
        queue.push('B');
      } else if(B>C) {
        B--;
        C++;
        queue.push('C');
      } else {
        B++;
        C--;
        queue.push('B');
      }
      if (B<0 || C<0){
        result = false;
      }
    } else {
      if (A==C && next[i]=="AB"){
        A++;
        C--;
        queue.push('A');
      } else if (A==C && next[i]=="BC"){
        C++;
        A--;
        queue.push('C');
      } else if(C>A) {
        C--;
        A++;
        queue.push('A');
      } else {
        C++;
        A--;
        queue.push('C');
      }
      if (C<0 || A<0){
        result = false;
      }
    }
  }
  if (result){
    printf("Yes\n");
    while(queue.size()>0){
      char value = queue.front();
      printf("%c\n", value);
      queue.pop();
    }
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 9620
N = gets.to_i
S = gets.chomp
stack = 0
ans = ""
S.chars{ |s|
  case s
  when "("
    stack += 1
  when ")"
    stack -= 1
    if stack < 0
      stack = 0
      ans = "(" + ans
      end
  end
  ans += s
}
ans += ")" * stack
puts ans

Measured memory_bytes: 1788
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <utility>
using namespace std;
#define INF 100000005
#define MAX 200005

int a[1001];
int main(){
	int n, sum;
	while(cin >> n, n){
		sum = 0;
		for(int i = 0;i < n;i++){
			cin >> a[i];
			sum += a[i];
		}
		sum -= *max_element(a, a+n);
		sum -= *min_element(a, a+n);
		cout << sum/(n-2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

// I'm trying to ~~~
int main(){
    int N,A,B; cin >> N >> A >> B;
    cout << min(N*A,B) << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string.h>
#include <vector>

using namespace std;

typedef vector<vector<int> > Graph;

vector<int> tsort(Graph G, int start, int end) {
  vector<int> ret;

  int degree[end];
  memset(degree, 0, sizeof(degree));

  for (int from = start; from < end; from++) {
    for (int i = 0; i < G[from].size(); i++) {
      int to = G[from][i];
      degree[to]++;
    }
  }

  stack<int> root;

  for (int i = start; i < end; i++) {
    if (degree[i] == 0) {
      root.push(i);
    }
  }

  while (!root.empty()) {
    int from = root.top();
    root.pop();

    ret.push_back(from);

    for (int i = 0; i < G[from].size(); i++) {
      int to = G[from][i];
      degree[to]--;

      if (degree[to] == 0) {
        root.push(to);
      }
    }
  }

  return ret;
}

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

  string S;
  cin >> S;

  Graph G(N);

  int a, b;

  for (int i = 0; i < M; ++i) {
    cin >> a >> b;

    --a;
    --b;

    G[a].push_back(b);
    G[b].push_back(a);
  }

  Graph G2(2 * N);

  for (int v = 0; v < N; ++v) {
    int v2 = v + N;
    char c1 = S[v];

    for (int i = 0; i < G[v].size(); ++i) {
      int u = G[v][i];
      char c2 = S[u];
      int u2 = u + N;

      if (v == u) {
        G2[v].push_back(u2);
      } else {
        if (c1 == c2) {
          G2[v].push_back(u2);
          G2[u].push_back(v2);
        } else {
          G2[v2].push_back(u);
          G2[u2].push_back(v);
        }
      }
    }
  }

  vector<int> res = tsort(G2, 0, 2 * N);

  if (res.size() != 2 * N) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}



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

using namespace std;

typedef long long ll;

ll result = LLONG_MAX;

inline ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
inline ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

int main() {
  ll h, w;
	cin >> h >> w;

	if (h%3==0) {
    cout << 0 << endl;
		return 0;
	} else {
    result = min(result, w);
	}
  
  if (w%3==0) {
    cout << 0 << endl;
		return 0;
	} else {
    result = min(result, h);
	}

	for (int i = 1; i < w; i++) {
    result = min(result, max(h*i, (w-i)*(h/2), (w-i)*(h/2+h%2)) - min(h*i, (w-i)*(h/2), (w-i)*(h/2+h%2)));
		if (result == 0) {
      cout << 0 << endl;
			return 0;
		}
	}

	for (int i = 1; i < h; i++) {
    result = min(result, max(w*i, (h-i)*(w/2), (h-i)*(w/2+w%2)) - min(w*i, (h-i)*(w/2), (h-i)*(w/2+w%2)));
		if (result == 0) {
      cout << 0 << endl;
			return 0;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAX=1e6+10;
int main()
{
    LL b[5];
    LL k;
    cin >> b[0] >> b[1] >> b[2];
    cin >> k;
    sort(b, b+3);
    for(int i = 1; i <= k; i++)
    b[2] = 2*b[2];
    cout << b[0]+b[1]+b[2] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}
long long gcd(long long a,long long b){
  if(b==0){
    return a;
  }
  return gcd(b,a%b);
}
long long lcm(long long a,long long b){
  long long g=gcd(a,b);
  return a/g*b;
}
long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}







int main(){
  long long N,M;
  cin>>N>>M;
  if(M>=N*2){
    long long x=M-N*2;
    cout<<N+x/4<<endl;
  }else{
    cout<<M/2<<endl;
  }
}



Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int i,j,a[10],k,max=-1,t;
    for(i=0;i<10;i++)
    {
        scanf("%d",&a[i]);
    }

    for(i=0;i<3;i++)
    {
        max=-1;
        for(j=i;j<10;j++)
        {
            if(max<a[j])
            {
                k=j;
                max=a[j];
            }

        }
        t=a[i];
        a[i]=a[k];
        a[k]=t;
        printf("%d\n",a[i]);

    }

    return 0;
}

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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> map(H, vector<char>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> map.at(i).at(j);
     }
  }
  
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if(map.at(i).at(j) == '#'){
        row.at(i) = true;
        col.at(j) = true;
      }//if
    } //for j
  }// for i
  
  for( int i= 0; i < H; i++){
    if(row.at(i)){
      for(int j = 0; j < W; j++){
        if(col.at(j)){
          cout << map.at(i).at(j);
          } //if j
      }// for j
      cout << endl;
     }//if i
  } //for i
}//main

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

int main() {
  int n, X, c = 1, x = 0;
  cin >> n >> X;
  int l[n];
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }
  for (int i = 0; i < n; i++) {
    x += l[i];
    if (x <= X) {
      c++;
    } else {
      break;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
def printTime(s):
    """
    s: integer (seconds)

    >>> printTime(10)
    0:0:10
    >>> printTime(60)
    0:1:0
    >>> printTime(45296)
    12:34:56
    """
    hour = s // 3600
    s %= 3600

    minute = s // 60
    s %= 60

    second = s

    print("{0}:{1}:{2}".format(hour, minute, second))


if __name__ == '__main__':


    time = int(input())
    printTime(time)

Measured memory_bytes: 7736
n = int(input())
h = list(map(int, input().split()))
h.reverse()
pflag = True
for i in range(n - 1):
  if h[i] < h[i + 1]:
    h[i + 1] -= 1
    if h[i] < h[i + 1]:
      pflag = False
      break
if pflag == True:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 14396
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <random>

using namespace std;

int main()
{
    long long A, B, K;

    cin >> A >> B >> K;

    for (int i = 0; i < K;i++)
    {
        if(i % 2 == 0)
        {
            if (A % 2 == 1)
            {
                A--;
            }
            B += A / 2;
            A /= 2;
        }
        else
        {
            if (B % 2 == 1)
            {
                B--;
            }
            A += B / 2;
            B /= 2;
        }
    }

    cout << A << ' ' << B << endl;
    return 0;
}

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

#define pb push_back
#define eb emplace_back

using namespace std;

using vi = vector<int>;
using ll = long long;

int main(){
    ios :: sync_with_stdio(false);
    int n, m;
    vi v;
    int x[2] {0, 0};
    int c=0;
    
    cin >> n;
    while(n--){
        cin >> m;
        v.pb(m);
    }

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

    for(int i=v.size()-1; i>=0; --i){
        x[c]+=v[i];
        c = 1 - c;
    }

    cout << (int)(x[0]-x[1]) << endl;

    return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  unless (n == 0) $ do
    solve <$> replicateM n (getl $ wrds toInt) >>= print
    main

solve :: [[Int]] -> Int
solve = sum . map toPrice
  where
    toPrice [x,y,h,w]
      | l <= 60 && w <= 2 = 600
      | l <= 80 && w <= 5 = 800
      | l <= 100 && w <= 10 = 1000
      | l <= 120 && w <= 15 = 1200
      | l <= 140 && w <= 20 = 1400
      | l <= 160 && w <= 25 = 1600
      | otherwise = 0
      where
        l = x + y + h

toInt :: String -> Int
toInt s = read s

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 12068
n = int(input())
s = input()
a = 0
b = 0
for c in s:
    if c == "R": a += 1
ans = max(a,b)
for i in range(n):
    if s[i] == "R": a -= 1
    else: b += 1
    ans = min(ans, max(a, b))
print(ans)








    


Measured memory_bytes: 9336
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;

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

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
char g[8][8];

void solve(int a, int b) {
  g[a][b] = '0';
  for(int i = 1; i <= 3; i++) {
    if(a+i < 8 && g[a+i][b] == '1') {
      g[a+i][b] = '0';
      solve(a+i, b);
    }
    if(a-i >= 0 && g[a-i][b] == '1') {
      g[a-i][b] = '0';
      solve(a-i, b);
    }
    if(b+i < 8 && g[a][b+i] == '1') {
      g[a][b+i] = '0';
      solve(a, b+i);
    }
    if(b-i >= 0 && g[a][b-i] == '1') {
      g[a][b-i] = '0';
      solve(a, b-i);
    }
  }
}

int main() {
  int n, X, Y;
  int k = 0;

  cin >> n;

  while(n > k) {
    for(int i = 0; i < 8; i++) {
      for(int j = 0; j < 8; j++) {
        cin >> g[i][j];
      }
    }
    cin >> X >> Y;
    X--; Y--;

    solve(Y, X);

    cout << "Data " << (k+1) << ':' << endl;
    for(int i = 0; i < 8; i++) {
      for(int j = 0; j < 8; j++) {
        cout << g[i][j];
      }
      cout << '\n';
    }
    k++;
  }

  return 0;
}



Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define OK cout<<"OK";
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    Deb(c,a,b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, a[3030];
int dp[3030][3030];
bool check[3030][3030];

int f(int x, int y, bool flag) {
    if (check[x][y])
        return dp[x][y];
    check[x][y] = true;
    if (x > y)
        return 0;
    int ret;
    if (flag) {
        ret = max(f(x + 1, y, false) + a[x], f(x, y - 1, false) + a[y]);
    } else {
        ret = min(f(x + 1, y, true) - a[x], f(x, y - 1, true) - a[y]);
    }
    return dp[x][y] = ret;
}


void solve() {
    cout << f(0, N - 1, true) << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(N)
    cin >> a[i];


    solve();
    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  string s;
  cin >> s;
  if(s.at(0)==s.at(1)||s.at(1)==s.at(2)||s.at(2)==s.at(3)){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
}


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

int i,j,k;

int main(){
    ll n;cin>>n;
    vector<ll> length(n);//棒の長さ
    for(i=0;i<n;i++){cin>>length[i];}
    
    sort(length.begin(),length.end());//昇順sort

    ll ans=0;
    int number;
    for(i=n-1;i>=2;i--){
        for(j=i-1;j>=1;j--){
            //binary search
            number=length[i]-length[j];
            int key;
            vector<long long int>::iterator position;
            position=upper_bound(length.begin(),length.begin()+j,number);
            //他の2辺を固定して、最後の辺になり得る最小値を探す
            key=distance(length.begin(),position);//最小で可能な辺の位置
            ans+=(j-key);
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <map>
#include <array>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl
 
//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)
 
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    array<int,100100> mp={};
    int tmp;
    while(n--){
        cin>>tmp;
        mp[tmp+2]++;
        mp[tmp]++;
        mp[tmp+1]++;
    }
    int result=0;
    for(auto &x:mp){
        result=max(result,x);
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 640
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
l = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
ans = []
def dfs(s, mx):
    if len(s) == N:
        ans.append(s)
        return
    for i in range(mx+1):
        # 新しい文字を登場させる
        if i == mx:
            # print("a:", s+l[i])
            dfs(s+l[i], mx+1)
        else:
            # print("b:", s+l[i])
            dfs(s+l[i], mx)


dfs("", 0)
print(*ans, sep="\n")
    

Measured memory_bytes: 16600