akhauriyash/Code-Regression huggingface dataset:
def fac(n):
    dic = {}
    cur = n
    for i in range(2,(int(n**0.5)+2)):
        if cur % i == 0:
            count = 0
            while cur % i == 0:
                count += 1
                cur //= i
            dic[i] = count
            if cur == 1:
                break
    if cur != 1:
        dic[cur] = 1
    return dic

n = int(input())
ans = 0
for i in fac(n).values():
    count = 1
    while i >= count:
        i -= count
        count += 1
        ans += 1
print(ans)

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


import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    t = 1
    for a in A:
        if a & 1:
            print(0)
            return
        else:
            t = lcm(t, a//2)
    for a in A:
        if t % a == 0:
            print(0)
            exit()

    print(-(-(M//t)//2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16268
from numba import njit


@njit(cache=True)
def solve(n,x,y):
    ans = [0] * (n - 1)
    for i in range(n):
        for j in range(n):
            c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
            if c:
                ans[c-1] += 1
    return ans


n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = solve(n,x,y)
for ai in ans:
    print(ai//2)


Measured memory_bytes: 110960
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,p,q;
  cin >> N;
  p=1;
  q=N;
  for(long long i=1;i<=sqrt(N);i++){
    if(N%i==0){
      p=i;
      q=N/i;
  }
  }
  cout << p+q-2;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int a[101010];
bool cnt[30];
int main() {
	cin >> n;
	REP(i, n)cin >> a[i];
	int sum = 0;
	REP(i, n) {
		sum ^= a[i];
		REP(j, 30) {
			if ((1 << j) & a[i]) {
				cnt[j] = true;
				break;
			}
		}
	}
	int ans = 0;
	for (int i = 29; i >= 0; i--) {
		if ((1 << i)&sum) {
			if (!cnt[i]) {
				cout << -1 << endl;
				return 0;
			}
			else {
				ans++;
				sum ^= (1 << (i + 1)) - 1;
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
int Ans = 0;
int A, B;cin >> A >> B;
int a = A, b = B;

for(int i = 0; i <= 2; i++){
int P = 0;
for(int j = 0; j < i; j++){
P += A;A -= 1;}

for(int k = 0; k < 2 - i; k++){
P += B;B -= 1;}

Ans = max(Ans, P);
A = a;B =b;
}

cout << Ans << endl;

}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;

#define forn(a, b) for(int i = a;i <= b;++i)

int N;
int X[105];
int cur, ans = 2147483647;

int main()
{
	scanf("%d", &N);
	forn(1, N)
		scanf("%d", &X[i]);
	forn(1, 100)
	{
		cur = 0;
		for(int j = 1;j <= N;++j)
			cur += (X[j] - i) * (X[j] - i);
		ans = min(ans, cur);
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
a = [0] + list(map(int, input().split()))
DP = [[0 for k in range(K+1)] for n in range(N+1)]
cs = [[0 for k in range(K+2)] for n in range(N+1)]
for i in range(1,N+1):
    for j in range(0,K+2):
        if i == 1 and j <= K:
            if j <= a[i]:
                DP[i][j] = 1
            else:
                DP[i][j] = 0
        elif j <= K:
            DP[i][j] += (cs[i-1][j+1] - cs[i-1][max(j-a[i],0)])%(10**9+7)
        if j > 0:
            cs[i][j] = (cs[i][j-1]%(10**9+7) + DP[i][j-1]%(10**9+7))%(10**9+7)
print(DP[N][K])

Measured memory_bytes: 288220
#include <stdio.h>
int main(void){
    // Your code here!
    long a, b, k;
    
    scanf("%ld %ld %ld", &a, &b, &k);
    
    if(a > k){
        a -= k;
    }else{
        b = (b - (k - a) >= 0) ? b - (k - a) : 0;
        a = 0;
    }

    printf("%ld %ld", a, b);
}


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

int main() {
  ll x,y,z;
  cin >> x >> y >> z;
  ll a = x/(y+z);
  if(a*(y+z)+z>x) cout << a-1 << endl;
  else cout << a << endl;
  
  return 0;
}

Measured memory_bytes: 3636
import sys
import numpy as np
read = sys.stdin.read

N, T, *AB = map(int, read().split())
AB = np.array(AB).reshape(N, 2)
AB = AB[np.argsort(AB[:, 0], axis=0)]

dp = np.zeros(T, np.int64)
answer = []

for a, b in AB:
    answer.append(dp[-1] + b)
    if a > T:
        continue

    dp[a:] = np.maximum(dp[:T - a] + b, dp[a:])

print(max(answer))

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()


ll sum(int n);

void go(){
	int a,b;cin>>a>>b;
	if(2*b<a) cout << abs(a-2*b);
	else cout << 0;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
N=int(input())
A,B=1,1
for i in range(N):
   tmpl=list(map(int,input().split()))
   tmp=max(-1*(-1*A//tmpl[0]),-1*(-1*B//tmpl[1]))
   A,B=tmpl[0]*tmp,tmpl[1]*tmp
print(A+B)

Measured memory_bytes: 9128
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = IO().exec {
    val n = int()
    var x = long()
    val a = LongArray(n){long()}
    a.sort()
    var cnt = 0
    for (i in 0 until n - 1) {
        if (x < a[i]) break
        cnt++
        x -= a[i]
    }
    if (x == a[n-1]) cnt++
    println(cnt)
}

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

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

int main() {
  string s;
  cin >> s;
  
  if (s == "Sunny")
    cout << "Cloudy" << endl;
  else if (s == "Cloudy")
    cout << "Rainy" << endl;
  else if (s == "Rainy")
    cout << "Sunny" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
   string s;
   cin>>s;
   ll ans=0;
   int l=s.size()-1;
   for(int i=0;i<(1<<l);i++){
      ll sum=0;
      ll a=s[0]-'0';
      for(int j=0;j<l;j++){
         if(i&(1<<j)){
            sum+=a;
            a=0;
         }
         a=a*10+s[j+1]-'0';
      }
      sum+=a;
      ans+=sum;
   }
   cout<<ans<<endl;
   return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int gcd(int a, int b, int c){
    int gcd_ab = 0;
    if(a<b) swap(a,b);
    for(int i=1; i<=b; i++){
        if(a % i == 0){
            if(b % i == 0) gcd_ab = i;
        }
    }
    int gcd_abc = 0;
    if(gcd_ab>c) swap(gcd_ab, c);
    for(int i=1; i<=gcd_ab; i++){
        if(c % i == 0){
            if(gcd_ab % i == 0){
                gcd_abc = i;
            }
        }
    } 
    return gcd_abc;
}

int main()
{
    int K; cin >> K;
    ll sum = 0;
    for(int i=1; i<=K; i++){
        for(int j=1; j<=K; j++){
            for(int k=1; k<=K; k++){
                sum += gcd(i, j, k);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3596
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <string>
#include <complex>
using namespace std;

#define INT_max 2147483647


typedef long long ll;
typedef long double ld;


int main(){
  int r;
  cin>>r;
  double pi = 3.141592554;
  double ans = (double)(r)*2 *pi;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <stdlib.h>

using namespace std;

int main(void)
{
	int n, a[200][200],G[200][200];
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> a[i][j];
		}
	}

	for (int j = 0; j < 3; j++)
	{
		for (int i = 0; i < n; i++)
		{
			for (int k = 0; k < n; k++)
			{
				if (a[i][j] == a[k][j] && i != k)
				{
					G[i][j] = 0;
					break;
				}
				else
				{
					G[i][j] = 0;
					G[i][j] = a[i][j];
				}
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		cout << G[i][0] + G[i][1] + G[i][2] << endl;
	}
}

Measured memory_bytes: 3376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif

const int MAXN = 100005;
const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;


ll n, k;
/*********************GoodLuck***********************/
int main () {
    IOS();
    cin >> n >> k;

    ll ans = 0;
    for (ll b=k+1;b<=n; b++) {
        for (ll i=0;i<=n; i+=b) {
//            debug(b, i,k,min(n+1,i+b) - (i+k));
            ans += max(0LL,min(n+1,i+b) - (i+k));
//            debug(ans);
        }
        if (k == 0) {
            ans--;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX_N 500001
#define INF (1<<30)

int cnt=0;
int L[MAX_N],R[MAX_N];

void merge(int *A,int left,int mid,int right){
  int i,j,k;
  
  int n1=mid-left;
  int n2=right-mid;
  
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];

  L[n1]=INF;
  R[n2]=INF;

  i=0;
  j=0;

  for(k=left;k<right;k++,cnt++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else {
      A[k]=R[j];
      j=j+1;
    }
  }
}

void mergeSort(int *A,int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(void){

  int n,A[MAX_N],i;
 
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  mergeSort(A,0,n);

  for(i=0;i<n;i++){
    printf("%d%c",A[i],(i<n-1?' ':'\n'));
  }  
  printf("%d\n",cnt);
  
  return 0;
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	long long a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	
	c*=2;

	long long ans = max(x, y) * c;

	long long t = min(x, y);
	ans = min(ans, c * t + (x - t) * a + (y - t) * b);

	ans = min(ans, x * a + b * y);
	cout << ans << endl;
}


Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        n: usize,
        k: usize,
        r: usize,
        s: usize,
        p: usize,
        t: Chars
    }

    let ts = {
        let mut ts = Vec::new();
        for &x in &t {
            match x {
                'r' => ts.push(0),
                's' => ts.push(1),
                'p' => ts.push(2),
                _ => unreachable!()
            }
        }
        ts
    };

    let mut ans = 0;
    let mut vec = vec![3; n];
    for mut i in 0..k {
        match ts[i] {
            0 => {
                ans += p;
                vec[i] = 2;
            }
            1 => {
                ans += r;
                vec[i] = 0;
            }
            2 => {
                ans += s;
                vec[i] = 1;
            }
            _ => unreachable!()
        }
        i += k;
        while i < n {
            if vec[i-k] != (ts[i]+2) % 3 {
                match ts[i] {
                    0 => {
                        ans += p;
                        vec[i] = 2;
                    }
                    1 => {
                        ans += r;
                        vec[i] = 0;
                    }
                    2 => {
                        ans += s;
                        vec[i] = 1;
                    }
                    _ => unreachable!()
                }
            } else {
                match ts.get(i+k) {
                    None => {}
                    Some(&x) => if x == ts[i] {
                        vec[i] = (vec[i-k]+1) % 3;
                    } else {
                        vec[i] = x;
                    }
                }
            }
            i += k;
        }

    }

    println!("{}",ans)
}


Measured memory_bytes: 3276
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string s, t;
int dp[3005][3005];

int main(void)
{
	cin >> s >> t;
	
	for(int i = 0; i < s.size(); i++){
		for(int j = 0; j < t.size(); j++){
			if(s[i] == t[j]){
				dp[i+1][j+1] = dp[i][j] + 1;
			}
			else{
				dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
			}
		}
	}
	
	string ans;
	int x = dp[s.size()][t.size()];
	
	/*for(int i = 0; i <= s.size(); i++){
		for(int j = 0; j <= t.size(); j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	
	int i = s.size(), j = t.size();
	while(i || j){
		//cout << i << " " << j << " " << x << endl;
		if(i > 0 && dp[i-1][j] == x) i--;
		else if(j > 0 && dp[i][j-1] == x) j--;
		else if(i > 0 && j > 0 && dp[i-1][j-1] == x-1) x--, ans += s[i-1], i--, j--;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 35456
/* ex 5_4
   YSK722 */

#include <stdio.h>

int main(void){
    int count = 0, count_hold = 0;
    // 10文字以下なので最大の要素数は'\0'を含めて11
    // ptr: "sequence"の各要素へのポインタ
    char sequence[11], *ptr;
    scanf("%s", sequence);
    ptr = sequence;
    // "ptr"の位置が'\0'になるまで動かす
    while (*ptr){
        // 連続でA,C,G,Tが並んでいる文字数を数える
        if (*ptr == 'A' || *ptr == 'C' || *ptr == 'G' || *ptr == 'T'){
            count++;
        }
        // 途切れたら、最大値を更新する
        else {
            if (count > count_hold){
                count_hold = count;
            }
            count = 0;
        }
        ptr++;
    }
    // 最後の文字がA,C,G,Tのどれかだった場合
    if (count > count_hold){
        count_hold = count;
    }
    // 最大値を出力
    printf("%d\n", count_hold);
    return 0;
}

Measured memory_bytes: 1732
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

INF = 10**9 + 1

N, M = map(int, readline().split())
data = np.array(read().split(), np.int64)
A = data[::3]
B = data[1::3]
C = data[2::3]

D = A[N:]
E = B[N:]
F = C[N:]
A = A[:N]
B = B[:N]
C = C[:N]

X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]

A = np.searchsorted(X, A)
B = np.searchsorted(X, B)
C = np.searchsorted(Y, C)
D = np.searchsorted(X, D)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F)

H, W = len(X), len(Y)
N = H * W

@njit
def set_ng(A, B, C, D, E, F):
    p = 0
    head = np.full(N, -1, np.int32)
    ng = np.empty(4 * N, np.int32)
    nxt = np.empty(4 * N, np.int32)

    def add(v, w):
        nonlocal p
        nxt[p] = head[v]
        head[v] = p
        ng[p] = w
        p += 1

    for i in range(len(A)):
        a, b, c = A[i], B[i], C[i]
        for x in range(a, b):
            v = x * W + c
            add(v, v - 1)
            add(v - 1, v)
    for i in range(len(D)):
        d, e, f = D[i], E[i], F[i]
        for y in range(e, f):
            v = d * W + y
            add(v, v - W)
            add(v - W, v)
    return head, ng[:p], nxt[:p]

head, ng, nxt = set_ng(A, B, C, D, E, F)

@njit
def next_w(head, ng, nxt, v):
    p = head[v]
    V = [v - W, v + W, v - 1, v + 1]
    while p != -1:
        if ng[p] in V:
            V.remove(ng[p])
        p = nxt[p]
    return V

x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
v0 = x0 * W + y0

@njit
def solve():
    visited = np.zeros(N, np.bool_)
    visited[v0] = 1
    stack = np.empty(N, np.int32)
    p = 0
    ret = 0

    def area(x):
        x, y = divmod(x, W)
        return DX[x] * DY[y]

    def push(x):
        nonlocal p, ret
        stack[p] = x
        visited[x] = 1
        ret += area(x)
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return stack[p]

    push(v0)
    while p:
        v = pop()
        for w in next_w(head, ng, nxt, v):
            if visited[w]:
                continue
            x, y = divmod(w, W)
            if x == 0 or x == H - 1 or y == 0 or y == W - 1:
                return 0
            push(w)
    return ret

x = solve()
if x == 0:
    print('INF')
else:
    print(x)


Measured memory_bytes: 227780
package main

import "fmt"

func max(a, b, c int) int {
	x := a
	if b > x {
		x = b
	}
	if c > x {
		x = c
	}
	return x
}

func sum(a, b, c int) int {
	return a + b + c
}

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	mx := max(a, b, c)
	sm := sum(a, b, c)

	var ans int
	if mx%2 == sm%2 {
		ans = (mx*3 - sm) / 2
	} else {
		ans = ((mx+1)*3 - sm) / 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import Control.Monad
import Data.List

judge [m,f,r]
  | m==(-1) || f==(-1) = "F"
  | c>=80 = "A"
  | c>=65 = "B"
  | c>=50 || (c>=30 && r>=50) = "C"
  | c>=30 = "D"
  | otherwise = "F"
  where c = m + f

main = do
    --d <- fmap (map judge . takeWhile (all (==(-1))) . map (map read . words) . lines) $ getContents 
    d <- fmap (map judge . takeWhile (any (/=(-1))) . map (map read . words) . lines) $ getContents 
    mapM_ putStrLn d
    return ()

Measured memory_bytes: 4044
//d+1????????§???????????????
//??????n-d-1????????§?????¨??°???????????????
//????????????min(3, d+1)??????????????¨??°???????????????(n-d-1??????)??¨????????????
//????????\??????????????£??????, ????????§????¨????????????????
//d + (n - d - 1) * (n - d - 2) / 2 + (n - d - 1) * min(3, d + 1)

#include <iostream>
#include <algorithm>
using namespace std;

long long n, d;

int main() {
	cin >> n >> d;
	cout << d + (n - d - 1) * (n - d - 2) / 2 + (n - d - 1) * min(3LL, d + 1) << endl;
	return 0;
}

Measured memory_bytes: 3104
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

string s;
int n;
vint pal;

unordered_map<int,vint> ma;

void mainmain(){
	cin>>s;
	n = s.size();	
	pal = vint(n);
	int state = 0;
	rep(i,n){
		int t = 1<<(s[i]-'a');
		state ^= t;
		pal[i] = state;
	}
	for(int i=n-1; i>=0; i--){
		ma[pal[i]].PB(i);
	}
	vint dp(n+1,INF);
	dp[0] = 0;
	rep(i,n){
		int t;
		mins(dp[i+1], dp[i]+1);
		if(i==0) t = 0;
		else t = pal[i-1];
		rep(j,26){
			int a = t ^ (1<<j);
			int cnt = 0;
			for(int x: ma[a]){
				if(x < i) break;
				mins(dp[x+1], dp[i]+1);
				if(cnt++>100) break;
			}
		}
		int a = t;
		int cnt = 0;
		for(int x: ma[a]){
			if(x < i) break;
			mins(dp[x+1], dp[i]+1);
			if(cnt++ > 100) break;
		}
	}
	cout<<dp[n]<<endl;
}


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

Measured memory_bytes: 245740
#include <cstdio>
using namespace std;
unsigned int a[200005],n,sum=0;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		sum^=a[i];
	}
	for(int i=1;i<=n;++i){
		printf("%d ",sum^a[i]);
	}
	printf("\n");
	return 0;
}

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

char maze[21][21];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
int ans = 0;
int h, w;

void dfs(int y, int x){
	ans += 1;
	maze[y][x] = '#';
	for(int i=0; i<4; i++){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(0 <= nx and nx < w and 0 <= ny and ny < h and maze[ny][nx] == '.'){
				dfs(ny, nx);
				//ans += 1;
			}
		}
	return;
}

int main(){
while(1){	
	ans = 0;
	int sx, sy;
	cin >> w >> h;
	if(w == 0 and h == 0) break;
	for(int i=0; i < h; i++){
		for(int j=0; j < w; j++){
			cin >> maze[i][j];
			if(maze[i][j] == '@'){
				sx = j;
				sy = i;
			}
		}
	}
	
	dfs(sy, sx);
	cout << ans << endl;
	/*
	for(int i=0; i < h; i++){
		for(int j=0; j < w; j++){
			cout << maze[i][j];
		}
		cout << endl;
	}
	*/
}//end	
	
	return 0;
}


Measured memory_bytes: 3032
import itertools

n,m,q=map(int,input().split())
Q=[]
for i in range(q):
    Q.append(list(map(int,input().split())))
ans=0
l=[i+1 for i in range(m)]
for i in itertools.combinations_with_replacement(l,n):
    temp=0
    for j in range(q):
        if i[Q[j][1]-1]-i[Q[j][0]-1]==Q[j][2]:
            temp+=Q[j][3]
    ans=max(ans,temp)
print(ans)

Measured memory_bytes: 9180
h, w = gets.split.map(&:to_i)
ss = Array.new(h) { gets.chomp.chars }
ans = 'Yes'

h.times do |i|
  w.times do |j|
    if ss[i][j] == '#'
      flag = false
      flag = true if j!=0   && ss[i][j-1]=='#'
      flag = true if j!=w-1 && ss[i][j+1]=='#'
      flag = true if i!=0   && ss[i-1][j]=='#'
      flag = true if i!=h-1 && ss[i+1][j]=='#'
      if !flag
        ans="No"
      end
    end
  end
end

puts ans

Measured memory_bytes: 2044
def print(str, a, b)
  return str.slice(a..b)
end

def reverse(str, a, b)
  str2 = str.slice!(a..b).reverse!
  str.insert(a, str2)
  return str
end

def replace(str, a, b, p)
  str.slice!(a..b)
  str.insert(a, p)
  return str
end

str = gets.chomp.to_s
n = gets.chomp.to_i

n.times{
  s, a, b, p = gets.split.map(&:to_s)
  a = a.to_i
  b = b.to_i

  if s == "print"
    puts print(str, a, b)
  elsif  s == "reverse"
    str = reverse(str, a, b)
  else
    str = replace(str, a, b, p)
  end
}

Measured memory_bytes: 8720
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long ul;
// #define int long long

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // 値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)  // 直後の要素をパディング
#define space_pad(num) setfill(' ') << std::right << setw(num)  // 直後の要素をパディング

// func declaration
template <class T> void print2DVec(vector< vector<T> >&);
template <class T> void calcVec(vector<T>&, int, char);
int char_to_int(const char);

// const
const int INF = 10000000;

/*MEMO
・辞書順
abc < abcd, atcoder < atlas
・イテレータ
std::vector<int>::iterator とタイプするのは面倒なので、
 通常は型推論の auto を使用する。
 auto iter = max_element(ALL(vec));
・2次元配列
vector<vector<int>> vec = {{1, 2, 3}, {4, 5, 6}}
・20×10の配列
vector<vector<int>> vec(20, vector<int>(10, 0));
・(n, m)の多次元配列
vector< vector<int> > vec(n, vector<int>(m, 0))  // 0で初期化
*/

int main() {
    cin.tie();
    ios::sync_with_stdio(false);
    
    // input
    int A, B;
    cin >> A >> B;
    
    if (A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) {
        cout << "Possible" << "\n";
    } else {
        cout << "Impossible" << "\n";
    }
    
    return 0;
}


// function
template <class T> void print2DVec(vector< vector<T> >& vec) {
    REP(i, vec.size()) {
        REP(j, vec.front().size()) {
            cout << vec.at(i).at(j);
        }
        cout << endl;
    }
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    switch (ch) {
        case '+':
            REP(i, vec.size()) vec.at(i) += num; break;
        case '-':
            REP(i, vec.size()) vec.at(i) -= num; break;
        case '*':
            REP(i, vec.size()) vec.at(i) *= num; break;
        case '/':
            REP(i, vec.size()) vec.at(i) /= num; break;
        case '%':
            REP(i, vec.size()) vec.at(i) %= num; break;
        default:
            cout << "Incorrect Operator" << endl;
    }
}

int char_to_int(const char c) {
    if('0' <= c && c <= '9') return (c - '0');
    return -1;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#include<cmath>
#define ll long long
#define inf 23333333
#define fur(i,x,y) for(i=x;i<=y;i++)
#define fdr(i,x,y) for(i=x;i>=y;i--)
#define Fur(i,x,y) for(ll i=x;i<=y;i++)
#define Fdr(x,y) for(ll i=x;i>=y;i--)
#define fl(i,x) for(ll i=head[x],to;to=e[i].to,i;i=e[i].next)
#define in2(x,y) in(x);in(y)
#define in3(x,y,z) in2(x,y);in(z)
#define in4(a,b,c,d) in2(a,b);in2(c,d)
#define clr(x,y) memset(x,y,sizeof(x))
#define cpy(x,y) memcpy(x,y,sizeof(x))

using namespace std;
/*---------------------------------------*/
namespace fib{char b[300000]= {},*f=b;}
#define gc ((*fib::f)?(*(fib ::f++)):(fgets(fib::b,sizeof(fib::b),stdin)?(fib::f=fib::b,*(fib::f++)):-1))
inline void in(ll &x){x=0;char c;bool f=0;while((c=gc)>'9'||c<'0')if(c=='-')f=!f;x=c-48;while((c=gc)<='9'&&c>='0')x=x*10+c-48;if(f)x=-x;}
namespace fob{char b[300000]= {},*f=b,*g=b+300000-2;}
#define pob (fwrite(fob::b,sizeof(char),fob::f-fob::b,stdout),fob::f=fob::b,0)
#define pc(x) (*(fob::f++)=(x),(fob::f==fob::g)?pob:0)
struct foce{~foce(){pob;fflush(stdout);}} _foce;
namespace ib{char b[100];}
inline void out(ll x){if(x==0){pc(48);return;}if(x<0){pc('-');x=-x;}char *s=ib::b;while(x) *(++s)=x%10,x/=10;while(s!=ib::b) pc((*(s--))+48);}
inline void outn(ll x){out(x);pc('\n');}
inline void swap(ll &x,ll &y){ll t=x;x=y;y=t;}
inline ll jdz(ll x){return x>0?x:-x;}
inline ll max(ll x,ll y){return x>y?x:y;}
inline ll min(ll x,ll y){return x<y?x:y;}
/*------------------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------------------------*/
#define N 200001
ll a[N],b[N],n;
map<ll,ll> v;
int main(){
	in(n);
	Fur(i,1,n){in(a[i]);b[i]=a[i];}
	sort(a+1,a+n+1);ll m=(n+1)/2;
	Fur(i,1,n)v[a[i]]=i;
	Fur(i,1,n){
		if(v[b[i]]<=m)outn(a[m+1]);else outn(a[m]);
	}
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
	int n,y;
    int i,j;
    cin >> n;
  	cin >> y;
  	for(i=0;i<=n;i++){
     	for(j=0;i+j<=n;j++){
            if(i*10000+j*5000+(n-i-j)*1000==y){
                cout << i << " " << j << " " << (n-i-j) << endl;
                return 0;
            }
        }
    }

   
    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
mod = 10**9 + 7

N, K = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]

def dot(X, Y):
    x = len(X)
    y = len(Y[0])
    z = len(Y)
    C = [[0] * y for _ in range(x)]
    for i in range(x):
        for j in range(y):
            for k in range(z):
                C[i][j] += X[i][k] * Y[k][j]
                C[i][j] %= mod
    return C

B = [[0] * N for _ in range(N)]
for k in range(N):
    B[k][k] = 1

while K > 0:
    if K & 1:
        B = dot(B, A)
    A = dot(A, A)
    K >>= 1

ans = 0
for i in range(N):
    for j in range(N):
        ans += B[i][j]
        ans %= mod

print(ans)

Measured memory_bytes: 42860
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    ll ans = 0;
    for(int i = 1; i <= n - 1; i++) {
        ans += i;
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 384
#include <cstdio>

int cache[45] = {};

int fib(int i){
    if(i == 0) return 1;
    if(i == 1) return 1;
    if(cache[i] == 0) cache[i] = fib(i - 1) + fib(i - 2);
    return cache[i];
}

int main(){
    int n;
    std::scanf("%d", &n);
    std::printf("%d\n", fib(n));
    return 0;
}



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

using namespace std;

int main()
{
    int k,a,b;
    int flg = 0;
    cin >> k;
    cin >> a >> b;
    for(int i=a; i<=b; i++){
        if(i % k == 0) flg = 1;
    }

    if(flg == 0) cout << "NG" << endl;
    else cout << "OK" << endl;

    return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    vector<int> A(b);
    vector<int> B(a);
    for(int i=0;i<b;i++){
        A.at(i) = a;
    }
    for(int i=0;i<a;i++){
        B.at(i) = b;
    }
    if(a>=b){
        for(int i=0;i<a;i++){
            cout << B.at(i);
        }
    }
    if(a<b){
        for(int i=0;i<b;i++){
            cout << A.at(i);
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n,m,k; cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  for(int i=1;i<n;i++) a[i]=a[i]+a[i-1];
  for(int i=1;i<m;i++) b[i]=b[i]+b[i-1];
  ll ans=0;
  rep(i,n){
    ll cnt=0;
    if(k-a[i]>=0) cnt=i+1;
    cnt+=upper_bound(all(b),k-a[i])-b.begin();
    chmax(ans,cnt);
  }
  chmax(ans,ll(upper_bound(all(b),k)-b.begin()));
  cout << ans << endl;
  
}

Measured memory_bytes: 6340
#include<cstdio>
int main()
{
    char str[105];
    int n;
    int x=0,max=0;
    scanf("%d",&n);
    scanf("%s",str);
    for(int i=0;i<n;i++)
    {
        if(str[i]=='I')
            x++;
        else if(str[i]=='D')
            x--;
        if(x>max)
            max=x;
    }
    printf("%d",max);
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
int p2[MAXN],sum[MAXN],fact[MAXN],invf[MAXN];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
int pow_mod(int a,int i)
{
    int s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
int comb(int n,int k)
{
    if(n<k) return 0;
    return 1LL*fact[n]*invf[k]%MOD*invf[n-k]%MOD;
}
int main()
{
    p2[0]=fact[0]=invf[0]=1;
    for(int i=1;i<=100000;i++) p2[i]=2LL*p2[i-1]%MOD;
    for(int i=1;i<=100000;i++) fact[i]=1LL*fact[i-1]*i%MOD;
    invf[100000]=pow_mod(fact[100000],MOD-2);
    for(int i=99999;i>=1;i--) invf[i]=1LL*invf[i+1]*(i+1)%MOD;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) 
    {
        sum[i]=sum[i-1];
        add(sum[i],a[i]);
    }
    int ans=0;
    for(int i=1;i<=n-1;i++)
    {
        add(ans,1LL*sum[i]%MOD*comb(n,n-i-1)%MOD*fact[n-i-1]%MOD*fact[i]%MOD);
        int now=sum[n];
        dec(now,sum[n-i]);
        add(ans,1LL*now%MOD*comb(n,n-i-1)%MOD*fact[n-i-1]%MOD*fact[i]%MOD);
    }
    add(ans,1LL*sum[n]*fact[n]%MOD);
    int cur=0,len=n-2;;
    for(int i=1;i<=(len+1)/2;i++)
    {
        int now=sum[n-i];
        dec(now,sum[i]);
        add(cur,now);
        add(ans,2LL*cur%MOD*comb(n,n-i-2)%MOD*fact[n-i-2]%MOD*fact[i]%MOD);
        if(i*2-1!=len) 
        {
            int rest=len+1-i;
            add(ans,2LL*cur%MOD*comb(n,n-rest-2)%MOD*fact[n-rest-2]%MOD*fact[rest]%MOD);
        }
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 2176
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;



//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        a: [usize;n],
    }

    // i-Ai == j+Aj || i+Ai == j-Aj
    let mut p = BTreeMap::new();
    for i in 0..n {
        let k = i+1 + a[i];
        p.entry(k).and_modify(|x|{*x+=1}).or_insert(1);
    }

    let mut ans = 0u64;
    for i in 0..n {
        if i+1 > a[i] {
            let k = i+1-a[i];
            if let Some(ct) = p.get(&k) {
                ans += ct;
            }
        }
    }

    println!("{}", ans);
}



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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
#define G0(x) get<0>((x))
#define G1(x) get<1>((x))
#define G2(x) get<2>((x))
#define G3(x) get<3>((x))


#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

#define G0(x) get<0>((x))

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

  int N;
  cin >> N;

  int base = -1;
  vector<tuple<int,int,int>> xs(N);
  REP(i,N){
    cin >> G0(xs[i]) >> G1(xs[i]) >> G2(xs[i]);
    if(G2(xs[i]) > 0) base = i;
  }
  assert(base >= 0);

  REP(cx, 101) REP(cy,101){
    int h = G2(xs[base]) + abs(cx - G0(xs[base])) + abs(cy - G1(xs[base]));

    // check validity
    bool ok = true;
    REP(i,N){
      int ch = max(0, h - abs(cx - G0(xs[i])) - abs(cy - G1(xs[i])));
      if(ch != G2(xs[i])) ok = false;
    }

    if(ok){
      cout << VI{cx, cy, h} << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector< int > vc(n + 1), dp(n + 1);
  for (int i = 1; i <= n; i++) cin >> vc[i];
  if (n >= 2) dp[2] = dp[1] + abs(vc[2] - vc[1]);
  for (int i = 3; i <= n; i++) {
    dp[i] = min(dp[i - 1] + abs(vc[i] - vc[i - 1]), dp[i - 2] + abs(vc[i] - vc[i - 2]));
  }
  cout << dp[n];
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define maxn 200001
#define gc getchar()
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define pb push_back
#define db double
#define pu puts(" ")
const int p=998244353;
int read() {
	int x=0,f=1;
	char ch=gc;
	while(!isdigit(ch)) {
		if(ch=='-')f=-1;
		ch=gc;
	}
	while(isdigit(ch))x=x*10+ch-48,ch=gc;
	return x*f;
}
void print(int x) {
	if(x>9)print(x/10);
	putchar(x%10+48);
}

int main() {
    int n=rd;
    fo(i,1,114514)
    {
    	if(floor(i*1.08)==n)
    	{
    		print(i);return pu,0;
		}
	}
	puts(":(");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
LL n,m;
scanf("%lld %lld",&n,&m);
if(abs(n-m)<=1){
    if(abs(n-m)==0){
        LL sum1=1,sum2=1;
        for(LL i=1;i<=n;++i){
            sum1=(sum1*i)%MOD;
        }
        for(LL i=1;i<=m;++i){
            sum2=(sum2*i)%MOD;
        }
        printf("%lld",(2*sum1*sum2)%MOD);
    }
    else{
        LL sum1=1,sum2=1;
        for(LL i=1;i<=n;++i){
            sum1=(sum1*i)%MOD;
        }
        for(LL i=1;i<=m;++i){
            sum2=(sum2*i)%MOD;
        }
        printf("%lld",(sum1*sum2)%MOD);
    }
}
else{
    printf("0");
}


    return 0;
}


Measured memory_bytes: 3784
#include<stdio.h>

int main(){
    int a,b;
    char op,s1,s2;
    scanf("%d%c%c%c%d",&a,&s1,&op,&s2,&b);

    int sum;
    if(op=='+'){
        sum=a+b;       
    }else{
        sum=a-b;
    }
    printf("%d\n",sum);
    return 0;
}

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

signed main(){
    int N;
    cin >> N;
    int A[110];
    for(int i=0; i<N; ++i) cin >> A[i];
    int res = -100;
    int cost = 1<<30;
    for(int x=-100; x<=100; ++x){
        int tmpcost=0;
        for(int i=0; i<N; ++i){
            tmpcost += abs(A[i]-x) * abs(A[i]-x);
        }    
        if(tmpcost<cost){
            cost = tmpcost;
            res = x;
        }
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
main(){
  int i,j,b=0;
  char a[1001];
  while(scanf("%s",a) !=EOF){
    if(b!=0) printf(" ");
    b++;
    for(i=0;i<996;i++){
      if(a[i]=='a'&&a[i+1]=='p'&&a[i+2]=='p'&&a[i+3]=='l'&&a[i+4]=='e'){
	a[i]='p';
	a[i+1]='e';
	a[i+2]='a';
	a[i+3]='c';
	a[i+4]='h';
      }
      else if(a[i]=='p'&&a[i+1]=='e'&&a[i+2]=='a'&&a[i+3]=='c'&&a[i+4]=='h'){
	a[i]='a';
	a[i+1]='p';
	a[i+2]='p';
	a[i+3]='l';
	a[i+4]='e';
      }
    }
    printf("%s",a);
  }
  printf("\n");
  return 0; 
}

Measured memory_bytes: 0
#include <iostream>

int main() {
	int a, b, k;
	std::cin >> a >> b >> k;

	int count = 0;
	for (int i = 100; ; --i) {
		if (a % i == 0 && b % i == 0)
			++count;

		if (count == k) {
			std::cout << i << std::endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cassert>
#include <bitset>
using namespace std;
typedef long long LL;

int main(void)
{
	int H, R;
	scanf("%d %d", &H, &R);
	if (H >= 0) printf("1\n");
	else if (-H <= R) printf("0\n");
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 3164
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int modBase = 1000000007;
        final int heightMax = 1000000000;
        int N = Integer.parseInt(br.readLine());
        int[] takahashi = new int[N+2];
        int[] aoki      = new int[N+2];
        //[0] and [N+1] are dummy datas; used to avoid array exc.
        
        String[] line = br.readLine().split(" ");
        for(int i=1;i<=N;i++) takahashi[i] = Integer.parseInt(line[i-1]);
        line = br.readLine().split(" ");
        for(int i=1;i<=N;i++) aoki[i] = Integer.parseInt(line[i-1]);
        takahashi[0]  =0;
        takahashi[N+1]=heightMax+1;
        aoki[0]       =heightMax+1;
        aoki[N+1]     =0;
        
        long answer = 1;
        for(int i=1;i<=N;i++){
        	boolean takHighest = (takahashi[i] > takahashi[i-1]);
        	int takMin,takMax;
        	if(takHighest){
        		takMin = takahashi[i];
        		takMax = takahashi[i];
        	}else{
        		takMin = 1;
        		takMax = takahashi[i];
        	}
        	boolean aokHighest = (aoki[i]      > aoki[i+1]);
        	int aokMin,aokMax;
        	if(aokHighest){
        		aokMin = aoki[i];
        		aokMax = aoki[i];
        	}else{
        		aokMin = 1;
        		aokMax = aoki[i];
        	}
        	int min = Math.max(takMin,aokMin);
        	int max = Math.min(takMax,aokMax);
        	int range = max-min+1;
        	if(range<0)range=0;
        	answer = (answer*range)%modBase;
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 45940
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 1e5 + 5;
const ll inf = 0x3f3f3f3f3f;
int i, j, n, m;

ll map[115][115];
int a,b,d,p,s,t;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
	    for (int j = 0; j < n; j++)
	        map[i][j] = inf;
	for (int i = 0; i < n; i++)
	    map[i][i] = 0;
	for (int i = 0; i < m; i++)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		if (map[a][b] > c) map[a][b] = c;
	}
	for (int k = 0; k < n; k++)
	{
	    for (int i = 0; i < n; i++)
	    {
	    	if (map[i][k] == inf) continue;
	    	for (int j = 0; j < n; j++)
	    	{
	    		if (map[k][j] == inf) continue;
	    		map[i][j] = min(map[i][j], map[i][k] + map[k][j]);
			}
		}
    }
    for (int i = 0; i < n; i++)
        if (map[i][i] < 0)
        {
        	printf("NEGATIVE CYCLE\n");
        	return 0;
		}
    for (int i = 0; i < n; i++)
    {
    	for (int j = 0; j < n; j++)
    	{
    		if (map[i][j] < inf / 2)
    		    printf("%d", map[i][j]);
    		else printf("INF");
    		if (j != n - 1)
    		printf(" ");
		}printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3308