akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memset( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

const int MAXN = 200020;
const int INF = 0x3f3f3f3f;

int n, m, v[20], tot, a[MAXN], d[MAXN];
int f[MAXN][20], g[MAXN][20];
int dpl[MAXN << 2], dpr[MAXN << 2], ans[MAXN];

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	scanf( "%d%d", &n, &m );
	for( int i = 1 ; i <= n ; i++ ) scanf( "%d", &a[ i ] );
	while( m ) v[ tot++ ] = m, m >>= 1;
	v[ tot++ ] = 0;
	d[ 1 ] = d[ n + 1 ] = INF;
	for( int i = 2 ; i <= n ; i++ ) d[ i ] = a[ i ] - a[ i - 1 ];
	for( int j = 0 ; j < tot ; j++ )
	{
		for( int i = 1 ; i <= n ; i++ )
			if( d[ i ] > v[ j ] ) f[ i ][ j ] = i;
			else f[ i ][ j ] = f[ i - 1 ][ j ];
		for( int i = n ; i ; i-- )
			if( d[ i + 1 ] > v[ j ] ) g[ i ][ j ] = i;
			else g[ i ][ j ] = g[ i + 1 ][ j ];
	}
	fill( dpr, 0x3f );
	dpr[ 0 ] = n + 1;
	for( int i = 0 ; i < ( 1 << tot ) ; i++ )
		for( int j = 0 ; j < tot ; j++ ) if( !( i >> j & 1 ) )
		{
			if( dpl[ i ] >= n ) dpl[ i | ( 1 << j ) ] = n;
			else dpl[ i | ( 1 << j ) ] = max( dpl[ i | ( 1 << j ) ], g[ dpl[ i ] + 1 ][ j ] );
			if( dpr[ i ] <= 1 ) dpr[ i | ( 1 << j ) ] = 1;
			else dpr[ i | ( 1 << j ) ] = min( dpr[ i | ( 1 << j ) ], f[ dpr[ i ] - 1 ][ j ] );
		}
	for( int i = 0 ; i < ( 1 << tot ) ; i++ )
	{
		if( i & 1 ) continue;
		int l = dpl[ i ], r = dpr[ ( 1 << tot ) - 1 - i - 1 ];
		if( l >= r ) ans[ 1 ]++;
		else
		{
			int L = f[ l + 1 ][ 0 ], R = g[ l + 1 ][ 0 ];
			if( R + 1 >= r ) ans[ L ]++, ans[ R + 1 ]--;
		}
	}
	for( int i = 1, cur = 0 ; i <= n ; i++ )
	{
		cur += ans[ i ];
		if( cur ) puts( "Possible" );
		else puts( "Impossible" );
	}
}


Measured memory_bytes: 41600
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

const int N = 301;
const int INF = 1e9 + 239;

int fd[N][N];
int can[N][N];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			fd[i][j] = INF;
			can[i][j] = INF;
		}
		fd[i][i] = 0;
		can[i][i] = 0;
	}

	int n, m, l;
	cin >> n >> m >> l;
	while (m--) {
		int u, v, c;
		cin >> u >> v >> c;
		u--;
		v--;
		fd[u][v] = min(fd[u][v], c);
		fd[v][u] = min(fd[v][u], c);
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				fd[i][j] = min(fd[i][j], fd[i][k] + fd[k][j]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (fd[i][j] <= l) {
				can[i][j] = 1;
			}
		}
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				can[i][j] = min(can[i][j], can[i][k] + can[j][k]);
			}
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		if (can[u][v] == INF) cout << -1 << '\n';
		else cout << can[u][v] - 1 << '\n';
	}
}


Measured memory_bytes: 1280
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int z = sc.nextInt();

    System.out.println(z+" "+x+" "+y);

  }

}


Measured memory_bytes: 21844
//
//AtCoder Beginner Contest 177
//E
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

const int MAX_A = 1e6+10;

vector<bool> primeTable(ll n) {
    vector<bool> prime(n+1, true);
    if(n >= 0) prime[0] = false;
    if(n >= 1) prime[1] = false;
    for(ll i = 2; i*i<=n; i++) {
        if(!prime[i]) continue;
        for(ll j=i+i; j<=n; j+=i) prime[j] = false;
    }
    return prime;
}

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

    vector<int> a(n);
    vector<int> cntTbl(MAX_A, 0);
    REP(i, n) {
        cin >> a[i];
        cntTbl[a[i]]++;
    }
    vector<bool> pTbl = primeTable(MAX_A);

    bool pairwise = true;
    FOR(i, 2, MAX_A){
        if (pTbl[i]==false) continue;
        int cnt = 0;
        for(int j=i; j<MAX_A; j+=i){
            cnt += cntTbl[j];
        }
        if (cnt>1){
            pairwise = false;
            break;
        }
    }
    if (pairwise){
        cout << "pairwise coprime" << endl;
        return 0;
    }

    int g = 0;
    REP(i,n){
        g = gcd(g, a[i]);
    }
    if (g==1){
        cout << "setwise coprime" << endl;
        return 0;
    }

    cout << "not coprime" << endl;
    return 0;
}


Measured memory_bytes: 11172
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque


def S(): return sys.stdin.readline().rstrip()


def I(): return int(sys.stdin.readline().rstrip())


def MI(): return map(int, sys.stdin.readline().rstrip().split())


def MS(): return map(str, sys.stdin.readline().rstrip().split())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def LS(): return list(sys.stdin.readline().rstrip().split())


# N = I()
# A = [LI() for _ in range(N)]


n, m = map(int, input().split())
a = [0] * m
b = [0] * m
box = [[] for i in range(n)]
s = deque()
ans = [-1] * (n - 1)
for i in range(m):
    a[i], b[i] = map(int, input().split())
    box[a[i] - 1].append(b[i])
    box[b[i] - 1].append(a[i])
for i in range(len(box[0])):
    s.append([1, box[0][i]])

while len(s) > 0:
    k = s.popleft()

    if ans[k[1] - 2] == -1 and k[1] != 1:
        ans[k[1] - 2] = k[0]

        for i in range(len(box[k[1] - 1])):
            s.append([k[1], box[k[1] - 1][i]])

print('Yes')
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 77956
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

int main() {
  string A, x, C;
  cin >> A >> x >> C;
  cout << A[0] << x[0] << C[0] << endl;
}

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

n, m, x = map(int, input().split())

A = map(int, input().split())
ans1 = 0
ans2 = 0

for a in A:
  if a > x:
    ans1 += 1
  else:
    ans2 += 1

print(min(ans1, ans2))


Measured memory_bytes: 7328
#include<bits/stdc++.h>
#define pb push_back
#define vl vector
#define ll long long
#define ff first
#define ss second
#define fast std::ios::sync_with_stdio(false)
using namespace std;

int main()
{
    fast;
    ll n,m;
    ll i,j;
    cin>>n>>m;
    ll hi[n];
    for(i=0;i<n;i++) cin>>hi[i];
    vector<pair<ll,ll>> p;
    for(i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        p.pb({a,b});
    }
    vl<vl<ll>> v(n);
    for(i=0;i<m;i++)
    {
        v[p[i].ff-1].pb(p[i].ss-1);
        v[p[i].ss-1].pb(p[i].ff-1);
    }
    ll ans=0;
    for(i=0;i<n;i++)
    {
        if(v[i].size()==0) ans++;
        else
        {
            ll flag=1;
            for(j=0;j<v[i].size();j++)
            {
                if(hi[i]<=hi[v[i][j]])
                {
                    flag=0;
                    break;
                }
            }
            if(flag) ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 11440
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int64 sum=0;
  for(i=0;i<n;i++) sum+=a[i];
  int64 x=a[0];
  int64 y=sum-x;
  int64 min=ABS(x-y);
  for(i=1;i<n-1;i++){
    x+=a[i];
    y-=a[i];
    min=MIN(min,ABS(x-y));
  }
  printf("%lld\n",min);
  return;
}

int main(void){
  run();
  return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

ll memo[1000];
ll fib(ll n) {
  if(n == 0) return 2;
  else if(n == 1) return 1;
  else if(memo[n]) return memo[n];
  else return memo[n] = fib(n-1) + fib(n-2);
}

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

  int n; cin >> n;
  vi a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());

  int al = 0, bo = 0;
  for(int i=0;i<n;i += 2) {
    al += a[i];
  }
  for(int i=1;i<n;i += 2) {
    bo += a[i];
  }
  cout << al - bo << endl;
}


Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()

    count = 0

    tmp_list = [i for i in range(1,n)]

    for i in range(1, n):
        insert_index = bisect_right(tmp_list, n//i)
        if i * insert_index == n:
            insert_index -= 1
        count += insert_index

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 147552
/* be name khoda */

// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 200010;

ll n, rt[maxn];
ll ql, qr;
vi pths[maxn];
pii es[maxn], q[maxn];
map<pii, ll> track;
bool vis[maxn];

ll root(ll x) {
    return rt[x] == x ? x : rt[x] = root(rt[x]);
}

void remove(pii e) {
    if (e.F > e.S) swap(e.F, e.S);
    track.erase(e);
}

void add(pii e, ll i) {
    if (e.F > e.S) swap(e.F, e.S);
    if (track.count(e)) {
        vis[i] = vis[track[e]] = 1;
        track.erase(e);
        q[qr++] = e;
    } else {
        track[e] = i;
    }
}

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

    cin >> n;
    fori (i, 2 * n - 2) {
        ll a, b; cin >> a >> b; --a, --b;
        es[i] = {a, b};
        pths[a].eb(i), pths[b].eb(i);
        add(es[i], i);
    }
    iota(rt, rt + n, 0);
    while (ql < qr) {
        auto [a, b] = q[ql++];
        a = root(a), b = root(b);
        if (pths[a].size() > pths[b].size()) swap(a, b);
        rt[a] = b;
        for (auto p : pths[a]) {
            if (vis[p]) continue;
            remove(es[p]);
            es[p] = {root(es[p].F), root(es[p].S)};
            pths[b].eb(p);
            add(es[p], p);
        }
    }
    cout << (ql == n - 1 ? "YES\n" : "NO\n");

}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> a(n, 1);
    vector<int32> b(n, 1);
    REP(i,n){
        int32 p;
        cin >> p;
        p--;
        a[p] += i;
        b[p] += i;
    }
    FOR(i,1,n){
        a[i] += a[i-1];
    }
    FORR(i,n-2,0){
        b[i] += b[i+1];
    }
    REP(i,n)cout << a[i] << " ";
    cout << endl;
    REP(i,n)cout << b[i] << " ";
    cout << endl;
    return 0;
}

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

using namespace std;
constexpr int64_t MOD = 1'000'000'007;

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

    int64_t N;
    cin >> N;
    vector<int64_t> num(60);
    for(int i=0; i<N; i++) {
        int64_t A;
        cin >> A;
        for(int j=0; j<60; j++) {
            if(A & (1LL << j)) {
                ++num[j];
            }
        }
    }

    int64_t ans = 0;
    for(int j=0; j<60; j++) {
        ans += ((((1LL << j) % MOD * num[j]) % MOD) * (N-num[j])) % MOD;
    }

    cout << ans % MOD << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, k;
vector<p> su;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    ll used[n];
    for (int i = 0; i < n; i++)
    {
        used[i] = 0;
    }
    for (int i = 0; i < n; i++)
    {
        ll a, b;
        cin >> a >> b;
        su.push_back(make_pair(b, a - 1));
    }
    sort(ALL(su), greater<p>());
    ll sp = 0;
    ll sum = 0;
    for (int i = 0; i < k; i++)
    {
        if (used[su[i].second] == 0)
        {
            sp++;
        }
        used[su[i].second]++;
        sum += su[i].first;
    }
    ll ans = ll(sum + sp * sp);
    ll m = k - 1;
    if (n == k)
    {
        cout << ans << "\n";
        return 0;
    }
    for (int i = k; i < n; i++)
    {
        if (used[su[i].second] != 0)
            continue;
        for (int j = m; j >= 0; j--)
        {
            if (used[su[j].second] > 1)
            {
                m = j;
                break;
            }
            else if (j == 0)
            {
                cout << ans << "\n";
                return 0;
            }
        }
        sum += ll(-su[m].first + su[i].first);
        sp++;
        ans = max(ans, ll(sum + sp * sp));
        used[su[m].second]--;
        used[su[i].second]++;
        m--;
        if (m == -1)
            break;
    }
    cout << ans << "\n";
}

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

#define int long long
#define pb  push_back
#define eb  emplace_back
#define scan(a,n)  for(int i = 0; i < n;i++)cin >> a[i];
#define print(a,n)  for(int i = 0;i < n;i++)cout <<a[i] <<' ';cout<<endl;
#define w(x)  int x; cin>>x; while(x--)
#define endl  '\n'
#define vi  vector<int>
#define rng(x) x.begin(),x.end()

// Tushar Goyal : Chalie Shuru karte hai

void solve()
{
	int n, m, k, q , cnt = 0, sum = 0;
	cin >> n;

	int ans = n + n * n  + n * n * n;

	cout << ans << endl;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    w(T)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3632
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	//iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve() {
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0) return;
		vector<string> inputs;
		REP(i, h) {
			string s;
			cin >> s;
			inputs.push_back(s);
		}
		int visited[50][50] = {};
		int answer[2] = {};
		REP(i, h) {
			REP(q, w) {
				if (visited[i][q]) continue;
				if (inputs[i][q] != '.') continue;
				int cnt[2] = {};
				visited[i][q] = 1;
				queue<pair<int, int>> next;
				next.push(mp(i,q));
				int ans = 1;
				while (next.empty() == false) {
					pair<int, int> now = next.front();
					next.pop();
					int dx[4] = { 1,-1,0,0 };
					REP(t, 4) {
						int x = dx[t] + now.first;
						int y = dx[3 - t] + now.second;
						if (x >= 0 && x < h && y >= 0 && y < w) {
							if (visited[x][y]) continue;
							if (inputs[x][y] == '.') {
								ans++;
								visited[x][y] = 1;
								next.push(mp(x, y));
								continue;
							}
							if (inputs[x][y] == 'W') {
								cnt[0]++;
								continue;
							}
							if (inputs[x][y] == 'B') {
								cnt[1]++;
								continue;
							}
						}
					}
				}
				if (cnt[0] != 0 && cnt[1] != 0) continue;
				if (cnt[0] != 0) {
					answer[0] += ans;
				}
				else  if(cnt[1] != 0){
					answer[1] += ans;
				}
			}
		}
		cout << answer[1] << " " << answer[0] << endl;
	}
}
#undef int
int main() {
	init();
	solve();
}


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

int main()
{
  int n = 0;
  int a[300],b[300];
  while(n < 300)
  {
    cin >> a[n] >> b[n];
    if(a[n] == 0 && b[n] ==0)break;
    n ++;
  }
  for(int i = 0; i <= n; i++)
  {
    for(int j = 0; j < a[i];j++)
    {

      for(int k = 0 ; k < b[i] ; k++)
      {
        if((k+j)%2 == 0)cout << '#';
        else cout << '.';
      }
      cout <<endl;

    }
    if(i < n)cout << endl;

  }
  return 0;
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, m; cin >> n >> m;
  vvi g(n);
  REP(i, m) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  vector<bool> sel(n);
  sel[0] = 1;
  int pos = 0;
  vi ans1;
  ans1.pb(1);
  while(1) {
    bool upd = false;
    REP(i, SZ(g[pos])) {
      if(!sel[g[pos][i]]) {
        pos = g[pos][i];
        sel[pos] = 1;
        ans1.pb(pos+1);
        upd = true;
        break;
      }
    }
    if(!upd) break;
  }
  pos = 0;
  vi ans2;
  ans2.pb(1);
  while(1) {
    bool upd = false;
    REP(i, SZ(g[pos])) {
      if(!sel[g[pos][i]]) {
        pos = g[pos][i];
        sel[pos] = 1;
        ans2.pb(pos+1);
        upd = true;
        break;
      }
    }
    if(!upd) break;
  }
  reverse(ALL(ans2));

  cout << SZ(ans1) + SZ(ans2) - 1 << endl;
  REP(i, SZ(ans2)-1) {
    cout << ans2[i] << " ";
  }
  REP(i, SZ(ans1)) {
    cout << ans1[i];
    if(i == SZ(ans1)-1) cout << endl;
    else cout << " ";
  }
}


Measured memory_bytes: 6776
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func main() {
	n := nextInt()
	as := make([]int, n+1)
	nn := make([]int, n+1)

	for i := 1; i <= n; i++ {
		as[i] = nextInt()
	}

	for i := n; i > 0; i-- {
		var sum int
		for j := i + i; j <= n; j += i {
			sum ^= nn[j]
		}
		nn[i] = sum ^ as[i]
	}

	ans := make([]int, 0, n+1)

	for idx, item := range nn {
		if item == 1 {
			ans = append(ans, idx)
		}
	}
	l := len(ans)
	fmt.Printf("%#v\n", l)
	if l > 0 {
		for _, item := range ans {
			fmt.Printf("%v ", item)
		}
		fmt.Println()
	}

}

func Divisors(n int) []int {
	divisors := make([]int, 0, 1000)
	end := int(math.Pow(float64(n), 0.5) + 1)
	for i := 1; i < end; i++ {
		if n%i == 0 {
			divisors = append(divisors, i)
			if v := n / i; i != n/i {
				divisors = append(divisors, v)
			}
		}

	}
	return divisors
}


Measured memory_bytes: 6144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int taro = 0;
		int hanako = 0;
		for(int i = 0; i < N; i++) {
			String[] set = br.readLine().split(" ");

			if(set[0].compareTo(set[1]) > 0) {
				taro += 3;
			} else if (set[0].compareTo(set[1]) < 0) {
				hanako += 3;
			} else {
				taro += 1;
				hanako += 1;
			}
		}
		System.out.println(taro + " " + hanako);
	}
}

Measured memory_bytes: 24820
a, b, c, k = map(int, input().split())
card = 0
if k >= a:
    card += a
    k -= a
    if k >= b:
        k -= b
        if k > 0:
            card -= k
            print(card)
        else:
            print(card)
    else:
        print(card)
else:
    print(k)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

bool prime[1000005];

int main(){
    prime[1] = true;
    for(int i = 2;i < 1000000;i++){
        if(prime[i] == false){
            for(int j = 2;i*j < 1000000;j++){
                prime[i*j] = true;
            }
        }
    }
    while(true){
        int a,d,n;
        cin >> a >> d >> n;
        if(a + d + n == 0) break;
        int count = 0;
        for(int i = 0;a+d*i < 1000000;i++){
            if(prime[a+d*i] == false){
                count++;
                if(count == n){
                    cout << a+d*i << endl;
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 4040
#include<iostream>
using namespace std;
int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == 5 || a == 7){
    if(b == 5 || b == 7) {
      if(c == 5 || c == 7){
        if((a + b + c) == 17){
          cout << "YES" << endl;
          return 0;
        }
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        XXOR solver = new XXOR();
        solver.solve(1, in, out);
        out.close();
    }

    static class XXOR {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long k = in.nextLong();
            long[] a = new long[n];
            long max = k;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
                max = Math.max(max, a[i]);
            }

            // 桁数 | 未満フラグ
            long[][] dp = new long[100][2];

            int dnum = 0;
            for (int i = 0; i <= 50; i++) {
                dp[i][0] = -1;
                dp[i][1] = -1;
                if ((max >> i) > 0) {
                    dnum++;
                }
            }
            if (k == 0) {
                long result = 0;
                for (long l : a) {
                    result ^= l;
                }
                out.println(result);
                return;
            }
            dp[0][0] = 0;
            for (int i = 0; i < dnum; i++) {
                int shift = dnum - i - 1;
                long mask = 1L << shift;
                long one = 0;
                for (long l : a) {
                    if ((l & mask) > 0L) {
                        one++;
                    }
                }
                long cost0 = mask * one;
                long cost1 = mask * (n - one);

                if (dp[i][1] != -1) {
                    // 未満フラグ立っている
                    dp[i + 1][1] = Math.max(dp[i + 1][1], dp[i][1] + Math.max(cost1, cost0));
                }
                // 未満フラグ立ってない
                if (dp[i][0] != -1) {
                    // ぴったり->未満
                    if ((k & mask) > 0L) {
                        // kのbitが立っていたときに未満にできる
                        dp[i + 1][1] = Math.max(dp[i + 1][1], dp[i][0] + cost0);
                    }

                    // ぴったり->ぴったり
                    if ((k & mask) > 0L) {
                        dp[i + 1][0] = Math.max(dp[i + 1][0], dp[i][0] + cost1);
                    } else {
                        dp[i + 1][0] = Math.max(dp[i + 1][0], dp[i][0] + cost0);
                    }

                }
            }
            out.print(Math.max(dp[dnum][0], dp[dnum][1]));
        }

    }
}



Measured memory_bytes: 61024
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

const double PI = acos(-1.0);

double A, B, H, M;
double xh, yh, xm, ym;

void calcu_rot(void) {
	double tm = -M * 6.0;
	if (tm < -180.0)
		tm += 360.0;
	tm = tm * PI / 180.0;
	xm = sin(tm) * B;
	ym = cos(tm) * B;

	double th = -(60.0 * H + M) * 0.5;
	if (th < -180.0)
		th += 360.0;
	th = th * PI / 180.0;
	xh = sin(th) * A;
	yh = cos(th) * A;
}

double calcu_dis(void) {
	double x2 = (xm - xh) * (xm - xh);
	double y2 = (ym - yh) * (ym - yh);
	double d = sqrt(x2 + y2);
	return d;
}

int main(void) {
	cin >> A >> B >> H >> M;

	calcu_rot();
	double ans = calcu_dis();

	cout << fixed << setprecision(12) << ans << '\n';
	return 0;
}


Measured memory_bytes: 4164
import numpy as np
import sys

n = int(sys.stdin.next())
values = np.array(map(int, sys.stdin.next().rstrip(' ').split(' ')))

arr = np.array([0] * n)

arr[1] = abs(values[1] - values[0])
for i in xrange(2, n):
    arr[i] = min(arr[i-2] + abs(values[i] - values[i-2]), arr[i-1] + abs(values[i] - values[i-1]))

print arr[n-1]


Measured memory_bytes: 18704
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<set>
#include<iomanip>
using namespace std;
using ll=long long int ;

ll gcd(ll p, ll q) {
	if (q == 0)return p;
	else return gcd(q, p % q);
}
ll lcm(ll p, ll q) {
	return  p * q / gcd(p, q);
}


int main() {

	ll  a, b, c, d;
	cin >> a >> b >> c >> d;

	ll bc = b / c;
	ll bd = b / d;
	
	ll ac = (a-1) / c;
	ll ad = (a-1)/ d;

	ll e = lcm(c,d);

	ll be = b / e;
	ll ae = (a-1) / e;

	cout << b - a + 1 - (bc - ac) - (bd - ad) + (be - ae) << endl;
	
		return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    static long[] sum;
    static int n;
    static long tot = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int K = sc.nextInt();
        sum = new long[n+1];
        for(int i=1;i<=n;i++) {
            sum[i] = sum[i-1]+sc.nextInt()-K;
        }
        // kind of like reverse number problem. Here we want to count how many (i,k) s.t. 0<=i<k<=n&&sum[i]<=sum[k];
        merge(0,n);
        System.out.println(tot);
    }
    static void merge(int left, int right){
        if(left>=right) return;
        int mid = (left+right)/2;
        merge(left,mid);
        merge(mid+1,right);
        int i=left,j=mid+1,k=0;
        long[] temp = new long[right-left+1];
        while(i<=mid&&j<=right){
            if(sum[i]<=sum[j]) {
                tot += mid-i+1;
                temp[k++] = sum[j++];
            }
            else temp[k++] = sum[i++];
        }
        while(i<=mid) temp[k++] = sum[i++];
        while(j<=right) temp[k++] = sum[j++];
        for(int m=0;m<temp.length;m++) sum[left+m] = temp[m];
    }
}


Measured memory_bytes: 92328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct Sieve_prime{
  vector<int> f, primes;
  int n;
  Sieve_prime(int n = 1): n(n), f(n +1){
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; i++){
      if(f[i])continue;
      primes.emplace_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i){
        //この条件をつけると最小素因数が記録される
        //つけないと最大素因数が記録される。
        if(!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorlist(int x){
    vector<int> res;
    while (x != 1){
      res.emplace_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorlist(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

ll gcd(ll a, ll b) {
  ll smaller = min(a, b);
  ll bigger = max(a, b);
  ll surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  surplus = gcd(smaller, surplus);
  return surplus;
}

int main() {
  Sieve_prime sieve(1e6);
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  int all_gcd = A[0];
  map<int, int> mp;
  rep(i, n){
    auto f = sieve.factor(A[i]);
    for (auto p : f) {
      mp[p.first]++;
    }
    all_gcd = gcd(all_gcd, A[i]);
  }
  int coprime = 1;
  for (auto k : mp){
    if(k.second > 1){
      coprime = 0;
      break;
    }
  }
  
  if(all_gcd != 1){
    cout << "not coprime" << endl;
  }else if(all_gcd == 1 && coprime == 0){
    cout << "setwise coprime" << endl;
  }else{
    cout << "pairwise coprime" << endl;
  }
}

Measured memory_bytes: 14880
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int m[10];

	for (int i = 0; i < 10; i++)cin >> m[i];

	stable_sort(m, m + 10);

	for (int i = 9; i > 6; i--)cout << m[i] << endl;

	return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int n, k; cin >> n >> k;
	cout << n - k + 1 << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.function.BiConsumer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			StringBuilder p = new StringBuilder();
			StringBuilder q = new StringBuilder();
			for (int i = 0; i < n; i++) {
				p.append(in.next());
			}
			for (int i = 0; i < n; i++) {
				q.append(in.next());
			}
			StringBuilder sb = new StringBuilder();
			for (int i = 1; i <= n; i++) {
				sb.append(i);
			}
			List<String> list = new ArrayList<String>();
			permutation(sb.toString(), "", list);
			int a = 0;
			int b = 0;
			for (int i = 0; i < list.size(); i++) {
				if (p.toString().equals(list.get(i).toString())) {
					a = i + 1;
				}
				if (q.toString().equals(list.get(i).toString())) {
					b = i + 1;
				}
			}
			out.println(Math.abs(a - b));
		}
	}

	static void permutation(String q, String ans, List<String> list) {
		// Base Case
		if (q.length() <= 1) {
			list.add(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1), ans + q.charAt(i), list);
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		public char nextChar() {
			return next().charAt(0);
		}

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

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

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

	}
}


Measured memory_bytes: 48256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

template <typename T>
int gcd(T a, T b){ return b%a==0 ? a : gcd(b%a, a); }

int main()
{
    int n,x;
    cin >> n >> x;
    vector<int> xi(n+1);
    rep(i,n) cin >> xi[i];
    xi[n] = x;
    sort(xi.begin(),xi.end());
    vector<int> d(n);
    rep(i,n) d[i] = xi[i+1] - xi[i];

    int g = d[0];
    rep(i,n)
        g = gcd(g,d[i]);

    cout << g << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

void out(){cout << "\n";}
template<class T,class... Args>
void out(const T &x,const Args &... args){
	cout << x << " ";
	out(args...);
}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	string s,t;
	cin >> n >> m >> s >> t;
	bool b=true;
	rep(i,n){
		if(i*m%n==0 && s[i]!=t[i*m/n]) b=false;
	}
	if(b) cout << lcm(m,n) << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }

    return true;
}
string s;
int main(void){
    cin >> s;
    for (int i = 0; i < s.size(); i+=2) {
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3676
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

N,C,*H = map(int,read().split())

class CHT:
    """
    f_i = a_ix + b_i とする。f_i の追加および、min_i f(x) の取得ができるデータ構造。
    ただし、傾き a_i は昇順に追加されなければならない。
    また、クエリ x も昇順に実行されなければならない。
    """
    def __init__(self):
        self.funcs = deque()

    def add(self,a,b):
        funcs = self.funcs
        while len(funcs) >= 2:
            a1,b1 = funcs[-2]
            a2,b2 = funcs[-1]
            if (a2-a1)*(b-b2) < (b2-b1)*(a-a2):
                break
            funcs.pop()
        funcs.append((a,b))

    def query(self,x):
        funcs = self.funcs
        a,b = funcs[0]
        y = a*x+b
        while len(funcs) >= 2:
            a2,b2 = funcs[1]
            y2 = a2*x+b2
            if y < y2:
                break
            y = y2
            funcs.popleft()
        return y

dp = [0] * N
cht = CHT()
add = cht.add; query = cht.query

h = H[0]
add(-2*h, h*h)
for i,h in enumerate(H[1:],1):
    x = query(h) + h*h + C
    dp[i] = x
    add(-2*h, h*h + x)

answer = dp[-1]
print(answer)

Measured memory_bytes: 41540
#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, x;
    cin >> n >> x;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int p;
        cin >> p;
        p = abs(p - x);
        ans = __gcd(ans, p);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256