akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

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

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

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

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            return false;
        }
    }
    return true;
}

int main()
{
	ll n,a,b;
	vll v,tmp;
	cin >> n;
	rep(i,n){
		cin >> a;
		if(a==0){
			cin >> b;
			v.pb(b);
		}
		else if(a==1){
			cin >> b;
			tmp.pb(v[b]);
		}
		else if(a==2) v.pop_back();
	}
	rep(i,SIZE(tmp)) cout << tmp[i] << endl;
	return 0;
}


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

int main() {
    string x;
    cin >> x;
    int s = 0, t = 0, cnt = 0;

    for (int i = 0; i < x.size(); i++) {
        if (x[i] == 'S') s++;
        else {
            if (s == t) cnt++;
            else t++;
        }
    }

    cout << cnt * 2 << endl;
    return 0;
}

Measured memory_bytes: 640
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

n = int(input())
if (n>=30):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9140
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a + 1):
  s = 500 * i
  for j in range(b + 1):
    t = 100 * j
    for k in range(c + 1):
      u = 50 * k
      if s + t + u == x:
        count += 1

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007; 

using namespace std;
typedef long long lint;

template< class T = lint>
struct Edge {
	int from, to;
	T cost;
	Edge() {}
	Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template< class T = lint>
vector<T> Bellman_Ford(vector<Edge<T>> &edges, int V, int st) {
	const T INF = numeric_limits<T>::max();
	vector<T> dist(V, INF);
	dist[st] = 0;
	for (int i = 0; i < V - 1; i++) {
		for (const auto &ele : edges) {
			if (dist[ele.from] != INF && dist[ele.to] > dist[ele.from] + ele.cost) {
				dist[ele.to] = dist[ele.from] + ele.cost;

				//if (i == V - 1) dist[ele.to] = -INF; // negative loop
			}
			//if (i == V - 1) if (dist[ele.from] == -INF) dist[ele.to] = -INF;
		}
	}
	for (const auto &ele : edges) {
		if (dist[ele.from] != INF && dist[ele.to] > dist[ele.from] + ele.cost) {
			dist[ele.to] = -INF; // negative loop
		}
		if (dist[ele.from] == -INF) dist[ele.to] = -INF;
	}
	return dist;
}

int main() {

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

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

	vector<Edge<lint>> edge(M);
	for (int i = 0; i < M; i++) cin >> edge[i].from >> edge[i].to >> edge[i].cost;
	for (auto &&elem : edge) {
		elem.from--;
		elem.to--;
		elem.cost *= -1;
	}

	vector<lint> ans = Bellman_Ford<lint>(edge, N, 0);
	
	if(ans[N - 1] == -numeric_limits<lint>::max()) cout << "inf";
	else cout << -ans[N - 1];

	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 4000005
const int mod=998244353;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

int n,m;
int fac[maxn],inv[maxn];

inline int read(){
    int x=0,f=1; char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

int power(int a,int k){
	int ret=1;
	for (;k;k>>=1,a=1ll*a*a%mod) if (k&1) ret=1ll*ret*a%mod;
	return ret;
}

int C(int n,int m){return n<m?0:1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}

int main(){
	n=read(),m=read(); int mx=n+n+m+m;
	fac[0]=inv[0]=1; for (int i=1;i<=mx;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[mx]=power(fac[mx],mod-2); for (int i=mx-1;i;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
	int ans=0; int pps=m,ub=m;
	if (n<m) ub=n-((m-n)&1),pps+=(m-ub)>>1;
	for (int i=ub;i>=0;i-=2,++pps){
		int res=C(n,i),num=(C(pps+n-1,n-1)-1ll*(n-i)*C(pps-m+n-2,n-1)-1ll*i*C(pps-m+n-1,n-1))%mod;
		//		cout<<i<<' '<<res<<' '<<num<<' '<<pps<<' '<<C(pps+n-1,n-1)<<' '<<i<<' '<<C(pps-m+n,n-1)<<endl;
		ans=(ans+1ll*res*num)%mod;
	}
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
    return 0;
}


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

int main(){
	int A, B, C, D, P, a, b, c;
	scanf("%d\n", &A);
	scanf("%d\n", &B);
	scanf("%d\n", &C);
	scanf("%d\n", &D);
	scanf("%d", &P);
	a = A * P;
	if(C > P){
		b = B;
	}else{
		b = B + D * (P - C);
	}
	c = fmin(a, b);
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 600
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <iomanip>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1000000007;
const LL LINF = 1LL * INF * INF;
const int MAXN = 100007;
const LD EPS = 1e-7;

vector <int> g[MAXN], used[MAXN], DP[MAXN];
int F[MAXN], FS[MAXN], FE[MAXN];
int ans = INF;

void dfs(int u, int pos = -1)
{
	int v, sum = 0, emp = 0;
	if (pos > -1)
		v = g[u][pos];
	else
		v = u;
	if (pos > -1 && F[v] > -1)
	{
		sum = FS[v];
		emp = FE[v];
		vector <int>::iterator it = lower_bound(g[v].begin(), g[v].end(), u);
		sum -= DP[v][it - g[v].begin()];
		emp -= !DP[v][it - g[v].begin()];
		it = lower_bound(g[v].begin(), g[v].end(), F[v]);
		if (!used[v][it - g[v].begin()])
			dfs(v, it - g[v].begin());
		sum += DP[v][it - g[v].begin()];
		emp += !DP[v][it - g[v].begin()];
	}
	else
		REP(i, SZ(g[v]))
	{
		int to = g[v][i];
		if (to == u)
			continue;
		if (!used[v][i])
		{
			used[v][i] = true;
			dfs(v, i);
		}
		sum += DP[v][i];
		emp += !DP[v][i];
	}
	if (pos > -1)
	{
		DP[u][pos] = sum + max(0, emp - 1);
		if (F[v] == -1)
		{
			F[v] = u;
			FS[v] = sum;
			FE[v] = emp;
		}
	}
	else
		ans = min(ans, sum + max(1, emp));
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("sparse.in", "r", stdin);
	//freopen("sparse.out", "w", stdout);
	int n;
	cin >> n;
	REP(i, n - 1)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	REP(i, n)
	{
		sort(g[i].begin(), g[i].end());
		used[i].resize(SZ(g[i]));
		DP[i].resize(SZ(g[i]));
		F[i] = -1;
	}
	REP(i, n)
		dfs(i, -1);
	cout << ans;
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 28672
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;

bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = INT_MIN, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 

ll findSubarraySum(ll arr[], ll n, ll sum = 0) 
{
    unordered_map<ll, ll> prevSum;
    ll res = 0;
    ll currsum = 0;
    for (ll i = 0; i < n; i++)
    {
        currsum += arr[i];
        if (currsum == sum) res++;
        if (prevSum.find(currsum - sum) != prevSum.end()) res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }
    return res; 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
ll powmp(ll x, ll y, ll p) 
{ 
    ll res = 1;     x = x % p;   
    while (y > 0) 
    {  
        if (y & 1)  res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
        string s,t;cin>>s>>t;
        t.pop_back();
        if(s==t) cout<<"Yes\n";
        else cout<<"No\n";
   
}


Measured memory_bytes: 3644
N = int(input())
S =input()

cntW, cntE = 0, S[1:].count('E')
ans = cntW + cntE
 
for i in range(N-1):
    if S[i+1] == 'E':
        cntE = cntE - 1 
    if S[i] == 'W':
        cntW = cntW + 1
    cnt = cntE + cntW
    ans = min(ans, cnt)

print(ans)

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

sum_A = sum(A)

mod = 10**9 + 7

sum_mod = 0

sum_minus = 0
for a in A:
    sum_mod += a * (sum_A - a - sum_minus) % mod
    sum_minus += a

print(sum_mod % mod)

Measured memory_bytes: 94156
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,k; cin >> n >> k;
  double a[200005];
  for(int i=1;i<=n;i++){
    double p; cin >> p;
    a[i] = (p+1)/2;
  }
  double sum[200005];
  sum[0] = 0;
  sum[1] = a[1];
  for(int i=1;i<=n-1;i++) sum[i+1] = sum[i] + a[i+1];
  double ans = 0;
  for(int i=1;i<=n-k+1;i++) ans = max(ans, sum[i+k-1] - sum[i-1]);
  printf("%.12f\n",ans);
  return 0;
}

Measured memory_bytes: 3328
from collections import deque

def topological_sort(V, E):
    '''
    Kahn's Algorithm (O(|V| + |E|) time)
    Input:
        V = [0, 1, ..., N-1]: a list of vertices of the digraph
        E: the adjacency list of the digraph (dict)
    Output:
        If the input digraph is acyclic, then return a topological sorting of the digraph.
        Else, return None.
    '''
    indeg = {v: 0 for v in V}
    for ends in E.values():
        for v in ends:
            indeg[v] += 1
    
    q = deque([v for v in V if indeg[v] == 0])
    top_sorted = []
    while q:
        v = q.popleft()
        top_sorted.append(v)
        
        for u in E[v]:
            indeg[u] -= 1
            if indeg[u] == 0:
                q.append(u)
    if len(top_sorted) == len(V): # The input digraph is acyclic.
        return top_sorted
    else: # There is a directed cycle in the digraph.
        return None

N, M = map(int, input().split())
V = list(range(1, N+1))
E = {v: [] for v in V}
for _ in range(M):
    x, y = map(int, input().split())
    E[x].append(y)
ts = topological_sort(V, E)
dp = {v: 0 for v in V}
for v in reversed(ts):
    dp[v] = max([dp[u] + 1 for u in E[v]]) if E[v] else 0
print(max(dp.values()))

Measured memory_bytes: 88292
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt(s *bufio.Scanner) int {
	if s.Scan() {
		t := s.Text()
		v, err := strconv.Atoi(t)
		if err == nil {
			return v
		}
		panic(err)
	} else {
		panic(s.Err())
	}
}

func scanString(s *bufio.Scanner) string {
	if s.Scan() {
		return s.Text()
	}
	panic(s.Err())
}

type pair struct {
	x, i int
}
type ints []*pair

func (is ints) Len() int           { return len(is) }
func (is ints) Less(i, j int) bool { return is[i].x < is[j].x }
func (is ints) Swap(i, j int)      { is[i], is[j] = is[j], is[i] }

func main() {
	sc := newScanner()
	n := scanInt(sc)
	p := make(ints, n)

	for i := 0; i < n; i++ {
		x := scanInt(sc)
		p[i] = &pair{x, i}
	}

	sort.Sort(p)

	res := 0
	min := 10000000
	for i := 0; i < n; i++ {
		if min > p[i].i {
			res++
			min = p[i].i
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main () {
	int n,m;
	cin>>n>>m;
	char ch[n][m];
	ll int dp[n][m]={0};
	ll int mod=1e9+7;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>ch[i][j];
		}
	}
	dp[0][0]=1;
	for(int i=1;i<n;i++)
	{	
		if(ch[i][0]=='.')
		{
			dp[i][0]=dp[i-1][0];
		}
		else
			dp[i][0]=0;
	}

	for(int i=1;i<m;i++)
	{
		if(ch[0][i]!='#')
			dp[0][i]=dp[0][i-1];
		else
			dp[0][i]=0;
	}
	
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		{
			if(ch[i][j]=='.')
				dp[i][j]=(dp[i-1][j]+ dp[i][j-1])%mod;
			else
				dp[i][j]=0;
		}
	}
			cout<<dp[n-1][m-1]%mod<<" ";

}


Measured memory_bytes: 9088
#include <stdio.h>

void depot(int *train, int x, int *out_train);

int main(void)
{
	int i;
	static int train[11];
	static int out_train[10];
	int array;
	
	while (scanf("%d", &array) != EOF){
		
		depot(train, array, out_train);
	}
	/*
	for (i = 0; i < 10; i++){
		if (out_train[i] != 0){
			printf("%d\n", out_train[i]);
		}
	}
	*/
	
	return (0);
}

void depot(int *train, int x, int *out_train)
{
	static int out = 0;
	int i;
	
	if (x != 0){
		for (i = 10; i > 0; i--){
			train[i] = train[i - 1];
		}
		train[1] = x;
	}
	if (x == 0){
		out_train[out] = train[1];
		printf("%d\n", out_train[out]);
		out++;
		for (i = 1; i < 11; i++){
			train[i] = train[i + 1];
		}
	}
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long power = 1;
		for(int i = 1; i <= N; i++){
			power = (int)(power * i % (Math.pow(10,9) + 7));
			if(power == 0){
				System.out.println(i);
				break;
			}
		}
		System.out.println(power);

	}

}


Measured memory_bytes: 21332
// E - Red and Green Apples
#include <bits/stdc++.h>
using namespace std;

int main(){
	int X, Y, A, B, C; cin>>X>>Y>>A>>B>>C;
	vector<int> E(A);
	while(A--) cin>>E[A];
	sort(E.rbegin(), E.rend());
	E.resize(X+B);
	while(B--) cin>>E[X+B];
	sort(E.rbegin(), E.rend()-X);
	E.resize(X+Y+C);
	while(C--) cin>>E[X+Y+C];
	sort(E.rbegin(), E.rend());
	cout<< accumulate(E.begin(), E.begin()+X+Y, 0LL) <<endl;
}

Measured memory_bytes: 2040
#include <iostream>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <numeric>
#include <cmath>
#include <cctype>
#include <memory>
//#include <unordered_map>

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

ll inf = pow(10,9)+7;

int main(){
  int H,W,K; cin>>H>>W>>K;
  ll dp[H+1][W+2];
  for(int h=0;h<=H;++h){
    if(h==0){
      dp[h][1] = 1;
      for(int w=2;w<=W;++w){
        dp[h][w] = 0;
      }
    }else{
      for(int w=1;w<=W;++w){
        int X=0,Y=0,Z=0;
        int C = W-1;
        for(ll bits=0;bits<pow(2,C);++bits){
          bool ok = true;
          for(int i=0;i<C;++i){
            if( ((bits>>(i))&1) && ((bits>>(i+1))&1) ){ ok = false; break;}
          }
          if(!ok){continue;}
          if(w==1){
            if( (bits>>(w-1))&1 ){ ++Z; }
            else{ ++Y;}
          }else if(w==W){
            if( (bits>>(w-2))&1 ){ ++X; }
            else{ ++Y; }
          }else{
            if( (bits>>(w-1))&1 ){ ++Z; }
            else if( (bits>>(w-2))&1 ){ ++X; }
            else{ ++Y; }
          }
        }
        dp[h][w] = X*dp[h-1][w-1];
        dp[h][w] %= inf;
        dp[h][w] += Y*dp[h-1][w];
        dp[h][w] %= inf;
        dp[h][w] += Z*dp[h-1][w+1];
        dp[h][w] %= inf;
      }
    }
  }
  cout << dp[H][K] << "\n";
}


Measured memory_bytes: 256
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007


const ll mxn = 2e5 + 2;
bool vis[mxn] = {false};
vell v[mxn];
ll r = 0;

void dfs(ll x)
{
    r++;
    // dbg(r);
    vis[x] = true;
    for (auto it : v[x])
        if (!vis[it])
            dfs(it);
}


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

    set <pair<ll, ll>> st;
    ll f = 0;
    while (m--) {
        ll x, y;
        cin >> x >> y;
        if (x > y)
            swap(x, y);

        if (st.count({x, y}))
            continue;

        v[x].pb(y);
        v[y].pb(x);
        st.insert({x, y});
    }

    for (ll i = 1 ; i <= n ; ++i) {

        if (vis[i])
            continue;
        r = 0;
        dfs(i);

        f = max(f , r);

    }

    cout << f;



}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    //TEST
    solve();
}



Measured memory_bytes: 33456
/*
sleep..sleep....sleep
*/
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int > pp;
typedef long long ll;
 
#define sz(x) (int)x.size() 
int const N=3e5+10,oo=1e9;
ll const OO=2e18;
double const eps=1e-8,PI=acos(-1);
int mod=oo+7;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    stack<int > st;
    int an=0;
    for(int i=0;i<s.size();i++){
        if(st.empty()||st.top()==s[i]){
            st.push(s[i]);
            continue;
        }
        st.pop();
        an+=2;
    }
    cout<<an;
    return 0;
}



Measured memory_bytes: 720
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

r = [(i+1)+a_i for i, a_i in enumerate(A)]
l = [(j+1)-a_j for j, a_j in enumerate(A)]
nr = Counter(r)
nl = Counter(l)

ans = 0
for k, v in nl.items():
    ans += nr[k]*v

print(ans)

Measured memory_bytes: 63588
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int N, T;
    int c[100];
    int t[100];
    int cs = 1001;
    cin >> N >> T;
    rep (i, N) {
        cin >> c[i] >> t[i];
        
        if (T >= t[i]) {
            if (cs > c[i]) {
                cs = c[i];
            }
        }
    }
    
    if (cs == 1001) {
        cout << "TLE" << endl;
    } else {
        cout << cs << endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>


int main(){
  long long N;
  scanf("%lld", &N);
  long long ans = 0;
  long long last;
  for (long long i=1; i*2<=N; i++){
    ans += i*(N/i)*(N/i+1)/2;
    //printf("+=%lld\n",i*(N/i)*(N/i+1)/2);
    last = i;
  }
  ans += N*(N+1)/2-last*(last+1)/2;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 3256
N, T = map(int, input().split())
food = [0] * N
for i in range(N):
  food[i] = list(map(int, input().split()))

food = sorted(food)  
#i番目までの商品でj分いないに完食できる美味しさの最大値  
dp = [[0] * (T + 1) for i in range(N + 1)]  

for i in range(N):
  for j in range(1, T + 1):
    #i番目の商品を使わない場合
    now = max(dp[i + 1][j - 1], dp[i][j])
    #使う場合
    if (j - food[i][0]) >= 0:
      now2 = dp[i][j - food[i][0]] + food[i][1]
    else:
      now2 = 0
    dp[i + 1][j] = max(now, now2)
    
#print(dp)
#T - 1分に i + 1番目の商品を注文
ans = 0
for i in range(N):
  now3 = dp[i][T - 1] + food[i][1]
  #print(dp[i][T - 1], food[i][1])
  ans = max(ans, now3)
  
print(ans)  
  
  
  

Measured memory_bytes: 141188
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;

int n;
vector<vector<P>> tr;
int col[MAX];
void dfs(int u, int p, int color)
{
    col[u] = color;
    for(int i = 0; i < tr[u].size(); i++){
        int  v = tr[u][i].first;
        int w = tr[u][i].second;
        if(v == p)  continue;
        if(w & 1)
            dfs(v, u, color^1);
        else dfs(v, u, color);
    }
}
int main()
{
    cin >> n;
    tr.resize(n+1);
    for(int i = 2; i <= n; i++){
        int u, v, w;
        cin >> u >> v >> w;
        tr[u].push_back({v, w});
        tr[v].push_back({u, w});
    }
    dfs(1, -1, 0);
    for(int i = 1; i <= n; i++){
        cout << col[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 8960
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <locale>
using namespace std;
#define FORN(i,m,n) for(int i=m; i<(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
#define p_b(x) push_back(x)
#define m_p(a,b) make_pair(a,b)
typedef long long ll;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  ll a,b,k;
  cin>>a>>b;
  if((a+b) % 2 == 0) cout<<(a+b)/2<<endl;
  else if(a==b) cout<<0<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
typedef long long ll;
using namespace std;

ll dF(ll x)
{
    return pow(x, 2);
}

ll dIntegral(ll d)
{
    ll ans = 0;
    for(int i = 1; i < 600 / d; i++)
    {
        ans += dF(i * d) * d;
    }

    return ans;
}

int main()
{
    ll d;
    while(cin >> d)
    {
        cout << dIntegral(d) << endl;
    }

    return EXIT_SUCCESS;
}

Measured memory_bytes: 1156
s = list(input())
t = list(input())

max_same = 0
ans = 0

for i in range(0,len(s)-len(t)+1):
        for j in range(0,len(t)):
                if s[i+j] == t[j] :
                            max_same += 1
        ans = max(ans, max_same)
        max_same = 0

print(len(t)-ans)

Measured memory_bytes: 8984
from collections import deque


# 数列の点数を計算する関数
def calc(seq):
    score = 0
    for a, b, c, d in req:
        if seq[b - 1] - seq[a - 1] == c:
            score += d

    return score


n, m, q = list(map(int, input().split()))
req = [list(map(int, input().split())) for _ in range(q)]

ans = 0

que = deque()

# 数列の1番目、[1]～[m]までキューに追加しますが、
# 実は、この問題は数列の最初が[1]の場合だけを考えても解けます。
for i in range(1, m + 1):
    que.append([i])

while que:
    seq = que.popleft()

    if len(seq) == n:
        # 長さがnになったので、得点を計算します
        score = calc(seq)
        ans = max(ans, score)
    else:
        # 次に追加する数字は、下限が今の数列の一番後ろの数字、上限がmです
        for i in range(seq[-1], m + 1):
            seq_next = seq + [i]
            que.append(seq_next)

print(ans)


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n; cin>>n;
    map<string,ll> mp;
    ll ans=0;
    rep(i,n){
        string s; cin>>s;
        mp[s]++;
    }
    ll m; cin>>m;
    rep(i,m){
        string s; cin>>s;
        mp[s]--;
    }
    for(auto s=mp.begin();s!=mp.end();++s){
        if(ans<s->second) ans=s->second;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    vi a(5);
    rep(i, 5) cin >> a[i];
    sort(all(a));
    int ans = INF;
    do {
        int tmp = 0;
        rep(i, 5) {
            tmp = (tmp+9)/10;
            tmp *= 10;
            tmp += a[i];
        }
        ans = min(tmp, ans);
    }while(next_permutation(all(a)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def inset(a, x):
    prev = x
    while a[prev] != -1:
        prev = a[prev]
    return prev


def putset(a, in1, x, in2, y):
    if in1 == in2:
        if a[x] == -1:
            a[y] = in1
        elif a[y] == -1:
            a[x] = in2
        else:
            a[x] = in1
            a[y] = in1
    else:
        a[in2] = in1
        a[y] = in1
        if a[x] != -1:
            a[x] = in1


N, M = map(int, input().split())
a = [-1] * N
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    in1 = inset(a, x)
    in2 = inset(a, y)
    putset(a, in1, x, in2, y)

print(a.count(-1))

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

int parent(int i){
	return i/2;
}

int left(int i){
	return 2*i;
}

int right(int i){
	return 2*i+1;
}


int main(){
	int H;
	cin >> H;
	int *A = new int[H+1];

	for(int i=1; i<=H; ++i){
		scanf("%d", &A[i]);
	}

	for(int i=1; i<=H; ++i){
		cout << "node " << i << ": key = " << A[i] << ", ";

		int p_i = parent(i);
		if(p_i >= 1)
			cout << "parent key = " << A[p_i] << ", ";

		int l_i = left(i);
		if(l_i <= H)
			cout << "left key = " << A[l_i] << ", ";

		int r_i = right(i);
		if(r_i <= H)
			cout << "right key = " << A[r_i] << ", ";

		cout << endl;
	}

	return 0;
}



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

int main()
{
    int N;
    int d[100000];
    std::cin >> N;
    for (int i = 0; i < N; i++){ std::cin >> d[i]; }

    int bucket[100001] = {0};
    for (int i = 0; i < N; i++){
        bucket[d[i]]++;
    }

    int halfIndex;
    int tempSumProb = 0;
    bool hasHalf = false;
    for (int i = 0; i < 100001; i++){
        tempSumProb += bucket[i];
        if (tempSumProb == N/2){
            halfIndex = i;
            hasHalf = true;
            break;
        }
    }

    if(hasHalf == false){ 
        std::cout << 0 << std::endl;
        return 0;
    }

    int cnt = 1;

    for (int i = halfIndex + 1; i < 100001; i++){
        if(bucket[i] == 0){
            cnt++;
        } else {
            break;
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

signed main() {
    string s;
    cin >> s;

    int n = s.length() - 1;
    long long res = 0;
    rep(bit, 0, 1 << n) {
        string t = {s[0]};
        rep(i, 0, n) {
            if (bit >> i & 1) t += "+";
            t += s[i + 1];
        }

        long long sum = 0;
        rep(i, 0, t.length()) {
            if (t[i] == '+') {
                res += sum;
                sum = 0;
            } else {
                sum *= 10;
                sum += (t[i] - '0');
            }
        }
        res += sum;
    }

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,m;
  cin >> n >> m;
  vector<vector<ll>> G(n);
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  queue<ll> que;
  que.push(0);
  vector<ll> dist(n,-1);
  dist.at(0)=0;
  while(!que.empty()){
    ll v=que.front();
    que.pop();
    for(ll p: G[v]){
      if(dist.at(p)!=-1){
        continue;
      }
      dist.at(p)=dist.at(v)+1;
      que.push(p);
    }
  }
  string ans="IMPOSSIBLE";
  if(dist.at(n-1)==2){
    ans="POSSIBLE";
  }
  cout << ans;
}


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

typedef struct TFC
{
    int T;
    int F;
    string C;
};

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    string S;
    int Q;

    ist >> S;
    ist >> Q;

    struct TFC Q_uery[Q];

    for (int i = 0; i < Q; i++)
    {
        ist >> Q_uery[i].T;
        if (Q_uery[i].T == 2)
        {
            ist >> Q_uery[i].F;
            ist >> Q_uery[i].C;
        }
    }

    /* ------- 計算 ------- */

    bool mode = true;
    deque<string> deq;

    for (int i = 0; i < S.length(); i++)
    {
        deq.emplace_back(S.substr(i, 1));
    }

    for (int i = 0; i < Q; i++)
    {
        if (Q_uery[i].T == 1)
        {
            mode = !mode;
        }
        else
        {
            if ((Q_uery[i].F == 1 && mode) || (Q_uery[i].F == 2 && !mode))
            {
                deq.emplace_front(Q_uery[i].C);
            }
            else if ((Q_uery[i].F == 1 && !mode) || (Q_uery[i].F == 2 && mode))
            {
                deq.emplace_back(Q_uery[i].C);
            }
        }
    }

    if (mode)
    {
        for (auto it = deq.begin(); it != deq.end(); ++it)
        {
            ost << *it;
        }
        ost << endl;
    }
    else
    {
        for (auto it = deq.rbegin(), e = deq.rend(); it != e; ++it)
        {
            ost << *it;
        }
        ost << endl;
    }
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll dp[2][1000100];

void solve() {
    ll N, W;
    cin >> N >> W;
    Vl ws(N), vs(N);
    for (ll i = 0; i < N; i++) {
        cin >> ws[i] >> vs[i];
    }

    auto dp1 = dp[0];
    auto dp2 = dp[1];
    for (ll i = 0; i < N; i++) {
        swap(dp1, dp2);
        memset(dp2, 0, sizeof(ll) * W);
        for (ll j = 0; j <= W; j++) {
            dp2[j] = dp1[j];
            if (j - ws[i] >= 0)
                chmax(dp2[j], dp1[j - ws[i]] + vs[i]);
        }
    }

    prints()(dp2[W]);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(nullptr), cout.tie(nullptr);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 5168
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
		}
		sc.close();

		long X[] = new long[N];
		for (int i = 0; i < N; i++) {
			if (i % 2 == 0) {
				X[0] += A[i];
			} else {
				X[0] -= A[i];
			}
		}

		for (int i = 1; i < N; i++) {
			X[i] = 2 * A[i - 1] - X[i - 1];
		}

		for (int i = 0; i < N; i++) {
			System.out.println(X[i]);
		}
	}
}


Measured memory_bytes: 70956
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP2_4_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] line = ReadIntAr();

            int q = ReadInt();
            for (int i = 0 ; i < q ; i++)
            {
                int[] items = ReadIntAr();

                var before = line.Take(items[0]).ToArray();
                var reversed = line.Skip(items[0]).Take(items[1] - items[0]).Reverse().ToArray();
                var after = line.Skip(items[1]).Take(line.Length - items[1]).ToArray();
                line = before.Concat(reversed).Concat(after).ToArray();
            }
            Console.WriteLine(WriteArray(line));
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteArray(int[] array,string sep =" ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteArray(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteArray(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 24572
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        ArrayList<String> ss = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            String tmp = s.substring(i, i + 1);
            if(tmp.equals("0")) {
                ss.add("0");
            } else if(tmp.equals("1")) {
                ss.add("1");
            } else if(tmp.equals("B")) {
                if(ss.size() != 0) {
                    ss.remove(ss.size() - 1);
                }
            }
        }
        for (String s1 : ss) {
            System.out.print(s1);
        }
    }
}


Measured memory_bytes: 35728
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1LL<<58
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

//typedef tuple<ll, ll, ll> T;

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

template<class T> int former(const vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template<class T> int latter(const vector<T> &v, T x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}
void chmin(long long &a, long long b) { if (a > b) a = b; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,q;
    cin>>a>>b>>q;
    vector<ll> s(a),t(b);
    for(int i=0;i<a;i++) cin>>s[i];
    for(int i=0;i<b;i++) cin>>t[i];
    s.push_back(INF);s.push_back(-INF);VSORT(s);
    t.push_back(INF);t.push_back(-INF);VSORT(t);

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

        for (int i = 0; i < 2; ++i) {
            long long first = (i ? s[former(s, x)] : s[latter(s, x)]);
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? t[former(t, first)] : t[latter(t, first)]);
                chmin(ans, abs(x - first) + abs(first - second));
            }
        }

        for (int i = 0; i < 2; ++i) {
            long long first = (i ? t[former(t, x)] : t[latter(t, x)]);
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? s[former(s, first)] : s[latter(s, first)]);
                chmin(ans, abs(x - first) + abs(first - second));
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2912
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll L, A, B, M;
vector<vector<ll>>matrix_mul(vector<vector<ll>>a, vector<vector<ll>>b) {
	vector<vector<ll>>res(a.size(),vector<ll>(b[0].size()));
	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < b[0].size();j++) {
			ll temp = 0;
			for (int k = 0; k < b.size(); k++) {
				a[i][k] %= M;
				b[k][j] %= M;
				temp += (a[i][k] * b[k][j]) % M;
				temp %= M;
			}
			res[i][j] = temp;
		}
	}
	return res;
}
vector<vector<ll>>matrix_pow(vector<vector<ll>>a,ll n) {
	vector<vector<ll>>E(a.size(), vector<ll>(a.size(),0));
	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < a.size(); j++) {
			E[i][j] = (i == j);
		}
	}
	while (n > 0) {
		if (n & 1)E = matrix_mul(E, a);
		a = matrix_mul(a, a);
		n >>= 1;
	}
	return E;
}
ll po(ll n) {
	ll ret = 1;
	for (int i = 0; i < n; i++)ret *= 10LL;
	return ret;
}

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

	cin >> L >> A >> B >> M;
	ll pre = -1;
	vector<vector<ll>>cur(3, vector<ll>(1, 0));
	cur[1][0] = A;
	cur[2][0] = 1;
	for (int i = 1; i <= 18; i++) {
		vector<vector<ll>>M(3, vector<ll>(3, 0));
		M[0] = { po(i),1,0 };
		M[1] = { 0,1,B };
		M[2] = { 0,0,1 };
		if (A + (L - 1)*B < po(i)) {
			cur = matrix_mul(matrix_pow(M,L-1-pre),cur);
			break;
		}
		ll ok = pre, ng = L - 1;
		while (ng - ok > 1) {
			ll mid = (ng + ok) / 2LL;
			if (A + mid * B < po(i))ok = mid;
			else ng = mid;
		}
		vector<vector<ll>>temp = matrix_pow(M, ok - pre);
		cur = matrix_mul(temp, cur);
		pre = ok;
	}
	puts(cur[0][0]);

	return 0;
}

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

using namespace std;

char arr[105];
int len;

int main()
{
    scanf("%s",&arr[1]);
    int i,a=0,b=0;
    len=strlen(&arr[1]);
    for(i=1;i<=len;i++){
        if(arr[i]=='C') a=1;
        if(arr[i]=='F' && a){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x;i <= y; ++ i)
#define repd(i,x,y) for(register int i = x;i >= y; -- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{
	char c;int sign = 1;x = 0;
	do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
	do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
	x *= sign;
}

const int mod = 1e9 + 7,N = 1e6 + 50;
int f[N],fac[N],m,n,h,d;

inline int ksm(int x,int y)
{
	int ans = 1;
	while(y)
	{
		if(y&1) ans = 1ll * ans * x % mod;
		y >>= 1; x = 1ll * x * x % mod;
	}
	return ans;
}
int main()
{
	read(n); read(h); read(d);
	f[0] = 1; fac[0] = 1;
	rep(i,1,n) fac[i] = 1ll * fac[i-1] * i % mod;
	rep(i,1,n) m = (m + fac[i]) % mod;

	rep(i,1,h)
	{
		f[i] = 1ll * (f[i - 1] - (i - d - 1 >= 0 ? f[i - d - 1] : 0)) * m % mod;
		if(f[i] < 0) f[i] = f[i] + mod;

		f[i] = (f[i-1] + f[i]) % mod;
	}
	
	cout << 1ll * (f[h] - f[h-1] + mod) % mod * fac[n] % mod * ksm(m,mod-2) % mod << endl;
	
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

pii grid[100][100];
bool done[100][100];
int num[100][100];
int cnt;

int DFS(int x,int y){
	if(done[x][y]){
		if(num[x][y]==0) return ++cnt;
		return num[x][y];
	}

	done[x][y]=true;
	return num[x][y]=DFS(grid[x][y].first,grid[x][y].second);
}

void Solve(){
	int n;
	while(true){
		cnt=0;
		fill_n((bool*)done,100*100,false);
		fill_n((int*)num,100*100,0);
		cin >> n;
		if(n==0) break;

		
		rep(i,0,n) rep(j,0,n){
			int x,y;
			cin >> x >> y;
			grid[j][i]=mp(x,y);
		}

		rep(i,0,n){
			rep(j,0,n){
				if(!done[i][j]) DFS(i,j);
			}
		}
		cout << cnt << endl;
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

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

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

    int res = 0;
    for (int i = 1; !res && i << 12; i++) {
        int count = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) count++;
        }
        if (count == N) res = i;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<ll> a(x), b(y), c(z);
	rep(i,x) cin >> a[i];
	rep(i,y) cin >> b[i];
	rep(i,z) cin >> c[i];
	vector<ll> v;
	rep(i,x) {
		rep(j,y) {
			v.push_back(a[i] + b[j]);
		}
	}
	sort(ALL(v), greater<>());
	int p = min((int)v.size(), k);
	vector<ll> ans;
	rep(i,p) {
		rep(j, z) {
			ans.push_back(v[i] + c[j]);
		}
	}
	sort(ALL(ans), greater<>());
	rep(i,k) cout << ans[i] << endl;
}

int main() {
	solve();
	return 0;
}

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

int a[1 << 19], n;
pair<int, int> f[1 << 19];

inline void update(pair<int, int>& a, pair<int, int>& b) {
	int t[4];
	t[0] = a.first; t[1] = a.second; t[2] = b.first; t[3] = b.second;
	sort(t, t + 4, [&](const int& i, const int& j) {
		return ::a[i] > ::a[j];
	});
	unique(t, t + 4);
	a.first = t[0]; a.second = t[1];
}

inline int calc(int x) {
	int ans = 0;
	for(int i = n - 1; i >= 0; -- i) {
		if(~x >> i & 1) continue;
		int p = ((x >> (i + 1) << (i + 1)) | ((1 << i) - 1));
		if(ans < a[f[p].first] + a[f[p].second]) ans = a[f[p].first] + a[f[p].second];
	}
	if(ans < a[f[x].first] + a[f[x].second]) ans = a[f[x].first] + a[f[x].second];
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 0; i < (1 << n); ++ i) cin >> a[i];
	a[1 << n] = 0;
	for(int i = 0; i < (1 << n); ++ i) f[i] = make_pair(i, 1 << n);
	for(int i = 0; i < n; ++ i)
	for(int j = 0; j < (1 << n); ++ j) {
		if(~j >> i & 1) {
			update(f[j | (1 << i)], f[j]);
		}
	}
	for(int i = 1; i < (1 << n); ++ i) {
		cout << calc(i) << "\n";
	}
	return 0;
}


Measured memory_bytes: 9216