akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair

int read()
{
    int v = 0, f = 1;
    char c = getchar();
    while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();}
    while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
    return v * f;
}

const int N = 101000;

int n, sg[N];

struct Edge
{
    int nxt, to;
} eg[N << 1];
int head[N], en;

void setEdge(int u, int v)
{
    eg[++en] = (Edge){head[u], v};
    head[u] = en;
}

void dfs(int u, int fa)
{
    for (int e = head[u]; e; e = eg[e].nxt)
    {
        int v = eg[e].to;
        if (v == fa) continue;
        dfs(v, u);
        sg[u] ^= (sg[v] + 1);
    }
}

int main()
{
    n = read();
    for (int i = 1; i < n; i++)
    {
        int u = read(), v = read();
        setEdge(u, v);
        setEdge(v, u);
    }
    dfs(1, 0);
    puts(sg[1] ? "Alice" : "Bob");
}


Measured memory_bytes: 7296
#include<stdio.h>
int N;
long A[88], hoge=1000, huga, ans = 1000;
int main(){
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		scanf("%ld", &A[i]);
		if(i && A[i] < A[i-1]){
			ans = ans%hoge + ans/hoge*huga;
			hoge = 1000;
			huga = 0;
		}
		if(hoge > A[i]){
			huga = 0;
			hoge = A[i];
		}
		if(huga < A[i]){
			huga = A[i];
		}
	}
	if(huga>hoge){
		ans = ans%hoge + ans/hoge*huga;
	}
	printf("%ld\n", ans);
	return 0;
}

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

int main()
{
	while (1) {
		int ba = 0;
		int a;
		string x;
		cin >> a;
		if (a == 0)break;
		cin >> x;
		vector<int>s(a);
		for (int b = 0; b < 100; b++)
		{
			s[b%a]++;
			switch (x[b])
			{
			case 'S':ba += s[b%a]; s[b%a] = 0; break;
			case 'L':s[b%a] += ba; ba = 0; break;
			}
		}
		sort(s.begin(), s.end());
		for (int k : s) {
			cout << k << " ";
		}
		cout << ba << endl;
	}
}

Measured memory_bytes: 3232
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-9;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int in[100050];
int main() {
	while (1) {
		int N, M, i, j;
		scanf("%d %d", &N, &M);
		if (!N) break;
		for (i = 1; i <= N; i++) scanf("%d", &in[i]);

		int ans = -1;
		for (i = 1; i <= N; i++) {
			for (j = i + 1; j <= N; j++) {
				if (in[i] + in[j] <= M) ans = max(ans, in[i] + in[j]);
			}
		}
		if (ans == -1) printf("NONE\n");
		else printf("%d\n", ans);
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    cout << (n + 1) / 2 << endl;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

vector<ll> teraa(100005);
vector<ll> jin(100005);

ll comp(ll x, ll idx, ll idx2, ll ans) {
    ll tmp = abs(x - jin[idx]) + abs(jin[idx] - teraa[idx2]);
    ans = min(ans, tmp);
    tmp = abs(x - teraa[idx2]) + abs(jin[idx] - teraa[idx2]);
    ans = min(ans, tmp);

    return ans;
}

int main(){
    ll a, b, q;
    cin >> a >> b >> q;
    jin.resize(a), teraa.resize(b);
    REP(i, a) cin >> jin[i];
    REP(i, b) cin >> teraa[i];
    sort(ALL(jin));
    sort(ALL(teraa));

    REP(i, q) {
        ll x;
        cin >> x;
        ll ans = INF_LL;

        /* 左神、左寺 */
        ll idx = distance(jin.begin(), upper_bound(ALL(jin), x));
        if(idx != 0) idx--;
        ll idx2 = distance(teraa.begin(), upper_bound(ALL(teraa), x));
        if(idx2 != 0) idx2--;
        ans = comp(x, idx, idx2, ans);

        /* 左神、右寺 */
        idx = distance(jin.begin(), upper_bound(ALL(jin), x));
        if(idx != 0) idx--;
        idx2 = distance(teraa.begin(), lower_bound(ALL(teraa), x));
        if(idx2 == b) idx2 = b - 1;  
        ans = comp(x, idx, idx2, ans);

        /* 右神、左寺 */
        idx = distance(jin.begin(), lower_bound(ALL(jin), x));
        if(idx == a) idx = a - 1;        
        idx2 = distance(teraa.begin(), upper_bound(ALL(teraa), x));
        if(idx2 != 0) idx2--;
        ans = comp(x, idx, idx2, ans);

        /* 右神、右寺 */
        idx = distance(jin.begin(), lower_bound(ALL(jin), x));
        if(idx == a) idx = a - 1;   
        idx2 = distance(teraa.begin(), lower_bound(ALL(teraa), x));
        if(idx2 == b) idx2 = b - 1;
        ans = comp(x, idx, idx2, ans);   

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 2944
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	for i, _ := range v {
		fmt.Scan(&v[i])
	}

	sort.Ints(v)

	ans := float64(v[0])
	for i := 1; i < n; i++ {
		ans = calc(ans, float64(v[i]))
	}
	fmt.Println(ans)
}

func calc(x, y float64) float64 {
	return (x + y) / 2.0
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

vector<vector<int> > map;

int search(int step, int subt, vector<bool> used, int prev,int r){
	if(step==r){
		return subt;
	}
	
	int ans=1e9;
	for(int i=0; i<r; i++){
		if(!used[i]){
			vector<bool> nu = used;
			nu[i] = true;
			if(step==0){
				ans = min(ans, search(step+1, 0, nu, i, r));
			}else{
				ans = min(ans, search(step+1, subt+map[prev][i], nu, i, r) );
			}
		}
	}
	return ans;
}

int main(){
	int n,m,r;
	cin >> n >> m >> r;
	
	vector<int> rs(r);
	vector<vector<int> > d(n+1, vector<int>(n+1, 1e9));
	for(int i=0; i<r; i++){
		cin >> rs[i];
	}
	for(int i=0; i<m; i++){
		int a,b,c;
		cin >> a >> b >> c;
		d[a][b] = d[b][a] = c;
	}
	for(int i=1; i<n+1; i++){
		d[i][i] = 0;
	}
	
	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(d[i][j] > d[i][k]+d[k][j]){
					d[i][j] = d[i][k]+d[k][j];
				}
			}
		}
	}
	
	vector<vector<int> > rmin(r, vector<int>(r, 1e9));
	for(int i=0; i<r; i++){
		for(int j=0; j<r; j++){
			rmin[i][j] = rmin[j][i] = d[rs[i]][rs[j]];
		}
	}
	map = rmin;
	
	cout << search(0, 0, vector<bool>(r, false), -1, r) << endl;
	return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(2500)
def dfs(i, j):
    global visited
    visited[i][j] = True
    for ii in [i - 1, i, i + 1]:
        for jj in [j - 1, j, j + 1]:
            if c[ii][jj] and not visited[ii][jj]:
                dfs(ii, jj)

w_list = []
h_list = []
c_list = []
while True:
    w, h = [int(x) for x in input().split()]
    if w == h == 0: break
    # dfsの条件分岐を減らすために、周りを海で囲む
    c = [[0 for _ in range(w + 2)]] + \
        [[0] + [int(x) for x in input().split()] + [0] for _ in range(h)] + \
        [[0 for _ in range(w + 2)]]
    w_list.append(w)
    h_list.append(h)
    c_list.append(c)

for w, h, c in zip(w_list, h_list, c_list):
    visited = [[False for _ in range(w + 2)] for _ in range(h + 2)]
    ans = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if c[i][j] == 1 and not visited[i][j]:
                ans += 1
                dfs(i, j)
    print(ans)


Measured memory_bytes: 8740
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(101);
    fill(v.begin(),v.end(),0);
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        v[a]++;
    }
    for(int i=100;i>0;i+=-1){
        v[i-1]+=v[i];
    }
    for(int i=100;i>=0;i+=-1){
        if(v[i]>=i){
            cout<<i<<endl;
            return 0;
        }
    }
}


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

int main(void)
{
    int n = 0;
    int num = 1;
    int i = 0, j = 0;
    cin >> n;
    vector<int> highest(n);
    for (i = 0; i < n; i++)
        cin >> highest[i];
    for (i = 1; i < n; i++)
    {
        int high = highest[i];
        bool is_ok = true;
        for (j = 0; j < i; j++)
        {
            if (highest[j] > high)
            {
                is_ok = false;
            }
        }
        if (is_ok)
            num++;
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define p 1000000007
#define pb push_back
ll dp[3001][3001];

ll points(ll i,ll j,vector<ll> &v,int turn)
{
    if(i>j)
    {
        return 0;
    }
    else if(i==j)
    {
        return dp[i][j]=(turn==1?v.at(i):0);
    }
    else
    {
        if(dp[i][j]!=-1)
        {
            return dp[i][j];
        }
        if(turn==1)
        {
            
            return dp[i][j]=max(v.at(i)+points(i+1,j,v,0),v.at(j)+points(i,j-1,v,0));
        }
        else if(turn==0)
        {
            
            return dp[i][j]=min(points(i+1,j,v,1),points(i,j-1,v,1));
        }
    }
}

ll solve(ll n,vector<ll> &v)
{
    memset(dp,-1,sizeof(dp));
    return points(1,n,v,1);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll n;
    cin>>n;
    ll sum=0;
    vector<ll> v(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>v.at(i);
        sum+=v.at(i);
    }
    //cout<<sum<<"\n";
    //cout<<solve(n,v)<<"\n";
    cout<<(2*solve(n,v)-sum)<<"\n";
    return 0;
}

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	bool is_not_prime[100000] = {false};
	vi primes;
	is_not_prime[0] = is_not_prime[1] = true;
	is_not_prime[2] = false;
	REP(i, 100000){
		if(!is_not_prime[i]){
			primes.push_back(i);
			for(int j = 2 * i; j < 100000; j += i) is_not_prime[j] = true;
		}
	}
	vi a(100001);
	REP1(i, 100000){
		a[i] = a[i - 1] + (binary_search(ALL(primes), i) && binary_search(ALL(primes), (i + 1) / 2));
	}
	int q;
	cin >> q;
	REP(i, q){
		int l, r;
		bool ok = true;
		int ans = 0;
		cin >> l >> r;
		cout << a[r] - a[l - 1] << "\n";
	}
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    string s;
    cin>>s;
    if(s[0]==s[1] && s[1]==s[2]) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
def rotate(vec, dir):
	new_vec = []
	if dir == 1:
		new_vec.append(-vec[1])
		new_vec.append(vec[0])
	elif dir == -1:
		new_vec.append(vec[1])
		new_vec.append(-vec[0])

	return new_vec

vecs12 = list(map(int, input().split()))
vec12 = [vecs12[0] - vecs12[2], vecs12[1] - vecs12[3]]
vec21 = [vecs12[2] - vecs12[0], vecs12[3] - vecs12[1]]
vec3 = [vecs12[2] + rotate(vec12, -1)[0], vecs12[3] + rotate(vec12, -1)[1]]
vec4 = [vecs12[0] + rotate(vec21, 1)[0], vecs12[1] + rotate(vec21, 1)[1]]
vecs34 = vec3 + vec4
print(' '.join(map(str, vecs34)))


Measured memory_bytes: 3064
# python3
# -*- coding: utf-8 -*-
import sys
import math
import bisect
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)]
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
r = ii()

print(2 * math.pi * r)


Measured memory_bytes: 10508
s = input()
t = input()
 
idx = -1
count = 0
if set(t) <= set(s):
    for i in t:
        idx = s.find(i, idx+1)
        if idx == -1:
            idx = s.find(i)
            count += 1
    pdc = count * len(s)
    print((idx + 1) + pdc)
else:
    print(-1)

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:256000000")
#include <iostream>
#include <iterator>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <climits>
#include <ctime>

using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 200000;

void solve() {
	int n, a, b;
	cin >> n >> a >> b;
	if (abs(b - a) % 2 == 0)
		cout << "Alice";
	else
		cout << "Borys";
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << " sec" << endl;
#endif
	return 0;
}

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

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

	const int mod=1000000007;
	int64_t pow=1;
	int64_t c=m;
	int mask=1;
	while (mask<=n)
	{
		if ((n&mask)!=0)
		{
			pow*=c;
			pow%=mod;
		}
		c*=c;
		c%=mod;
		mask<<=1;
	}
	cout << pow << endl;
}








Measured memory_bytes: 3100
#import<iostream>
#define r(a)for(int i=0;i<a;i++)
#define s (std::cin>>w,w);
#define c(a,b)a=a<b?a:b
int w,n,m,d[999],p[999];main(){n=s;m=s;r(n)d[i]=s;r(n)p[i]=1e9;r(m){s;r(n)c(p[i],p[i+1]+w*d[n-i-1]);}std::cout<<*p<<"\n";}

Measured memory_bytes: 1172
#include <stdio.h>

int main(void)
{
	int h, min, s;
	int t, t_3;
	
	while (1){
		scanf("%d %d %d", &h, &min, &s);
		if (h == -1 && min == -1 && s == -1){
			break;
		}
			
		t = 7200 - (h * 3600) - (min * 60) - s;
		printf("%02d:%02d:%02d\n", t / 3600, t % 3600 / 60, t % 60);
	
		t_3 = t * 3;
		printf("%02d:%02d:%02d\n", t_3 / 3600, t_3 % 3600 / 60, t_3 % 60);
	}
	
	return (0);
}
	
 	
	
	
	

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

int main(){
    int t,h,m,s;
    cin >> t;
    h = t/(60*60);
    m = (t - h*60*60)/60;
    s = t - (h*60*60 + m*60);
    
    cout << h <<':'<< m << ':' << s << endl;
    return 0;
}


Measured memory_bytes: 3100
n, x, m = gets.chomp.split.map(&:to_i)    # 要素数、初期値、割る数
id = Array.new(m, -1)    # 
a = []
len = tot = 0
while id[x] == -1
  a << x    # 
  id[x] = len   # id[x] に、ｘが何番目にでてきたか入れる
  len += 1    # 何番目か
  tot += x    # tot に、これまでのｘの累計を入れる
  x = (x*x)%m   # 次のx
end
c = len - id[x]   # c 周期の長さ
s = 0   # s １周期の中のｘの和
for i in id[x]..(len - 1) do
  s += a[i]
end
ans = 0
if n <= len   # 周期に入らず終わる場合
  for i in 0...n do
    ans += a[i]
  end
else  # 周期に入る場合
  ans += tot
  n -= len
  ans += s*(n/c)
  n %= c
  for i in 0...n do
    ans += a[id[x]+i]
  end
end
puts ans

Measured memory_bytes: 15692
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    bool ok=1;
    string t=s;
    reverse(all(t));
    if(s!=t) ok=0;

    string u=s.substr(0,(n-1)/2);
    string v=u;
    reverse(all(u));
    if(u!=v) ok=0;
    string z=s.substr((n+3)/2-1,n-(n+3)/2+1);
    string x=z;
    reverse(all(z));
    if(x!=z) ok=0;
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
*/

Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;
int d[100001], N;
int main() {
   cin>>N;
   for(int i = 0; i < N; i++){
   	cin>>d[i];
   }
   sort(d, d + N);
   cout<<d[N/2] - d[N/2-1] <<endl;
    return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> va;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    for (int j = 0; j < a; ++j) {
      va.push_back(i + 1);
    }
  }

  for (int i = 0; i < h; ++i) {
    vector<int> ans;
    for (int j = i * w; j < i * w + w; ++j) {
      ans.push_back(va[j]);
    }

    for (int j = 0; j < ans.size(); ++j) {
      if (j != 0) {
        cout << ' ';
      }

      if (i % 2 == 0) {
        cout << ans[j];
      } else {
        cout << ans[ans.size() - j - 1];
      }
    }

    cout << '\n';
  }

  return 0;
}

Measured memory_bytes: 3708
N, u, v = map(int, input().split())
G = [[] for i in range(N)]

for _ in range(N-1):
    A, B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)

# 1つしかつながる頂点がないものを葉とする
isLeaf, dU, dV = [len(g) == 1 for g in G], [-1]*N, [-1]*N

for D, P in [(dU, u-1), (dV, v-1)]:
    S = [(P, 0)]
    while len(S) > 0:
        p, d = S.pop()
        D[p] = d # その頂点になんパスでいけるか記録
        # 今いる場所から行ける頂点がまだ行ったことのないところならキューに追加
        for g in G[p]:
            if D[g] == -1:
                S.append((g, d+1))

ans = 0
# 全頂点のうち、葉（端っこの頂点）であり、かつ、高橋くんの方が青木くんより先につける頂点のうち最大のものが2人が目指す頂点
# 最終的に高橋くんが自ら捕まりにいくので、その頂点1歩手前が答え
for i in range(N):
    if isLeaf[i] and dU[i] < dV[i]:
        ans = max(ans, dV[i]-1)

print(ans)


Measured memory_bytes: 72044
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    map<ll,ll> m;
    ll sum = 0;
    rep(i,n){
        int x; cin >> x;
        m[x]++;
        sum += x;
    }
    int q; cin >> q;
    rep(i,q){
        int x,y; cin >> x >> y;
        sum += (y-x) * m[x];
        m[y] += m[x]; m[x] = 0;
        cout << sum << endl;
    }
    return 0;
}


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

void output_vector(vector<int> &A) {
  int vector_size = A.size();
  
  for (int i = 0; i < vector_size-1; i++) {
    cout << A.at(i) << " ";
  }
  cout << A.at(vector_size-1) << endl;
}

int main() {
  int N, v, j;
  cin >> N;
  vector<int> A(N);
  
  for (int i = 0; i < N; i++) cin >> A.at(i);
  output_vector(A);
  
  for (int i = 1; i < N; i++) {
  	v = A.at(i);
  	j = i - 1;
  	while (j >= 0 && A.at(j) > v) {
  		A.at(j+1) = A.at(j);
  		j--;
  	}
  	A.at(j+1) = v;
  	
    output_vector(A);
    
  }
  
}


Measured memory_bytes: 3108
#include <stdio.h>
#include <math.h>

void mChain(int *, int);

main(){
  int  n, i, b[101];

  scanf("%d", &n);

  for(i = 0;i < n;i++){
    scanf("%d", &b[i]);
    scanf("%d", &b[i+1]);
  }
  mChain(b, n);
  return 0;
}
void mChain(int *b, int n){
  int i, j, k, t, min;
  int m[101][101];
  
  for(i = 1;i <= n+1;i++) m[i][i] = 0;
  
  for(k = 2;k <= n;k++) for(i = 1; i <= n - k + 2;i++){
      j = i + k - 1;
      m[i][j] = pow(2, 31) - 1;
      for(t = i;t <  j; t++){
	min = m[i][t] + m[t+1][j] + b[i - 1]*b[t]*b[j];
	if(m[i][j]  > min || t == i){
	  m[i][j] = min;
	}
      }
    }
  
  printf("%d\n", m[1][n]);
}

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

int main () {
  
  long long MOD = 1000000000 + 7;
  
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  
  int N = S.size();
  vector<vector<long long>> dp(N + 1, vector<long long>(13));
  dp[0][0] = 1;
  
  long long A = 1;
  
  for (int i = 0; i < N; i++) {
    
    if (S[i] != '?') {
      
      long long a = S[i] - '0';
      
      for (int j = 0; j < 13; j++) {
        dp[i + 1][(j + a * A) % 13] += dp[i][j];
        dp[i + 1][(j + a * A) % 13] %= MOD;
      }
      
    }
    
    if (S[i] == '?') {
      
      for (long long j = 0; j < 13; j++) {
        for (long long k = 0; k <= 9; k++) {
          dp[i + 1][(j + k * A) % 13] += dp[i][j];
          dp[i + 1][(j + k * A) % 13] %= MOD;
        }
      }
      
    }
    
    A *= 10;
    A %= 13;
    
  }
  
  cout << dp[N][5] << endl;
  
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	vector<pair<lli,lli>> v;
	lli n;

	cin>>n;

	for(lli i=1;i<=n;i++){
		for(lli j=i+1;j<=n;j++){
			if(n%2==0){
				if(j == n-i+1)continue;
			}
			else{
				if(j == n-i)continue;
			}
			v.push_back(make_pair(i,j));
		}
	}
	cout<<v.size()<<endl;
	REP(i,0,v.size()){
		cout<<v[i].first<<" "<<v[i].second<<endl;
	}

	return 0;
}

Measured memory_bytes: 512
H, W, K = map(int, input().split())

mat = []
for i in range(H):
	mat.append(str(input()))

num = 0
for i in range(H):
	for j in range(W):
		if mat[i][j] == '#':
			num += 1

ans = 0
for i in range(1<<H):
	for j in range(1<<W):
		cnt = 0
		for ii in range(H):
			for jj in range(W):
				if (i>>ii) & 1 == 1 and (j>>jj) & 1 == 1 and mat[ii][jj] == '#':
					cnt += 1
		if cnt == K:
			ans += 1

print(ans)

Measured memory_bytes: 73792
# include<bits/stdc++.h>
# include<ext/pb_ds/assoc_container.hpp>
# include<ext/pb_ds/tree_policy.hpp>
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
# pragma GCC optimize ("Ofast")

using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;

# define S second
# define F first
# define kill(x) return(cout << x << '\n', 0LL)
# define debug(x) cerr<< #x << " = " << (x) << endl
# define ddebug(x, y) cerr<< #x << " = " << (x)  << ", " << #y << " = " << (y) << endl
# define tdebug(x, y, z) cerr<< #x << " = " << (x)  << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl
# define bin(x) cerr<< #x << " : " << bitset<4>(x) << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define uop(x, y) pii(min(x, y), max(x, y))

const int MAXN = 2000 + 10;
int MOD,
    fact[3 * MAXN],
    inv[3 * MAXN],
    r2[3 * MAXN],
    r3[3 * MAXN];

int _pow(int a, int p)
{
    if (!p)
        return 1;
    return _pow(sq(a) % MOD, p >> 1) * (p & 1 ? a : 1) % MOD;
}

int rev(int a)
{
    return _pow(a, MOD - 2);
}

int ch(int n, int k)
{
    return fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}

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

    int n;
    cin >> n >> MOD;

    fact[0] = 1;
    for (int i = 1; i <= n * 3 + 10; i ++)
        fact[i] = fact[i - 1] * i % MOD;

    for (int i = 0; i <= n * 3 + 10; i ++)
    {
        r2[i] = rev(_pow(2, i));
        r3[i] = rev(_pow(3, i));
        inv[i] = rev(fact[i]);
    }

    int ans = 0;
    for (int i = 0; i <= n; i ++)
        for (int j = i; i + (j - i) / 3 <= n; j += 3)
        {
            int k = n - i - (j - i) / 3;

            int x = ch(3 * n, j)
                    * ch(3 * n - j, 2 * i) % MOD
                    * fact[2 * i] % MOD
                    * r2[i] % MOD
                    * inv[i] % MOD
                    * fact[3 * k] % MOD
                    * r3[k] % MOD
                    * inv[k] % MOD;
            ans = (ans + x) % MOD;
        }
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
n,a,b,c,d = map(int, input().split())
a -= 1
b -= 1
s = input()
ans = "No"
snk = s[a:c].count("##")
fnk = s[b:d].count("##")
if snk == 0 and fnk == 0:
  if c > d:
    if s[b-1:d+1].count("...") >= 1:
      ans = "Yes"
  else:
    ans = "Yes"
    
print(ans)

Measured memory_bytes: 3572
// AGC 16 A
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    string s; cin >> s;
    int len = s.length();
    int mi = INT_MAX;
    for(char it = 'a'; it <= 'z'; it++){
        int c = 0, cma = INT_MIN;
        for(int i = 0; i < len; i++){
            if(s[i] == it){
                cma = max(cma, c);
                c = 0;
            }else{
                c++;
            }
        }
        cma = max(cma, c);
        mi = min(mi, cma);
    }
    cout << mi << endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<vector<int> > arr(n,vector<int>(3));
    
    for(int i = 0; i < n; i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }

    for(int i = 1; i < n; i++){
        arr[i][0] += max(arr[i-1][1],arr[i-1][2]);
        arr[i][1] += max(arr[i-1][0],arr[i-1][2]);
        arr[i][2] += max(arr[i-1][0],arr[i-1][1]);
    }

    int ans = max({arr[n-1][0],arr[n-1][1],arr[n-1][2]});
    cout<<ans;
}

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

int main()
{
  long a, b, k, c, d;
  cin >> a >> b >> k;
  c = (a > k) ? a - k : 0;
  if(!c)
  {
    k -= a;
    d = (b > k) ? b - k : 0;
  }
  else
    d = b;
  
  cout << c << ' ' << d << endl;
  return 0;
}

Measured memory_bytes: 3604
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬╬╬██╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#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 RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) (a)<=(i) && (i)<(b)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef pair<int,int> P;
typedef vector<vector<P>> Graph;

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

  int n;
  cin >> n;

  vector<int> a(n);
  REP(i,n) cin >> a[i];

  map<int,int> mp;
  REP(i,n) mp[a[i]]++;
  
  sort(a.begin(),a.end());

  int ans = 0;
  RREP(i,n){
    if(mp[a[i]] == 0) continue;
    REP(j,32){
      if((1<<j)-a[i] < 0) continue;
      if(mp[(1<<j)-a[i]] && (mp[a[i]] > 1 || a[i] != (1<<j)-a[i])){
        ans++;
        mp[a[i]]--;
        mp[(1<<j)-a[i]]--;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
    int bingo[3][3];
    bool correctMap[3][3] = {false};
    int n;
    int b[10];

    rep(0,3){
        rep2(0,3){
            cin >> bingo[i][j];
        }
    }
    cin >> n;
    rep(0,n) cin >> b[i];
    rep(0,3){
        rep2(0,3){
            for(int k=0; k<n; k++){
                if(bingo[i][j] == b[k]){
                    correctMap[i][j] = true;
                    continue;
                }
            }
        }
    }
    //斜め
    if(correctMap[0][0] && correctMap[1][1] && correctMap[2][2]){
        cout << "Yes" << endl;
        return 0;
    }
    if(correctMap[0][2] && correctMap[1][1] && correctMap[2][0]){
        cout << "Yes" << endl;
        return 0;
    }
    //縦
    rep2(0,3){
        if(correctMap[0][j] && correctMap[1][j] && correctMap[2][j]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    //横
    rep(0,3){
        if(correctMap[i][0] && correctMap[i][1] && correctMap[i][2]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  string s;
  string prev = "";
  bool is_success = true;
  map<string, int> sis;
  for(int i = 0; i < N; ++i) {
    cin >> s;
    sis[s]++;
    if(prev == "") {
      prev = s;
      continue;
    }
    if(prev[prev.size() - 1] != s[0]) {
      is_success = false;
    }
    prev = s;
  }
  if(!is_success) {
    cout << "No" << endl;
    return 0;
  } else {
    for(auto si : sis) {
      if(si.second > 1) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

using ll = long long;
using vi = vector<int>; using vi2 = vector<vi>;
#define loopi(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define loop(i, n) for (int i = 0; i < (int)n; i++)
#define loopeq(i, n) for (int i = 0; i <= (int)n; i++)
#define loopll(i, n) for (ll i = 0; i < (ll)n; i++)

ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
    int k; cin >> k;
    vi2 table(k + 10, vi(k + 10, 0));
    ll sum = 0;
    loopi(p, 1, k + 5) {
        loopi(q, 1, k + 5) {
            table[p][q] = gcd(p, q);
        }
    }
    loopi(p, 1, k + 1) {
        loopi(q, 1, k + 1) {
            loopi(r, 1, k + 1) {
                sum += table[table[p][q]][r];
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3772
n,x,y=map(int,input().split())
d=[[0 for _ in range(n)]for _ in range(n)]
for i in range(n):
  for j in range(n):
    d[i][j]=abs(j-i)
for i in range(n):
  for j in range(n):
    d[i][j]=min(d[i][j],d[i][x-1]+d[y-1][j]+1)
ans=[0]*n
for i in range(n):
  for j in range(i+1,n):
    ans[d[i][j]]+=1
for i in ans[1:]:
  print(i)

Measured memory_bytes: 107348
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1000000007;

ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a) { return (a % mod + mod) % mod; }

inline ll add(ll a, ll b) { return take_mod(a + b); }

inline ll sub(ll a, ll b) { return take_mod(a - b); }

inline ll mul(ll a, ll b) { return take_mod(a * b); }

inline ll pow(ll x, ll n) {
  ll res = 1LL;
  while (n > 0) {
    if (n & 1) res = mul(res, x);
    x = mul(x, x);
    n >>= 1;
  }
  return res;
}

ll mod_inv(ll x) { return pow(x, mod - 2); }

void make_fact(ll n) {
  fact[0] = 1;
  ll res = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = res;
    res = mul(res, i + 1);
  }
}

void make_invfact(ll n) {
  invfact[0] = 1;
  invfact[n] = mod_inv(fact[n]);
  for (int i = n - 1; i >= 1; i--) {
    invfact[i] = mul(invfact[i + 1], i + 1);
  }
}

ll perm(ll n, ll k) { return mul(fact[n], invfact[n - k]); }

ll comb(ll n, ll k) { return mul(mul(fact[n], invfact[n - k]), invfact[k]); }

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

  vll c(n);
  rep(i, n) cin >> c[i];
  Sort(c);
  ll ans = 0;

  ll tt[n + 1];
  tt[0] = 1;
  rep(i, n) tt[i + 1] = mul(tt[i], 2);

  rep(i, n) {
    ll addv = tt[n - i - 1];
    if (i != n - 1) addv = add(addv, mul(n - i - 1, tt[n - i - 2]));
    addv = mul(addv, tt[i]);
    addv = mul(addv, c[i]);
    ans = add(ans, addv);
  }
  ans = mul(ans, tt[n]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#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 all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

    ll n;
    cin >> n;

    ll prd = 1;
    while(prd <= n) prd *= 2;

    cout << prd / 2 << endl;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 444;
const ll mod = 1e9+7;

int n,c;
int a[maxn], b[maxn];
ll dp[maxn][maxn];

ll P[maxn][maxn];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n>>c;
  for (int i=1; i<=n; i++) {
    cin>>a[i];
  }
  for (int i=1; i<=n; i++) {
    cin>>b[i];
  }
  
  for (int i=1; i<=n; i++) {
    for (int j=a[i]; j<=b[i]; j++) {
      ll x = 1;
      P[i][0]++;
      for (int k=1; k<=c; k++) {
	x *= j; x %= mod;
	P[i][k] += x;
	P[i][k] %= mod;
      }
    }
  }

  dp[0][0] = 1;

  for (int i=1; i<=n; i++) {
    for (int j=0; j<=c; j++) {
      for (int k=0; k<=j; k++) {
	dp[i][j] += (P[i][k]*dp[i-1][j-k])%mod;
	dp[i][j] %= mod;
      }
    }
  }

  // for (int i=0; i<=n; i++) {
  //   for (int j=0; j<=c; j++) {
  //     cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }
  // cout<<endl;

  cout<<dp[n][c]<<endl;    

  return 0;
}


Measured memory_bytes: 3072
n, a, b = map(int, input().split())


def calculate_summary_of_digits(n):
    result = 0
    while n != 0:
        result += (n % 10)
        n //= 10

    return result


result = 0
for i in range(1, n + 1):
    sum_of_digits = calculate_summary_of_digits(i)
    if a <= sum_of_digits <= b:
        result += i

print(result)


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll X[101],Y[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	double pi=atan(1)*4;
	
	cin>>N;
	FOR(i,N) cin>>X[i]>>Y[i];
	FOR(i,N) {
		double L=-1010,R=0;
		vector<double> D;
		FOR(j,N) if(i!=j) {
			ll dx=X[j]-X[i];
			ll dy=Y[j]-Y[i];
			D.push_back(atan2(dx,dy));
		}
		
		sort(ALL(D));
		D.push_back(D[0]+2*pi);
		double ret=0;
		FOR(j,D.size()-1) {
			if(D[j+1]-D[j]>=pi) ret=(D[j+1]-D[j])-pi;
		}
		
		_P("%.12lf\n",ret/(2*pi));
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 384
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def is_all_same(S):
    pre_s = S[0]
    for s in (S):
        if s != pre_s:
            return False
    return True

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    N = int(input_raw[0])
    S = str(N)
    new_S = ""
    for s in S:
        if s == "9":
            new_S += "1"
        elif s == "1":
            new_S += "9"
        else:
            new_S = s
    print int(new_S)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.Scanner;

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

		int result = 0;
		if(A*C < B) {
			result = C;
		}else {
			result = B/A;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const double EPS = 1e-10;
 
int main() {
	string S;
	cin >> S;
	ll sum = 0;
	ll ans = 0;
	for (int i = S.size() - 1; i >= 0; i--) {
		if (S[i] == 'B') ans += sum;
		else sum++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))

n1, n2, n4 = 0, 0, 0
for a in A:
	if not a % 4:
		n4 += 1
	elif not a % 2:
		n2 += 1
	else:
		n1 += 1

#print(n1, n2, n4)
print(["Yes", "No"][not(n1 + (n2 % 2) <= n4 + 1)])


Measured memory_bytes: 15020
n = gets.to_i
cnt = 1
x=[]
n.times do
  m,l = gets.chomp.split(" ").map(&:to_i)
  x.push([m-l,m+l])
end
x.sort! {|a,b| a[1] <=> b[1]}

now = 0
x.length.times do |i|
    if x[now][1] <= x[i][0]
      now = i
      cnt += 1
    end
end

puts cnt

Measured memory_bytes: 10488
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val d = sc.nextInt()
    val c = (0 until 26).map { sc.next().toInt() }
    val s = (0 until d).map {
        (0 until 26).map { sc.next().toInt() }
    }
    println(problemintroduction_to_heuristics_contest(d, c, s))
}

fun problemintroduction_to_heuristics_contest(
    d: Int,
    c: List<Int>,
    s: List<List<Int>>
): String {
    val list = IntArray(26) { 0 }
    val ans = IntArray(d) { 1 }
    for (i in 0 until d) {
        ans[i] = s[i].indexOf(s[i].max()) + 1
    }
    return ans.joinToString("\n")
}

Measured memory_bytes: 47996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vp = vector<P>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int q;
    cin >> q;
    vp qs(q);
    rep(i, q) cin >> qs[i];
    int n = 0;
    rep(i, q)
    {
        n = max(n, qs[i].second);
    }

    vint p(n + 1);
    p[0] = -1;
    for (int i = 2; i <= n; ++i)
    {
        if (p[i])
            continue;

        p[i] = i;
        for (ll j = (ll)i * i; j <= n; j += i)
        {
            p[j] = i;
        }
    }
    auto isPrime = [&](int x) { return p[x] == x; };
    vint l(n + 1);
    rep(i, n)
    {
        l[i + 1] = l[i];
        if (i % 2)
            continue;
        l[i + 1] += isPrime(i + 1) && isPrime((i + 2) / 2);
    }

    for (P lr : qs)
    {
        cout << l[lr.second] - l[lr.first - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,D,A=map(int, sys.stdin.readline().split())
XH=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
XH.sort()

q=deque()   #攻撃が無効となる座標、攻撃から差し引くポイント
ans=0
cnt=0

attack_point=0
for x,h in XH:
    while q:
        if x<q[0][0]:break
        end_x,end_point=q.popleft()
        attack_point-=end_point

    if h<=attack_point:
        pass
    else:
        if h%A==0:
            cnt=(h-attack_point)/A
        else:
            cnt=(h-attack_point)/A+1
        attack_point+=cnt*A
        q.append((x+2*D+1,cnt*A))
        ans+=cnt

print ans

Measured memory_bytes: 54684
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxA = 0;
        int maxB = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(maxA < a) {
                maxA = a;
                maxB = b;
            }
        }
        System.out.println(maxA + maxB);
    }
}


Measured memory_bytes: 58360
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())

// code
// ------------------------------------------------
int main() {

  int n;
  cin >> n;
  int max = (n - n % 4) / 4;
  bool can = false;
  rep(i,25)
  {
    rep(j,25)
    {
      if((4 * i + 7 * j) == n)
      {
        can = true;
        break;
      }
    }
  }

  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

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

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int j = 1;
    rep(i,n){
        if(a[i] == j){
            cnt++;
            j++;
        }
    }
    if(cnt == 0) cout << -1 << endl;
    else cout << n - cnt << endl;
}

Measured memory_bytes: 1024