akhauriyash/Code-Regression huggingface dataset:
'use strict'

const main = (input) => {
    input = input.split('\n')
    const H = parseInt(input[0].split(' ')[0])
    const W = parseInt(input[0].split(' ')[1])
    let S = input.slice(1, H + 1).map(v => v.split('').map(i => {
        if(i === '.'){
            return 0
        }else{
            return '#'
        }
    }))

    for(let i = 0; i < H; i++){
        for(let j = 0; j < W; j++){
            if(S[i][j] === '#'){
                if(typeof S[i - 1] !== 'undefined' && typeof S[i - 1][j - 1] !== 'undefined' && S[i - 1][j - 1] !== '#') S[i - 1][j - 1]++
                if(typeof S[i - 1] !== 'undefined' && typeof S[i - 1][j] !== 'undefined'  && S[i - 1][j] !== '#') S[i - 1][j]++
                if(typeof S[i - 1] !== 'undefined' && typeof S[i - 1][j + 1] !== 'undefined'  && S[i - 1][j + 1] !== '#') S[i - 1][j + 1]++
                if(typeof S[i] !== 'undefined' && typeof S[i][j - 1] !== 'undefined'  && S[i][j - 1] !== '#') S[i][j - 1]++
                if(typeof S[i] !== 'undefined' && typeof S[i][j + 1] !== 'undefined'  && S[i][j + 1] !== '#') S[i][j + 1]++
                if(typeof S[i + 1] !== 'undefined' && typeof S[i + 1][j - 1] !== 'undefined'  && S[i + 1][j - 1] !== '#') S[i + 1][j - 1]++
                if(typeof S[i + 1] !== 'undefined' && typeof S[i + 1][j] !== 'undefined'  && S[i + 1][j] !== '#') S[i + 1][j]++
                if(typeof S[i + 1] !== 'undefined' && typeof S[i + 1][j + 1] !== 'undefined'  && S[i + 1][j + 1] !== '#') S[i + 1][j + 1]++
            }
        }
    }
    S.forEach((v, i) => {
        console.log(v.map(v => v.toString()).join(''))
    })
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 8072
import math
from functools import reduce 
import itertools
k = int(input())
l = [i for i in range(1,k+1)]
ans = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for x in itertools.product(l,repeat=3):
    ans += gcd(x[0],x[1],x[2])
print(ans)

Measured memory_bytes: 69044
import java.util.*;
import java.io.*;
import java.lang.*;

class Main{

    public static void main(String args[])throws IOException{
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	String A,B;
	while((A = in.readLine()) != null){
	    B = in.readLine();
	    String MA,MI;
	    if(A.length() >= B.length()){
		MA = A;
		MI = B;
	    }
	    else{
		MA = B;
		MI = A;
	    }	  
	    int mex = 0;
	    int[][] dp = new int[MI.length()][2];
	    for(int i=0;i<MI.length();i++){
		if(MI.charAt(i) == MA.charAt(0)){
		    dp[i][0] = 1;
		    mex = Math.max(1,mex);
		}
		else{
		    dp[i][0] = 0;
		}
	    }	 

	    for(int i=1;i<MA.length();i++){
		for(int j=0;j<MI.length();j++){
		    if(j == 0){
			if(MA.charAt(i) == MI.charAt(j)){
			    dp[j][1] = 1;
			    mex = Math.max(1,mex);
			}
			else {		      
			    dp[j][1] = 0;
			}
		    }
		    else {
			if(MA.charAt(i) == MI.charAt(j)){
			    dp[j][1] = dp[j-1][0]+1;
			    mex = Math.max(mex,dp[j][1]);
			}
			else {
			    dp[j][1] = 0;
			}
		    }
		}
		for(int j=0;j<MI.length();j++)dp[j][0] = dp[j][1];
	    }



	    System.out.println(mex);


	}

    }

}

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

int main(){
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++){
    if((int)(i * 1.08) == n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
int main(){
    unsigned long ulW_D_inact[100][100];    /* 行列Ａの格納用変数 */
    unsigned long ulW_D_act[100];           /* 行列Ｂの格納用変数 */
    unsigned long ulW_D_ans[100];           /* 積の格納用変数 */
    unsigned short usW_D_row, col;          /* 行列の要素数の格納用変数 */
    unsigned short i, j;              /* ループ変数 */

    /* 配列の初期化 */
    for(i = 0;i < 100;i++){
        for(j = 0;j < 100;j++){
            ulW_D_inact[i][j] = 0;
        }
        ulW_D_act[i] = 0;
        ulW_D_ans[i] = 0;
    }

    /* 行列の要素数の入力 */
    scanf("%d %d", &usW_D_row, &col);

    /* 行列Ａの入力 */
    for(i = 0;i < usW_D_row;i++){
        for(j = 0;j < col;j++){
            scanf("%d", &ulW_D_inact[i][j]);
        }
    }

    /* 行列Ｂの入力 */
    for(i = 0;i < col;i++){
        scanf("%d", &ulW_D_act[i]);
    }

    /* ＡとＢの積の計算 */
    for(i = 0;i < usW_D_row;i++){
        for(j = 0;j < col;j++){
            /* i番目の積の計算 */
            ulW_D_ans[i] += ulW_D_inact[i][j] * ulW_D_act[j];
        }
    }
    /* 積の出力 */
    for(i = 0;i < usW_D_row;i++){
        /* i番目の積の出力 */
        printf("%d\n", ulW_D_ans[i]);
    }
    return 0;
}


Measured memory_bytes: 2100
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int x1 = sc.nextInt();
    int y1 = sc.nextInt();
    int x2 = sc.nextInt();
    int y2 = sc.nextInt();

    sc.close();

    int dx = 0;
    int dy = 0;

    if (x2 == x1){
      dx = y2 - y1;
      dy = y2 - y1;
      System.out.println((x2 - dx) + " " + y2 + " " + (x1 - dx) + " " + y1);
    } else if (y2 == y1){
      dx = x2 - x1;
      dy = x2 - x1;
      System.out.println(x2 + " " + (y2 + dy) + " " + x1 + " " + (y1 + dy));
    } else {
      dx = y2 - y1;
      dy = x2 - x1;
      System.out.println((x2 - dx) + " " + (y2 + dy) + " " + (x1 - dx) + " " + (y1 + dy));
    }

  }

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//素因数分解
vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    string S,T; cin >> S >> T;

    int cnt=0;

    REP(i,S.size()){
        if(S[i]!=T[i]) cnt++;
    }
    

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3920
#include <stdio.h>

int main()
{   int h,w;
    scanf("%d%d",&h,&w);
    char s[h][w+1];
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    int grid[52][52]={0};
    for(int i=0;i<=h;i++){
        for(int j=0;j<=w;j++){
            int cnt=0;
            if(s[i-1][j-1]=='#'){
                cnt++;
            }
            if(s[i][j-1]=='#'){
                cnt++;
            }
            if(s[i+1][j-1]=='#'){
                cnt++;
            }
            if(s[i-1][j]=='#'){
                cnt++;
            }
            if(s[i][j]=='#'){
                grid[i][j]=-1;
                continue;
            }
            if(s[i+1][j]=='#'){
                cnt++;
            }
            if(s[i-1][j+1]=='#'){
                cnt++;
            }
            if(s[i][j+1]=='#'){
                cnt++;
            }if(s[i+1][j+1]=='#'){
                cnt++;
            }
            grid[i][j]=cnt;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]==-1){
                printf("#");
            }else{
                printf("%d",grid[i][j]);
            }
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	s := []int{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 := readi()
	fmt.Println(s[k-1])
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func readSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func readFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func ave(a []int) (ave int) {
	for i := 0; i < len(a); i++ {
		ave += a[i]
	}
	ave /= len(a)
	return
}

func eq(a []string, b []string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

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

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func mid(a []int) int {
	sort.Ints(a)
	return a[len(a)/2]
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

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


void solve(long long N, std::string S){
    int ans = 0;
    for(int i = 0; i < N-2; ++i){
        if(S.substr(i, 3) == "ABC") ans++;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3700
my ($n, $a, $b, $c) = split(/\s+/, <>);
my @s = ();
for (0..$n-1) {
    ($s[$_]) = split(/\s+/, <>);
}

my @hand = ();
sub loop {
    my ($depth, $a, $b, $c) = @_;
    if ($depth == $n) {
	print "Yes\n";
	print join("\n", @hand), "\n";
	exit;
    }
    if ($s[$depth] eq 'AB') {
	if ($b>0) { $hand[$depth] = 'A'; loop($depth+1, $a+1, $b-1, $c); }
	if ($a>0) { $hand[$depth] = 'B'; loop($depth+1, $a-1, $b+1, $c); }
    }
    elsif ($s[$depth] eq 'BC') {
	if ($c>0) { $hand[$depth] = 'B'; loop($depth+1, $a, $b+1, $c-1); }
	if ($b>0) { $hand[$depth] = 'C'; loop($depth+1, $a, $b-1, $c+1); }
    }
    elsif ($s[$depth] eq 'AC') {
	if ($c>0) { $hand[$depth] = 'A'; loop($depth+1, $a+1, $b, $c-1); }
	if ($a>0) { $hand[$depth] = 'C'; loop($depth+1, $a-1, $b, $c+1); }
    }
}

loop(0, $a, $b, $c);
print "No\n";


Measured memory_bytes: 226756
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*
言語：1~mと人をつなげる
*/

struct UnionFind{
	int n;
	vector<int> r,p;
	UnionFind(){}
	UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
	int find(int x){
		return (x==p[x]?x:p[x]=find(p[x]));
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y) return;
		if(r[x]<r[y]) swap(x,y);
		r[x]+=r[y];
		p[y]=x;
	}
};

int main(void){
	bool ok=true;
	ll n,m;
	cin>>n>>m;
	UnionFind f(n+m+2);
	//人と言語を繋ぐ
	reg(i,1,n){
		ll k;
		cin>>k;
		rep(j,k){
			ll a;
			cin>>a;
			f.unite(i+m,a);
		}
	}
	//１番目の参加者とコミュニケーションできるかチェック
	reg(i,2,n){
		if(!f.same(1+m,i+m))ok=false;
	}
	cout<<(ok?"YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()0
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!



void solve(){
    int n;
    cin>>n;
    vi arr(n);
    for(int i=0;i<n;i++){cin>>arr[i];}
    
    sort(all(arr));
    int idx=n/2 - 1;
    cout<<arr[idx+1]-arr[idx];
}

 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3668
N, X, Y = map(int, input().split())

distance_counter = [0 for i in range(0, N-1)]

# 各頂点同士の距離を求める
for i in range(1, N):
    for j in range(i+1, N + 1):
        if i <= X and Y <= j:
            distance = (X-i) + 1 + (j-Y)
        if i <= X and j < Y:
            distance = (X-i) + min(j-X, 1+(Y-j))
        if X < i and Y <= j:
            distance = min(Y-i, i-X+1) + (j-Y)
        if X < i and j < Y:
            distance = min(j-i, (i-X)+(Y-j)+1)

        distance_counter[distance-1] += 1

for i in range(N-1):
    print(distance_counter[i])


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1000005;
struct node
{
    int from, to, w;
} G[MAXN];
int dist[MAXN];
int head[MAXN];
bool vis[MAXN];
int cnt;
void add(int u, int v, int w)
{
    G[cnt].to=v;
    G[cnt].w=w;
    G[cnt].from=head[u];
    head[u]=cnt++;
}
void spfa(int s)
{
    memset(vis, false, sizeof(vis));
    queue<int> q;
    while(!q.empty())
        q.pop();
    vis[1]=true;
    q.push(s);
    dist[s]=0;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=false;
        for(int i=head[u]; ~i; i=G[i].from)
        {
            int v=G[i].to;
            if(dist[v]>dist[u]+G[i].w)
            {
                dist[v]=dist[u]+G[i].w;
                if(!vis[v])
                {
                    vis[v]=true;
                    q.push(v);
                }
            }
        }
    }
}
int main()
{
    int k;
    scanf("%d", &k);
    memset(head, -1, sizeof(head));
    memset(dist, 0x3f,sizeof(dist));
    cnt=0;
    for(int i=0; i<k; ++i)
    {
        add(i,(i+1)%k, 1);
        add(i, i*10%k, 0);
    }
    spfa(1);
    printf("%d\n", dist[0]+1);
    return 0;
}



Measured memory_bytes: 12672
using System;

namespace abc048A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            string A = (str[0]);
            string B = (str[1]);
            string C = (str[2]);
            Console.WriteLine(A.Substring(0, 1) + B.Substring(0, 1) + C.Substring(0, 1));
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
using namespace std;
using li = long long;
using vi = vector<li>;
using vs = vector<string>;

int main(int argc,char* argv[])
{
    int n;
    cin>>n;
    cout<<"ABC"<<n<<endl;
    
    return 0;
}

Measured memory_bytes: 256
while True:
    n,k=map(int,input().split())
    if k==0 and n==0:break
    a=[int(input()) for i in range(n)]
    s=sum(a[0:k])
    max=s
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        if s>max:max=s
    print(max)



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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999;
	
	public static void Main(string[] args)
	{
		var s = Console.ReadLine();
		var r = new List<char>();
		for(int i = 0; i < s.Length; i++)
		{
			if(r.Count > 0 && s[i] == 'B')
			{
				r.RemoveAt(r.Count - 1);
			}
			else if(s[i] != 'B')
			{
				r.Add(s[i]);
			}
		}
		Console.WriteLine(new string(r.ToArray()));
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  vi x(n);
  rep(i,n) cin >> x[i];
  vi y(m);
  rep(i,m) cin >> y[i];
  int xmax = *max_element(rng(x));
  int ymin = *min_element(rng(y));
  for (int Z = xmax+1; Z <= ymin; ++Z) {
    if (X < Z && Z <= Y) {
      puts("No War");
      return 0;
    }
  }
  puts("War");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define S second
#define F first
#define ii pair <int,int>
#define IOS std::ios_base::sync_with_stdio(false)
#define pb push_back
#define inf INT_MAX

int q = 1 ;
const int N = 1e5+10;
struct day{
    int a,b,c;
};
day a[N];

ll n , mem[N][3];

ll dp(int i , int l)
{
    if( i == n)
        return 0ll;
    ll &ret = mem[i][l];
    if( ret != -1)
        return ret;
    ll p1 = 0 , p2 = 0 , p3 = 0;
    if(l != 0)
        p1 = a[i].a + dp(i+1,0);
    if(l != 1)
        p2 = a[i].b + dp(i+1,1);
    if(l != 2)
        p3 = a[i].c + dp(i+1,2);
    return ret = max({p1,p2,p3});
}

void solve()
{
    cin>>n;
    for(int i = 0 ; i < n; i++)
        cin>>a[i].a>>a[i].b>>a[i].c;
    memset(mem,-1,sizeof mem);
    ll ans = a[0].a + dp(1,0);
    ans = max(ans,a[0].b + dp(1,1));
    ans = max(ans,a[0].c + dp(1,2));
    cout<<ans;
}


int main()
{
    IOS;
//    cin>>;
    while(q--)
    {
         solve();
    }

}


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

int main(){
  long long a, b, n;
  cin >> n >> a >> b;
  if((b-a)%2 == 0){
    cout << (b-a)/2;
  }else{
  	cout << min(a-1, n-b)+1+(b-a-1)/2;
  }
  return 0;
}

Measured memory_bytes: 256
def resolve():
    n=int(input())
    a=list(map(int,input().split()))
    count=0
    for each in a:
        if each%2==0:
            if not (each%3 == 0 or each%5==0):
                count+=1
    if count==0:
        print("APPROVED")
    else:
        print("DENIED")
resolve()

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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()
#define MP(n, m) make_pair(n, m);

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;
using ul = unsigned long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

void printv(VI& v){
  REP(i,v.size()) cout << v[i] << " ";
  cout << endl;
}

int vtotal(VI& v){
  int total=0;
  REP(i,v.size()) total+=v[i];
  return total;
}

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

  // string n;
	// getline(cin,n);

  int n;
  cin>>n;

  VI a(n+1);
  VI b(n);

  REP(i,n+1){
    cin>>a[i];
  }
  REP(i,n){
    cin>>b[i];
  }

  ll ans=0;
  RREP(i,n){
    int next=a[i+1];
    int s=min(b[i],a[i+1]);
    ans+=s;
    b[i]-=s;
    s=min(b[i],a[i]);
    ans+=s;
    a[i]-=s;
  }

  cout<<ans<<endl;

  // cout<<std::setprecision(10)<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define l(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	ll count=0;
	l(i,0,s.length()){
		if(s[i]!=t[i]) count++;
	}
	cout<<count<<"\n";
}

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

int main()
{
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  int s[h][w];
  
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if((i<b&&j<a)||(i>=b&&j>=a)){
        cout << "0";
      }else{
        cout << "1";
      }
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String w = sc.next();
		int count = 0;
		boolean judge = true;
		while(judge){
			if(0 == w.length()){
				System.out.println("Yes");
				break;
			}else{
				char a = w.charAt(0);
				for (int i = 0; i < w.length(); i++) {
					if(a == w.charAt(i)){
						count++;
					}
					if(i == w.length() -1){
						if(count%2 == 0){
							w = w.replaceAll(String.valueOf(a), "");
							count = 0;
						}else{
							System.out.println("No");
							judge = false;
							break;
						}
					}
				}
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

string S;
int x, y;

bool mon(int x)
{
    return x>0&&x<=12;
}

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

    cin>>S;
    x = (S[0]-'0')*10+(S[1]-'0');
    y = (S[2]-'0')*10+(S[3]-'0');

    if( mon(x)&&mon(y) )
    {
        cout<<"AMBIGUOUS\n";
    }
    else if( !mon(x)&&mon(y) )
    {
        cout<<"YYMM\n";
    }
    else if( mon(x)&&!mon(y) )
    {
        cout<<"MMYY\n";
    }
    else cout<<"NA\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1e9+7;
const ll ARR_MAX = 1e2+1;
const ll VAL_MAX = 1e5+1;
const ll INF=1e14;

ll dp[VAL_MAX],prev_cum[VAL_MAX]; 
//dp[i][j]= number of ways to split j candies among children 0...i;

void modulo(ll &x){
	x%=MOD;
	x+=MOD;
	x%=MOD;
}

void solve(){
    int n,k;cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }
    dp[0]=1;
    for(int i=0;i<n;i++){
    	ll s=0;
    	for(int j=0;j<=k;j++){
    		s+=dp[j];
    		// s%=MOD;
    		modulo(s);
    		prev_cum[j]=s;
    	}
    	for(int j=0;j<=k;j++){
    		if(j<=a[i]){
    			dp[j]=prev_cum[j]; //prev_cum[j] = dp[0]+dp[1]+...+dp[j]
    		}
    		else{
    			dp[j]=prev_cum[j]-prev_cum[j-a[i]-1];
    			modulo(dp[j]);
    		}
    	}
    }
    cout<<dp[k]<<nl;
}

int main(){
    fastio();
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
def isPrime(num)
  return true if num == 2
  return false if num <= 1 || num%2 == 0
  sqrt = Math.sqrt(num).floor
  for d in 2..sqrt do
    if num%d == 0
      return false
    end
  end
  true
end

n = gets.to_i
res = 0
n.times do
  res += 1 if isPrime(gets.to_i)
end
puts res


Measured memory_bytes: 6884
#include <bits/stdc++.h>
/**
AHMAD;HASSAN;SAEED
*/
using namespace std;
int n;
long long rm=1e9+7;
int cnt=0;
vector<long long>dp((1<<22),-1ll);
vector<vector<int> >mtx2;
long long slv(int vis=(1<<(n))-1){
    cnt++;
    long long ret=0ll;
    int idx=n;
    int tm=vis;
    while(tm){
        if(tm&1)
            idx--;
        tm/=2;
    }
    if(idx==n){
        return 1ll;

    }
    if(dp[vis]!=-1ll)
        return dp[vis];
    for(int i=0;i<n;i++){
        if(mtx2[idx][i]&&(vis&((1<<i)))){
            ret+=slv(vis&(~(1<<i)));
            ret%=rm;
        }

    }
    return dp[vis]=ret;
}


int main()
{

    cin>>n;
    vector<vector<int> >mtx(n,vector<int>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>mtx[i][j];
        }
    }
    mtx2=mtx;
    cout<<slv()<<'\n';
/**
4
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
*/
    return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<long> h(n);
    for(auto&& e:h) cin >> e;
    vector<vector<int>> adj(n,vector<int>());
    int a,b;
    while(cin >> a >> b){
        --a;
        --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int ans = 0;
    for(int i=0; i<n; i++){
      	bool flag = 1;
        for(auto j: adj[i]){
            if(h.at(i) <= h.at(j))
                flag = 0;
        }
      	if(flag)
        	ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

int main() {
    long long n, sum = 0, min = 1e12;
    cin >> n;
    for (long long i = 1; i * i <= n; i++){
        if (n % i == 0){
            sum = i + (n / i) - 2;
        }
        if (sum < min){
            min = sum;
        }
    }
    cout << min << endl;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;

    int N = s.size();

    if(N == 2 && s[0] == s[1]){
        cout << 1 << " " << 2 << endl;
        return 0;
    }

    for(int i = 0; i < N - 2; i++){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
        else if(s[i+1] == s[i+2]){
            cout << i+2 << " " << i+3 << endl;
            return 0;
        }
        else if(s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
   
    cout << -1 << " " << -1 << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int R, G;
	cin >> R >> G;
	cout << 2 * G - R << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int mo = 1000000007;
        long na = 1;
        long ma = 1;
        if (Math.abs(n - m) > 1) {
            System.out.println(0);
        } else {
            for (int i = 0; i < n; i++) {
                na = na % mo * (n - i) % mo;
            }
            for (int i = 0; i < m; i++) {
                ma = ma % mo * (m - i) % mo;
            }
            if (m != n) {
                System.out.println(na % mo * ma % mo);
            } else {
                System.out.println(na % mo * ma % mo * 2 % mo);
            }
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int N;
string S1, S2;
long long dp[52];
int MOD = 1000000007;

int main() {
	cin >> N;
	cin >> S1 >> S2;
	if (S1[0] == S2[0])dp[0] = 3;
	else dp[1] = 6;

	for (int i = 0; i < N - 1; i++) {
		dp[i] %= MOD;
		if (S1[i] == S2[i]) {
			if(S1[i + 1] == S2[i + 1])
				dp[i + 1] += (dp[i] * 2);
			else if (i + 2 < N && S1[i + 1] == S1[i + 2])
				dp[i + 2] += (dp[i] * 2);
		}
		else if (i + 2 < N && S1[i] == S1[i + 1]) {
			if (S1[i + 2] == S2[i + 2]) {
				dp[i + 2] += (dp[i + 1]);
			}
			else if(i + 3 < N && S1[i + 2] == S1[i + 3]){
				dp[i + 3] += (dp[i + 1] * 3);
			}
		}
	}
	cout << dp[N - 1] % MOD << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
int a[N];
int p1[N],p2[N];
int f1[N],f2[N];
int main(){
    int n;
    cin>>n;

    cout<<(n-1)/2<<endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp::min;

const INF: i64 = 1_i64 << 60;
fn func(x: i64, s: &Vec<i64>) -> (i64, i64) {
    match s.binary_search(&x) {
        Ok(i) => (s[i], s[i]),
        Err(i) => if i == 0 {
            (s[i], s[i])
        } else if i == s.len() {
            (s[i-1], s[i-1])
        } else {
            (s[i-1], s[i])
        }
    }
}

fn calc(x: i64, s: i64, t: i64) -> i64 {
    min((s - x).abs() + (t - s).abs(),
        (t - x).abs() + (t - s).abs())
}

fn main() {
    let a: usize = read();
    let b: usize = read();
    let q: usize = read();
    let s: Vec<i64> = (0..a).map(|_| read()).collect();
    let t: Vec<i64> = (0..b).map(|_| read()).collect();

    for _ in 0..q {
        let x: i64 = read();
        let (s1, s2) = func(x, &s);
        let (t1, t2) = func(x, &t);
        let mut ans = INF;
        ans = min(ans, calc(x, s1, t1));
        ans = min(ans, calc(x, s1, t2));
        ans = min(ans, calc(x, s2, t1));
        ans = min(ans, calc(x, s2, t2));
        println!("{}", ans);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 7420
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll X, K, D;
    cin >> X >> K >> D;
    ll min_dist = INF;
    X = abs(X);
    ll straight = min(K, X/D);
    K -= straight;
    X -= straight * D;
    if(K%2==0) cout << X << endl;
    else cout << D - X << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3624
N, A, B = map(int, input().split())

ans = 0
for i in range(N+1):
    s = str(i)
    jdg = 0
    for k in range(len(s)):
        jdg += int(s[k])
    if A <= jdg and jdg <=B:
        ans += i
print(ans)

Measured memory_bytes: 40560
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

int r, D, x;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> r >> D >> x;

  for (int i = 1; i <= 10; i++) {
    int ans = r * x - D;
    cout << ans << endl;
    x = ans;
  }
  return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [u128; n],
    }

    if a.iter().filter(|x| **x == 0).count() != 0 {
        println!("0");
        return;
    };

    let mut ans: u128 = 1;
    for item in a {
        ans *= item;
        if ans > 1000000000000000000 {
            println!("-1");
            return;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5256
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

ll MODP = 998244353;

ll gen(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x%MODP;
  if(y%2 == 1){
    return ((x%MODP)*(gen(x,y-1))%MODP)%MODP;
  }else{
    ll t = gen(x,y/2);
    return ((t%MODP)*(t%MODP))%MODP;
  }
}

ll comb(ll x,ll y){
  if(y == 0)return 1;
  ll res = 1;
  rep(i,y){
    res = ((res%MODP)*((x-i)%MODP))%MODP;
  }
  for(ll i = 1;i <= y;i++){
    res = ((res%MODP)*gen(i,MODP-2))%MODP;
  }
  return res%MODP;
}

int main(){
  ll N;
  cin >> N;
  vector<double> p(N+1);
  rep(i,N)cin >> p[i];
  double dp[N+5][N+5];
  dp[0][0] = 1;
  for(int i = 0;i < N;i++){
    for(int j = 0;j < N;j++){
      if(i + j < N){
        dp[i][j+1] += dp[i][j]*(1.0-p[i+j]);
        dp[i+1][j] += dp[i][j]*p[i+j];
      }
    }
  }
  double ans = 0.0;
  rep(i,N+1)rep(j,N+1){
    if(i == 0 & j == 0)continue;
    if(i > j & i + j == N){
      ans += dp[i][j];
    }
  }
  cout << fixed << setprecision(10) << ans << endl;



  return 0;
}


Measured memory_bytes: 49920
#include <bits/stdc++.h>
using namespace std;
#define N int(1e5 + 5)
#define MOD 1000003
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
int main(){
    IO
    int n; cin >> n;
    vector<pair<int, ll> >v(n);
    for(int i=0 ; i < n ; i++){
        cin >> v[i].second >> v[i].first;
        v[i].second *= -1;
    }
    sort(v.begin(), v.end());
    ll meh = 0;
    for(int i=0 ; i < n ; i++){
        meh += v[i].second * -1;
        if(v[i].first < meh)
            return cout << "No", 0;
    }
    cout << "Yes";
}


Measured memory_bytes: 3328
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

0.upto(n-1) do |i|
    a[i] -= (i+1)
end
a.sort!

if n%2!=0
    m = a[n/2]
else
    m = ((a[n/2] + a[n/2-1])/2.0).round
end

ans = 0
0.upto(n-1) do |i|
    ans += (a[i] - m).abs
end

puts ans

Measured memory_bytes: 19456
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    h,w,d = LI()
    r = [['.']*w for _ in range(h)]
    cs = ['R','Y','G','B']
    for i in range(0,h+d,d):
        for j in range(0,w+d,d):
            c = cs[(i+j) % (d*2) // d]
            for ii in range(-d,d):
                for jj in range(-d,d):
                    if i+ii < 0 or i+ii >= h or j+jj < 0 or j+jj >= w or abs(ii)+abs(jj) >= d or abs(ii)+abs(d-jj-1) >= d:
                        continue
                    r[i+ii][j+jj] = c
    for i in range(1,h+d,d):
        for j in range(0,w+d,d):
            c = cs[(i+j) % (d*2) // d + 2]
            for ii in range(d):
                for jj in range(d):
                    if i+ii < 0 or i+ii >= h or j+jj < 0 or j+jj >= w:
                        continue
                    if abs(ii)+abs(jj) >= d or r[i+ii][j+jj] != '.' or jj > ii:
                        break
                    r[i+ii][j+jj] = c
                for jj in range(-1,-d-1,-1):
                    if i+ii < 0 or i+ii >= h or j+jj < 0 or j+jj >= w:
                        continue
                    if abs(ii)+abs(jj) >= d or r[i+ii][j+jj] != '.':
                        break
                    r[i+ii][j+jj] = c


    return '\n'.join([''.join(c) for c in r])


print(main())




Measured memory_bytes: 81644
#include<iostream>
using namespace std;
int main()
{
int a,b,c,g;
cin>>a;
cin>>b;
cin>>c;

g=a;
a=b;
b=g;

g=a;
a=c;
c=g;
  
cout<< a << " " << b << " " << c << endl;
return 0;
}

Measured memory_bytes: 256
n = gets.to_i
as = []
n.times do |i|
  a = [gets.to_i, i]
  as << a
end

as.sort!.reverse!

n.times do |i|
  if as[0][1] == i
    puts as[1][0]
  else
    puts as[0][0]
  end
end


Measured memory_bytes: 19804
import math
n, x = map(int,input().split())
p = list(map(int,input().split()))
if n == 1:
    print(abs(p[0]-x))
else:
    g = math.gcd(p[0]-x,p[1]-x)
    for i in range(2,n):
        g = math.gcd(g,p[i]-x)
    print(g)

Measured memory_bytes: 20404
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
const int Maxn=200005;
const int Maxm=1000005;
const LL mod=998244353;
int a[Maxn],n;
LL coef[Maxm],sum[Maxm];
int ft[Maxm][241],kt[Maxm];
LL qp(LL x,LL p){
	LL ret=1;
	while (p){
		if (p&1) ret=ret*x%mod;
		p>>=1;
		x=x*x%mod;
	}
	return ret;
}
LL inv(LL x){
	return qp(x,mod-2);
}
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for (int i=1;i<Maxm;i++){
		coef[i]=inv(i);
	}
	for (int i=1;i<Maxm;i++){
		ft[i][kt[i]++]=i;
		for (int j=i+i;j<Maxm;j+=i){
			coef[j]-=coef[i];
			if (coef[j]<0) coef[j]+=mod;
			ft[j][kt[j]++]=i;
		}
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<kt[a[i]];j++){
			sum[ft[a[i]][j]]+=a[i];
			if (sum[ft[a[i]][j]]>=mod) sum[ft[a[i]][j]]-=mod;
		}
	}
	LL ans=0;
	for (int i=1;i<Maxm;i++){
		//if (sum[i]) cout<<i<<' '<<sum[i]<<endl;
		ans+=coef[i]*sum[i]%mod*sum[i]%mod;
		ans%=mod;
	}
	for (int i=0;i<n;i++) ans-=a[i];
	ans=(ans%mod+mod)%mod;
	ans=ans*inv(2)%mod;
	printf("%lld\n",ans);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string base = "AKIHABARA";
    string S;
    cin >> S;
    rep(i, base.size()) {
        if(base[i] != S[i]) S.insert(S.begin() + i, 'A');
    }
    if(base == S) cout << "YES";
    else cout << "NO";
    cout << endl; 
    return 0;
}


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

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


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

	function<i64(i64,i64)> mpow = [&](i64 x, i64 y){
		if(y < 2)
			return (i64)(y ? x : 1);

		i64 tmp = mpow(x, y >> 1);
		return (tmp * tmp) % MOD * mpow(x, y & 1) % MOD;
	};

	vector<i64> fact(n + 5, 1), inv(n + 5, 1);
	for(int i = 1; i < n + 5; ++i){
		fact[i] = (fact[i - 1] * i) % MOD;
		inv[i] = mpow(fact[i], MOD - 2);
	}

	vector<i64> dp(n + 1, 0);
	dp[n] = 1;

	for(int i = b; i >= a; --i){
		vector<i64> nex(n + 1, 0);
		for(int j = 0; j <= n; ++j){
			nex[j] = (dp[j] + nex[j]) % MOD;
			i64 p = fact[j];
			for(int k = 0; k < c; ++k)
				p = (p * inv[i]) % MOD;

			for(i64 k = j - (c * i), l = c; k >= 0 && l <= d; k -= i, ++l, p = (p * inv[i]) % MOD){
				nex[k] = (nex[k] + dp[j] * p % MOD * inv[k] % MOD * inv[l]) % MOD;
			}
		}
		dp = move(nex);
	}
	cout << dp[0] << endl;
}



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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

namespace flow {

class bipartite_matching {
private:

  int V;
  vector<vector<int>> G;
  vector<int> match;
  vector<bool> used;

  bool dfs(int v) {
    used[v] = 1;
    for(auto& u: G[v]) {
      int w = match[u];
      if(w < 0 || (!used[w] && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }


public:

  bipartite_matching(int V): V(V) {
    G.resize(V), match.resize(V), used.resize(V);
  }

  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  int maximum_matching() {
    int ret = 0;
    match.clear(), match.resize(V, -1);
    rep(v, V) {
      if(match[v] < 0) {
        used.clear(), used.resize(V, 0);
        if(dfs(v)) { ret ++; }
      }
    }
    return ret;
  }
};

}

int main() {

  for(int N; cin >> N && N;) {
    int M; cin >> M;

    int dcnt = 0;
    map<int, int> dayidx;
    rep(i, M) {
      int x; cin >> x;
      if(dayidx.find(x) == dayidx.end()) {
        dayidx[x] = dcnt++;
      }
    }

    flow::bipartite_matching bp(dcnt + N);

    rep(girl, N) {
      cin >> M;
      rep(i, M) {
        int k; cin >> k;
        if(dayidx.find(k) != dayidx.end())
          bp.add_edge(dayidx[k], dcnt + girl);
      }
    }

    cout << bp.maximum_matching() << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

int main(){
  int a,b;
  cin >> a >> b;
  if(a <= b) cout << a << endl;
  else cout << a-1 << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

#define N_MAX 100001
#define M_MAX 100001

void solv()
{
	int N, M;  scanf("%d%d", &N, &M);
	vector<pair<int, int> > table;
	for (int i = 0; i < N; i++){
		int a; scanf("%d", &a);
		table.push_back(make_pair(a, 1));
	}
	for (int i = 0; i < M; i++){
		int b, c; scanf("%d%d", &b, &c);
		table.push_back(make_pair(c, b));
	}

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

	long long int sum = 0;
	int tail = table.size() - 1;
	for (int i = 0; i < N; i++){
		sum = sum + (long long int)table[tail].first;
		table[tail].second--;
		if (0 == table[tail].second){
			tail--;
		}
	}

	printf("%lld", sum);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 2420