akhauriyash/Code-Regression huggingface dataset:
use std::cmp;

const B_SIZE: usize = 31;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let k: u32 = sc.read();

    let ab: Vec<(u32, u64)> = (0..n).map(|_| (sc.read(), sc.read())).collect();

    let mut max = 0;
    for r in 0..B_SIZE {
        if ((1 << r) & k) == 0 { continue; }
        let u = (1 << B_SIZE) - (1 << (r + 1));
        assert_eq!(k, (u & k) + (1 << r) + (((1 << r) - 1) & k));
        let x = (u & k) + (1 << r) - 1;

        let mut values = 0;
        for &t in &ab {
            let (a, b) = t;
            if (x | a) == x {
                values += b;
            }
        }

        max = cmp::max(max, values);
    }
    let mut values = 0;
    for &t in &ab {
        let (a, b) = t;
        if (k | a) == k {
            values += b;
        }
    }
    max = cmp::max(max, values);

    println!("{}", max);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 6396
n, x, y = list(map(int, input().split()))

a = {i:0 for i in range(1, n)}


for i in range(1,n+1):
    for j in range(i+1, n+1):
        k = min(j-i, abs(i-x) +abs(j-y)+1)
        a[k] += 1

for i in range(1, n):
    print(a[i])

Measured memory_bytes: 3572
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define f(i,n) for(int i=0;i<int(n);i++)
#define N (1<<18)
#define INIT 9223372036854775807
#define INIT2 0
#define INIT3 0
long long a[(2 * N)];
long long laz[(2 * N)];
int l[(2 * N)];
int r[(2 * N)];

long long f1(long long x, long long y) {
	if (x != INIT)return x;
	return y;
}
long long f2(long long k, long long x, long long y) {
	if (x != INIT)return x*(r[k]-l[k]);
	return y;
}
long long f3(long long x, long long y) {
	return (x + y);
}


void init(void) {
	f(i, (2 * N)) {
		a[i] = INIT2;
		laz[i] = INIT;
	}
	l[1] = 0;
	r[1] = N;
	for (int i = 1; i < N; i++) {
		l[(2 * i)] = l[i];
		r[(2 * i)] = (l[i] + r[i]) / 2;
		l[(2 * i) + 1] = (l[i] + r[i]) / 2;
		r[(2 * i) + 1] = r[i];
	}
	return;
}



long long change(int ll, int rr, int k, long long x) {
	long long vl, vr;
	if ((rr <= l[k]) || (r[k] <= ll))return f2(k, laz[k], a[k]);
	if (laz[k] != INIT) {
		a[k] = f2(k, laz[k], a[k]);
		if (k < N) {
			laz[(2 * k)] = f1(laz[k], laz[(2 * k)]);
			laz[(2 * k) + 1] = f1(laz[k], laz[(2 * k) + 1]);
		}
		laz[k] = INIT;
	}
	if ((ll <= l[k]) && (r[k] <= rr)) {
		laz[k] = f1(x, laz[k]);
		return f2(k, laz[k], a[k]);
	}
	else {
		int mm = (l[k] + r[k]) / 2;
		if ((l[k] < rr) && (ll < mm)) {
			vl = change(ll, rr, 2 * k, x);
		}
		else vl = f2((2 * k), laz[(2 * k)], a[(2 * k)]);

		if ((mm < rr) && (ll < r[k])) {
			vr = change(ll, rr, (2 * k) + 1, x);
		}
		else vr = f2((2 * k) + 1, laz[(2 * k) + 1], a[(2 * k + 1)]);

		a[k] = f3(vl, vr);
		return f2(k, laz[k], a[k]);
	}
}


long long search(int ll, int rr, int k) {
	if (laz[k] != INIT) {
		a[k] = f2(k, laz[k], a[k]);
		if (k < N) {
			laz[(2 * k)] = f1(laz[k], laz[(2 * k)]);
			laz[(2 * k) + 1] = f1(laz[k], laz[(2 * k) + 1]);
		}
		laz[k] = INIT;
	}
	long long vl, vr;
	if (rr <= l[k] || r[k] <= ll)return INIT3;
	else if (ll <= l[k] && r[k] <= rr) return f2(k, laz[k], a[k]);
	else {
		vl = search(ll, rr, 2 * k);
		vr = search(ll, rr, (2 * k) + 1);
		a[k] = f3(f2((2 * k), laz[(2 * k)], a[(2 * k)]), f2((2 * k) + 1, laz[(2 * k) + 1], a[(2 * k) + 1]));
		return f3(vl, vr);
	}
}


int main(void) {
	int q;
	int c, x, y;
	long long k;
	init();
	scanf("%d %d", &c, &q);
	f(qq, q) {
		scanf("%d", &c);
		if (c == 0) {
			scanf("%d %d %lld", &x, &y, &k);
			change(x, y + 1, 1, k);
		}
		else if (c == 1) {
			scanf("%d %d", &x, &y);
			k = search(x, y + 1, 1);
			printf("%lld\n", k);
		}
	}
	return 0;
}


Measured memory_bytes: 15044
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;


int main() {
	string S, T;
	cin >> S >> T;
	vector<int> start(26, -1);
	vector<int> goal(26, -1);
	for (int i = 0; i < S.length(); i++)
	{
		int a = S[i] - 'a';
		int b = T[i] - 'a';

		if (start[a] != -1 || goal[b] != -1) {
			if (start[a] != b || goal[b] != a) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			start[a] = b;
			goal[b] = a;
		}
	}

	cout << "Yes" << endl;
}


Measured memory_bytes: 776
n = int(input())
p = list(map(int, input().split()))
l = []
for i in range(n):
    p[i] -= 1
    if p[i] != i:
        l.append([i, p[i]])
if len(l) == 0:
    print('YES')
elif len(l) == 2 and l[0][1] == l[1][0] and l[0][0] == l[1][1]:
    print('YES')
else:
    print('NO')

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

int main() {
map<string,int> gift;
int N,ans;
  ans=0;
cin>>N;
string S[N];
for(int i=0;i<N;i++){
cin>>S[i];
if(gift[S[i]]!=1){
gift[S[i]]=1;
ans++;
}
}
cout<<ans;
}

Measured memory_bytes: 25508
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn inv(a: usize) -> usize {
    let m = M as i64;
    let mut a = a as i64;
    let mut b = m as i64;
    let mut u = 1;
    let mut v = 0;
    let mut tmp;
    while b != 0 {
        let t = a / b;
        a -= t * b;
        tmp = a;
        a = b;
        b = tmp;
        u -= t * v;
        tmp = u;
        u = v;
        v = tmp;
    }
    u %= m;
    if u < 0 {
        u += m;
    }
    return u as usize;
}

fn main() {
    input! {
        n: usize,
        m: usize,
    }
    let mut f = vec![1; m + 1];
    let mut g = vec![1; m + 1];
    for i in 1..=m {
        f[i] = i * f[i - 1] % M;
        g[i] = inv(f[i]);
    }
    // let mut h1 = vec![1; n + 1];
    // let mut h2 = vec![1; n + 1];
    // for k in 1..=n {
    //     let s = (m - n + k) * inv(k) % M;
    //     h1[k] = s * h1[k - 1] % M;
    //     eprintln!("{}", (s + M - h1[k]));
    // }
    // eprintln!("{:?}", f);
    // eprintln!("{:?}", g);
    // eprintln!("{:?}", h1);
    let mut result = 0;
    for k in 0..=n {
        let s = f[m - k] * g[m - n] % M;
        let s = s * s % M;
        let t = f[n] * g[k] % M * g[n - k] % M;
        let u = f[m] * g[m - k] % M;
        // eprintln!("{} {} {}", s, t, u);
        if k % 2 == 0 {
            result = (result + s * t % M * u % M) % M;
        } else {
            result = (result + M - s * t % M * u % M) % M;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 9876
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println((int)Math.max(a+b, Math.max(a-b, a*b)));
	}
}

Measured memory_bytes: 23892
n,k = (int(i) for i in input().split())  
string = input()
s = [string[i] for i in range(len(string))]

count = 0
first = 0
end = 0

if s[0] == 'L':
    first = 1

if s[-1] == 'R':
    end = 1

for i in range(len(s)):
    d = s[i]
    if d == 'L' and i>0 and s[i-1]=='L':
        count += 0
    elif d == 'R' and i<n-1 and s[i+1]=='R':
        count += 0
    else:
        count += 1

line = first + end

for i in range(k):
    if count-2 >= line:
        count += -2
    else:
      	count += -1


if count < 1:
    count = 1
    
print(n-count)

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=0; i<(int)n; i++)
ll power(ll x,ll n);
bool isprime(ll n);

void test_case()
{
    char c;
    cin>>c;
    if(c>='A' && c<='Z')
        cout<<"A";
    else
        cout<<"a";
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}
ll power(ll x,ll n)
{
    ll ans=1;
    while(n>0) {
        if(n&1)
            ans*=x;
        n>>=1;
        x*=x;
    }
    return ans;
}

bool isprime(ll n)
{
    if(n==2 || n==3)
        return true;
    if(n<=1 || n%2==0 || (n%6!=1 && n%6!=5))
        return false;
    for(int i=3;i*i<=n;i+=2) {
        if(n%i==0)
            return false;
    }
    return true;
}


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

int A,B,C,D;

int main()
{
    int N;
    scanf("%d",&N);
    A = N / 1000;
    B = N / 100 % 10;
    C = N / 10 % 10;
    D = N % 10;

    for(int i = 0; i < (1 << 3); i++)
    {
        int sum = A;
        if(i & (1 << 2))sum += B;
        else sum -= B;
        if(i & (1 << 1))sum += C;
        else sum -= C;
        if(i & 1)sum += D;
        else sum -= D;
        if(sum == 7)
        {
            printf("%d",A);
            if(i & (1 << 2))printf("+");
            else printf("-");
            printf("%d",B);
            if(i & (1 << 1))printf("+");
            else printf("-");
            printf("%d",C);
            if(i & 1)printf("+");
            else printf("-");
            printf("%d",D);
            printf("=7\n");
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
a,b = map(int,input().split())

x1 = -(-a //0.08)
x2 = -(-b //0.1)
counter = int(max(x1,x2))
for i in range(1,counter+1):
  y1 = int(i * 0.08)
  y2 = int(i * 0.1)
  if y1 == a and y2 == b:
    print(i)
    exit()
print("-1")

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
from collections import defaultdict
from functools import lru_cache
from collections import deque
MOD = 1000000007  # type: int


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, src, dest, w=1):
        self.E[src].append((dest, w))
        self.E[dest].append((src, w))


@lru_cache(maxsize=None)
def div(a, b):
    return (a * pow(b, MOD-2, MOD)) % MOD


class Combination(object):

    def __init__(self, N, mod=MOD):
        fac, finv, inv = [0]*(N+1), [0]*(N+1), [0]*(N+1)
        fac[:2] = 1, 1
        finv[:2] = 1, 1
        inv[1] = 1
        for i in range(2, N+1):
            fac[i] = fac[i-1]*i % mod
            inv[i] = -inv[mod % i]*(mod//i) % mod
            finv[i] = finv[i-1]*inv[i] % mod
        self.N = N
        self.MOD = mod
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def __call__(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        b = (self.finv[k]*self.finv[n-k] % self.MOD)
        return (self.fac[n] * b) % self.MOD


def solve(N: int, a: "List[int]", b: "List[int]"):
    # グラフの構築
    g = Graph(N)
    for aa, bb in zip(a, b):
        g.add_edge(aa-1, bb-1)

    # 組み合わせの初期化
    cmb = Combination(N)

    # BFSの入り順を構成する
    curr = -1
    downward = [0]
    parent = [-1]*N
    while len(downward) < N:
        curr += 1
        v = downward[curr]
        for u, _ in g.E[v]:
            if u == parent[v]:
                continue
            parent[u] = v
            downward.append(u)
    # print(downward)

    # 節点vを根とした部分木の塗り方dp[v]
    dp = [1]*N
    # 節点vを根とした部分木のサイズsize[v]+1
    size = [0]*N

    # 葉から根へ向かう探索
    for v in reversed(downward):
        for u, _ in g.E[v]:
            if u == parent[v]:
                continue
            size[v] += size[u]+1
            dp[v] *= cmb(size[v], size[u]+1)
            dp[v] %= MOD
            dp[v] *= dp[u]
            dp[v] %= MOD

    # 全方位木DP
    # 根から葉へ向かう探索
    for v in downward:
        for u, _ in g.E[v]:
            if u == parent[v]:
                continue
            d = div(dp[v], cmb(N-1, size[u]+1))
            d = div(d, dp[u])
            dp[u] *= cmb(N-1, size[u])
            dp[u] %= MOD
            dp[u] *= d
            dp[u] %= MOD

    for v in dp:
        print(v)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)


if __name__ == '__main__':
    main()


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    int ac, wa, tle, re;
    ac = 0;
    wa = 0;
    tle = 0;
    re = 0;

    string s;
    for(int in=0;in<n;in++) {
        cin >> s;
        if(s=="AC") ac++;
        if(s=="WA") wa++;
        if(s=="TLE") tle++;
        if(s=="RE") re++;
    }

    cout << "AC" << " " << "x" << " " << ac << endl;
    cout << "WA" << " " << "x" << " " << wa << endl;
    cout << "TLE" << " " << "x" << " " << tle << endl;
    cout << "RE" << " " << "x" << " " << re << endl;
    return 0;
}


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

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    string s;
    cin >> s;
    if(c > d) {
        swap(a, b);
        swap(c, d);
    }
    while(a < c || b < d) {
        if(b < d) {
            if(s[b + 1] == '.' && b + 1 != a) {
                b++;
                continue;
            }
            if(s[b + 2] == '.' && b + 2 != a) {
                b += 2;
                continue;
            }
        }
        if(a < c) {
            if(s[a + 1] == '.' && a + 1 != b) {
                a++;
                continue;
            }
            if(s[a + 2] == '.' && a + 2 != b) {
                a += 2;
                continue;
            }
        }
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ii pair <int, int>
#define x first
#define y second
#define db(x) cerr << #x << " = " << x << endl;
#define _ << ", " << 

using namespace std;

inline void read(int &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void read(long long &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void writeln(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar('\n');}
inline void write(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar(' ');}

const int N = 2e5 + 7;

string s;
int n, g;
char t[N];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> s;
	n = s.size();
	s = ' ' + s;
	for (int i = n; i >= 1; i--){
		if (s[i] == 'C' && s[i - 1] == 'B'){
			t[++g] = 'X';
			i--;
		}
		else 
			if (s[i] == 'A')
				t[++g] = 'A';
			else 
				t[++g] = s[i];
	}
	reverse(t + 1, t + g + 1);

	int cnt = 0;
	long long res = 0;

	for (int i = 1; i <= g; i++){
		if (t[i] == 'X'){
			res += cnt;
		}
		else if (t[i] == 'A')
			cnt++;
		else 
			cnt = 0;
	}

	cout << res;
}

Measured memory_bytes: 788
n = int(input())
s10 = []
snot10 = []
for i in range(n):
    num = int(input())
    if num % 10 == 0:
        s10.append(num)
    else:
        snot10.append(num)
snot10 = sorted(snot10)

if len(snot10) == 0:
    print(0)
    exit()
if not (sum(snot10) + sum(s10)) % 10 == 0:
    print(sum(snot10) + sum(s10))
else:
    print(sum(snot10) + sum(s10) - snot10[0])

Measured memory_bytes: 3188
h, w = [int(i) for i in input().split()]
ch, cw = [int(i) for i in input().split()]
ch -= 1
cw -= 1
dh, dw = [int(i) for i in input().split()]
dh -= 1
dw -= 1

loc = []
move = []
checked = []
magicchecked = []
for i in range(h):
    line = input()
    loc.append([j for j in line])
    move.append([-1 for j in line])
    checked.append([0 for j in line])
    magicchecked.append([0 for j in line])

move[ch][cw] = 0
cur = 0
walk = [(ch, cw)]
walkhistory = []
magic = []
while len(walk) > 0:
    node = walk.pop()
    walkhistory.append(node)
    checked[node[0]][node[1]] = 1
    if node[0] - 1 >= 0 and loc[node[0] - 1][node[1]] != "#" and checked[node[0] - 1][node[1]] == 0:
        walk.append((node[0] - 1, node[1]))
    if node[1] - 1 >= 0 and loc[node[0]][node[1] - 1] != "#" and checked[node[0]][node[1] - 1] == 0:
        walk.append((node[0], node[1] - 1))
    if node[0] + 1 < h and loc[node[0] + 1][node[1]] != "#" and checked[node[0] + 1][node[1]] == 0:
        walk.append((node[0] + 1, node[1]))
    if node[1] + 1 < w and loc[node[0]][node[1] + 1] != "#" and checked[node[0]][node[1] + 1] == 0:
        walk.append((node[0], node[1] + 1))
    move[node[0]][node[1]] = cur
    i = node[0]
    j = node[1]

for node in walkhistory:
    i = node[0]
    j = node[1]
    for k in range(-2, 3):
        for l in range(-2, 3):
            if i + k >= 0 and i + k < h and j + l >= 0 and j + l < w \
            and loc[i + k][j + l] == "." and checked[i + k][j + l] == 0 and magicchecked[i + k][j + l] == 0:
                magicchecked[i + k][j + l] = 1
                magic.append((i + k, j + l))

cur += 1

while magic:
    walk = magic[:]
    magic = []
    walkhistory = []

    while len(walk) > 0:
        node = walk.pop()
        walkhistory.append(node)
        checked[node[0]][node[1]] = 1
        if node[0] - 1 >= 0 and loc[node[0] - 1][node[1]] != "#" and checked[node[0] - 1][node[1]] == 0:
            walk.append((node[0] - 1, node[1]))
        if node[1] - 1 >= 0 and loc[node[0]][node[1] - 1] != "#" and checked[node[0]][node[1] - 1] == 0:
            walk.append((node[0], node[1] - 1))
        if node[0] + 1 < h and loc[node[0] + 1][node[1]] != "#" and checked[node[0] + 1][node[1]] == 0:
            walk.append((node[0] + 1, node[1]))
        if node[1] + 1 < w and loc[node[0]][node[1] + 1] != "#" and checked[node[0]][node[1] + 1] == 0:
            walk.append((node[0], node[1] + 1))
        move[node[0]][node[1]] = cur
        i = node[0]
        j = node[1]

    for node in walkhistory:
        i = node[0]
        j = node[1]
        for k in range(-2, 3):
            for l in range(-2, 3):
                if i + k >= 0 and i + k < h and j + l >= 0 and j + l < w \
                and loc[i + k][j + l] == "." and checked[i + k][j + l] == 0 and magicchecked[i + k][j + l] == 0:
                    magicchecked[i + k][j + l] = 1
                    magic.append((i + k, j + l))


    cur += 1

print(move[dh][dw])

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, tmp;
    cin >> n;

    vector<int> b(n), ans;
    vector<bool> x(n, true);

    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    for (int i = 0; i < n; i++) {
        int now = 0, idx = -1;

        for (int j = 0; j < n; j++) {
            if (x[j]) now++;
            if (b[j] == now) idx = j;
            //cout << b[j] << " " << now << endl;
        }
        //cout << "----------" << endl;
        //cout << i << " " << now << " " << idx << endl;
        if (idx == -1) {
            cout << -1 << endl;
            return 0;
        }
        //cout << idx+1 << endl;
        ans.push_back(b[idx]);
        x[idx] = false;
    }
    
    for (int i = ans.size()-1; i >= 0; i--) cout << ans[i] << endl;
    return 0;
}



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

int main() {
  long long k;cin>>k;
  vector<long long> an(50,49+(k/50));
  k %= 50;
  rep(i,k) an[i] += (51-k);
  rep(i,50-k) an[i+k] -= k;
  cout << 50 << endl;
  cout << an[0];
  rep(i,49) cout << " " << an[i+1];
}


Measured memory_bytes: 256
while (n = gets.split.map(&:to_i)) != [0, 0]
  h, w = n

  h.times do |j|
    w.times do |i|
      if j.odd?
        printf(".") if i.even?
        printf("#") if i.odd?
      else
        printf("#") if i.even?
        printf(".") if i.odd?
      end
    end
    puts
  end
  puts
end

Measured memory_bytes: 6112
#include <iostream>
#include <vector>

using std::cin;

int main()
{

    int n;
    while (cin >> n) {
        if (n == 0) {
            break;
        }

        std::vector<int> line(n);
        for (auto i = 0; i < n; i++) {
            int in;
            cin >> in;
            line.at(i) = in;
        }

        int max = -100000;
        for (auto i = 0; i < n; i++) {
            int sum_ij;
            int max_i;
            max_i = sum_ij = line.at(i);
            for (auto j = i + 1; j < n; j++) {
                sum_ij += line.at(j);
                if (sum_ij > max_i) {
                    max_i = sum_ij;
                }
            }
            if (max_i > max) {
                max = max_i;
            }
        }

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

    return 0;
}

Measured memory_bytes: 1204
type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI32()]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI64()]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF32()]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF64()]

    member public __.Tuple2List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]]
    
    member public __.Tuple3List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]]

end

[<EntryPoint>]
let main _ =
    let scanner = Scanner()
    let alls = [for i in scanner.Next() -> (int i) - 48]

    let rec g liI liS i s =
        function
        | [] -> i::liI, s::liS
        | x::xs ->
            let h = string x
            let c, d = g liI liS (i + x) (s + "+" + h) xs
            let e, f = g liI liS (i - x) (s + "-" + h) xs
            c @ e, d @ f
    
    let p, q = g [] [] alls.[0] (string alls.[0]) alls.[1..3]
    List.tryFindIndex ((=) 7) p
    |> function
        | Some(x) -> q.[x]
        | None -> ""
    |> printfn "%s=7"

    0


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

#define int long long

int N;

signed main(void) {
  int t, a;
  cin.tie(0);
  ios::sync_with_stdio(false);

  int r, l;
  l = r = 1;

  cin >> N;
  // l r =>t a
  for (int i = 0 ; i < N; i++) {
    cin >> t >> a;
    int k = max((l%t==0) ? l/t : l/t+1, (r%a==0) ? r/a : r/a+1);
    l=t*k; r=a*k;
  }
  cout << r + l << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if(a>b)
	{
		printf("a > b\n");
	}
	
	else if(a<b)
	{
		printf("a < b\n");
	}
	
	else
	{
		printf("a == b\n");
	}
	

	return 0;
} 


Measured memory_bytes: 2056
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
using namespace std;
#define pii pair<int, int>
const int N = 1e6 + 50;
int head[N], nxt[N], ver[N], tot, in[N], ans[N], n;
void add(int x, int y)
{
    ver[++tot] = y, nxt[tot] = head[x], head[x] = tot, in[y]++;
}
int index(int x, int y)
{
    if (x > y)
        swap(x, y);
    return (x - 1) * (2 * n - x) / 2 + y - x;
}
int main()
{
    scanf("%d", &n);
    for (int u = 1; u <= n; u++)
    {
        for (int j = 0, v, pre; j < n - 1; j++)
        {
            scanf("%d", &v);
            if (j)
                add(index(u, pre), index(u, v));
            pre = v;
        }
    }
    queue<int> q;
    for (int i = 1; i <= n * (n - 1) / 2; i++)
        if (!in[i])
            q.push(i), ans[i] = 1;
    int pcnt = 0;
    int ret = 0;
    while (!q.empty())
    {
        int x = q.front();
        q.pop();
        ret = max(ret, ans[x]);
        pcnt++;
        for (int i = head[x]; i; i = nxt[i])
        {
            int y = ver[i];
            ans[y] = ans[x] + 1;
            if (--in[y] == 0)
            {
                q.push(y);
            }
        }
    }
    if (pcnt < n * (n - 1) / 2)
        printf("-1\n");
    else
        printf("%d\n", ret);
    //system("pause");
    return 0;
}

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

#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  // so basically we are looking for j - i = A[i] + A[j]
  // and equating we get
  // j - A[j] = A[i] + i
  long long res = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    if (mp.count(i - a[i])) 
      res += mp[i - a[i]];
    ++mp[a[i] + i];
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 13284
i = int(input())
p = list(map(int, input().split()))

ct = 0
for j in range(len(p)-2):
  if (p[j]<p[j+1] and p[j+1]<p[j+2])or(p[j]>p[j+1] and p[j+1]>p[j+2]):
    ct += 1
    
print(ct)

Measured memory_bytes: 3060
a,b,c,d,e =map(int ,input().split())
g=0
h=0
if d-b<0:
  g=60+d-b
  c-=1
else:
  g=d-b
f=c-a
g+=f*60
if g<e :
  h=0
else:
  h=g-e
print(h)

Measured memory_bytes: 9184
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
  auto s = readln.split.map!(to!int);
  auto N = s[0];
  auto W = s[1];
  auto K = N.iota.map!(_ => readln.split.map!(to!int).array).array;
  K.sort!"a[1] < b[1]"();
  auto dp = new int[][](N, W+1);
  foreach (i; 0..W+1) dp[0][i] = i / K[0][1] * K[0][0];

  foreach (i; 1..N)
    foreach (w; 0..W+1) {
      if (w - K[i][1] >= 0)
        dp[i][w] = max(dp[i-1][w-K[i][1]], dp[i][w-K[i][1]]) + K[i][0];
      dp[i][w] = max(dp[i-1][w], dp[i][w]);
    }

  dp[N-1][W].writeln;
}

Measured memory_bytes: 6348
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
      
    divisors.sort()
    return divisors

import fractions
a,b=map(int,input().split())
gcd = fractions.gcd(a,b)

#print(gcd)
pnum = set()

if gcd == 1:
    print(1)
elif gcd == 2:
    print(2)
else:
    devlist = make_divisors(gcd)
    #print(devlist)
    #pnum.add(2)
    
    for num in devlist:
        if (num!=1):
            #print("gg",num)
            ptf = True
            for p in pnum:
                if num%p==0:
                    ptf = False
                    break
            if ptf ==True:
                pnum.add(num)
            
    print(len(pnum)+1)#1の分を足す

Measured memory_bytes: 64876
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] a = new int[N];

		for(int i = 0;i < N;i++){
			a[i] = sc.nextInt();
		}

		long before = a[0];
		long after = 0;
		for(int i = 1;i < N;i++){
			after += a[i];
		}
		long minAbs = Math.abs(before - after);
		for(int i = 1;i < N - 1;i++){
			before += a[i];
			after -= a[i];
			long abs = Math.abs(before - after);
			if(abs < minAbs){
				minAbs = abs;
			}
		}
		System.out.println(minAbs);
	}
}


Measured memory_bytes: 66832
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdlib>
using namespace std;

int main()
{
	int N, ANS = 0;
	cin >> N;
	int hoge = N / 100;
	if (N - hoge * 111 <= 0)ANS = hoge * 111;
	else ANS = (hoge + 1) * 111;
	cout << ANS;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define INF 2147483647
pair<int,int> data[4000001];
int n,_n;
void init(int n){
  _n=1;
  while(_n<2000000)_n*=2;
}
void update(int i,int x){
  int p=i;
  i+=_n-1;
  data[i].f+=x;
  data[i].s=p+1;
  while(i>0){
    i=(i-1)/2;
    if(data[2*i+1].f==data[2*i+2].f){
      if(data[2*i+1].s<data[2*i+2].s)
        data[i]=data[2*i+1];
      else data[i]=data[2*i+2];
    }
    else if(data[2*i+1].f>data[2*i+2].f)
      data[i]=data[2*i+1];
    else data[i]=data[2*i+2];
  }
}
int main(){
  int q;
  cin>>n>>q;
  init(n);
  while(q--){
    int a,b;
    cin>>a>>b;
    update(a-1,b);
    cout<<data[1].second<<' '<<data[1].first<<endl;
  }
}

Measured memory_bytes: 34344
# 入力値の取得
n = gets.chomp.to_i
points = n.times.map { |i|
  point_array = gets.chomp.split(" ").map(&:to_i)
  { t: point_array[0], x: point_array[1], y: point_array[2] }
}

# 計算
current = { t: 0, x: 0, y: 0 }
goal = true

points.each do |point|
  dt = point[:t] - current[:t]
  dx = (point[:x] - current[:x]).abs
  dy = (point[:y] - current[:y]).abs
  dxy = dx + dy

  if dxy <= dt && dt % 2 == dxy % 2
    current = point
  else
    goal = false
    break
  end
end

puts goal ? "Yes" : "No"


Measured memory_bytes: 31356
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
int r,c,n;
inline bool compare(pair<pii,int> uu,pair<pii,int> vv)
{
	if(uu.first.second==0)
	{
		if(vv.first.second==0)
		{
			return uu.first.first<vv.first.first;
		}
		return true;
	}
	else
	{
		if(vv.first.second==0)
		{
			return false;
		}
		if(uu.first.first==r)
		{
			if(vv.first.first==r)
			{
				return uu.first.second<vv.first.second;
			}
			return true;
		}
		else
		{
			if(vv.first.first==r)
			{
				return false;
			}
			if(uu.first.second==c)
			{
				if(vv.first.second==c)
				{
					return uu.first.first>vv.first.first;
				}
			}
			else
			{
				if(vv.first.second==c)
				{
					return false;
				}
				if(uu.first.first==0)
				{
					if(vv.first.first==0)
					{
						return uu.first.second>vv.first.second;
					}
					return true;
				}
				else
				{
					if(vv.first.first==0)
					{
						return false;
					}
				}
			}
		}
	}
}
vector<pair<pii,int> > v;
inline bool bound(int x,int y)
{
	if(x==0||x==r||y==0||y==c)
	{
		return true;
	}
	return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>r>>c>>n;
	int x1,y1,x2,y2;
	for(int i=0;i<n;i++)
	{
		cin>>x1>>y1;
		cin>>x2>>y2;
		if(bound(x1,y1)&&bound(x2,y2))
		{
			v.pb(mk(mk(x1,y1),i));
			v.pb(mk(mk(x2,y2),i));
		}
	}
	sort(v.begin(),v.end(),compare);
	bool reached[n+1];
	stack<int> s;
	memset(reached,false,sizeof(reached));
	for(int i=0;i<v.size();i++)
	{
		//cout<<v[i].second<<"\n";
		//cout<<v[i].first.first<<" "<<v[i].first.second<<"\n";
		if(reached[v[i].second])
		{
			if(s.top()==v[i].second)
			{
				s.pop();
			}
			else
			{
				cout<<"NO\n";
				return 0;
			}
		}
		else
		{
			s.push(v[i].second);
			reached[v[i].second]=true;
		}
	}
	cout<<"YES\n";
}

Measured memory_bytes: 4980
import sys
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

K = I()
d = deque([i for i in range(1,10)])

cnt = 0
while True:
  num = d.popleft()
  cnt += 1
  if cnt == K:
    print(num)
    break
  tmp = int(str(num)[-1])
  for i in range(tmp-1,tmp+2):
    if i == -1 or i == 10:
      continue
    else:
      d.append(str(num) + str(i))

Measured memory_bytes: 69340
#include <bits/stdc++.h>
    #define pb push_back
    #define mp make_pair
    #define fst first
    #define snd second
    #define all(cont) cont.begin(), cont.end()
    #define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
    #define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
    #define SZ(x) ((int)x.size())
    #define EPS 1e-9
    #define PI 3.1415926535897932384626433832795
    #define MOD 1000000007
    #define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

    const int N = 0;

    typedef long long int ll;

    using namespace std;

    int main(){
        ll H,W;cin>>H>>W;
        if(H%3 == 0 || W%3 == 0){
            cout<<"0";
        }else{
            ll minA = H*W; 
            fore(oh,1,H){
                ll aB = oh*W;
                ll a1 = (H-oh)*(floor((double)W/2));
                ll a2 = (H-oh)*(ceil((double)W/2));
                ll a3 = W*(floor((double)(H-oh)/2));
                ll a4 = W*(ceil((double)(H-oh)/2));

                minA = min(minA,abs(max(max(aB,a2),a1) - min(min(aB,a2),a1)));
                minA = min(minA,abs(max(max(aB,a3),a4) - min(min(aB,a3),a4)));
            }

            fore(ow,1,W){
                ll aB = ow*H;
                ll a1 = (W-ow)*(floor((double)H/2));
                ll a2 = (W-ow)*(ceil((double)H/2));
                ll a3 = H*(floor((double)(W-ow)/2));
                ll a4 = H*(ceil((double)(W-ow)/2));
                minA = min(minA,abs(max(max(aB,a2),a1) - min(min(aB,a2),a1)));
                minA = min(minA,abs(max(max(aB,a3),a4) - min(min(aB,a3),a4)));
            }
            cout<<minA;
        }
        
        return 0;
    }

Measured memory_bytes: 256
from collections import deque
k=int(input())
qu=deque([1,2,3,4,5,6,7,8,9])
for i in range(k):
  x=qu.popleft()
  if x%10!=0:
    qu.append(10*x+(x%10)-1)
  qu.append(10*x+(x%10))
  if x%10 != 9:
    qu.append(10*x+(x%10)+1)

print(x)

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

int main() {
	string s,t;
	cin>>s>>t;
	int a[26],b[26];
	for(int i=0;i<26;i++){
		a[i]=b[i]=-1;
	}
	for(int i=0;i<s.size();i++){
		if(a[t[i]-'a']==-1){
			a[t[i]-'a']=s[i]-'a';
		}
		else{
			if(a[t[i]-'a']!=s[i]-'a'){
				cout <<"No";
				return 0;
			}
		}
		if(b[s[i]-'a']==-1){
			b[s[i]-'a']=t[i]-'a';
		}
		else{
			if(b[s[i]-'a']!=t[i]-'a'){
				cout <<"No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 776
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

LL add(LL a, LL b) { return a + b; }

int main() {
  int N; cin >> N;
  vector<LL> a(N); cin >> a;

  LL sum = 0;
  for (LL v : a) {
    sum = add(sum, v - 1);
  }

  cout << sum << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <iomanip>
#include <map>
#include <sstream>
#define ll long long
using namespace std;
// ver..(1.1)
string ent="\n";
string space=" ";
int main(){
   	ios_base::sync_with_stdio(false);
      ll a,b,k;
      cin >> a >> b >> k;

      ll rand=min(a,k);
      a-=rand;    k-=rand;

      rand=min(b,k);
      b-=rand;

      cout << a << space << b << ent;
}
/*


*/

Measured memory_bytes: 256
//Exchange Arguments
//1.Boxes
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

bool comp(pair<int, int> a, pair<int, int> b) {
    return a.first + a.second < b.first + b.second;
}

int dp[5010][5010];

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

    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;

        v.push_back({a, b});
    }
    sort(v.begin(), v.end(), comp);
    memset(dp, 63, sizeof dp);
    int inf = dp[0][0];
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j > 0 and dp[i - 1][j - 1] != inf and dp[i - 1][j - 1] <= v[i - 1].first)
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + v[i - 1].second);
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (dp[i][j] == inf)continue;
            ans = max(ans, j);
        }
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 196736
#include<stdio.h>

int main(){
    char b;
    scanf("%c",&b);
    if(b=='A'){
        printf("%c",'T');
    }
    if(b=='T'){
        printf("%c",'A');
    }

    if(b=='G'){
        printf("%c",'C');
    }

    if(b=='C'){
        printf("%c",'G');
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    int n;
    cin >> n;
    int w[n];
    REP(i,n) cin >> w[i];
    
    int left[n+1], right[n+1];
    
    left[0] = 0;
    right[0] = 0;
    
    for(int i=1; i<n+1; i++){
        left[i] = left[i-1] + w[i-1];
        right[i] = right[i-1] + w[n-i];
    }
    
    int small = INF;
    
    REP(i,n+1){
        int diff = abs(left[i] - right[n-i]);
        small = min(small, diff);
    }
    
    cout << small << endl;

    return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s;
    cin >> s;

    bool flag = true;
    vector <char> str[2];

    int q;
    cin >> q;

    while (q--) {
        int t;
        cin >> t;

        if (t == 1) {
            flag ^= 1;
        } else {
            int f;
            char c;
            cin >> f >> c;
            str[flag ^ (f % 2)].push_back(c);
        }
    }

    if (flag) {
        for (int i = str[0].size() - 1; i >= 0; i--) cout << str[0][i];
        cout << s;
        for (char c : str[1]) cout << c;
    } else {
        for (int i = str[1].size() - 1; i >= 0; i--) cout << str[1][i];
        reverse(s.begin(), s.end());
        cout << s;
        for (char c : str[0]) cout << c;
    }

    cout << '\n';
    return 0;
}

Measured memory_bytes: 960
from collections import defaultdict


n = int(input())
A = map(int, input().split())

L = defaultdict(int)
R = defaultdict(int)
for i, v in enumerate(A):
    L[i + v] += 1
    R[i - v] += 1
print(sum(L.get(i, 0) * R.get(i, 0) for i in range(n)))


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

int main(){
  	int H,W;
  	cin>>H>>W;
	vector<string>s(H);
  	for(int i=0;i<H;++i)cin>>s[i];
  	vector<bool>x(H,false);
  	vector<bool>y(W,false);
  	for(int i=0;i<H;++i){
    	for(int j=0;j<W;++j)if(s[i][j]=='#'){x[i]=true;y[j]=true;}
    }for(int i=0;i<H;++i){
    	for(int j=0;j<W;++j)if(x[i]&&y[j])cout<<s[i][j];
      	cout<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;


void solve_old(long long A, long long B){
    ll val=A-B*2;
    if(val<0){val=0;}
    cout << val << "\n";
}

void solve(long long A, long long B){
    cout << max((ll)0, A-2*B) << "\n";
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	ll N, D, A;
	cin >> N >> D >> A;
	ll X[200000];
	ll H[200000];
	for(int i = 0; i < N; i++){
		cin >> X[i] >> H[i];
	}
	
	map<ll, ll> monsters;
	map<ll, ll> bomb;
	for(int i = 0; i < N; i++){
		monsters[X[i]] = H[i];
		bomb[X[i]] = 0;
	}
	
	ll ans = 0;
	auto itr = monsters.begin();
	for(int i = 0; i < N; i++){
		auto lower = bomb.lower_bound(itr->first - 2 * D);
		ll remainHP = itr->second;
		if(itr != monsters.begin()){
			remainHP -=bomb[prev(itr)->first] * A;
		}
		if(lower != bomb.begin()){
			remainHP += bomb[prev(lower)->first] * A;
		}
		if(remainHP > 0){
			ans += remainHP / A + (remainHP % A == 0 ? 0 : 1);
			bomb[itr->first] = remainHP / A + (remainHP % A == 0 ? 0 : 1);
		}
		if(itr!=monsters.begin()){
			// ボムを投げた回数の総和を記録しておく.
			bomb[itr->first] += bomb[prev(itr)->first];
		}
		itr++;
	}
	cout << ans << endl;
	
	return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    if (y % 2) {
        cout << "No";
    }
    else if (2 *x <= y && y <= 4*x) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}




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

int main(){
    int R,G,B,N;
    int sr,sg,sb,c;
    cin >> R;
    cin >> G;
    cin >> B;
    cin >> N;
    for (int i=0;i<int(N/R+1);i++){
        int sr = i*R;
        for (int j=0;j<int((N-i*R)/G)+1;j++){
            sg = j * G;
            if (sr + sg <= N) {
                sb = N - sr - sg;
                if (sb % B == 0) {c++;}
            }
        }
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;
int main()
{
	string S;
	cin >> S;

	if((S[0] == S[1] && S[2] == S[3] && S[0] != S[2])||
		(S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) ||
		(S[0] == S[3] && S[1] == S[2] && S[0] != S[1])){
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


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

using namespace std;

int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a>b)
        a=b;
    if(c>d)
        c=d;
    printf("%d\n",a+c);
    return 0;
}


Measured memory_bytes: 256
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(list[K-1])

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  REP(i, 3) {
    string s; cin >> s;
    cout << s[i];
  }
  cout << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;
typedef long long int ll;

ll n,a[100010],b[100010],r=0,cut=0;

ll sqt(ll an,ll bn){
    return (an/bn+1)*bn-an;
}

int main(){
    scanf("%lld",&n);
    
    for(int i=0;i<n;i++){
        scanf("%lld %lld",&a[i],&b[i]);
    }
    
    for(int i=n-1;i>=0;i--){
        if((a[i]+cut)%b[i]!=0)cut+=sqt(a[i]+cut,b[i]);
        //printf("%lld\n",cut);
    }
    printf("%lld\n",cut);
    
}

Measured memory_bytes: 1792