akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2,62);

int main(){
    ll n;
    cin >> n;
    vec A(n);
    for(int i = 0;i < n;i++){
        cin >> A[i];
    }
    ll ans = 0;
    for(int i = 1;i < n;i++){
        if(A[i-1] > A[i]){
            ans += A[i-1] - A[i];
            A[i] = A[i-1];
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 4812
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		
		while(stdIn.hasNext()){
			int n = stdIn.nextInt();
			int count = 0;
			for(int a=0;a<10;a++){
				for(int b=0;b<10;b++){
					for(int c=0;c<10;c++){
						for(int d=0;d<10;d++){
							if((a+b+c+d)==n){
								count++;
							}
						}
					}
				}
			}
			
			System.out.println(count);
		}
	}
}

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

int main() {
    string s;
    cin >> s;
    int n = 0;
    // cout << s[0] << " " << s[s.size()-1] << endl;
    rep(i, s.size()/2){
        // cout << s[i] << " " << s[s.size()-1-i] << endl;
        if(s[i] != s[s.size()-1-i]) n++;
    }
    cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

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; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    // dp[i][j]...i列目が終わった時にj行目にいるようなあみだくじの作り方
    vector<vector<ll>> dp(h+10, vector<ll>(w+10));

    vector<ll> com(w+10);
    com[0] = 1ll;
    com[1] = 2ll;
    rp(i, 2, w){
        com[i] = com[i-1] + com[i-2];
        com[i] %= MOD;
    }

    dp[0][1] = 1ll;
    rp(i, 0, h) {
        rp(j, 1, w+1) {
            if(j < w) {
                int right = max(0, w-j-2);
                int left = max(0, j-2);
                dp[i+1][j+1] += dp[i][j] * com[right] * com[left] % MOD; dp[i+1][j+1] %= MOD;
            }
            if(j > 1) {
                int right = max(0, w-j-1);
                int left = max(0, j-3);
                dp[i+1][j-1] += dp[i][j] * com[right] * com[left] % MOD; dp[i+1][j-1] %= MOD;
            }
            int right = max(0, w-j-1);
            int left = max(0, j-2);
            dp[i+1][j] += dp[i][j] * com[right] * com[left] % MOD; dp[i+1][j] %= MOD;
        }
    }
    // rp(i, 0, h) {
    //     rp(j, 1, w+1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[h][k] << endl;
    return 0;

}


Measured memory_bytes: 3648
fun main(args: Array<String>) {
    agc002a()
}

fun agc002a() {
    val (a, b) = readLine()!!.split(' ').map { it.toLong() }

    if (0 in a..b) return println("Zero")

    val answer = if (a < 0) if ((a - Math.min(0, b + 1)) % 2 == 0L) "Positive" else "Negative" else "Positive"

    println(answer)
}


Measured memory_bytes: 38128
from math import factorial

if __name__ == "__main__":
    n, m = map(int, input().split())

    mod = 10**9+7

    if n > m + 1 or m > n + 1:
        print(0)
        exit()

    if n == m:
        print((factorial(n)**2 + factorial(m)**2) % mod)
    else:
        print(factorial(n)*factorial(m) % mod)


Measured memory_bytes: 5184
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const double PI = 3.14159265358979323846;

int main() {
    int h, w;
    char map[101][101] = {};
    cin >> h >> w;
    for (int y = 0; y < h; ++y) {
        char temp[101];
        cin >> temp;
        for (int x = 0; x < w; ++x) {
            map[x][y] = temp[x];
        }
    }

    int r[101][101] = {};
    for (int y = 0; y < h; ++y) {
        int lastC = -1;
        for (int x = 0; x < w; ++x) {
            if (map[x][y] == 'c') {
                lastC = x;
            }

            r[x][y] = (lastC == -1) ? -1 : x - lastC;
        }
    }

    for (int y = 0; y < h; ++y) {
        for (int x = 0; x < w; ++x) {
            cout << r[x][y];
            if (x != w - 1) {
                cout << " ";
            }
        }

        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1220
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//$fp = fopen("input.txt", "r");
$fp = fopen("php://stdin", "r");

$str = explode(" ", rtrim(fgets($fp)));
$sum_a = 0;
for($i = 0; $i < 4; $i++) {
    $sum_a += (int)($str[$i]);
}
$str = explode(" ", rtrim(fgets($fp)));
$sum_b = 0;
for($i = 0; $i < 4; $i++) {
    $sum_b += (int)($str[$i]);
}
echo $sum_a > $sum_b ? $sum_a : $sum_b;
?>

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

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

	int p = 0;

	for (int i = 0; i < 2; ++i) {
		if (A >= B) {
			p += A;
			--A;
		}
		else {
			p += B;
			--B;
		}
	}
	cout << p << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    double l = a+b, r = c+d;

    if(l>r) cout << "Left" << endl;
    else if(l<r) cout << "Right" << endl;
    else cout << "Balanced" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String[] AC = S.split(""); //1文字ずつ分割
    boolean ans = true; 
    int cnt = 0;
    
    if(AC[0].equals("A")){//1文字目＝A
      for(int i = 1; i < AC.length; i++){
        if(AC[i].toUpperCase().equals(AC[i])){//大文字の数を判定
          if(i == 1 || i == AC.length-1){
            ans = false;
          }else{
            if(AC[i].equals("C")){//3文字目までにC
              cnt ++;
            }else{
              ans = false;
            }
          }
        }
      }
    }else{
      ans = false;
    }
    if(cnt != 1){
      ans = false;
    }
        if(ans){
            System.out.println("AC");
        }else{
            System.out.println("WA");
        }
    }
}


Measured memory_bytes: 22868
#include <iostream>
#include<stdio.h>
#include<string>
#include <bits/stdc++.h>

using namespace std;

int main(){
    int i,n,count=0;
    string S,T;
    cin >> S >> T;
    n = S.length();
    for(i=0;i<n;i++){
        if(S[i]!=T[i])count++;
    }
    cout<<count<<endl;

}

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

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

Node *NIL = NULL;

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

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

void postorder(Node* v) {
	if (v == NIL) return;
	postorder(v->left);
	postorder(v->right);
	printf(" %d", v->key);
}

void insert(Node* &T, Node *z) {
	Node *y = NIL;
	Node *x = T;
	while (x != NIL) {
		y = x;
		if (z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;

	if (y == NIL)
		T = z;
	else if (z->key < y->key)
		y->left = z;
	else
		y->right = z;
}


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

	Node *T = NIL;
	for (int i = 0; i < n; ++i) {
		char cmd[20];
		int v;
		scanf("%s %d", cmd, &v);
		if (cmd[0] == 'i') {
			Node *p = new Node;
			p->key = v;
			insert(T, p);
		} else if (cmd[0] == 'p') {
			inorder(T);
			printf("\n");
			preorder(T);
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 24468
#include <bits/stdc++.h>
using namespace std;
 
int n, now;
int ans = 0;
 
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> now;
        while (now % 2 == 0) {
            now /= 2;
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
// AOJ Volume 1 Problem 0141

#include <stdio.h>
#include <string.h>

int main(void)
{
    int d;
    int n;
    int i, j;
    char screw[100][101];
    int x, y;
    int cnt;
    
    scanf("%d", &d);
    for (i = 0; i < d; i++){
        scanf("%d", &n);
        
        if (i > 0){
            puts("");
        }
        
        if (n == 2){
            printf("##\n# \n");
            continue;
        }
        
        memset(screw, ' ', sizeof(screw));
        for (j = 0; j < n; j++){
            screw[j][n] = '\0';
        }
        
        x = 0;
        y = n - 1;
        
        screw[y][x] = '#';
        while (1){
            // ツ湘」ツ古シツつォ
            cnt = 0;
            while (y > 0){
                y--;
                if (y < 1 || screw[y - 1][x] == ' '){
                    screw[y][x] = '#';
                    cnt++;
                }
                else {
                    y++;
                    break;
                }
            }
            if (cnt < 2){
                break;
            }

            // ツ右ツ古シツつォ
            cnt = 0;
            while (x < n - 1){
                x++;
                if (x >= n - 1 || screw[y][x + 1] == ' '){
                    screw[y][x] = '#';
                    cnt++;
                }
                else {
                    x--;
                    break;
                }
            }
            if (cnt < 2){
                break;
            }

            // ツ可コツ古シツつォ
            cnt = 0;
            while (y < n - 1){
                y++;
                if (y >= n - 1 || screw[y + 1][x] == ' '){
                    screw[y][x] = '#';
                    cnt++;
                }
                else {
                    y--;
                    break;
                }
            }
            if (cnt < 2){
                break;
            }

            // ツ債カツ古シツつォ
            cnt = 0;
            while (x > 0){
                x--;
                if (x < 1 || screw[y][x - 1] == ' '){
                    screw[y][x] = '#';
                    cnt++;
                }
                else {
                    x++;
                    break;
                }
            }
            if (cnt < 2){
                break;
            }
        }
        
        for (j = 0; j < n; j++){
            printf("%s\n", screw[j]);
        }
    }
    
    
    return (0);
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        int area = a*b;
        int perimeter = 2*(a+b);
        System.out.println(area+" "+perimeter);
    }
}


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

int main() {
	double velocity, time, height;
	int answer;
	while (cin >> velocity) {
		time = velocity / 9.8;
		height = 4.9 * time * time;
		answer = (ceil(height) - 1) / 5 + 2;
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
char s[7];
int main(void){
    scanf("%s",s);
    if (s[2] == s[3] && s[4] == s[5])
    {
        printf(yes);
    } else
    {
        printf(no);
    }
    
    
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
#include <stdbool.h>


//using ll = long long;
int ASC( void *a,  void *b) {
	return strcmp(*(const char **)a, *(const char **)b);//降順
}
int GCD(int a, int b) {	//最大公約数
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int min(double a, double b ) {
	if (a < b) {
		return a;
	}
	else
		return b;
}
int max(int a, int b) {
	if (a < b)
		return b;
	else
		return a;
}
int main(void)
{
	char n[200000];
	scanf("%s",n);
	long len = strlen(n);
	for (long i = 0; i < len; i++) {
		if (i == 0 && n[i] == '?') {
			if (n[i + 1] == 'D' || n[i + 1] == '?')
				n[i] = 'P';
			else n[i] = 'D';
		}
		else if (n[i] == '?') { 
			if (n[i - 1] == 'P'|| n[i-1] == 'D')
				n[i] = 'D';
			else if (n[i + 1] == 'D' || n[i + 1] == '?')
				n[i] = 'P';
		}
		printf("%c",n[i]);
	}
	return 0;
}

Measured memory_bytes: 1856
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    int N; cin >> N;
    cout << N*N*N << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    //abc
    if(a <= b && b <= c)
      System.out.println(a + " " + b + " " + c);
    //acb
    else if(a <= c && c <= b)
      System.out.println(a + " " + c + " " + b);
    // bac
    else if(b <= a && a <= c)
      System.out.println(b + " " + a + " " + c);
    // bca
    else if(b <= c && c <= a)
      System.out.println(b + " " + c + " " + a);
    // cab
    else if(c <= a && a <= b)
      System.out.println(c + " " + a + " " + b);
    // cba
    else if(c <= b && b <= a)
      System.out.println(c + " " + b + " " + a);
  }
}


Measured memory_bytes: 26296
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cstdint>

std::vector<std::string> sys_args(int argc, char **argv) {
    std::vector<std::string> args;

    for (int i = 0; i < argc; ++i)
        args.emplace_back(argv[i]);

    return args;
}

/*
 * output: 12345
 */
template<typename T>
void print(const T& vs) {
    for (auto&& v : vs)
        std::cout << v;

    std::cout << std::endl;
}

/*
 * output: [ 1 2 3 4 5 ]
 */
template<typename T>
void print_list(const T& vs) {
    std::cout << "[ ";

    for (auto&& v : vs)
        std::cout << v << " ";

    std::cout << "]" << std::endl;
}

/*
 * input: "012345"
 * output: [0, 1, 2, 3, 4 ,5]
 */
template<typename T>
std::vector<T> str_to_nums(const std::string& s) {
    std::vector<T> vs;
    for (auto&& v : s)
        vs.emplace_back(v - '0');
    return vs;
}

/*
 * input:
 * S
 */
std::string get_line(void) {
    std::string line;
    getline(std::cin, line);
    return line;
}

/*
 * input:
 * H1 H2 H3 ... Hn ...
 */
template<typename T>
std::vector<T> get_nums() {
    auto line = get_line();
    std::istringstream iss(line);
    std::vector<T> vs;

    T v;
    while (iss >> v)
        vs.emplace_back(v);

    return vs;
}

/*
 * input:
 * N
 * H1 H2 ... HN
 */
std::vector<int> get_n_nums(void) {
    size_t n;
    std::cin >> n;

    std::vector<int> hs;
    hs.reserve(n);

    for (size_t i = 0; i < n; ++i) {
        int h;
        std::cin >> h;
        hs.emplace_back(h);
    }

    return hs;
}

using namespace std;

int main(int argc, char **argv)
{
    auto line = get_line();
    int win = 0;
    for (auto c : line) {
        if (c == 'o')
            win++;
    }
    if (win + (15 - line.length()) >= 8)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define vv vector
#define pp pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define fastio                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);
typedef pair<ll, ll> pll;
typedef vv<ll> vll;
typedef vv<pll> vpll;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//adds two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
#define LG(args...)                               \
	{                                             \
		string _s = #args;                        \
		replace(_s.begin(), _s.end(), ',', ' ');  \
		stringstream _ss(_s);                     \
		err(istream_iterator<string>(_ss), args); \
		cerr << endl;                             \
	}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "(" << *it << ":" << a << ") ";
	err(++it, args...);
}
//:::::::::::::::::::::::::::::::::::::::::::::
const ll INF = 9e18;
const ll MOD = 1e9 + 7;
// #define dbg

int main(){
	fastio;
	char a;
	cin>>a;
	if(a>='a' && a<='z')
		cout<<"a";
	else
		cout<<"A";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 100000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pii a, pii b)//true for a before b
{
	if(a.S < b.S)
		return 1;
	if(a.S > b.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (5e3) + 9;
const int M = (3e7) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;

int dp[N], pr[2][3];
ll dp2[M];

void solve()
{
	int n, i, j;
	ll ans;
	cin >> n;
	ans = n;
	fo(j,0,2)
		fo(i,0,3)
			cin >> pr[j][i];
	
	fo(i,0,n+1)
		dp[i] = i;
	fo(i,1,n+1)
		fo(j,0,3)
			if(pr[0][j] <= i)
				dp[i] = max(dp[i], dp[i-pr[0][j]] + pr[1][j]);
	ans = max(ans, 1LL*dp[n]);
	n = max(n, dp[n]);

	fo(i,0,n+1)
		dp2[i] = i;
	dp2[0] = 0;
	fo(i,1,n+1)
		fo(j,0,3)
			if(pr[1][j] <= i)
				dp2[i] = max(dp2[i], dp2[i-pr[1][j]] + pr[0][j]);
	ans = max(ans, dp2[n]);
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand(clock());

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(6);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    int rev = 0;
    string front = "", back = "";
    for (int i = 0; i < q; i++) {
        int t, f;
        char c;
        cin >> t;
        if (t == 1) {
            rev++;
            continue;
        } else {
            cin >> f >> c;
            f--;
            if (rev % 2) f = 1 - f;
            if (f == 0) {
                front+= c;
            } else {
                back += c;
            }
        }
    }
    reverse(front.begin(), front.end());
    string ans = front + s + back;
    if (rev % 2) reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int M, K;
    cin >> M >> K;
    
    if (K == 0) {
        rep(i, 0, 1<<M) cout << i << " " << i << " ";
        return 0;
    }

    if (((1<<M)-1) < K or M == 1) {
        cout << -1 << endl;
        return 0;
    }

    cout << K;
    stack<int> st;
    rrep(i, (1<<M)-1, 0) {
        if (i != K) {
            cout << " " << i;
            st.push(i);
        }
    }
    cout << " " << K;
    rrep(i, st.size()-1, 0) {
        cout << " " << st.top();
        st.pop();
    }
    cout << endl;
}

Measured memory_bytes: 2432
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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


int main(void) {
	int N, i, j, k, tmp, r = 0, sum = 0, ans = 0;
	vector<int> A[2];

	scanf("%d", &N);
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			scanf("%d", &tmp);
			A[i].push_back(tmp);
		}
	}

	for (int i = 0; i < N; i++) {
		r = 0;
		sum = 0;
		for (int j = 0; j < N; j++) {
			if (i == j) {
				sum += A[r].at(j);
				r = 1;
				sum += A[r].at(j);
			}
			else {
				sum += A[r].at(j);
			}
		}
		ans = max(ans, sum);
	}
	printf("%d", ans);
	

	


	return 0;
}

Measured memory_bytes: 384
n = gets.to_s.to_i
rr = ll = 0
ary = []

n.times do
  s = gets.to_s.chomp
  nil while s.sub!("()", "")

  l = r = 0
  s.each_char do |c|
    if c == ?(
      l += 1
    else
      r += 1
    end
  end
  
  if l == 0
    rr += r
  elsif r == 0
    ll += l
  else
    ary << [r, l]
  end
end

ary.sort_by!{|(r,l)| r - l }.each do |(r,l)|
  ll -= r
  break if ll < 0
  ll += l
end

puts ll == rr ? "Yes" : "No"

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

using namespace std;

typedef long long ll;


int main() {
    string s;cin >> s;
    sort(s.begin(),s.end());
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]==s[i+1]){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline int mul(int a, int b) {
  return (int)((long long)a * b % md);
}
inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
      b--;
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
inline int inv(int a) {
  a %= md;
  if(a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= a * t; swap(a, b);
    u -= v * t; swap(u, v);
  }
  assert(b == 1);
  if(u < 0) u += md;
  return u;
}
int main() {
  string s;
  cin >> s;
  int n = s.length();
  s.insert(s.begin(), '$');
  vector<vector<int>> dp(n + 1, vector<int>(4, 0));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 3; j++) {
      int crr = dp[i][j];
      add(dp[i + 1][j], mul(crr, s[i + 1] == '?' ? 3 : 1));
      if (j < 3 && (s[i + 1] == 'A' + j || s[i + 1] == '?')) {
        add(dp[i + 1][j + 1], crr);
      }
    }
  }
  cout << dp[n][3] << endl;
  return 0;
}

Measured memory_bytes: 5760
import math
s=input()
n=len(s)
count=0
a=[0 for i in range(2019)]
a[0]=1
k=0
b=[0 for i in range(n)]
b[0]=1
for i in range(1,n):
    b[i]=b[i-1]*10%2019
for i in reversed(range(0,n)):
    k+=(b[n-i-1])*int(s[i])%2019
    a[k%2019]+=1        
for i in range(len(a)):
    if a[i]>=2:
        count+=(a[i])*(a[i]-1)//2
print(count)

Measured memory_bytes: 16448
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int h, w; cin >> h >> w;
	rep(i, 0, h) {
		string s; cin >> s;
		rep(j, 0, w) {
			if (j)cout << " ";
			for (int k = j; k >= 0; k--) {
				if (s[k] == 'c') {
					cout << j - k;
					goto here;
				}
			}
			cout << -1;
		here:;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
const ll big=998244353;
const ll bbig=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%bbig;
    ll t=exp(x,y/2);
    return (t*t)%bbig;
}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll in(ll x){
    return exp(x,bbig-2);
}
/*ll com(ll x,ll y){
    ll ans=1;
    rep(i,y){ans*=x-i;ans%=bbig;}
    rep(i,y){ans*=in(i+1);ans%=bbig;}
    return ans;
}*/

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    ll n,m,k;cin >> n >> m >> k;
    vector<ll> a(n+1);
    vector<ll> b(m+1);
    rep(i,n){
        ll aa;cin >> aa;
        a[i+1]=a[i]+aa;
    }
    rep(i,m){
        ll l;cin >> l;
        b[i+1]=b[i]-l;
    }
    reverse(b.begin(),b.end());
    vector<ll> ans(n+m+1);
    ans[0]=b[0];
    rep(i,m)ans[i+1]=b[i+1];
    rep(j,n)ans[j+m+1]=a[j+1];
    
    
    ll cnt=0;
    int right=m;//開区間で見る
    for(int i=0;i<=m;i++){
        if(right<=i)right=i+1;
        if(ans[right]-ans[i]>k)continue;
        while(right<=(n+m)&&ans[right]-ans[i]<=k){
            right++;
        }
        cnt=max(cnt,right-i-1);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 9508
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;

const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
if(b==0)return a;

return gcd(b,a%b);
}

LL lcm(LL a,LL b){
LL g=gcd(a,b);

return a/g*b;
}


int main(){
    string s;
    cin>>s;
    int ans=0;
    int now=0;
    for(int i=0;i<s.size();++i){
        if(s[i]=='1'){
            now++;
        }
        else now--;
    }
    cout<<s.size()-abs(now)<<endl;
}



Measured memory_bytes: 512
def func():
  array = input().split(' ')
  N = int(array[0])
  K = int(array[1])
  K_2 = K / 2
  if N <= K_2:
    print(N)
    return
  while 1:
    if N >=K:
      N %= K
    else:
      N = K - N
    if N <= K_2:
      break;

  print(N)

func()

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AthleteProgramming
{
    class Program
    {
        static void Main()
        {
            char[] str = Console.ReadLine().ToArray();
            Reverse(ref str);
            Console.WriteLine(str);
        }

        static void Reverse(ref char[] str)
        {
            for(int i = 0; i < str.Length / 2; i++)
            {
                Swap(ref str[i], ref str[str.Length-i-1]);
            }
        }

        static void Swap(ref char a,ref  char b)
        {
            char tmp = a;
            a = b;
            b = tmp;
        }
        
    }
}

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

namespace AtCoder
{
    class Program
    {
        static bool Count(int[] values, int num, int step)
        {
            for (int i = 0; i < 26 && num > 0; ++i)
            {
                while (values[i] >= step && num > 0)
                {
                    values[i] -= step;
                    --num;
                }
            }
            return num == 0;
        }
        static bool Solve(int H, int W, string[] A)
        {
            var values = new int[26];
            foreach (string a in A)
            {
                foreach (char c in a)
                {
                    ++values[c - 'a'];
                }
            }
            if (!Count(values, (H / 2) * (W / 2), 4)) { return false; }
            if (!Count(values, (H / 2) * (W % 2), 2)) { return false; }
            if (!Count(values, (H % 2) * (W / 2), 2)) { return false; }
            if (!Count(values, (H % 2) * (W % 2), 1)) { return false; }
            return values.Sum() == 0;
        }
        static void Main(string[] args)
        {
            int[] V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int H = V[0];
            int W = V[1];
            var A = new string[H];
            for (int i = 0; i < H; ++i) { A[i] = Console.ReadLine(); }
            Console.WriteLine(Solve(H, W, A) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int M;
  cin >> N >> M;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += vec.at(i);
  }
        
        sort(vec.begin(), vec.end());
  
  int answer = 0;
  
        for (int i = 0; i < N; i++) {
        if (vec.at(i) * 4 * M >= sum) {
          answer++;
        }
        }
  
  if (answer >= M) {
   cout << "Yes" << endl;
  }
  
   else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int compare_int(const void *a, const void *b)
{
	// 降順 
	return *(int *) b - *(int *) a;
}

int main(int argc, char *argv[])
{
	int n, i, c;
	int j;
	int a[200000];
	
	int x, y;
	int min_sq, l_min_sq;
	
	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	
	qsort(a, n, sizeof(int), compare_int);

	c = 0;

	l_min_sq = -1;
	for (i = 0; i < n; i++) {
		x = a[i];
		if (x == 0) {continue;}
		min_sq = pow(2, (int) log2(x) + 1);

		if (l_min_sq != min_sq) {
			j = n - 1;
		}
		for (;j > i; j--) {
			y = a[j];
			if (y == 0) {continue;}
			if (y == min_sq - x) {
				a[j] = 0;
				c++;
				break;
			}
			if (y > min_sq - x) {
				break;
			}
		}
		l_min_sq = min_sq;
	}

	printf("%d\n", c);
	
	return 0;
}

Measured memory_bytes: 1788
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

int main() {
    ll n;
    double val = 380000.0;
    cin >> n;
    double res = 0;
    for (ll i = 0; i < n; ++i) {
        double v;        
        string unit;
        cin >> v >> unit;
        if (unit == "JPY") {
            res += v;
        } else {
            res += v * val;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
s = input()
k = int(input())
ans = []
for i in range(len(s)):
  toa =(ord('z')-ord(s[i]))+1
  if s[i] =='a':ans += s[i]
  else:
   if toa <= k:
     k -= toa 
     ans += 'a'
   else: ans += s[i]

if k == 0:print("".join(ans))
else: 
  rest = k%26
  tmp = ord(ans[-1])+rest
  if tmp >122:
    tmp -= 26
  ans[-1] = chr(tmp)
  print("".join(ans))

Measured memory_bytes: 4212
N = int(input())

a = N/1.08
X = a*10//10

if(int(int(X)*1.08)==N):
  print(int(X))
elif(int((int(X)+1)*1.08)==N):
  print(int(X)+1)
elif(int((int(X)-1)*1.08)==N):
  print(int(X)-1)
else:
  print(":(")

Measured memory_bytes: 3060
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"4 10"# => "3",
r#"8 9"# => "2",
r#"8 8"# => "1",
r#"2 20"# => "19",
r#"3 10"# => "5",
r#"5 1"# => "0",
r#"2 19"# => "18",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: usize,
        b: usize,
    }

    let mut ans = 0;
    let mut outlet = 1;

    while outlet < b {
        outlet -= 1;
        outlet += a;
        ans += 1;
    }

    ans.to_string()
}

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

if n==1:
  print(1)
elif n==2:
  print(3)
else:
  ans=0
  num_1=2
  num_2=1
  for i in range(n-1):
    ans = num_1+num_2
    num_1,num_2 = num_2, ans
  print(ans)

Measured memory_bytes: 9116
def calc_count(token):
    num_left = token.count('<')
    num_right = token.count('>')
    sum_left = sum(range(num_left))
    sum_right = sum(range(num_right))
    midle = max(num_left, num_right)
    return sum_left + sum_right + midle


def main(n):
    strings = n.replace('><', '>|<').split('|')
    return sum([calc_count(s) for s in strings])


if __name__ == '__main__':
    N = input().strip()
    print(main(n=N))

Measured memory_bytes: 13368
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int N, K;
int H[200200];

int c(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}
int main() {
  int i;
  long long total = 0;
  
  scanf("%d", &N);
  scanf("%d", &K);
  for (i = 0; i < N; i++) {
    scanf("%d", &(H[i]));
  }
  qsort(H, N, sizeof(int), c); // 降順ソート
  for (i = K; i < N; i++) {
    total += H[i];
  }
  printf("%lld\n", total);
}

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int M = 1299710, n, l, r;
  vector<bool> P(M, true);
  for (int i = 2; i*i < M; ++i) {
    if (P[i]) {
      for (int j = i; i*j < M; ++j) {
	P[i*j] = false;
      }
    }
  }
  while (cin >> n, n) {
    r = n;
    l = n;
    while (!P[r]) ++r;
    while (!P[l]) --l;
    cout << r - l << endl;
  }
  return 0;
}

Measured memory_bytes: 3080
//============================================================================
// Name        : Codeforces.cpp
// Author      : SilkayYu
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <functional>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

const int maxn = 100010;
const int MOD = 1000000007;

int main()
{
	long long ans = 1;
	int n, t[maxn], m[maxn];
	long long cnt[maxn];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &t[i]);
		if (i == 0) {
			cnt[i] = 1;
		} else {
			if (t[i] > t[i - 1]) {
				cnt[i] = 1;
			} else {
				cnt[i] = (long long)t[i - 1];
			}
		}
		m[i] = t[i];
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &t[n - i - 1]);
	}
	for (int i = 0; i < n; i++) {
		//cout << t[i] << " " << cnt[n - i - 1] << endl;
		if (i == 0) {
			if (cnt[n - 1] == 1) {
				if (t[0] != m[n - 1]) {
					cnt[n - 1] = 0;
					continue;
				}
			}
			cnt[n - 1] = 1;
			if (t[0] > m[n - 1]) {
				cnt[n - i - 1] = 0;
			}
		} else {
			if (cnt[n - i - 1] == 1) {
				if (t[i] < m[n - i - 1]) {
					cnt[n - i - 1] = 0;
				}
			} else {
				if (t[i] > t[i - 1]) {
					cnt[n - i - 1] = 1;
				} else {
					cnt[n - i - 1] = min(cnt[n - i - 1], (long long)t[i]);
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		ans = ans * (long long)cnt[i];
		ans = ans % MOD;
	}
	printf("%I64d\n", ans);
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  string S;
  cin>>S;
  ll A=0,BC=0,ans=0;
  rep(i,S.size()){
    if(S[i]=='A'&&BC==0) A++;
    else if(S[i]=='A'&&BC==10) A=1,BC=0;
    else if(S[i]=='B'&&A&&BC==0) BC+=10;
    else if(S[i]=='C'&&BC==10) ans+=A,BC=0;
    else A=0,BC=0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
N = int(input())
a = [int(x) for x in input().split()]

min_df = 10**100

for i in range(min(a), max(a) + 1) :
    sum_over = 0 
    for j in a :
        sum_over += (i - j) ** 2
        
    min_df = min(min_df, sum_over)
    
print(min_df)

Measured memory_bytes: 2940
N = int(input())
S = ''.join([str(int(d) - 1) for d in input()])

def solve01(s):
    "solve the problem when 's' consists of 0 or 1"
    ans = 0
    for k, d in enumerate(s):
        if k & (N - 1) == k:
            ans ^= int(d)
    return ans      

if '1' in S: # 0 or 1
    print(solve01(S.replace('2', '0')))
else: # 0 or 2
    print(solve01(S.replace('2', '1')) * 2)

Measured memory_bytes: 82996
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
#define F first
#define S second

int n, m, k;
pair<int, int> src, dst;
vector<vector<char>> grid;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
vector<vector<pair<int, int>>> nxt[4];
vector<vector<int>> vis;

int dist(int x, int y, int nx, int ny) {
  return abs(x - nx) + abs(y - ny);
}

bool good(int nx, int ny) {
  return nx >= 0 && nx < n && ny >= 0 && ny < m;
}

pair<int, int> find_nxt(int d, int x, int y) {
  if(!good(x, y)) return {x, y};
  if(nxt[d][x][y] == mp(x, y)) return {x, y};
  int nx = nxt[d][x][y].F, ny = nxt[d][x][y].S;
  return nxt[d][x][y] = find_nxt(d, nx, ny);
}

void update_nxt(int x, int y) {
  for(int d = 0; d < 4; d++) {
    int nx = x + dx[d];
    int ny = y + dy[d];
    nxt[d][x][y] = {nx, ny};
  }
}

int main()
{
  ios::sync_with_stdio(false);
  
  cin >> n >> m >> k;
  cin >> src.F >> src.S >> dst.F >> dst.S;
  src.F--, src.S--, dst.F--, dst.S--;
  grid.resize(n, vector<char>(m));
  cin.ignore();
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m ;j++)  {
      cin >> grid[i][j];
    }
  }
  for(int i = 0; i < 4; i++)
    nxt[i].resize(n, vector<pair<int, int>>(m));
  for(int d = 0; d < 4; d++) {
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < m; j++) {
        nxt[d][i][j] = {i, j};
      }
    }
  }
  vis.resize(n, vector<int>(m, -1));
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      if(grid[i][j] == '@') {
        vis[i][j] = 0;
        for(int d = 0; d < 4; d++)
          nxt[d][i][j] = {-1, -1}; // out
      }
    }
  }
  
  queue<pair<int, int>> q;
  q.push(src);
  vis[src.F][src.S] = 0;
  update_nxt(src.F, src.S);

  while(!q.empty()) {
    int x = q.front().F;
    int y = q.front().S;
    q.pop();
    if(mp(x, y) == dst)
      break;
    for(int d = 0; d < 4; d++) {
      int nx = x + dx[d];
      int ny = y + dy[d];
      // cerr << d << " " << nx + 1 << " " << ny + 1 << endl;
      auto cell = find_nxt(d, nx, ny);
      nx = cell.F, ny = cell.S;
      // cerr << d << " " << nx + 1 << " " << ny + 1 << endl;
      while(good(nx, ny) && dist(x, y, nx, ny) <= k) {
        vis[nx][ny] = 1 + vis[x][y];
        update_nxt(nx, ny);
        q.push({nx, ny});
        cell = find_nxt(d, nx, ny);
        nx = cell.F, ny = cell.S;
      }
    }
  }
  cout << vis[dst.F][dst.S] << endl;
  return 0;
}


Measured memory_bytes: 47284
def hoge():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    a = 0
    b = 0

    ib = 0
    while True:
        if ib != M and b + B[ib] <= K:
            b += B[ib]
            ib += 1
        else:
            break
    ans = ib
    for ia in range(N):
        while a + A[ia] + b > K:
            if ib == 0:
                return ans
            ib -= 1
            b -= B[ib]
        a += A[ia]
        ans = max(ans,ia+ib+1)

    return ans

print(hoge())

Measured memory_bytes: 117692
use proconio::input;

fn main() {
    input! {
        s: String,
    }
    let (mut max, mut current) = (0, 0);
    for c in s.chars() {
        match c {
            'A' | 'C' | 'G' | 'T' => current += 1,
            _ => current = 0,
        }
        max = max.max(current);
    }
    println!("{}", max);
}


Measured memory_bytes: 2092
#include<stdio.h>
#include <string.h>
typedef long long int ll;
ll n,maxW;
ll weight[104], value[105];
ll dp[100005][105];
ll max(ll a, ll b){
    return a > b ? a: b;
}
ll knap(ll currW, ll i){
    //base case
    if(i == n){
        return 0;
    }
    
    if(dp[currW][i] != -1){
        return  dp[currW][i];
    }
    if(weight[i] + currW <= maxW){
        return dp[currW][i]  = max(value[i] + knap(currW + weight[i], i + 1), knap(currW, i + 1));
    }
    return dp[currW][i] = knap(currW, i + 1);
    
    
    
}
int main(){
    memset(dp, -1, sizeof(dp));
    scanf("%lld %lld", &n , &maxW);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld %lld", &weight[i], &value[i]);
        
    }
    
    printf("%lld", knap(0, 0));
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int a, b;
    cin >> a >> b;
    cout << a * b << " " << a * 2 + b * 2 << endl;
}



Measured memory_bytes: 2996
N=int(input())
result=[]
for i in range(1,N):
  A=str(i)
  B=str(N-int(A))
  goukei=[]
  for j in range(len(A)):
    goukei.append(int(A[j]))
  for k in range(len(B)):
    goukei.append(int(B[k]))
  result.append(sum(goukei))

print(min(result))

Measured memory_bytes: 3864
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())
int F[100][15];
int main(void) {
	int N, w=1;
	std::string s;
	std::cin >> s;
	bool flag = true;
	reverse(s.begin(), s.end());
	size_t i = 0;
	while (i<s.size()) {
		if (s.substr(i, 7) == "remaerd")i += 7;
		else if (s.substr(i, 6) == "resare")i += 6;
		else if (s.substr(i, 5) == "esare" || s.substr(i, 5) == "maerd")i += 5;
		else {
			std::cout << "NO" << std::endl;
			return 0;
		}
	}
	
	std::cout << "YES" << std::endl;
	
	return 0;
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A == B && B == C){
    cout << "No";
  }
  else if(A == B || B == C || C == A){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 256