akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int dayofweek(int year, int month, int day)
{
	struct tm  t;

	t.tm_year = year - 1900;    /* ??´????????´ */
	t.tm_mon = month - 1;        /* ???????????´ */
	t.tm_mday = day;            /* ??\ */
	t.tm_hour = 0;                /* ??? */
	t.tm_min = 0;                /* ??? */
	t.tm_sec = 0;                /* ?§? */
	t.tm_isdst = -1;            /* ????????? */

	if (mktime(&t) == -1)        /* ???????????±??? */
		return (-1);
	return (t.tm_wday);
}

int main() {
	map<int, string>m;
	m[0] = "Sunday";
	m[1] = "Monday";
	m[2] = "Tuesday";
	m[3] = "Wednesday";
	m[4] = "Thursday";
	m[5] = "Friday";
	m[6] = "Saturday";
	while (1) {
		int a, b; cin >> a >> b;
		if (!a)break;
		int num = dayofweek(2004, a, b);
		cout << m[num] << endl;
	}
	return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define end1l '\n'
typedef long long ll;
typedef long double ld;

int n,m;
int a[100000+10];
vector<int> start[100000+10];
vector<int> end1[100000+10];

int diff(int a,int b){
    if(b>a){
        return (b-a);
    }
    else{
        return (m+b-a);
    }
}

int main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    cin>>n>>m;
    rep(i,0,n){
        cin>>a[i];
    }
    ll total = 0;
    rep(i,0,n-1){
        start[a[i]].pb(a[i+1]);
        end1[a[i+1]].pb(a[i]);
        if(a[i+1]>a[i]){
            total+=(a[i+1]-a[i]);
        }
        else{
            total+=(m+a[i+1]-a[i]);
        }
    }
    ll ans = total;
    ll sum1 = 0;
    ll cnt = 0;
    rep(i,0,n-1){
        if(a[i+1]<a[i]){
            sum1+=(m+1-a[i]-1);
            cnt++;
        }
    }
    ans=min(ans,total-sum1);
    rep(i,2,m+1){
        int k = i-1;
        iter(it,end1[k]){
            sum1-=(diff((*it),k)-1);
            cnt--;
        }
        sum1+=(cnt);
        iter(it,start[k]){
            cnt++;
        }
        ans=min(ans,total-sum1);
    }
    cout<<ans<<end1l;
}

Measured memory_bytes: 9984
n = gets.to_i

c, s, f = [], [], []
(n-1).times do
  ci, si, fi = gets.chomp.split.map(&:to_i)
  c << ci
  s << si
  f << fi
end
c << 0
s << 1
f << 1
# なんとなくシミュレーションする
# 終点だったら終了
# (次の待ち時間)+次への乗車時間
# - 次の発車時間 == 到着時間 -> すぐ乗れる
# - 到着時間 < 次の始発 -> 始発に乗る
# - それ以外（待ち時間） -> 到着時間 + （到着時間-(到着時間/発車間隔+1)*発車間隔）
n.times do |i|
  now = 0
  (i...n-1).each do |j|
    if now < s[j]
      now = s[j]
    elsif (now % f[j]).zero?
      # なにもしない
    else
      # now += now-(now/f[j+1]+1)*f[j+1]
      # now = now + f[j+1]-now%f[j+1] # (now/f[j+1]+1)*f[j+1]
      now = now + f[j]-now%f[j] # (now/f[j+1]
    end
    now += c[j]
  end
  puts now
end

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >>b >>c;
    if(c<=a) cout <<"0"<< endl;
    else
        if(a+b<c) cout<< "NA" << endl;
            else cout << c-a<< endl;
return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
queue<pair<int, int> > q;
int main () {
    int h, w;
    cin >> h >> w;
    bool white[h + 1][w + 1];
    int count[h + 1][w + 1];
    memset(count, -1, sizeof(count));
    int whitecount = 0;
    for (int i = 1; i <= h; i++) {
        string s;
        cin >> s;
        for (int j = 1; j <= w; j++) {
            if (s[j - 1] == '.') {
                white[i][j] = true;
                whitecount++;
            }
            else {
                white[i][j] = false;
            }
        }
    }
    q.push(make_pair(1, 1));
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    count[1][1] = 0;
    while (q.size()) {
        pair<int, int> p = q.front();
        if ((p.first == h) && (p.second == w)) {
            break;
        }
        q.pop();
        for (int i = 0; i < 4; i++) {
            int nextx = p.first + dx[i];
            int nexty = p.second + dy[i];
            if ((1 <= nextx) && (nextx <= h) && (1 <= nexty) && (nexty <= w) && (count[nextx][nexty] == -1) && (white[nextx][nexty])) {
                count[nextx][nexty] = count[p.first][p.second] + 1;
                q.push(make_pair(nextx, nexty));
            }
        }
    }
    if (count[h][w] == -1) {
        cout << -1 << endl;
    }
    else {
        cout << whitecount - count[h][w] - 1 << endl;
    }
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<pii> vp;
  rep(i, n) {
    int a;
    cin >> a;
    vp.eb(mp(a, i + 1));
  }
  sort(all(vp));
  rep(i, n) cout << vp[i].S << ' ';
  cout << endl;
}


Measured memory_bytes: 1780
package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var wr *bufio.Writer = bufio.NewWriter(os.Stdout)

func nextInt() int {
	sc.Scan()
	val, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return val
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

type edge struct {
	to  int
	col int
	idx int
}

func main() {
	sc.Split(bufio.ScanWords)
	//
	A, B, C, D, E, F := nextInt(), nextInt(), nextInt(), nextInt(), nextInt(), nextInt()
	wl := make([]int, 0, 3001)
	sl := make([]int, 0, 3001)
	G := F * E / 100
	for a := 0; a <= F/(100*A); a++ {
		for b := 0; b <= F/(100*B); b++ {
			if 100*(A*a+B*b) > F {
				continue
			}
			wl = append(wl, 100*(A*a+B*b))
		}
	}
	for c := 0; c <= G/C; c++ {
		for d := 0; d <= G/D; d++ {
			if (C*c + D*d) > F {
				continue
			}
			sl = append(sl, C*c+D*d)
		}
	}
	rr := float64(-1)
	rw, rs := 0, 0
	for _, w := range wl {
		for _, s := range sl {
			if w+s > F {
				continue
			}
			if w*E/100 < s {
				continue
			}
			r := float64(s) / float64(w+s)
			if r > rr {
				rr = r
				rw = w
				rs = s
			}
		}
	}
	fmt.Fprintln(wr, fmt.Sprintf("%d %d", rw+rs, rs))
	wr.Flush()
}


Measured memory_bytes: 7168
#include <iostream>
#include <string>
#include <functional>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

int d[10];

int main() {
	for (int i = 1; i <= 3; i++) {
		int x, y;
		cin >> x >> y;
		d[x]++;
		d[y]++;
	}
	int mx = 0;
	for (int i = 1; i <= 4; i++) mx = max(mx, d[i]);
	puts(mx <= 2 ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int[] l = new int[N];
        for (int i = 0; i < N; i++) {
            l[i] = scan.nextInt();
        }
        Arrays.sort(l);
        int answer = Integer.MAX_VALUE;
        int[] three = new int[3];
        for (int i = 1; i < 1 << N; i++) {
            for (int j = 1; j < 1 << N; j++) {
                if (0 < (i & j)) {
                    continue;
                }
                for (int k = 1; k < 1 << N; k++) {
                    if (0 < (i & k) || 0 < (j & k)) {
                        continue;
                    }
                    three[0] = total(l, i);
                    three[1] = total(l, j);
                    three[2] = total(l, k);
                    int count = count(l, i) + count(l, j) + count(l, k);
                    answer = Math.min(answer, (count - 3) * 10 + Math.abs(A-three[0]) + Math.abs(B-three[1]) + Math.abs(C-three[2]));
                }
            }
        }
        System.out.println(answer);
    }
    private int total(int[] l, int pairs) {
        int current = 0;
        int total = 0;
        while(0 < pairs) {
            if ((pairs & 1) == 1) {
                total += l[current];
            }
            pairs >>= 1;
            current += 1;
        }
        return total;
    }
    private int count(int[] l, int pairs) {
        int total = 0;
        while(0 < pairs) {
            if ((pairs & 1) == 1) {
                total += 1;
            }
            pairs >>= 1;
        }
        return total;
    }
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
template<typename T> using Graph = vector<vector<T>>;

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

    int N, M, K;
    cin >> N >> M >> K;
    vi a(N), b(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];

    int ans = -1;
    rep(s, 1 << N) {
        if (__builtin_popcount(s) != K) {
            continue;
        }
        vector<Pii> vp;
        rep(i, N) {
            if ((s >> i) & 1) {
                vp.emplace_back(a[i], b[i]);
            }
        }
        sort(all(vp));
        reverse(all(vp));
        int tmp = 0;
        int res = M;
        for (auto p : vp) {
            int a, b;
            tie(a, b) = p;
            tmp += a * min(res, b);
            res -= min(res, b);
        }
        ans = max(ans, tmp + res);
    }
    cout << ans << endl;
}

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

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

#define int ll
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define sz(x) int(x.size())

const int MOD = 1e9 + 7;

struct mi {
	int value;
	mi(ll x = 0) : 
		value(int(x % MOD)) {}
};
mi operator+(mi a, mi b) {
	return (a.value + b.value) % MOD;
}
void operator+=(mi &a, mi b) {
	a = a + b;
}
mi operator-(mi a, mi b) {
	return (a.value + MOD - b.value) % MOD;
}
void operator-=(mi &a, mi b) {
	a = a - b;
}
mi operator*(mi a, mi b) {
	return (ll)a.value * b.value % MOD;
}
void operator*=(mi &a, mi b) {
	a = a * b;
};
mi powmod(mi a, int p) {
	mi x = 1;
	for (; p > 0; p >>= 1) {
		if (p & 1) {
			x *= a;
		}
		a *= a;
	}
	return x;
}
mi inv(mi a) {
	return powmod(a, MOD - 2);
}
mi operator/(mi a, mi b) {
	return a * inv(b);
}
void operator/=(mi &a, mi b) {
	a = a / b;
}
ostream &operator<<(ostream &out, mi a) {
	return out << a.value;
}

const int N = 1e6 + 100;
vector<int> g[N];
int n;
int s[N];

void dfs(int v, int p) {
	s[v] = 1;
	for (int u : g[v]) {
		if (u == p) {
			continue;
		}
		dfs(u, v);
		s[v] += s[u];
	}
}

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int v;
		int u;
		cin >> v >> u;
		--v;
		--u;
		g[v].pb(u);
		g[u].pb(v);
	}
	dfs(0, -1);
	
	mi edges = 0;
	for (int v = 0; v < n; ++v) {
		for (int u : g[v]) {
			assert(s[v] != s[u]);
			if (s[v] < s[u]) {
				continue;
			}
			int sv = n - s[u];
			int su = s[u];
			mi pr = (1 - inv(powmod(2, sv))) * (1 - inv(powmod(2, su)));
			edges += pr;
		}
	}
	mi answer = edges + 1 - inv(powmod(2, n)) - mi(n) / 2;
	cout << answer << "\n";
	return 0;
}


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

#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)

int main(){
    int p,q;
    method(gcd,int,int a,int b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    };
    method(func,int,int x){
        int res = 1;
        for(int i=2;i*i<=x;++i){
            bool flag = false;
            while(x%i==0){
                x /= i;
                flag = true;
            }
            if(flag)res *= i;
        }
        res *= x;
        return res;
    };
    cin >> p >> q;
    cout << func(q /gcd(p,q)) << endl;
    return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
struct node{
	int sumy;
	int val;
};
int n;
int hed[N],tal[N<<1],val[N<<1],nxt[N<<1],cnt=0;
int nod[N];
int bot[16];
int sum=0;
int q[16],t=0;
int sxr[1<<17];
int d[1<<17];
void addege(int x,int y,int z){
	cnt++;
	tal[cnt]=y;
	val[cnt]=z;
	nxt[cnt]=hed[x];
	hed[x]=cnt;
} 
void dfs(int u,int fa){
	for(int i=hed[u];i;i=nxt[i]){
		int v=tal[i];
		if(v==fa) continue;
		nod[v]^=val[i];
		dfs(v,u);
		nod[u]^=val[i];
	}
}
bool cmp(node x,node y){
	return x.sumy>y.sumy;
}
int st=0;
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		x++,y++;
		addege(x,y,z);
		addege(y,x,z);
	}
	dfs(1,1);
	//for(int i=1;i<=n;i++) cout<<nod[i]<<endl;
	for(int i=1;i<=n;i++) bot[nod[i]]++;
	for(int i=1;i<=15;i++) sum+=bot[i]/2,st|=(bot[i]&1)<<(i-1);	
	for(int i=1;i<(1<<15);i++) d[i]=d[i>>1]+(i&1);
    for(int i=1;i<(1<<15);i++) d[i]-=1;
    for(int i=1;i<(1<<15);i++)
        for(int j=0;j<15;j++)
			if((i>>j)&1)
				sxr[i]^=(j+1);
    for(int i=1;i<(1<<15);i++)
    {
        if(sxr[i]!=0) continue;
        for(int k=(i-1)&i;k;k=(k-1)&i)
            if(sxr[k]==0)d[i]=min(d[i],d[k]+d[i^k]);
    }
    cout<<d[st]+sum<<endl;
	return 0;
} 

Measured memory_bytes: 14432
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
#define dmp make_pair
#define fi first
#define se second
const int inf = 1e9;
const int INF = 1e18;
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = 1;i <= n;i++)

int q[200002][3], ran[100002];
pair<int,int> p[100002];
P find(int x, int y){
	if(p[x].fi == x)return P(x, y);
	else {
		p[x] = find(p[x].fi, p[x].se);
		return P(p[x].fi, p[x].se+y);
	}
}

bool unite(int xx, int yy, int d){
	P x = find(xx, 0);
	P y = find(yy, 0);
	if(x.fi == y.fi){
		if(x.se+d == y.se)return 0;
		else return 1;
	}
	if(ran[x.fi] < ran[y.fi]){
		p[x.fi] = P(y.fi, y.se-d-x.se);
	}else{
		p[y.fi] = P(x.fi, x.se+d-y.se);
		if(ran[x.fi] == ran[y.fi])ran[x.fi]++;
	}
	return 0;
}


signed main(){
	int n, m;
	scanf("%lld%lld", &n, &m);
	rep(i,m)rep(j,3)scanf("%lld", &q[i][j]);
	rep(i,n){
		p[i].fi = i;
		ran[i] = 0;
	}
	
	for(int i = 0;i < m;i++){
		int l = q[i][0]-1, r = q[i][1]-1, d = q[i][2];
		if(unite(l, r, d)){
			printf("No\n");
			return 0;
		}
	}
	
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int x[100], y[100], h[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ii = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] != 0)
            ii = i;
    }

    for (int i = 0; i <= 100; ++i)
    {
        for (int j = 0; j <= 100; ++j)
        {
            bool good = true;
            int h = ::h[ii] + abs(i - x[ii]) + abs(j - y[ii]);
            for (int k = 0; k < n && good; ++k)
            {
                if (::h[k])
                {
                    if (::h[k] + abs(i - x[k]) + abs(j - y[k]) != h)
                        good = false;
                }
                else
                {
                    if (abs(i - x[k]) + abs(j - y[k]) < h)
                        good = false;
                }
            }

            if (good)
                cout << i _ j _ h << '\n';
        }
    }
}


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

int main()
{
    int N;
    cin >> N;
    unsigned long long res = 0;
    for(int i=0; i<=N; i++){
        if(i%3 != 0 && i%5 != 0) res += i;
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

typedef complex<double> cd;

const int LG = 18;
const int SZ = (1 << LG);
const double PI = acos(-1);

int bitreverse[SZ];

int Bitreverse(int x)
{
    int y = 0;
    for (int i = 0; i < LG; i++)
    {
        y = y * 2 + (((1 << i) & x) > 0);
    }
    return y;
}

int k;

vector<cd> copier;
cd was[2][LG + 1][SZ + 1];

void precompute(int fl)
{
    for (int len = 1; len <= LG; len++)
    {
        double ang = 2 * PI / (1 << len) * fl;
        cd wlen(cos(ang), sin(ang));
        cd w(1, 0);
        for (int j = 0; j < (1 << (len - 1)); j++)
        {
            was[fl > 0][len][j] = w;
            w = w * wlen;
        }
    }
}

vector<cd> dft(const vector<cd> & a, const int & fl)
{
    vector<cd> b(SZ);
    for (int i = 0; i < SZ; i++)
        b[i] = a[bitreverse[i]];
    for (int len = 1; len <= LG; len++)
    {
        for (int i = 0; i < SZ; i += (1 << len))
        {
            for (int j = 0; j < (1 << (len - 1)); j++)
            {
                cd u = b[i + j], v = b[i + j + (1 << (len - 1))] * was[fl > 0][len][j];
                b[i + j] = u + v;
                b[i + j + (1 << (len - 1))] = u - v;
            }
        }
    }
    return b;
}

vector<int> fft(const vector<int> & b0)
{
    vector<cd> b(SZ), c(SZ);
    vector<int> r(SZ);
    for (int i = 0; i < SZ; i++) b[i].real(b0[i]);
    b = dft(b, 1);
    for (int i = 0; i < SZ; i++) c[i] = copier[i] * b[i];
    c = dft(c, -1);
    for (int i = 0; i < SZ; i++) r[i] = round(c[i].real() / SZ);
    return r;
}

signed main()
{
    precompute(1);
    precompute(-1);
    cin >> k;
    for (int i = 0; i < SZ; i++) bitreverse[i] = Bitreverse(i);
    while (k % 2 == 0) k /= 2;
    while (k % 5 == 0) k /= 5;
    if (k == 1)
    {
        cout << 1;
        return 0;
    }
    vector<int> reach(SZ);
    int klik = 1;
    for (int i = 0; ; i++)
    {
        reach[klik] = 1;
        klik = klik * 10 % k;
        if (klik == 1)
            break;
    }
    vector<int> b = reach;
    reach[0] = 1;
    vector<cd> rr(SZ);
    for (int i = 0; i < SZ; i++) rr[i].real(reach[i]);
    copier = dft(rr, 1);
    for (int i = 1; i <= 45; i++)
    {
        if (b[0] > 0)
        {
            cout << i;
            return 0;
        }
        b = fft(b);
        for (int j = k; j < 2 * k; j++)
        {
            if (b[j] > 0)
            {
                b[j - k] = 1;
                b[j] = 0;
            }
        }
        for (int j = 0; j < k; j++)
            if (b[j]) b[j] = 1;
    }
}


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

constexpr int SIZE = 3;
constexpr int N = SIZE * SIZE;
constexpr int correct = 'a' - 'A';

string pieces[N];

int ans;
int turn[SIZE][SIZE];
int put[SIZE][SIZE];
bool used[N];

inline bool match(char a, char b) {
	return abs(a - b) == correct;
}

void dfs(int x, int y) {
	if(x == SIZE) return dfs(0, y + 1);
	if(y == SIZE) {
		++ans;
		return;
	}

	int &i = put[y][x];
	int &r = turn[y][x];

	for(i = 0; i < N; ++i) {
		if(used[i]) continue;

		for(r = 0; r < 4; ++r) {
			if(x && !match(pieces[i][(r+3)%4], pieces[put[y][x-1]][(turn[y][x-1]+1)%4])) continue;
			if(y && !match(pieces[i][r], pieces[put[y-1][x]][turn[y - 1][x] ^ 2])) continue;

			used[i] = true;
			dfs(x + 1, y);
			used[i] = false;
		}
	}
}


void solve() {
	for(auto &e : pieces) cin >> e;
	ans = 0;
	dfs(0, 0);
	cout << ans << endl;
}

int main() {
	int t;
	cin >> t;
	while(t--) solve();

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int H,W;
    cin >> H >> W;

    int a = 0;
    rep(i,H) rep(j,W) {
        char b;
        cin >> b;
        if(b == '#') a++;
    }
    
    cout << (a == H+W-1 ? "Possible" : "Impossible") << endl;
    
    
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
/**/
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

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

	int N;
	cin>>N;
	long long res = 1;
	for(int i = 2;i <= N;i++) {
		bool prime = true;
		for(int j = 2;j * j <= i;j++) {
			if(i%j == 0) {
				prime = false;
				break;
			}
		}
		if(!prime)
			continue;
		long long pw = 0;
		for(long long j = 1,p = i;p <= N;p*=i,j++) {
			pw = (pw + N / p);
			if(pw >= mod)
				pw -= mod;
		}
		res = res * (pw + 1) % mod;
	}
	cout<<res<<'\n';
	return 0;
}
/**/


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;
const int Maxa=200000;


signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    Vs s(n);
    REP(i,0,n) cin>>s[i];
    
    map<Vi,int> ma;
    REP(i,0,n){
        Vi t(26,0);
        REP(j,0,10){
            t[ s[i][j]-'a' ]++;
        }
//        REP(j,0,26) cout<<t[j]<<" ";
        ma[t]++;
    }
    
    int ans=0;
    for(auto x : ma){
        if(x.second>=2) ans += x.second*(x.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

const int MAXN = 100000;
const ll MOD = 998244353;

int n;
char str[1000100];
int num2[1000100];

int main(){
	scanf("%d",&n);
	scanf("%s",str);
	for (int i=0;i<n;i++) str[i] -= '1';
	for (int i=0;i<=n;i++) {
		int x = 0, p = i;
		while(p) {
			x += p/2;
			p/=2;
		}
		num2[i] = x;
	}
	bool exi1 = 0;
	for (int i=0;i<n;i++) {
		if (str[i]==1) exi1 = 1;
	}
	if (!exi1) {
		int c = 0;
		for (int i=0;i<n;i++) {
			int x = (num2[n-1]-num2[i]-num2[n-1-i]>0?0:1);
			c ^= x*(str[i]/2);
		}
		printf("%d\n",c*2);
		return 0;
	}
	int c = 0;
	for (int i=0;i<n;i++) {
		int x = (num2[n-1]-num2[i]-num2[n-1-i]>0?0:1);
		c ^= x*(str[i]==1?1:0);
	}
	printf("%d\n",c);

	return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define pii pair<ll,ll>
const int M=1e9+7;
vector<pii > V[300];
ll f[300],n,m;
int T;
int main(){
	V[1].push_back(mp(1,2));
	V[1].push_back(mp(1,3));
	V[1].push_back(mp(1,4));
	f[0]=f[1]=1;
	for (int i=2;i<300;i++)f[i]=f[i-1]+f[i-2];
	for (int i=1;i;i++){
		if (f[i+1]>1e18)break;
		for (pii j:V[i]){
			ll x=j.fi,y=j.fi;
			while (y+j.se<=f[i+3]+f[i]){
				y+=j.se;
				V[i+1].push_back(mp(j.se,y));
			}
		}
	}
	scanf("%d",&T);
	while (T--){
		scanf("%lld%lld",&n,&m);
		if (n>m)swap(n,m);
		int ans=1;
		for (;f[ans+1]<=n&&f[ans+2]<=m;ans++);
		printf("%d ",ans);
		if (ans==1){
			printf("%lld\n",n*m%M);
			continue;
		}
		ll ans2=0;
		for (pii j:V[ans-1]){
			if (j.se<=n&&j.se<=m)(ans2+=(m-j.fi)/j.se)%=M;
			if (j.se<=m&&j.fi<=n)(ans2+=(n-j.fi)/j.se)%=M;
		}
		printf("%lld\n",ans2);
	}
}


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

void message(int, int, int);

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

	if (a < b) 
	{
		if (b < c)	message(a, b, c);
		else
		{
			if (a < c)	message(a, c, b);
			else message(c, a, b);
		}
	}
	else
	{
		if (a < c)	message(b, a, c);
		else
		{
			if (b < c)	message(b, c, a);
			else message(c, b, a);
		}
	}

	return 0;

}

void message(int x, int y, int z) {
	cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 1160
import bisect
n = int(input())

a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = sorted([int(i) for i in input().split()])

ans = 0
for i in b:
    x = bisect.bisect(c,i)
    y = bisect.bisect_left(a,i)
    ans += (n-x) * y
    
print(ans)

Measured memory_bytes: 22720
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s ; i < t ; ++i)
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define UNIQ(a) a.erase(unique(ALL(a)),a.end())
#define debug(a) cerr<<#a":="<<a<<endl
using LL = long long; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>;

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

	int C[] = { 1,5,10,50,100,500 };
	int sum = 0;
	FOR(i, 0, 6) {
		int a; cin >> a;
		sum += a * C[i];
	}
	cout << (sum >= 1000) << endl;

	return 0;
}


Measured memory_bytes: 3152
n_num = int(input())
plan_list = [[0, (0, 0)]]

def movable(p1, p2):
    time = p2[0] - p1[0]
    distance = 0
    
    distance += abs(p1[1][0] - p2[1][0])
    distance += abs(p1[1][1] - p2[1][1])
    
    if distance > time:
        return 0
    else:
        if (time - distance) % 2 != 0:
            return 0
        else:
            return 1
    

for _ in range(n_num):
    line = [int(i) for i in input().split()]
    plan_list.append([line[0], (line[1], line[2])])
    
vector = (0, 0)

flag = 0
for n in range(1, n_num+1):
    if movable(plan_list[n-1], plan_list[n]) == 0:
        flag = 1
    
if flag == 1:
    print('No')
else:
    print('Yes')

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

int main() {
	ll x, k, d;
	cin >> x >> k >> d;

	if (x < 0) x = -x;

	/* d*k進んでも届かないかどうか. */
	ll p = x/d;
	ll z = x%d;
	if (z != 0) p++;
	/* 足りない場合はここで終了. */
	if (p > k) {
		cout << (x - k*d) << endl;
		return 0;
	}
	if (z != 0) p--;

	/* 近いのはp回か、p+1回か。 */
	ll tmp_z = 0;
	ll tmp_x = x - (d * p);
	if (tmp_x < 0) tmp_x *= -1;
	ll tmp_y = x - (d * (p+1));
	if (tmp_y < 0) tmp_y *= -1;

	if (tmp_x < tmp_y) tmp_z = tmp_x;
	else tmp_z = tmp_y;

	int nearest = 0;
	if (tmp_x < tmp_y) nearest = p;
	else nearest = p+1;

	/* ここでnearest回で一番近い状況. k-nearest回の値が偶数ならtmp_zがこたえ。奇数なら差がこたえ。 */
	ll ans = 0;
//	cout << "tmp_z = " << tmp_z << endl;
//	cout << "nearest = " << nearest << endl;
	if (((k-nearest)%2) == 0) ans = tmp_z;
	else ans = tmp_z - d;
	if (ans < 0) ans *= -1;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3628
/*input
37564
whydidyoudesertme
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long 
#define ld long double
#define pii pair<int,int>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=mult(res,a);
        }
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
ll arr[maxn];
ll inv(int x){
    return mypow(x,MOD-2);
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int k;
    string s;
    cin>>k>>s;
    int cnt=0;
    ll cur=1;
    vector<ll> v;
    REP(i,sz(s)+k+1){
        if(i<sz(s)) arr[i]=0;
        else{
            v.pb(mult(cur,mypow(25,i-sz(s))));
            cur=mult(cur,i);
            cur=mult(cur,inv(i-sz(s)+1));
        }
    }
    REP1(i,sz(v)){
        v[i]+=mult(v[i-1],26);
        v[i]%=MOD;
    }
    cout<<v.back()<<'\n';
}

Measured memory_bytes: 20776
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let r: i64 = itr.next().unwrap().parse().unwrap();
    let d: i64 = itr.next().unwrap().parse().unwrap();
    let x: i64 = itr.next().unwrap().parse().unwrap();

    let mut now = x;
    for _ in 0..10 {
        now = r * now - d;
        println!("{}", now);
    }
}


Measured memory_bytes: 2136
N = int(input())
H = list(map(int, input().split(" ")))
cnt=0
for i in range(N):
    if i==0:
        cnt+=1
    else:
        h=H[i]
        c=0
        for j in range(i):
            if H[j]>h:
                c=1
        if c==0:
            cnt+=1
print(cnt)


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

long long n, ans=0, a[100100], p,l,idx ;
int main() {
	cin >>n;
    for (int i=1; i<=n; i++){
        cin>>a[i];
    }
    sort(a+1, a+n+1);
    
    for (int i=n; i>=1 ;i--){
        if (a[i]==a[i-1]){
            p=a[i];
            idx=i;
            break;
        }
    }
    
    for (int i=idx-2; i>=1; i--){
        if (a[i]==a[i-1]){
            l=a[i];
            break;
        }
    }
    
    cout<<p*l<<endl;
}


Measured memory_bytes: 4356
#include <iostream>
using namespace std;
int main()
{
  int health,n;
  cin>>health>>n;
  int attack[n];
  for(auto i=0;i<n;++i)
  {
    cin>>attack[i];
  }
  for(auto i=0;i<n;++i)
  {
    health-=attack[i];
    if(health<=0)
    {
      cout<<"Yes"<<endl;
      break;
    }
  }
  if(health>0)
  {
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
typedef long double ld;
const ld PI = acos(-1);

typedef complex<ld> P;

struct L {
    P a, b, v;
    L(){}
    L(P _a, P _b) : a(_a), b(_b), v(b - a) {}
};

P rot(P p, ld theta) {
    ld x = p.real(), y = p.imag();
    return P(x * cos(theta) - y * sin(theta), x * sin(theta) + y * cos(theta));
}

ld cross(P a, P b) {
    return imag(conj(a) * b);
}

P crosspointSS(L l1, L l2) {
    ld d1 = abs(cross(l2.v, l1.a - l2.a)); // <----????
    // ld d1 = abs(cross(l2.v, l1.a - l2.b)); // <----????
    // ld d1 = abs(cross(l2.v, l1.b - l2.a)); // <----????
    ld d2 = abs(cross(l2.v, l1.b - l2.a));
    ld t = d1 / (d1 + d2);
    return l1.a + t * l1.v;
}

ld distanceLP(L l, P p) {
    return abs(cross(l.v, p - l.a)) / abs(l.v);
}

ld area(P p0, P p1, P p2) {
    p1 -= p0, p2 -= p0;
    return abs(cross(p1, p2)) / 2;
}

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

    ld N, K;
    cin >> N >> K;

    ld theta = 2 * PI / N;
    P p0(1, 0);
    P p1 = rot(p0, K * theta);
    P q0 = rot(p0, theta);
    P q1 = rot(q0, - K * theta);

    L l(p0, p1);
    L m(q0, q1);
    P C = crosspointSS(l, m);

    const P O(0, 0);
    ld ans = N * (area(O, p0, q0) - area(C, p0, q0));
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        int x = N % 10;
        if (x == 3) {
            System.out.println("bon");
        } else if ( x == 0 || x == 1 || x == 6 || x == 8) {
            System.out.println("pon");
        } else {
            System.out.println("hon");
        }

    }
}


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

long N, M;

void solve(){
    cin >> M;
    long P[N + 1]; P[0] = 0;
    for (long i = 1; i < N + 1; i++) cin >> P[i];
    sort(P, P + N + 1);
    long *p = unique(P, P + N + 1);
    N = distance(P, p);
    set<long> s;
    for(long i = 0; i < N; i++){
        for (long j = i; j < N; j++){
            if (P[i] + P[j] > M) break;
            s.insert(P[i] + P[j]);
        }
    }
    long S[s.size()];
    set<long>::iterator it; long i = 0;
    for (it = s.begin(); it != s.end(); it++){
        S[i] = *it;
        i++;
    }
    long ans = 0;
    for (int i = 0; i < s.size(); i++){
        p = upper_bound(S, S + s.size(), M - S[i]);
        if (p == S + 1) break;
        ans = max(ans, S[i] + *(p - 1));
    }
    cout << ans << endl;
    return;
}

int main(){
    while(cin >> N){
        if (N == 0) return 0;
        solve();
    }
}


Measured memory_bytes: 30148
//aising2019_a.cpp
//Sat Jan 12 20:59:51 2019

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,h,w;
	cin >> n >> h >> w;

	cout << (n-h+1)*(n-w+1)<< endl;

}

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

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> math(h);
    int cntflag=0;
    vector<bool> flag(h,false),tate(w,false);
    for(int i=0; i<h; i++){
        bool white=true;
        for(int j=0; j<w; j++){
            char tmp;
            cin >> tmp;
            math[i].push_back(tmp);
            if(tmp=='#')white=false;
        }
        if(white){
            cntflag++;
            flag[i]=true;
        }

    }
    for(int i=0; i<w; i++){
        bool white=true;
        for(int j=0; j<h; j++){
            if(math[j][i]=='#')white=false;
        }
        if(white)tate[i]=true;
    }
    vector<vector<char>> ans(h-cntflag);
    for(int i=0; i<h; i++){
        if(flag[i])continue;
        for(int j=0; j<w; j++){
            if(tate[j])continue;
            cout << math[i][j];
        }
        cout << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;



int main(){
     
    int a,b,c;
    
    cin>>a>>b>>c;
    if((a==7&&b==5&&c==5)||(b==7&&a==5&&c==5)||(c==7&&a==5&&b==5))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
     
    return 0;
}
 

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    l,n = LI()
    x = [I() for _ in range(n)]
    if n == 1:
        return max(x[0], l-x[0])

    ir = [0]
    for c in x:
        ir.append(ir[-1] + c*2)
    jr = [0]
    for c in x[::-1]:
        jr.append(jr[-1] + (l-c)*2)
    jr = jr[::-1]

    r = max(x[-1], l-x[0])
    for i in range(n-1):
        k = (n - i) // 2 + i
        t = 0
        if (n-i) % 2 == 0:
            t += ir[k] - ir[i]
            t += jr[k+1] + l - x[k]
        else:
            t += ir[k] - ir[i] + x[k]
            t += jr[k+1]
        if r < t:
            r = t

    x = [l-c for c in x][::-1]
    tr = ir[::-1]
    ir = jr[::-1]
    jr = tr
    for i in range(n-1):
        k = (n - i) // 2 + i
        t = 0
        if (n-i) % 2 == 0:
            t += ir[k] - ir[i]
            t += jr[k+1] + l - x[k]
        else:
            t += ir[k] - ir[i] + x[k]
            t += jr[k+1]
        if r < t:
            r = t

    return r


print(main())


Measured memory_bytes: 41784
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#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;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int a, b;
    while(cin>>a>>b){
        vector<int> deg(110, 0);
        deg[a]++;
        deg[b]++;
        while(1){
            cin>>a>>b;
            if(a == 0) break;
            deg[a]++;
            deg[b]++;
        }

        bool valid = true;
        if(deg[1] % 2 == 0) valid = false;
        if(deg[2] % 2 == 0) valid = false;

        for(int i=3; i<105; i++){
            if(deg[i] % 2 == 1) valid = false;
        }

        if(valid){
            cout << "OK" << endl;
        }
        else{
            cout << "NG" << endl;
        }
    }
}


Measured memory_bytes: 3000
# -*- coding: utf-8 -*-
from sys import stdin


def bubble_sort(A, N):  # N個の要素を含む0-オリジンの配列 A
  #A = [int(a[1]) for a in A]
  flag = True  # 逆の隣接要素が存在する
  exchange_cnt = 0
  while flag:
    flag = False
    for j in range(N - 1, 0, -1):
      if int(A[j][1]) < int(A[j - 1][1]):
        A[j], A[j - 1] = A[j - 1], A[j]
        flag = True
        exchange_cnt += 1
  return A#exchange_cnt

def selection_sort(A, N):  #N個の要素を含む0-オリジンの配列 A
  # A = [int(a[1]) for a in A]
  exchange_cnt = 0
  for i in range(0, N):
    minj = i
    for j in range(i, N):
      if int(A[j][1]) < int(A[minj][1]):
        minj = j
    else:
      if i != minj:
        A[i], A[minj] = A[minj], A[i]
        exchange_cnt += 1
  return A#exchange_cnt

n = int(stdin.readline().rstrip())
A = list(stdin.readline().split())

ans = bubble_sort(list(A), n)
print(' '.join(map(str, ans)))
print('Stable')

ans2 = selection_sort(A, n)
print(' '.join(map(str,ans2)))
print('Stable' if ans2==ans else 'Not stable')



Measured memory_bytes: 5616
import numpy as np
H, W = map(int, input().split())
grid = np.zeros((H, W), dtype="unicode")
for h in range(H):
    input_ = input()
    for w in range(W):
        grid[h, w] = input_[w]
    
h_candi = [0, 0, 1, -1]
w_candi = [1, -1, 0, 0]

cannot_flag = 0
for h in range(H):
    if cannot_flag:
        break
    for w in range(W):
        if grid[h, w] == ".":
            continue
        count = 0
        for h_, w_ in zip(h_candi, w_candi):
            h_idx = h + h_
            w_idx = w + w_
            if (h_idx < 0) or (h_idx >= H):
                continue
            if (w_idx < 0) or (w_idx >= W):
                continue
            if grid[h_idx, w_idx] == "#":
                count += 1
        if count == 0:
            cannot_flag = 1
            break

if cannot_flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 12500
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <stdio.h>

using namespace std;
using ll = long long;
using ld = long double;
template <class T> using vec = std::vector<T>;
template <class T> using vvec = std::vector<std::vector<T>>;

#define REP(i, s, e) for (ll i = s; i < e; ++i)

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

    int A, B, C; cin >> A >> B >> C;
    cout << max(0, C - A + B) << endl;

    return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
using namespace std;
 
int main(){
    double n;
    cin >> n;
    double x = n*(1.0/1.08);
    int xx = n*(1.0/1.08);
    // cout << x << " " << xx << endl;
    int res;
    if(xx == x){
        res = xx;
    }
    else{
        res = xx+1;
    }
    if((int)res*108/100 == (int)n){
        cout << res;
    }
    else{
        cout << ":(";
    }
    

}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>
#include <set>
using namespace std;

const int INF = 1e9;

const int FAKE_OWNER = 0;

struct TEdge {
    int From;
    int To;
    int Owner;
    int Index;
};

vector<vector<TEdge>> g;
vector<TEdge> edges;

int AddEdge(int from, int to, int owner) {
    edges.push_back(TEdge{from, to, owner, (int) edges.size()});
    g[from].push_back(edges.back());
    return edges.size() - 1;
}

bool operator < (const TEdge& lhs, const TEdge& rhs) {
    return lhs.Owner < rhs.Owner;
}

bool operator == (const TEdge& lhs, const TEdge& rhs) {
    return lhs.Owner == rhs.Owner;
}

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

    g.resize(n + 1);

    int rootEdge = AddEdge(0, 1, FAKE_OWNER);
    for (int i = 0; i < m; ++i) {
        int v1, v2, c;
        scanf("%d%d%d", &v1, &v2, &c);
        AddEdge(v1, v2, c);
        AddEdge(v2, v1, c);
    }

    for (int i = 0; i <= n; ++i) {
        sort(g[i].begin(), g[i].end());
    }

    set<pair<int, int>> zeroUsed;
    set<int> oneUsed;

    vector<int> dist(2 * edges.size(), INF);
    dist[rootEdge] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.push(make_pair(dist[rootEdge], rootEdge));
    while (!q.empty()) {
        int d = q.top().first;
        int v = q.top().second;
        q.pop();

        if (d > dist[v]) {
            continue;
        }

        int to = edges[v].To;

        if (oneUsed.find(to) == oneUsed.end()) {
            oneUsed.insert(to);

            for (const TEdge& e : g[to]) {
                int nd = d + 1;
                if (nd < dist[e.Index]) {
                    dist[e.Index] = nd;
                    q.push(make_pair(dist[e.Index], e.Index));
                }
            }
        }

        if (zeroUsed.find(make_pair(to, edges[v].Owner)) == zeroUsed.end()) {
            zeroUsed.insert(make_pair(to, edges[v].Owner));

            auto il = lower_bound(g[to].begin(), g[to].end(), edges[v]);
            auto ir = upper_bound(g[to].begin(), g[to].end(), edges[v]);

            for (; il != ir; ++il) {
                const TEdge e = *il;
                int nd = d;
                if (nd < dist[e.Index]) {
                    dist[e.Index] = nd;
                    q.push(make_pair(dist[e.Index], e.Index));
                }
            }
        }
    }

    int result = INF;
    for (int i = 0; i < (int) edges.size(); ++i) {
        if (edges[i].To == n) {
            result = min(result, dist[i]);
        }
    }

    printf("%d\n", (result == INF ? -1 : result));

    return 0;
}

Measured memory_bytes: 46440
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

  int x = 0, t = 0;
  while(x < X) {
    t++;
    x = t*(t+1)/2;
  }

  cout << t << endl;
}

Measured memory_bytes: 256