akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

struct game{
	int i;
	vector<int> point;
	game() : i(0){}
	game(int i) : i(i){}
	bool strike(){ return point[0] == 10;}
	bool spare(){ return point[0] + point[1] == 10;}
	bool fill(){ return strike() || sz(point) == 2;}
	int sum(){ return accumulate(point.begin(),point.end(),0); }
};

bool CMP(const Pii& l,const Pii &r){ return l.second == r.second ? l.first < r.first : l.second > r.second; }

int main(){
	int n;
	while(cin>>n,n){
		vector<Pii> out;
		FOR(i,n){
			int id; cin>>id;
			string line; getline(cin,line);
			istringstream iss(line);
			vector<game> g(1);
			vector<int> v;
			int a; 
			while(iss>>a){
				v.push_back(a);
				g.back().point.push_back(a);
				if(sz(g) != 10 && g.back().fill())
					g.push_back(game(sz(v)));
			}

			int ans = 0;
			FOR(i,9){
				ans += g[i].sum();
				if(g[i].strike()){
					int c = g[i].i;
					ans += v[c+1] + v[c+2];
				} else if(g[i].spare()){
					ans += v[g[i].i+2];
				}
			}
			ans += g[9].sum();
			out.push_back(Pii(id,ans));
		}
		sort(out.begin(),out.end(),CMP);
		FOR(i,sz(out)){
			printf("%d %d\n",out[i].first,out[i].second);
		}
	}


	return 0;
}

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

int n;
char s[100010];

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for (int i = 1; i <= n; ++i) s[i] -= '0';
	if (!s[1] || s[n]) {
		puts("-1");
		return 0;
	}
	for (int i = 1; i <= n >> 1; ++i)
		if (s[i] != s[n - i]) {
			puts("-1");
			return 0;
		}
	int j = 1;
	for (int i = 2; i <= n >> 1; ++i)
		if (s[i])
			for (; j < i; ++j)
				printf("%d %d\n", i, j);
	for (; j < n; ++j)
		printf("%d %d\n", j, n);
	return 0;
}


Measured memory_bytes: 3896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<int> a(n);
    int S = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        S += a[i];
    }
    int ans = 0;
    if(S % n == 0){
        S /= n;
        for(int i = 0; i < n; ++i)  ans += (a[i] - S) * (a[i] - S);
    }
    else{
        int foo = S / n;
        for(int i = 0; i < n; ++i)  ans += (a[i] - foo) * (a[i] - foo);
        --foo;
        int sum = 0;
        for(int i = 0; i < n; ++i)  sum += (a[i] - foo) * (a[i] - foo);
        chmin(ans, sum);
        foo += 2;
        sum = 0;
        for(int i = 0; i < n; ++i)  sum += (a[i] - foo) * (a[i] - foo);
        chmin(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main()
{
    char s[100];
    int n, AC = 0, WA = 0, TLE = 0, RE = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%s", s);
        if (strcmp(s, "AC") == 0)
        {
            AC += 1;
        }
        else if (strcmp(s, "WA") == 0)
        {
            WA += 1;
        }
        else if (strcmp(s, "TLE") == 0)
        {
            TLE += 1;
        }
        else
        {
            RE += 1;
        }
    }
    printf("AC x %d\n", AC);
    printf("WA x %d\n", WA);
    printf("TLE x %d\n", TLE);
    printf("RE x %d\n", RE);
    return 0;
}

Measured memory_bytes: 1712
var
	n,k,a,b:qword;
begin
	readln(n,k);
	a:=n div k;
	if k mod 2=0 then 
	begin 
		b:=n div (k div 2)-a;
		writeln(a*a*a+b*b*b);
	end
	else writeln(a*a*a);
end.


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef pair<double, int> PD;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll q, h, s, d;
    ll n;
    priority_queue<PD, vector<PD>, greater<PD>> pq;
    cin >> q >> h >> s >> d >> n;
    ll temp_hash[9] = {};
    temp_hash[1] = q;
    temp_hash[2] = h;
    temp_hash[4] = s;
    temp_hash[8] = d;
    n *= 4;
    pq.push(make_pair((double)q / 1, 1));
    pq.push(make_pair((double)h / 2, 2));
    pq.push(make_pair((double)s / 4, 4));
    pq.push(make_pair((double)d / 8, 8));

    PL dn, sn, hn, qn;
    dn.first = n / pq.top().second;
    dn.second = pq.top().second; pq.pop();
    sn.first = (n - dn.first * dn.second) / pq.top().second;
    sn.second = pq.top().second; pq.pop();
    hn.first = (n - dn.first * dn.second - sn.first * sn.second) / pq.top().second;
    hn.second = pq.top().second; pq.pop();
    qn.first = (n - dn.first * dn.second - sn.first * sn.second - hn.first * hn.second) / pq.top().second;

    cout <<  (dn.first * temp_hash[dn.second]
            + sn.first * temp_hash[sn.second]
            + hn.first * temp_hash[hn.second]
            + qn.first * temp_hash[qn.second]) << "\n";
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  long ans = 1;
  for (auto a : A) {
    if ((long double) ans * a > 1e18) return cout << -1 << "\n", 0;
    ans *= a;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 4044
/*
**   Contest : Educational DP Contest
**   Problem : H - Grid 1
**
**    Author : Dhiraj Govindvira
**      Date : 05-Jun-2020 ~ Friday
**      Time : 03:46:16 PM
*/

#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename T> 
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U> 
inline void inp(T &a, U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

const ll Mod = 1e9 + 7;
inline ll md(ll x, ll M = Mod)
{
    x %= M;
    return ((x < 0) ? (x + M) : x);
}

void solve(ll &T)
{
    ll n, m;
    cin>>n>>m;

    vector<string> a(n);
    cin>>a;

    ll dp[n+1][m+1];
    memset(dp, 0, sizeof(dp));
    
    loop(i,0,m) {
        if(a[0][i] == '.') {
            dp[0][i] = 1;
        }
        else break;
    }
    loop(i,0,n) {
        if(a[i][0] == '.') {
            dp[i][0] = 1;
        }
        else break;
    }

    loop(i,1,n)
    {
        loop(j,1,m)
        {
            dp[i][j] = 0;
            if(a[i][j] == '#') continue;

            if(a[i-1][j] == '.') {
                dp[i][j] = md(dp[i-1][j] + dp[i][j]);
            }
            if(a[i][j-1] == '.') {
                dp[i][j] = md(dp[i][j-1] + dp[i][j]);
            }
        }
    }
    cout<<dp[n-1][m-1]<<endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

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

    int t = 1;
    loop(Case,1,t+1)
    {
        cerr<<"Case #"<<Case<<'\n';
        solve(Case);
    }
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x,long long y);


int main(){
    long long x,y,ans,i;
        cin>>x>>y;
        ans=gcd(x,y);
        cout<<ans<<endl;
    return(0);
}

long long gcd(long long x,long long y){
        while(y!=0){
            long long r=x%y;
            x=y;
            y=r;
        }
        return x;
    }




Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int h,w,d;
    cin >> h >> w >> d;
    int a[h][w];
    vector<pair<int,int>> p(h*w); 
    rep(i,h)rep(j,w){
        cin >> a[i][j];
        a[i][j]--;
        p[a[i][j]] = make_pair(i,j);
    }
    vector<vector<int>> k(d);
    for(int i=0;i<d;i++){
        int j = i,cur=0;
        while(j+d<h*w){
            cur += abs(p[j+d].first-p[j].first)+abs(p[j+d].second-p[j].second);
            k[i].push_back(cur);
            j += d;
        }
    }
    int q;
    cin >> q;
    rep(i,q){
        int b,c;
        cin >> b >> c;
        b--;c--;
        int t = b%d;
        if(b==c) cout << 0 << endl;
        else cout << k[t][(c-t)/d-1]-k[t][(b-t)/d-1] << endl;
    }
}

Measured memory_bytes: 6348
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    // 数値
    let n = {
        let i = read::<isize>();
        (i[0])
    };
    let an = read::<isize>();

    let mut sum = 0;

    for ai in an {
        sum = sum + ai;
    }

    sum = sum - n;

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    ll D, T, S;
    cin >> D >> T >> S;
    if(D%S==0){
        if(D/S <= T) out("Yes");
        else out("No");
    } else {
        if((double)D/S <= T) out("Yes");
        else out("No");
    }
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> scoreArrays = new ArrayList<String>();
		while (true) {
			String strTensu = br.readLine();
			if ("-1 -1 -1".equals(strTensu)) {
				break;
			}
			String[] strTensuArrays = strTensu.split(" ");
			Integer totalScore = Integer.parseInt(strTensuArrays[0]) + Integer.parseInt(strTensuArrays[1]);
			if (!"-1".equals(strTensuArrays[0]) && !"-1".equals(strTensuArrays[1])) {
				if (80 <= totalScore) {
					scoreArrays.add("A");
				} else if (totalScore < 80 && 65 <= totalScore ) {
					scoreArrays.add("B");
				} else if (totalScore < 65 && 50 <= totalScore ) {
					scoreArrays.add("C");
				} else if (totalScore < 50 && 30 <= totalScore ) {
					if (50 <= Integer.parseInt(strTensuArrays[2])) {
						scoreArrays.add("C");
					} else {
						scoreArrays.add("D");
					}
				} else {
					scoreArrays.add("F");
				} 
			} else {
				scoreArrays.add("F");
			}
		}
		for (int i = 0; i < scoreArrays.size(); i++) {
			System.out.println(scoreArrays.get(i));
		}
	}

}

Measured memory_bytes: 16940
#include <stdio.h>
int board[100][100];
int main()
{
	int H,W,N; 
	int board[100][100];
	scanf("%d%d%d",&H,&W,&N);
	int color[N];
	for(int i=0;i<N;i++)
	{
		scanf("%d",&color[i]);
	}
//	printf("\nH=%d W=%d N=%d\n",H,W,N);
//	for(int i=0;i<N;i++)
//	{
//		printf("color[%d]=%d\n",i,color[i]);
//	}
	int lie=0;
	int hang=0;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<color[i];j++)
		{
			if(!(hang&1))
			{
				board[hang][lie]=i+1;
				lie++;
				if(lie==W)
				{
					hang++;
					lie=0;
				}
			}
			else
			{
				board[hang][W-1-lie]=i+1;
				lie++;
				if(lie==W)
				{
					hang++;
					lie=0;
				 } 
			}
		}
	}
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
			printf("%d ",board[i][j]);
		printf("\n");
	}
 } 

Measured memory_bytes: 256
s = input()

valley, apex, wave, ans = 0, 0, 0, 0
prev = None
END = 'e'
for i, c in enumerate(s + END):
    if (prev==None)&(c=='>') | (prev=='<')&(c==END) | (prev=='<')&(c=='>'):
        apex = i
        ans += (apex-valley-1)*(apex-valley)//2 # valley has 0, so add sum(range(valley-apex-1))
        if c == END:
            ans += wave
    if (prev==None)&(c=='<') | (prev=='>')&(c==END) | (prev=='>')&(c=='<'):
        valley = i
        apex_wave = wave + valley - apex
        if wave < 0:
            ans += (valley-apex)*(valley-apex+1)//2   # valley has 0, so calculate sum(range(valley-apex))
        else:
            ans += (valley-apex-1)*(valley-apex)//2 + apex_wave  # calculate sum(range(valley-apex-1)) + origin apex value
        wave = 0

    prev = c
    if c == '<':
        wave += 1
    elif c == '>':
        wave -= 1

print(ans)
    


    

Measured memory_bytes: 4212
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  double x, y;
  scanf("%lf%lf", &x, &y);
  printf("%.10f\n", x / y);
  return 0;
}


Measured memory_bytes: 256
h, w = (int(x) for x in input().split())
n = int(input())
seq = [int(x) for x in input().split()]
ans = [[0 for _ in range(w)] for _ in range(h)]
cnt = 0
for color, val in enumerate(seq,1):
    color = str(color)
    for _ in range(val):
        if (cnt // w) % 2 == 0:
            ans[cnt // w][cnt % w] = color
        else:
            ans[cnt // w][-1 - (cnt % w)] = color
        cnt += 1
for line in ans:
    print(' '.join(line))

Measured memory_bytes: 41072
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    for(int i = 0; i < n; i++) {
      int p = sc.nextInt();
      list.add(p);
    }
    int ans = 0;
    int t = x;
    for(int i = 1; i <= 101; i++) {
      if(!list.contains(i)) {
        if(Math.abs(x - i) < t) {
          t = Math.abs(x - i);
          ans = i;
        }
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,m;
    cin>>n>>m;

    vector<vector<Pi>> v(n+1);

    rep(i,m){
        ll y, p;
        cin>>p>>y;
        v[p].emplace_back(y,i);
    }

    vector<string> res(m);
    rep(i,n+1){
        if(v[i].size()==0LL)continue;
        vector<Pi> &ord = v[i];
        sort(ALL(ord));
        ll cnt = 1;
        Each(el,ord){
            auto zero = [](int x){
                stringstream ss;
                ss<<setw(6)<<setfill('0')<<x;
                string out;
                return ss.str();
            };
            string s = zero(i)+zero(cnt);
            res[el.se] = s;
            cnt++;
        }
    }
    rep(i,m){
        cout<<res[i]<<endl;
    }
    return  0;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    
    vector<string> c(h);
    for (int i = 0; i < h; i++) cin >> c[i];
    
    for (int i = 0; i < h; i++) {
        cout << c[i] << endl << c[i] << endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


int main(){
	ll a,b;
	cin>>a>>b;
	ll sum=a+b;
	if(sum%2)print("IMPOSSIBLE");
	else print(sum/2);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//





int main() {

    int N; cin >> N;
    string s; cin >> s;
    ll r, g, b;
    r = g = b = 0;
    rep(i,N) {
        if (s[i] == 'R') ++r;
        else if (s[i] == 'G') ++g;
        else ++b;
    }
    ll all = r * g * b;
    ll ex = 0;
    rep(j, N) {
        for (int len = 1; len < N; ++len) {
            if (j - len >= 0 && j + len <= N - 1) {
                if (s[j - len] != s[j] && s[j] != s[j + len] && s[j + len] != s[j - len]) {
                    ++ex;
                }
            }
        }
    }
    out(all - ex);


    return 0;
}






Measured memory_bytes: 3636
phone = [[], [".", ",", "!", "?", " "], ["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"], ["j", "k", "l"], 
         ["m", "n", "o"], ["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"]]

n = int(input())
for i in range(n) :
    message = list(input().split("0"))
    for j in range(len(message)) :
        if message[j] != "" :
            push = list(message[j])
            num = int(push[0])
            kaisuu = len(push) % len(phone[num])
            if kaisuu == 0 :
                print(phone[num][-1], end="")
            else :
                print(phone[num][kaisuu-1], end="")
    print()


Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int k; cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int cnt = 1;
  ll x = 7;
  bool can = true;
  while (true)
  {
    if (x % k == 0) {break;}
    x %= k; x *= 10; x += 7;
    cnt++;
    if (cnt >= 10000000) {can = false; break;}
  }
  if (can) cout << cnt << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string s;
    cin >> s;
    string kami_no_ku = s.substr(0,5);
    string naka_no_ku = s.substr(6,7);
    string shimo_no_ku = s.substr(14,5);
    cout << kami_no_ku << " " << naka_no_ku << " " << shimo_no_ku << endl;
}


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

using namespace std;

typedef long long   ll;

const int   N   = 2e3 + 1;
const ll    mod = 1e9 + 7;

void add(int &a,int b)  {
    a += b;
    if(a >= mod)a -= mod;
    if(a < 0)   a += mod;
}

ll  qpow(ll a,int exp)  {
    ll ans = 1;
    while(exp)  {
        if(exp & 1) ans = ans * a % mod;
        a = a * a % mod;  exp >>= 1;
    }
    return ans;
}

ll  Fac[N * N];
ll  Inv[N * N];

int Ckn(int n,int k)    {
    if(n < k || n < 0 || k < 0) return 0;
    ll  res = Inv[k] * Inv[n - k] % mod;
        res = Fac[n] * res % mod;
    return (int)res;
}

int f[N][N];

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

    int n, K;   cin >> n >> K;

    if(K < 2)   return puts("1"),0;

    Fac[0] = 1;

    for(int i = 1 ; i <= n * K ; ++i)
        Fac[i] = 1ll * Fac[i - 1] * i % mod;

    Inv[n * K] = qpow(Fac[n * K],mod - 2);
    for(int i = n * K - 1 ; ~i ; --i)
        Inv[i] = 1ll * Inv[i + 1] * (i + 1) % mod;

    f[0][0] = 1;

    for(int i = 1 ; i <= n ; ++i)
        for(int j = 0 ; j <= i ; ++j)   {
            if(i)   add(f[i][j],f[i - 1][j]);
            if(j)   add(f[i][j],1ll * f[i][j - 1] * Ckn(n * K - i - (j - 1) * (K - 1) - 1,K - 2) % mod);
        }

    cout << 1ll * f[n][n] * Fac[n] % mod << endl;
}

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

using namespace std;

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

#define int ll


main(){
	string s;
	cin >> s;
	if(s=="ABC"){
		cout << "ARC" << endl;
	}else{
		cout << "ABC" << endl;
	}
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int a,b;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b;
    cout<<(a-1)*(b-1)<<newl;
}


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

using namespace std;

int main() {
    int a, b, c, d, e, k;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;

    if(e-a <= k)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;

    return 0;
}

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

int main(void) {
	int n;
	int a[100000] = { 0 };
	int cost[100000] = { 0 };
	int total = 0;

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

	cost[0] = abs(a[0]);
	total += cost[0];

	for (int i = 1; i < n ; i++) {	
		cost[i] = abs(a[i] - a[i - 1]);
		total += cost[i];
	}
	
	cost[n] = abs(a[n - 1]);
	total += cost[n];

	for (int i = 0; i < n; i++) {
		int temp = 0;
		if (i == 0) temp = -abs(a[0]) - cost[1] + abs(a[1]);
		else if ((i == n - 1))temp = -abs(a[n - 1]) - cost[n - 1] + abs(a[n - 2]);
		else temp = -cost[i] - cost[i + 1] + abs(a[i + 1] - a[i - 1]);
		printf("%d\n", total + temp);
	}
	return 0;
}


Measured memory_bytes: 1920
from sys import stdin
readline = stdin.readline


import heapq

def main():
    heap = []
    while True:
        line = readline()
        if line[2] == 't':
            print(heapq.heappop(heap)[1])
        elif line[2] == 's':
            n = int(line.split()[1])
            heapq.heappush(heap, (-n, n))
        else:
            break

main()

Measured memory_bytes: 152136
#include<stdio.h>
int main(void)
{
	int H,W,x,y,i;
	char o,p;
	
	o='#';
	p='.';
	
	scanf("%d %d",&H,&W);
	
	while(!(H==0 && W==0)){
		for(i=0;i<W;i++){
		printf("%c",o);
		}
		printf("\n");
			for(x=0;x<H-2;x++){
				printf("%c",o);
				for(y=0;y<W-2;y++){
					printf("%c",p);
					}
				printf("%c",o);
				printf("\n");
			}
			for(i=0;i<W;i++){
				printf("%c",o);
			}
			printf("\n");
			scanf("%d %d",&H,&W);
			printf("\n");
	}	
	return 0;
}

Measured memory_bytes: 1000
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define INF 1e9

int main(){
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  int s[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      s[i][j] = 1;
    }
  }

  for(int i=0;i<b;i++){
    for(int j=0;j<a;j++){
      s[i][j] = 0;
    }
  }

  for(int i=b;i<h;i++){
    for(int j=a;j<w;j++){
      s[i][j] = 0;
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << s[i][j];
    }
    cout << endl;
  }




  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    rep(i,n) cin >> a[i];

    int ans = 0;

    
    for(int i=1; i <= n; i+=2){
        if(a[i-1] % 2 == 1){
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include <stdio.h>

typedef struct
{
    char c;
    int number;
} card;

int main()
{
    int n, i, j, min, flag;
    card a[36], b[36], x;
    char w;

    scanf("%d\n", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%c%d%c", &a[i].c, &a[i].number, &w);
        b[i] = a[i];
    }

//BubbleSort
    for (j = 0; j < n; j++)
    {
        flag = 0;
        for (i = n - 1; i > j; i--)
        {
            if (a[i].number < a[i - 1].number)
            {
                x = a[i];
                a[i] = a[i - 1];
                a[i - 1] = x;
                flag = 1;
            }
        }
        if (flag == 0) break;
    }

//SelectionSort
    for (j = 0; j < n; j++)
    {
        min = j;
        for (i = j; i < n; i++)
        {
            if (b[i].number < b[min].number)
                min = i;
        }
        if (min != j)
        {
            x = b[j];
            b[j] = b[min];
            b[min] = x;
        }
    }


//Output
    for (i = 0; i < n - 1; i++)
        printf("%c%d ", a[i].c, a[i].number);
    printf("%c%d\n", a[n - 1].c, a[n - 1].number);

    printf("Stable\n");
    for (i = 0; i < n - 1; i++)
    {
        printf("%c%d ", b[i].c, b[i].number);
        if (a[i].c != b[i].c)
            flag = 2;
    }
    printf("%c%d\n", b[n - 1].c, b[n - 1].number);
    if (flag == 2)
        printf("Not stable\n");
    else
        printf("Stable\n");

    return 0;
}


Measured memory_bytes: 2004
import sys

def print_data(data):
    last_index = len(data) - 1
    
    for idx, item in enumerate(data):
        print(item, end='')
        if idx != last_index:
            print(' ', end='')

    print('')
        
def main():
    N = int(input())
    A_list = list(map(int, input().split()))
    nowmax = -1
    result = []
    for i in range(N):
        if A_list[i] >= nowmax:
            result.append(A_list[i])
            nowmax = A_list[i]
        else:
            junban = []
            for j in range(i):
                if A_list[i] < result[j]:
                    asa = result[:j]
                    junban = asa
                    junban.append(A_list[i])
                    junban += result[j:]
                    result = junban
                    break         
        shutu = result[:i+1] + A_list[i+1:]
        print_data(shutu)
            
if __name__ == '__main__':
    main()


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

using namespace std;

vector<int> dice(7, 0);
vector<int> dice2(7, 0);
vector<int> newdice(7, 0);
string str;

void dicerot() {

	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'N') {
			newdice[1] = dice[2];
			newdice[2] = dice[6];
			newdice[3] = dice[3];
			newdice[4] = dice[4];
			newdice[5] = dice[1];
			newdice[6] = dice[5];
		}
		else if (str[i] == 'S') {
			newdice[1] = dice[5];
			newdice[2] = dice[1];
			newdice[3] = dice[3];
			newdice[4] = dice[4];
			newdice[5] = dice[6];
			newdice[6] = dice[2];
		}
		else if (str[i] == 'E') {
			newdice[1] = dice[4];
			newdice[2] = dice[2];
			newdice[3] = dice[1];
			newdice[4] = dice[6];
			newdice[5] = dice[5];
			newdice[6] = dice[3];
		}
		else if (str[i] == 'W') {
			newdice[1] = dice[3];
			newdice[2] = dice[2];
			newdice[3] = dice[6];
			newdice[4] = dice[1];
			newdice[5] = dice[5];
			newdice[6] = dice[4];
		}
		else if (str[i] == 'R') {
			newdice[1] = dice[1];
			newdice[2] = dice[3];
			newdice[3] = dice[5];
			newdice[4] = dice[2];
			newdice[5] = dice[4];
			newdice[6] = dice[6];
		}
		else if (str[i] == 'L') {
			newdice[1] = dice[1];
			newdice[2] = dice[4];
			newdice[3] = dice[2];
			newdice[4] = dice[5];
			newdice[5] = dice[3];
			newdice[6] = dice[6];
		}

		for (int j = 1; j <= 6; j++) {
			dice[j] = newdice[j];
		}

	}

}

int dicecheck() {
	int counter = 0;
	for (int i = 1; i < 6; i++) {
		if (dice[i] != dice2[i]) { counter++; }
	}
	return counter;
}


int main() {

	cin >> dice[1] >> dice[2] >> dice[3] >> dice[4] >> dice[5] >> dice[6];
	cin >> dice2[1] >> dice2[2] >> dice2[3] >> dice2[4] >> dice2[5] >> dice2[6];

	for (int k = 0; k < 4; k++) {
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (dicecheck() == 0) {
					cout << "Yes" << endl;
					return 0;
				}
				str = "R";
				dicerot();
			}
			str = "N";
			dicerot();
		}
		str = "E";
		dicerot();
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3160
#156
def main():
    N = int(input())
    X = list(map(int,input().split()))
    sum_x = sum(X)
    sum_xsqrt = sum([x**2 for x in X])
    
    p = sum(X)//N
    candidate = [N*p**2-2*p*sum_x+sum_xsqrt,N*(p+1)**2-2*(p+1)*sum_x+sum_xsqrt]
    print(min(candidate))
main()

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

int main () {
	int n, a[210], cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	bool exist_odd = false;

	while (true) {
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 == 1) exist_odd = true;
		}
		if (exist_odd) break;
		
		for (int i = 0; i < n; i++) a[i] /= 2;
		cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include "stdio.h"

using namespace std;

#define mod 1000000007
#define int long long
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define psb push_back

const int maxn=3e5+5;
map<pair<int,int>,int> mp;

void solve()
{
    int q,n,m;
    cin>>n>>m>>q;
    int maxv=0,maxh=0;
    vector<int> vh,vv,hor(maxn,0),ver(maxn,0);
    vector<pair<int,int>> v;
    for(int i=0;i<q;i++)
    {
        int h,w;
        cin>>h>>w;
        mp[{h,w}]=1;
        hor[h]++;
        if(hor[h] > maxh)
            maxh=hor[h];
        ver[w]++;
        if(ver[w] > maxv)
            maxv=ver[w];
    }
    for(int i=1;i<=n;i++)
        if(hor[i]==maxh)
            vh.push_back(i);
    
    for(int i=1;i<=m;i++)
        if(ver[i]==maxv)
            vv.push_back(i);

    int ans=maxh+maxv;

    if(vh.size()*vv.size() <= q){
        for(int i:vh)
            for(int j:vv)
                if(!mp.count({i,j})){
                    cout<<ans<<endl;
                    return;
                }
        ans--;
    }
    cout<<ans<<endl;
}

int32_t main()
{
    fio;
    int t;
    // cin>>t;
    t=1;
    while(t--)
        solve();
}

Measured memory_bytes: 35028
#include <stdio.h>
 
int alg ( int a, int b ) 
{ 
    int src = a + b;                                                                   
    int result = 0;  
 
    do  
    {   
        result++; 
    } while ( (src /= 10) != 0 );  
 
    return result; 
} 
 
int main ( void ) 
{ 
    int a, b;  
 
    while ( scanf( "%d %d", &a, &b ) != EOF ) 
    {   
        printf( "%d\n", alg( a, b ) );  
    }   
 
    return 0;  
} 

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool in(ll y, ll x, ll h, ll w){
	return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
	int h,w; cin >> h >> w;
	int sy, sx; cin >> sy >> sx; sy--; sx--;
	int gy, gx; cin >> gy >> gx; gy--; gx--;
	vs s(h);
	rep(i,h) cin >> s[i];
	vvl d(h,vl(w,inf));
	d[sy][sx] = 0;
	priority_queue<pair<ll,pii>,vector<pair<ll,pii>>,greater<pair<ll,pii>>> q;
	q.emplace(0,pii(sy,sx));
	while(!q.empty()){
		auto p = q.top(); q.pop();
		int y = p.second.first;
		int x = p.second.second;
		if(d[y][x] < p.first) continue;
		rep(i,4){
			int ny = y + dy[i];
			int nx = x + dx[i];
			if(!in(ny,nx,h,w) || s[ny][nx] == '#') continue;
			if(d[ny][nx] > d[y][x]){
				d[ny][nx] = d[y][x];
				q.emplace(d[ny][nx],pii(ny,nx));
			}
		}
		for(int ny=y-2; ny<=y+2; ny++){
			for(int nx=x-2; nx<=x+2; nx++){
				if(ny == y && nx == x) continue;
				if(!in(ny,nx,h,w) || s[ny][nx] == '#') continue;
				if(d[ny][nx] > d[y][x] + 1){
					d[ny][nx] = d[y][x] + 1;
					q.emplace(d[ny][nx],pii(ny,nx));
				}
			}
		}
	}
	if(d[gy][gx] == inf) puts("-1");
	else cout << d[gy][gx] << "\n";
}

Measured memory_bytes: 13468
#include<bits/stdc++.h>
using namespace std;
bool com(int a,int b)
{
    return (a<b);
}
int main()
{
    int n,k,i,ans=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n,com);
    for(i=0;i<k;i++)
        ans+=a[i];
    cout<<ans<<endl;
    return 0;
}

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

int main(void)
{
    ll x,k,d;
    cin>>x>>k>>d;
    ll a=floor((double)x/d);
    ll b=x-a*d;
    ll ans;
    if(abs(a+1)<=k&&abs(a)<=k)
    {
        if(k%2==abs(a)%2) ans=b;
        else ans=d-b;
    }
    else
    {
        if(a<0)
            ans=d-(a+k+1)*d-b;
        else
            ans=(a-k)*d+b;
    }
    cout<<ans<<endl;
    return 0;
}

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

using ll = long long int;

int n;

unordered_map<char, int> cnt;
unordered_map<int, char> mpi2c;
int k = 3;

ll ans;

int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}

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

  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H') cnt[s[0]] += 1;
  }

  mpi2c[0] = 'M';
  mpi2c[1] = 'A';
  mpi2c[2] = 'R';
  mpi2c[3] = 'C';
  mpi2c[4] = 'H';

  for (int bit = (1 << k) - 1; bit < (1 << cnt.size()); bit = next_combination(bit)) {
    vector<int> s;
    for (int i = 0; i < cnt.size(); ++i) {
      if (bit & (1 << i)) {
        s.push_back(i);
      }
    }

    ll tmp = (ll)(1);

    for (int i = 0; i < s.size(); ++i) {
      tmp *= (ll)(cnt[mpi2c[s[i]]]);
    }
    ans += (ll)(tmp);
  }

  printf("%lld\n", ans);

  return 0;
}

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

using namespace std;

const int N = 1000010, mod = 1e9 + 7;

long long a[N];
long long sum[N] = {0};

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; --i) {
        sum[i] = (sum[i + 1] + a[i]) % mod;
    }
    long long res = 0;
    for (int i = 1; i < n; ++i) {
        res = (res + a[i] * sum[i + 1] % mod) % mod;
    }
    cout << res << '\n';
    return 0;
}

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


int main(){
  int N;
  cin >> N;
  vector<string> W;
  for(int ii=0; ii<N; ii++){
    string w;
    cin >> w;
    if(W.size() == 0){
      W.push_back(w);
      continue;
    }
    if(find(W.begin(), W.end(), w) != W.end()){
      cout << "No" << endl;
      return 0;
    }
    if(W.back().back() != w.front()){
      cout << "No" << endl;
      return 0;
    }
    W.push_back(w);
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const double PI = 3.14159265358979323846264338327950;
const LL MOD = 1000000007;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int main(void)
{
	int N;
	cin >> N;
	int L[200];
	Rep(i, 2*N){
		cin >> L[i];
	}
	sort(L, L+2*N);
	int ans = 0;
	Rep(i, N){
		ans += L[2 * i];
	}
	PrintLn(ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define re(x) cout<<(#x)<<" is "<<(x)<<"\n"; 
#define gif(a,b) ((a)/(b)+((a)%(b)?1:0))
using namespace std;

int32_t main()
{
	IOS
	int T = 1; 
	  
	for (int t = 0; t < T; ++t)
	{
		int n;
		cin >> n;
		int a[n], b[n];
		int count = 0, flag = 0;
		for (int i = 0 ; i < n; ++i)
		{
			cin >> a[i] >> b[i];
			if(a[i] == b[i])
				count++;
			else
				count = 0;
			if(count == 3)
				flag = 1;

		}
		if(flag)
			cout << "Yes" << "\n";
		else
			cout << "No" << "\n";
		

	}
	return 0;
}
//if not working? go ahead.


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int m,d,ans;

signed main() {
    cin >> m >> d;
    rep1(i,m) rep(j,d-9) {
        int sum=1,tmp = j+10;
        bool f=false;
        while(tmp) {
            if (tmp%10 < 2) f = true;
            sum *= tmp%10;
            tmp/=10;
        }
        if (f) continue;
        if(sum == i) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
int ds[100001];
int df[100001];
bool seen[100001];
vector<vector<int>> g;

void dfs_vers(int s,int dis,int pre = -1){
    seen[s] = true;
    ds[s] = dis;
    for (auto nx:g[s]){
        if (nx == pre) continue;
        if (seen[nx] != true){
            dfs_vers(nx,dis+1,s);
        }
    }
}

void dfs_verf(int s,int dis,int pre = -1){
    seen[s] = true;
    df[s] = dis;
    for (auto nx:g[s]){
        if (nx == pre) continue;
        if (seen[nx] != true){
            dfs_verf(nx,dis+1,s);
        }
    }
}

int main(){
    int n;
    cin >> n;
    g.resize(n);
    rep(i,n-1){
        int x,y;
        cin >> x >> y;
        x--;y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    //printf("input ok\n");
    dfs_vers(n-1,0);
    rep(i,n) seen[i] = false;
    dfs_verf(0,0);
    int fcnt=0,scnt = 0;
    rep(i,n){
        if (ds[i] >= df[i]) fcnt++;
        else scnt++;
    }
    if (fcnt <= scnt) cout << "Snuke" << endl;
    else cout << "Fennec" << endl;
    
    
}

Measured memory_bytes: 11264
dirs = [
    (1,0,0),(0,1,0),(0,0,1),
    (1,1,0),(1,-1,0),
    (0,1,1),(0,1,-1),
    (1,0,1),(-1,0,1),
    (1,1,1),(1,1,-1),
    (1,-1,1),(1,-1,-1)
]
def judge(x,y,z):
    c = pegs[x][y][z]
    for dx,dy,dz in dirs:
        sq = 1
        for _m in (1,-1):
            m = _m
            while True:
                mx,my,mz = x + m*dx, y + m*dy, z + m*dz
                if any(map(lambda l:not(0<=l<N), (mx,my,mz))): break
                if pegs[mx][my][mz] == c:
                    sq += 1
                    if sq >= M:
                        return c
                else:
                    break
                m += _m
    return 0

while True:
    N,M,P = map(int,input().split())
    if N == 0: break
    moves = [tuple(map(lambda x:int(x)-1, input().split())) for i in range(P)]
    pegs = [[[0 for z in range(N)] for y in range(N)] for x in range(N)]
    turn = 1
    for i,(x,y) in enumerate(moves):
        z = pegs[x][y].index(0)
        pegs[x][y][z] = turn
        turn *= -1
        c = judge(x,y,z)
        if c != 0:
            winner = 'Black' if c > 0 else 'White'
            print(winner + ' ' + str(i+1))
            break
    else:
        print('Draw')

Measured memory_bytes: 5780