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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


int dp[100005]; //0は未判定　1は負け　2は勝ち
int N, K;
int a[101];

int AB(int k) {
    if (k == 0) return 1;
    if (dp[k] != 0) return dp[k];

    int res = 1;
    rep(i, N) {
        if (k >= a[i] && AB(k - a[i]) == 1) {
            res = 2;
            break;
        }
    }

    return dp[k] = res;
}

int main() {
    cin >> N >> K;
    rep(i, N) {
        cin >> a[i];
    }

    cout << (AB(K) == 2 ? "First" : "Second" ) << endl;
}

Measured memory_bytes: 3712
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	N := getNextInt64(scanner)
	K := getNextInt64(scanner)

	A := []int64{}
	for i := int64(0); i < N; i++ {
		A = append(A, getNextInt64(scanner))		
	}

	for k := int64(0); k < K; k++ {
		B := make([]int64, N+1)
		for i := int64(0); i < N; i++ {
			l := max(0, i - A[i])
			r := min(i + A[i] +1, N)
			B[l]++
			B[r]--
		}
		for i := int64(0); i < N; i++ {
			B[i+1] += B[i]
		}
		B = B[:N]

		isSame := true
		for i, e := range A {
			if e != B[i] {
				isSame = false
				break
			}
		}

		if isSame {
			break
		}
		A = B
	}

	for i := int64(0); i < N-1; i++ {
		fmt.Fprintf(writer, "%d ",A[i])
	}
	fmt.Fprintln(writer, A[N-1])
}

func max(x, y int64) int64 {
	if x >= y {
		return x
	}
	return y
}

func min(x, y int64) int64 {
	if x <= y {
		return x
	}
	return y
}


Measured memory_bytes: 17748
#include<iostream>

using namespace std;

int main(){
    int n,y;
    cin>>n>>y;
    
    int res10000,res5000,res1000;
    res10000=-1;
    res5000=-1;
    res1000=-1;
    for(int i=0;i<=n;++i){
        for(int j=0;j<=n-i;++j){
                int k=n-i-j;
                int t=10000*i+5000*j+1000*k;
                if(t==y){
                    res10000=i;
                    res5000=j;
                    res1000=k;
                    break;
                }
        }
    }

    cout<<res10000<<" "<<res5000<<" "<<res1000<<endl;
}

Measured memory_bytes: 256
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

ll read() {
	ll X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int mod=1e9+7;

map<ll,int> f;

int calc(ll n) {
	if (f.count(n)) return f[n];
	return f[n]=((calc(n/2)+calc((n-1)/2))%mod+calc((n-2)/2))%mod;
}

int main() {
	f[0]=1,f[1]=2;
	printf("%d\n",calc(read()));
	return 0;
}


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

#define INF int(1e9)
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

int calc(int x){
	int res=0;
	while(x)res+=x%10,x/=10;
	return res;
} 

int main(){
	int n;
	scanf("%d",&n);
	int ans=INF;
	REP(i,n-1)ans=min(ans,calc(i)+calc(n-i));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  int m=0;
  rep(i,n){
    if(s[i]=='L'&&i){
      if(s[i-1]=='L') m++;
    }
    if(s[i]=='R'&&i!=n-1){
      if(s[i+1]=='R') m++;
    }
    //cout<<m<<endl;
  }

  cout<<min(n-1,m+k*2)<<endl;
  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
const constexpr int MAX = 100;
constexpr ll INF = 1LL<<32;
int n;
vv(ll, d, MAX, MAX, INF);
inline void floyd() {
	rep(k, 0, n) {
		rep(i, 0, n) {
			if(d[i][k] == INF) continue;
			rep(j, 0, n) {
				if(d[k][j] == INF) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}
int main() {
	int e; cin >> n >> e;
	rep(i, 0, n) d[i][i] = 0L;
	int u, v, c;
	rep(i, 0, e) {
		cin >> u >> v >> c;
		d[u][v] = c;
	}
	floyd();
	bool negative = false;
	rep(i, 0, n) if(d[i][i] < 0) { negative = true; break; }
	if(negative) P("NEGATIVE CYCLE");
	else {
		rep(i, 0, n) {
			rep(j, 0, n) {
				if(d[i][j] == INF) p("INF");
				else p(d[i][j]);
				p(j + 1 == n ? "\n" : " ");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3304
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bisection(l,r,f,left=True,discrete=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if not discrete else l if left else r

def resolve():
    n,k=map(int,input().split())
    A=sorted(map(int,input().split()))
    F=sorted(map(int,input().split()),reverse=1)
    def check(x):
        res=0
        for a,f in zip(A,F):
            if(a*f)<=x: continue
            res+=a-int(x/f)
        return res<=k
    print(bisection(0,10**12,check,left=False))
resolve()

Measured memory_bytes: 114176
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;

int n, a[maxn], f[maxn], t[maxn];

int main()
{
    cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=n;i++)
      f[i] = __gcd(f[i-1], a[i]);
    for(int i=n;i>=1;i--)
      t[i] = __gcd(t[i+1], a[i]);

    int ans = 0;
    for(int i=1;i<=n;i++) ans = max(ans, __gcd(f[i-1], t[i+1]));
    cout << ans;
  	return 0;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    ll x; cin >> x;

    for(ll a=-500;a<=500;a++){
        for(ll b=-500;b<=500;b++){
            if(a*a*a*a*a - b*b*b*b*b == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3552
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static T[] Recursion<T>(int n, T v, Func<int, T, T> f) { var a = new T[n]; a[0] = v; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], X = I[1];
		var S = G;
		Array.Sort(S, (p, q) => q.CompareTo(p));
		var dp = new long[2][];
		dp[0] = MakeArray(X + 1, i => i == X ? 1 : 0L);
		for (var i = 0; i < N; i++)
		{
			var inv = Inverse(N - i);
			var i2 = i % 2;
			var j2 = (i + 1) % 2;
			dp[j2] = ConstantArray(X + 1, 0L);
			for (var x = 0; x <= X; x++)
			{
				var y = x % S[i];
				dp[j2][y] = (dp[j2][y] + dp[i2][x] * inv % MOD) % MOD;
				dp[j2][x] = (dp[j2][x] + dp[i2][x] * (1 - inv + MOD) % MOD) % MOD;
			}
		}
		var s = 0L;
		for (var x = 0; x <= X; x++) s = (s + x * dp[N % 2][x] % MOD) % MOD;
		for (var i = 1; i <= N; i++) s = s * i % MOD;
		WriteLine(s);
	}
	public static long Inverse(long a, long mod = MOD)
	{
		if (a < 0) { a %= mod; if (a < 0) a += mod; }
		var t = SolveLinear(a, mod);
		return t.Item1 > 0 ? t.Item1 : t.Item1 + mod;
	}
	public static Tuple<long, long> SolveLinear(long n, long m)
	{
		if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); }
		if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); }
		if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); }
		long a = 1, b = 0, c = 0, d = 1;
		while (m > 0)
		{
			var r = n % m;
			var q = n / m;
			n = m;
			m = r;
			var tmp = a;
			a = -a * q + b;
			b = tmp;
			tmp = c;
			c = -c * q + d;
			d = tmp;
		}
		return n != 1 ? null : new Tuple<long, long>(d, b);
	}
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define MIN(c) (*min_element(ALL(c))) 
#define MAX(c) (*max_element(ALL(c)))
#define ACC(c) (accumulate(ALL(c), 0))
#define SLL(x, n) ((x) << (n))
#define SRL(x, n) ((x) >> (n))
#define MIN2(a, b) ((a) < (b)) ? (a) : (b)
#define MAX2(a, b) ((a) > (b)) ? (a) : (b)
#define MP(a, b) (make_pair((a), (b)))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

template<typename T> inline void fill(T array[], T value) {for(T t: array) t = value;}
inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}

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

signed main(){
    int A, B;
    cin >> A >> B;
    if(A >= 13) PRINT(B);
    else if(A >= 6) PRINT(B / 2);
    else PRINT("0");
    return 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using static System.Math;
using static System.Console;

class E { static void Main() => new J(); }
class J
{
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	int MOD = 1000000007;
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		Console.WriteLine(string.Join("", Console.ReadLine().Split().Select(x => char.ToUpper(x[0]))));
	}
}

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

using namespace std;

#define ll long long

int main(){
	map<ll, ll> m;
	ll n, t, ans=0, num, freq;
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>t;
		if(m.count(t)){
			m[t]++;
		}
		else{
			m[t]=1;
		}
	}

	for(auto it=m.begin(); it!=m.end(); it++){
		num= it->first;
		freq= it->second;

		if(num>freq){
			ans += freq;
		}
		if(num < freq){
			ans += (freq-num);
		}
	}
	cout<<ans;
}

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

int main()
{
    std::string str,str2,str3;
    std::cin >> str;
    str2="ABC";
    str3="ARC";

    if(str==str2 ){
     std::cout << str3 << std::endl;
    }
    else{
        std::cout << str2 << std::endl;
    }
}

Measured memory_bytes: 3564
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a) for (auto &i : a)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD   = (int)(1e9 + 7);
const int INF   = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class BDistance {
public:
  static void solve(istream &cin, ostream &cout) {
    int N, D;
    cin>>N>>D;
    int ans = 0;
    rep(i, N){
      int X, Y;
      cin>>X>>Y;
      if (X*X + Y*Y <= D*D)
      ans++;
    }
    cout<<ans<<endl;

  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  BDistance solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
#define SZ(a) ((int) a.size())
using namespace std;
typedef long long ll;
const int N=55,M=22;
const ll inf=1e18;

int n,v[N][M][2],c[N];
ll f[N][M][2],ans=inf;
string s[N];

ll dp(int x,int y,int d) {//x为串编号,y为位置,d为方向(正反)
    if(y==SZ(s[x])) return 0;
    int &u=v[x][y][d]; 
    ll &v=f[x][y][d];
    if(u) return v;
    u=1; v=inf;
	bool flag=1;
	if(!d) {for(int j=y,k=SZ(s[x])-1;j<k;j++,k--) if(s[x][j]!=s[x][k]) {flag=0; break;}}
	else {for(int j=y,k=0;j>k;j--,k++) if(s[x][j]!=s[x][k]) {flag=0; break;}}
	if(flag) return v=0;
    for(int i=1,j,k;i<=n;i++) {//枚举另一个方向接哪个串
        flag=1;
        if(!d) {
            for(j=y,k=SZ(s[i])-1;j<SZ(s[x])&&k>=0;j++,k--)
                if(s[x][j]!=s[i][k]) {flag=0; break;}
            if(flag) {
                if(k<0) v=min(v,c[i]+dp(x,j,0));
                else v=min(v,c[i]+dp(i,k,1));
            }
        }
        else {
            for(j=y,k=0;j>=0&&k<SZ(s[i]);j--,k++)
                if(s[x][j]!=s[i][k]) {flag=0; break;}
            if(flag) {
                if(j<0) v=min(v,c[i]+dp(i,k,0));
                else v=min(v,c[i]+dp(x,j,1));
            }
        }
    }
    return v;
}

int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) cin>>s[i]>>c[i];
    for(int i=1;i<=n;i++) 
		ans=min(ans,c[i]+dp(i,0,0));
    printf("%lld\n",ans==inf?-1:ans);return 0;
}



Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc138/abc138_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  string S;
  cin >> N >> S;

  cout << ((N >= 3200) ? S : "red") << endl;
}

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

int dir[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};

int main()
{
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if(a % b == 0) cout << a / b << endl;
	else cout << a / b + 1 << endl;
	return 0;
}

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

int main(int argc, char* argv[]) {
	int m, f, r;
	int score;

	while(1){
		cin >> m >> f >> r;
		if(m == -1 && f == -1 && r == -1) break;

		if(m == -1 || f == -1){
			printf("F\n");
			continue;
		}

		score = m + f;
		if(score < 30){
			printf("F\n");
		}else if(score < 50){
			if(r >= 50) printf("C\n");
			else printf("D\n");
		}else if(score < 65){
			printf("C\n");
		}else if(score < 80){
			printf("B\n");
		}else{
			printf("A\n");
		}
	}

	return 0;

}

Measured memory_bytes: 1116
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int H, W, K;
    cin >> H >> W >> K;

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;

    vector<vector<char>> m(H, vector<char>(W));
    REP(i, H) REP(j, W) cin >> m[i][j];

    vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};

    queue<pair<ll, Pin>> q;
    q.push({0, {x1, y1}});

    vector<vll> dist(H, vll(W, INF));

    while(!q.empty()) {
        auto p = q.front(); q.pop();

        ll cost = p.fi;
        int x = p.se.fi, y = p.se.se;

        REP(i, 4) {
            FOR(k, 1, K + 1) {
                int nx = x + dx[i] * k, ny = y + dy[i] * k;
                if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
                if (m[nx][ny] == '@') break;

                if (cost + 1 < dist[nx][ny]) {
                    q.push({cost + 1, {nx, ny}});
                    dist[nx][ny] = cost + 1;
                } if (dist[nx][ny] == cost + 1) continue;
                else break;
            }
        }
    }

    print(dist[x2][y2] == INF ? -1 : dist[x2][y2]);


}


Measured memory_bytes: 19900
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b;
    cin >> a  >> b;
    cout << (b % a ? b-a:b+a) << endl;
}



Measured memory_bytes: 256
// AOJ 1179

#include <iostream>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	while (n--){
		int y, m, d;
		cin >> y >> m >> d;

		int cnt = 0;
		int x;
		while (1){
			if (y == 1000 && m == 1 && d == 1){
				break;
			}
			d++;
			// 3 で割り切れない年 && 小の月
			if (d == 20 && ((y % 3) != 0) && (m % 2) == 0){
				m++;
				d = 1;
			}
			// 3で割り切れる年 || 大の月
			else if (d == 21 && ((y % 3 == 0) || (m % 2 != 0))){
				m++;
				d = 1;
			}
			if (m == 11){
				m = 1;
				y++;
			}
			// cout << y << " " << m << " " << d << endl;
			// cin >> x;
			cnt++;
		}

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
N = int(input())
temp = [int(i) for i in input().split(' ')]
T = temp[0]
A = temp[1]
H = [int(i) for i in input().split(' ')]

min_temp = float('inf')
for i,h in enumerate(H):
  t = T - h*0.006
  diff = abs(t-A)
  if diff<min_temp:
    min_temp = diff
    min_index = i+1

print(min_index)
  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
 
#define check(a)         cout<<#a<<" : "<<a<<endl;
#define check2(a, b)     cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<endl;
#define check3(a, b, c)  cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<" | "<<#c<<" : "<<c<<endl;


int parent[200001];
int Size[200001];

void make_set(int a){ //disjoint set union
    parent[a]=a;
    Size[a]=1;
}

int find_set(int a){
    if(parent[a]==a)return a;
    else return parent[a]=find_set(parent[a]);
}

void make_union(int a,int b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(Size[a]<Size[b])
            swap(a,b);
        parent[b]=a;
        Size[a]+=Size[b];
    }
}
void testCase(){
    int n, m; cin >> n >> m;
    for(int i = 1; i <= n; i++){
        make_set(i);
    }

    for(int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        make_union(a, b);
    }

    int ans = -1;
    for(int i = 1; i <= n; i++){
        ans += (parent[i] == i);
    }

    cout << ans << '\n';

}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int t = 1;
    // int t; cin >> t;
    while(t--)
        testCase();
    
    return 0;
}

Measured memory_bytes: 5188
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  long long ans;
  cin >> ans;
  
  for (int i = 1; i < n; i++) {
    long long a;
    cin >> a;
    
    ans = __gcd(ans, a);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
p=list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    if (p[i] > p[i+1] and p[i+1] > p[i+2]) or (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i] == p[i+2] and p[i+1] > p[i]):
        cnt += 1
print(cnt)

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007

int main(void)
{

    int x, y, z;
    cin >> x >> y >> z;

    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#define INF 1000000000
#define LM 55555
#define LL long long
using namespace::std;


long long Q,ch[501][501],mc,pc,p[100001],m[100001],n, bc, now, C, H, W, X[100000],K, Y, ans, r, l, numcon, N, M;
string S,s,a[101],b[101],c[101];
bool h,k[101];

int main() {
	cin >> N;
	if (N == 0) {
		cout << '0' << endl;
		return 0;
	}
	now = 1;
	while (N!=0) {
			if (N % (now*2) == 0) {
				S += '0';
			}
			else {
				S += '1';
				N -= now;
			}
		now = now * (-2);
	}
	for (int i = S.size()-1; i >= 0; i--)
		cout << S[i];
	cout << endl;
	return 0;

}




Measured memory_bytes: 256
//  cd Desktop/Atcoder
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i,n) for(i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007


int main(){
    char n;
    scanf("%c",&n);
    if ('A'<=n&&n<='Z')
    {
        printf("A");
    }else printf("a");
    
    return 0;
}


Measured memory_bytes: 1580
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <utility>
#include <cmath>
#include <string>
#include <bitset>
#include <queue>
#include <cstdio>
#include <cstring>
#include <deque>
#include <unordered_map>
#include <climits>
#include <map>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <ctime>
#include <cstdint>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define fa(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>b;--i)
#define setp pair<pair<int,int>,int>
#define setl pair<LL,LL>
#define M_PI 3.14159265358979323846

using namespace std;

LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }
pair <int, int> vu[8] = { {0,1}, {1,0} , {1,-1},{0,-1},{-1,0},{-1,1},{0,1}, {1,0} }; // EWSN

const int max_v = 1e5 + 7;
const int INF = 1e7 + 7;

LL a;
string b;
LL bt;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);	
	ci(a >> b);
	bt += (b[0] - '0')*100;
	bt += (b[2] - '0') * 10;
	bt += (b[3] - '0');
	a *= bt;
	a /= 100;
	co(a);
	return 0;
}

Measured memory_bytes: 3652
require 'set'
lines = readlines.map{|line| line.split(' ')}
d=[]
for i in 0..lines[0][0].to_i-1
  d.push(0)
end
e=0
c=Set.new
for j in 1..lines[0][1].to_i do
  t=!c.include?(lines[j][0].to_i)
  if lines[j][1]=="WA" && t then
    d[lines[j][0].to_i-1]=d[lines[j][0].to_i-1]+1
  elsif lines[j][1]=="AC" && t then
    c.add(lines[j][0].to_i)
    e=e+d[lines[j][0].to_i-1]
    d[lines[j][0].to_i-1]=0
  end
end
puts c.length.to_s+" "+e.to_s


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

using namespace std;

int H,W;

int main(){
  cin>>H>>W;
  char board[H][W];

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>board[i][j];
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(board[i][j]=='#'){
        if(board[i-1][j]!='#'&&board[i][j-1]!='#'&&board[i][j+1]!='#'&&board[i+1][j]!='#'){
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    char O[51];
    char E[51];

    if (scanf("%s%s", O, E) < 2) return 0;

    for (int i = 0; i < strlen(O); i++)
    {
        printf("%c", O[i]);
        if (i < strlen(E))
        {
            printf("%c", E[i]);
        }
    }

    printf("\n");
    return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    lint a, n, m;
    cin >> a >> n >> m;

    lint ans = 0;
    for(lint y = 1 ; y <= 72 ; ++y){
        lint x = pow(y + a, n);
        lint d = 0;
        if(x > m){
            continue;
        }
        while(x > 0LL){
            d += x % 10LL;
            x /= 10LL;
        }
        if(d == y){
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3416
#include<stdio.h>
int solve(int, int, int);
int A[2001];
int n;

int main(){
  int j, q, i;
  int M[2001];
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&M[i]);
  }
  
  for(i=0; i<q; i++){
    if(solve(0, 0, M[i])) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



int solve(int p, int t, int k){
  if(t == k) return 1;
  if(p >= n) return 0;
  if(solve(p+1, t, k)) return 1;
  if(solve(p+1, t+A[p], k)) return 1;
  return 0;
}

Measured memory_bytes: 388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
	ll n;
	string s;
	cin>>n>>s;
	ll ans=0;
	for(int l=0;l<n;l++){
		vector<ll> z(n-l);
		z[0]=n-l;
		int i=1,j=0;
		string t=s.substr(l,n-l);
		while(i<n-l){
		    while(i+j<n-l&&t[j]==t[i+j])j++;
		    z[i]=j;
		    if(!j){
	        i++;
	        continue;
		    }
		    int k=1;
		    while(k<j&&k+z[k]<j){
	        z[i+k]=z[k];
	        k++;
		    }
		    i+=k;
		    j-=k;
		}
		for(ll m=1;m<n-l;m++)ans=max(ans,min(m,z[m]));
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3640
/* 
	今日も一日がんばるぞい
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<< '\n'

int main(){
    int n;
    cin >> n;
    int x[n],y[n];
    vector<int> v(n);
    int a,b;
    REP(i,n){
        cin >> a >> b;
        x[i] = a;y[i] = b;
        v[i] = i+1;
    }
    double ans = 0;
    int count = 0;
    do{
        double dis = 0;
        count++;
        for(int i=1;i<n;i++){
            int n1 = v[i]-1;
            int n2 = v[i-1]-1;
            dis += pow((x[n2]-x[n1])*(x[n2]-x[n1]) + (y[n2]-y[n1])*(y[n2]-y[n1]),(1.0/2.0));
        }
        ans += dis;
    }while(next_permutation(v.begin(),v.end()));
    ans /= count;
    cout << setprecision(20) << ans << endl;
    return 0;
}


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

  int n, k;
  cin >> n >> k;

  int res = 0;
  rep (i, 0, n) {
    int h;
    cin >> h;

    if (h >= k)
      res++;
  }

  cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import itertools
n, y = map(int, input().split())
k = [i for i in range(n + 1)]
ans = 0
for a, b in itertools.product(k, k):
  if n >= a + b and a * 10000 + b * 5000 + (n - a - b) * 1000 == y:
    print(a, b, n - a - b)
    ans = 1
    break
if ans == 0:
  print('-1 -1 -1')

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;


int main() {
    int n;
    cin >> n;
    ll ans = 0;
    vector<int> d(n+1);
    for(int i = 1;i<=n;i++){
        for(int j = i;j<=n;j += i) d[j]++;
    }
    for(int i=1;i<=n;i++) ans += ll(i)*d[i];
    cout << ans << endl;
}

Measured memory_bytes: 42296
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll arr[n][3],dp[n+1][3];
	dp[n][0]=dp[n][1]=dp[n][2]=0;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){
			cin>>arr[i][j];
			dp[i][j]=0;
		}
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){
			for(ll k=0;k<3;k++){
				if(j==k)continue;
				dp[i+1][k]=max(dp[i+1][k],dp[i][j]+arr[i][k]);
			}
		}
	}
	cout<<max(max(dp[n][0],dp[n][1]),max(dp[n][1],dp[n][2]));
	return 0;
}

Measured memory_bytes: 4992
//#include </Users/kmudda/Downloads/Karthik/stdc++.h>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <climits>
#define ll long long int
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define vvl vector< vl >
#define vvi vector< vi >
#define pb push_back
#define mp make_pair
#define max_int_value 2147483647
#define max_long_value 9223372036854775807
#define min_long_value -9223372036854775806
#define ii pair<ll,ll>
#define F first
#define S second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)
 
#define CLR(v, d)     memset(v, d, sizeof(v))
 
template<typename T> T gcd(T a, T b){return (b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return (a*(b/gcd_gg(a,b)));}
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
template<typename T> T mod_neg(T a, T b) {return ((a%b)+b)%b;}
ll mulmod(ll a,ll b, ll m){ll q=(ll)(((ld)a*(ld)b)/(ld)m);ll r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template<typename T> T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T> T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template<typename T> T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T> T mod_inverse(T a, T n){T x,y;T d = extended_euclid(a, n, x, y);return (d>1?-1:mod_neg(x,n));}
 
using namespace std;
 
string IntToString (int a)
{
    ostringstream temp;
    temp<<a;
    return temp.str();
}
 
int StringToInt (string str)
{
    int xx;
    stringstream ss;
    ss << str;
    ss >> xx;
    return xx;
}
 
ll powerwithmodulus(ll base, ll exponent,ll modulus){
    ll result = 1; base%=modulus;
    while (exponent > 0)
    {
        if (exponent % 2 == 1) result = (result * base) % modulus;
        exponent = exponent >> 1;
        base = (base * base) % modulus;
    }
    return result;
}

/*  NCR using DP
for(int n = 0; n <= 1000; n++)
        for(int r = 0; r <= n; r++)
            if(r == 0 || n == r) ncr[n][r] = 1;
            else ncr[n][r] = (ncr[n-1][r-1] + ncr[n-1][r]) % mod;

*/

 
ll largestPowerOf2(ll n)
{
    return (ll)pow(2, floor(log(n) / log(2)));
}

inline bool cmp1(pair<ll,ll> &p1, pair<ll,ll> &p2) {
    if(p1.F == p2.F)
        return p1.S < p2.S;
    else
        return p1.F < p2.F;
}
 
//lower case std::transform(str.begin(), str.end(), str.begin(), ::tolower);
//Ascii A-65 Z-90 a-97 z-122 0-48 9-57

int cal(int pow, int val, int MOD){
   if(pow <= 0)
      return 1;
   int v = cal(pow/2, val, MOD);
   if(pow % 2 == 0)
      return (v*v) % MOD; 
   else
      return (((v*val) % MOD) * v) % MOD;
}


ll t,n,m,sum=0,coun=0,m1,m2,m3,i,j,k,sum1,sum2,p,q,r,s,p1,q1;
bool flag2;

int main() {

  fast_io;
  //freopen("inputf.in", "r", stdin);
  //freopen("outputf.in", "w", stdout);
  cin>>p>>q>>r;

  for(i=0;i<10;i++) {
    s = (p*r) - q;
    cout<<s<<endl;
    r = s;
  }
  
  

}



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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, m;
vector<vector<int>> g(5050, vector<int>(5050, 0));

void imos3_add(int a, int b, int x, vector<vector<int>>& g) {
    g[a][b] += 1; g[a][b + 1] -= 1;
    g[a + x + 1][b] -= 1; g[a + x + 2][b + 1] += 1;
    g[a + x + 1][b + x + 2] += 1; g[a + x + 2][b + x + 2] -= 1;
    return ;
}

void imos3_update(vector<vector<int>>& g) {
    for (int i = 0; i < 5010; i++) for (int j = 0; j < 5010; j++) g[i][j + 1] += g[i][j];
    for (int i = 0; i < 5010; i++) for (int j = 0; j < 5010; j++) g[i + 1][j] += g[i][j];
    for (int i = 0; i < 5010; i++) for (int j = 0; j < 5010; j++) g[i + 1][j + 1] += g[i][j];
    return ;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> m;
    rep(i, m) {
        int a, b, x;
        cin >> a >> b >> x;
        imos3_add(a, b, x, g);
    }
    imos3_update(g);
    int ans = 0;
    rep(i, 5010)rep(j, 5010) {
        if (g[i][j] > 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 202616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  if (N%10 == 2 || N%10 == 4  || N%10 == 5 || N%10 == 7 || N%10 == 9) {
    cout << "hon" << endl;
  }
 
  else if (N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8) {
    cout << "pon" << endl;
  }
 
  else  {
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3624
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  [n, k] <- readIntList
  arr    <- sortOn Down <$> readIntegerList
  let (done, rest) = splitAt k arr
  print $ if n > k then sum rest else 0



Measured memory_bytes: 46460
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 9 * (long long int)pow(10, 13);

int N, a, b;
long long int num[100];
list<int>box;
int s;
long long int  bag;
long long int  ans;
long long int  sum[100];
long long int  M;
vector<long long int> pas[100];

int main() {
	cin >> N >> a >> b;
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		//cout << setprecision(18) << num[i] << endl;
	}
	pas[1].push_back(1);
	pas[1].push_back(1);
	for (int i = 2; i <= 50; i++) {
		pas[i].push_back(1);
		for (int j = 0; j < (int)pas[i - 1].size() - 1; j++) {
			pas[i].push_back(pas[i - 1][j] + pas[i - 1][j + 1]);
		}
		pas[i].push_back(1);
	}
	s = 0;
	sort(num, num + N);
	reverse(num, num + N);
	for (int i = 0; i < N; i++) {
		if (num[i] != num[s]) {
			box.push_back(i - s);
			s = i;
		}
	}
	box.push_back(N - s);
	for (int j = 0; j < a; j++) {
		sum[a] += num[j];
	}
	M = sum[a];
	for (int i = a + 1; i <= b; i++) {
		bag = 0;
		for (int j = 0; j < i; j++) {
			sum[i] += num[j];
		}
	}
	cout << setprecision(20) << (double)M / a << endl;
	for (long long int i = a; i <= b; i++) {
		bag = i;
		//cout << sum[i] * a << " " << M*i << endl;
		if (sum[i] * a == M*i) {
			for (auto j : box) {
				if (bag > j) {
					bag -= j;
				}
				else {
					ans += pas[j][bag];
					break;
				}

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


Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    double[] resx, resy, a;
    String s;
    char[] c;
    int i, j, l;

    resx = new double[1]; resy = new double[1]; a = new double[6];

    for(;sc.hasNext();){
      s = sc.next(); c = new char[s.length()];
      for(i = 0;i < s.length();i++)c[i] = s.charAt(i);
      l = 0; j = 0;
      for(i = 0;i < 6;j++)if(j == s.length() || c[j] == ','){
        a[i++] = readdouble(c, l, j);
        l = ++j;
      }
      getsympoint(a, resx, resy);
      out.println(resx[0] + " " + resy[0]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
  private static void getsympoint(double[] a, double[] resx, double[] resy){
    double x1, y1, x2, y2, xq, yq, t;
    x1 = a[0]; y1 = a[1]; x2 = a[2]; y2 = a[3]; xq = a[4]; yq = a[5];
    t = (x2 - x1) * (xq - x1) + (y2 - y1) * (yq - y1);
    t /= (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
    resx[0] = x1 + t * (x2 - x1);
    resx[0] = resx[0] + (resx[0] - xq);
    resy[0] = y1 + t * (y2 - y1);
    resy[0] = resy[0] + (resy[0] - yq);
    return;
  }
  private static double readdouble(char[] ch, int l, int r){
    int i;
    double res, d, s = 1;
    if(ch[l] == '-'){ s = -1; l++; }
    d = 1.0; res = 0.0;
    for(i = l;i < r;i++){
      if(ch[i] == '.')break;
      d *= 10;
    }
    d /= 10;
    for(i = l;i < r;i++)if(ch[i] != '.'){
      res += d * (double)(ch[i] - '0');
      d /= 10;
    }
    return res * s;
  }
}

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

int main()
{
    string s;
    cin >> s;
    if(s=="SUN")cout << 7;
    if(s=="MON")cout << 6;
    if(s=="TUE")cout << 5;
    if(s=="WED")cout << 4;
    if(s=="THU")cout << 3;
    if(s=="FRI")cout << 2;
    if(s=="SAT")cout << 1;
}


Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
typedef long long ll;
//ll mod = 1e9+7;
ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    if ( k == 0 ) {
        cout << n * n << endl;
        return 0;
    }
    for ( ll i = k + 1; i <= n; ++i ) {
        ll mod_group_num = ( n + 1 ) / i;
        ans += mod_group_num * ( i - k );
        ll num = ( n + 1 ) % i;
        ans += max(0LL, num - k);
    }
    cout << ans << endl;
    return 0;
}


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

fn main() {
    let mut line = String::new();
    let _ = stdin().read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let a: i32 = vec[0].parse().unwrap();
    let b: i32 = vec[1].parse().unwrap();

    if a > b {
        println!("a > b");
    }
    if a < b {
        println!("a < b");
    }
    if a == b {
        println!("a == b");
    }

}



Measured memory_bytes: 5016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

unordered_set<int> node[200001];
bool visited[200001];

int dfs(int u) {
    visited[u] = true;

    int sz = 1;
    for(auto c: node[u]) if(!visited[c])
        sz += dfs(c);
    
    return sz;
}

int main() {
    int n, m, a, b; scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++) visited[i] = false;
    for(int i=0; i<m; i++) {
        scanf("%d %d", &a, &b);
        node[a].insert(b);
        node[b].insert(a);
    }

    int sz, ans = 0;
    for(int i=1; i<=n; i++) if(!visited[i]) {
        sz = dfs(i);
        ans = max(ans, sz);
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 39864
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll a;
    cin >> a;
    cout << a + pow(a, 2) + pow(a, 3) << endl;
}


Measured memory_bytes: 4188
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    ll x; cin >> x;
    ll res = (x + (5.5 - 1)) / 5.5;
    cout << res << endl;
}

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

const int MAX = 100005;
int main(){
  ll n,k,r,s,p; cin >> n >> k >> r >> s >> p;
  string t; cin >> t;
  bool flag[MAX];
  ll ans=0;
  for(int i=0;i<n;i++) flag[i] = true;

  for(int i=0;i<n-k;i++){
    if(t[i]==t[i+k] && flag[i]==true){
      flag[i+k] = false;
    }
  }

  for(int i=0;i<n;i++){
    if(flag[i]){
      if(t[i]=='r') ans += p;
      else if(t[i]=='s') ans += r;
      else ans += s;
    }
  }

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

Measured memory_bytes: 512