akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
#define sor sort 
#define cl clear
#define m_p make_pair 
#define sz(a) a.size()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
bool isp[100010];
int main()
{
	isp[0] = isp[1] = 1;
	for(ll i=2;i<=101000;i++)
	{
		for(ll j = i*i;j<=101000;j+=i)
		{
			isp[j] = 1;
		}
	}
	ll x;
	cin>>x;
	ll pos = x;
	while(isp[pos])
	{
		pos++;
	}
	cout<<pos<<endl;
	return 0;
}

Measured memory_bytes: 3736
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
--import Debug.Trace


main :: IO ()
main = do
  n <- readLn ::IO Int
  hs <- map read.words <$> getLine :: IO [Int]
  --traceShowM (hs, scanr1 min hs)
  putStrLn $ if [] == (filter (> 1) $ zipWith (-) hs (scanr1 min hs)) then "Yes" else "No"


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

const int MAXN = 200005;

int x[MAXN], y[MAXN];

int f(int a, int b) { return abs(x[a] - x[b]) + abs(y[a] - y[b]); }

int main(void)
{
	int n, i;
	int mx1 = INT_MIN, mx2 = INT_MIN, mx3 = INT_MIN, mx4 = INT_MIN;
	int t1, t2, t3, t4;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &x[i], &y[i]);

		int one = x[i] + y[i];
		int two = x[i] - y[i];
		int three = -x[i] + y[i];
		int four = -x[i] - y[i];

		if (mx1 < one)
		{
			mx1 = one;
			t1 = i;
		}

		if (mx2 < two)
		{
			mx2 = two;
			t2 = i;
		}

		if (mx3 < three)
		{
			mx3 = three;
			t3 = i;
		}

		if (mx4 < four)
		{
			mx4 = four;
			t4 = i;
		}
	}

	int ans = 0;

	for (i = 0; i < n; i++)
	{
		ans = max(ans, f(i, t1));
		ans = max(ans, f(i, t2));
		ans = max(ans, f(i, t3));
		ans = max(ans, f(i, t4));
	}

	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 5384
import math
N = int(input())
XYS = [list(map(int, input().split())) for _ in range(N)]

def rec(prefix, remains):
    if remains:
        for xy in remains:
            for xys in rec(prefix + [xy], [x for x in remains if x != xy]):
                yield xys
    else:
        yield prefix

s = 0
for xys in rec([], XYS):
    prev = xys.pop(0)
    for xy in xys:
        v = math.sqrt(((xy[0] - prev[0])**2) + ((xy[1] - prev[1])**2))
        prev = xy
        s += v

ans = s / math.factorial(N)
print(ans)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define Endl endl
typedef long long ll;
const int MAXN = (int)1e5 + 5;
int n, l;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n >> l)
	{
		int sum = 0, mi = INT_MAX;
		for (int i = 1; i <= n; ++i)
		{
			sum += l + i - 1;
			if (abs(l + i - 1) < abs(mi))
				mi = l + i - 1;
		}
		cout << sum - mi << endl;
	}
}
/*
5 2
3 -1
30 -50
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
/*const int inf=1e9+5;
ll n,k,y,x;
const int N = 1e5+5;*/
/*bool vis[N];
ll a[N];*/
/*bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
     return (a.f>b.f);
}*/
void solve()
{   ll n,m,res=0,l,r,cnt0=0,z,sum1=0,cnt1=0,h,res1,ans=0,sum=0,cnt=0;
    cin>>n;
    ll ar[n];
    rep(i,0,n) cin>>ar[i];
    sort(ar,ar+n);
    ll x=(n/2);
    cnt=ar[x]-ar[x-1];
    cout<<cnt;


}
int main()
{   speed_up
    ll t;
   //cin>>t;
    t=1;
    while(t--)
        solve();

}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A+B > C+D){
    cout << "Left" << endl;
  }
  else if (A+B == C+D){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
   
}

Measured memory_bytes: 3608
using System;
using System.Linq;

namespace ABC112B
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int[] ints = Input.IntArray();
            int N = ints[0];
            int T = ints[1];

            int[] costs = new int[N];
            for (int i = 0; i < N; i++)
            {
                int[] inputs = Input.IntArray();
                if (inputs[1] <= T)
                {
                    costs[i] = inputs[0];
                    continue;
                }

                costs[i] = int.MaxValue;
            }

            if (costs.Min() == int.MaxValue)
            {
                Console.WriteLine("TLE");
                return;
            }
            Console.WriteLine(costs.Min());
        }
    }
    internal static class Input
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

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

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

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back

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

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

int main() {

	bool j[8] = { false };
	int n, mina = 0, maxa = 0;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a >= 3200)maxa++;
		else j[a / 400] = true;
	}

	for (int i = 0; i < 8; i++) {
		if(j[i])mina++;
	}
	maxa += mina;
	if (mina == 0)mina = 1;
	cout << mina << ' ' << maxa << endl;

	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let c: i32 = sc.cin();
    let b: Vec<i32> = (0..m).map(|_| sc.cin()).collect();
    put!((0..n).filter(|_| 0 < (0..m).map(|i| sc.cin::<i32>() * b[i]).sum::<i32>() + c).count());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S;
    cin >> S;

    reverse(all(S));
    int index = 0;
    string cmp[] = {"maerd", "remaerd", "esare", "resare"};
    bool flag = true;

    while ((int)S.size() - 4 > index) {
        rep(j, 4) {
            int cnt = index;
            flag = true;
            rep(k, cmp[j].size()) {
                if (S[cnt + k] != cmp[j][k]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                index += (int)cmp[j].size();
                break;
            }
        }
        //cout << index << ":" << S;
        if (!flag) break;
    }

    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main(){
	string a,b;
	cin >> a >> b;
	if(a.size()==b.size()){
		if(a>b)cout << "GREATER\n";
		else if(a<b) cout << "LESS\n";
		else cout << "EQUAL\n";
	}
	else{
		if(a.size()>b.size())cout << "GREATER\n";
		else cout << "LESS\n";
	}
	return 0;
}

Measured memory_bytes: 256
def num_of_divisors(x):
  num=0
  for divisor in range(1, x + 1):
    if x % divisor == 0: num += 1
  return num

N = int(input())
cnt = 0
for i in range(1, N + 1, 2):
  if num_of_divisors(i) == 8:
    cnt += 1

print(str(cnt))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

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

int main()
{
    int n, k; cin >> n >> k;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(ALL(l));
    reverse(ALL(l));
    int ans = 0;
    rep(i,k) ans += l[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3576
def calculate_num(index, number, _length, _ways):
    way_list = []
    __ways = _ways

    for i in range(_length - index):
        __ways = __ways/2
        way_list.append(int(__ways))
    way_list[-1] *= 2
    if way_list[-1] == 0:
        way_list[-1] = 1

    result = 0

    for i, way in enumerate(way_list):
        result += number * pow(10, i) * way

    return result


if __name__ == '__main__':
    num = input()
    num_list = [int(i) for i in str(num)]
    length = len(num_list)
    ways = pow(2, length - 1)
    sum_result = 0

    for num, value in enumerate(num_list):
        sum_result += calculate_num(num, value, length, ways)

    print(sum_result)
'''
    "1:1"
    "1:1:2"
    "1:1:2:4 2:2:4 4:4 8"
    "1:1:2:4:8"
    "12345"
'''

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
  ll n;cin>>n;
  vector<string>s(n);
  rep(i,n)cin>>s[i];
  set<string>S;
  rep(i,n)S.insert(s[i]);
  cout<<S.size()<<endl;
}

Measured memory_bytes: 25128
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
#define int long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const int maxn=10005;
int n,a[maxn],head[maxn],cnt,bisheng[maxn];
struct edge
{
	int to,next;
}e[maxn<<1];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		putchar('-');
		putchar('1');
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}
void add(int from,int to)
{
	e[++cnt]=(edge){to,head[from]};
	head[from]=cnt;
}
void dfs(int now,int father)
{
	for(int i=head[now];i;i=e[i].next)
	{
		int to=e[i].to;
		if(to==father)
			continue;
		dfs(to,now);
		if(!bisheng[to]&&a[now]>a[to])
			bisheng[now]=1;
	}
}
signed main()
{
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	for(int i=1;i<n;++i)
	{
		int u=read(),v=read();
		add(u,v),add(v,u);
	}
	for(int i=1;i<=n;++i)
	{
		memset(bisheng,0,sizeof(bisheng));
		dfs(i,0);
		if(bisheng[i])
			write(i),putchar(' ');
	}
    return 0;
}


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

int prime(int x)
{
	if (x == 2)
		return true;

	if (x < 2 || x % 2 == 0)
		return false;

	int i = 3;
	while (i <= sqrt(x))
	{
		if (x%i == 0)
		{
			return false;
		}
		i = i + 2;
	}
	return true;
}

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

	int count = 0;
	int a;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a);
		if (prime(a))count++;
	}
	printf("%d\n", count);
}


Measured memory_bytes: 2668
#include<stdio.h>
int main(){
int a,b,c,d,i;
while(1){
scanf("%d\n",&a);
if(a==0){
break;
}
else{
d=a;
c=a;
for(i=0;i<a;i++){
scanf("%d\n",&b);
if(b==0){
d--;
c--;
}
else if(b==1){
d--;
}
}
scanf("\n");
if(d==0){
printf("NA\n");
}
else{
printf("%d\n",c+1);
}
}
}
return 0;
}




Measured memory_bytes: 2140
local n, m = io.read("*n", "*n")
local cnt, may = {1}, {true}
for i = 2, n do
  cnt[i] = 1
  may[i] = false
end
for i = 1, m do
  local x, y = io.read("*n", "*n")
  if may[x] then may[y] = true end
  cnt[x], cnt[y] = cnt[x] - 1, cnt[y] + 1
  if cnt[x] == 0 then may[x] = false end
end
local ret = 0
for i = 1, n do
  if may[i] then ret = ret + 1 end
end
print(ret)


Measured memory_bytes: 4444
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int n, k;
    string s;
    cin >> n >> k >> s;
    --k;
    Int diff = 'a' - 'A';
    s[k] += diff;
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 3608
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    Ans = 0
    C = 0
    for i in range(1, len(A)):
        C += A[i-1]
        Ans += A[i]*C % (10**9+7)
    print(Ans % (10**9 + 7))
    
resolve()    

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) (int)x.size()
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 105;

int n, w;
unordered_map <int, ll> dp[MAXN];
int cost[MAXN], val[MAXN];
ll sol;

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

  cin >> n >> w;
  REP(i, n)
    cin >> cost[i + 1] >> val[i + 1];

  dp[0][0] = 0;

  FOR(i, 1, n + 1){
    for(auto it : dp[i - 1]){
      if(it.second >= dp[i][it.first]) dp[i][it.first] = it.second;
      ll ncost = cost[i] + it.first;
      ll nval = val[i] + it.second;
      if(ncost <= w && nval > dp[i][ncost]){
        dp[i][ncost] = nval;
      }
    }
  }
  ll sol = 0;
  for(auto it : dp[n])
    sol = max(sol, it.second);
  cout << sol;
}


Measured memory_bytes: 4480
#include<stdio.h>
#include<string.h>
int main()
{
	int a[100001],b[100001],c[100001][4],x,y,z,i;
	scanf("%d%d%d",&x,&y,&z);
	int p1=100000,p2=100000;
	for(i=1;i<=x;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<p1)
		p1=a[i];
	}
	for(i=1;i<=y;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]<p2)
		p2=b[i];
	}
	p1=p1+p2;
	for(i=1;i<=z;i++)
	{
		scanf("%d%d%d",&c[i][1],&c[i][2],&c[i][3]);
		if(a[(c[i][1])]+b[(c[i][2])]-c[i][3]<p1)
		p1=a[(c[i][1])]+b[(c[i][2])]-c[i][3];
	}
	printf("%d",p1);
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <array>
#include <complex>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  ll M;
  cin >> M;
  vector<ll> b(M);
  vector<ll> c(M);
  for(int i = 0; i < M; ++i) {
    cin >> b[i];
  }
  for(int i = 0; i < M; ++i) {
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  vector<ll> s(N + 1);
  s[0] = 0;
  for(int i = 1; i < N + 1; ++i) {
    s[i] = s[i - 1] + a[i-1];
    // cout << "s[" << i << "] = " << s[i] << endl;
  }
  for(int i = 0; i < M; ++i) {
    auto id = upper_bound(a.begin(), a.end(), b[i]) - a.begin();
    // cout << "id = " << id << endl;
    cout << (s[id] >= c[i] ? "Yes" : "No") << endl;
  }
}

Measured memory_bytes: 10236
n, T = map(int,input().split())
t = list(map(int, input().split()))
result = 0
p = t[0]
for i in range(1, n):
    if p+T >= t[i]:
        result += t[i] - p
    else:
        result += T
    p = t[i]
print(result+T)

Measured memory_bytes: 25196
#include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define lim 100010
#define mod 1e9 + 7
#define INF 1e9
#define REP(i, n) for (int i = 0; i < n; i++)

ll GCD(int x, int y){return x%y == 0 ? y : GCD(y, x % y);}

int main() {
  ll N;
  scanf("%lld", &N);
  ll ans = 0;
  ll a = 10;
  if(N%2==0){
    while(a <= N){
      ans += N / a;
      a *= 5;
    }
  }

  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}　これが経路圧縮!!!
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

};
int main(){
  ll n,m;
  cin >> n >> m;
  UnionFind uf(n);
  vector<ll> score(n,0);
  rep(i,m){
    cin >> t1 >> t2;
    t1--,t2--;
    uf.unite(t1,t2);
  }
  rep(i,n){
    score[uf.root(i)]++;
  }
  ll ans = 0;
  rep(i,n){
    chmax(ans,score[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 11880
import java.util.*;

public class Main{
  
  public static void main (String[] args){
    
    Main main = new Main();
    
    main.solve();
  }
  
  private void solve(){
    Scanner scanner = new Scanner(System.in);
    
    int X = scanner.nextInt();
    int T = scanner.nextInt();
    
    double answer;
    
    answer=(double)X/T;
    System.out.println(answer);
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
 
const int INF = (1<<29);
const int dy[4] = {-1,0,1,0};
const int dx[4] = {0,1,0,-1};
int h,w;
 
class state{
public:
  int y,x, up,n,e, cost;
};
 
bool check(int y, int x){
  if(y < 0 || y >= h) return false;
  if(x < 0 || x >= w) return false;
  return true;
}
 
int main(){
  while(cin >> h >> w && (h|w)){
    int a[11][11],b[11][11][6][6][6],gx,gy,ans=INF;
    state u,v;
    queue<state> Q;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> a[i][j];
        for(int k=0;k<6;k++) for(int l=0;l<36;l++) b[i][j][k][l/6][l%6] = INF;
      }
    }
    cin >> u.y >> u.x >> gy >> gx;
    b[u.y][u.x][0][4][2] = 0;
    u.up = 1;
    u.n = 5;
    u.e = 3;
    u.cost = 0;
    Q.push(u);
 
    while(!Q.empty()){
      u = Q.front();
      Q.pop();
 
      if(u.y == gy && u.x == gx){
        ans = min(ans,u.cost);
        continue;
      }
 
      for(int i=0;i<4;i++){
        v = u;
        v.y += dy[i];
        v.x += dx[i];
        if(!check(v.y,v.x)) continue;
        if(i == 0){
          v.up = 7 - u.n;
          v.n = u.up;
        } else if(i == 1){
          v.up = 7 - u.e;
          v.e = u.up;
        } else if(i == 2){
          v.up = u.n;
          v.n = 7 - u.up;
        } else if(i == 3){
          v.up = u.e;
          v.e = 7 - u.up;
        }
        v.cost += a[v.y][v.x] * (7 - v.up);
        if(b[v.y][v.x][v.up-1][v.n-1][v.e-1] > v.cost){
          b[v.y][v.x][v.up-1][v.n-1][v.e-1] = v.cost;
          Q.push(v);
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1344
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
  int N;cin>>N;
  VI A(N);
  VI B(N+1);
  REP(i,N){
    int tmp;
    cin>>tmp;
    tmp=tmp-1-i;
    A[i]=tmp;
  }
  REP(i,N+1){
    B[i]=0;
  }
  int count=0;
  REP(i,N){
    if(A[i]+B[i]!=0){
      B[i+1]=B[i]+1;
      count=count+1;
    }
    else{
      B[i+1]=B[i];

    }
  }
if(count>N-1){
  cout<<-1<<endl;
}
else{
  cout<<count<<endl;
}

}


Measured memory_bytes: 1792
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, M = map(int, input().split())

    ans = min(M//2, (2*N + M)//4)

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>  
#include <iostream>
#include <string>
typedef long long int ll;

using namespace std;

int main() {
  int n;
  cin>>n;
  
  int ans;
 
  vector<int> vec(n);
  for(int i=0; i<n; i++)cin>>vec.at(i);
  
  for(int p=1; p<=100; p++){
    int s=0;
    for(int i=0; i<n; i++){      
     
      s+=(p-vec.at(i)) *(p-vec.at(i));   
    }
    if(p==1)ans=s;
    ans= min(ans,s);
  }
  cout<<ans;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

template <class T>
ostream &operator<<(ostream &s, vector<T> vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        if (i > 0) {
            s << ' ';
        }
        s << vec[i];
    }
    return s << endl;
}

int dfs(int N, int s, const vector<int> num, int now = 0, int pos = 0) {
    if (s == pos) {
        return now;
    }
    int ans = INF;
    for (auto n : num) {
        int d = n;
        for (int i = 0; i < (s - pos - 1); i++) {
            d *= 10;
        }
        int tmp = dfs(N, s, num, now + d, pos + 1);
        if (N <= tmp) {
            chmin(ans, tmp);
        }
    }
    return ans;
}

int main() {
    int N;
    int K;
    cin >> N >> K;
    vector<int> D(K);
    for (int i = 0; i < K; i++) {
        cin >> D.at(i);
    }
    vector<int> num;
    for (int i = 0; i < 10; i++) {
        if (find(ALL(D), i) == D.end()) {
            num.push_back(i);
        }
    }

    int s = to_string(N).size();
    int ans = dfs(N, s, num, 0, 0);
    if (ans != INF) {
        cout << ans << endl;
    } else {
        cout << dfs(N, s + 1, num, 0, 0);
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    int ret = 0;
    for(int i = 0;i < N - 2;i++) {
        for(int j = i + 1;j < N - 1;j++) {
            auto itr = lower_bound(vec.begin(),vec.end(),vec.at(i) + vec.at(j));
            int itr2 = itr - vec.begin();
            itr2--;
            ret += (itr2 - (j + 1) + 1);
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

#枚数
n = int(arr_data[0][0])
#合計
y = int(arr_data[0][1])

chkflg = False

for i in range(0, n+1):

    for j in range(0, n+1):

        if (n-i-j) >= 0 and 10000 * i + 5000 * j + 1000 * (n-i-j) == y:

            print(i,j,(n-i-j))
            chkflg = True
            break
            
    if chkflg:
        
        break

if chkflg == False:
    
    print(-1, -1, -1)

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

int main()
{
    int n;
    double ans = 0;
    cin >> n;
    ans = 1 - (n / 2) / (double)n;
    printf("%.10f\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = __int128_t;
using PLL = P<ll, ll>;

istream& operator >>(istream &stream, ll &a) {
    int64_t b;
    cin >> b;
    a = b;
    return stream;
}

ostream& operator <<(ostream &stream, ll a) {
    auto b = static_cast<int64_t>(a);
    stream << b;
    return stream;
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

class Combination {
private:
    template <typename T> using V = vector<ll>;
    ll N;
    ll MOD;
    V<ll> factv, rfactv;

public:
    /*
     * MOD must be a prime number.
     */
    Combination(ll N, ll MOD)
        : N(N), 
          MOD(MOD),
          factv(N + 1, 1),
          rfactv(N + 1)
    {
        for(ll i = 1; i <= N; i++) {
            factv[i] = factv[i - 1] * i % MOD;
        }
        for(ll i = 0; i <= N; i++) {
            rfactv[i] = pow(factv[i], MOD - 2);
        }
    }

    ll fact(ll n) {
        return factv[n];
    }

    ll rfact(ll n) {
        return rfactv[n];
    }

    ll pow(ll a, ll b) {
        return b ? (b & 1 ? a : 1) * pow(a * a % MOD, b / 2) % MOD : 1;
    }

    ll comb(ll n, ll k) {
        return factv[n] * rfactv[n - k] % MOD * rfactv[k] % MOD;
    }
};

const ll MOD = 1e9 + 7;

int main() {
    init_io();
    Combination comb(3e5, MOD);
    ll B, W;
    cin >> B >> W;
    V<ll> imos(B + W + 10, 0);

    for(ll i = B; i < B + W; i++) {
        ll p = comb.pow(2, i);
        p = comb.pow(p, MOD - 2);
        if(i - 1 >= B - 1) {
            ll v1 = comb.comb(i - 1, B - 1) * p % MOD;
            imos[i - 1] += v1;
            imos[i] -= v1;
        }
        if(i >= 2 && i - 2 >= B - 2 && B - 2 >= 0) {
            ll v2 = comb.comb(i - 2, B - 2) * p % MOD;
            imos[0] += v2;
            imos[i - 1] -= v2;
        }
    }
    for(ll i = W; i < B + W; i++) {
        ll p = comb.pow(2, i);
        p = comb.pow(p, MOD - 2);
        if(i > W && i >= 2 && i - 2 >= W - 1) {
            ll v1 = comb.comb(i - 2, W - 1) * p % MOD;
            imos[0] += v1;
            imos[i - 1] -= v1;
        }
        if(i - 1 >= W - 1) {
            ll v2 = comb.comb(i - 1, W - 1) * p % MOD;
            imos[i] += v2;
        }
    }

    for(ll i = 0; i < B + W; i++) imos[i + 1] += imos[i];
    for(ll i = 0; i < B + W; i++) cout << (imos[i] + (imos[i] < 0 ? MOD * MOD * MOD * MOD : 0)) % MOD << endl;
    return 0;
}


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

#include <bits/stdc++.h>

using namespace std;

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

void d_err() {
    cerr << endl;
}

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

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

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

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

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S;
    cin >> S;

    set<char> s;
    REP(i, S.size()) s.insert(S[i]);

    if(s.size() == 3) print("Yes");
    else print("No");
    
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin >> n >> k;
    vector<ll> a(n),f(n);
    rep(i,0,n){
        cin >> a[i];
    }
    rep(i,0,n){
        cin >> f[i];
    }
    sort(a.begin(),a.end());
    sort(f.begin(),f.end(),greater<ll>());
    ll l=-1,r=INF;
    while(r-l>1){
        ll mid=(l+r)/2;
        ll sum=0;
        rep(i,0,n){
            sum+=max(0LL,a[i]-mid/f[i]);
        }
        if(sum>k){
            l=mid;
        }
        else{
            r=mid;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 6332
#include "stdio.h"
#include "climits"

int day;
int town;
int dis[1001] = {};
int wea[1001] = {};
int dp[1001][1001] = {};

int min(int a, int b) {
	if (a < b)return a;
	return b;
}

int main() {
	scanf("%d %d", &town, &day);
	for (int i = 0; i < town; i++) {
		scanf("%d", &dis[i + 1]);
	}
	for (int i = 0; i < day; i++) {
		scanf("%d", &wea[i + 1]);
	}
	for (int i = 1; i <= town; i++) {
		for (int j = 0; j <= day; j++) {
			dp[i][j] = INT_MAX-10000000;
		}
	}
	for (int i = 1; i <= town; i++) {
		for (int j = 1; j <= day; j++) {
			dp[i][j] = min(dp[i - 1][j - 1] + dis[i] * wea[j], dp[i][j - 1]);
		//	printf("%d??\??????%d?????????????°?????????????%d\n", j, i, dp[i][j]);
		}
	}
	printf("%d\n", dp[town][day]);
	return 0;
}

Measured memory_bytes: 4212
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];

    vector<int> turn(n);
    for(int i = 0; i < n; i++) turn[i] = i;
    double sum = 0;
    int lim = 1;
    for(int i = 1; i <= n; i++) lim *= i;
    for(int i = 0; i < lim; i++){
        double cosum = 0;
        for(int j = 0; j < n-1; j++){
            cosum += sqrt(pow(x[turn[j]]-x[turn[j+1]], 2) + pow(y[turn[j]]-y[turn[j+1]], 2));
        }
        sum += cosum;
        next_permutation(turn.begin(), turn.end());
    }

    printf("%.7f\n", sum/lim);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  ll W, H, N;
  cin >> W >> H >> N;
  vvl sq(W, vl(H, 1));

  ll x, y, a;
  rep(i, N){
    cin >> x >> y >> a;
    
    if(a == 1){
      if(x != 0){
        rep(j, x){
          rep(k, H){
            sq[j][k] = 0;
          }
        }
      }
    } else if(a == 2){
      if(x != W){
        rep2(j, x, W){
          rep(k, H){
            sq[j][k] = 0;
          }
        }
      }
    } else if(a == 3){
      if(y != 0){
        rep(j, y){
          rep(k, W){
            sq[k][j] = 0;
          }
        }
      }
    } else{
      if(y != H){
        rep2(j, y, H){
          rep(k, W){
            sq[k][j] = 0;
          }
        }
      }
    }
  }

  ll cnt = 0;
  
  rep(i, W){
    rep(j, H){
      cnt += sq[i][j];
    }
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

std::vector<int> dp(50, 1);

int fibonacci(int n) {
  if (n < 2)
    return dp.at(n);
  if (dp.at(n) == 1)
    dp.at(n) = fibonacci(n-1) + fibonacci(n-2);
  return dp.at(n);
}

int main() {
  int n;
  std::cin >> n;
  std::cout << fibonacci(n) << std::endl;
}



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

using namespace std;

const int maxn = 1e5+10;

bitset<maxn> bs;

int main(){
	int n,k,r,s,p,ans=0;
	
	string t;

	cin >> n >> k >> r >> s >> p >> t;

	for(int i=0;i<int(t.size()); ++i)
	{
		if(i < k){
			if(t[i] == 'r') ans+=p;
			else if(t[i] == 's') ans+=r;
			else ans+=s;
			bs[i] = 1;
		}
		else{
				if(t[i-k] == t[i] && bs[i-k]) continue;
				if(t[i] == 'r') ans+=p;
				else if(t[i] == 's') ans+=r;
				else if(t[i] == 'p') ans+=s;
				bs[i] = 1;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){

bool N[31]={};int x;
for(int i=0;i<30;i++)
N[i]=false;
for(int i=0;i<28;i++)
{scanf("%d",&x);x=x-1;N[x]=true;}
for(int i=0;i<30;i++)
{if(N[i]==false){int p=i+1;printf("%d\n",(p));}}
return 0;
}

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

typedef long long int ll;

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

	ll n, temp;
	ll sum(0);
	cin >> n;

	vector<int> num;
	num.assign(100001, 0);

	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		num[temp]++;
		sum += temp;
	}

	ll q, bb, cc;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		cin >> bb >> cc;
		sum -= num[bb] * bb;
		sum += num[bb] * cc;
		num[cc] += num[bb];
		num[bb] = 0;
		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
const int maxn = 310000;
vi e[maxn];
int d[maxn][2], dup[maxn];
int rad[maxn];
int dth[maxn];
string s;
 
void add(int *m, int x) {
    forn(i, 2) if (x > m[i]) swap(x, m[i]);
}
 
int max_exc(int *m, int x) {
    forn(i, 2) {
        if (m[i] == x) x = -1;
        else return m[i];
    }
    return -1;
}
 
void dfs_d(int v, int p) {
    for (int u: e[v]) {
        if (u == p) continue;
        dfs_d(u, v);
        add(d[v], max_exc(d[u], -1) + 1);
    }
}
 
void dfs_up(int v, int p, int D) {
    dup[v] = D;
    for (int u: e[v]) {
        if (u == p) continue;
        dfs_up(u, v, max(D, max_exc(d[v], d[u][0] + 1) + 1) + 1);
    }
}
 
i64 ans;
 
int dfs_C(int v, int p) {
    dth[v] = 0;
    int minq = s[v] == '1' ? 0 : 1e9;
    for (int u: e[v]) {
        if (u == p) continue;
        uin(minq, dfs_C(u, v) - 1);
        uax(dth[v], dth[u] + 1);
    }
    int sk = max(0, min(rad[v] - 1, dth[v] + 1) - minq + 1);
    //uin(sk, rad[v] - 1);
    ans += sk;
    minq += sk;
    if (minq == rad[v]) minq = 1e9;
    return minq;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif
 
    int n;
    cin >> n;
    forn(i, n - 1) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        e[x].pb(y);
        e[y].pb(x);
    }
    cin >> s;
    forn(i, n) forn(j, 2) d[i][j] = -1;
    dfs_d(0, -1);
    dfs_up(0, -1, -1e9);
    forn(i, n) rad[i] = max(dup[i], max_exc(d[i], -1) + 1);
    int C = 0;
    forn(i, n) if (rad[i] < rad[C]) C = i;
    ans = 1;
    dfs_C(C, -1);
    cout << ans << '\n';
 
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Measured memory_bytes: 27536
MOD = 1000000007
n = int(input())
a = [int(_) for _ in input().split()]
p = [0] * (n + 1)
for i in range(n - 1, -1, -1):
    p[i] = p[i + 1] + a[i]
ans = 0
for i in range(n):
    add = a[i] * (p[i] - a[i])
    add = add % MOD
    ans += add
    ans = ans % MOD
print(ans)


Measured memory_bytes: 105244
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

template <typename T> void max_self(T& a, T b) {
    a = max(a, b);
}

// dp[n][m]

bool first_row_or_column(pair<int,int> p) {
    return p.first == 0 || p.second == 0;
}

const int INF = 1e9 + 5;

int main() {
    string a, b;
    cin >> a >> b;
    vector<vector<pair<int,pair<int,int>>>> dp(a.length() + 1,
        vector<pair<int,pair<int,int>>>(b.length() + 1, {-INF,{0,0}}));
    dp[0][0] = {0, {0,0}};
    // dp[i][j] - the max total length so far
    for(int i = 0; i < (int) a.length(); ++i) {
        for(int j = 0; j < (int) b.length(); ++j) {
            if(a[i] == b[j]) {
                max_self(dp[i+1][j+1], make_pair(dp[i][j].first + 1, make_pair(i,j)));
            }
            max_self(dp[i+1][j], make_pair(dp[i][j].first, make_pair(i,j)));
            max_self(dp[i][j+1], make_pair(dp[i][j].first, make_pair(i,j)));
        }
    }
    pair<int,pair<int,int>> answer = {0,{0,0}};
    for(int i = 0; i <= (int) a.length(); ++i) {
        for(int j = 0; j <= (int) b.length(); ++j) {
            max_self(answer, make_pair(dp[i][j].first, make_pair(i, j)));
        }
    }
    string s;
    pair<int,int> cur = answer.second;
    while(!first_row_or_column(cur)) {
        int i = cur.first;
        int j = cur.second;
        pair<int,int> previous = dp[i][j].second; // a cell from which we came to (i,j)
        debug() << imie(cur) imie(previous);
        if(previous == make_pair(i - 1, j - 1)) {
            assert(a[i-1] == b[j-1]);
            s += a[i-1];
        }
        cur = previous;
    }
    //~ debug() << answer;
    reverse(s.begin(), s.end());
    cout << s << endl;
}


Measured memory_bytes: 106112
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        PriorityQueue<Integer> q = new PriorityQueue<>(new Comparator<Integer>() {
            @Override public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        for(int i=0; i<n; i++) {
            q.add(sc.nextInt());
        }
        for(int i=0; i<m; i++) {
            int p = q.poll();
            q.add(p/2);
        }

        long res = 0;
        while(!q.isEmpty()) {
            res += q.poll();
        }

        System.out.println(res);
    }

}


Measured memory_bytes: 60456
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  int N,sum;
  cin >> N;
  
  for(int i=0;i<N;i++){
    int r,l;
    cin >> r >> l;
    sum+=l-r+1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
std::vector<int>a;
char s[maxn],ans[5];
int n,pos;
bool query(std::vector<int>a)
{
	printf("? ");
	for(int i=0;i<n-1;i++)
		writesp(a[i]);
	writeln(a[n-1]);
	fflush(stdout);
	scanf("%s",ans);
	return ans[0]=='R';
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a.push_back(i);
	if(query(a)){
		int l=1,r=n;
		while(l<r){
			int mid=(l+r)>>1;
			a.clear();
			for(int i=mid+1;i<=mid+n;i++)
				a.push_back(i);
			if(query(a))l=mid+1;
			else r=mid;
		}
		s[l]='R'; s[l+n]='B';
		pos=l;
	}
	else{
		int l=1,r=n;
		while(l<r){
			int mid=(l+r)>>1;
			a.clear();
			for(int i=mid+1;i<=mid+n;i++)
				a.push_back(i);
			if(!query(a))l=mid+1;
			else r=mid;
		}
		s[l]='B'; s[l+n]='R';
		pos=l;
	}
	a.clear();
	for(int i=pos+1;i<pos+n;i++)
		a.push_back(i);
	for(int i=1;i<=2*n;i++)
		if(i<pos||i>pos+n){
			a.push_back(i);
			if(query(a))s[i]='R';
			else s[i]='B';
			a.pop_back();
		}
	a.clear();
	for(int i=1;i<=2*n;i++)
		if(i<pos||i>pos+n)a.push_back(i);
	for(int i=pos+1;i<pos+n;i++){
		a.push_back(i);
		if(query(a))s[i]='R';
		else s[i]='B';
		a.pop_back();
	}
	printf("! %s\n",s+1);
}

Measured memory_bytes: 724
#include<stdio.h>

int main(void)
{
  
  int n,k,i;
  i=0;
  int *box;
  scanf("%d",&n);
  box=calloc(n,sizeof(int));
  for(k=0;k<n;k++)
  {
    scanf("%d",&box[k]);
  }
  
  for(k=0;k<n;k=k+2)
  {
    if(box[k]%2==1)
    {
      i=i+1;
    }
  }
  printf("%d",i);
  return 0;
}

Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string str;
  cin >> str;
  if (str[0]==str[1] && str[1]==str[2] && (str[2]=='A' || str[2]=='B')){
    cout<<"No"<<endl;
    return 0;
  }
  cout <<"Yes" <<endl;
}

Measured memory_bytes: 256