akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private final static byte MASK_RIGHT = 0x0F; //右4bit数値化用マスク
	private final static int STRIP_LENGTH = 10; //短冊1行の長さ
	private static int[] punchTape = new int[100]; //10*10の方眼紙を短冊にしてくっつけた紙テープ

	public static void main(String[] args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 512);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & MASK_RIGHT, sLine.charAt(2) & MASK_RIGHT, sLine.charAt(4) & MASK_RIGHT);
		}
		calcResult();
	}

	/**
	 *都合の良い滴下
	 */
	private static void droppingInk(int x, int y, int size) {
		sinking(x, y - 1);
		sinking(x - 1, y);
		sinking(x, y);
		sinking(x + 1, y);
		sinking(x, y + 1);
		if (size == 1) {
			return;
		}

		sinking(x - 1, y - 1);
		sinking(x + 1, y - 1);
		sinking(x - 1, y + 1);
		sinking(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		sinking(x, y - 2);
		sinking(x - 2, y);
		sinking(x + 2, y);
		sinking(x, y + 2);
	}

	/**
	 * 床は汚さないようにする
	 */
	private static void sinking(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			punchTape[x * STRIP_LENGTH + y]++;
		}
	}

	/**
	 *紙の染みを数え、損害を報告する
	 */
	private static void calcResult() {
		int white = 0;//綺麗な部分
		int max = 0;//一番ひどい汚れ
		for (int cell : punchTape) {
			if (cell == 0) {
				white++;
			} else if (cell > max) {
				max = cell;
			}
		}
		System.out.println(white);
		System.out.println(max);
	}
}

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

using namespace std;
using ll = long long;

const int MAX { 2010 };
const ll MOD { 1000000007 };

ll dp[MAX][MAX];

ll solve(int N, int M, const vector<ll>& xs, const vector<ll>& ys)
{
    dp[0][0] = 1;

    for (int i = 1; i <= N; ++i)
        dp[i][0] = 1;

    for (int i = 1; i <= M; ++i)
        dp[0][i] = 1;

    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= M; ++j)
        {
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
            dp[i][j] = (dp[i][j] - dp[i - 1][j - 1]) % MOD;
            dp[i][j] = (dp[i][j] + MOD) % MOD;

            if (xs[i] == ys[j])
            {
                dp[i][j] += dp[i - 1][j - 1];
                dp[i][j] %= MOD;
            }
/*
            if (xs[i] == ys[j - 1])
            {
                dp[i][j] += dp[i - 1][j];
                dp[i][j] %= MOD;
            }

            if (xs[i - 1] == ys[j])
            {
                dp[i][j] += dp[i][j - 1];
                dp[i][j] %= MOD;
            }
*/
 //           cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
        }
    }

    return dp[N][M];
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<ll> xs(N + 1), ys(M + 1);

    for (int i = 1; i <= N; ++i)
        cin >> xs[i];

    for (int i = 1; i <= M; ++i)
        cin >> ys[i];

    auto ans = solve(N, M, xs, ys);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 31744
#include<iostream>
 #include <string.h>
using namespace std;
int table[16777216];
char str[13];

int get_num(char c) {
	switch (c)
	{
		case 'A': return 1;
		case 'C': return 2;
		case 'G': return 3;
		default: return 4;
	}
}

int hash_table() {
	int ret=0;
	for (int i = 0; str[i] != '\0'; i++) {
		ret = ret * 4 + get_num(str[i]);
	}
	return ret;
}

int main() {
	int n;
	char com[6];
	cin >> n;
	memset(table, 0, sizeof(table));
	for (int i = 0; i < n; i++) {
		cin >> com >> str;
		if (com[0] == 'i') {
			table[hash_table()] = 1;
		}
		else {
			int ret = hash_table();
			if (table[ret] == 1)
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 68628
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) { os << p.first << " " << p.second; return os; }

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; }return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	string N; cin >> N;
	if (N.size() == 3) {
		reverse(all(N));
	}
	cout << N << endl;

	return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int64 N;
vector<int64> G[2020];
vector<int64> cnt, dep;
string S;

PLL dfs(int64 idx, int64 p) {
  if (S[idx] == '1') cnt[idx]++;

  int64 mn = 0, mx = 0, sum = 0;
  REP(i, G[idx].size()) {
    int64 to = G[idx][i];
    if (to == p) continue;
    PLL ret = dfs(G[idx][i], idx);
    cnt[idx] += cnt[to];
    dep[idx] += dep[to] + cnt[to];
    if (mn < ret.fs + cnt[to]) {
      mn = ret.fs + cnt[to];
      mx = ret.sc + cnt[to];
    }
  }
  if (dep[idx]-mx >= mn) return PLL(dep[idx]%2, dep[idx]);
  return PLL(mn-dep[idx]+mx, dep[idx]);
}

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

  cin >> N >> S;
  REP(i, N-1) {
    int64 a, b;
    cin >> a >> b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  int64 res = INF_LL;
  REP(i, N) {
    cnt = vector<int64>(N, 0);
    dep = vector<int64>(N, 0);
    PLL ret = dfs(i, -1);
    if (ret.fs == 0 && dep[i] % 2 == 0) res = min(res, dep[i]/2);
  }
  cout << (res == INF_LL ? -1 : res) << endl;
}


Measured memory_bytes: 640
a, b, c = gets.split(" ").map(&:to_i)
k = gets.to_i
x = [Math.log2(a.to_f / b).floor + 1, 0].max
y = [Math.log2((b * 2**x).to_f / c).floor + 1, 0].max
puts (k >= x + y ? "Yes" : "No")

Measured memory_bytes: 14408
IDENTIFICATION DIVISION.
PROGRAM-ID. 173A.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N          PIC 9(05).
01 S          PIC 9(04).
01 OT         PIC 9(04).
01 OUT        PIC ZZ9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  DIVIDE N BY 1000 GIVING S REMAINDER OT.
  COMPUTE OT = 1000 - OT
  IF OT = 1000
    MOVE 0 TO OT
  END-IF.
*>
  MOVE OT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 3912
#include <iostream>

using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	string ans;
	for (int i = 0; i < 100; ++i) {
		c -= b;
		if (c <= 0) {
			ans = "Yes";
			break;
		}
		
		a -= d;
		if (a <= 0) {
			ans = "No";
			break;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,K;
  cin >> N >> K;
  ll ans=0;
  ll cnt;
  if(K==0){
    cout << N*N << endl;
    return 0;
  }
  for(ll i=K+1;i<=N;i++){
    // cnt=0;
    ans+=(i-K)*(N/i);
    //cout << ans << " " << cnt << endl;
    ll r=N-(N/i)*i+1;
    ans+=max(0LL,r-K);
    //cout << ans << " " << cnt << endl;
  }
  cout << ans << endl;
  return 0;
}

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#endif

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

    string S;
    cin >> S;

    int N = S.size();    

    int wr = -1;
    for (int i=N-1; i>=0; --i) {
        if (S[i] == 'W') {
            wr = i;
            break;
        }
    }
    if (wr == -1) {
        cout << 0 << endl;
        return 0;
    }

    long long res = 0;
    int cnt = 0;
    for (int i=wr-1; i>=0; --i) {
        if (S[i] == 'B') {
            res += wr - i - cnt;
            cnt ++;
        }
    }

    cout << res << endl;

    return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    int ans=1;
    for(int i=0;i<n;i++){
        ans=min(ans*2,ans+k);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
h = [int(i) for i in input().split()]
inf = float("inf")
dp = [inf]*N
dp[0] = 0
for i in range(N-1):
    if i <N-2:
        dp[i+2] = dp[i] + abs(h[i]-h[i+2])
    dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
print(dp[-1])

Measured memory_bytes: 13928
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }
template<typename T = i64>
void OUT(T& x) { cout << (x) << endl; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

#ifdef _DEBUG
signed Main()
#else
signed main()
#endif
{
	auto A = IN();
	auto B = IN();
	cout << (max({A+B,A-B,A*B})) << endl;
	return 0;
}


Measured memory_bytes: 892
n = int(input())
a = [int(input()) for _ in range(n)]

ans, x = 1, a[0]
for i in range(n+1):
    if x == 2:
        print(ans)
        exit()
    v = a[x-1]
    a[x-1], x = 0, v
    ans += 1
    if x == 0:
        break
print(-1)


Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  multiset<int> s;
  for(int i=0;i<n;i++) {
    if(i == 0) s.emplace(a[i]);
    else {
      auto it = s.lower_bound(a[i]);
      if(it == s.begin()) s.emplace(a[i]);
      else {
        s.erase(prev(it));
        s.emplace(a[i]);
      }
    }
  }
  cout << s.size() << endl;
}


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

int main(){
  int64_t d;
  while(cin >> d){
    int64_t ans = 0;
    for(int64_t i=0; i<600/d;i++){
      ans += d*(i*d)*(i*d);
    }
    cout << ans << endl;
  }
}
  
  


Measured memory_bytes: 3120
# https://atcoder.jp/contests/abc116/tasks/abc116_c

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    flowers = [0] + input_int_list()
    section_min = 0
    ans = 0
    for i in range(1, n + 1):
        if flowers[i] < flowers[i - 1]:
            ans += flowers[i - 1] - section_min
            section_min = flowers[i]
    if flowers[n] > section_min:
        ans += flowers[n] - section_min
    print(ans)
    return


if __name__ == "__main__":
    main()


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

int main(){
    int n, cnt = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a.at(i);
    for(int i = 0; i < n; ++i){
        if(a.at(i) != i+1){
            ++cnt;
        }
    }
    if(cnt < 3) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main(){
 int N,K; cin>>N>>K;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int kotae=1; 
  N-=K;
  while(N>0){
    kotae++;
    N-=K-1;
  }
    cout<<kotae<<endl;
}

Measured memory_bytes: 640
n, m = [int(i) for i in input().split()]
a = []
for i in range(n):
    tmp = input()
    a.append(tmp)
b = []
for i in range(m):
    tmp = input()
    b.append(tmp)
f = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        g = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    g = False
        if g:
            f = True
if f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second 
#define ull unsigned long long  
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif

int n;
vector<int> dp[3] , a[3];

int fun(int cur, int idx){
	if(idx == 0)
		return a[cur][0];
	int& ans = dp[cur][idx];
	if(ans != -1) return ans ;
	for(int k = 0 ; k < 3 ; ++k)
		if(k != cur)
			ans = max(ans, fun(k,idx-1) + a[cur][idx]);
	return ans ;
}
void solve()
{
	cin >> n;
	for(int i = 0 ; i < 3 ; ++i) dp[i].resize(n,-1), a[i].resize(n);
	for(int i = 0 ; i < n ; ++i)
		for(int j = 0; j < 3 ; ++j)
			cin >> a[j][i];
	cout << max(fun(0,n-1),max(fun(1,n-1),fun(2,n-1))) << endl ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 11264
#include<stdio.h>
int main(void)
{
  int i,j,k[100000],x,y;
  i=0;
  char c;
  do{
    scanf("%d %c %d",&x,&c,&y);
    if(c=='+'){
      k[i]=x+y;
    }
    if(c=='-'){
      k[i]=x-y;
    }
    if(c=='*'){
      k[i]=x*y;
    }
    if(c=='/'){
      k[i]=x/y;
    }
    i++;
    }while(c!='?');
  for(j=0;j<i-1;j++){
    printf("%d\n",k[j]);
  }
  return 0;
}

Measured memory_bytes: 608
n,m,Q = map(int, input().split())
train = []
for i in range(n):
  a = []
  for j in range(n):
    a.append(0)
  train.append(a)
  
for i in range(m):
  l,r = map(int, input().split())
  train[l-1][r-1] += 1
cumsum = []
list1 = []
for i in range(n+1):
  list1.append(0)
cumsum.append(list1)
for i in range(n):
  lst = [0,cumsum[i][1]+train[i][0]]
  for j in range(1,n):
    lst.append(lst[j]+train[i][j]+(cumsum[i][j+1]-cumsum[i][j]))
  cumsum.append(lst)
for i in range(Q):
  p,q = map(int, input().split())
  print(cumsum[q][q]-cumsum[p-1][q]-cumsum[q][p-1]+cumsum[p-1][p-1])


Measured memory_bytes: 61272
// ABC053A - 

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	int x;
	cin >> x;

	if (x < 1200) {
		cout << "ABC" << endl;
	} else {
		cout << "ARC" << endl;
	}

	return 0;
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll X, Y, Z; cin >> X >> Y >> Z;
  swap(X, Y);
  swap(X, Z);
  cout << X << " " << Y << " " << Z << endl;

  return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<int> a(N+1,0);
    vector<int> b(N+1,0);
    vector<int> sumA(N+1,0);
    vector<int> sumB(N+1,0);

    for(int i = 1; i <= N; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= N; i++){
        cin >> b[i];
    }

    for(int i = 1; i <= N; i++){
        sumA[i] = sumA[i-1] + a[i];
    }
    for(int i = 1; i <= N; i++){
        sumB[i] = sumB[i-1] + b[i];
    }

    int ans = 0;
    for(int i = 1; i <= N;i++){
        ans = max(ans,sumA[i]+sumB[N]-sumB[i-1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
S = [0]
for i in range(N):
    S.append(A[i] + S[i])
ans = float('inf')
for i in range(1, N):
    ans = min(ans, abs((S[i] - S[0]) - (S[N] - S[i])))
print(ans)


Measured memory_bytes: 100172
#include <stdio.h>

int main(){
  int N;
  int h[101]={};//高さのゴール
  scanf("%d",&N);
  int i;
  for(i=1;i<=N;i++) scanf("%d",&h[i]);
  int h_now[101]={};
  int L=1,R=1;
  int count=0;

  while(1){
    //Lを決定する．
    while(L<N){
      if(h_now[L]<h[L]) break;
      else if(h_now[L]==h[L]) L++;
    }
    //printf("L=%d\n",L);

    //Rを決定する.
    R=L;
    while(R<N){
      if(h_now[R+1]<h[R+1]) R++;
      else if(h_now[R+1]==h[R+1]) break;
    }
    //printf("R=%d\n",R);

    //終了条件
    if(L==N && h_now[L]==h[L]) break;

    //水をやる
    for(i=L;i<=R;i++){
      h_now[i]++;
    }
    count++;
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using  namespace std;
int main()
{
    long long n,s=0;
    cin>>n;
    vector<long long  >v;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
    }
    sort(v.rbegin(),v.rend());
    //int m=*max_element (v.begin(),v.end());
    long long  j=0;
    for(int i=0;i<n-1;i++)
    {
       s=s+v[j];
       if(i%2==0)
        j++;
    }
    cout<<s<<endl;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	int a = 0;
	int b = 0;
	for( int i = 0; i < S.size(); ++i ) {
		if( S[i] == '0' ) {
			a += 1;
		}
		else {
			b += 1;
		}
	}

	cout << 2 * min( a, b ) << endl;

	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>

using namespace std;

typedef long long LL;

int n;
LL l,t,x[110000];
int w[110000],a[110000],num;
int main()
{
	scanf("%d %lld %lld",&n,&l,&t);
	for (int i=0;i<n;i++)
	{
		scanf("%lld %d",&x[i],&w[i]);
		x[i]+=(w[i]==1?t:-t);
		(num+=x[i]/l)%=n,x[i]%=l;
		if (x[i]<0) x[i]+=l,num--;
		a[i]=x[i];
	}
	sort(a,a+n);
	for (int i=0;i<n;i++)
		printf("%d\n",a[(i+num+n)%n]);
	return 0;
}

Measured memory_bytes: 2816
N , Y = gets.split(" ").map!{|i| i.to_i}
for x in 0..N do
  for y in 0..(N-x) do
    if Y == 10000 * x + 5000 * y + 1000*(N - x - y)
      puts "#{x} #{y} #{N - x - y}"
      exit
    end
  end
end
puts "-1 -1 -1"

Measured memory_bytes: 1788
A,B=list(map(int, input().split()))
if A==1:
  if B==1:
    print('Draw')
  else:
    print('Alice')
else:
  if B==1:
    print('Bob')
  else:
    if A>B:
      print('Alice')
    elif A<B:
      print('Bob')
    else:
      print('Draw')

Measured memory_bytes: 61760
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <iomanip>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[15];
	int x[15][15];
	int y[15][15];
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=0;j<a[i];j++){
			cin>>x[i][j]>>y[i][j];
			x[i][j]--;
		}
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++){
		int f[15];
		bool ok=true;
		int cnt=0;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				f[j]=1;
			}else{
				f[j]=0;
			}
		}
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				cnt++;
				for(int k=0;k<a[j];k++){
					int nx=x[j][k];
					int ny=y[j][k];
					if(f[nx]==-1){
						f[nx]=ny;
					}else if(f[nx]!=ny){
						ok=false;
					}
				}
			}
		}
		if(ok){
			ans=max(ans,cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
W, H, x, y, r = map(int, input().split())

def YesOrNo(W, H , x, y, r):
	Xr = x + r
	Xl = x - r
	Yu = y + r
	Yd = y - r
	if (W >= Xr and H >= Yu and 0 <= Xl and 0 <= Yd):
		return "Yes"
	else:
		return "No"

print(YesOrNo(W, H, x, y, r))

Measured memory_bytes: 7676
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
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 ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    REP(i,1000){
        string t;
        int x = i;
        REP(j,3){
            t += ('0' + (x % 10));
            x /= 10;
        }
        reverse(ALL(t));
        int j = 0;
        REP(p,n){
            if (j < 3 && s[p] == t[j]) j++;
        }
        if (j == 3){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
from numba import jit, njit
input = lambda: sys.stdin.buffer.readline().rstrip()

@njit
def main(n,m,k,sa,sb):
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  return(rx)

n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = np.cumsum([0]+a)
sb = np.cumsum([0]+b)
print(main(n,m,k,sa,sb))

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

ll func(ll n){
    ll t=n%4;
    if(t==0) return n;
    if(t==1) return 1;
    if(t==2) return 1^n;
    else return 0;
}

int main(){
  ll a,b;cin>>a>>b;
  ll ans=func(a-1)^func(b);
  
  cout<<ans;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long int
#define maxs 1000000007
using namespace std;
int n,k,dp[1005][1005];
char a[1005][1005];
int pos;

long long int solve(int i,int j)
{
    if(dp[i][j]!=-1)
        return dp[i][j];
   if(i==n && j==k)
    return 1;
    if(i>n || j>k)
        return 0;
   ll sum  = 0;
   //cout<<endl<<"current value of i and j is  : "<<i<<" "<<j;
   if( a[i+1][j] != '#')
   sum = ((sum%maxs)+(solve(i+1,j)%maxs))%maxs;
   if(a[i][j+1]!='#')
    sum = (((sum%maxs)+(solve(i,j+1)%maxs))%maxs);
   dp[i][j] = sum;
   return dp[i][j];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        cin>>n>>k;
    memset(dp,-1,sizeof(dp));
        for(int i=1;i<=n;++i)
            for(int j=1;j<=k;++j)
        {
            cin>>a[i][j];
        }
    cout<<(solve(1,1));
}




Measured memory_bytes: 5248
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  int N, M; cin >> N >> M;
  vector <int> X(N);
  for (int i = 0; i < N; i++){
    cin >> X[i];
  }
  sort(X.begin(), X.end());

  vector <int> cnt1(M), cnt2(M);
  for (int i = 0; i < N; i++){
    cnt1[X[i] % M]++;
  }

  int cnt = 1;
  for (int i = 0; i < N - 1; i++){
    if (X[i] == X[i + 1]){
      cnt++;
    }else{
      cnt2[X[i] % M] += cnt / 2;
      cnt = 1;
    }
  }
  cnt2[X[N - 1] % M] += cnt / 2;
  
  int ans = cnt1[0] / 2;
  cnt1[0] %= 2;
  
  for (int i = 1; i < M; i++){
    if (i != M - i){
      int m = min(cnt1[i], cnt1[M - i]);
      ans += m;
      cnt1[i] -= m;
      cnt1[M - i] -= m;
    }else{
      ans += cnt1[i] / 2;
      cnt1[i] = cnt1[i] % 2;
    }
  }


  for (int i = 1; i < M; i++){
    if (cnt1[i] >= 2 * cnt2[i]){
      ans += cnt2[i];
    }else{
      ans += cnt1[i] / 2;
    }
  }
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N=2e5+5;
vll v[N];
ll vis[N];
ll ans[N];
ll ve[N];

ll nv=0;

void solve()
{
    ll n,m;
    cin>>n>>m;
    ll i,x,y;
    for(i=0;i<n;i++)
    {
        ans[i]=INF;
    }
    
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        x--,y--;
        v[x].pb(y);
        v[y].pb(x);
    }

    ans[0]=1;
    queue<ll > q;
    vis[0]=1;
    q.push(0);
    vll vv;
    ll cur=-1;
    while(!q.empty())
    {
        ll xx=q.front();
        q.pop();

        for(auto it:v[xx])
        {
             if(!vis[it])
             {
                q.push(it);
                ans[it]=xx;
                vis[it]=1;
             }
        }
      
       nv++; 
    }
    if(nv!=n)
    {
        cout<<"No\n";
        return;
    }

    cout<<"Yes\n";

    for(i=1;i<n;i++)
    {
        cout<<ans[i]+1<<"\n";
    }    
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 16048
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 998244353;
int main() {
  ll N,A,B;
  cin >> N >> A >> B;
  ll ans = (N/(A+B)) * A;
  if ((N%(A+B)) >= A) {
    ans += A;
  } else {
    ans += (N%(A+B));
  }
  cout << ans << endl;
  return 0;
}

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

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

	rep(i, 0, k) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}

	cout << 1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
const int N = 10010;
inline int read()
{
	register char cc = getchar(); register int cn(0), flus(1);
	while(cc < '0' || cc > '9') {if(cc == '-') flus = - flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
	return cn * flus;
}
int a,h;
signed main()
{
	h = read();
	a = read();
	printf("%lld",(h-1)/a+1);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n;
	vector<double> vec;
	cin >> n;
	for(int i = 0;i < n;i++){
		double a;
		cin >> a;
		vec.pb(a);
	}
	sort(all(vec));
	double ans = vec[0];
	for(int i = 1;i < n;i++){
		ans = (ans + vec[i]) / 2.0;
	}
	printf("%.9lf\n",ans);
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll N, A[5];

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

    std::cin >> N;

    for(int i=0;i<5;++i){
        std::cin >> A[i];
    }

    int i = std::min_element(A, A + 5) - A;
    
    ll t = 4ll + (N + A[i] - 1) / A[i];
    std::cout << t << std::endl;
}


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

long long S, K, dp[4][10001] = {};
bool used[4][10001] = {};

long long func(int n, int s)
{
	if (used[n][s])
		return dp[n][s];
	if (n == 3)
	{
		used[n][s] = true;
		return dp[3][s] = s == S;
	}
	else
	{
		long long e = 0;
		n++;
		for (int i = 0; i <= K; i++)
		{
			e += func(n, s + i);
		}
		used[--n][s] = true;
		return dp[n][s] = e;
	}
}

int main()
{
	cin >> K >> S;
	cout << func(0, 0) << '\n';
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
	int N,K;
	scanf("%d %d",&N,&K);
	int A = 1;
	int B = 1;
	int num = 1;
	for(int i=0; i<N; i++){
		A = num * 2;
		B = num + K;
		if(A > B){
			num = B;
		}
		else{
			num = A;
		}
	}
	printf("%d\n",num);
	return 0;
}

Measured memory_bytes: 128
/*
 * @author Dhruvit
 */
#include<cstring>
#include<math.h>
#include<stdlib.h>
#include <fstream>
#include<algorithm>
#include<vector>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
#define vi          vector<int>
#define vii         vector<vector<int>>
#define pii         pair<int,int>
#define pb          push_back
#define pf          push_front
#define all(v)      v.begin(),v.end()
class ACurtain {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int a,b;
	    in>>a>>b;
	    int dis = a - (2*b);
        if(dis <0){
            out<<"0";
        }else{
            out<<dis;
        }
	}
};


signed main() {
    fast;
	ACurtain solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter};
use std::io::*;
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = [$(&stringify!([$arg]:), &$arg as &Debug),*];
            stderr().write_fmt(format_args!("{:#?}\n", entries)).unwrap();
        }
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let N = read!(usize);
    let A = read![[i64]];
    println!("{}", A.into_iter().sum::<i64>() - N as i64);
    return;
}


Measured memory_bytes: 4352
x,k,d = map(int,input().split())
x = abs(x)
if x - k*d > 0:
    print(x-k*d)
else:
    tmp1 = x - (x//d)*d
    tmp2 = k - (x//d)
    if tmp2 % 2 == 0:
        print(tmp1)
    else:
        print(abs(tmp1-d))

Measured memory_bytes: 61812
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    string t = s.substr(0, 2), r = s.substr(2);
    // int tt, rr;
    // tt = (t[0] - '0') + (t[1] - '0')*10;
    // rr = (r[0] - '0') + (r[1] - '0')*10;
    bool a = true, b = true;
    if(t == "00" || t >= "13") b = false;
    if(r == "00" || r >= "13"){
        a = false;
    }
    if(a && b) cout << "AMBIGUOUS" << endl;
    else if(a) cout << "YYMM" << endl;
    else if(b) cout << "MMYY" << endl;
    else cout << "NA" << endl; 
}


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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int n;

int main() {
	scanf("%d", &n);
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				int add = __gcd(i, __gcd(j,k));
				ans += add;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

ll a,b;
set<ll> v;
vector<ll> d,ans;
int main() {
	cin>>a>>b;
	if(a>b)
		swap(a,b);
	for(ll i=1;i*i<=a;i++)
		if(a%i==0)
			v.insert(i),v.insert(a/i);
	for(auto i:v)
	{
		if(b%i==0)
			d.push_back(i);
	}
	sort(d.begin(),d.end());
	for(auto i:d)
	{
		ll o=0;
		if(ans.empty())
		{
			ans.push_back(i);
			continue;
		}
		for(auto j:ans)
			if(__gcd(i,j)!=1)
			{
				o=1;
				break;
			}
		if(!o)
			ans.push_back(i);
	}
	cout<<ans.size();
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
const int num = 8;
int tf[num][num], col[num], ld[num*2-1], rd[num*2-1], row[num];
inline void print() {
	for (int i = 0; i < num; i++) {
		for (int j = 0; j < num; j++) {
			if (tf[i][j])
				if (row[i] != j) return;
		}
	}
	for (int i = 0; i < num; i++) {
		for (int j = 0; j < num; j++) {
			cout << (row[i] == j ? "Q" : ".");
		}
		cout << endl;
	}
}
inline void queen(int i) {
	if (i == num) {
		print();
		return;
	}
	else {
		for (int j = 0; j < num; j++) {
			if (!col[j] || !ld[i + j] || !rd[i - j + num - 1]) continue;
			row[i] = j;
			col[j] = ld[i + j] = rd[i - j + num - 1] = 0;
			queen(i + 1);
			col[j] = ld[i + j] = rd[i - j + num - 1] = 1;
			row[i] = -1;
		}
	}
}
int main() {
	for (int i = 0; i < num; i++) {
		for (int j = 0; j < num; j++) tf[i][j] = 0;
		col[i] = 1; row[i] = -1;
	}
	for (int i = 0; i < num * 2 - 1; i++) ld[i] = rd[i] = 1;
	int n, x, y;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		tf[x][y] = 1;
	}
	queen(0);
	return 0;
}

Measured memory_bytes: 3108
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static class UnionFind {
		private int n;
		private int[] parent;
		private int[] rank;

		public UnionFind(int n) {
			this.n = n;
			rank = new int[n];
			Arrays.fill(rank, 1);
			this.parent = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
			}
		}

		public boolean connected(int a, int b) {
			return root(a) == root(b);
		}

		public void union(int a, int b) {
			if (connected(a, b)) return;
			int rootA = root(a);
			int rootB = root(b);

			if (rank[rootA] > rank[rootB]) {
				parent[rootB] = parent[rootA];
				rank[rootA] = rank[rootB] = rank[rootA] + rank[rootB];
			} else {
				parent[rootA] = parent[rootB];
				rank[rootA] = rank[rootB] = rank[rootA] + rank[rootB];
			}
		}

		public int rank(int a) {
			return rank[root(a)];
		}

		private int root(int a) {
			while (parent[a] != parent[parent[a]]) parent[a] = parent[parent[a]];
			return parent[a];
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] ab = new int[m][2];
		for (int i = 0; i < m; i++) {
			ab[i][0] = sc.nextInt() - 1;
			ab[i][1] = sc.nextInt() - 1;
		}

		long[] answer = new long[m];
		answer[m - 1] = (long) n * (n - 1) / 2L;

		UnionFind uf = new UnionFind(n);
		for (int i = m - 2; i >= 0; i--) {
			if (uf.connected(ab[i + 1][0], ab[i + 1][1])) {
				answer[i] = answer[i + 1];
			} else {
				answer[i] = answer[i + 1] - (long) uf.rank(ab[i + 1][0]) * uf.rank(ab[i + 1][1]);
			}
			uf.union(ab[i + 1][0], ab[i + 1][1]);
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < m; i++) {
			sb.append(answer[i]).append("\n");
		}

		System.out.print(sb.toString());
	}
}


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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n), b(n), c(n-1);
    for (int &i: a) scanf("%d", &i);
    for (int &i: b) scanf("%d", &i);
    for (int &i: c) scanf("%d", &i);
    int ans = 0;
    for (int i=0; i<n; i++) {
        ans += b[a[i]-1];
        if (i<(n-1) && a[i+1]==(a[i]+1)) {
            ans += c[a[i]-1];
        }
        // printf ("ans = %d\n", ans);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int[] ans = new int[n + 1];
		for (int i = n; i > 0; i--) {
			int j = i * 2;
			int cnt = 0;
			while (j <= n) {
				cnt += ans[j];
				j += i;
			}
			ans[i] = cnt + a[i - 1];
		}

		StringBuilder sb = new StringBuilder();
		int cnt = 0;
		for (int i = 1; i <= n; i++) {
			if (ans[i] % 2 == 1) {
				cnt++;
				sb.append(i).append(' ');
			}
		}
		System.out.println(cnt);
		if (cnt > 0) {
			sb.deleteCharAt(sb.length() - 1);
			System.out.println(sb.toString());
		}
	}
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

int arr[105];

int main(){
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    for (int i = 1; i < n; i++)
        if (arr[i] == arr[i-1]){
            ans++;
            arr[i] = -1;
        }

    printf("%d\n", ans);
    return 0;
}


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

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> pix(h);
    for(int i = 0;i<h;i++){
        cin >> pix.at(i);
    }
    //cout << pix.at(0).size() << endl;
    for(int i=0;i<pix.at(0).size()+2;i++){
        cout << '#';
    }
    cout << endl;
    for(int i=0;i<h;i++){
        cout << '#' << pix.at(i) << '#' << endl;
    }
    for(int i=0;i<pix.at(0).size()+2;i++){
        cout << '#';
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

int A, B, K;

int main(void) {

	cin >> K >> A >> B;

	int num = K;

	string ans = "NG";

	for (int i = 1; K*i <= B; i++) {
		if (K*i >= A) { ans = "OK"; }
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3128
import sys
readline = sys.stdin.readline
import sys
readline = sys.stdin.readline
INF = int(1e10)
def partition(A, p, r):
    x = A[r][1]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1
def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q - 1)
        quicksort(A, q + 1, r)
def isStable(A):
    for i in range(0, len(A) - 1):
        if A[i][1] == A[i + 1][1]:
            if A[i][2] > A[i + 1][2]:
                return False
    return True
n = int(input())
f = lambda a, i: (a[0], int(a[1]), i)
A = [f(readline().split(), i) for i in range(n)]
quicksort(A, 0, n - 1)
print("Stable" if isStable(A) else "Not stable")
print(*(f"{a} {b}" for a, b, c in A), sep="\n")



Measured memory_bytes: 26604
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<Pll> p(N), q(N);
  for(int i = 0; i < N; i++){
    ll A, B;
    cin >> A >> B;
    A *= 2; B *= 2;
    p.at(i) = Pll(A, B);
    q.at(i) = Pll(B, A);
  }
  if(N % 2 == 0){
    ll pre = N/2 - 1;
    ll post = N/2;

    sort(ALL(p));
    ll x = p.at(pre).first;
    ll y = p.at(post).first;

    sort(ALL(q), greater<Pll>());
    ll z = q.at(post).first;
    ll w = q.at(pre).first;

    cout << (w + z) / 2 - (y + x) / 2 + 1 << endl;
  }
  else{
    ll pre = N/2;
    sort(ALL(p));
    ll x = p.at(pre).first;
    sort(ALL(q));
    ll z = q.at(pre).first;
    cout << (z - x) / 2 + 1 << endl;
  }
}

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

using namespace std;
using ll = long long;

int main() {
  int n, x, y;
  cin >> n >> x >> y;

  vector<int> d(n, 0);
  for (auto i = 0; i != n; ++i) {
    for (auto j = i + 1; j != n; ++j) {
      ++d[min(j - i, abs(i - x + 1) + abs(j - y + 1) + 1)];
    }
  }

  for (auto i = 1; i != n; ++i) {
    cout << d[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
typedef struct {
  char C[37];
  int A[37];
}Curd;
Curd curd[3];
void bubblesort(int n){
  int i,flag=1,temp1;
  char temp2;
  while(flag==1){
    flag=0;
    for(i=n-1;i>=1;i--){
      if(curd[1].A[i] < curd[1].A[i-1]){
        temp1=curd[1].A[i];
	temp2=curd[1].C[i];
        curd[1].A[i]=curd[1].A[i-1];
	curd[1].C[i]=curd[1].C[i-1];
        curd[1].A[i-1]=temp1;
	curd[1].C[i-1]=temp2;
        flag=1;
      }
    }
  }
}

void selectionsort(int n){
  int i,j,minj,temp1,flag;
  char temp2;
  for(i=0;i<n;i++){
    flag=0;
    minj=i;
    for(j=i;j<n;j++){
      if(curd[2].A[j] < curd[2].A[minj]){
        minj=j;
        flag++;
      }
    }
    if(flag!=0){
      temp1=curd[2].A[i];
      temp2=curd[2].C[i];
      curd[2].A[i]=curd[2].A[minj];
      curd[2].C[i]=curd[2].C[minj];
      curd[2].A[minj]=temp1;
      curd[2].C[minj]=temp2;

    }
  }
}

int main(){
  int i,j,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c",&curd[0].C[i]);
    scanf("%d",&curd[0].A[i]);
  }
  for(j=1;j<3;j++){
    for(i=0;i<n;i++){
      curd[j].C[i]=curd[0].C[i];
      curd[j].A[i]=curd[0].A[i];
}
}
  bubblesort(n);
  selectionsort(n);
  for(i=0;i<n;i++){
    printf("%c%d",curd[1].C[i],curd[1].A[i]);
    if(i!=n-1){
    printf(" ");
    }
}
  printf("\nStable\n");

  for(i=0;i<n;i++){
    printf("%c%d",curd[2].C[i],curd[2].A[i]);
    if(i!=n-1){
      printf(" ");
    }
  }
  j=0;
  for(i=0;i<n;i++){
    if((curd[1].A[i]==curd[2].A[i])&&(curd[1].C[i]==curd[2].C[i])){
      j++;
}
}
  if(j==n){
    printf("\nStable\n");
}
  else{
    printf("\nNot stable\n");
}
  return 0;
}



Measured memory_bytes: 2104