akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

//count inside [sy,ey) [sx,ex)
int count_inside(VVI &sum, int sy, int sx, int ey, int ex)
{
    if (sy == ey || sx == ex)
        return 0;
    return sum[ey][ex] - sum[sy][ex] - sum[ey][sx] + sum[sy][sx];
}

int main()
{
    int n, k;
    cin >> n >> k;
    VVI black(2 * k, VI(2 * k, 0));
    VVI white(2 * k, VI(2 * k, 0));
    rep(i, n)
    {
        int x, y;
        char c;
        cin >> x >> y >> c;
        x %= 2 * k;
        y %= 2 * k;
        if (c == 'B')
        {
            black[y][x]++;
        }
        else
        {
            white[y][x]++;
        }
    }
    VVI bsum(2 * k + 1, VI(2 * k + 1, 0));
    VVI wsum(2 * k + 1, VI(2 * k + 1, 0));
    rep(i, 2 * k)
    {
        rep(j, 2 * k)
        {
            bsum[i + 1][j + 1] = bsum[i][j + 1] + bsum[i + 1][j] - bsum[i][j] + black[i][j];
            wsum[i + 1][j + 1] = wsum[i][j + 1] + wsum[i + 1][j] - wsum[i][j] + white[i][j];
        }
    }
    int ans = -1;
    rep(i, k)
    {
        rep(j, k)
        {
            int wnum = count_inside(wsum, 0, 0, i, j) + count_inside(wsum, i, j, i + k, j + k) + count_inside(wsum, i + k, j + k, 2 * k, 2 * k) + count_inside(wsum, i + k, 0, 2 * k, j) + count_inside(wsum, 0, j + k, i, 2 * k);
            int bnum = count_inside(bsum, 0, j, i, j + k) + count_inside(bsum, i, j + k, i + k, 2 * k) + count_inside(bsum, i, 0, i + k, j) + count_inside(bsum, i + k, j, 2 * k, j + k);
            chmax(ans, bnum + wnum);
            bnum = count_inside(bsum, 0, 0, i, j) + count_inside(bsum, i, j, i + k, j + k) + count_inside(bsum, i + k, j + k, 2 * k, 2 * k) + count_inside(bsum, i + k, 0, 2 * k, j) + count_inside(bsum, 0, j + k, i, 2 * k);
            wnum = count_inside(wsum, 0, j, i, j + k) + count_inside(wsum, i, j + k, i + k, 2 * k) + count_inside(wsum, i, 0, i + k, j) + count_inside(wsum, i + k, j, 2 * k, j + k);
            chmax(ans, bnum + wnum);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 66068
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll a, b, c;
  cin>>a>>b>>c;
  if(c-a-b>=0 && 4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



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

int main() {
	int a[3],j=0,k=0;
	cin >> a[0] >> a[1] >> a[2];
	
	for (int i = 0; i < 3; i++)
	{
		if(a[i] == 7) j++;
		if(a[i] == 5) k++;

	}

	if(j == 1 && k == 2) cout << "YES" << endl;
	else  cout << "NO" << endl;
	

}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct UnionFind {
  vector<int> parent; // parentの番号。親だった場合は-(その集合のサイズ)
  // parentはすべて-1にする。全てバラバラになる
  UnionFind(int N) { parent = vector<int>(N, -1); }
  // Aがどのグループに属しているかを調べる
  int root(int A) {
    if (parent[A] < 0) return A;
    return (parent[A] = root(parent[A]));
  }
  // 自分のいるグループの頂点数を調べる
  int size(int A) { return -parent[root(A)]; }
  // AとBをくっつける
  int connect(int A, int B) {
    // AとBを直接つなぐのではなくroot(A)とroot(B)をくっつける
    A = root(A);
    B = root(B);
    if (A == B) return false; // すでにくっついている
    // 大きい方(A)を小さい方(B)にくっつけたいので大小が逆だったらひっくり返す
    if (size(A) < size(B)) swap(A, B);
    parent[A] += parent[B]; // Aのサイズを更新する
    parent[B] = A;          // Bの親をAに変更する
    return true;
  }
};

void solve() {
  int n, m;
  cin >> n >> m;
  UnionFind uni(n);
  rep(i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    uni.connect(x, y);
  }
  map<int, int> mp;
  rep(i, n) mp[uni.root(i)] = 0;
  // dump(mp);
  int ans = mp.size();
  // dump(ans);
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int K, S; cin >> K >> S;
	int Z, ans = 0;
	for(int X = 0; X <= K; X++) for(int Y = 0; Y <= K; Y++) {
		Z = S - X - Y;
		if(Z >= 0 && Z <= K) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            sum += Math.min(x,k-x) * 2;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <stack>
const int INF = 1e9;

struct Edge
{
	int cost, to;
};

class Vertex
{
public:
	int no;
	int cost;
	std::vector<Edge> ve;
};

int main()
{
	int N; std::cin >> N;
	int M; std::cin >> M;
	
	int d[128][128];
	for(int i=0; i<N; i++)
		for(int j=0; j<N; j++)
		{
			d[i][j] = INF;
		}
	for(int i=0; i<N; i++)
	{
		d[i][i] = 0;
	}
	std::vector<std::vector<std::pair<int, int> > > edge(N);
	int num[128][128];
	for(int m=0; m<M; m++)
	{
		int a; std::cin >> a;
		int b; std::cin >> b;
		int c; std::cin >> c;
		a--; b--;
		d[a][b] = c; d[b][a] = c;
		edge[a].push_back(std::pair<int, int>(b,c));
		edge[b].push_back(std::pair<int, int>(a,c));
		num[a][b] = m; num[b][a] = m;
	}
	/* for(int i=0; i<N; i++)                                       */
	/* 	for(int j=0; j<N; j++)                                      */
	/* 	{                                                           */
	/* 		std::cout << i << " " << j << " " << d[i][j] << std::endl; */
	/* 	}                                                           */
	/* for(auto &x : edge[0])        */
	/* {                             */
	/* 	std::cout << x.first << " "; */
	/* }                             */

	//ワーシャルフロイド法
	for(int k=0; k<N; k++)
		for(int i=0; i<N; i++)
			for(int j=0; j<N; j++)
			{
				d[i][j] = std::min(d[i][j], d[i][k]+d[k][j]);
			}
	/* for(int i=0; i<N; i++)                                     */
	/* for(int j=0; j<N; j++)                                     */
	/* {                                                          */
	/* std::cout << i << " " << j << " " << d[i][j] << std::endl; */
	/* }                                                          */
	
	std::vector<bool> used(M);
	for(auto x : used)
	{
		x = false;
	}
	for(int i=0; i<N; i++)
		for(int j=i+1; j<N; j++)
		{
			std::stack<std::vector<int> > st;
			std::vector<int> tmp; tmp.push_back(i);
			st.push(tmp);

			while(!st.empty())
			{
				std::vector<int> path = st.top(); st.pop();
				if(path.back()==j)
				{
					for(int k=0; k<path.size()-1; k++)
					{
						used[num[path[k]][path[k+1]]] = true;
					}
				}
				else
				{
					for(auto &x : edge[path.back()])
					{
						if(d[i][x.first]==d[i][path.back()]+x.second)
						{
							tmp = path;
							tmp.push_back(x.first);
							st.push(tmp);
						}
					}
				}
			}

		}
	int ans = 0;
	for(auto x : used)
	{
		if(x==false) ans++;
	}
	std::cout << ans << std::endl;

	return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

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


    int n,q;
    cin >> n >> q;

    
    UnionFind uf = UnionFind(n);

    rep(i,0,q){
        int op, x, y;
        cin >> op >> x >> y;
        if(op){
            if(uf.issame(x,y)){
                cout << 1 << endl;
            }else{
                cout << 0 << endl;
            }
        }else{
            uf.merge(x,y);
        }
    }
   
}


Measured memory_bytes: 3372
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;

using Input = pair<int, int>;

int main()
{
	int count = 1;
	string s, result;
	cin >> s;
	for (auto ch : s)
	{
		if (count % 2 == 1)
			result += ch;
		count++;
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		int score = 0;

		for (int i = 0; i < n - 1; i++) {
			if (s.charAt(i) == s.charAt(i + 1)) score++;
		}

		int ans = Math.min(score + 2 * k, n - 1);
		System.out.println(ans);
	}
}


Measured memory_bytes: 26644
#include<bits/stdc++.h>
#define llong __int128
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

map<llong,llong> mp;
llong n,A,B,C,D;

void read128(__int128 &x) {long long y; scanf("%lld",&y); x = y;}

llong absl(llong x) {return x<0?-x:x;}

void updmin(llong &x,llong y) {x = min(x,y);}

void dfs(llong x)
{
	if(mp.count(x)) {return;}
	llong ret = x*D,t;
	t = x/2ll; dfs(t); updmin(ret,mp[t]+min((x-x/2ll)*D,A+(x%2ll)*D));
	t = (x+1)/2ll; dfs(t); updmin(ret,mp[t]+min((x-(x+1ll)/2ll)*D,A+(2ll-x%2ll)%2ll*D));
	t = x/3ll; dfs(t); updmin(ret,mp[t]+min((x-x/3ll)*D,B+(x%3ll)*D));
	t = (x+2)/3ll; dfs(t); updmin(ret,mp[t]+min((x-(x+2ll)/3ll)*D,B+(3ll-x%3ll)%3ll*D));
	t = x/5ll; dfs(t); updmin(ret,mp[t]+min((x-x/5ll)*D,C+(x%5ll)*D));
	t = (x+4)/5ll; dfs(t); updmin(ret,mp[t]+min((x-(x+4ll)/5ll)*D,C+(5ll-x%5ll)%5ll*D));
	mp[x] = ret;
	return;
}

int main()
{
	int T = read(); while(T--)
	{
		read128(n),read128(A),read128(B),read128(C),read128(D);
		mp.clear(); mp[0] = 0ll; mp[1] = D;
		dfs(n);
		printf("%lld\n",(long long)mp[n]);
	}
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <climits>
#include <unordered_map>
#include <numeric>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<int,int> pii;
ll a[400];
ll sum[401];
ll dp[401][401];
ll dfs(int x,int y){
    if(dp[x][y] != -1)return dp[x][y];
    if(x>=y)return dp[x][y] = 0;
    dp[x][y] = 1LL<<60;
    for(int i = x; i <= y; i++){
        dp[x][y] = min(dp[x][y], dfs(x,i) + dfs(i+1,y) + sum[y+1]-sum[x]);
    }
    return dp[x][y];
}
int main(){
    int n;
    cin >> n;
    rep(i,n)cin >> a[i];
    rep(i,n)sum[i+1] = sum[i] + a[i];
    rep(i,n+1)rep(j,n+1)dp[i][j] = -1;
    cout << dfs(0,n-1) << endl;
}

Measured memory_bytes: 1536
def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n)]
    cd=[list(map(int,input().split())) for _ in range(m)]
    ans =[]
    for AB in ab:
        m = 10**9
        mza = None
        for i,CD in enumerate(cd):
            d = dist(AB,CD)
            if m > d:
                mza = i+1
                m = d
        ans.append(mza)
    for a in ans:
        print(a)
    
def dist(ab, cd):
    return abs(ab[0]-cd[0])+abs(ab[1]-cd[1])
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 9088
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    h,w = LI()
    if min(h,w) == 1:
        print(1)
        return 
    k = w>>1
    ans = (h>>1)*k+(h-(h>>1))*(k+(w&1))
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

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

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

map<ll, ll> memo;
ll a, b, c, d;
ll f(ll n) {
  if (n == 0) return 0;  
  if (n == 1) return d;

  if(memo.count(n)) return memo[n];
  ll ret = INF;
  if (n < ret/d) ret = n*d;
  if (n % 2 == 0) {
    chmin(ret, a + f(n / 2));
  } else {
    chmin(ret, a + d + f((n + 1)/2));
    chmin(ret, a + d + f((n - 1)/2));
  }
  if (n % 3 == 0)
    chmin(ret, b + f(n / 3));
  else {
    ll r = n % 3;
    chmin(ret, b + d * (3 - r) + f((n + 3 - r) / 3));
    if (n - r >= 0) chmin(ret, b + d * r + f((n - r) / 3));
  }
  if (n % 5 == 0)
    chmin(ret, c + f(n / 5));
  else {
    ll r = n % 5;
    chmin(ret, c + d * (5 - r) + f((n + 5 - r) / 5));
    if (n - r >= 0) chmin(ret, c + d * r + f((n - r) / 5));
  }
  return memo[n] = ret;
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll t;
  cin >> t;

  rep(i, t) {
    ll n;    
    cin >> n >> a >> b >> c >> d;
    memo.clear();
    ll ans = f(n);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4436
#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>>;



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

    int N, M;
    cin >> N >> M;
    int sum[N+1];
    int A[N];
    sum[0] = 0;
    map<int, int> mp;
    mp[0]++;
    rep(i,N){
        cin >> A[i];
        sum[i+1] = (sum[i] + A[i]) % M;
        mp[sum[i+1]]++;
    }
    int ans = 0;
    for(auto p : mp){
        int x = p.second;
        ans += x * (x-1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N  = 100010, M = 200010;

long long a[M];
long long l[M], r[M];

int main(){
	int n;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);

		if (a[i] + i <= n){
			l[i + a[i]] ++;
		}
		if (i - a[i] >= 1){
			r[i - a[i]] ++;
		}

	}

	long long res = 0;

	for (int i = 1; i <= n; i++){
		res += l[i] * r[i];
	}

	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 8448
n = gets.to_i
a = Array.new(n){gets.split.map(&:to_i)}
a.sort_by!{|a| a[1]}
ans = 0
n.times do |i|
  ans += a[i][0]
  if ans > a[i][1]
    puts "No"
    exit
  end
end
puts "Yes"

Measured memory_bytes: 22520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
const int INF = 1e9;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}

using Cost = int;
struct Edge{
    Cost cost;
    int y,x,foot;
    bool operator>(const Edge &right)const{
        return cost > right.cost;
    }
};

int X,Y;
char s[60][30];
Cost dp[60][30][2];

int main(void){
    while(cin>>X>>Y, X|Y){
        Fill(dp, (Cost)INF);
        vector<int> T,S;
        rep(y,Y)rep(x,X){
            cin>>s[y][x];
            if(s[y][x] == 'T'){
                T.push_back(x);
                s[y][x] = '0';
            }
            if(s[y][x] == 'S') {
                S.push_back(x);
                s[y][x] = '0';
            }
        }
        priority_queue<Edge,vector<Edge>,greater<Edge>> qu;
        for(int x : S)rep(foot,2){
            dp[Y-1][x][foot] = 0;
            qu.push({0,Y-1,x,foot});
        }

        while(qu.size()){
            Edge cur = qu.top(); qu.pop();
            int y = cur.y;
            int x = cur.x;
            int foot = cur.foot;
            if(dp[y][x][foot] < cur.cost) continue;
            for(int dx=-3; dx<=3; dx++){
                if(foot==0 && dx<=0) continue;
                if(foot==1 && dx>=0) continue;
                for(int dy=-2; dy<=2; dy++){
                    if(abs(dx)+abs(dy)>3) continue;
                    int ny = y + dy;
                    int nx = x + dx;
                    if(ny<0 || nx<0 || ny>=Y || nx>=X) continue;
                    if(s[ny][nx] == 'X') continue;
                    int c = s[y][x]-'0';
                    if( dp[ny][nx][!foot] > cur.cost + c){
                        dp[ny][nx][!foot] = cur.cost + c;
                        qu.push({dp[ny][nx][!foot], ny,nx,!foot});
                    }
                }
            }
        }

        int res = INF;        
        for(int x : T)rep(foot,2){
            res = min(res,dp[0][x][foot]);
        }
        cout<<(res == INF ? -1 : res)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3128
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let n: usize = get();
    let a: Vec<i64> = (0 .. 1 << n).map(|_| get()).collect();
    let mut tap = a;
    let mut ris = vec![0; 1 << n];
    for i in 0 .. n {
        for bits in 0 .. 1 << n {
            if (bits & 1 << i) != 0 {
                let prev = bits ^ 1 << i;
                ris[bits] = max(ris[bits], tap[bits] + tap[prev]);
                tap[bits] = max(tap[bits], tap[prev]);
            }
        }
    }
    let mut ma = 0;
    for i in 1 .. 1 << n {
        ma = max(ma, ris[i]);
        println!("{}", ma);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main() {
  int A, B, C, K;
    cin >> A >> B >> C >> K;
  if (K <= A) {
    cout << K << endl;
  }
  else if (K > A && K <= A + B) {
    cout << A << endl;
  }
  else if (K > A + B) {
    cout << 2*A-K+B << endl;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N; cin >> N;
    vector<vector<int>> c(10, vector<int>(10));
    REPS(i, N)
    {
        string s = to_string(i);
        c[s[0]-'0'][s[s.length()-1]-'0']++;
    }
    ll ans = 0;
    REPS(i, 9)
    {
        REPS(j, 9) ans += c[i][j] * c[j][i];
    }
    cout << ans << endl;
}

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

#define int long long
#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef pair < ll , ll > pp;
const int mod = 1e9 + 7;
const int N   = 52;

pair < double , pp > P[N];
int dp[N*N*N],val[N],W[N],par[N],n,d,budget,K,i,j,k,l;
deque < pp > Q;

int kesv,kesw,ans,cur,valmax,t;

bool cmp(pp a, pp b){
    return a.st * b.nd > b.st * a.nd;
}

signed main(){

    cin >> n >> budget >> d >> W[1];
    for(i=2;i<=n;i++) cin >> W[i] >> par[i];
    for(i=n; i ;i--) { W[ par[i] ] += W[i]; val[ par[i] ] += ++val[i]; }

    if(val[1] != n) assert(0);

    K = min(d , n);
    valmax = n * n * n + 1;


    memset(dp , 11 , sizeof dp);
    dp[0] = 0;
    for(i=1;i<=n;i++){
        for(j=0;j<val[i];j++){
            Q.clear();
            for(l=0,k=j;k<valmax;k+=val[i],l--){
                t = dp[k];
                if(Q.size() && Q.front().nd - l == K+1) Q.pop_front();
                if(Q.size()) dp[k] = min(dp[k] , Q.front().st - l * W[i]);

                for(; Q.size() && Q.back().st > t+l*W[i] ;) Q.pop_back();
                Q.pb(mp(t+l*W[i] , l));
            }
        }
    }

    for(i=1;i<=n;i++) P[i] = mp(1.0*val[i]/W[i],mp(val[i] , W[i]));
    sort(P+1 , P+n+1);
    reverse(P+1 , P+n+1);
    for(i=valmax-1; i>=0 ;i--){
        if(dp[i] > budget) continue;
        kesv = kesw = 0;
        for(cur=1; P[cur].nd.st != n && (budget - dp[i] - kesw) >= P[cur].nd.nd * (d - K); cur++){
            if(cur > n) assert(0);
            kesw += P[cur].nd.nd * (d - K);
            kesv += P[cur].nd.st * (d - K);
        }

        ans = max(ans , i + kesv + (budget - dp[i] - kesw) / P[cur].nd.nd * P[cur].nd.st);
    }

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

Measured memory_bytes: 1408
/* Life is all about calculated risks.
    But man am I bad at math. */

#include <bits/stdc++.h> 
#define ll long long int
#define INF (ll)1e12
#define MOD 1000000007

#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;

using namespace std;

ll lp(ll node);

ll n,m;
vector<vector<ll>> adjList(100100);

vector<ll> dp(100100,-1);

ll a,b;

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

    cin>>n>>m;
    for(ll i=0; i<m; i++)
    {
        cin>>a>>b;
        adjList[a].push_back(b);
    }

    ll max_path = 0;

    for(ll i=1; i<=n; i++)
    {
        max_path = max(max_path, lp(i));
    }
    cout<<max_path<<endl;

    return 0;
}

ll lp(ll node)
{
    if(dp[node] != -1)
    {
        return dp[node];
    }
    
    ll l = adjList[node].size();
    
    ll longpath = 0;
    for(auto it: adjList[node])
    {   
        longpath = max(longpath, 1+lp(it));
    }
    return dp[node] = longpath;
}

Measured memory_bytes: 8576
# dfs
import sys
sys.setrecursionlimit(10**6)

C = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
L = len(S)

def dfs(l):
    if l == L:
        return True
    elif l > L:
        return False

    for c in C:
        if S.find(c, l, l+7) == l:
            if dfs(l+len(c)):
                return True
    return False

print('YES' if dfs(0) else 'NO')


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextInt();
        long[] a = new long[n];
        long[] b = new long[n];

        for (int i = 0; i < n; i++)
        {
            a[i] = sc.NextLong();
            b[i] = sc.NextLong();
        }

        long answer = 0;

        for (long i = n - 1; i >= 0; i--)
        {
            long now = a[i] + answer;
            answer += now % b[i] == 0 ? 0 : b[i] - now % b[i];
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

int main() {
  long long int n;
  cin>>n;
  long long int t=n/500, y=n%500,r;
  if(y>0)
  r=y/5;
  else
  r=0;
  cout<<+(t*1000)+(r*5);
}
  

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
#define int long long
signed main(void){
    int n,m,r; cin>>n>>m>>r;
    vector <int> R(r);
    for(int i=0;i<r;i++){
        cin>>R[i]; R[i]--;
    }
    vector <vector<int>> d(210 ,vector <int>(210));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=INF;
        }
        d[i][i]=0;
    }
    for(int i=0;i<m;i++){
        int a,b,c; cin>>a>>b>>c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            chmin(d[i][j],d[i][k]+d[k][j]);
        }
    }
}

    int ans = INF;
    sort(R.begin(),R.end());
    do {
        int tmp=0;
        for(int i=0;i<R.size()-1;i++){
            tmp+= d[R[i]][R[i+1]];
            //cout<<R[i]<<"to"<<R[i+1]<<endl;
        }
        
        chmin(ans,tmp);
    } while( next_permutation(R.begin(), R.end()) );
    cout<<ans<<endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
using l1 = long long;

int main(){
    int A, B, outlet=1,cnt=0;
    cin >> A >> B;

    while(outlet < B){
        --outlet;
        outlet += A;
        ++cnt;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  if (b == 0) return a;
  else return gcd(b, a%b);
}

int main()
{
  int N; cin >> N;
  ll lcm = 1;
  REP(i, N) {
    ll T; cin >> T;
    lcm = lcm/gcd(lcm, T)*T;
  }
  cout << lcm << endl;
  return 0;
}

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

vector<int> a;
vector< vector<ll> > dp(105, vector<ll>(100005, -1));

ll q(int i, int k) { //a_0...a_i 残りk個
    if (k == 0) return 1;
    else if (k < 0 || i < 0) return 0;
    else if (dp[i][k] != -1) return dp[i][k];

    dp[i][k] = (q(i-1, k) + q(i, k-1) - q(i-1, k-a[i]-1)) % 1000000007;
     if (dp[i][k] < 0) dp[i][k] += 1000000007;
    return dp[i][k];
}

int main() {
    int N, K;
    cin >> N >> K;
    a.resize(N);
    rep(i,N) cin >> a[i];
    cout << q(N-1, K) << endl;
    return 0; 
}


Measured memory_bytes: 90480
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 200000+5;
ll T,n,m;
vector<ll> a;
vector<ll> b;
int main() {
	cin>>n;
	for(int i=0;i<n+1;i++){
		ll t ;
		cin>>t;
		a.push_back(t);
	}
	for(int i=0;i<n;i++){
		ll t;
		cin>>t;
		b.push_back(t);
	}
	ll cnt = 0;
	if(b[n-1]>a[n]){
		cnt+=a[n];
		b[n-1]-=a[n];
	}
	else {
		cnt+=b[n-1];
		b[n-1] = 0;
	}
	for(int i=n-1;i>0;i--){
		if(b[i]>a[i]){
			b[i]-=a[i];
			cnt+=a[i];
		}
		else {
			if(b[i-1]>(a[i]-b[i])){
				b[i-1]-=(a[i]-b[i]);
				cnt+=a[i];
			}
			else {
				cnt+=b[i]+b[i-1];
				b[i-1] = 0;
			}
		}
	}
	cnt+=min(b[0],a[0]);
	cout<<cnt<<endl;
}



Measured memory_bytes: 2548
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

#define netoze(a) (a<=0?0:a)


int main(void){
	string s;
	cin >> s >> s;
	int x = 0, m = 0;
	rep(i,s.size()){
		if(s[i] == 'I'){
			x++;
			m = max(x, m);
		}
		else x--;
	}

	cout << m << endl;
	
	return 0;
}

Measured memory_bytes: 256
L = gets.to_i
A = L.times.map { gets.to_i }

dp = Array.new(L + 1) { Array.new(5, Float::INFINITY) }
dp[0][0] = 0

A.each_with_index do |a, i|
  5.times do |j|
    next if dp[i][j] == Float::INFINITY

    case j
    when 0
      nc0 = dp[i][j] + a
      dp[i + 1][0] = nc0 if dp[i + 1][0] > nc0

      nc1 = dp[i][j] + ((a == 0) ? 2 : a % 2)
      dp[i + 1][1] = nc1 if dp[i + 1][1] > nc1

      nc2 = dp[i][j] + (a + 1) % 2
      dp[i + 1][2] = nc2 if dp[i + 1][2] > nc2
    when 1
      nc1 = dp[i][j] + ((a == 0) ? 2 : a % 2)
      dp[i + 1][1] = nc1 if dp[i + 1][1] > nc1

      nc2 = dp[i][j] + (a + 1) % 2
      dp[i + 1][2] = nc2 if dp[i + 1][2] > nc2

      nc4 = dp[i][j] + a
      dp[i + 1][4] = nc4 if dp[i + 1][4] > nc4
    when 2
      nc2 = dp[i][j] + (a + 1) % 2
      dp[i + 1][2] = nc2 if dp[i + 1][2] > nc2

      nc3 = dp[i][j] + ((a == 0) ? 2 : a % 2)
      dp[i + 1][3] = nc3 if dp[i + 1][3] > nc3

      nc4 = dp[i][j] + a
      dp[i + 1][4] = nc4 if dp[i + 1][4] > nc4
    when 3
      nc3 = dp[i][j] + ((a == 0) ? 2 : a % 2)
      dp[i + 1][3] = nc3 if dp[i + 1][3] > nc3

      nc4 = dp[i][j] + a
      dp[i + 1][4] = nc4 if dp[i + 1][4] > nc4
    when 4
      nc4 = dp[i][j] + a
      dp[i + 1][4] = nc4 if dp[i + 1][4] > nc4
    end
  end
end

puts dp[L].min


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

N = int(input())
v = [[] for _ in range(N)]
for i in range(N - 1) :
    a = int(input())
    v[a-1].append(i + 1)

l = [0]
i = 0
while i < len(l) :
    cur = l[i]
    for nex in v[cur] :
        l.append(nex)
    i += 1

dp = [0] * N
while len(l) > 0 :
    cur = l.pop()
    ret = []
    for nex in v[cur] :
        ret.append(dp[nex])
    
    if len(ret) == 0 :
        continue
        
    ret.sort(reverse=True)
    dp[cur] = max([i + 1 + ret[i] for i in range(len(ret))])
    
print(dp[0])


Measured memory_bytes: 59184
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

constexpr ll MOD = 0x1fff'ffff'ffff'ffff;
constexpr ll base = 257;

ll mul(ll a, ll b) {
  __uint128_t ans = __uint128_t(a) * b;
  ans = (ans >> 61) + (ans & MOD);
  if (ans >= MOD) ans -= MOD;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin>>n;
  set<ll> hs;
  ll ans = 0;
  vector<string> vs;
  REP(i,n) {
    string s;
    cin>>s;
    vs.push_back(s);
    ll h = 0;
    ll len = size(s);
    REP(rj,len) {
      ll j = len-rj-1;
      h = mul(h, base);
      h += s[j];
      if (h >= MOD) h -= MOD;
    }
    hs.insert(h);
  }
  REP(i,n) {
    auto s = vs[i];
    ll h = 0;
    ll len = size(s);
    vecll cnt(26, 0);
    for(auto&&c:s) ++cnt[c-'a'];
    REP(rj,len) {
      ll j = len-rj-1;
      h = mul(h, base);
      REP(k,26) {
        if (cnt[k]) {
          ll hk = h + k + 'a';
          if (hk >= MOD) hk -= MOD;
          if (hs.count(h + k + 'a')) {
            ++ans;
          }
        }
      }
      h += s[j];
      if (h >= MOD) h -= MOD;
      --cnt[s[j] - 'a'];
    }
  }
  cout<<(ans-n)<<"\n";
  return 0;
}


Measured memory_bytes: 18736
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef vector<int> vi;
const int mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    cout << a[0]*a[1]/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=2e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
struct node{
	string s;
	int val;
};
int main()
{
	int n;
	scanf("%d",&n);
	queue<node>q;
	string s="a";
	q.push({s,1});
	for(int i=2;i<=n;i++)
	{
		while(!q.empty())
		{
			node v=q.front();
			if(v.s.size()>=i)break;
			q.pop();
			
			for(int i=0;i<v.val;i++)
			{
				string ss=v.s;
				ss+=('a'+i);
				q.push({ss,v.val});
			}
			string ss=v.s;
			ss+=('a'+v.val);
			q.push({ss,v.val+1});
		}
	}
	while(!q.empty())cout<<q.front().s<<endl,q.pop();
}

Measured memory_bytes: 8832
# -*- coding: utf-8 -*-

import sys
import copy
import math

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~


import heapq

N, M = map(int, input().split())
A = [-int(x) for x in input().split()]

heapq.heapify(A)

for _ in range(M):
    t = heapq.heappop(A)
    t *= -1
    t //= 2
    t *= -1
    heapq.heappush(A, t)

ans = 0
for x in A:
    ans += -x

print(ans)

Measured memory_bytes: 14820
#include <iostream>
#include <cstdlib>
#include <map>
#include <string>

using namespace std;

int main()
{
    map<string, int> m;
    int q, query, k;
    string w;
    cin >> q;
    for (int i=0; i<q; ++i){
        cin >> query;
        if(query == 0){
            cin >> w >> k;
            if(m.find(w) != m.end()){
                m.erase(w);
            }
            m.insert(make_pair(w, k));
        }
        else if(query == 1){
            cin >> w;
            cout << m.at(w) << endl;
        }
    }
}



Measured memory_bytes: 27776
#include <iostream>
#include <queue>
#include <map>

using namespace std;

typedef pair<int, int> P;

int main() {
    int w, h;
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    char map[20][20];
    while (true) {
        int count = 1;
        queue<P> q;
        cin >> w >> h;
        if (w == 0) {
            return 0;
        }
        for (int y=0; y<h; y++) {
            for (int x=0; x<w; x++) {
                cin >> map[x][y];
                if (map[x][y] == '@') {
                    q.push(P(x, y));
                }
            }
        }
        while (!q.empty()) {
            int x = q.front().first;
            int y = q.front().second;
            q.pop();
            for (int i=0; i<4; i++) {
                int nx = x+dx[i];
                int ny = y+dy[i];
                if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                    continue;
                }
                if (map[nx][ny] != '.') {
                    continue;
                }
                map[nx][ny] = '#';
                q.push(P(nx, ny));
                count++;
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
using namespace std;
int main(){
    ios::sync_with_stdio(false), cin.tie(0);
    vector<int>x;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        x.push_back(a);
    }
    bool ans = false;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            swap(x[i],x[j]);
            if(is_sorted(x.begin(),x.end())){
                ans=true;
            }
            swap(x[j],x[i]);
        }
    }
    if(ans){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut input = String::new();

    stdin().read_line(&mut input)
        .expect("Failed to read line");
    let splitted_words: Vec<&str> = input.split_whitespace().collect();
    let hp: u32 = splitted_words[0].parse().unwrap();
    let damage: u32 = splitted_words[1].parse().unwrap();

    if (hp % damage) == 0 {
        println!("{}", hp / damage);
    } else {
        println!("{}", (hp / damage) + 1);
    }
}

Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int m[101][101]; //[w][h]

int main()
{
	while(1) {
		int n;
		cin >> n;
		if (!n) break;
		bool half = false;
		bool foot[2] = {false, false};
		int cnt = 0;
		rep(i,0,n) {
			string s;
			cin >> s;
			if (s == "lu") foot[0] = true;
			else if (s == "ru") foot[1] = true;
			else if (s == "ld") foot[0] = false;
			else if (s == "rd") foot[1] = false;
			if (half) {
				if (foot[0] == false && foot[1] == false) {
					cnt++;
					half = false;
				}
			}
			else {
				if (foot[0] == true && foot[1] == true) {
					cnt++;
					half = true;
				}
			}
		}
		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    int p[n];
    for(int i = 0; i < n; i++) cin >> p[i];
    int ans = 0;
    for(int i = 1; i < n - 1; i++) {
        if((p[i - 1] < p[i]) && (p[i] < p[i + 1])) ans++;
        else if((p[i - 1] > p[i]) && (p[i] > p[i + 1])) ans++;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
int main() {
	int N, K;
	scanf("%d%d", &N, &K);
	int Min = 1, x;
	for(int i=1;i<=N;i++) {
		scanf("%d", &x);
		if( x == 1 ) Min = i;
	}
	printf("%d\n", (N-1+(K-2)) / (K-1) );
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<=num; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    seq_inv[0] = 1;
    seq_inv[1] = 1;
    for(int i=2; i<=num; i++){
        seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fact_inv[0] = 1;
    fact_inv[1] = 1;
    for(int i=2; i<=num; i++){
        fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
    }
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

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

    create_mod_tables(B+W);

    int64_t b = 1, bw = 1, base = 1;
    for(int i=1; i<=B+W; i++){
        int64_t ans = (b - bw * inv_mod(2)) % MOD;
        ans = (ans + MOD) % MOD;
        mul(ans, base);
        cout << ans << endl;
        
        mul(base, inv_mod(2));
        mul(b, 2);
        mul(bw, 2);
        if(i >= B){
            add(b, MOD - comb_mod(i-1, B-1));
            add(bw, MOD - comb_mod(i-1, B-1));
        }
        if(i >= W){
            add(bw, MOD - comb_mod(i-1, i-W));
        }
    }
    return 0;
}


Measured memory_bytes: 6912
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int r = sc.nextInt();
		int g = sc.nextInt();
		
		// 計算
		int result = 0;
		result = g*2 - r;
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 21716
n,m,c=[int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
ans = 0
for _ in range(n):
  A = [int(i) for i in input().split(' ')]
  sum = c
  for i in range(m):
    sum += A[i] * B[i]
  ans += 1 if sum > 0 else 0
print(ans)
  


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
   int n,k,x;
   cin >> n >>k;
  
   x=k;
  
   for(int i=1;;i++){
     if(x>n){
       cout << i <<endl;
       break;
     }
     x=x*k;
   }
     
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
using namespace std;

int main() {
    int num=0,N,i,j,k;
    scanf("%d",&N );
    for(i=0;i<N;i++){
        scanf("%d",&k);
        scanf("%d",&j);
        num += j-k+1;
        
    }
    printf("%d\n",num);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
#include <cstdlib>
// #include <fstream>
 
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; }
 
const long long mod = 1e9 + 7;
 
int main()
{
    long long int n; std::cin >> n;
    long long int ans = 0;
    for(int i=1; i<=n; i++)
    {
        if(i%3==0);
        else if(i%5==0);
        else if(i%15==0);
        else
        {
            ans += i;
        }
            
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3584