akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if(a1 + a2 + a3 >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    N, Y = map(int, input().split())

    # 最低限必要な諭吉を計算
    if 5000 * N < Y:
        n_yukichi = 1
        while True:
            if n_yukichi * 10000 + (N - n_yukichi) * 5000 >= Y:
                yukichi_need = n_yukichi
                break
            n_yukichi += 1
    else:
        yukichi_need = 0

    # 1000円の開始枚数を計算
    noguchi_start = (Y % 5000) // 1000

    for yukichi in range(yukichi_need, N+1):
        for higuchi in range(N+1):
            if yukichi + higuchi > N:
                break

            noguchi = N - yukichi - higuchi

            if yukichi + higuchi + noguchi == N:
                if yukichi*10000 + higuchi*5000 + noguchi*1000 == Y:
                    print(yukichi, higuchi, noguchi)
                    return

    print(-1, -1, -1)
    return

main()


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

int main(){
    int N, i; cin >> N >> i;
    cout << N - i + 1 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e5 + 5;

int n,k;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n>>k;
  vector<pair<ll,int>> v(n);
  for (int i=0; i<n; i++) {
      cin>>v[i].second>>v[i].first;
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  set<int> t;
  stack<ll> st;
  
  ll best = 0;
  ll cur = 0;

  for (int i=0; i<k; i++) {
      int ty=v[i].second;
      if (t.find(ty)!=t.end()) {
          st.push(v[i].first);
      }
      cur += v[i].first;
      t.insert(ty);
  }
  cur = cur + t.size()*t.size();
  best = max(best, cur);

    for (int i=k; i<n && !st.empty(); i++) {
        int ty = v[i].second;
        ll wei = v[i].first;
        if (t.find(ty)!=t.end()) continue;
        ll x = st.top();
        st.pop();
        cur -= x;
        cur += wei;
        cur -= t.size()*t.size();
        t.insert(ty);
        cur += t.size()*t.size();
        best = max(cur, best);
    }

  cout<<best<<endl;
  
  return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
#define N 500000

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key){
      u = u->left;
    }
    else{
      u = u->right;
    }
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
void treeDelete(Node z){
  Node y;
  Node x;
  if(z->left == NIL || z->right == NIL){
    y = z;
  }
  else{
    y = treeSuccessor(z);
  }
  if(y->left != NIL){
    x = y->left;
  }
  else{
    x = y->right;
  }
  if(x != NIL){
    x->parent = y->parent;
  }
  if(y->parent == NIL){
    root = x;
  }
  else if(y == y->parent->left){
    y->parent->left = x;
  }
  else{
    y->parent->right = x;
  }
  if(y != z){
    z->key = y->key;
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u->left != NIL){
    inorder(u->left);
  }
  printf(" %d", u->key);
  if(u->right != NIL){
    inorder(u->right);
  }
}



void preorder(Node u){
  printf(" %d", u->key);
  if(u->left != NIL){
    preorder(u->left);
  }
  if(u->right != NIL){
    preorder(u->right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for(i = 0;i < n;i++){
    scanf("%s", com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      if (treeSearch(root, x) != NIL) {
	printf("yes\n");
      }
      else{ 
	printf("no\n");
      }
    }

    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 

    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }

    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }

  }
  return 0;
}

Measured memory_bytes: 19364
#include <stdio.h>

int main() {
  int h, w;
  while (scanf("%d%d", &h, &w), h | w) {
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
}


Measured memory_bytes: 2576
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,K,answer;
  cin >> A >> B >> C >> K;
  

  if((A+B)>=K){
   if(A<K){answer = A;}
   else{answer= K;} 
  }
  else{
    answer = A - (K - (A + B));
  }

  cout << answer << endl;
}

Measured memory_bytes: 3636
def main():
    N, K = map(int, input().split())
    l = []
    xl = []
    yl = []
    for _ in range(N):
        x, y = map(int, input().split())
        l.append((x, y))
        xl.append(x)
        yl.append(y)
    xl.sort()
    yl.sort()
    xd = {}
    dx = {}
    t = 0
    p = xl[0]
    for i in xl:
        if i != p:
            t += 1
        xd[i] = t
        dx[t] = i
        p = i
    yd = {}
    dy = {}
    t = 0
    p = yl[0]
    for i in yl:
        if i != p:
            t += 1
        yd[i] = t
        dy[t] = i
        p = i
    l2 = []
    for x, y in l:
        l2.append((xd[x], yd[y]))
    m = 10**100
    for si in range(len(xd)-1):
        for ei in range(si+1, len(xd)):
            for sj in range(len(yd)-1):
                for ej in range(sj+1, len(yd)):
                    t = 0
                    for x, y in l2:
                        if si <= x <= ei and sj <= y <= ej:
                            t += 1
                    if t >= K:
                        m = min(m, (dx[ei]-dx[si]) * (dy[ej]-dy[sj]))
    return m
print(main())
                


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

int main(){
  int K;
  string S;
  cin >> K >> S;

  if(K >= S.length()){
    cout << S << endl;
  }else{
    cout << S.substr(0,K) << "..." << endl;
  }
}

Measured memory_bytes: 3604
#include "cmath"
#include "iostream"

using namespace std;

long long a, b, n;
long long fuck(long long x) { return floorl(a * x / b) - (a * floorl(x / b)); }

int main() {
    cin >> a >> b >> n;
    cout << max(fuck(min(b - 1, n)), fuck(0));
    return 0;
}


Measured memory_bytes: 3188
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, W: int, s: "List[str]"):
    print(YES if all(
        any(
            s[y + dy][x + dx] == "#"
            for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]
            if 0 <= x + dx < W and 0 <= y + dy < H
        )
        for y in range(H)
        for x in range(W)
        if s[y][x] == "#"
    ) else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
def judge(lst):
	x = 0
	y = 0
	memo = 0
	for i in range(0, len(lst)-1):
		if lst[i] == lst[i+1]:
			x = lst[i]
			memo = i
			break
	for i in range(memo+2, len(lst)-1):
		if lst[i] == lst[i+1]:
			y = lst[i]
			break
	return x*y

N = int(raw_input())
A = map(int, raw_input().split())
A.sort(reverse=True)

print judge(A)

Measured memory_bytes: 11320
S=int(input())
DP=[0 for i in range(S+1)]
DP[0]=1
for i in range(S+1):
    for j in range(3,S+1):
        if i+j<=S:
            DP[i+j]+=DP[i]
            DP[i+j]%=(10**9+7)
print(DP[-1])

Measured memory_bytes: 67576
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

const int MAX_N = 200010;

int par[MAX_N];
int Rank[MAX_N];
int size;

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        Rank[i] = 0;
    }
    size = n;
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    size--;
    if (Rank[x] < Rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (Rank[x] == Rank[y]) {
            Rank[x]++;
        }
    }
}
bool same(int x, int y) {
    return find(x) == find(y);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    init(M + N);
    rep(i, N) {
        int K; cin >> K;
        rep(j, K) {
            int L; cin >> L;
            L--;
            unite(i, N + L);
        }
    }
    rep(i, N) {
        if (!same(0, i)) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 0) {
    cout << (a + b) / 2 << endl;
  }
  else {
    cout << (a + b) / 2 + 1 << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
char S[100002];
char res[100002];
int main(){
  int a, b, i, j, k;
  rd(N);
  rd(S);
  for(i=0;i<(N);i++){
    if(S[i]=='o'){
      S[i] =0;
    }
    else{
      S[i] =1;
    }
  }
  for(a=0;a<(2);a++){
    for(b=0;b<(2);b++){
      res[0] = a;
      res[1] = b;
      for(i=(2);i<(N);i++){
        res[i] = (res[i-2] + res[i-1] + S[i-1]) % 2;
      }
      if( (res[N-2] + res[N-1] + S[N-1] + res[0]) % 2 ){
        continue;
      }
      if( (res[N-1] + res[0] + S[0] + res[1]) % 2 ){
        continue;
      }
      for(i=0;i<(N);i++){
        if(res[i]==0){
          res[i] ='S';
        }
        else{
          res[i] ='W';
        }
      }
      wt_L(res);
      wt_L('\n');
      return 0;
    }
  }
  wt_L(-1);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190902-1

// --- original code ---
// int N;
// char S[100002];
// char res[100002];
// {
//   int i, j, k, a, b;
//   rd(N,S);
//   rep(i,N) S[i] = if[S[i]=='o', 0, 1];
//   rep(a,2) rep(b,2){
//     res[0] = a;
//     res[1] = b;
//     rep(i,2,N) res[i] = (res[i-2] + res[i-1] + S[i-1]) % 2;
//     if( (res[N-2] + res[N-1] + S[N-1] + res[0]) % 2 ) continue;
//     if( (res[N-1] + res[0] + S[0] + res[1]) % 2 ) continue;
//     rep(i,N) res[i] = if[res[i]==0, 'S', 'W'];
//     wt(res);
//     return 0;
//   }
//   wt(-1);
// }


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

ll dp[51][51][5001];

const int M = 2500;
// const int M = 6;

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

  if (k % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }

  k = k / 2;

  dp[0][0][M] = 1;
  rep (i, n) {
    rep (j, n + 1) {
      rep (l, 5001) {
        if (dp[i][j][l] == 0) continue;
        // 自分
        (dp[i + 1][j][l] += dp[i][j][l]) %= MOD;
        // 下をすませる
        (dp[i + 1][j][l] += dp[i][j][l] * j % MOD) %= MOD;
        // 下に住む
        (dp[i + 1][j][l] += dp[i][j][l] * j % MOD) %= MOD;
        
        (dp[i + 1][j + 1][l - (i + 1)] += dp[i][j][l]) %= MOD;
        (dp[i + 1][j - 1][l + (i + 1)] += dp[i][j][l] * j % MOD * j % MOD) %= MOD;
      }
    }
  }
  
  /*
  rep (i, n + 1) {
    rep (j, n + 1) {
      rep (l, 2*M + 1) {
        cout << dp[i][j][l] << " ";
      }
      cout << endl;
    }
    cout << endl;
  }
  //*/
  ll ans = dp[n][0][M + k];
  cout << ans << endl;
  
}


Measured memory_bytes: 98816
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

int main(void){
   long long K,N;
   cin>>N>>K;
   long long ans=0;
   for(long long i=K;i<=N+1;i++){
      long long mini=i*(i-1)/2;
      long long maxi=(N+N-i+1)*i/2;
      ans+=(maxi-mini+1);
   }
   cout<<ans%mod<<endl;
   return 0;
}

Measured memory_bytes: 3612
n, m, p = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]

for i in range(m):
    A[i][2] = - (A[i][2]-p)

#import numpy as np
# A = np.full(np.inf, (n+1, n+1))

# scipy.sparse.csgraph.bellman_ford


S = [10**10 for i in range(n+1)]

S[1]=0
for i in range(m):
    if A[i][0] == 1:
        S[A[i][1]]=A[i][2]

for j in range(n-1):
    for i in range(m):
        S[A[i][1]] = min(S[A[i][1]], S[A[i][0]]+A[i][2])

ans0 = -S[n]

for j in range(n-1):
    for i in range(m):
        S[A[i][1]] = min(S[A[i][1]], S[A[i][0]]+A[i][2])

ans1 = -S[n]

if ans0 != ans1:
    print(-1)
else:
    print(max(0, ans0))

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

int main()
{
    string a;
    int n;
    while(cin>>n)
    {
        cin>>a;
        int len=a.length();
        for(int i=0;i<len;i++)
        {
            a[i]=a[i]+n;
            if(a[i]>'Z')
                a[i]=a[i]-'Z'+'A'-1;
        }
        cout<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int r;
    cin >> r;
    cout << 3*r*r << endl;
    return 0;
}

Measured memory_bytes: 3632
use proconio::input;
use rand::Rng;
use std::collections::BTreeSet;

fn main() {
   input! {
      dn: usize,
      c: [i64; 26],
      mut s: [[i64;26]; dn],
   }

   s.insert(0, vec![]);
   let mut t = vec![0];
   let mut last = vec![BTreeSet::new(); 26];
   let start = std::time::Instant::now();
   let time_limit = std::time::Duration::from_millis(1940);

   for i in 0..26 {
      last[i].insert(0);
      last[i].insert(dn + 1);
   }
   for d in 1..=dn {
      let mut mx = std::i64::MIN;
      let mut tn = 0;
      for t in 0..26 {
         let mut score = 0i64;
         score += s[d][t];
         for j in 0..26 {
            if j != t {
               score -= c[j] * (d - last[j].range(..d).rev().next().unwrap()) as i64;
            }
         }
         if score > mx {
            mx = score;
            tn = t;
         }
      }
      last[tn].insert(d);
      t.push(tn);
   }

   let mut rng = rand::thread_rng();
   loop {
      let elapsed = start.elapsed();
      if elapsed >= time_limit {
         break;
      }
      let diff = elapsed.as_micros() as f64 / time_limit.as_micros() as f64;
      let d = rng.gen_range(1, dn + 1);
      let q = rng.gen_range(0, 26);
      if t[d] == q {
         continue;
      }
      let p = t[d];
      let mut score = 0;
      score -= s[d][p];
      score += s[d][q];
      let f1 = last[p].range(..d).rev().next().unwrap();
      let b1 = last[p].range(d + 1..).next().unwrap();
      let f2 = last[q].range(..d).rev().next().unwrap();
      let b2 = last[q].range(d + 1..).next().unwrap();
      score -= c[p] * (d - f1) as i64 * (b1 - d) as i64;
      score += c[q] * (d - f2) as i64 * (b2 - d) as i64;
      let temp: f64 = 1000.0 / (((10.0 * diff - 3.0) as f64).exp() + 1.0);
      if score > 0 || rng.gen_range(0.0, 1.00) <= (score as f64 / temp).exp() {
         t[d] = q;
         last[p].remove(&d);
         last[q].insert(d);
      }
   }
   for &t in t.iter().skip(1) {
      println!("{}", t + 1);
   }
}


Measured memory_bytes: 3376
n,k = map(int,input().split())
s = input()
oo = ['A','B','C']
syo = ['a','b','c']
for i in range(n):
    if k-1 == i:
        for j in range(3):
            if s[i] == oo[j]:print(syo[j],end = '')
    else:
        print(s[i],end = '')
print()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int h,w; cin >> h >> w;
  vector<string> s(h); rep(i,h) cin >> s[i];
  vector<vi> dp(h,vi(w,INF));
  dp[0][0] = (s[0][0] == '#');
  rep(i,h){
    rep(j,w){
      if(0 <= j-1){
        if(s[i][j-1] != s[i][j]) chmin(dp[i][j],dp[i][j-1]+1);
        else chmin(dp[i][j],dp[i][j-1]);
      }
      if(0 <= i-1){
        if(s[i-1][j] != s[i][j]) chmin(dp[i][j],dp[i-1][j]+1);
        else chmin(dp[i][j],dp[i-1][j]);
      }
    }
  }
  if(s[h-1][w-1] == '#') dp[h-1][w-1]++;
  cout << dp[h-1][w-1]/2;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,i;
    string s;
    cin>>n;
    cin>>s;
    
    int x=0;
    if(n%2==0)
    {
    	for(i=0;i<n/2;i++)
    {
    	if(s[i]==s[n/2+i])
    	x++;
	}
	if(x==n/2)
	cout<<"Yes";
	else
	cout<<"No";
	}
	else
	cout<<"No";
    
    
	

}


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


def main():
    N, K = [int(x) for x in input().split()]
    ans = 0
    if K & 1:
        print((N // K) ** 3)
    else:
        ans += (N // K) ** 3
        ans += ((N + K // 2) // K) ** 3
        print(ans)



if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=m-n+1;i<=m;i++){
		cout<<i<<' ';
	}
	for(int i=m+1;i<=m+n-1;i++){
		cout<<i<<' ';
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		String t = scanner.next();
		String[] ans = s.split("");

		int index = -1;
		out_of_loop: for (int i = s.length() - 1; i >= 0; i--) {
			for (int j = 0; j < t.length(); j++) {
				char cs = s.charAt(i - j);
				char ct = t.charAt(t.length() - 1 - j);
				if (!((cs != '?' && cs == ct) || cs == '?')) {
					break;
				}
				if (t.length() > i + 1) {
					System.out.println("UNRESTORABLE");
					return;
				}
				if (j == t.length() - 1) {
					index = i;
					break out_of_loop;
				}
			}
		}

		for (int i = 0; i < t.length(); i++) {
			ans[index - i] = String.valueOf(t.charAt(t.length() - 1 - i));
		}

		for (int i = 0; i < s.length(); i++) {
			if (ans[i].equals("?")) {
				System.out.print("a");
			} else {
				System.out.print(ans[i]);
			}
		}

	}
}


Measured memory_bytes: 22868
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}


int s[4][4]={
    {6,3,1,4},
    {2,0,2,0},
    {1,3,6,4},
    {5,0,5,0}
};
int check(int x,int y){
    return s[x%4][y%4];
}

main(){
    int n=in();
    vec a;
    int mi=INT_MAX;
    rep(i,n)a.pb(in());
    rep(i,n)chmin(mi,a[i]);
    if(n&1){
        ll sum=0;
        sum=accumulate(all(a),0);
        cout <<(sum&1 ? "First\n" : "Second\n");
        return 0;
    }
    if(mi&1){
        cout<<"First\n";
    }
    else{
        ll sum=0;
        rep(i,n)sum+=a[i]-mi;
        if(sum&1){
            cout<<"First\n";
        }
        else cout<<"Second\n";
    }
    
}


Measured memory_bytes: 3932
import sys
sys.setrecursionlimit(10 ** 6)


N, M, X = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(N)]


def dfs(asum, b):
    global N, M, X
    rst = 10 ** 8
    if b == N:
        if all(asum[i] >= X for i in range(1, M + 1)):  # check関数は all で代替可能
            rst = asum[0]
    else:
        # b番目を買わない場合
        rst = min(rst, dfs(asum, b + 1))
        
        # b番目を買う場合
        asum2 = tuple(asum[i] + C[b][i] for i in range(M + 1))  # tashi関数を普通に書くならこうかな、、tupleにキャストする。
        rst = min(rst, dfs(asum2, b + 1))

    return rst


rst = dfs(tuple([0] * (M + 1)), 0)
ans = rst if rst < 10 ** 8 else -1
print(ans)


Measured memory_bytes: 9332
/**
 * @author      : Luis Miguel Baez <es.luismiguelbaez@gmail.com>
 * @created     : Thursday August 13, 2020
 */

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(arr, value) memset(arr, value, sizeof arr)
#define ll    int64_t

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

// add template here

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template<class T>
void println(const T &data) {
#ifndef ONLINE_JUDGE
    cout << to_string((T)data) << endl;
#endif
}


const int oo  = (int)(1e9);
const ll lloo  = (ll)(1e18);

const int N = 1e5 + 10;

class Task {
public:
    int n;
    vector<int> A;

    ll dp[N];

    ll go(int index) {
        if(index > n) return 0LL;
        if(index == n) {
            return 0LL;
        }

        ll &ans = dp[index];
        if(ans != -1) return ans;

        ll x = oo;
        ll y = oo;

        if(index+1 <= n) {
            x = abs(A[index]-A[index+1]) + go(index + 1);
        }
        
        if(index+2 <= n) {
            y = abs(A[index]-A[index+2]) + go(index + 2);
        }
        ll mn = min(x, y);
        if(mn == oo) {
            ans = 0;
            return ans;
        }
        ans = min(x, y);
        return ans;
    }

    ll solveOne(istream &in, ostream &out) {
        in >> n;
        A.resize(n+1);
        for(int i = 1; i <= n; ++i){
            in >> A[i];
        }
        memset(dp, -1, sizeof dp);
        ll ans = go(1);
        return ans;  
    }
    
    void solve(istream &in, ostream &out) {
        int t = 1;
        while(t--) {
            out << solveOne(in, out) << endl;
        }
    }
};

auto main() -> int {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    Task solver;
    istream &in(cin);
    ostream &out(cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 12188
#include <bits/stdc++.h>
using namespace  std;
bool solve(string s, string t){
    for(int i=0;i<s.length();i++){
            if(s[i]!=t[i])
                return false;
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    string t;
    cin >> t;
    if(solve(s,t))  cout << "Yes\n";
    else    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/*---------------------------------------------------------------------------------------------------------------------*/

const int M = 2e5 + 5;

ll dp[M];
ll arr[M];

int main(){


	int n;
	si(n);

	vector<int> vec;

	vec.push_back(0);

	for(int i = 1 ; i <= n ; i++){
        int el;
        si(el);
        if(vec.back() == el) continue;
        vec.push_back(el);
	}

	arr[vec[1]] = 1;

	dp[1] = 1;

	for(int i = 2 ; i < vec.size() ; i++){
        dp[i] = dp[i - 1] + arr[vec[i]];

        arr[vec[i]] += dp[i - 1];
        arr[vec[i]] %= mod;
        dp[i] %= mod;
	}

	cout<<dp[vec.size() - 1];


}






































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

struct Edge {
    int to;
    int cost;
};
using Graph = vector<vector<Edge>>;

/* topo_sort(G): グラフG をトポロジカルソート
    返り値: トポロジカルソートされた頂点番号
    計算量: O(|E|+|V|)
    返り値のサイズがグラフより小さければ閉路が存在する
    （スタックオーバーフローの可能性があるので、dfsではなくbfsで実装）
 */
vector<int> topo_sort(const Graph &G) {  // bfs
    vector<int> ans;
    int n = (int)G.size();
    vector<int> ind(n);
    for (int i = 0; i < n; i++) {
        for (auto e : G[i]) {
            ind[e.to]++;
        }
    }
    queue<int> que;
    for (int i = 0; i < n; i++) {
        if (ind[i] == 0) {
            que.push(i);
        }
    }
    while (!que.empty()) {
        int now = que.front();
        ans.push_back(now);
        que.pop();
        for (auto e : G[now]) {
            ind[e.to]--;
            if (ind[e.to] == 0) {
                que.push(e.to);
            }
        }
    }
    return ans;
}

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

    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M), D(M);
    for (int i = 0; i < M; i++) {
        cin >> L.at(i) >> R.at(i) >> D.at(i);
        L[i]--, R[i]--;
    }

    Graph G(N);
    for (int i = 0; i < M; i++) {
        G[L[i]].push_back({R[i], D[i]});
    }
    vector<int> sorted = topo_sort(G);

    if ((int)sorted.size() != N) {
        cout << "No" << endl;
        return 0;
    }
    const int INF = 1e8;
    vector<int> d(N, INF);
    for (auto i : sorted) {
        if (d[i] == INF) d[i] = 0;
        for (auto e : G[i]) {
            if (d[e.to] == INF) {
                d[e.to] = d[i] + e.cost;
            } else {
                if (d[e.to] != d[i] + e.cost) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 10;

ll a, b, c, d;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d});
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define int long long
#define deb(x) cout << #x << " = " << x << "\n";
using namespace std;

signed main() {
    
    int n; cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += ((n + i - 1)/i - 1);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<int(n);i++)

int main()
{
  while(1){
    int m, n_min, n_max;
    cin >> m >> n_min >> n_max;
    if(m == 0 && n_min == 0 && n_max == 0) break;
    int P[m];
    REP(i,m) cin >> P[i];
    int ans;
    int gap = 0;
    for(int i = n_min; i <= n_max; i++)
      if(P[i-1]-P[i] >= gap){
        gap = P[i-1]-P[i];
        ans = i;
      }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2992
from bisect import bisect_left

def main():
    n = int(input())
    l = list(map(int,input().split()))
    l.sort()

    ans = 0
    for i in range(n-2):
        for j in range(i+1,n-1):
            ans += bisect_left(l,l[i]+l[j])-j-1

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vvl dp(n, vl(2, -INF));  // dp[i+1][j] : a[i]まで(iは0-index)の総和の最大値。ただし、j = 1 のとき a[i]とa[i+1]に操作を行っているものとする
    dp[0][0] = 0;
    rep(i, n-1) {
        rep(j, 2) {
            chmax(dp[i+1][j], dp[i][j] + a[i]);
            chmax(dp[i+1][1-j], dp[i][j] - a[i]);
        }
    }

    out(max(dp[n-1][0] + a[n-1], dp[n-1][1] - a[n-1]));
    re0;
}

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


int main() {
	
	string s;
	cin >> s;
	multiset<int> t;
	int len = s.size();
	vector<int> r(len), l(len);
	
	for(int i=0; i<len; i++){
		if(s.at(i)=='R'){
			int j;
			if(i!=0){
				if(s.at(i-1)=='R'){
					r.at(i) = r.at(i-1) - 1;
					j = r.at(i);
					if(j%2==1) t.insert(i+j-1);
					else t.insert(i+j);
					continue;
				}
			}
			
			j=1;
			while(1){
				if(s.at(i+j)=='L'){
					r.at(i) = j;
					if(j%2==1) t.insert(i+j-1);
					else t.insert(i+j);
					break;
				}
				else j++;
			}
		}
	}
	
	for(int i=len-1; i>=0; i--){
		if(s.at(i)=='L'){
			int j;
			if(i!=len-1){
				if(s.at(i+1)=='L'){
					l.at(i) = l.at(i+1) - 1;
					j = l.at(i);
					if(j%2==1) t.insert(i-j+1);
					else t.insert(i-j);
					continue;
				}
			}
			
			j=1;
			while(1){
				if(s.at(i-j)=='R'){
					l.at(i) = j;
					if(j%2==1) t.insert(i-j+1);
					else t.insert(i-j);
					break;
				}
				else j++;
			}
		}
		
	}
	
	for(int i=0; i<len; i++){
		cout << t.count(i) << ' ';
	}
	cout << endl;
	
	
	return 0;
}

Measured memory_bytes: 6016
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    sort(begin(l), end(l));
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int ab = l[i] + l[j];
            auto itr = lower_bound(begin(l), end(l), ab);
            itr--;
            if((*itr) >= ab) continue;
            ans += (itr - begin(l)) - j;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

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


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

    res = 0
    for i in range(n):
        if A[i] <= B[i]:
            res += A[i]
            B[i] -= A[i]
            A[i] = 0

            if A[i + 1] <= B[i]:
                res += A[i + 1]
                B[i] -= A[i + 1]
                A[i + 1] = 0
            else:
                res += B[i]
                A[i + 1] -= B[i]
                B[i] = 0
        else:
            res += B[i]
            A[i] -= B[i]
            B[i] = 0

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 19004
n = int(input())
h = [int(i) for i in input().split()]
dp = [0, abs(h[1] - h[0])]
for i in range(2, n):
    dp += [min(dp[-1] + abs(h[i] - h[i - 1]), dp[-2] + abs(h[i] - h[i - 2]))]
print(dp[-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};

using Graph = vector<vector<Edge>>;

Graph G;
vi ans;

void dfs(int v, int p, int col = 0){
  ans[v] = col;
  for(auto e : G[v]){
    if(e.to == p) continue;
    if(e.weight%2 == 0) dfs(e.to, v, col);
    else dfs(e.to, v, 1-col);
  }
}

int main(){
  int n; cin >> n;
  G.assign(n,vector<Edge>());
  rep(i, n-1){
    int u,v,w; cin >> u >> v >> w;
    u--; v--;
    G[u].pb(Edge(v,w));
    G[v].pb(Edge(u,w));
  }

  ans.assign(n,0);
  dfs(0, -1);

  rep(i, n) std::cout << ans[i] << '\n';
}


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

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

    map<int, int> m;
    m[a] += 1;
    m[b] += 1;
    m[c] += 1;
    if (m[5] == 2 && m[7] == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

int n, a, b;

int main() {
    cin >> n >> a >> b;

    if (a+b > n+1 or a*(long long)b < n) {
        cout << "-1";
        return 0;
    }

    vector<int> v(a-1, 0);
    
    for (int i=1; i<=n-b; i++) v[i%v.size()]++;

    v.push_back(b);

    int k = 1;
    for (int i : v) {
        int l = k + i - 1;
        while (l>=k) cout << l-- << ' ';
        k += i;
    }
}

Measured memory_bytes: 3052
const int isDebugMode = 1;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long gcd(T1 a, T2 b){return a % b ? gcd(b , a % b) : b;}
template<class T1, class T2> void reduce(T1 &a, T2 &b){ll g = gcd(a, b); a /= g; b /= g; return;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

int main(){
    vector<int> x(5);
    rep(i, 5) cin >> x[i];
    rep(i, 5){
    if(i != x[i] - 1){
        pt(i + 1);
        return 0;
    }
    }
    return 0;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int ret = 0;
        if (a < 0) {
            ret += a * (-1) * c;
            ret += d;
            ret += b * e;
        } else {
            ret += (b-a) * e;
        }
        System.out.println(ret);
    }
}



Measured memory_bytes: 26288
import numpy as np

param = [int(i) for i in input().split()]
N = param[0]
H = param[1]
W = param[2]

material = np.empty([N,2],dtype=np.int)

for i in range(N):
    material[i,:] = [int(j) for j in input().split()]

count = np.array([material[:,0] >= H, material[:,1] >= W]).T
count = np.all(count==True, axis=1)
count = np.sum(count)
print(count)

Measured memory_bytes: 21328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(),a = scanner.nextInt(),b = scanner.nextInt();
		long[] x = new long[n];
		for(int i=0;i<n;i++){
			x[i] = scanner.nextLong();
		}
		Long count = (long) 0;
		for(int i=0;i<n-1;i++){
			if((x[i+1] - x[i]) * a >= b ){
				count += b;
			}else{
				count += (x[i+1] - x[i]) * a;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 62036
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

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

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

string s[2010];
int zentai[2010][2010];
int ue[2010][2010], hidari[2010][2010];

int get_sum(int table[][2010], int r1, int c1, int r2, int c2) {
    int res = table[r2][c2];
    if (r1 > 0) res -= table[r1 - 1][c2];
    if (c1 > 0) res -= table[r2][c1 - 1];
    if (r1 > 0 && c1 > 0) res += table[r1 - 1][c1 - 1];
    return res;
}

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    for (int r = 0; r < n; r++) {
        cin >> s[r];
    }
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            if (s[r][c] == '1') {
                zentai[r][c]++;
                if (r > 0 && s[r - 1][c] == '1') ue[r][c]++;
                if (c > 0 && s[r][c - 1] == '1') hidari[r][c]++;
            }
            if (c > 0) {
                zentai[r][c] += zentai[r][c - 1];
                ue[r][c]     += ue[r][c - 1];
                hidari[r][c] += hidari[r][c - 1];
            }
        }

        for (int c = 0; c < m; c++) {
            if (r > 0) {
                zentai[r][c] += zentai[r - 1][c];
                ue[r][c]     += ue[r - 1][c];
                hidari[r][c] += hidari[r - 1][c];
            }
        }
    }
    for (int i = 0; i < q; i++) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        r1--; c1--; r2--; c2--;
        int ans = get_sum(zentai, r1, c1, r2, c2);
        // cerr << "最初 <= " << ans << endl;
        if (c1 != c2) ans -= get_sum(hidari, r1, c1 + 1, r1, c2);
        if (r1 != r2) ans -= get_sum(ue, r1 + 1, c1, r2, c1);
        if (c1 != c2 && r1 != r2) {
            ans -= get_sum(hidari, r1 + 1, c1 + 1, r2, c2);
            ans -= get_sum(ue, r1 + 1, c1 + 1, r2, c2);
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 53248
#include <stdio.h>
int main(){
    int N, x, win =0;
    scanf("%d", &N);
    while(N--){
        scanf("%d", &x);
        if(x%2) win = 1;
    }
    if (win) printf("first\n");
    else printf("second\n");
    return 0;
}


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

using namespace std;

int main(){
        string s;
        cin>>s;
        string s2;
        for(int i=0;i<(int)s.length();i++){
                if(s[i]!='x'){
                        s2+=s[i];
                }
        }
        bool res=true;
        for(int i=0;i<(int)s2.length()/2;i++){
                if(s2[i]!=s2[(int)s2.length()-i-1]){
                        res=false;
                        break;
                }
        }
        if(!res){
                cout<<-1<<endl;
                return 0;
        }
        int ans=0;
        for(int i=0;i<(int)s.length()/2;i++){
                if(s[i]!=s[(int)s.length()-i-1]){
                        if(s[i]=='x'){
                                s.insert((int)s.length()-i, "x");
                                ans++;
                                i--;
                        }
                        else{
                                s.insert(i, "x");
                                ans++;
                                i--;
                        }
                }
        }
        //cout<<s<<endl;
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N, K;
  cin>>N>>K;
  int x[N];
  REP(i, N) cin>>x[i];

  if(N==1){
    cout<<abs(x[0])<<endl;
    return 0;
  }

  int ans=1000000000;
  int l, r;
  REP(i, N-K+1){
    l=x[i];
    r=x[i+K-1];
    ans=min(ans, r-l+abs(l));
    ans=min(ans, r-l+abs(r));
  }

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 896