akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int n,m; cin >>n >>m;
  int d; cin >>d;
  double res = 0;
  for (int i=0; i<m-1; i++){
    // 隣り合う2項はm-1個ある
    int beauty = (n-d);
    if (d != 0) beauty *= 2;
    res += (double)beauty / (double)n / (double)n;
  }
  cout <<fixed <<setprecision(12) <<res <<endl;
}

Measured memory_bytes: 3808
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


string alpha = "abcdefghijklmnopqrstuvwxyz";
set<string> st;

int n;
string now = "a";

void dfs() {

	if (now.size() == n) {
		st.insert(now);
		return;
	}
	//cout << "now= " << now << endl;

	int maxi = 0;
	for (int i = 0; i < now.size(); i++)
	{
		maxi = max(maxi, now[i] - 'a');
	}
	int lim = maxi;
	//cout << "lim= " << lim << endl;
	for (int i = 0 ; i <= lim + 1; i++)
	{
		now.push_back(alpha[i]);
		dfs();
		now.pop_back();
	}
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(10)

	
	cin >> n;

	dfs();

	for (auto itr : st) {
		cout << itr << endl;
	}

	return 0;
}



Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  vector<int> a(n);
  int x,y,z;//a,b,c
  int ans = 0;
  for(auto &i:a) cin >> i;
  sort(a.begin(),a.end());
  for(int i=0;i<=n-3;i++){
    for(int j = i+1;j<=n-2;j++){
      for(int k=j+1;k<=n-1;k++){
        if(a[i]<a[j]+a[k]&&a[j]<a[i]+a[k]&&a[k]<a[i]+a[j]) ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from fractions import Fraction as F
mod=10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
ret=1
cnt=0
for x in a:
	if x<0:
		b.append((-x,0))
	else:
		b.append((x,1))
b.sort(reverse=True)
p=-1
m=-1
for i in range(k):
	ret*=b[i][0]
	ret%=mod
	if b[i][1]==0:
		cnt+=1
		m=i
	else:
		p=i
if cnt%2==0:
	print(ret)
	exit()
ret1=-1
ret2=-1
f1=f2=0
if p!=-1:
	ret1=ret*pow(b[p][0],mod-2,mod)%mod
	for i in range(k,n):
		if b[i][1]==0:
			ret1*=b[i][0]
			ret1%=mod
			f1=1
			val1=F(b[i][0],b[p][0])
			break
if m!=-1:
	ret2=ret*pow(b[m][0],mod-2,mod)%mod
	for i in range(k,n):
		if b[i][1]==1:
			ret2*=b[i][0]
			ret2%=mod
			f2=1
			val2=F(b[i][0],b[m][0])
			break
if f1==0:
	ret1=-1
if f2==0:
	ret2=-1
if ret1==ret2==-1:
	ret=-1
	for i in range(k):
		ret*=b[-i-1][0]
		ret%=mod
	print(ret%mod)
elif ret1==-1:
	print(ret2)
elif ret2==-1:
	print(ret1)
else:
	if val1>val2:
		print(ret1)
	else:
		print(ret2)

Measured memory_bytes: 107708
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, K; cin >> N >> K;
    if(N % K == 0) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.util.*
import kotlin.math.abs
import kotlin.math.min

fun main() = abc119d()

@OptIn(ExperimentalStdlibApi::class)
fun abc119d() = SimpleFastIOWithToken_abc119d().exec {
    val n = readInt()
    val abc = IntArray(3) { readInt() }
    val bamboos = IntArray(n) { readInt() }

    var answer = Int.MAX_VALUE

    searchAllPatterns(arrayOf(-1, 0, 1, 2), n) { groups ->
        val lengths = IntArray(3)
        var merge = 0
        groups.forEachIndexed { index, group ->
            if (group != -1) {
                merge++
                lengths[group] += bamboos[index]
            }
        }
        if (lengths.any { it == 0 }) return@searchAllPatterns
        val diffSum = (0..2).sumBy { abs(lengths[it] - abc[it]) }
        answer = min(answer, diffSum + (merge - 3) * 10)
    }

    println(answer)
}

private inline fun <reified T> searchAllPatterns(patterns: Array<T>, length: Int, action: (Array<T>) -> Unit) {
    val patternSize = patterns.size
    val pow = (1..length).fold(1L) { acc: Long, _: Int -> acc * patternSize }
    val allPatterns = if (pow in 1..Int.MAX_VALUE) pow.toInt() else error("$pow is too large!")
    for (i in 0 until allPatterns) {
        val array = Array(length) { patterns[0] }
        var div = 1
        for (j in 0 until length) {
            array[length - j - 1] = patterns[(i / div) % patternSize]
            div *= patternSize
        }
        action(array)
    }
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc119d(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc119d.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 45124
S = list(input())

can = True

for i in range(len(S)):
    if (i % 2 != 0):
        if (S[i] == 'R'):
            can = False
            break
    else:
        if (S[i] == 'L'):
            can = False
            break
if (can):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k, sum, u;
ll a[1010], ans, tmp;
vector<ll> vec[2];
int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	for (int i = 1; i <= n; i++)
	{
		tmp = 0;
		for (int j = i; j <= n; j++)
		{
			tmp += a[j];
			vec[0].push_back(tmp);
		}
	}
	u = 1;
	for (int i = 40; i >= 0; i--)
	{
		sum = 0;
		for (auto j : vec[u ^ 1])
			if (j & (1LL << i))
				sum++;
		if (sum >= k)
		{
			ans += (1LL << i);
			vec[u].clear();
			for (auto j : vec[u ^ 1])
				if (j & (1LL << i))
					vec[u].push_back(j);
			u ^= 1;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define MAX_N 100010

int r, c, n;
stack <int> s;
struct point {int id, coor;} p[4][2 * MAX_N];

int boundary(int x, int y)
{
    if (x == 0) return 0;
    else if (y == c) return 1;
    else if (x == r) return 2;
    else if (y == 0) return 3;
    else return -1;
}

bool cmp_inc(point a, point b)
{
    return a.coor < b.coor;
}

bool cmp_dec(point a, point b)
{
    return a.coor > b.coor;
}

int main(void)
{
    scanf("%d%d%d", &r, &c, &n);
    int cnt[4] = {0};
    for (int i = 1; i <= n; i++) {
        int x[2], y[2];
        scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);
        bool is_boundary = true;
        for (int j = 0; j < 2; j++) {
            if (x[j] % r && y[j] % c) is_boundary = false;
        }
        if (is_boundary) {
            for (int j = 0; j < 2; j++) {
                int t = boundary(x[j], y[j]);
                p[t][cnt[t]].id = i;
                p[t][cnt[t]].coor = t % 2? x[j]: y[j];
                cnt[t]++;
            }
        }
    }
    for (int i = 0; i < 4; i++) {
        if (i < 2) sort(p[i], p[i] + cnt[i], cmp_inc);
        else sort(p[i], p[i] + cnt[i], cmp_dec);
        for (int j = 0; j < cnt[i]; j++) {
            if (s.size() && s.top() == p[i][j].id)
                s.pop();
            else
                s.push(p[i][j].id);
        }
    }
    if (s.empty()) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 5632
#!/usr/bin/env python3


if __name__ == '__main__':
    n, x = list(map(int, input().split()))
    l = list(map(int, input().split()))

    cnt = 1
    tmp = 0
    f = False
    for i in l:
        tmp += i
        if tmp > x:
            f = True
            break
        cnt += 1

    if f:
        print(cnt)
    else:
        print(n+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define mp make_pair
#include <iostream>
#define fastinput ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

vector<LL> value;
vector<vector<int>> adj;
void dfs(LL s,LL par,LL carried)
{
    value[s]+=carried;
    for(auto x:adj[s])
    {
        if(x!=par)
        {
            dfs(x,s,value[s]);
        }
    }
}

int main()
{    
    fastinput;
    LL n,i,j,k,t,temp;
    int queries;
    cin>>n>>queries;
    adj.resize(n+1);
    value.resize(n+1);
    for(i=1;i<=n;i++)
    {
        value[i]=0;
    }

    for(i=1;i<=n-1;i++)
    {
        cin>>j>>k;
        adj[j].pb(k);
        adj[k].pb(j);
    }

    while(queries--)
    {
        cin>>j>>k;
        value[j]+=k;
    }

    dfs(1,0,0);
    for(i=1;i<=n;i++)
    {
        cout<<value[i]<<" ";
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 24320
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let mut it = buf.split_whitespace().map(|n| String::from_str(n).unwrap());
    let (a, b, c) = (it.next().unwrap(), it.next().unwrap(), it.next().unwrap());

    let lena = a.chars().count();
    let lenb = b.chars().count();
    //    let lenc = c.chars().count();
    if a.chars().nth(lena - 1) == b.chars().nth(0) {
        if b.chars().nth(lenb - 1) == c.chars().nth(0) {
            println!("YES");
            return;
        }

    }
    println!("NO");
}


Measured memory_bytes: 4352
#include <stdio.h>
int main(){
	int S,h,m,s;
	scanf("%d",&S);
	if(S>=0 && S<=86400){
		h=S/3600;
		m=(S-h*3600)/60;
		s=S-(h*3600+m*60);
		printf("%d:%d:%d\n",h,m,s);
	}
	return 0;
}

Measured memory_bytes: 1852
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100

ll N,x;
std::vector<ll> a,b;
ll ans = 0;

int main() {
  cin >> N >> x;
  rep(i,N) {
    ll t1;
    scanf("%lld", &t1);
    a.push_back(t1);
  }

  for (auto itr = a.begin(); itr != a.end() - 1; ++itr) {
    ll temp = *itr + *(itr+1);
    if (temp > x) {
      ll t = temp - x;
      ans += t;
      if (*(itr + 1) > t) {
        *(itr + 1) -= t;
      } else {
        *(itr + 1) = 0;
      }
    }
  }

  cout << ans << endl;
}


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

signed main(void)
{
	int n, maxi, cnt; cin >> n;
	vector<int> h(n);

	rep(i, n) cin >> h[i];
	maxi = h[0];
	cnt = 1;
	rep(i, n - 1)
	{
		if (maxi <= h[i + 1])
		{
			cnt++;
			maxi = h[i + 1];
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
	#include <string>
	#include <vector>
	#include <algorithm>
	#include <utility>
	#include <map>
	using namespace std;
	typedef long long ll;
	#define rep(i,n) for (int i=0;i < (int)(n);i++)


	int main(){
		int n;
		ll k;
		cin >> n >> k;
		vector<ll> v(n);
		rep(i,n) cin >> v[i];

		ll res = 0;

		for (int kdigit = 60; kdigit >= -1;kdigit--){
			if (kdigit != -1 && !(k & (1LL<<kdigit))) continue;

			ll tmp = 0;
			for (int xdigit = 60; xdigit >= 0;xdigit--){
				ll mask = 1LL << xdigit;
				int num = 0;
				rep(i,n) if (v[i] & mask) num++;

				if (xdigit > kdigit){
					if (k & mask) tmp += mask * (n-num);
					else tmp += mask *num;
				}
				else if (xdigit == kdigit){
					tmp += mask * num;
				}
				else {
					tmp += mask * max(num,n-num);
				}
			}
			res =max(res,tmp);
		}
		cout << res << endl;
		return 0; 
	}



Measured memory_bytes: 4040
import math
from functools import reduce


def gcd(*numbers):  # greatest common divisor
    return reduce(math.gcd, numbers)


def lcm_base(x, y):  # least common multiplier
    return (x*y) // math.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def main():
    n = int(input())
    t = []
    for i in range(n):
        t.append(int(input()))

    answer = lcm(*t)

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 67952
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int x,a;
	cin >> x >> a;
	if (x < a) {
		cout << 0 << endl;
	}
	if (x >=a) {
		cout << 10 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define ll long long int
#define fab(a,b,i) for(int i=a;i<b;i++)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
vector<int> v[100005];
ll dp[100005][2];
void dfs(int src,int par )

{
	//cout<<"src:"<<src<<" "<<pr<<endl;
	\
	dp[src][0]=dp[src][1]=1;

	for(auto i: v[src])
	{
		if(i==par)
			continue;
			dfs(i,src);
		
			dp[src][0]=((dp[i][1]+dp[i][0])*dp[src][0])%MOD;
	
		
			dp[src][1]=(dp[src][1]*dp[i][0])%MOD;

	}
	//cout<<"dp:"<<dp[src][pr]<<endl;
}

int main()
{ quick;

	int n;
	cin>>n;
	fab(0,n+1,i)
	dp[i][0]=dp[i][1]=-1;
	fab(1,n,i)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		v[x].pb(y);
		v[y].pb(x);

	}
	dfs(0,-1);
	cout<<(dp[0][1]+dp[0][0])%MOD<<endl;

	return 0;
}

Measured memory_bytes: 14208
import java.util.*;
import java.io.PrintWriter;
public class Main{
	static ArrayList<Integer>[] edge;
	static long mod=1000000007;
	static long[][] dp;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		edge=new ArrayList[n];
		dp=new long[n][2];
		for(int i=0; i<n; i++){
			dp[i][0]=dp[i][1]=1;
		}
		for(int i=0; i<n; i++){
			edge[i]=new ArrayList<>();
		}
		for(int i=1; i<n; i++){
			int x=sc.nextInt()-1;
			int y=sc.nextInt()-1;
			edge[x].add(y);
			edge[y].add(x);
		}
		dfs(0,0);
		System.out.println((dp[0][0]+dp[0][1])%mod);
	}
	static void dfs(int now,int from){
		for(int i:edge[now]){
			if(i!=from){
				dfs(i,now);
				dp[now][0]=(dp[now][0]*(dp[i][0]+dp[i][1]))%mod;
				dp[now][1]=dp[now][1]*dp[i][0]%mod;
			}
		}
	}
}

Measured memory_bytes: 117844
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int a = Input.ScanInt();
          
          Console.WriteLine(a*((a&1)+1));
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  rep(i, n) cin >> p.at(i);
  rep(i, n) cin >> q.at(i);
  vector<int> v(n);
  rep(i, n) v.at(i) = i + 1;
  int cnt = 0;
  int a = 0;
  int b = 0;
  do {
    bool find_a = true;
    bool find_b = true;
    rep(i, n) {
      if (p.at(i) != v.at(i)) find_a = false;
      if (q.at(i) != v.at(i)) find_b = false;
    }
    if (find_a) a = cnt;
    if (find_b) b = cnt;
    cnt++;
  } while (next_permutation(v.begin(), v.end()));
  cout << abs(a - b) << endl;
  return 0;
}

Measured memory_bytes: 3568
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){ 
    int n, m; cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i, m){
        int u, v; cin >> u >> v; u--, v--;
        G[u].push_back(v);
    }
    int s, t; cin >> s >> t; s--, t--;
    queue<pii> que; que.push({s, 0});
    vector<vector<int>> cost(n, vector<int>(3, -1));
    cost[s][0] = 0;
    while(!que.empty()){
        auto nd = que.front(); que.pop();
        int v1 = nd.first, v2 = nd.second;
        for(auto e: G[v1]){
            int nv2 = (v2+1)%3;
            if(cost[e][nv2] != -1) continue;
            cost[e][nv2] = cost[v1][v2] +1;
            que.push({e, nv2});
        }
    }
    if(cost[t][0] == -1) cout << -1 << ln;
    else cout << cost[t][0] / 3 << ln;
}

Measured memory_bytes: 11136
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1e2 + 5;

int main()
{
    ll n, m;
    scanf("%lld %lld", &n, &m);
    if(n == 1 && m == 1)
        printf("1\n");
    else if(min(n, m) == 2)
        printf("0\n");
    else if(min(n, m) == 1)
        printf("%d\n", max(n, m)-2);
    else
        printf("%lld\n", (n-2)*(m-2));
    return 0;
}
/****


****/


Measured memory_bytes: 256
#include <stdio.h>

long p[100000];

int argmax(int l, int r){
  int nowmax=p[l];
  int maxindex=l;
  for(int i=l+1;i<=r;i++){
    if(p[i]>nowmax){
      maxindex=i;
      nowmax=p[i];
    }
  }
  return maxindex;
}

int ascending(int l, int r){
  for(int i=l;i<=r-1;i++){
    if(p[i]>p[i+1]) return 0;
  }
  return 1;
}

int descending(int l, int r){
  for(int i=l;i<=r-1;i++){
    if(p[i]<p[i+1]) return 0;
  }
  return 1;
}

long firstsum(int l, int r, int n){
  int i,imax;
  long ans;
  if(l==n && r==n) return 0;
  if(l!=n) imax=l;
  else imax=l+1;
  for(i=l+1;i<=r;i++){
    if(i!=n && p[i]>p[imax]) imax=i;
  }
  if(imax<n){
    ans=p[imax]*(imax-l+1)*(r-n+1)+firstsum(imax+1,r,n);
  }else{
    ans=p[imax]*(n-l+1)*(r-imax+1)+firstsum(l,imax-1,n);
  }
  return ans;
}

long secondsum(int l, int r){
  long ans=0;
  int imax,i;

  if(r-l<1) return 0;
  if(ascending(l,r)){
    for(i=l;i<=r-1;i++){
      ans+=p[i]*(i-l+1);
    }
    return ans;
  }
  if(descending(l,r)){
    for(i=r;i>=l+1;i--){
      ans+=p[i]*(r-i+1);
    }
    return ans;
  }
  imax=argmax(l,r);
  
  if(imax==l)
    ans=secondsum(imax+1,r)+firstsum(l,r,imax);
  else if(imax==r)
    ans=secondsum(l,imax-1)+firstsum(l,r,imax);
  else
    ans=secondsum(l,imax-1)+secondsum(imax+1,r)+firstsum(l,r,imax);
  return ans;
}

int main()
{
  int n;
  scanf("%d", &n);
  for(int i=0;i<n;i++) scanf("%ld", &p[i]);
  printf("%ld\n",secondsum(0,n-1));  
  return 0;
}

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

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}
//const int INF = 0x3f3f3f3f;
//const int mod=1e9+7;
//const double pi=3.14159265359;
//###################################################################
int main() {

    int n=D(),d=D();
    int cnt=0;
    for(int i=0;i<n;i++){
        ll a=LLD(),b=LLD();
        if(sqrt((a*a)+(b*b))<=d)cnt++;
    }
    cout<<cnt;

}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> key;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    int s = 0;
    rep(j,b){
      int c;
      cin >> c;
      c--;
      s |= 1<<c;
    }
    key.emplace_back(s,a);
  }
  vector<int> dp(1<<n,INF);
  dp[0] = 0;
  rep(s,1<<n){
    rep(i,m){
      int t = s | key[i].first;
      int cost = dp[s] + key[i].second;
      dp[t] = min(dp[t],cost);
    }
  }
  int ans = dp.back();
  if(ans==INF) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 256
/* ABC106 - B
 */
#include <iostream>

using namespace std;

int N;

int calc(void) {

	int result = 0;
	for (int n = 8; n <= N; n++) {
		if ((n % 2) == 0) {
			// even
			continue;
		}

		// odd
		int num = 0;
		for (int v = 1; v <= n; v++) {
			if (n % v == 0) {
				// able to divide
				++num;
			}
		}

		if (num == 8) {
			++result;
		}
	}
	return result;
}

int main(void) {

	cin >> N;
	int ans = calc();
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y) {
  int c[N + 1][N + 1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for ( int i = 0; i <= m; i++ ) c[i][0] = 0;
  for ( int j = 1; j <= n; j++ ) c[0][j] = 0;

  for ( int i = 1; i <= m; i++ )
    for ( int j = 1; j <= n; j++ ) {
      if ( X[i] == Y[j] )
        c[i][j] = c[i - 1][j - 1] + 1;
      else
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      maxl = max(maxl, c[i][j]);
    }

  return maxl;
}

int main() {
  string s1, s2;
  int n; cin >> n;
  for ( int i = 0; i < n; i++ ) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}


Measured memory_bytes: 7104
import scala.io.StdIn
 
object Main {
  def main(args: Array[String]){
    val inputs = (0 to (StdIn.readInt() - 1)).map(_ => StdIn.readInt)
    println(inputs.filter{i =>
      (2 to Math.sqrt(i).toInt).forall(i % _ != 0)}.length)
  }
}

Measured memory_bytes: 120388
#include <bits/stdc++.h>
#define INF (1LL<<60)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int a[1005],b[1005];
vector<int> vec[1005];
ll dp[1005][2020];

void solve(){
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n*2;j++){
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;
	for(int i=0;i<=n;i++){
		vec[i].clear();
	}
	vec[0].push_back(0);
	for(int i=0;i<n;i++){
		int dif=b[i]-a[i];
		if(dif<0){
			dif+=m;
		}
		for(int j=0;j<n*2;j++){
			vec[i+1].push_back(dif);
			dif+=m;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<vec[i].size();j++){
			if(dp[i][j]==INF)continue;
			int pos=lower_bound(vec[i+1].begin(),vec[i+1].end(),vec[i][j])-vec[i+1].begin();
			if(pos>0){
				ll dif=vec[i+1][pos-1]-vec[i][j];
				if(dif<0)dif=0;
				dp[i+1][pos-1]=min(dp[i+1][pos-1],dp[i][j]+dif);
			}
			if(pos<vec[i+1].size()){
				ll dif=vec[i+1][pos]-vec[i][j];
				if(dif<0)dif=0;
				dp[i+1][pos]=min(dp[i+1][pos],dp[i][j]+dif);
			}
		}
	}
	ll ans=INF;
	for(int i=0;i<vec[n].size();i++){
		ans=min(ans,dp[n][i]);
	}
	printf("%lld\n",ans);
}

int main(void){
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(int i=0;i<n;i++){
			scanf("%d",&b[i]);
		}
		solve();
	}
	return 0;
} 


Measured memory_bytes: 26844
using System;
class E
{
	static void Main()
	{
		int N = int.Parse(Console.ReadLine());
		var a = new int[N];
		var strs = Console.ReadLine().Split();
		for (var i = 0; i < N; i++) a[i] = int.Parse(strs[i]);
		var min = 100000000000000000L;
		for (var t = -100; t<=100;t++)
		{
			var sum = 0L;
			foreach (var x in a) sum += (x - t) * (x - t);
			min = Math.Min(min, sum);
		}
		Console.WriteLine(min);
	}
}

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

signed main(){
	char c;
	cin >> c;
	bool ok = false;
	for(int i = 0; i <26; i++) if(c == 'A' + i) ok = true;
	if(ok) cout << 'A' << endl;
	else cout << 'a' << endl;
}

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

typedef long long ll;

int n,k;
int p[5005],c[5005],ir[5005],rc,rl[5005],vis[5005];
stack<int> st;
ll rs[5005],ans=-1e9;

void dfs(const int &x){
    vis[x]=1;
    st.push(x);
    if(!vis[p[x]]){
        dfs(p[x]);
    }else{
        rc++;
        while(st.top()!=p[x]){
            ir[st.top()]=rc;
            rl[rc]++;
            rs[rc]+=c[st.top()];
            st.pop();
        }
        ir[p[x]]=rc;
        rl[rc]++;
        rs[rc]+=c[p[x]];
        st.pop();
    }
}

ll calc(const int &x,int y){
    if(y==0)return 0;
    if(ir[x]){
        ll pre=0;
        if(y>rl[ir[x]]){
            pre+=max(0ll,(y-rl[ir[x]])/rl[ir[x]]*rs[ir[x]]);
            y-=(y-rl[ir[x]])/rl[ir[x]]*rl[ir[x]];
        }
        return max(0ll,calc(p[x],y-1))+c[x]+pre;
    }else{
        return max(0ll,calc(p[x],y-1))+c[x];
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    for(int i=1;i<=n;i++){
        cin>>c[i];
    }
    for(int i=1;i<=n;i++)if(!vis[i])dfs(i);
    for(int i=1;i<=n;i++){
        ans=max(ans,calc(i,k));
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3992
use std::io::*;
use std::str::*;


// while let Some(x)=read(cin) { ... }
fn read<T: FromStr>(cin: &mut StdinLock) -> Option<T> {
    let cin = cin.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    cin.parse::<T>().ok()
}


fn read_vec<T: FromStr>(cin: &mut StdinLock) -> Vec<T> {
    let mut s = String::new();
    cin.read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


fn main(){
    let cin = stdin();
    let mut cin = cin.lock();
    let cin = &mut cin;
    
    let a:i32 = read(cin).unwrap();
    let b:i32 = read(cin).unwrap();
    let c:i32 = read(cin).unwrap();
    let x:i32 = read(cin).unwrap();
    let x=x/50;
    let mut ans =0;
    'a0: for a0 in 0..a+1 {
        let x1=x-a0*10;
        if x1<0 {break}
        'b0: for b0 in 0..b+1 {
            let x2=x1-b0*2;
            if x2<0 {continue 'a0}
            if x2 <= c {ans=ans+1}
        }
    }

        
    println!("{}",ans);

    
}


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

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

struct State { int tx, ty, kx, ky, cost; };
int X, Y;
int d[52][52];
bool used[52][52][52][52];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	while (cin >> X >> Y, X) {
		int tx, ty, kx, ky;
		cin >> tx >> ty >> kx >> ky;
		for (int i=0; i<=Y+1; ++i) {
			for (int j=0; j<=X+1; ++j) {
				if (i==0 || i==Y+1 || j==0 || j==X+1) d[i][j] = 1;
				else cin >> d[i][j];
			}
		}
		memset(used, false, sizeof used);
		queue<State> q;
		q.push((State){tx, ty, kx, ky, 0});
		int res = -1;
		while ( ! q.empty()) {
			State s = q.front(); q.pop();
			if (100 <= s.cost) break;
			if (used[s.tx][s.ty][s.kx][s.ky]) continue;
			used[s.tx][s.ty][s.kx][s.ky] = true;
			if (s.tx == s.kx && s.ty == s.ky) {
				res = s.cost;
				break;
			}
			for (int i=0; i<4; ++i) {
				if (d[s.ty+dy[i]][s.tx+dx[i]] && d[s.ky-dy[i]][s.kx-dx[i]]) continue;
				int tx2 = s.tx, ty2 = s.ty;
				if ( ! d[s.ty+dy[i]][s.tx+dx[i]]) {
					tx2 += dx[i];
					ty2 += dy[i];
				}
				int kx2 = s.kx, ky2 = s.ky;
				if ( ! d[s.ky-dy[i]][s.kx-dx[i]]) {
					kx2 -= dx[i];
					ky2 -= dy[i];
				}
				if ( ! used[tx2][ty2][kx2][ky2] && s.cost+1 < 100) {
					q.push((State){tx2, ty2, kx2, ky2, s.cost+1});
				}
			}
		}
		if (res < 0) {
			cout << "NA" << endl;
		} else {
			cout << res << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 8864
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e10+10;

/*----------------------------------------------*/

signed main(){
  int n,m;
  cin>>n>>m;
  int t=1900*m+100*(n-m);
  int p=pow(2,m);
  int ans=t*p;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from sys import stdin
#time 2.49
def sp(G,R,V):
    d = {}
    INF = float('inf')
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = deque([(0, R)])
    while q:
        (cost, v) = q.popleft()
        for (u, c) in G[v].items():
            if d[u] > d[v] + c:
                d[u] = d[v] + c
                q.append((d[u], u))
    return d

V, E, R = [int(x) for x in stdin.readline().split()]
G = defaultdict(dict)
for case in range(E):
    s, t, w = [int(x) for x in stdin.readline().split()]
    G[s][t] = w
d = sp(G, R, V)
for k in range(V):
        if d[k] == float('inf'):
            print("INF")
        else:
            print(d[k])

Measured memory_bytes: 104916
import java.util.Scanner;

//*クラス名について
//Main.javaにしないとatcoder上でコンパイルが通らないので注意。


//＊標準入力について
//単語の場合はnext()
//整数の場合はnextInt()
//文字列（1行）の場合はnextLine()

//問題url
//https:atcoder.jp/contests/abc085/tasks/abc085_b
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int total = sc.nextInt();
		int d;
		
		//＊解法
		//「異なる大きさの餅がいくつあるか」という問題に読み換えることができる。
		//餅の総数が最大１００個、大きさも１〜１００までの整数なので、
		//１００個の要素をもつ配列(Aとする)を作り、
		//順番に餅の大きさを見て、餅の大きさと等しいAの要素番号に１を入れる。
		//全ての餅を見終わった後に、配列Aの要素を全て足すと、異なる餅の数になる。
		
		int[] kata = new int[100];
		
		for (int i=0;i<total;i++) {
			d=sc.nextInt();
			//配列の番号は1からでなく、0からなので1ずらして調整
			kata[d-1]=1;
		}
		int sum=0;
		for(int j=0; j<100;j++) {
			sum=sum+kata[j];
		}
		System.out.println(sum); 
	}	
}

Measured memory_bytes: 23252
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = LI()
Q = I()
BC = [LI() for _ in range(Q)]
ans = sum(A)
count_A = collections.defaultdict(int)
for a in A:
    count_A[a] += 1
for b,c in BC:
    if b in count_A:
        ans += (c-b)*count_A[b]
        count_A[c] += count_A[b]
        count_A[b] = 0
    print(ans)


Measured memory_bytes: 53964
#include <iostream>

int main()
{
    int n;
    int *a, *b, *c;
    int total = 0;
    int old = 0;
    std::cin >> n;
    
    a = new int[n];
    b = new int[n];
    c = new int[n - 1];

    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        std::cin >> b[i];
    }
    for (int i = 0; i < n - 1; i++) {
        std::cin >> c[i];
    }

    for (int i = 0; i < n; i++) {
        total += b[a[i] - 1];
        if (a[i] - 1 == old) {
            total += c[a[i] - 2];
        }
        old = a[i];
    }

    std::cout << total << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define maxn 205
#define mod 1000000007
using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = getchar();c < '0' || c > '9';c = getchar()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res * sig;
}
int n,x,s[maxn],f[maxn][100005];
int main(){
  n = getint(), x = getint();
  for(int i = 1;i <= n;i++) s[i] = getint();
  sort(s + 1,s + n + 1,greater<int>());
  f[0][x] = 1;
  for(int i = 0;i < n;i++){
    for(int j = 0;j <= x;j++){
      (f[i + 1][j % s[i + 1]] += f[i][j]) %= mod;
      (f[i + 1][j] += (ll)f[i][j] * (n - i - 1) % mod) %= mod;
    }
  }
  int ans = 0;
  for(int i = 1;i <= x;i++) (ans += (ll)f[n][i] * i % mod) %= mod;
  printf("%d\n",ans);
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a, b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n, m, arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

string s;
ll n;
//Vec ignr;

ll cntsq(ll a, ll b, ll ans) {
    ll cnt=ans;
    //5文字
    while (true) {
        if(b+cnt-1>=n||a+cnt-1>=b) {
            break;
        }
        if(s.substr(a, cnt)!=s.substr(b, cnt)) {
            break;
        }
        cnt++;
        //dbg(s[a+cnt]);
    }
    return cnt-1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    VV index(28);
    cin>>n>>s;
    rep(i, n) {
        index[s[i]-'a'].pb(i);
    }
    ll ans=0;

    ll pointer;
    rep(i, 27) {
        if(index[i].size()>1) {
            rep(j, index[i].size()) {
                REP(k, j+1, index[i].size()) {
                    ans=max(ans, cntsq(index[i][j], index[i][k], ans));
                }
            }
        }
    }
    //dbg(index);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include<iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
	int n;
	scanf("%d",&n);

	float sum=0;
	char x[14],u[4];
	for(int i=0;i<n;i++){
		scanf("%s %s",x,u);
		if(strcmp(u,"JPY")==0){sum+=atoi(x);}
		else{sum += atof(x) * 380000.0;}
	}
	printf("%lf\n",sum);
	return 0;
}



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

int main(){
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	int mn = max(a,max(b,c));
	int ans = a + b + c - mn + pow(2,k) * mn;
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace atcoder.abc166.c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] paramArray = getIntParams();
            int N = paramArray[0];
            int M = paramArray[1];

            int[] H = getIntParams();

            List<int>[] route = new List<int>[N + 1];
            for (int c = 0; c <= N; c++)
            {
                route[c] = new List<int>();
            }

            for (int i = 1; i <= M; i++)
            {
                int[] data = getIntParams();
                int A = data[0];
                int B = data[1];

                if (!route[A].Contains(B))
                {
                    route[A].Add(B);
                }
                if (!route[B].Contains(A))
                {
                    route[B].Add(A);
                }
            }

            int ret = 0;
            for (int x = 1; x <= N; x++)
            {
                if (route[x].Count == 0)
                {
                    ret++;
                }
                else
                {
                    int count = route[x].Where(i => H[i - 1] >= H[x - 1]).Count();
                    if (count == 0)
                    {
                        ret++;
                    }
                }
            }
            Console.WriteLine(ret);
        }
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
        static decimal getDecimalParam()
        {
            return decimal.Parse(Console.ReadLine());
        }
        static decimal[] getDecimalParams()
        {
            return Console.ReadLine().Split(' ').Select(i => decimal.Parse(i)).ToArray();
        }
    }
}


Measured memory_bytes: 60876
#include<bits/stdc++.h>
using namespace std ;
int main ()
{
   long int n,x1=0,x,i,j;
   cin>>n;
   long int a[n];
   for(i=0;i<n;i++)
   {
       cin>>a[i];
   }
   for(i=0;i<n;i++)
   {
       for(j=i;j<n;j++)
       {
           x=abs(a[i]-a[j]);
           x1=max(x1,x);
       }
   }
   cout<<x1;
}


Measured memory_bytes: 3548
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		System.out.println(xor(b)^xor(a-1));
		sc.close();
	}
	public static long xor(long x) {
		if(x%2 == 0) {
			return ((x/2)%2)^x;
		}else {
			return ((x+1)/2)%2;
		}
	}
}

Measured memory_bytes: 23124
#include <stdio.h>

int main() {
	long long int ans = 0, usum = 0, dsum = 0;
	int N, K;
	scanf("%d%d", &N, &K);
	for (int i = 0; i < K; i++) {
		usum += i;
		dsum += (long long int)N - (long long int)i;
	}
	for (int i = K; i <= N; i++) {
		ans += dsum - usum + 1;
		ans = ans % (1000000007);
		usum += i;
		dsum += (long long int)N - (long long int)i;
	}
	printf("%lld", ans+1);
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  for(int i=1;i<=N;i++){
  int p=i*1.08;
  if(p==N){
    cout<<i<<endl;
    return 0;
  }
  }
  cout<<":("<<endl;
}


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

using namespace std;
using namespace std::chrono;
#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,T,k,q;

ll ANS[1000001] = {0};

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;

    vector<ll> A;

    cin >> n;

    ll l = 0;
    ll r = n-1;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        A.push_back(a);
    }
    for(ll c1 = n-1; c1 >= 0; c1--){
        if((n-c1-1)%2 == 0){
            ANS[l] = A[c1];
            l++;
        }
        else{
            ANS[r] = A[c1];
            r--;
        }
    }

    for(ll c1 = 0; c1 < n; c1++){
        cout << ANS[c1] << " ";
    }

    return 0;
}



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

using namespace std;

int main()
{
	int d, g;
	cin >> d >> g;
	vector<int> p(d), c(d);
	for (int i = 0; i < d; i++)
		cin >> p[i] >> c[i];
	int ans = 1e9;
	for (int i = 0; i < (1 << d); i++)
	{
		int sum = 0, cnt = 0, m = -1;
		for (int j = 0; j < d; j++)
			if (i >> j & 1)
			{
				sum += 100 * (j + 1) * p[j] + c[j];
				cnt += p[j];
			}
			else
				m = max(m, j);
		if (sum < g)
			if ((g - sum + 100 * (m + 1) - 1) / (100 * (m + 1)) < p[m])
				cnt += (g - sum + 100 * (m + 1) - 1) / (100 * (m + 1));
			else
				continue;
		ans = min(ans, cnt);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a = Integer.parseInt(br.readLine());
		int b = Integer.parseInt(br.readLine());
		int c = Integer.parseInt(br.readLine());
		int d = Integer.parseInt(br.readLine());

		System.out.println(Math.min(a, b) + Math.min(c, d));

	}

}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

template <typename T>
void vecin(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n - 1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vint h(n);
    vecin(h);
    int ans = 0;
    REP(i,n){
        if (h[i] >= k)
            ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640