akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli a[200000] = {};


int main(void) {

	lli n, s = 0;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
		if (i != 0)
			a[i] += a[i - 1];
	}

	lli mini = INF;

	for (int i = 0; i < n; i++) {
		CHMIN(mini,abs(s - 2 * a[i]));
	}

	COUT(mini);


	return 0;
}


Measured memory_bytes: 1792
N,W=map(int,input().split())

DP=[[0 for j in range(W+1)]for i in range(N+1)]
v=[0]*(N+1)
w=[0]*(N+1)

for i in range(1,N+1):
    v[i],w[i]=map(int,input().split())


for i in range(1,N+1):
    for j in range(1,W+1):
        if j-w[i]<0:
            DP[i][j]=DP[i-1][j]
        else:
            if v[i]+DP[i-1][j-w[i]]>DP[i-1][j]:
                DP[i][j]=v[i]+DP[i-1][j-w[i]]
            else:
                 DP[i][j]=DP[i-1][j]
print(DP[N][W])


Measured memory_bytes: 25944
#include<iostream>
#include<string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
    int a,b,c;
    cin >> a>> b;
    c = (a+b)/2;
    if (2*c == a+b)
    {
        cout << c << endl;
    }else
    {
        cout << "IMPOSSIBLE" << endl;
    }
    


}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  private static long count(int n, long x, HashMap<Long, Long>[] cache) {
    if (n == 0) return 1L;
    if (x == 1L) return 0L;
    if (cache[n].containsKey(x)) return cache[n].get(x);
    long layers_n_1 = (1L << (n + 1)) - 3L;
    long ans = 0L;
    if (x > 2L + layers_n_1) {
      ans = 1L + count(n - 1, x - layers_n_1 - 2L, cache) + count(n - 1, layers_n_1, cache);
    } else if (x == 2L + layers_n_1) {
      ans = 1L + count(n - 1, layers_n_1, cache);
    } else {
      ans = count(n - 1, x - 1L, cache);
    }
    cache[n].put(x, ans);
    return ans;
  }
  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    long x = sc.nextLong();
    HashMap<Long, Long>[] cache = new HashMap[n + 1];
    for (int i = 0; i <= n; i++) {
      cache[i] = new HashMap<Long, Long>();
    }
    System.out.println(count(n, x, cache));
  }
}

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

for i in range(K):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        b += a // 2
        a //= 2
    else:
        if b % 2 == 1:
            b -= 1

        a += b // 2
        b //= 2

print(a, b)


Measured memory_bytes: 2940
#include<stdio.h>
#include<vector>
#include<queue>
#include<iostream>

using namespace std;

int main() {
  int numbers[10010];
  vector<int> prime_number;
  int num, sum = 0;
  for(int i = 2; i <= 10000; i++) numbers[i-2] = i;
  for(int i = 2; i <= 10000; i++) {
    int p = numbers[i-2];
    if(p != 0) {
      for(int j = i+1; j <= 10000; j++) if(numbers[j-2]%p == 0) numbers[j-2] = 0;
    }
  }
  for(int i = 2; i <= 10000; i++) {
    if(numbers[i-2] != 0) prime_number.push_back(numbers[i-2]);
  }
  while(true) {
    int ans = 0;
    sum = 0;
    scanf("%d", &num);
    if(num == 0) break;
    queue<int> q;
    int i = 0;
    do {
      if(sum < num) {
	q.push(prime_number[i]);
	sum += prime_number[i];
	i++;
      }
      else if(sum > num) {
	sum -= q.front();
	q.pop();
      }
      else {
	ans++;
	sum -= q.front();
	q.pop();
	q.push(prime_number[i]);
	sum += prime_number[i];
	i++;
      }
    }while(prime_number[i-1] <= num || i <= prime_number.size()-1);
    printf("%d\n", ans);
  }

  return 0;
}
    
	

Measured memory_bytes: 3224
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    println!(
        "{}",
        (0..n)
            .map(|_| {
                let l: i64 = read();
                let r: i64 = read();
                r - l + 1
            })
            .sum::<i64>()
    )
}

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


Measured memory_bytes: 4352
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;

signed main(){
    cin >> N;
    int ans = 0;
    rep(i, N){
        int a;
        cin >> a;
        if(i%2 == 0 && a%2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	string s;
	cin >> s;

	bool flag = true;
	Array ans;
	ll con = 0;
	ll max = 0;
	REP(i, s.size()) {
		if (flag) {
			if (s[i] == '<') {
				con++;
			}
			else {
				ans.push_back(con);
				con = 1;
				flag = false;
			}
		}
		else {
			if (s[i] == '>') {
				con++;
			}
			else {
				ans.push_back(con);
				con = 1;
				flag = true;
			}
		}
	}
	if (con > 0) ans.push_back(con);
	if (ans.size() % 2 != 0) ans.push_back(0);
	ll sum = 0;
	for (int i = 0; i < ans.size(); i += 2) {
		ll x0 = ans[i];
		ll x1 = ans[i + 1];
		if (min(x0, x1) > 0) {
			ll k = min(x0, x1);
			sum += k * (k-1) / 2;
		}
		ll k2 = 0;
		chmax(k2, x0);
		chmax(k2, x1);
		sum += k2 * (k2 + 1) / 2;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3352
n=int(input())
b=list(map(int,input().split()))
if len(b)==1:
  print (2*b[0])
else:
  ans=0
  for i in range(1,len(b)):
    ans+=min(b[i],b[i-1])
  print (ans+b[0]+b[len(b)-1])

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

int main() {
    ll W, H, X, Y; cin >> W >> H >> X >> Y;
    
    bool flg = false;
    if (X * 2 == W && Y * 2 == H) flg = true;

    cout << W * H / 2.0 << " " << flg << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
bool compare(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.second > b.second); 
}
int findmax(int arr[], int n){
	int curr_max = -1;
	for(int i=0;i<n;i++){
		curr_max = max(curr_max, arr[i]);
		}
	return curr_max;
	}
int findmin(int arr[], int n){
	int curr_max = INT_MAX;
	for(int i=0;i<n;i++){
		curr_max = min(curr_max, arr[i]);
		}
	return curr_max;
	}
bool help(int arr[], int mid, int n, int c){
	int last_pos = arr[0];
	int cows = 1;
	for(int i=1;i<n;i++){
		if(abs(arr[i]-last_pos) >= mid){
			last_pos = arr[i];
			if(++cows == c)
				return true;
			last_pos = arr[i];
		}
	}
	return false;
}
int main() 
{ 
	ll t;
	t=1;
	while(t--){
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<ll> dp(n, INT_MAX);
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=i+2;j++){
			dp[j]=min(dp[j], dp[i]+abs(a[j]-a[i]));
		}
	}
	cout<<dp[n-1]<<endl;		
	// your code goes here
	return 0;
	}
} 


Measured memory_bytes: 1792
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def search_next(l, r, SC):
    ll, lc = l
    rr, rc = r
    nexts = []
    if len(ll) > len(rr):
        part = ll[::-1]
        for s,c in SC:
            if s[-len(part):] == part:
                r_n = (s[:-len(ll)], rc + c)
                l_n = ('', lc)
                nexts.append((rc+c+lc, (l_n, r_n)))
            elif s == part[-len(s):]:
                l_n =(ll[len(s):], lc)
                r_n = ('', rc + c)
                nexts.append((rc + c + lc, (l_n, r_n)))
    else:
        part = rr[::-1]
        for s, c in SC:
            if s[:len(part)] == part:
                l_n = (s[len(rr):], lc + c)
                r_n = ('', rc)
                nexts.append((lc+rc+c, (l_n, r_n)))
            elif s == part[:len(s)]:
                r_n = (rr[:-len(s)], rc)
                l_n = ('', lc + c)
                nexts.append((lc + rc + c, (l_n, r_n)))
    return nexts

def palindrome(l, r):
    if l + r == (l+r)[::-1]:
        return True
    else:
        return False



def run():
    totalL = 0
    N = int(sysread())
    SC = []
    for i in range(N):
        s,c = input().split()
        c = int(c)
        SC.append((s,c))
        totalL += len(s)

    min_val = INF
    for s,c in SC:
        queue = []
        left = (s, c)
        right = ('', 0)
        heappush(queue, (c, (left, right)))
        done = False
        count = 0
        while queue:
            count += 1
            if count > 200000:break
            #print(queue)
            cost, (l, r) = heappop(queue)
            if palindrome(l[0], r[0]):
                done = True
                #print(l, r)
                break
            nexts = search_next(l, r, SC)
            for n in nexts:
                heappush(queue, n)
        if done:
            min_val = min(min_val, cost)
    if min_val == INF:
        print(-1)
    else:
        print(min_val)

if __name__ == "__main__":
    run()

Measured memory_bytes: 9760
#include <cstdio>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <array>

using namespace std;

int main() {
	
	int N;
	vector<int> H;
	int l;
	int m = 0;
	int ans = 0;
	
	// 入力
	scanf("%d", &N);
	for(int i = 0; i<N; i++){
		scanf("%d", &l);
		H.push_back(l);
	}
	
	for(int i=0; i<N; i++){
		if(m <= H[i]){
			ans++;
			m = H[i];
		}
	}
	
	// 出力
	printf("%d\n", ans);
	
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n, vector<int>());
  rep(i, m) {
    int a, b; cin >> a >> b; a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  vector<int> s(n, INF);
  s[0] = 0;
  queue<int> q;
  q.push(0);

  while (!q.empty()) {
    int x = q.front(); q.pop();
    for (auto& v : to[x]) {
      if (s[v] != INF) continue;
      s[v] = x;
      q.push(v);
    }
  }

  if (EXIST(s, INF)) {
    puts("No");
    return 0;
  }

  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << s[i] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 10304
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <fstream>
#include <cstring>

using namespace std;
#define int long long

signed main()
{
	string s;
	cin >> s;
	int a, b;
	bool a1=0, b1=0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'A'&&a1==false) {
			a = i;
			a1 = true;
		}
		if (s[i] == 'Z') b = i;
		
	}
	cout << b-a+1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int NUM = 2e5 + 5;

int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        int a,b,c; cin>>a>>b>>c;
        cout<<c-(min(a,b+c)-b);
    }   
}


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

int max_a(vector <int>V){
  int m;
  m=V[0];
  for(int i;i<V.size();i++){
    m=max(m,V[i]);
  }
  return m;
}

int min_a(vector <int>V){
  int m;
  m=V[0];
  for(int i;i<V.size();i++){
    m=min(m,V[i]);
  }
  return m;
}



int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0;i<N;i++){
    cin >> A[i];
  }
  cout<<max_a(A)-min_a(A)<< endl;
}


Measured memory_bytes: 256
#include <stdio.h>

main(){
 
  int i,n;
  int f[100];
  
  scanf("%d",&n);
  f[0]=1;
  f[1]=1;
 
  for(i = 2;i <= n;i++){
    f[i]=f[i-1]+f[i-2];
  }
  printf("%d\n",f[n]);
  return 0;
}

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

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = int;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

map<string, int> replacement {
    {"SSS", 0}, {"SSR", 1}, {"SRS", 1}, {"SRR", 2}, {"RSS", 1}, {"RRS", 2}, {"RSR", 1}, {"RRR", 3}
};

int main(int argc, char *argv[])
{
    
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;
    
    cin >> S;
    cout << replacement[S] << endl;
    
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);
    ll need = x / d;
    if (need > k) {
        cout << x - d * k << '\n';
    } else {
        k -= need;
        x -= need * d;
        if (k & 1) x = abs(x - d);
        cout << x << '\n';
    }
    return 0;
}


Measured memory_bytes: 3688
#include<stdio.h>
int main()
{
	int H, W, i, j, a, b;

	while(1)
	{
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0)break;
	
		for(i=0; i<H; i++)
		{
			for(j=0; j<W; j++)
			{
				a = i % 2;
				b = j % 2;
				if((a == 0 && b == 0) || (a != 0 && b != 0))
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
		
			printf("\n");
		}
		printf("\n");
		
	}

	return 0;
}

Measured memory_bytes: 572
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned char uchar;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

vector<ull> data;

void make(ull mask, int rem, int p)
{
    if(rem == 0){
        data.push_back(mask);
        return;
    }
    
    if(p >= 2){
        make(mask, rem, p-1);
    }
    if(p <= rem){
        reinterpret_cast<uchar*>(&mask)[p-1]++;
        make(mask, rem-p, p);
    }
}

bool ok(ull a, ull b)
{
    uchar* p = reinterpret_cast<uchar*>(&a);
    uchar* q = reinterpret_cast<uchar*>(&b);
    
    rep(i, 8){
        if(p[i] < q[i]) return false;
    }
    
    return true;
}

unordered_map<ull, int> memo;
int func(ull mask)
{
    if(memo.count(mask)) return memo[mask];
    
    int ans = 0;
    for(ull d : data){
        if(ok(mask, d)){
            ans = max(ans, func(mask - d) + 1);
        }
    }
    
    return memo[mask] = ans;
}

void func(int n)
{
    int hist[10] = {};
    rep(i, n){
        int a;
        cin >> a;
        hist[a]++;
    }
    
    int ans = hist[5] / 2;
    hist[5] %= 2;
    reps(i, 1, 5){
        int v = min(hist[i], hist[10-i]);
        ans += v;
        hist[i] -= v;
        hist[10-i] -= v;
    }
    
    ull mask = 0;
    rep(i, 8){
        reinterpret_cast<uchar*>(&mask)[i] = hist[i+1];
    }
    ans += func(mask);
    
    cout << ans << endl;
}


int main()
{
    make(0, 10, 8);
    
    int n;
    while(cin >> n, n){
        func(n);
    }
}

Measured memory_bytes: 8104
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int n;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= 9; ++i)
    for (int j = 1; j <= 9; ++j)
        if (i * j == n) return cout << "Yes\n", 0;
    cout << "No\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s, t;
	cin >> s >> t;

	t += s;
	cout << t << "\n";

}


Measured memory_bytes: 384
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int32_t N;
std::set<int64_t> sA;
int64_t num[100000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> num[i];
		sA.insert((num[i]<<32)|i);
	}
	{
		auto iter = sA.begin();
		for (int32_t i = 0; i < N; ++i)
		{
			num[(*iter)& 0xffffffff] = i;
			++iter;
		}
	}

	int64_t count = 0;
	for (int32_t i = 0; i < N; ++i)
	{
		count += std::abs(i - num[i]) & 1;
	}
	out << (count >> 1) + (count & 1) << endl;

	return 0;
}
#endif


Measured memory_bytes: 6264
s = input()
t = input()
sd = {}
td = {}
for i in range(len(s)):
    if s[i] in sd:
        if sd[s[i]] != t[i]:
            print("No")
            exit()
    else:
        sd[s[i]] = t[i]
for i in range(len(t)):
    if t[i] in td:
        if td[t[i]] != s[i]:
            print("No")
            exit()
    else:
        td[t[i]] = s[i]
print("Yes")

Measured memory_bytes: 3632
import sys
import heapq


input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, M = map(int, input().split())
    adj = [[] for _ in range(N)]

    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        adj[a].append(b)
        adj[b].append(a)

    # print(adj)

    INF = 10 ** 18
    WHITE = 0
    GRAY = 1
    BLACK = 2

    def dijkstra(s):
        color = [WHITE] * N
        d = [INF] * N
        p = [-1] * N
        d[s] = 0
        PQ = []
        heapq.heappush(PQ, (0, s))  # (距離, 頂点の番号)
        color[s] = GRAY

        while PQ:
            distance, u = heapq.heappop(PQ)
            color[u] = BLACK

            if d[u] < distance:
                continue
            # print(u)

            for j in range(len(adj[u])):
                v = adj[u][j]
                if color[v] == BLACK:
                    continue
                if d[v] > d[u] + 1:
                    d[v] = d[u] + 1
                    p[v] = u
                    heapq.heappush(PQ, (d[v], v))
                    color[v] = GRAY

        return d, p

    d, p = dijkstra(0)
    # print(d, p)
    if INF in d[1:]:
        print("No")
        sys.exit()
    else:
        print("Yes")
        for i in range(1, N):
            print(p[i] + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 39640
import math
X=int(input())
max_num = 0
for i in range(2,10):
  tei = math.floor(X**(1/i))
  if (tei+1)**i <= X: tei = tei + 1
  if max_num < tei**i:
    max_num = tei**i
print(max_num)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 50;
int main(){
	ll n;
	cin >> n;
	string str = "";
	while(n){
		int a = (n-1)%26;
		n--;
		n/=26;
		char c = 'a' + a;
		str = c + str;
	}
	cout << str << endl;
	return 0;
}

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

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

    int H;
    cin >> H;
    vector<int> V(H);
    for (int i = 0; i < H; i++) cin >> V[i];
    for (int i = 1; i <= H; i++) {
        cout << "node " << i << ": " << "key = " << V[i - 1] << ", ";
        if (i != 1)
            cout << "parent key = " << V[i/2 - 1] << ", ";
        if (2 * i - 1< H)
            cout << "left key = " << V[2 * i - 1] << ", ";
        if (2 * i < H)
            cout << "right key = " << V[2 * i] << ", ";
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3148
import sys
N = int(input())
A = sorted(list(map(int,input().split())))

mn = A[0]
mx = A[-1]
if N ==2:
    print(A[1] - A[0])
    print(A[1],A[0])
    sys.exit()
ope = []
for a in A[1:-1]:
    if a <=0:
        ope.append([mx, a])
        mx -= a
    else:
        ope.append([mn, a])
        mn -= a
ope.append([mx,mn])
print(mx-mn)
for o in ope:
    print(o[0],o[1])

Measured memory_bytes: 23236
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long cnt = 0, n;
	cin >> n;
	for(int i=1; i<=n; i++)
		if(i % 3 != 0 && i % 5 != 0)
			cnt += i;
	cout << cnt << endl;
	return 0; 
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };

int n, w;
const int M_W = 1001;
const int M_N = 1001;
P dp[M_N][M_W];
PArray arr;

P dfs(int idx, int weight)
{
	if(idx == n) return P(0, weight);
	if(dp[idx][weight] != P()) return dp[idx][weight];

	P v1 = P(-1, weight + arr[idx].second);
	if(v1.second <= w)
	{
		P ret = dfs(idx + 1, weight + arr[idx].second);
		v1.first = ret.first + arr[idx].first;
		v1.second = ret.second;
	}
	P v2 = dfs(idx + 1, weight);
	P ans;
	if(v1.first == v2.first)
	{
		ans.first = v1.first;
		ans.second = min(v1.second, v2.second);
	}
	else ans = max(v1, v2);
	return dp[idx][weight] = ans;
}

int main(void)
{
	ios::sync_with_stdio(false);
	int counter = 0;
	while(cin >> w && w)
	{
		counter++;
		cin >> n;
		arr.resize(n);
		char c;
		for (int i = 0; i < n; i++)
		{
			cin >> arr[i].first >> c >> arr[i].second;
		}
		memset(dp, 0, sizeof(dp));
		P ans = dfs(0, 0);
		
		cout << "Case " << counter << ":" << endl;
		cout << ans.first << endl;
		cout << ans.second << endl;
	}
	return 0;
}

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std ; 
#define ll              long long int
// #define cini(x)	        scanf("%lld",&x)
// #define cins(s)	        scanf("%s",s)
#define deb(x)          cout << (x) << "  " ;
#define out(x)          cout << (x) << endl ;
#define endl            '\n'
#define pb              push_back
#define mk              make_pair
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(x,n,v)     for(ll v=x; v<n; v++)
#define loopr(n,x,v)     for(ll v=n-1; v>=x; v--)
#define mod             1000000007
#define all(x)          x.begin(), x.end()
#define clr(x)          memset(x, 0, sizeof(x))
#define sortall(x)      sort(all(x))
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define PI              3.1415926535897932384626
#define setbits(x)      __builtin_popcount(x)
#define zrobits(x)      __builtin_ctz(x)
#define ps(x,y)         fixed << setprecision(y) << (x)
#define w(t)            int t; cin>>t; while(t--) 
#define     vi          vector<ll>
#define     vtt         vector<pair<ll,ll>> 
#define     pii         pair<ll,ll> 
#define  mapp           map<ll,ll> 
#define  sett           set<ll>
int dp[1000][1000] ;
ll mpow(ll base, ll exp); 
// =================================
// =================================

vector<ll> vec[100002];
ll arr[100002];
ll brr[100002];
ll dfs(ll i, ll cnt){
    if(arr[i] != -1)  return brr[i];
    arr[i]=0;
    // ll ans=1;
    for(auto itt : vec[i]){
        // if(arr[itt]){
            brr[i] = max( brr[i], 1+dfs(itt,cnt) );
            // arr[i]=1;
        // }
    }
    return  brr[i];
}

int main(){
    fastio ;
    // w(t)
    // {
        ll a=0, b=0, c=0, d=0, e=0, p=0, q=0, r=0 ;
        ll ans=0, res=0, cnt=0, sum=0, diff=0, mul=1, val=0, k=0 ;
        // loop(0,n,i) brr[i]=0;
        // char s[100005];
        string s ;
        ll n,m ;
        cin >> n ;
        cin >> m ;
        // clr(arr);
        // clr(brr);
        loop(0,n+1,i) arr[i]=-1;
        loop(0,n+1,i) brr[i]=0;
        vi vecc;
        c=m;
        while(c--){
            cin >> a >> b ;
            vec[--a].pb(--b);
            vecc.pb(a);
        }
        for(auto it : vecc){
            cnt = dfs(it,1);
            ans=max(ans,cnt);
        }
        out(ans)
    return 0 ;
}

// g++ x.cpp -o as && ./as

Measured memory_bytes: 13368
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector <char> v;

int main()
{
    int n, j = 0;
    cin >> n;

    string s1, s2;
    cin >> s1 >> s2;

    for(int i = 0; i < n; i++)
        v.push_back(s1[i]);

    for(int i = 0; ; )
    {
        if(i >= n)
        {
            for(; j < n; j++)
                v.push_back(s2[j]);
            break;
        }
        //cout << s1[i] << " " << s2[j] << endl;
        if(s1[i] == s2[j])
        {
            j++;
            for(i = i + 1; i < n; i++)
            {
                if(s1[i] != s2[j])
                {
                    //cout << i << "              " << j << endl;
                    j = 0;
                    break;
                }
                else
                {
                    j++;
                    //cout << i << " " << j << endl;
                }
            }
            //cout << i << "      " << j << endl;
        }
        else
            i++;

    }

    cout << v.size() << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[110][100100] = {0};
int weight[110],value[110];

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

signed main(){
    int n,w;
    cin >> n >> w;
    for(int i = 0; i < n; i++){
        cin >> weight[i] >> value[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= w; j++){
            if(j - weight[i] >= 0){
                chmax(dp[i + 1][j],dp[i][j - weight[i]] + value[i]);
            }
            
                chmax(dp[i + 1][j],dp[i][j]);
            
        }
    }
    cout << dp[n][w] << endl;
}


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

using namespace std;
typedef long long ll;

int main() {
    int H, W, K;
    const int mod = 1e9 + 7;
    cin >> H >> W >> K;

    vector<vector<ll>> c(3, vector<ll>(W));
    for (int i = 0; i < 1 << (W - 1); i++) {
        if (i & (i >> 1)) continue;
        for (int j = 0; j < W; j++) {
            if (i >> j & 1) {
                c[2][j]++;
            } else if (j >= 1 && i >> (j - 1) & 1) {
                c[0][j]++;
            } else {
                c[1][j]++;
            }
        }
    }

    vector<vector<ll>> dp(H + 1, vector<ll>(W));
    dp[0][0] = 1;
    for (int i = 1; i <= H; i++) {
        for (int j = 0; j < W; j++) {
            for (int k = 0; k < 3; k++) {
                if (j + k - 1 < 0 || j + k - 1 >= W) continue;
                dp[i][j] += c[k][j] * dp[i - 1][j + k - 1];
                dp[i][j] %= mod;
            }
        }
    }
    
    cout << dp[H][K - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
#define mod 1000000007
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
unordered_set<int> adj[200002];
bool visited[200002];
int step=0;
void dfs(int u) {
    visited[u] = true;
    step++;
    for(int v : adj[u])
        if(!visited[v])
            dfs(v);
}
int main(){
    int nodes, edges, u, v;
    cin >> nodes >> edges;
    for(int i = 0; i < edges; i++) {
        cin >> u >> v;
        --u, --v;       //there is an undirected edge between u and v (0 based)
        adj[u].insert(v);
adj[v].insert(u);
}
int ans=0;
for(int i=0;i<nodes;i++){
    if(!visited[i]){
     step=0;
        dfs(i);
        ans=max(ans,step);
    }
}
cout<<ans;
return 0;
}


Measured memory_bytes: 39644
h,w,k = map(int,input().split())
c = [list(input()) for _ in range(h)]

cnt=0
for i in range(2**h):
  for j in range(2**w):
    black=0
    for hh in range(h):
      if bin((i>>hh)&0b1)==bin(1):
        continue
      for ww in range(w):
        if bin((j>>ww)&0b1)==bin(1):
          continue
        if c[hh][ww]=="#":
          black+=1
    if black==k:
        cnt+=1
print(cnt)



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

int main(){
  int n,l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  sort(s.begin(),s.end());
  string ans="";
  for(int i=0;i<n;i++){
    ans+=s[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define all(a) begin(a),end(a)
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << " = " << a << ENDL;
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;

lli MOD = 1e9 + 7;
const int MAX = 5e5 + 5;
lli fact[MAX];

void makeFact() {
    fact[0] = 1;
    fact[1] = 1;
    fore(i, 2, MAX) {
        fact[i] = (i * fact[i - 1]) % MOD;
    }
}

lli modpow(lli u, lli v) {
    if(v == 0) return 1;
    if(v == 1) return u;
    lli x = modpow(u, (v - v%2) / 2);
    x = (x * x) % MOD;
    if(v%2) x = (x * u) % MOD;
    return x;
}

lli inv(lli u) {
    return modpow(u, MOD - 2);
}

lli ncr(lli u, lli v) {
    return fact[u] * ( (inv(fact[v]) * inv(fact[u - v])) % MOD) % MOD;
}

int main()
{   _
    makeFact();
    lli n, m; cin >> n >> m;
    lli base = (fact[m] * inv(fact[m - n])) % MOD;
    lli cur = (base * base) % MOD;
    for(int i = 1; i <= n; ++i) {
        lli acomodos = (fact[m - i] * inv(fact[m - n])) % MOD;
        acomodos = (acomodos * ( (fact[m] * inv(fact[m - n])) % MOD))  % MOD;
        lli arreglos = ncr(n, i);
        //arreglos = (arreglos * arreglos) % MOD;
        //arreglos = (arreglos * 2) %  MOD;
        lli current = (acomodos * arreglos) % MOD;
        //cout << i << ' ' << current << ENDL;
        if(i % 2) {
            cur = (MOD + cur - current) % MOD;
        }
        else cur = (cur + current) % MOD;
    }
    cout << cur << ENDL;
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll sum = 15;
    for(i = 0;i < 5;++i){
        ll x;
        cin >> x;
        sum -= x;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 1e5 + 5;
vector<int> edges[nax];

const int mod = 1e9 + 7;
int mul(int a, int b) {
    return (ll) a * b % mod;
}

// returns a pair {black, white}
pair<int,int> dfs(int a, int parent) {
    int all_white = 1; // means: my vertex can be painted black
    int sth_is_black = 0;
    for(int b : edges[a]) {
        if(b != parent) {
            pair<int,int> p = dfs(b, a);
            // p.first is the number of ways to color the subtree
            // such that 'b' is black
            int memo_all_white = all_white;
            all_white = mul(all_white, p.second);
            sth_is_black = (mul(memo_all_white, p.first)
                + mul(sth_is_black, p.first + p.second)) % mod;
        }
    }
    return make_pair(all_white, (all_white + sth_is_black) % mod);
}

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n - 1; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    pair<int,int> p = dfs(1, -1);
    int answer = (p.first + p.second) % mod;
    printf("%d\n", answer);
}


Measured memory_bytes: 12672
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W, M = LI()
    hw = {tuple(LI()) for _ in range(M)}

    cnt_h = collections.Counter([h for h, w in hw])
    cnt_w = collections.Counter([w for h, w in hw])

    max_h = max(cnt_h.values())
    max_w = max(cnt_w.values())
    max_h_k = [k for k, v in cnt_h.items() if v == max_h]
    max_w_k = [k for k, v in cnt_w.items() if v == max_w]

    # 縦横のターゲット数最大の座標に置く
    # そのような座標がターゲット上ならば、縦横ターゲット数から1を引く
    is_on_target = True
    for i, j in itertools.product(max_h_k, max_w_k):
        if (i, j) not in hw:
            is_on_target = False
            break

    if is_on_target:
        ans = max_h + max_w - 1
    else:
        ans = max_h + max_w
    print(ans)

if __name__ == '__main__':
    resolve()


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

// #define DEBUG
#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; for(int i = 0; i < (int) v.size(); i++) o << v[i] << (i != (int)v.size()-1 ? ", " : ""); o << "}";  return o; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
#else
#define dump(...)
#endif

int dy[] = {1, 0, -1, 0};
int dx[] = {0, -1, 0, 1};

ll period;
vector< vector<int> > tmp, f;

ll BFS(vector< vector<int> > &used, int y0, int y1, int h) {
  ll cnt = 0;
  for(ll y = y0; y < y1; y++) {
    for(ll x = 0; x < 7; x++) {
      if(f[y][x]) continue;
      if(used[y][x]) continue;
      // if(connect != -1 ? f[connect][x] : false) continue;
      used[y][x] = 1;
      queue<pair<ll, ll>> q;
      q.emplace(y, x);
      cnt++;
      while(q.size()) {
        ll yy = q.front().first, xx = q.front().second;
        q.pop();
        for(int d = 0; d < 4; d++) {
          ll ny = yy + dy[d];
          ll nx = xx + dx[d];
          if(ny < 0 || h <= ny || nx < 0 || 7 <= nx) continue;
          if(f[ny][nx]) continue;
          if(used[ny][nx]) continue;
          used[ny][nx] = 1;
          q.emplace(ny, nx);
        }
      }
    }
  }
  return cnt;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  ll n, m, q; cin >> n >> m >> q;
  ll h = (m + 6) / 7; // one shared block
  period = h * 7 - (7 - m % 7) % 7; // height of period
  if(period % 7 == 0) period /= 7; // 一応これで最小単位の最大値になるはず
  ll full = n / period;
  ll rest = n - full * period;
  tmp = vector< vector<int> >(period * 3, vector<int>(7) );
  f = tmp;

  while(q--) {
    ll a; cin >> a;
    for(; a < period * 7; a += m) {
      ll y = a / 7, x = a % 7;
      f[y][x] = 1;
      f[y + period][x] = 1;
      f[y + period * 2][x] = 1;
    }
  }

  auto used = tmp;
  ll b2 = BFS(used, 0, period, period * 3);
  ll b4 = BFS(used, period, period * 2, period * 3);
  auto used2 = tmp;
  BFS(used2, 0, period, period * 2 + rest);
  ll b3 = BFS(used2, period, period * 2 + rest, period * 2 + rest);
  auto used3 = tmp;
  ll b1 = BFS(used3, 0, period + rest, period + rest);
  auto used4 = tmp;
  ll b5 = BFS(used4, 0, rest, rest);

  ll ans = 0;
  
  if(full == 0) {
    ans = b5;
  } else if(full == 1) {
    ans = b1;
  } else {
    ans = b2 + b3 + (full - 2) * b4;
  }
  cout << ans << endl;
}


Measured memory_bytes: 126848
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
char a[104],b[104]; 
int main() {
	scanf("%d",&n);
	scanf("%s%s",a+1,b+1);
	for (int i=1;i<=(n<<1);++i)
		printf("%c",(i&1)?a[(i>>1)+1]:b[i>>1]);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define min(a, b) (a < b ? a : b)

int main()
{
  int a, b, c, x;
  scanf("%d %d %d %d", &a, &b, &c, &x);
  int ans = 0;
  for (int i = 0; i <= min(a, x / 500); i++)
  {
    for (int j = 0; j <= min(b, (x - 500 * i) / 100); j++)
    {
      if ((x - 500 * i - 100 * j) / 50 <= c)
        ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        long ans = 0;
        int[] A = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = NextInt();
        }
        for (int i = 1; i < N; i++)
        {
            if (A[i] + A[i - 1] >= 2)
            {
                int B = A[i] + A[i - 1];
                ans += B / 2;
                A[i - 1] = 0;
                A[i] = B % 2;
            }
        }
        Console.WriteLine(ans + A[0]/2);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 17464
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")
}

fn main() {
    let n = read();
    println!(
        "{}",
        (0..n)
            .map(|_| read::<u32>().trailing_zeros())
            .min()
            .unwrap()
    );
}

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

string J(string s, int len) {
  return s.substr(1) + s[0];
}

string C(string s, int len) {
  return s[len-1] + s.substr(0,len-1);
}

string E(string s, int len) {
  if (len % 2 == 1) {
    return s.substr(len/2+1) + s[len/2] + s.substr(0, len/2);
  } else {
    return s.substr(len/2) + s.substr(0, len/2);
  }
}

string A(string s, int len) {
  reverse(s.begin(), s.end());
  return s;
}

string P(string s, int len) {
  for (int i = 0; i < len; i++) {
    if (!isdigit(s[i])) continue;
    if (s[i] == '9') s[i] = '0';
    else s[i]++;
  }
  return s;
}

string M(string s, int len) {
  for (int i = 0; i < len; i++) {
    if (!isdigit(s[i])) continue;
    if (s[i] == '0') s[i] = '9';
    else s[i]--;
  }
  return s;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string messengers, crypt;
    cin >> messengers >> crypt;
    int len = crypt.length();
    reverse(messengers.begin(), messengers.end());
    for (char m : messengers) {
      if (m == 'J') {
        crypt = C(crypt, len);
      } else if (m == 'C') {
        crypt = J(crypt, len);
      } else if (m == 'E') {
        crypt = E(crypt, len);
      } else if (m == 'A') {
        crypt = A(crypt, len);
      } else if (m == 'P') {
        crypt = M(crypt, len);
      } else if (m == 'M') {
        crypt = P(crypt, len);
      }
    }
    cout << crypt << endl;
  }
}

Measured memory_bytes: 1208