akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e17;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)




/* Segment Tree */
class SegmentTree
{
private:
    long long n;    // 配列の要素数
    long long s;    // 配列を初期化するときの値
    vector<long long> data;     // セグメントツリーを持つ配列
public:
    SegmentTree(long long m, long long t);   // mは配列の要素数、tは配列を初期化するときの値
    long long operation(long long t1, long long t2); // 二項演算
    void update(long long k, long long a);  // k番目(0-indexed)の値をaに変更
    long long query(long long a, long long b);   // [a, b) の最小値を求める。外から呼ぶときはこっち
    long long ans(long long a, long long b, long long k, long long l, long long r);   // [a, b) の最小値を求める。
};

SegmentTree::SegmentTree(long long m, long long t){
    n = 1;
    
    while(n < m) n *= 2;
    
    for(long long i = 0; i < 2 * n - 1; i++){
        data.push_back(t);
    }
    
    s = t;
}

long long SegmentTree::operation(long long t1, long long t2){
    return max(t1, t2);
}

void SegmentTree::update(long long k, long long a){
    k += n - 1;
    data[k] = a;
    
    while(k > 0){
        k = (k - 1) / 2;
        data[k] = operation(data[k * 2 + 1], data[k * 2 + 2]);
    }
}

long long SegmentTree::query(long long a, long long b){
    return ans(a, b, 0, 0, n);
}

long long SegmentTree::ans(long long a, long long b, long long k, long long l, long long r){
    if(r <= a || b <= l) return s;
    if(a <= l && r <= b){
        return data[k];
    }
    else{
        long long vl = ans(a, b, k * 2 + 1, l, (l + r) / 2);
        long long vr = ans(a, b, k * 2 + 2, (l + r) / 2, r);
        
        return operation(vl, vr);
    }
}

int main() {
    ll n, c, x[100000], v[100000];
    
    scanf("%lld %lld", &n, &c);
    REP(i, n){
        scanf("%lld %lld", &x[i], &v[i]);
    }
    
    ll sum1 = 0, sum2 = 0, mx1 = 0, mx2 = 0;
    SegmentTree s1(n, -INF), s2(n, -INF);
    REP(i, n){
        if(i == 0){
            sum1 += v[i] - x[i];
            sum2 += v[n - i - 1] - (c - x[n - i - 1]);
        }
        else{
            sum1 += v[i] - x[i] + x[i - 1];
            sum2 += v[n - i - 1] - (c - x[n - i - 1]) + (c - x[n - i]);
        }
        mx1 = max(mx1, sum1);
        s1.update(i, mx1);
        mx2 = max(mx2, sum2);
        s2.update(i, mx2);
    }
    
    ll mx3 = 0;
    sum1 = 0;
    sum2 = 0;
    REP(i, n - 1){
        if(i == 0){
            sum1 += v[i] - x[i];
            sum2 += v[n - i - 1] - (c - x[n - i - 1]);
        }
        else{
            sum1 += v[i] - x[i] + x[i - 1];
            sum2 += v[n - i - 1] - (c - x[n - i - 1]) + (c - x[n - i]);
        }
        mx3 = max(mx3, max(sum1 - x[i] + s2.query(0, n - i - 1), sum2 - (c - x[n - i - 1]) + s1.query(0, n - i - 1)));
    }
    
    printf("%lld\n", max(max(mx1, mx2), mx3));
}

Measured memory_bytes: 7024
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int N;
const int Nmax = 1e5;
int D[Nmax];

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
N = list(map(int,input()))
ans = sum(N)
ans1 = 0
if N[0] == 1:
  for i in range(len(N)-1):
    ans1 += 9
  print(max(ans,ans1))
else:
  for i in range(len(N)):
    if i == 0:
      ans1 += N[i]-1
    else:
      ans1 += 9
  print(max(ans, ans1))

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};



int main(void){
  ll N;
  cin >> N;
  vector<ll> A(N+1), B(N);
  rep(i, N+1) cin >> A[i];
  rep(i, N) cin >> B[i];

  ll ans = 0;
  rep(i, N){
    if(A[i] > B[i]){
      ans += B[i];
      A[i] -= B[i];
      B[i] = 0;
    }else{
      ans += A[i];
      B[i] -= A[i];
      A[i] = 0;
    }
    if(A[i+1] > B[i]){
      ans += B[i];
      A[i+1] -= B[i];
      B[i] = 0;
    }else{
      ans += A[i+1];
      B[i] -= A[i+1];
      A[i+1] = 0;
    }
  }
  cout << ans << endl;


}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#include <math.h> 

int main()
{
	
	int A, B;
	cin >> A >> B;
	char* L=new char[A+B+1];
	cin >> L;
	bool flag = true;
	for (int i = 0; i < A; i++)
	{
		if ('0' <= L[i] && L[i] <= '9')
		{

		}
		else
		{
			flag = false;
		}
	}
	for (int i = A+1; i < A+B; i++)
	{
		if ('0' <= L[i] && L[i] <= '9')
		{

		}
		else
		{
			flag = false;
		}
	}
	if (L[A] != '-')
	{
		flag = false;
	}
	if (flag)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextInt();

        int cnt = 1;

        int min = arr[0];
        for (int i=1; i<n; i++){
            if (min>arr[i]) cnt++;
            min = Math.min(min, arr[i]);
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 63612
/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX   XXXXXXXXX  XXXXXXXXXXXXXXXX  XXXXXXXXXXXXXXXXXXXXXXXXX X
X XXX XX   XXXX XXXX    X XXX XXX XXXX   XXXX XXXX   XXXXXX X
X XXXXXXXXX XXX XXX XXXXX XXX XXX XXXXXXX XX   XX XXX XX    X
X XXXXX     XXX XXX XXXXX XXX XXX XXX     XXX XXX     X XXX X
X XXX X XXX XXX XXX XXXXX XXX XXX XXX XXX XXX XXX XXXXX XXX X
XX   XXX    XX   XXX    XX    XX   XXX    XXX  XXX    XX    X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXXX   XXXX   XX  X XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXX XXX XXXXXX X X X XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXX     XX     X X X XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXX XXXXXX XXX X XXX XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXXX    XXX    X XXX XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <chrono>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <array>
#include <set>
#include <list>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>
#include <map>
#include <iterator>
#include <cstring>
using namespace std;

#define loop(i,start,end) for(auto i = start; i < end; i++)
#define loopi(end) loop(i,0,end)
#define loopj(end) loop(j,0,end)
#define loopk(end) loop(k,0,end)
#define get_i(n) int n; cin >> n;
#define get_ch(n) char x; cin >> x;
#define get_doub(n) double n; cin >> n;
#define pb push_back
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vb vector<bool>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define clear(a) memset(a, 0, sizeof(a))
#define all(a) (a).begin(), (a).end()
const long long modulo = 1e18+3;
const ll INF = 1e18;
const int inf = 2e9;
const double PI = 3.141592653589793238463;

//#define FILE "substrcmp"
#define FAST_IO
#define FSOL

#ifdef FSOL
void solve() {
	get_i(n); get_i(ma);
	vi w(n), cost(n);
	loopi(n) cin >> w[i] >> cost[i];
	vvll dp(n + 1, vll(ma + 1));
	loop(i, 1, n + 1)
		loopj(ma + 1) {
		if (w[i - 1] > j) dp[i][j] = dp[i - 1][j];
		else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + cost[i - 1]);
	}
	cout << dp[n][ma];
}
#else 
void solve() {
	
}
#endif

int main() {
#ifdef FAST_IO
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#endif
#ifdef DEBUG
	freopen("debug.in", "r", stdin);
	auto timestamp = std::chrono::system_clock::now();
#else 
#ifdef FILE
	freopen(FILE".in", "r", stdin);
	freopen(FILE".out", "w", stdout);
#endif
#endif
	solve();
#ifdef DEBUG 
	cout << endl << "Time elapsed: " << chrono::duration_cast<chrono::milliseconds>(std::chrono::system_clock::now() - timestamp).count() << " ms" << endl;
#endif
	return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
const int N=4004,mod=1e9+7;
int n,m,cnt,ans,a[N],b[N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=m;i++)scanf("%d",&b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	reverse(a+1,a+n+1);
	reverse(b+1,b+m+1);
	for(int i=1;i<n;i++)if(a[i]==a[i+1]){puts("0");return 0;}
	for(int i=1;i<m;i++)if(b[i]==b[i+1]){puts("0");return 0;}
	if(a[1]!=n*m||b[1]!=n*m){puts("0");return 0;}
	ans=1;
	int num=0,p1=0,p2=0;
	for(int i=n*m;i>=1;i--)
	{
		if(a[p1+1]==i&&b[p2+1]==i)p1++,p2++;
		else if(a[p1+1]==i)ans=1ll*ans*p2%mod,p1++;
		else if(b[p2+1]==i)ans=1ll*ans*p1%mod,p2++;
		else if(p1*p2-num<=0){puts("0");return 0;}
		else ans=1ll*ans*(p1*p2-num)%mod;
		num++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
long long int k[200005], l[200005], r[200005];
long long int h[200005], hl;
int comp_h(long long int a, long long int b, int z)
{
	if (z == 0)
	{
		if (l[h[a]] == r[h[a]])
			return 1;
		else if (l[h[b]] == r[h[b]])
			return -1;
		else if (l[h[a]] > r[h[a]] && l[h[b]] > r[h[b]])
		{
			if (k[h[a]] > k[h[b]])
				return 1;
			return -1;
		}
		else if (l[h[a]] < r[h[a]] && l[h[b]] < r[h[b]])
		{
			if (k[h[a]] < k[h[b]])
				return 1;
			return -1;
		}
		else
		{
			if (l[h[a]] < r[h[a]])
				return 1;
			return -1;
		}
	}
	else if (z == 1)
	{
		if (l[h[a]] - r[h[a]] > l[h[b]] - r[h[b]])
			return 1;
		return -1;
	}
	else
	{
		if (r[h[a]] - l[h[a]] > r[h[b]] - l[h[b]])
			return 1;
		return -1;
	}
}
void swap_h(long long int a, long long int b)
{
	long long int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void f1(long long int ne, int z)
{
	h[hl] = ne;
	long long int p = hl;
	hl++;
	while (p > 0)
	{
		if (comp_h((p - 1) / 2, p, z) > 0)
			swap_h((p - 1) / 2, p);
		p = (p - 1) / 2;
	}
	return;
}
long long int f2(int z)
{
	hl--;
	swap_h(0, hl);
	long long int p = 0;
	for (;;)
	{
		if (2 * p + 2 < hl)
		{
			if (comp_h(2 * p + 1, 2 * p + 2, z) > 0)
			{
				if (comp_h(p, 2 * p + 2, z) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1, z) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < hl)
		{
			if (comp_h(p, 2 * p + 1, z) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[hl];
}
int main()
{
	int t;
	scanf("%d", &t);
	long long int n;
	long long int i, j, jj;
	long long int c[200005];
	long long int ans;
	long long int p;
	for (; t > 0; t--)
	{
		scanf("%lld", &n);
		for (i = 0; i < n; i++)
			scanf("%lld %lld %lld", &k[i], &l[i], &r[i]);
		hl = 0;
		for (i = 0; i < n; i++)
			f1(i, 0);
		for (i = 0; i < n; i++)
			c[i] = f2(0);
		ans = 0;
		j = 0;
		while (j<n && l[c[j]]>r[c[j]])
			j++;
		hl = 0;
		for (i = 0; i < j; i++)
		{
			ans += l[c[i]];
			f1(c[i], 1);
			if (hl > k[c[i]])
			{
				p = f2(1);
				ans -= l[p];
				ans += r[p];
			}
		}
		jj = j;
		while (jj < n && l[c[jj]] < r[c[jj]])
			jj++;
		hl = 0;
		for (i = j; i < jj; i++)
		{
			ans += r[c[i]];
			f1(c[i], 2);
			if (hl > n - k[c[i]])
			{
				p = f2(2);
				ans -= r[p];
				ans += l[p];
			}
		}
		for (i = jj; i < n; i++)
			ans += l[c[i]];
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 9544
import sys
input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    s = list(input())
    cnt = 0  # 幸福の人の数
    for i in range(n-1):
        if s[i] == s[i+1]:
            cnt += 1
    # 1回の操作で最大２人まで幸福にできるが，必ず一人は幸福にならない
    print(min(n-1, cnt + 2 * k))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()

if N >= 30:
    Yes()
else:
    No()


Measured memory_bytes: 9500
#include <iostream>
#include <string>

using namespace std;

int main() {
	int a;
	cin >> a;
	int b[3];
	for (int i = 0; i < 3; i++) {
		b[i] = a % 10;
		a = a / 10;
	}
	for (int i = 0; i < 3; i++) {
		if (b[i] == 7) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3596
import itertools
n = int(input())
a = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

able = [0] * (max(n * max(a) + 1, 2001))
for item in itertools.product([0, 1], repeat=n):
    total = sum([i * j for i, j in zip(a, item)])
    able[total] = 1

for m in M:
    print('yes' if able[m] else 'no')



Measured memory_bytes: 5700
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
 
 double abs(double x)
 {
   if(x<0) return -x;
   else return x;       
 }
 
 bool judge(int x,int y)
 {
   if(x>=0&&x<10&&y>=0&&y<10) return true;
   else return false;     
 }
  
 int main()
 {
   int map[10][10]={{0}};
   int x,y,s;
   int dep=0;
   int blank=0;
   char temp,temp2;
   while(cin>>x>>temp>>y>>temp2>>s)
   {
     if(s==1)
     {
       if(judge(x-1,y)) map[x-1][y]++;
       if(judge(x+1,y)) map[x+1][y]++;
       if(judge(x,y+1)) map[x][y+1]++;
       if(judge(x,y-1)) map[x][y-1]++;
       if(judge(x,y)) map[x][y]++;        
     }                   
     else if(s==2)
     {
       for(int i=-1;i<=1;i++)
       {
         for(int j=-1;j<=1;j++)
         {
           if(judge(x+i,y+j)) map[x+i][y+j]++;       
         }        
       }     
     }
     else
     {
       for(int i=-1;i<=1;i++)
       {
         for(int j=-1;j<=1;j++)
         {
           if(judge(x+i,y+j)) map[x+i][y+j]++;       
         }        
       }   
       if(judge(x-2,y)) map[x-2][y]++;
       if(judge(x+2,y)) map[x+2][y]++;
       if(judge(x,y+2)) map[x][y+2]++;
       if(judge(x,y-2)) map[x][y-2]++;    
     }
   }
   for(int i=0;i<10;i++)
   {
     for(int j=0;j<10;j++)
     {
       if(!map[i][j]) blank++;
       if(map[i][j]>dep) dep=map[i][j];        
     }        
   }
   cout<<blank<<endl;
   cout<<dep<<endl;
   //while(1);      
   return 0;    
 }

 

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

const int maxn = 333;

vector<int> vt[maxn];

int res[maxn][maxn];

string s[maxn];


int main() {
	//freopen("inp.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = 0;
	int m = 0;
	int k = 0;
	cin >> n >> m >> k;
	for(int i=0;i<n;i++) cin >> s[i];
	int maxX = 0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if (s[i][j] == '#') {
				vt[i].push_back(j);
				maxX = max(maxX, i);
			}
		}
	}
	
	int cnt = 0;
	int lastX = -1;
	
	for(int i=0;i<n;i++) {
		int nxtX = i;
		if (i == maxX) nxtX = n-1;
		sort(vt[i].begin(), vt[i].end());
		if (vt[i].size()) {
			int lastY = -1;
			int maxY = *max_element(vt[i].begin(), vt[i].end());
			for(int j=0;j<vt[i].size();j++) {
				int nxtY = vt[i][j];
				if (vt[i][j] == maxY) nxtY = m-1;
				for(int xx=lastX + 1; xx <= nxtX; xx++) {
					for(int yy = lastY + 1; yy <= nxtY; yy++) {
						res[xx][yy] = cnt;
					}
				} 
				lastY = nxtY;
				cnt++;
			}	
			lastX = nxtX;
		}
	}
	
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) cout << res[i][j] + 1<<" ";
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 1920
from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())

ch -= 1
cw -= 1
dh -= 1
dw -= 1

S = [input() for i in range(h)]

walk = [(-1, 0), (0, 1), (1, 0), (0, -1)]
warp = [(y, x) for y in range(-2, 3) for x in range(-2, 3)]

q = deque()
q.append((ch, cw))

dist = [[10**7] * w for _ in range(h)]
dist[ch][cw] = 0

while q:
    y, x = q.popleft()
    if [y, x] == [dh, dw]:
        break

    for dy, dx in walk:
        if 0 <= y+dy < h and 0 <= x+dx < w:
            if S[y+dy][x+dx] == '.':
                if dist[y][x] < dist[y+dy][x+dx]:
                    dist[y + dy][x + dx] = dist[y][x]
                    q.appendleft((y+dy, x+dx))

    for dy, dx in warp:
        if 0 <= y+dy < h and 0 <= x+dx < w:
            if S[y+dy][x+dx] == '.':
                if dist[y][x]+1 < dist[y+dy][x+dx]:
                    dist[y + dy][x + dx] = dist[y][x]+1
                    q.append((y+dy, x+dx))

print(dist[dh][dw] if dist[dh][dw] != 10**7 else -1)

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

int main(){
	long long x,d,k;
	cin >> x >> d >> k;
	long long mins=abs(x);
	long long a;
	if(d%2){
		if(mins>=k){
			mins-=k;
			d--;
			if(2*(mins/(2*k))<=d){
				a=2*(mins/(2*k));
				mins-=a*k;
				d-=a;
				if(d>=2){
					mins=min(abs(mins-2*k),mins);
				}
			}else{
				mins-=k*d;
			}
		}else{
			mins=abs(mins-k);
		}
	}else{
		if(2*(mins/(2*k))<=d){
			a=2*(mins/(2*k));
			mins-=a*k;
			d-=a;
			if(d>=2){
				mins=min(abs(mins-2*k),mins);
			}
		}else{
			mins-=k*d;
		}
	}
	cout << mins << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}
int t[100010], x[100010], y[100010];
int main(){

	int n;
	cin >> n;
	

	rep(i,n) cin >> t[i] >> x[i] >> y[i];
	int dis;

	rep(i, n) {
		if (i == 0) {
			dis = t[i] - (x[i] + y[i]);
			if (x[i] + y[i] > t[i]) {
				pr("No");
				return 0;
			}
			else if (dis % 2 != 0) {
				pr("No");
				return 0;
			}
		}
		else {
			dis = (t[i] - t[i - 1]) - (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]));
			if(t[i] - t[i-1] < abs(x[i] - x[i-1])+abs(y[i]-y[i-1])) {
				pr("No");
				return 0;
			}
			else if (dis % 2 != 0) {
				pr("No");
				return 0;
			}
		}
	}
	pr("Yes");

	//system("pause");
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void)
{
int n,a[50]={0},i,j,sum=0;
scanf("%d",&n);
  for(i=0;i<n;i++)
  {
  scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++)
  {
  for(j=i+1;j<n;j++)
    sum+=a[i]*a[j];
  }
  printf("%d",sum);
 
return 0;
}

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

int main()
{
    int w, a, b;

    scanf("%d %d %d", &w, &a, &b );

    if ( abs( a - b ) <= w ) {
        printf("%d\n", 0 );
    } else {
        printf("%d\n", abs( a - b ) - w );
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);

set<int> st[26];
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
 
	int D;
	cin >> D;
	rep(i,26){
		st[i].insert(-1);
		st[i].insert(D);
	}
	int c[26];
	int s[D][26];
	int t[D];
	int ok[26];
	rep(i,26) ok[i] = -1;
	rep(i,26) cin >> c[i];
	rep(i,D){
		rep(j,26){
			cin >> s[i][j];
		}
	}
	int num;
	rep(i,D){
		int maxi = -INF;
		rep(k,26){
			int ans = 0;
			ans += s[i][k];
			// ok[t[i]] = i;
			rep(j,26){
				if(j == k) continue;
				ans -= c[j] * (i-ok[j]);
			}
			if(maxi < ans){
				maxi = ans;
				num = k;
			}
		}
		ok[num] = i;
		t[i] = num;
		st[num].insert(i);
	}	
	rep(loop,3){
		rep(i,D-1){
			int dx = 0;
			int old1 = t[i], old2 = t[i+1];
			// st[_].erase(d[i]);
			auto itr = st[old1].upper_bound(i);
			int W2 = *itr;
			--itr;
			--itr;
			int W1 = *itr; 
			dx -= c[old1] * (i - W1) * (W2 - i);
			auto itr1 = st[old2].upper_bound(i);
			int A2 = *itr1;
			--itr1;
			int A1 = *itr1;
			dx += c[old2] * (i - A1) * (A2 - i);
			// st[q[i]].insert(d[i]);
			dx += s[i][t[i+1]] - s[i][t[i]];

			++i;
			// st[_].erase(d[i]);
			itr = st[old2].upper_bound(i);
			W2 = *itr;
			--itr;
			--itr;
			W1 = *itr;
			dx -= c[old2] * (i - W1) * (W2 - i);
			itr1 = st[old1].upper_bound(i);
			A2 = *itr1;
			--itr1;
			A1 = *itr1;
			dx += c[old1] * (i - A1) * (A2 - i);
			// st[q[i]].insert(d[i]);
			dx += s[i][t[i-1]] - s[i][t[i]];
			--i;
			if(dx > 0){
				t[i] = old2;
				t[i+1] = old1;
			}
		}
	}
	rep(loop,80000){
		rep(i,D-1){
			int dx = 0;
			int old1 = t[i], old2 = t[i+1];
			// st[_].erase(d[i]);
			auto itr = st[old1].upper_bound(i);
			int W2 = *itr;
			--itr;
			--itr;
			int W1 = *itr; 
			dx -= c[old1] * (i - W1) * (W2 - i);
			auto itr1 = st[old2].upper_bound(i);
			int A2 = *itr1;
			--itr1;
			int A1 = *itr1;
			dx += c[old2] * (i - A1) * (A2 - i);
			// st[q[i]].insert(d[i]);
			dx += s[i][t[i+1]] - s[i][t[i]];

			++i;
			// st[_].erase(d[i]);
			itr = st[old2].upper_bound(i);
			W2 = *itr;
			--itr;
			--itr;
			W1 = *itr;
			dx -= c[old2] * (i - W1) * (W2 - i);
			itr1 = st[old1].upper_bound(i);
			A2 = *itr1;
			--itr1;
			A1 = *itr1;
			dx += c[old1] * (i - A1) * (A2 - i);
			// st[q[i]].insert(d[i]);
			dx += s[i][t[i-1]] - s[i][t[i]];
			--i;
			if(dx > 0){
				t[i] = old2;
				t[i+1] = old1;
			}
		}
	}
	rep(i,D) cout << t[i]+1 << endl;
}

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

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

    for(int i = 0; i < N; i++) {
        bool ans = true;
        int B_top = 0, C_top = 0;
        vector<int> ball(10);
        for(int i = 0; i < 10; i++) {
            cin >> ball[i];
        }
        for(int j = 0; j < 10; j++) {
            if(B_top < ball[j]) {
                B_top = ball[j];
            }
            else if(C_top < ball[j]) {
                C_top = ball[j];
            }
            else {
                ans = false;
                break;
            }
        }
        if(ans) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl; 
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        int N, M;
        string s;
        cin >> N;
        map<string, int> mp;

        rep(i, N)
        {
                cin >> s;
                mp[s]++;
        }
        cin >> M;

        rep(i, M)
        {
                cin >> s;
                mp[s]--;
        }
        int ans = 0;
        for (auto itr = mp.begin(); itr != mp.end(); itr++)
                ans = max(ans, itr->second);

        cout << ans << endl;

        return 0;
}


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

long long gcd(long long a,long long b){
  return b ? gcd(b, a%b) : a;
}

long long lcm(long long a, long long b){
  return a/gcd(a,b)*b;
}

long long f(long long x, int c, int d){
  long long result=x;
  result-=x/c;
  result-=x/d;
  result+=x/lcm(c,d);
  return result;
}

int main(){
  long long A, B;
  int C, D;
  cin >> A >> B >> C >> D;
  long long ans = f(B, C, D)-f(A-1, C, D);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<i64> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] -= i + 1;
    }
    sort(WHOLE(A));
    i64 ans = 0;
    for(auto &x : A) {
        ans += abs(A[N / 2] - x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
char a[100005];
int ans=0;
int main()
{
	cin>>a;
	for(int i=1;i<strlen(a);i++)
	{
		if(a[i]!=a[i-1]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int N;
        int X;
            cin >> N >> X;
        vector<int> L(N);
            for(int i = 0; i < N; i++){
                cin >> L.at(i);
            }
        int p = 0;
        int c = 1;
            for(int j = 0; j < N; j++){
                //if(p <= X){
                //    c += 1;
                //}
                    p += L.at(j);
                if(p <= X){
                    c += 1;
                }
            }
                cout << c;
    return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

template<typename T>
struct SegmentTree{
    int n;
    T e; //単位元
    vector<T> v;
    function<T(T,T)> operation;
    function<T(T,T)> update;
    //区間[a,b)に対してのクエリ 今は[l,r)を見ている
    T _query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return e;
        if(a<=l && r<=b) return v[k];
        else{
            T c1=_query(a,b,2*k+1,l,(l+r)/2);
            T c2=_query(a,b,2*k+2,(l+r)/2,r);
            return operation(c1,c2);
        }
    }
public:
    SegmentTree(size_t _n,T _e,function<T(T,T)> _operation,function<T(T,T)> _update):e(_e),operation(_operation),update(_update){
        n=1;
        while(n<_n){
            n*=2;
        }
        v=vector<T>(2*n-1,e);
    }
    void change(int i,T x){
        i+=n-1;
        v[i]=update(v[i],x);
        while(i>0){
            i=(i-1)/2;
            v[i]=operation(v[i*2+1],v[i*2+2]);
        }
    }
    T query(int a,int b){
        return _query(a,b,0,0,n);
    }
    T operator[](int i){
        return v[i+n-1];
    }
};
const int INF = 200200;
int main(){
    int n,k; cin >> n >> k;
    SegmentTree<int> stmax(n,0,[](int a,int b){return max(a,b);},[](int a,int b){return b;});
    SegmentTree<int> stmin(n,INF,[](int a,int b){return min(a,b);},[](int a,int b){return b;});
    int p[n];
    rep(i,n){
        cin >> p[i];
        stmax.change(i,p[i]);
        stmin.change(i,p[i]);
    }
    vector<bool> mi(n,1);
    int ans=n-k+1;
    rep(i,n-k){
        if(p[i]==stmin.query(i,i+k)&&stmax.query(i+1,i+k+1)==p[i+k]){
            ans--;
            mi[i+1]=0;
        }
    }
    //cout << ans << endl;
    vector<int> v;
    int cnt=1;
    int f=0;
    rep(i,n-1){
        if(p[i]>p[i+1]){
            cnt=1;
            f=i+1;
        }
        else cnt++;
        if(cnt==k){
            cnt=1;
            v.pb(f);
            f=i+1;
        }
    }
    //rep(i,n) cout << mi[i] << " ";
    rep(i,v.size()){
        //cout << v[i] << " ";
        if(v[0]+k<=v[i] && mi[v[i]]) ans--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int N, A, B;
    string S;
    int sanka = 0;
    int foreign_sanka = 0;

    cin >> N >> A >> B;
    cin >> S;
    
    for (int i = 0; i < N; i++) {
        if (S[i] == 'c') {
            cout << "No" << endl;
        } else if (S[i] == 'a') {
            if (sanka < A+B) {
                sanka++;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            if (sanka < A+B && foreign_sanka < B) {
                sanka++;
                foreign_sanka++;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
    }
}


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

int main(void) {
  int a,b,c,s,k;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&k);
  s=a;
  if(b>s){
    s=b;
  }
    
  if(c>s){
    s=c;
    }
    
    if(s==a){
      a=a*pow(2,k);
    }else if(s==b){
      b=b*pow(2,k);
    }else if(s==c){
      c=c*pow(2,k);
    }
  
  printf("%d\n",a+b+c);
  return 0;
}

Measured memory_bytes: 128
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p,s=[-1]*-~n,[-1]*-~n
for i,(a,b)in enumerate(t):
  x,y=r(a),r(b)
  if(x!=y)*m>i:
    if x>y:x,y=y,x
    p[x]+=p[y]
    p[y]=x
  if(x!=y)*i<m:
    s[a]-=1
    s[b]-=1
print(*[s[i+1]-p[r(i+1)]for i in range(n)])

Measured memory_bytes: 96856
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	map<int, int> a, b;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		if (i % 2 == 0)
		{
			a[x]++;
		}
		else
		{
			b[x]++;
		}
	}

	int m = n / 2;

	vector<pair<int, int>> ap;
	for (map<int, int>::iterator it = a.begin(); it != a.end(); it++)
	{
		pair<int, int> i = *it;
		ap.push_back(make_pair(i.second, i.first));
	}

	sort(ap.begin(), ap.end());
	reverse(ap.begin(), ap.end());

	vector<pair<int, int>> bp;
	for (map<int, int>::iterator it = b.begin(); it != b.end(); it++)
	{
		pair<int, int> i = *it;
		bp.push_back(make_pair(i.second, i.first));
	}

	sort(bp.begin(), bp.end());
	reverse(bp.begin(), bp.end());

	int ans = 0;
	if (a.size() == 1 && b.size() == 1)
	{
		if (ap.front().second == bp.front().second)
		{
			ans = m;
		}
		else
		{
			ans = 0;
		}
	}
	else
	{
		if (ap.front().first == bp.front().first)
		{
			if (ap.front().second == bp.front().second)
			{
				ans = 2 * m - max(ap.front().first + bp.at(1).first, bp.front().first + ap.at(1).first);
			}
			else
			{
				ans = 2 * (m - ap.front().first);
			}
		}
		else
		{
				ans = m - min(ap.front().first, bp.front().first);
		}
	}

	cout << ans << endl;
}

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

string s;

int main()
{
    cin >> s;
    int cnt = 0;
    for (int i = 1; i < (int)s.length(); i++) {
        if (s[i] == s[i-1]) {
            s[i-1] == '1' ? s[i] = '0' : s[i] = '1';
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 512
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long int				int32;
typedef unsigned long int		uint32;
typedef long long int			int64;
typedef unsigned long long int  uint64;
typedef pair<int, int>			PII;
typedef vector<int>				VI;
typedef vector<long long>		VLL;
typedef vector<string>			VS;
typedef vector<PII>				VII;
typedef vector<VI>				VVI;

#define MEM(a, b)				memset(a, (b), sizeof(a))
#define calctime				std::cout << setprecision(5) << fixed << "Time to completed program: " << (double)(clock() - start)/(CLOCKS_PER_SEC) << "s.\n";
#define FOR(i, j, k, in)		for (int i = (j); i < (k); i += (in))
#define FORW(i, j, k, in)		for (int i = (j); i <= (k); i += (in))
#define RFOR(i, j, k, in)		for (int i = (j); i >= (k); i -= (in))
#define RFORW(i, j, k, in)		for (int i = (j); i > (k); i -= (in))
#define aint64(cont)			cont.begin(), cont.end()
#define raint64(cont)			cont.end(), cont.begin()
#define sz(cont)				int((cont).size())
#define PB						push_back
#define MP						make_pair
#define EPS						1e-9
#define MOD						1000000007
#define PI						3.1415926535897932384626433832795
#define Ff						first
#define Ss						second
#define FastIO					ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define fileIO(name)			ifstream iFs(name".inp"); ofstream oFs(name".out");
#define fileio(name)			ifstream cin(name".inp"); ofstream cout(name".out");
#define endl					'\n'

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

VI adj[100006] = {};
int dp[100006] = {};
bool used[100006] = {};

void dfs(int u) {
	used[u] = 1;
	FOR(i, 0, adj[u].size(), 1) {
		int v = adj[u][i];
		if (!used[v])
			dfs(v);
		dp[u] = max(dp[u], 1 + dp[v]);
	}
}

int main() {
	FastIO;

	int n, m; cin >> n >> m;
	FOR(i, 0, m, 1) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
	}
	
	int ans = 0;
	FORW(i, 1, n, 1) {
		if (!used[i])
			dfs(i);
	}
	FORW(i, 1, n, 1) ans = max(ans, dp[i]);
	cout << ans << endl;

	//calctime
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll K, S;
	cin >> K >> S;
	ll res = 0;
	REP(x, K+1)REP(y, K+1){
		ll z = S - x - y;
		res += (z>=0 && z<=K);
	}
	cout << res << endl;
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

int N;
vpint ps;

const int mod=998244353;
int po[222];

bool ok(pint d,pint dd){
    if(d.fi==0)return dd.fi==0;
    return d.fi*dd.se==d.se*dd.fi;
}

signed main(){
    po[0]=1;
    for(int i=1;i<222;i++)po[i]=po[i-1]*2%mod;

    cin>>N;
    rep(i,N){
        int x,y;
        cin>>x>>y;
        ps.pb({x,y});
    }
    sort(all(ps));


    int ans=N+1;
    rep(i,N){
        for(int j=i+1;j<N;j++){
            int num=0;
            pint d={ps[j].fi-ps[i].fi,ps[j].se-ps[i].se};
            for(int k=j+1;k<N;k++){
                pint dd={ps[k].fi-ps[i].fi,ps[k].se-ps[i].se};
                if(ok(d,dd))num++;
            }
            ans=(ans+po[num])%mod;
        }
    }

    cout<<(po[N]-ans+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 256
#nは街の数　kは移動の回数　k＋１個の街にいくことになる　
#最高でもn回移動すれば一つは二回訪れる街が現れる　そのあとはループする
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = [-1]*(n+1) #街３に5回目の移動でついた場合、b[3]に５が入る　
tmp = [] #経路を記録していく
here = 1
count = 0 #移動回数

while True:
    if b[here] != -1: #一度訪れた街に再び来た
        roop = count - b[here] #ループの長さ　(街aに二回目に来た時の移動回数-一回目に来た時の移動回数)
        if k < count: #ループに入る前に移動が終わった時
            print(tmp[k])
        else:
            new_tmp = tmp[b[here]:]
            s = k-b[here]
            print(new_tmp[s%roop])
        break
    b[here] = count
    count += 1
    tmp.append(here)
    here = a[here-1]


Measured memory_bytes: 32176
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#include <climits>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)

struct Edge
{
	int to;
	int cost;
};

struct Node
{
	int city_index;
	int total_cost;
	int current_life;
	int can_regain_remain;

	bool operator >(const Node &a) const
	{
		return total_cost > a.total_cost;
	}
};

int main()
{
	int city_count, initial_life, cooler_count, road_count, start_index, goal_index;
	while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index,
		city_count)
	{
		// input
		vector<int> is_cooler(city_count, false);
		REP(i, cooler_count)
		{
			int cooler_index;
			cin >> cooler_index;
			is_cooler[cooler_index] = true;
		}
		vector<vector<Edge>> roads(city_count);
		REP(i, road_count)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			roads[from].push_back({ to, cost });
			roads[to].push_back({ from, cost });
		}

		// dijkstra
		vector<vector<int>> d(city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost
		d[start_index][initial_life] = 0;
		priority_queue<Node, vector<Node>, greater<Node> > pq;
		pq.push({ start_index, 0, initial_life, 0});
		while (true)
		{
			if (pq.empty())
			{
				cout << "Help!" << endl;
				break;
			}
			auto current_node = pq.top(); pq.pop();
			if (current_node.city_index == goal_index)
			{
				cout << current_node.total_cost << endl;
				break;
			}
			for (auto &road : roads[current_node.city_index])
			{
				int total_cost = current_node.total_cost + road.cost;
				int life = current_node.current_life - road.cost;
				int can_regain_remain = is_cooler[current_node.city_index] ? initial_life - current_node.current_life : current_node.can_regain_remain;
				if (life < 0)
				{
					int shortage = -life;
					can_regain_remain -= shortage;
					if (can_regain_remain < 0)
					{
						continue;
					}
					total_cost += shortage;
					life = 0;
				}
				auto &di = d[road.to][can_regain_remain];
				if (total_cost < di)
				{
					di = total_cost;
					pq.push({ road.to, total_cost, life, can_regain_remain });
				}
			}

		}
	}

	return 0;
}

Measured memory_bytes: 1452
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18+5;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  long double a,b,h,m,x,y,cnt,ans;
  cin >> a >> b >> h >> m;
  x=m*6,y=h*30+0.5*m;
  cnt=max(x,y)-min(x,y);
  if(cnt>180) {
    cnt=360-cnt;
  }
  ans=a*a+b*b-2*a*b*cos(cnt/180*pi);
  ans=sqrt(ans);
  cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 4184
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1);

void test();

int main() {
    fast_io();
    test();
    return 0;
}

void test() {
    int n;
    cin >> n;
    cout << (n - 2) * 180 << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include <random>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include <unordered_map>
#include<numeric>
using namespace std;
#define ios std::ios_base::sync_with_stdio(false);
#define ll  long long
#define pb push_back
#define fi(ss) freopen (ss,"r",stdin)
#define fo(ss) freopen (ss,"w",stdout)
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
#define ld long double
#define lp(i,n) for(int i = 0 ; i < n ; ++i)
typedef pair<ll,char> pii;
typedef pair<pii,int> tri;
using namespace std;

int main() {
	ios
	ld n,m,d;
	cin >> n >> m >> d;
	cout << fixed << setprecision(12);
	if (d == 0) {
		cout << (m - 1)* (1.0 / n);
	} else {
		cout << (m-1) * 2.0*(n - d) / (1.0*n * n);
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
#include <queue>
using namespace std;
using ll = long long int;
 
 
int main(void){
    ll n, m;
    cin >> n >> m;
    priority_queue<int> a;
    for(ll i = 0; i < n; i++){
        ll check;
        cin >> check;
        a.push(check);
    }
    for(ll i = 0; i < m; i++){
        ll count = a.top();
        a.pop();
        count /= 2;
        a.push(count);
    }
    ll sum = 0;
    for(ll i = 0; i < n; i++){
        ll count = a.top();
        sum += count;
        a.pop();
    }
    cout << sum << endl;
    return 0;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

struct graph{
    vector<vector<int>> adj;
    int n;
    graph(){}
    graph(int n) : n(n), adj(n){}
    void add_edge(int a, int b, bool directed = false){
        adj[a].push_back(b);
        if(!directed) adj[b].push_back(a);
    }
	pii distances(int s){
		const int INF = 1e9;
		vector<int> D(n, INF); D[s] = 0; 
		queue<int> q; q.push(s);
		int lst = 0, lstd = 0;
		while(!q.empty()){
			int u = q.front(); q.pop();
			int d = D[u];
			lst = u, lstd = d;
			for(int v : adj[u]) if(D[v] == INF){
				D[v] = d + 1;
				q.push(v);
			}
		}
		return {lst, lstd};
	}
	void input(int m, int ind = 1, bool directed = false){
        for(int i = 0; i < m; i++){
            int u, v;
            scanf("%d %d", &u, &v);
            add_edge(u - ind, v - ind, directed);
        }
    }
};

int main(){
	int n; sd(n);
	graph g(n);
	g.input(n - 1);
	pii U = g.distances(0);
	pii Q = g.distances(U.F);
	printf(Q.S % 3 == 1 ? "Second\n" : "First\n");
}

Measured memory_bytes: 16588