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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10, m = 10000;
int f[nax];

inline int g (int x, int y, int z) {
    return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main () {

    for (int x = 1 ; x <= 100 ; ++ x)
    for (int y = 1 ; y <= 100 ; ++ y)
    for (int z = 1 ; z <= 100 ; ++ z) {
        f[g(x, y, z)] ++ ;
    }

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

    for (int i = 1 ; i <= n ; ++ i)
        printf("%d\n", f[i]);

}
/*
    Good Luck
        -Lucina
*/


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

class Program
{
    static int sum;
    static void Main(string[] args)
    {
        int[] arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int rest = arr[0] - Console.ReadLine().Split(' ').Select(v => int.Parse(v)).Sum();
        Console.WriteLine(rest >= 0 ? rest : -1);
        


    }

  

 
   



}



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

signed main(){
  string S;
  cin>>S;
  int SS=S.size()-1;
  if(S[SS]=='s')S+="es";
  else S+='s';
  cout<<S<<endl;
  return 0;
}

Measured memory_bytes: 3596
import Control.Monad
import Data.Maybe
import Control.Monad.ST
import Data.List
import Data.Array
import Data.Array.ST
import qualified Data.ByteString.Char8 as B

main = do
  let a = buildSum (sieve 100000)
  q <- readLn
  forM_ [1..q] $ \_ -> do
    [l, r] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    print $ a!(r+1) - a!l

sieve :: Int -> Array Int Bool
sieve n = runST $ do
  a <- newArray (0, n) True :: ST s (STUArray s Int Bool)
  writeArray a 0 False
  writeArray a 1 False
  forM_ [2..n] $ \i -> do
    x <- readArray a i
    when x $ do
      forM_ [i*2, i*3 .. n] $ \j -> writeArray a j False
  freeze a

buildSum :: Array Int Bool -> Array Int Int
buildSum s = let n = length s - 1
             in listArray (0, n+1) . scanl (+) 0 . map (\i -> if s!i && s!((i+1)`div`2) then 1 else 0) $ [0..n]


Measured memory_bytes: 24316
N,M,X=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
ANS=[]
now=[0]*(M+1)
i=0
j=0
def choice(now,A,i,N,ANS):
    if i==N-1:
        add=[x+y for (x,y) in zip(now,A[i])]
        ANS.append(now)
        ANS.append(add)
    else:
        add=[x+y for (x,y) in zip(now,A[i])]
        choice(now,A,i+1,N,ANS)
        choice(add,A,i+1,N,ANS)

choice(now,A,i,N,ANS)
ans=1200001
for i in range(len(ANS)):
    for j in range(1,M+1):
        if ANS[i][j]<X:
            break
    else:
        ans=min(ans,ANS[i][0])
if ans==1200001:
    ans=-1
print(ans)

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(V),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	cout << int(k*pow(k-1, n - 1)) << endl;
	return 0;
}


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

using namespace std;

int main(void){
  int line_length;
  cin>>line_length;
  string str;
  getline(cin, str);

  for(int i=0;i<line_length;++i){
    string input;
    getline(cin,input);
    std::string::size_type pos;
    while(( pos = input.find("Hoshino")) != std::string::npos){
      input.replace(pos, 7, "Hoshina");
    }
    cout << input<<endl;
  }
  return 0;
}



Measured memory_bytes: 3144
#include<stdio.h>

int main(){
	int h,w,i,j;
	while(scanf("%d %d",&h,&w),h!=0 && w!=0){
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}
template <typename T>
T modpow(T x, T n, T m) {
  if (n == 0) return 1;
  if (n % 2 == 0) {
    return modpow(x * x % m, n / 2, m);
  } else {
    return x * modpow(x, n - 1, m) % m;
  }
}

template <typename T>
T modinv(T a, T m) {
  T b = m, u = 1, v = 0;
  while (b != 0) {
    const auto t = a / b;
    a -= t * b;
    std::swap(a, b);
    u -= t * v;
    std::swap(u, v);
  }
  u %= m;
  if (u < 0) {
    u += m;
  }
  return u;
}

int main() {
  int64_t q;
  std::cin >> q;
  constexpr int64_t mod = 1000003;

  std::vector<int64_t> f(mod), f_inv(mod);
  f[0] = 0;
  f[1] = 1;
  f_inv[0] = 1;
  f_inv[1] = modinv(f[1], mod);

  for (int64_t i = 2; i < mod; i++) {
    f[i] = f[i - 1] * i;
    f[i] %= mod;
    f_inv[i] = modinv(f[i], mod);
  }

  for (int64_t i = 0; i < q; i++) {
    int64_t x, d, n;
    std::cin >> x >> d >> n;

    if (d == 0) {
      std::cout << modpow(x, n, mod) << std::endl;
    } else {
      const auto x_c = (x * modinv(d, mod)) % mod;
      if (x_c == 0) {
        std::cout << 0 << std::endl;
      } else if (mod < x_c + n) {
        std::cout << 0 << std::endl;
      } else {
        const auto start = x_c;
        const auto end = x_c + n - 1;
        const auto v = (f[end] * f_inv[start - 1]) % mod;
        std::cout << (modpow(d, n, mod) * v) % mod << std::endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 18048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int k;
    cin >> k;

    queue<ll> q;
    for (ll i = 1; i < 10; i++) {
        q.push(i);
    }

    while (1) {
        ll t = q.front(); q.pop();
        if (--k == 0) {
            cout << t << endl;
            break;
        }
        ll d = t % 10;
        ll s = t * 10 + d;
        if (d != 0) q.push(s - 1);
        q.push(s);
        if (d != 9) q.push(s + 1);
    }

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,x,y,p;
    cin>>n>>k>>x>>y;

    if(n>k)
    {
        p=k*x+y*(n-k);
    }
    else
    {
        p=x*n;
    }
    cout<<p<<endl;

    return 0;
}


Measured memory_bytes: 3608
n,m=map(int,input().split())
a=[[int(x) for x in input().split()] for _ in range(n)]
d={i:0 for i in range(m)}
for i in range(n):
    k=a[i][0]
    for j in range(k):
        d[a[i][j+1]-1] += 1
cnt=0
for key in d:
    if d[key] == n:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
// 正四角錐の表面積の公式
// 底辺＊√（４＊高さ＊高さ＋底辺＊底辺）＋底辺＊底辺

#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(void){

  double x,h;
  while( cin >> x >> h , x || h ){
    double ans = x * sqrt( 4 * h * h + x * x ) + x * x;
    printf("%.6f", ans);
    cout << endl;

  }
  return 0;
}

Measured memory_bytes: 1264
import sys
N = int(input())


sys.setrecursionlimit(1000000)

plist = []


def dfs(p):
    if len(set(p)) == 3:
        plist.append(int(''.join(map(str, p))))
    if len(p) == 9:
        return
    dfs(p+[3])
    dfs(p+[5])
    dfs(p+[7])


dfs([])

ans = 0
for p in plist:
    if int(p) <= N:
        ans += 1
print(ans)


Measured memory_bytes: 4172
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef struct point
{
	int x,y;
	bool operator < (const struct point & t)const
	{
		return x==t.x?y<t.y:x<t.x;
	}
}POINT,*PPOINT;
int w,h;
POINT arr[200010];
long long fac[200010],rev[200010],f[200010];
void init()
{
	int i;
	fac[0]=fac[1]=rev[0]=rev[1]=1;
	for(i=2;i<=h+w-2;i++)
	{
		fac[i]=fac[i-1]*i%MOD;
		rev[i]=(MOD-MOD/i)*rev[MOD%i]%MOD;	
	}
	for(i=2;i<=h+w-2;i++)
		rev[i]=rev[i-1]*rev[i]%MOD;	
}
int main()
{
	int i,j,n;
	scanf("%d %d %d",&h,&w,&n);
	for(i=0;i<n;i++)
		scanf("%d %d",&arr[i].x,&arr[i].y);
	arr[n].x=h;
	arr[n].y=w;
	sort(arr,arr+n+1);
	init();
	for(i=0;i<=n;i++)
	{
		f[i]=fac[arr[i].x+arr[i].y-2]*rev[arr[i].x-1]%MOD*rev[arr[i].y-1]%MOD;
		//printf("%d %d\n",i,f[i]);
		for(j=0;j<i;j++)
		{
			f[i]=(f[i]-f[j]*fac[arr[i].x-arr[j].x-arr[j].y+arr[i].y]%MOD*rev[arr[i].x-arr[j].x]%MOD*rev[arr[i].y-arr[j].y]%MOD);
		}
		f[i]=(f[i]+MOD)%MOD;
	}
	printf("%lld\n",(f[n]+MOD)%MOD);
	return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<map>
#include<vector>
#include<queue>

#define F first
#define S second

using namespace std;

typedef pair<int,int> P;
int sx, sy;
int n;
vector<P> s;
queue<P> que;

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

bool bfs(void){
  while(que.size()) que.pop();
  que.push(P(sx,sy));

  int d[11][11];

  for(int i = 0;i < 11; i++)
    for(int j = 0;j < 11; j++) d[i][j] = -1;

  d[sy][sx] = 0;

  while(que.size()){
    P p = que.front(); que.pop();
    if(d[p.S][p.F] == n) return true;
    
    for(int i = 0;i < 12; i++){
      int nx = p.F + dx[i], ny = p.S + dy[i];
     
      if(nx < 0 || ny < 0 || nx >= 10 || ny >= 10) continue;
      if(d[ny][nx] != -1) continue;
      
      int x = d[p.S][p.F];
      if(s[x].F-1 <= nx && nx <= s[x].F+1 && s[x].S-1 <= ny && ny <= s[x].S+1){
	d[ny][nx] = x + 1;
	que.push(P(nx,ny));
      }
    }
  }
  return false;
}

int main(void){

  for( ; ; ){
    cin >> sx >> sy;
    if(!sx && !sy) break;

    cin >> n;
    s.clear();
    for(int i = 0;i < n; i++){
      P p;
      cin >> p.F >> p.S;
      s.push_back(p);
    }

    bool t = bfs();
    cout << (t? "OK" : "NA") << endl;
  }
}


Measured memory_bytes: 1192
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let mut a: Vec<i32> = readnc();
    for i in 0..n {
        a[i] -= (i+1) as i32;
    }
    a.sort();

    let c = n/2;
    let mut ans: i64 = 0;
    for i in 0..n {
        ans += (a[i]-a[c]).abs() as i64;
    }

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



Measured memory_bytes: 8444
l = list(input())
unique_l = list(set(l))
err = False

if len(unique_l) == 2:
    for s in unique_l:
        if l.count(s) != 2:
            err = True
            break
else:
    err = True

if not err:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
 
function main(input) {
  var temp = input.split(' ');
  var a = parseInt(temp[0]);
  var b = parseInt(temp[1]);
  var c = parseInt(temp[2]);
  if (a < b && b < c) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}

main(x);


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

int main(){
  int N, x;
  cin >> N;
  for(int i = 0;i < N; i++){
    string S;
    cin >> S;
    if (S == "Y"){
      x += 1;
    }
  }
  if (x == 0){
  cout << "Three" <<endl;
  }
  else {
    cout << "Four" <<endl;
  }
}

Measured memory_bytes: 256
n, k, q = map(int, input().split())
src = [int(input()) for _ in range(q)]
base = k-q
lis = [base]*n
#print(lis)
#[0, 0, 0, 0, 0, 0]
for s in src:
    lis[s-1] += 1
for l in lis:
    print('Yes' if l>0 else 'No')

Measured memory_bytes: 10472
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main() {
	string s;
	int w;
	cin >> s >> w;

	string getWord = "";

	for (int i = 0; i < s.length(); i++) {
		if (s.length() <= i * w) {
			break;
		}
		getWord.push_back(s[i * w]);
	}

	cout << getWord << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int rates[200000];

int main() {
  int n;

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    std::cin >> rates[i];
  }

  int baseline = rates[0];
  int max = -1500000000;
  int sum = 0;
  for (int i = 1; i < n; i++) {
    int current_value = rates[i];
    sum += current_value - rates[i - 1];
    if (sum > max) max = sum;
    if (current_value < baseline) {
      baseline = current_value;
      sum = 0;
    }
  }

  std::cout << max << std::endl;

  return 0;
}


Measured memory_bytes: 3876
import java.util.Scanner;
public class Main {
	
	static int a;
	static int b;
	static int q;
	static long []s;
	static long []t;
	static long []x;
	static long [][]aa;
	static long [][]bb;
	static long []ans;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		 a = Integer.parseInt(sc.next());
		 b = Integer.parseInt(sc.next());
		 q = Integer.parseInt(sc.next());
		
		
		 s = new long [a+2];
		 t = new long [b+2];
		 x = new long [q];
		
		for(int i = 1 ;i <= a ; i++) {
			s[i] = Long.parseLong(sc.next());
		}
		for(int i = 1; i <= b ;i++) {
			t[i] = Long.parseLong(sc.next());
		}
		for(int i = 0 ; i < q ;i++) {
			x[i] = Long.parseLong(sc.next());
		}
		s[0] = -100000000000000L;
		s[a+1] = 1000000000000000L;
		t[0] = s[0];
		t[b+1] = s[a+1];
		aa = new long [q][2];
		bb = new long [q][2];
		
		ans = new long [q];
		
		solve();
		
		for(int i = 0 ;i < q ;i++) {
			System.out.println(ans[i]);
		}
		
	}
	
	static void solve() {
		
		for(int i = 0 ;i < q ;i++) {
			int Amax = a+1;
			int Amin = 0;
			int Bmax = b+1;
			int Bmin = 0;
			
			boolean flag1 = false;
			boolean flag2 = false;
		while(Amax - Amin > 1) {
			
			int mid = (Amax + Amin)/2;
			
			if(s[mid] == x[i]) {
				flag1 = true;
				break;
			}
			else if(s[mid] <x[i]) {
				Amin = mid;
			}
			else {
				Amax = mid;
			}
		}
		if(flag1) {
			aa[i][0] = 0;
			aa[i][1] = 0;
		}
		else {
		aa[i][0] = s[Amax] - x[i];
		aa[i][1] = s[Amin] - x[i]; 
		}
		
		while(Bmax - Bmin > 1) {
			
			int mid = (Bmax + Bmin)/2;
			
			if(t[mid] == x[i]) {
				flag2 = true;
				break;
			}
			else if(t[mid] < x[i]) {
				Bmin = mid;
			}
			else {
				Bmax = mid;
			}
		}
		if(flag2) {
			bb[i][0] = 0;
			bb[i][0] = 0;
		}
		
		else {
		bb[i][0] = t[Bmax] - x[i];
		bb[i][1] = t[Bmin] - x[i];
		}
		
		long temp = 2000000000000000000L;
		
		for(int j = 0 ;j <= 1 ; j++) {
			for(int k = 0 ;k <= 1 ;k++) {
				if((aa[i][j] > 0 && bb[i][k] > 0)||(aa[i][j] < 0 && bb[i][k] < 0)) {
					long a = Math.abs(aa[i][j]);
					long b = Math.abs(bb[i][k]);
					temp = Math.min(temp, Math.max(a, b));
				}
				else {
					long a = Math.abs(aa[i][j]);
					long b = Math.abs(bb[i][k]);
					
					long temp1 = Math.max(a, b) + Math.min(a, b) * 2;
					temp1 = Math.abs(temp1);
					temp = Math.min(temp,temp1);
				}
			}
		}
		
		ans[i] = temp;
		
			}
			
		}
	
	

}


Measured memory_bytes: 75960
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int dp[123456];
int n,a,b,now;

main(){
	cin>>n>>a>>b;
	int x[n];
	rep(i,n)cin>>x[i];
	now=x[0];
	rep(i,n){
		dp[i+1]=min(dp[i]+a*(x[i+1]-x[i]),dp[i]+b);
	}
	dump(dp[n-1]);
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui; 
int main() {
	int i, j;
	int T[200001] = {};
	int cT[30][200001];
	for (i = 0; i < 30; i++) {
		for (j = 0; j < 200001; j++) {
			cT[i][j] = 0;
		}
	}
	int n, C, s, t, c;
	cin >> n >> C;
	for (i = 0; i < n; i++) {
		cin >> s >> t >> c; c--;
		cT[c][2 * s-1] = 1;
		cT[c][2 * t] = -1;
	}
	for (i = 0; i < C; i++) {
		for (j = 1; j < 200001; j++) {
			cT[i][j] += cT[i][j - 1];
			if (cT[i][j] > 0)T[j]++;
		}
	}
	int ma = 0;
	for (i = 0; i < 200001; i++) {
		ma = max(ma, T[i]);
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 24448
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long a = sc.nextInt();
			long b = sc.nextInt();
			long c = sc.nextInt();
 
			if (a == b) 
				System.out.println(c);
			else if(b == c) 
				System.out.println(a);
			else
				System.out.println(b);
		}
	}
}

Measured memory_bytes: 22100
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
	//file();
	fast();
	int x; cin >> x;
	int ans = x / 500 * 1000;
	ans += ((x % 500) / 5 * 5);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<int> to;

int detect_loop(const int cur, vector<bool> &visited) {
    if (visited[cur]) {
        return cur;
    }
    visited[cur] = true;
    return detect_loop(to[cur], visited);
}

int main(void) {
    int N;
    ll K;
    cin >> N >> K;

    to.resize(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        a--;
        to[i] = a;
    }

    int loop_start;
    {
        vector<bool> visited(N, false);
        loop_start = detect_loop(0, visited);
    }
    // printf("loop_start: %d\n", loop_start);

    // 0 -> 5 -> 1 for sample2
    vector<int> vs_till_loop;
    {
        int cur = 0;
        while (cur != loop_start) {
            vs_till_loop.push_back(cur);
            cur = to[cur];
        }
    }
    vs_till_loop.push_back(loop_start);
    // for (auto x : vs_till_loop) {
    //     cout << x << " ";
    // }
    // cout << endl;

    // 1 -> 4 -> 2 for sample1
    vector<int> vs_in_loop;
    vs_in_loop.push_back(loop_start);
    {
        int cur = to[loop_start];
        while (cur != loop_start) {
            vs_in_loop.push_back(cur);
            cur = to[cur];
        }
    }
    // for (auto x : vs_in_loop) {
    //     cout << x << " ";
    // }
    // cout << endl;

    const int steps_till_loop = (int) vs_till_loop.size() - 1;
    if (K <= steps_till_loop) {
        cout << vs_till_loop[K] + 1 << endl;
    } else {
        cout << vs_in_loop[(K - (steps_till_loop)) % ((int) vs_in_loop.size())] + 1 << endl;
    }

    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int sum = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == '1') sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
using namespace std;

int main(){
    string word,text;
    cin >> word;
    int count = 0;
    while(cin >> text && text!="END_OF_TEXT"){
        for(int i = 0;i<text.size();i++){
            if(text[i]>='A' && text[i]<='Z'){
                text[i]+=32;
            }
        }
        if(text==word){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3236
# -*- coding: utf-8 -*-
N = int(input())
W_list = list(map(int, input().split()))

lr_sum = 0
for _ in range(N):
    if lr_sum <= 0:
        lr_sum += W_list.pop(0)
    else:
        lr_sum -= W_list.pop(-1)
print(abs(lr_sum))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
//#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MP make_pair
#define PB push_back
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> PII;
const int N= 1e5 +10;
vector<PII> mi;
int x[N], y[N],n;
int sgn(int x){if (x==0) return 0; return x<0 ? -1 :1;}
bool vis[N];
struct cmplf{
	bool operator()(int a,int b){return x[a] < x[b];}
};
struct cmpri{
	bool operator()(int a, int b){return y[a] > y[b];}
};
LL Solve();

int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	scanf("%d", &n);
	for (int i=0; i<n; i++) scanf("%d%d", &x[i], &y[i]);
	
	LL ans= Solve();
	for (int i=0; i<n; i++){
		swap(x[i], y[i]);
		x[i]=-x[i]; y[i]=-y[i];
	}
	ans= max(ans, Solve());
	
	printf("%lld\n", ans);
	return 0;
}
LL Solve(){
	priority_queue<int, vector<int> , cmplf>lf;
	priority_queue<int, vector<int> , cmpri>ri; 
	
	LL pos=0,dis=0;
	for (int i=0; i<n; i++) lf.push(i), ri.push(i);
	#ifdef che
	debug("lf.top()=%d\nri.top()=%d\n", lf.top(), ri.top());
	#endif
	memset(vis, 0 ,sizeof(vis));
	for (int cur=0; ; cur^=1){
		if ( !cur){ //lef point on right
			while (lf.size() && vis[lf.top()]) lf.pop();
			if ( !lf.size()) break;
			int i= lf.top();
			vis[i] = true;lf.pop(); 
			#ifdef che
			debug("cur= %d pick i=%d\n", cur, i);
			#endif
			if( x[i] <= pos) break;
			dis+= x[i]-pos; pos= x[i];
		}	else{
			while (ri.size() && vis[ri.top()]) ri.pop();
			if ( !ri.size()) break;
			int i= ri.top();
			vis[i] = true; ri.pop();
			#ifdef che
			debug("cur= %d, pick i= %d\n", cur, i);
			#endif
			if ( y[i] >= pos) break;
			dis += pos-y[i]; pos=y[i];
		}
		#ifdef che
		debug("dis= %lld \t, pos=%d\n", dis, pos);
		#endif
	}
	return dis + abs(pos);
}

Measured memory_bytes: 2404
using System;
using System.Collections.Generic;

class AGC_034_B
{
    static void Main(string[] args)
    {
        char[] S = Console.ReadLine().ToCharArray();

        if(S.Length<3)
        {
            Console.WriteLine(0);
            return;
        }

        List<char> ns = new List<char>();
        for (int i = 0; i < S.Length; i++)
        {
            char c1 = S[i];

            if(c1=='B')
            {
                if (i+1 < S.Length)
                {
                    char c2 = S[i+1];
                    if (c2 == 'C')
                    {
                        ns.Add('D');
                        i++;
                    }
                    else
                    {
                        ns.Add(c1);
                    }
                }
                else
                {
                    ns.Add(c1);
                }
            }
            else
            {
                ns.Add(c1);
            }
        }

        char[] newS = ns.ToArray();
        long ans = 0;
        long counter = 0;
        for (int i = newS.Length-1; i>=0 ; i--)
        {
            if (newS[i] == 'D')
            {
                counter++;
            }
            else if (newS[i] == 'A')
            {
                ans += counter;
            }
            else
            {
                counter = 0;
            }
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13536
import Foundation

let main: () = {
    let K = getInt()
    var ans = 0
    for a in 1...K {
    for b in 1...K {
    for c in 1...K {
        ans += gcd(gcd(a, b), c)
    }}}
    print(ans)
}()

func gcd(_ a: Int, _ b: Int) -> Int { (b > 0) ? gcd(b, a % b) : a }

func getString() -> String { readLine()! }
func getInt() -> Int { Int(getString())! }
func getDouble() -> Double { Double(getString())! }



Measured memory_bytes: 13220
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main(){
  vector<vector<int>> time(5,vector<int>(2));
  int min_time = 0;
  int counter = 0;
  int min = 10;
  int min_i = 10;

  for(int i = 0;i < 5;i++){
    cin >> time[i][0]; 
    time[i][1] = i;
    int j = time[i][0] % 10;
    if(min > j && j != 0){
      min = j;
      min_time = time[i][0];
      min_i = i;
    }
  }
  
  for(int i =0;i < 5;i++){
    if(time[i][1] != min_i){
      int j = 0;
      if(time [i][0] % 10 != 0){
      j = ((time[i][0] / 10) + 1 ) * 10;
      }else j = time[i][0];
      counter += j;
    }else counter += min_time;
  }

  cout << counter << endl;
  

}


Measured memory_bytes: 256
//atcoder clange
#include <stdio.h>

int main(void){
    int N,K;
    int i,j,k,n;
      scanf("%d", &N);//数値の取得
      scanf("%d", &K);//数値の取得
    if(K == 1){
		printf("0");
      return 0;
    }
  
  int ans = 0;
  ans = N -K;
    printf("%d",ans);
    return 0;
    
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int W = sc.nextInt();
    int[][] weightAndValues = new int[N][2];
    for (int i = 0; i < N; i++) {
      weightAndValues[i][0] = sc.nextInt();
      weightAndValues[i][1] = sc.nextInt();
    }
    long ans = solve(weightAndValues, N, W);
    System.out.println(ans);
  }

  private static long solve(int[][] weightAndValues, int n, int w) {
    long[] dp = new long[w + 1];
    for (int i = 0; i < n; i++) {
      for (int j = w - weightAndValues[i][0]; j >= 0; --j) {
        dp[j + weightAndValues[i][0]] =
            Math.max(weightAndValues[i][1] + dp[j], dp[j + weightAndValues[i][0]]);
      }
    }
    long max = Integer.MIN_VALUE;
    for (int i = 0; i <= w; i++) {
      max = Math.max(max, dp[i]);
    }
    return max;
  }
}


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

using namespace std;

const int MAX_N = 5e2 + 10;

int N, Ans;
int level[MAX_N][MAX_N], obst[MAX_N][MAX_N];

bool setmin(int &x, int y) { return x > y ? x = y, true : false; }

void update(int x, int y) {
    if (setmin(level[x][y - 1], level[x][y] + obst[x][y - 1])) {
        update(x, y - 1);
    }
    if (setmin(level[x][y + 1], level[x][y] + obst[x][y + 1])) {
        update(x, y + 1);
    }
    if (setmin(level[x - 1][y], level[x][y] + obst[x - 1][y])) {
        update(x - 1, y);
    }
    if (setmin(level[x + 1][y], level[x][y] + obst[x + 1][y])) {
        update(x + 1, y);
    }
}

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            level[i][j] = min(min(i, N + 1 - i), min(j, N + 1 - j));
            obst[i][j] = 1;
        }
    }
    for (int i = 1; i <= N * N; i++) {
        int p; scanf("%d", &p);
        int x = (p - 1) / N + 1, y = (p - 1) % N + 1;
        obst[x][y] = 0;
        level[x][y] = min(min(level[x - 1][y], level[x + 1][y]), min(level[x][y - 1], level[x][y + 1]));
        Ans += level[x][y];
        update(x, y);
    }
    printf("%d\n", Ans);
}


Measured memory_bytes: 25044
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	sort(all(s));
	cout<< (s=="abc"?"Yes":"No")<<endl;
}






Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<malloc.h>
#include<math.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, a[100100];

int partition(int A[], int p, int r){
    int x = A[r];
    int i = p - 1;
    for(int j = p; j < r; j++){
        if(A[j] <= x){
            i++;
            if(i != j)swap(a[i], a[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

signed main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    int q = partition(a, 0, N - 1);
    for(int i = 0; i < N; i++){
        if(i == q)printf("[%d]", a[i]);
        else printf("%d", a[i]);
        if(i < N - 1)printf(" ");
    }
    printf("\n");

    return 0;
}

/*

*/


Measured memory_bytes: 3500
import java.util.*;
 
public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    String N = sc.next();
    int count = 0;
    char[] x = new char[N.length()];

    for(int i = 0 ; i < N.length() ; i ++){
      x[i] = N.charAt(i);
      if(i != 0){
        count = ((x[i] != x[i - 1]) )  ? count + 1 : count + 0;
      }
      
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 26476
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}


int main(){
	desperate_optimization(10);
	int A,B;
	cin>>A>>B;
	if(A == 0) {
		B += B/100;
		if(B % 100 == 0) B++;
		cout<<B<<endl;
	}
	else if(A == 1) {
		B *= 100;
		B += B/ 10000 * 100;
		if(B % 10000 == 0) B+=100;
		cout<<B<<endl;
	}
	else {
		B *= 10000;
		B += B/ 1000000 * 10000;
		if(B % 1000000 == 0) B+=10000;
		cout<<B<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a[7], b[7], i;

  for (i = 0; i < 7; i++)
    scanf("%d %d", &a[i], &b[i]);

  for (i = 0; i < 7; i++)
    printf("%d\n", a[i] - b[i]);

  return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int a,cal=0;
int main()
{
	int N;
	cin>>N;
	for(int i=1;i<=N;i++)
	{	
		cin>>a;
		if(a&1)cal++;
	}	
	if(cal&1)cout<<"NO";
	else cout<<"YES";
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int a,b,c,d;
        a = int.Parse(Console.ReadLine());
        b = int.Parse(Console.ReadLine());
        c = int.Parse(Console.ReadLine());
        d = int.Parse(Console.ReadLine());

        int count = 0;

        for(int i= 0;i <= a; i++)
        {
            for(int j = 0;j<=b;j++)
            {
                for(int k=0; k<=c;k++)
                {
                    if ((i * 500 + j * 100 + k * 50) == d)
                    {
                        count++;
                    }
                }
            }
        }

        //標準入力
        //string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
        //b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
        //c = int.Parse(str[1]);

        Console.Write("{0}", count);//改行なし出力
        //onsole.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
    }
}


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

int main(){
    long long X;
    cin >> X;

    int target = X % 100;
    int max_count = X / 100;
    
    int max_count_5 = min({target / 5, max_count});
    int max_count_4 = min({target / 4, max_count});
    int max_count_3 = min({target / 3, max_count});
    int max_count_2 = min({target / 2, max_count});
    int max_count_1 = min({target, max_count});

    if(target == 0){
        cout << 1 << endl;
        return 0;
    }

    for(int i=0; i<=max_count_5; i++){
        for(int j=0; j<=(max_count_4-i); j++){
        for(int k=0; k<=(max_count_3-i-j); k++){
        for(int l=0; l<=(max_count_2-i-j-k); l++){
        for(int m=0; m<=(max_count_1-i-j-k-l); m++){
            if(target == (5*i + 4*j + 3*k + 2*l + m) && max_count >= (i+j+k+l+m)){
                cout << 1 << endl;
                return 0;
            }
        }
        }
        }
        }
    }

    cout << 0 << endl;
    return 0;

}

Measured memory_bytes: 3588
main=do
 [n,y]<-map read.words<$>getLine
 putStrLn(head([unwords[(show a),(show b),(show(n-a-b))]|a<-[0..n],b<-[0..(n-a)],y-1000*n==9000*a+4000*b]++["-1 -1 -1"]))

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

int main() {
	int N;
	cin >> N;

	int num = N/100;
  	int	fraction = N - num*100;
  
    for(int i = 0; i < num; i++){
      if(fraction <= 5){
        cout << 1 << endl;
        return 0;
      }
      else fraction -= 5;
    }
      cout << 0 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    map<int, int> mp;
    int cursum = 0;
    mp[0]++;
    rep(i, n) {
        cursum += a[i];
        mp[cursum % m]++;
    }

    int ans = 0;
    for(auto &x : mp) {
        ans += x.second * (x.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

typedef struct directed_edge {
  int32_t vertex;
  int32_t next;
} graph_edge;

typedef struct directedGraph {
  graph_edge *edge;
  int32_t *start;
  int32_t pointer;
  int32_t vertex_num;
  int32_t edge_max_size;
} graph;

graph* new_graph (const int vertex_num) {
  graph *g = (graph *) calloc (1, sizeof (graph));
  g->edge = (graph_edge *) calloc (1, sizeof (graph_edge));
  g->start = (int32_t *) calloc (vertex_num, sizeof (int32_t));
  g->pointer = 0;
  g->vertex_num = vertex_num;
  g->edge_max_size = 1;
  for (int32_t i = 0; i < vertex_num; ++i) {
    g->start[i] = -1;
  }
  return g;
}

void add_edge (graph *g, int32_t from, int32_t to) {
  if (g->pointer == g->edge_max_size) {
    g->edge_max_size *= 2;
    g->edge = (graph_edge *) realloc (g->edge, sizeof (graph_edge) * g->edge_max_size);
  }
  g->edge[g->pointer] = (graph_edge) {to, g->start[from]};
  g->start[from] = g->pointer++;
}

void BFS_graph (graph *g, int32_t src, i32 *q, i32 *parent) {
  uint8_t *used = (uint8_t *) calloc (g->vertex_num, sizeof (uint8_t));
  int32_t front = 0;
  int32_t last = 0;
  used[src] = 1;
  q[last++] = src;
  parent[src] = -1;
  while (front < last) {
    const int32_t v = q[front++];
    for (int32_t p = g->start[v]; p != -1; p = g->edge[p].next) {
      const int32_t u = g->edge[p].vertex;
      //hoge
      if (!used[u]) {
        used[u] = 1;
        q[last++] = u;
        parent[u] = v;
      }
    }
  }
  free(used);
}

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  graph *g = new_graph (n);
  for (i32 i = 1; i < n; ++i) {
    i32 a, b;
    scanf ("%" SCNi32 "%" SCNi32, &a, &b);
    a--; b--;
    add_edge (g, a, b);
    add_edge (g, b, a);
  }
  i32 *q = ALLOC (n, i32);
  i32 *parent = ALLOC (n, i32);
  BFS_graph (g, 0, q, parent);
  i32 *dp = ALLOC (n, i32);
  for (i32 i = n - 1; i >= 0; --i) {
    i32 v = q[i];
    for (i32 p = g->start[v]; p != -1; p = g->edge[p].next) {
      i32 u = g->edge[p].vertex;
      if (u == parent[v]) continue;
      dp[v] ^= 1 + dp[u];
    }
  }
  puts (dp[0] > 0 ? "Alice" : "Bob");
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 3456
N,X,M = gets.split.map(&:to_i)

a = [X]
mem = {}
ans = X
x = X
i = 1
while i < N
  x = (x**2) % M
  a << x
  if mem[x]
    j = mem[x][0]
    n = a[j...i].sum
    ans += n * ((N - i) / (i-j))
    ans += a[j,(N-i)%(i-j)].sum
    break
    i = N - (N - i) % i
  else
    mem[x] = [i, ans]
    ans += x
  end
  i += 1
end
puts ans

Measured memory_bytes: 18256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
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);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w;
    cin >> w;
    cout << 32 * w << endl;
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int X;
  int Y;
  int c;
  int t;
  int a = 0;
  cin>>X;
  cin>>Y;
  for(int i = 0;i <= X;i++){
    c = i;
    t = X - c;
    //for(int i = 0;i < (X - c);i++){
      //t = i;
      if((c * 2 + t * 4) == Y){
        cout<<"Yes";
        a = 1;
        break;
        }
    //}
  }
  if(a == 0){
    cout<<"No";
  }
}

Measured memory_bytes: 3584
from functools import reduce
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    maxA = 10**6

    N = int(input())
    As = list(map(int, input().split()))

    def getMinPFs(n):
        isPrimes = [False]*2 + [True]*(n-1)
        minPFs = [1] + list(range(1, n+1))
        for d in range(2, int(n**0.5)+1):
            if isPrimes[d]:
                minPFs[d] = d
                for x in range(d*d, n+1, d):
                    isPrimes[x] = False
                    if minPFs[x] == x:
                        minPFs[x] = d
        return minPFs

    def getPrimeFactors(x, minPFs):
        anss = set()
        while minPFs[x] > 1:
            anss.add(minPFs[x])
            x //= minPFs[x]
        return anss

    minPFs = getMinPFs(maxA)

    useds = [0] * (maxA+1)
    for A in As:
        PFs = getPrimeFactors(A, minPFs)
        for PF in PFs:
            if useds[PF]:
                break
            useds[PF] = 1
        else:
            continue
        break
    else:
        print('pairwise coprime')
        return

    def gcd(a, b):
        while b:
            a, b = b, a%b
        return a

    g = reduce(gcd, As)

    if g == 1:
        print('setwise coprime')
    else:
        print('not coprime')


solve()


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

int main() {
    long long A,B,C,D;
    cin >> A >> B >> C >> D;
    long long c=C,d=D;
    long long ans;
    long long x = C * D;
    if(C<D){
        long long tmp = C;
        C = D;
        D = tmp;
    }
    long long r = C % D;
    while(r!=0){
        C = D;
        D = r;
        r = C % D;
    }
    ans = B - A + 1 - ((B / c - (A-1) / c) + (B / d - (A-1) / d) - (B / (x/D) - (A-1) / (x/D)));
    cout << ans << endl;

}

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

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007

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

    int n,k;
    cin>>n>>k;
    double x;
    double e[n];
    double ans = 0;
    double pre[n+1]={0};
    for(int i = 0; i<n; i++){
        cin>>x;
        e[i] = (x + 1)/2;
    }
    for(int i = 0; i<=n; i++){
        pre[i+1]+=pre[i] + e[i];
    }
    for(int i = k; i<=n; i++){
        ans = max(ans,pre[i]-pre[i-k]);
    }
    
    
    cout<<fixed<<setprecision(12)<<(double)ans<<"\n";
}

Measured memory_bytes: 3456