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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(int (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(int (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> Vec;

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];
	ll sum = 0;
	rep(i, n) sum += a[i];

	ll dif = 0;
	ll s = 0;
	rep(i, n){
		s += a[i]*2;
		if(s < sum) dif = sum-s;
		else{
			dif = min(dif, s-sum);
			break;
		}
	}

	co(dif);

	return 0;
}


Measured memory_bytes: 1920
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
int cnt;
int t[3]={-1,0,1};
    int map[55][55];
void dfs(int h,int w){
    if(map[h][w]==1){
        map[h][w]=0;
        for(int i=0;i<3;i++){for(int j=0;j<3;j++)dfs(h+t[i],w+t[j]);}
       }
}
int main()
{
    int w,h;

    while(cin>>w>>h,w+h){cnt=0;
        for(int i=0;i<55;i++){for(int j=0;j<55;j++)map[i][j]=0;}
        for(int i=0;i<h;i++){for(int j=0;j<w;j++)scanf("%d",&map[i+1][j+1]);}
        for(int i=0;i<53;i++){for(int j=0;j<53;j++){
            if(map[i][j]==1)cnt++;
            dfs(i,j);}}
        cout<<cnt<<endl;}
    return 0;
}

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

#define ll long long int
#define L 3000

ll dp[L + 5][L + 5], A[L + 5];

ll max(ll a, ll b)
{
    if (a >= b) return(a);
    return(b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        dp[i][i] = A[i];
    }
    for (int i = 1; i < N; i++) for (int j = 0; j + i < N; j++) dp[j][j + i] = max(A[j] - dp[j + 1][j + i], A[j + i] - dp[j][j + i - 1]);
    cout << dp[0][N - 1] << '\n';
    return(0);
}

Measured memory_bytes: 70016
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    S=STR()
    l=sorted(S)
    #print(l)
    if l[0]=='a' and l[1]=='b' and l[2]=='c':
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
from copy import deepcopy

H, W, K = map(int, input().split())
c = []
for _ in range(H):
    s = input()
    s = s.replace('#', '1')
    s = s.replace('.', '0')
    c.append(list(map(int, s)))

red = sum([sum(r) for r in c])

ans = 0
lim = (1 << (H+W))
for i in range(lim):
    tmp = deepcopy(c)
    tmp_red = red
    for j in range(H):
        bit = 1 & (i >> j)
        if bit == 1:
            for k in range(W):
                if tmp[j][k] == 1:
                    tmp[j][k] = 0
                    tmp_red -= 1
    for j in range(W):
        bit = 1 & (i >> (j + H))
        if bit == 1:
            for k in range(H):
                if tmp[k][j] == 1:
                    tmp[k][j] = 0
                    tmp_red -= 1
    if tmp_red == K:
        ans += 1
print(ans)

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

using namespace std;
typedef long long LL;

int main()
{
	map<int,set<int>> adj;
	map<pair<int,int>,int> cost;
	int N;
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		adj[a].insert(b);
		adj[b].insert(a);
		cost[make_pair(a, b)] = c;
		cost[make_pair(b, a)] = c;
	}
	int Q, K;
	cin >> Q >> K;
	// calc single source shortest path distance from K to all others
	map<int,LL> dist;
	dist[K] = 0;
	queue<int> q;
	q.push(K);
	while (q.size() > 0) {
		int h = q.front();
		q.pop();
		for (auto v : adj[h]) {
			if (dist.count(v) == 0) {
				q.push(v);
				dist[v] = dist[h]+cost[make_pair(h,v)];
			}
		}
	}
	for (int i = 0; i < Q; i++) {
		int x, y;
		cin >> x >> y;
		cout << dist[x]+dist[y] << endl;
	}
	exit(0);
}



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


#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"

typedef long long ll;

int main()
{
   ll n,x,t;

   cin>>n>>x>>t;

   ll r = n/x;

   if(n%x==0)
    cout<<t*r<<endl;
   else
    cout<<(r+1)*t<<endl;
}


Measured memory_bytes: 3588
_, s = open(0)
c = 0
for i in range(1000):
    p = 0
    F = 1
    for j in str(i).zfill(3):
        q = s[p:].find(j)
        if q < 0:
            F = 0
            break
        p += q + 1
    c += F
print(c)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "";
            switch (sS)
            {
                case "A": sOut = "T"; break;
                case "T": sOut = "A"; break;
                case "C": sOut = "G"; break;
                case "G": sOut = "C"; break;
            }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 11220
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		for (int i = 0; i < s.length; i++) {
			int key = i % 2;
			if (key == 0) {
				if (s[i] == 'L') {
					System.out.println("No");
					return;
				}
			} else {
				if (s[i] == 'R') {
					System.out.println("No");
					return;
				}

			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  string s; cin >> s;
  int k; cin >> k;

  char c = s[k-1];
  rep(i, n) {
    if (s[i] != c) cout << "*";
    else cout << s[i];
  }

  cout << endl;

  return (0);
}


Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

long double dp[4000][4000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  //  freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=min(a,b);i>=1;i--)
    {
    	if(a%i==0 && b%i==0)
    	{
    		c--;
    		if(c==0)
    		{
    			cout<<i;
    			return 0;
    		}
    	}
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x; cin >> x;
    cout << 10 - x/200 << endl;
}

Measured memory_bytes: 3648
def fib_iter(n):
  fib_n  = 1
  fib_n2 = 1
  fib_n1 = 1
  for i in range(n - 1):
    fib_n  = fib_n1 + fib_n2
    fib_n2 = fib_n1
    fib_n1 = fib_n
  return fib_n

x = int(raw_input())

print fib_iter(x)

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

int main() {
	long long n,i,c;
	cin >> n;
	vector<long long> a(n);
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	if(n%2==0){
		for(i=n-1; i>0; i-=2){
			cout << a[i] << ' ';
		}
		for(i=0; i<n; i+=2){
			cout << a[i] << ' ';
		}
	}else{
		for(i=n-1; i>=0; i-=2){
			cout << a[i] << ' ';
		}
		for(i=1; i<n; i+=2){
			cout << a[i] << ' ';
		}
	}
}


Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#include<numeric>
#define rep(a,b) for(ll a=0;a<b;++a)
#define REP(a,b,c,d) for(ll a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_ll = pair<ll, ll>;
int main() {
	int N, num = 0;	cin >> N;
	vector<int> h(N);
	rep(i, N)cin >> h[i];
	rep(i, N) {
		bool ok = true;
		rep(j,i) {
			if (h[j] > h[i]) {
				ok = false;
				break;
			}
		}
		if (ok)++num;
	}
	cout << num << endl;
	cin >> N;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long sum = 0;
		long sum1=0;
		long mod = 1000000007;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
			sum=(sum+a[i])%(mod*2);
			sum1=(sum1+a[i]*a[i])%(mod*2);
		}
		long ans = ((sum*sum-sum1)/2)%mod;
		System.out.println(ans%mod);
	}
}

Measured memory_bytes: 63208
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String stn = str.replaceAll("BC", "D");
        long a_count = 0;
        long count = 0;
        for(int i = 0; i < stn.length(); i++) {
            char a = stn.charAt(i);
            if (a == 'A') a_count++;
            else if (a == 'D') count += a_count;
            else a_count = 0;
        }
        System.out.println(count);
    }
}

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

inline int in() { int x; cin >> x; return x; }

void solve() {
  int n = in();
  if (n%2!=0) {
    cout << 0 << endl;
    return;
  }
  int ans = 0;
  n /= 2;
  while(n) {
    n /= 5;
    ans += n;
  }
  cout << ans << endl;
}

#undef int
int main() {
  solve();
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

//const MAX:usize = 100006;

fn main() {
    let s:Vec<char> = read::<String>().chars().collect();
    let mut v:Vec<(bool,u64)> = vec![];

    let mut f:bool = if s[0]=='<' {true} else {false};
    let mut cnt:u64 = 0;

    for &ch in s.iter() {
        let g:bool = if ch=='<' {true} else {false};
        if f != g {
            v.push((f, cnt));
            cnt=1;
            f=g;
        } else {
            cnt += 1;
        }
    }
    v.push((f, cnt));

    let mut ans:u64 = 0;
    for i in 0..v.len() {
        let i = i as usize;
        let f = v[i].0;
        let cnt = v[i].1;
        //println!("{} {}", f, cnt);
        // '<' の場合は、右隣りの'>'の連続数と比較する
        if f {
            if i == v.len()-1 {
                ans += cnt*(cnt+1)/2;
                continue;
            }
            if cnt <= v[i+1].1 {
                ans += cnt*(cnt-1)/2;
            } else {
                ans += cnt*(cnt+1)/2;
            }
        }
        // '>' の場合は、左隣りの'<'の連続数と比較する
        else {
            if i == 0 {
                ans += cnt*(cnt+1)/2;
                continue;
            }
            if cnt < v[i-1].1 {
                ans += cnt*(cnt-1)/2;
            } else {
                ans += cnt*(cnt+1)/2;
            }
        }
    }

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


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

using namespace std;

int main()
{
	int len;
  	string a, b;
  	cin>>len>>a>>b;
  	for(int i = 0; i < len; ++i){
    	cout<<a[i]<<b[i];
    }
  	cout<<'\n';
	return 0;
}

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

using namespace std;

int main() {
  int p[5];
  int k;
  for(int i=0 ; i < 5 ; ++i) cin >> p[i];
  cin >> k;
  

  if(abs(p[0]-p[4]) > k) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}


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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,b,a)     for(int i=b;i>=a;i--)
#define endl '\n'

#define ll long long int

int n;
string s;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    
    cin>>n>>s;
    if(s.length()<=n)
    	cout<<s;
    else
    {
    	rep(i,0,n-1)
    		cout<<s[i];
    	cout<<"...";
    }
}
	

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

typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

string S, T, U;
int A, B;

int main() {
	cin >> S;
	for (char c : S) {
		cout << 'x';
	}
	cout << endl;
}

Measured memory_bytes: 256
a,b,h,m = gets.split.map(&:to_i)
harg = (360 / (60*12).to_f) * ((h * 60) + m)
marg = 6 * m
len = 0
theta = harg - marg
len = (a**2) + (b**2) - (2 * a * b * Math.cos(theta*Math::PI/180))
theta = marg - harg
len2 = (a**2) + (b**2) - (2 * a * b * Math.cos(Math::PI*theta/180))

puts Math.sqrt([len,len2].min)

Measured memory_bytes: 14680
#!/usr/bin/env python3

import array


P_NUM = 1000000007


def solv(n, m, a):
    comb = array.array('I', [1] * (n+1))
    for i in a:
        comb[i] = 0

    for i in range(2, n+1):
        if comb[i] != 0:
            comb[i] = (comb[i-1] + comb[i-2]) % P_NUM

    return comb[-1]


if __name__ == '__main__':

    n, m = map(int, input().split())
    a = [int(input()) for _ in range(m)]

    ans = solv(n, m, a)

    print(ans)


Measured memory_bytes: 8232
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int main(){
	
	string s;
	cin >> s;
	
	set<char> m;
	for(int i=0;i<s.size();i++) m.insert(s[i]);
	cout << (m.size() == 3 ? "Yes" : "No") << endl;
	
	
	
	
	
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for(int i = (l); i < (r); ++i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-------
const int N = 101;
int n, m;
char ans[N][N];
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 0, 50) rep(j, 0, N - 1) ans[i][j] = '.';
	rep(i, 50, 100) rep(j, 0, N - 1) ans[i][j] = '#';
	for(int cnt = m - 1, i = 0; i < 50 && cnt != 0; i+=2) {
		for(int j = 0; j < N - 1 && cnt != 0; j++) {
			bool ok = 1;
			for(int k = 0; k < 4; k++) {
				int nx = i + (k == 0) - (k == 1), ny = j + (k == 2) - (k == 3);
				if(nx < 0 || nx > 99 || ny < 0 || ny > 99) continue;
				if(ans[nx][ny] == '#') ok = 0;
			}
			if(ok) cnt--, ans[i][j] = '#';
		}
	}
	for(int cnt = n - 1, i = 50; i < N - 1 && cnt != 0; i += 2) {
		for(int j = 0; j < N - 1 && cnt != 0; j++) {
			bool ok = 1;
			for(int k = 0; k < 4; k++) {
				int nx = i + (k == 0) - (k == 1), ny = j + (k == 2) - (k == 3);
				if(nx < 0 || nx > 99 || ny < 0 || ny > 99) continue;
				if(ans[nx][ny] == '.') ok = 0;
			}
			if(ok) cnt--, ans[i][j] = '.';
		}
	}
	printf("%d %d\n", 100, 100);
	rep(i, 0, N) printf("%s\n", ans[i]);
	
	return 0;
}



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

using namespace std;
typedef long long int ll;

int dh[4] = {1,0,-1,0};
int dw[4] = {0,1,0,-1};

int main()
{
   int n,m;
   cin >> n >> m;
   vector<int>c(m);
   for(int i = 0; i < m; i++) cin >> c[i];
   vector<vector<int>>dp(m+1,vector<int>(n+1,INF));
   for(int i = 0; i <= m; i++) dp[i][0] = 0;
   for(int i = 1; i <= m; i++)
   {
       for(int j = 0; j <= n; j++)
       {
           if(j < c[i-1]) dp[i][j] = dp[i-1][j];
           else dp[i][j] = min(dp[i-1][j],dp[i][j-c[i-1]] + 1);
       }
   }
   cout << dp[m][n] << endl;
}


Measured memory_bytes: 7092
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val a, b, n = sc.nextLong()

    var x = b - 1

    while (x > n) x -= b

    if (n < b - 1) x = n

    println((a * x) / b - a * (x / b))
  }

  @scala.annotation.tailrec
  def gcd(a: Int, b: Int): Int = {
    if (b == 0) a else gcd(b, a % b)
  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


Measured memory_bytes: 55352
#include<bits/stdc++.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define ull unsigned long long int
#define T int test; scanf("%d",&test); while(test--)
#define pb push_back
#define in insert
#define PI acos(-1)
#define sc(n) scanf("%d",&n)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define lsc(n) scanf("%lld",&n)
#define lsc2(a,b) scanf("%lld%lld",&a,&b)
#define rep(i,n) for(i=0;i<n;i++)
#define fr(i,a,b) for(i=a;i<b;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/__gcd(a,b)
using namespace std;



int main()
{
	ll n,k,i,ans=0;
	lsc2(n,k);
	for(i=k;i<=n+1;i++)
	{
		ll mn=((i*(i+1))/2)-i;
		ll mx=((n*(n+1))/2)-(((n-i)*(n-i+1))/2);
		ans+=mx-mn+1;
	}
	cout << ans%1000000007 << endl;
    return 0;
}


Measured memory_bytes: 3756
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))

dp=[[0,0,0] for _ in range(n)]
dp[0]=l[0]
for i in range(1,n):
    dp[i][0]=l[i][0]+max(dp[i-1][1],dp[i-1][2])
    dp[i][1]=l[i][1]+max(dp[i-1][0],dp[i-1][2])
    dp[i][2]=l[i][2]+max(dp[i-1][1],dp[i-1][0])
print(max(dp[-1]))

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

signed main(){
	int H,W,D; cin>>H>>W>>D;
	vector<pair<int,int>> fie(100000);
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int a; cin>>a;
			fie[a].first=i;
			fie[a].second=j;
		}
	}

	vector<int> dist(fie.size());
	dist[1]=0; dist[0]=0;
	for(int i=2;i<H*W+100;i++){
		if(i-D<0)dist[i]=0;
		else{
			dist[i]=dist[i-D]+llabs(fie[i].first-fie[i-D].first)+llabs(fie[i].second-fie[i-D].second);

		}

	}

	int Q; cin>>Q;
	for(int i=0;i<Q;i++){
		int L,R,ans=0;
		cin>>L>>R;
		ans=dist[R]-dist[L];
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<vector>
#include<array>
#include<algorithm>
using namespace std;
int n;
int rd()
{
	int ret=0;
	for(int i=0;i<16;i++)
	{
		int a;cin>>a;
		ret+=a<<i;
	}
	return ret;
}
vector<int>G[9];
int F[9];
main()
{
	G[0].push_back(0);
	G[0].push_back(1);
	G[0].push_back(2);
	G[0].push_back(3);
	G[0].push_back(6);
	G[1].push_back(0);
	G[1].push_back(1);
	G[1].push_back(2);
	G[1].push_back(4);
	G[1].push_back(7);
	G[2].push_back(0);
	G[2].push_back(1);
	G[2].push_back(2);
	G[2].push_back(5);
	G[2].push_back(8);
	G[3].push_back(0);
	G[3].push_back(3);
	G[3].push_back(4);
	G[3].push_back(5);
	G[3].push_back(6);
	G[4].push_back(1);
	G[4].push_back(3);
	G[4].push_back(4);
	G[4].push_back(5);
	G[4].push_back(7);
	G[5].push_back(2);
	G[5].push_back(3);
	G[5].push_back(4);
	G[5].push_back(5);
	G[5].push_back(8);
	G[6].push_back(0);
	G[6].push_back(3);
	G[6].push_back(6);
	G[6].push_back(7);
	G[6].push_back(8);
	G[7].push_back(1);
	G[7].push_back(4);
	G[7].push_back(6);
	G[7].push_back(7);
	G[7].push_back(8);
	G[8].push_back(2);
	G[8].push_back(5);
	G[8].push_back(6);
	G[8].push_back(7);
	G[8].push_back(8);
	F[0]=1<<0|1<<1|1<<4|1<<5;
	F[1]=1<<1|1<<2|1<<5|1<<6;
	F[2]=1<<2|1<<3|1<<6|1<<7;
	F[3]=1<<4|1<<5|1<<8|1<<9;
	F[4]=1<<5|1<<6|1<<9|1<<10;
	F[5]=1<<6|1<<7|1<<10|1<<11;
	F[6]=1<<8|1<<9|1<<12|1<<13;
	F[7]=1<<9|1<<10|1<<13|1<<14;
	F[8]=1<<10|1<<11|1<<14|1<<15;
	while(cin>>n,n)
	{
		vector<array<int,6> >now;
		int ret=rd();
		if(!(ret&F[4]))
		{
			array<int,6>a;
			for(int i=0;i<5;i++)a[i]=-1;
			a[5]=4;
			now.push_back(a);
		}
		for(int i=1;i<n;i++)
		{
			ret=rd();
			bool ok[9]={};
			for(int j=0;j<9;j++)ok[j]=!(ret&F[j]);
			vector<array<int,6> >tmp;
			for(int j=0;j<now.size();j++)
			{
				array<int,6>a=now[j];
				int out=(1<<16)-1;
				if(a[0]==-1)out=0;
				for(int k=0;k<6;k++)if(a[k]>=0)out&=~F[a[k]];
				for(int k=0;k<5;k++)
				{
					int v=G[a[5]][k];
					if(ok[v]&&!(out&~F[v]))
					{
						array<int,6>b;
						for(int l=0;l<5;l++)b[l]=a[l+1];
						b[5]=v;
						tmp.push_back(b);
					}
				}
			}
			sort(tmp.begin(),tmp.end());
			tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
			now=tmp;
		}
		cout<<!now.empty()<<endl;
	}
}



Measured memory_bytes: 3340
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var currentX = 0L;
            var currentY = 0L;
            var currentT = 0L;
            for (var i = 0; i < N; i++)
            {
                var (t, x, y) = Read3Longs();
                var kyoriX = Math.Abs(currentX - x);
                var kyoriY = Math.Abs(currentY - y);
                if (t - currentT >= kyoriX + kyoriY && (t - currentT - kyoriX - kyoriY) % 2 == 0)
                {
                    currentX = x;
                    currentY = y;
                    currentT = t;
                }
                else
                {
                    return "No";
                }
            }

            return "Yes";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 46440
#include <bits/stdc++.h>
using namespace std;
int n,m,a,b;
int x[110],y[110];
int main(){
	int xmax=-100,ymin=100;
	cin>>n>>m>>a>>b;
	for(int i=0;i<n;i++){
		cin>>x[i];
		if(x[i]>xmax||i==0){
			//cout<<"x "<<i<<endl;
			xmax=x[i];
		}
	}
	for(int i=0;i<m;i++){
		cin>>y[i];
		if(y[i]<ymin||i==0){
			ymin=y[i];
		}
	}
	//cout<<xmax<<" "<<ymin<<endl;
	if(a>=b||xmax>=ymin||a>=ymin||b<=xmax){
		cout<<"War"<<endl;
	}
	else{
		cout<<"No War"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int cnt[27];
 
int main () {
string s;
cin>>s;
for(int i = 0; i < s.size (); i ++)
cnt[s[i] - 'a'] ++;
if (cnt[0] == 1 && cnt[1] == 1 && cnt[2] == 1) cout << "Yes";
else cout << "No";
 
}

Measured memory_bytes: 256
package main

import "fmt"

func main()  {
	var n int
	fmt.Scan(&n)
	nums := ScanNums(n)
	max := nums[0]
	count := 1
	for i := 1; i < n; i++ {
		if nums[i] >= max {
			count++
			max = nums[i]
		}
	}
	fmt.Println(count)
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>


using namespace std;

int main(void){
  int n;
  long long l[87];

  cin >> n;

  l[0] = 2;
  l[1] = 1;

  for (int i = 0; i < n-1 ;i++){
    l[i+2] = l[i] + l[i+1];
  }

  cout << l[n] << "\n";

}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;
void xxx(int A[],int n,int g)
{
	for(int i=g;i<n;i++)
	{
	int v=A[i];
	int j=i-g;
	while(j>=0 &&A[j]>v)
	{
		A[j+g]=A[j];
		j-=g;
		cnt++;
	}
	A[j+g]=v;
 } 
}
void xx(int A[],int n)
{
	for(int h=1; ;)
	{
		if(h>n)
		break;
		G.push_back(h);
		h=3*h+1;
	}
	for(int i=G.size()-1;i>=0;i--)
	
	{
		xxx(A,n,G[i]);
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	scanf("%d",&A[i]);
	cnt=0;
	xx(A,n);
	cout<<G.size()<<endl;
	for(int i=G.size()-1;i>=0;i--)
	{
		printf("%d",G[i]);
		if(i)
		printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++)
	printf("%d\n",A[i]);
	return 0;
	} 

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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  vector<long long> B(N+1);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  B.at(0)=0;
  for(int i=0; i<N; i++) B.at(i+1)=B.at(i)+A.at(i); 
  cout << endl;
  int ans=0;
  for(int i=0; i<N; i++){
    if(B.at(i)*2<A.at(i)) ans=0;
    else ans++;
  }
  cout << ans+1 << endl;
}


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

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int lcmof(int x)
{
    int gcd=__gcd(x,360);
    int mul=x*360;
    return mul/gcd;
}

int main()
 {  fast();
	int x;
	cin>>x;
	int lcm=lcmof(x);
    int res=lcm/x;
    cout<<res<<endl;

	return 0;
}

Measured memory_bytes: 3608
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>
#include <boost/dynamic_bitset.hpp>

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;


int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    boost::multi_array<bool, 2> mat(boost::extents[N][N]);
    std::fill(mat.data(), mat.data() + mat.num_elements(), false);

    for (decltype(M) i = 0; i < M; ++i) {
        int64_t a, b;
        std::cin >> a >> b;
        a--;
        b--;
        mat[a][b] = mat[b][a] = true;
    }

    boost::dynamic_bitset<> visited(N);
    auto dfs = [&visited, N, &mat](auto DFS, int64_t n) -> int
        {
            if (visited.count() == visited.size()) {
                return 1;
            }

            int ret = 0;
            for (int64_t i = 0; i < N; ++i) {
                if (visited[i]) {
                    continue;
                }
                if (!mat[n][i]) {
                    continue;
                }
                // 状態追加
                visited[i] = true;
                ret += DFS(DFS, i);
                // 状態復帰
                visited[i] = false;
            }

            return ret;
        };

    visited[0] = true;
    int ret = dfs(dfs, 0);

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> piii;

#define F first
#define S second
#define mkp make_pair
#define pb push_back
#define ppb pop_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define show(x) cerr << "# " << #x << " = " << (x) << endl
//#define int ll

const int N = 1001;

int n, a[N];

int main () {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    cout << a[n] - a[1];
    return 0;
}


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

zmax = 0
zmin = 10**10
wmax = -10**10
wmin = 10**10

for i in range(n):
    x, y = map(int, input().split())
    zref = x + y
    wref = x - y
    zmax = max(zmax, zref)
    zmin = min(zmin, zref)
    wmax = max(wmax, wref)
    wmin = min(wmin, wref)

ans = max(zmax - zmin, wmax - wmin)
print(ans)

Measured memory_bytes: 9108
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
//use std::collections::HashMap;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let x: i32 = sc.read();
    let y: i32 = sc.read();
    let z: i32 = sc.read();

    let max = std::cmp::max(x, y);
    let max = std::cmp::max(z, max);

    let min = std::cmp::min(x, y);
    let min = std::cmp::min(z, min);

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



Measured memory_bytes: 4352
#include<iostream>
#include<stdlib.h>
#include<cstring>
#include<string>

using namespace std;
struct Node
{
    int x;
    Node *l,*r,*p;
}*root,*NIL;
void Insert(Node *T,int v)
{
    Node *y=NIL;        //用来指向新加入节点的父亲节点
    Node *z=new Node();     //创建
    Node *x=T;              //搜索的指针，如果不能回到过去，那么就不要回去了，重新开始也挺好的。y指针就是一个不错的尝试。
    z->x=v;
    z->l=z->r=NIL;
    while(x!=NIL)
    {
        y=x;
        if(z->x<x->x)
            x=x->l;
        else
            x=x->r;
    }
    z->p=y;
    if(y==NIL)root=z;
    else if(z->x<y->x)y->l=z;
    else if(z->x>y->x)y->r=z;
}

void Inorder(Node *i)
{
    if(i==NIL)return ;
    Inorder(i->l);
    cout<<' '<<i->x;
    Inorder(i->r);
}

void Preorder(Node *i)
{
    if(i==NIL)return ;
    cout<<' '<<i->x;
    Preorder(i->l);
    Preorder(i->r);
}

void Print()
{
    Inorder(root);cout<<endl;
    Preorder(root);cout<<endl;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s=="insert")
        {
            int v;
            cin>>v;
            Insert(root,v);
        }
        else Print();
    }
    return 0;
}



Measured memory_bytes: 26652
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d = [abs(x[i] - y[i]) for i in range(n)]
for i in range(1,4):
    print('{0:f}'.format(sum(j ** i for j in d) ** (1 / i)))
print('{0:f}'.format(max(d)))

Measured memory_bytes: 7788
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner num = new Scanner(System.in);
        int i = 0;
        int a = 0;
        while((a = num.nextInt()) != 0) {
            i++;
            System.out.printf("Case %d: %d\n", i, a);
        }
    }
}


Measured memory_bytes: 65508
import math

INIT_VAL = pow(2, 31)-1

class SegmentTree():
    def __init__(self, n):
        self.n = n
        self.height = math.ceil(math.log2(n))
        self.nodes = [INIT_VAL for i in range(pow(2, self.height+1)-1)]
        self.leaf_start = pow(2, self.height)-1

    def update(self, i, x):
        pntr = self.leaf_start + i
        self.nodes[pntr] = x
        while True:
            pntr = (pntr-1)//2
            if pntr == -1: break
            l, r = pntr*2 + 1, pntr*2 + 2
            self.nodes[pntr] = min(self.nodes[l], self.nodes[r])

    def __query(self, s, t, k, l, r):
        if t - s <= 0: return INIT_VAL
        if r <= s or t <= l: return INIT_VAL
        if l == s and t == r: return self.nodes[k]
        else:
            m = (l+r)//2
            if t <= m:
                return self.__query(s, t, k*2+1, l, m)
            elif m <= s:
                return self.__query(s, t, k*2+2, m, r)
            else:
                vl = self.__query(s, m, k*2+1, l, m)
                vr = self.__query(m, t, k*2+2, m, r)
                return min(vl, vr)

    def find(self, s, t):
        return self.__query(s, t+1, 0, 0, pow(2, self.height))

n, q = list(map(int, input().split(' ')))
st = SegmentTree(n)
for i in range(q):
    com, x, y = list(map(int, input().split(' ')))
    if com == 0:
        st.update(x, y)
    elif com == 1:
        print(st.find(x, y))



Measured memory_bytes: 8892
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
 
    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll n;
        cin>>n;
        ll x=logint(n,10);
        if(x==1) cout<<n;
        else if(x==2) cout<<9;
        else if(x==3) cout<<n-99+9;
        else if(x==4) cout<<909;
        else if(x==5) cout<<n-9999+909;
        else cout<<90909;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int n;
char s[500010];
int dfs(int l,int r){
	while(l<r&&s[l]=='0')l++;
	while(l<r&&s[r-1]=='0')r--;
	if(r-l<3)return 0;
	for(int i=l;i+1<r;i++)if(s[i]=='0'&&s[i+1]=='0')return dfs(l,i)+dfs(i+2,r);
	int res=0,tmp;
	for(int i=l+1;i+1<r;i++)if(s[i-1]=='1'&&s[i]=='0'&&s[i+1]=='1'){
		s[i-1]='0';s[i]='1';s[i+1]='0';
		if((tmp=1+dfs(l,r))>res)res=tmp;
		s[i-1]='1';s[i]='0';s[i+1]='1';
	}
	return res;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
void cmax(int&a,int b){b>a?a=b:1;}
int a[500010],m,f[500010][3];
// 0: none
// 1: -1
// 2: +1 -1
int calc(){
	f[m][0]=f[m][1]=f[m][2]=0;
	for(int i=m;i--;){
		for(int j=0;j<2;j++){
			f[i][j]=f[i+1][j]; // 00
			if(i+1<m){
				if(a[i]-j==1||a[i+1]==1){ // 01
					cmax(f[i][j],f[i+2][0]+a[i]-j+a[i+1]-1);
					if(i+2<m&&a[i+1]>1&&a[i+2]>1)cmax(f[i][j],f[i+2][2]+a[i+1]);
				}
				else{
					cmax(f[i][j],f[i+1][2]+1); // 10
					cmax(f[i][j],f[i+1][1]+a[i]-j); // 11
				}
			}
		}
		f[i][2]=f[i][1]; // 0
		cmax(f[i][2],f[i+1][0]+a[i]-1); // 1
		if(a[i]-1>1&&a[i+1]>1)cmax(f[i][2],f[i+1][2]+a[i]-1);
	}
	return f[0][0];
}
int solve(){
	int sum=m=0;
	for(int i=0,j=0;i<n;i=j){
		while(j<n&&s[i]==s[j])j++;
		if(s[i]=='1')a[m++]=j-i;
		else if(j-i>1)sum+=calc(),m=0;
	}
	return sum+calc();
}
int main(){
	//int c=0;
	scanf("%d%s",&n,s);
	printf("%d\n",solve());
	//while(scanf("%d%s",&n,s)!=EOF){
	//	if(++c%100==0)fprintf(stderr,"c=%d\n",c);
	//	int tmp=dfs(0,n),tmp2=solve();
	//	if(tmp!=tmp2)return!printf("%s: %d %d\n",s,tmp,tmp2);
	//}
}

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

#define int long long

const int N = 18;
int n, A, B;
vector <int> ans;

void f(int mask, int v, int u) {
	if (v == u)
		return;
	if (__builtin_popcount(mask) == 1) {
		ans.push_back(v);
		ans.push_back(u);
		return;
	}
	
	int indx = 0;
	for (int i = 0; i < n; i++)
		if ((mask & (1LL << i)) && (((1LL << i) & v) != ((1LL << i) & u)))
			indx = i;
	
	int w = v;
	for (int i = 0; i < n; i++)
		if ((mask & (1LL << i)) && i != indx) {
			w ^= (1LL << i);
			break;
		}
	
	mask ^= (1LL << indx);
	f(mask, v, w);
	f(mask, w ^ (1LL << indx), u);
}

int32_t main() {
	cin >> n >> A >> B;
	if ((__builtin_popcount(A) & 1) == (__builtin_popcount(B) & 1))
		return cout << "NO", 0;
		
	f((1LL << n) - 1, A, B);
	cout << "YES\n";
	for (int i : ans)
		cout << i << ' ';
}

Measured memory_bytes: 2164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main() {
	std::string s;

	std::cin >> s;

	int ans = 0;
	int s_count = 0;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'S') s_count++;
		else {
			if (s_count == 0) {
				ans++;
			} else {
				s_count--;
			}
		}
	}

	std::cout << ans + s_count << std::endl;

	return 0;
}

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

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

    vector<string> W(N);
    for (int i = 0; i < N; i++)
    {
        cin >> W[i];
    }

    // check if the same word in a loop
    bool is_same_word = false;
    for (int i = 0; i < N - 1; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            if (W[i] == W[j])
            {
                is_same_word = true;
                break;
            }
        }
        if (is_same_word == true)
        {
            break;
        }
    }
    if (is_same_word == true)
    {
        cout << "No" << endl;
        return 0;
    }

    bool is_connected = true;
    for (int i = 0; i < N - 1; i++)
    {
        if (W[i][W[i].size() - 1] != W[i + 1][0])
        {
            is_connected = false;
            break;
        }
    }

    if (is_connected == true)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

    void yes(bool fl = true){
            if(fl) cout << "YES\n";
            else cout << "Yes\n";
    }
    void no(bool fl = true){
        if(fl) cout << "NO\n";
        else cout << "No\n";
    }  

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q;
        ll mod = 1e9 + 7;
        


        void solve(){
            cin >> n >> m;
            if(m >= n){
                cout << "unsafe";
            }else cout << "safe";
        }  
            
        int main(){
        ios_base::sync_with_stdio(false);
       
        int cases = 1;
        //cin >> cases;
    
        while(cases--){ 
            solve();
        }

        return 0;

        }

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>


int main(){
    long A,B,C,K;
    std::cin >> A >> B >> C;
    std::cin >> K;
    for(int i=0; i<K; i++){
      if(B<=A){
        B*=2;
      }else if(C<=B){
        C*=2;
      }
      if(C>B && B>A){
        std::cout << "Yes" << std::endl;
        break;
      }
      if(i==K-1){
        std::cout << "No" << std::endl;
      }
    }
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int main(){
    int N;
    cin >>N;
    ll A=0,C=0,G=0,T=0;
    vector<vl> MOJI(4,vl(4,1)),moji(4,vl(4,0)),mo(4,vl(4,0));
    vector<vl> SAFE = {
        {4,3,3,4},
        {4,4,4,4},
        {3,4,4,4},
        {4,4,4,4}
    };
    vector<vl> NG = {
        {0,0,2,1},
        {0,0,0,0},
        {0,0,0,0},
        {0,0,0,0}
    };
    rep(n,N-3){
        mo =moji;
        moji = MOJI;
        rep(i,4){
            rep(j,4){
                MOJI[i][j]=0;
                rep(k,4) MOJI[i][j]+=moji[k][i];
                MOJI[i][j] %= mod;
            }
        }
        MOJI[2][1] = (mod+MOJI[2][1]-(moji[0][2]+mo[0][2]+mo[0][3])%mod)%mod;
        MOJI[0][1] = (mod+MOJI[0][1]-moji[2][0])%mod;
        MOJI[1][2] = (MOJI[1][2]+mod-moji[0][1])%mod;
        MOJI[3][1] = (-mo[0][2]+mod+MOJI[3][1])%mod;
    }

    ll ans = 0;
    rep(i,4){
        rep(j,4){
            ans = (ans + MOJI[i][j]*SAFE[i][j]-moji[i][j]*NG[i][j])%mod;
        }
    }
    cout <<(ans+mod)%mod<<endl;
}

Measured memory_bytes: 256
# https://akhtikd.com/posts/ruby-de-union-find/
class UnionFind
    attr_accessor :parent
    
    def initialize(size)
        @parent = Array.new(size, -1)
    end

    # xが所属するグループのルートノードを返す
    def root(x)
        if @parent[x] < 0
            x
        else
            # 経路圧縮を行なう
            @parent[x] = root(@parent[x])
        end
    end

    # xとyが同じグループに属しているか判定する
    def same_parent?(x, y)
        root(x) == root(y)
    end

    # xとyが所属するグループを併合する
    def merge(x, y)
        x_root = root(x)
        y_root = root(y)

        return false if x_root == y_root

        # merge technique
        if @parent[x_root] > @parent[y_root]
            x_root, y_root = y_root, x_root
        end

        @parent[x_root] += @parent[y_root]
        @parent[y_root] = x_root

        return true
    end

    # xが所属するグループのサイズを返す
    def size(x)
        return -@parent[root(x)]
    end
end

N, M = gets.split.map &:to_i
uf = UnionFind.new(N)
M.times.map{ gets.split.map(&:to_i) }.each do |a, b|
    uf.merge(a-1, b-1)
end

p -uf.parent.min

Measured memory_bytes: 29756
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;

const int H_MAX = 1000005;
const int W_MAX = 1000005;
const int INF = 10000005;
vector<string> C;
vector<vector<int>> T;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;
    C.resize(h);
    for(int i = 0; i < h; i++){
        cin >> C[i];
    }
    T.assign(h, vector<int>(w, INF));
    T[x1][y1] = 0;
    int ans = -1;
    queue<pair<int, int>> Q;
    Q.push(make_pair(x1, y1));
    while(!Q.empty()){
        int x = Q.front().first;
        int y = Q.front().second;
        int now = T[x][y];
        if (x == x2 && y == y2){
            ans = now;
            break;
        }
        Q.pop();
        for(int i = 1; i <= k; i++){
            if (x+i >= h || C[x+i][y] == '@')break;
            if (T[x+i][y] <= now)break;
            else if (T[x+i][y] == now+1)continue;
            T[x+i][y] = now+1;
            if (x+i == x2 && y == y2){
                ans = now+1;
                break;
            }
            Q.push(make_pair(x+i, y));
        }
        for(int i = 1; i <= k; i++){
            if (x-i < 0 || C[x-i][y] == '@')break;
            if (T[x-i][y] <= now)break;
            else if (T[x-i][y] == now+1)continue;
            T[x-i][y] = now+1;
            if (x-i == x2 && y == y2){
                ans = now+1;
                break;
            }
            Q.push(make_pair(x-i, y));
        }
        for(int i = 1; i <= k; i++){
            if (y+i >= w || C[x][y+i] == '@')break;
            if (T[x][y+i] <= now)break;
            else if (T[x][y+i] == now+1)continue;
            T[x][y+i] = now+1;
            if (x == x2 && y+i == y2){
                ans = now+1;
                break;
            }
            Q.push(make_pair(x, y+i));
        }
        for(int i = 1; i <= k; i++){
            if (y-i < 0 || C[x][y-i] == '@')break;
            if (T[x][y-i] <= now)break;
            else if (T[x][y-i] == now+1)continue;
            T[x][y-i] = now+1;
            if (x == x2 && y-i == y2){
                ans = now+1;
                break;
            }
            Q.push(make_pair(x, y-i));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12080
function Main(input) {
  input = input.split("\n");
  var X = parseInt(input[0].split(" ")[0]);
  var Y = parseInt(input[0].split(" ")[1]);
  var ans ="No";
  for(var i=0;i<=X;i++){
    if((Y-2*i)/4==X-i){
      var ans ="Yes";
      break;
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29456