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

int MAX_N=131072*4;
int64_t Null=0;//初期値
vector<int64_t> seg(MAX_N*2-1,Null);
vector<int64_t> lazy(MAX_N*2-1,Null);
void eval(int k){
  if(lazy[k]==Null){
    return;
  }
  if(k<MAX_N-1){//子への伝播
    lazy[k*2+1]=max(lazy[k*2+1],lazy[k]);//change
    lazy[k*2+2]=max(lazy[k*2+2],lazy[k]);//change
  }
  seg[k]=max(seg[k],lazy[k]);//change
  lazy[k]=Null;
}

int64_t qu_s(int a,int b,int k,int l, int r){
  eval(k);
  if(r<=a||b<=l){
    return 0;//change
  }
  else if(a<=l&&r<=b){
    return seg[k];
  }
  else{
    int64_t X=qu_s(a,b,k*2+1,l,(l+r)/2);
    int64_t Y=qu_s(a,b,k*2+2,(l+r)/2,r);
    return max(X,Y);//change
  }
}
int64_t qu(int a,int b){
  return qu_s(a,b,0,0,MAX_N);
}

void chran_s(int c,int a,int b,int k,int l, int r){
  eval(k);
  if(r<=a||b<=l){
    return;
  }
  else if(a<=l&&r<=b){
    lazy[k]=c;
    eval(k);
    while(k>0){//親への伝播
      k--;
      k/=2;
      eval(k);
      eval(2*k+1);
      eval(2*k+2);
      seg[k]=max(seg[2*k+1],seg[2*k+2]);//change
    }
  }
  else{
    chran_s(c,a,b,k*2+1,l,(l+r)/2);
    chran_s(c,a,b,k*2+2,(l+r)/2,r);
  }
}
void chran(int c,int a,int b){
  chran_s(c,a,b,0,0,MAX_N);
}



int main(){
  int N,K,Z=0;
  cin>>N>>K;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    int b=max(a-K,0);
    p[i]=qu(b,a+K+1);
    p[i]++;
    chran(p[i],a,a+1);
    Z=max(p[i],Z);
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 20928
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"YES":"NO")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int a,c,b;
    bool ans=false;
    cin >>a>>b>>c;
    int ab=__gcd(a,b);
    if(ab==1 or __gcd(ab,c)!=1){
        ans=true;
    }
    cout<<solve(ans)<<endl;
}
/*
nA mod B == C
if A B が素　... true
else gcd(a,b) C が素　...false ex, 4 ,6 ,3 ;   4,6,2 => 2,3,1==true 4,6,4 => 2,3,2
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000010
#define F first
#define S second
using namespace std;
int n,m,book[N],nd;
vector<pair<int,int> > ed[N];
vector<int> col[N],ng[N];
int main(){
	int x,y,c,i,j,k;
	//memset(book,-1,sizeof(book));
	cin>>n>>m;
	nd=n;
	for(i=0;i<m;i++)
	{
		cin>>x>>y>>c;
		x--;
		y--;
		ed[x].push_back(make_pair(c,y));
		ed[y].push_back(make_pair(c,x));
		col[c].push_back(x);
		col[c].push_back(y);
	}
	for(i=0;i<n;i++)
	{
		sort(ed[i].begin(),ed[i].end());
	}
	for(i=0;i<N;i++)
	{
		for(j=0;j<col[i].size();j++)
		{
			y=col[i][j];
			if(book[y]==i)
			{
				continue;
			}
			queue<int> q;
			q.push(y);
			book[y]=i;
			while(q.size())
			{
				x=q.front();
				q.pop();
				ng[x].push_back(nd);
				ng[nd].push_back(x);
				for(k=lower_bound(ed[x].begin(),ed[x].end(),make_pair(i,0))-ed[x].begin();k<ed[x].size();k++)
				{
					if(ed[x][k].F!=i)
					{
						break;
					}
					if(book[ed[x][k].S]!=i)
					{
						book[ed[x][k].S]=i;
						q.push(ed[x][k].S);
					}
				}
			}
			nd++;
		}
	}
	/*for(i=0;i<n;i++)
	{
		for(j=0;j<ng[i].size();j++)
		{
			cout<<i<<"->"<<ng[i][j]<<endl;
		}
	}*/
	queue<int> q,st;
	q.push(0);
	st.push(0);
	book[0]=-2;
	while(q.size())
	{
		x=q.front();
		y=st.front();
		q.pop();
		st.pop();
		if(x==n-1)
		{
			cout<<y/2<<endl;
			return 0;
		}
		for(i=0;i<ng[x].size();i++)
		{
			c=ng[x][i];
			if(book[c]==-2)
			{
				continue;
			}
			book[c]=-2;
			q.push(c);
			st.push(y+1);
		}
	}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 93824
n,m=list(map(int,input().split()))
ans=[set() for _ in range(n)]
for i in range(m):
    s,c=list(map(int,input().split()))
    s-=1
    ans[s].add(c)
cal=[float("inf") for _ in range(n)]
if n>1 and (0 in ans[0]):
    print(-1)
    exit()
for i in range(n):
    if len(ans[i])>1:
        print(-1)
        exit()
    if len(ans[i])==1:
        cal[i]=str(list(ans[i])[0])
    elif len(ans[i])==0:
        if i==0 and n>1:
            cal[i]=str(1)
        else:
            cal[i]=str(0)
ans="".join(cal)
print(ans)

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

solver::[Int]->Int->Int
solver ls k = let st = sort ls in (minimum.(map (\(x,y)-> x-y)).(zip (drop (k-1) st))) st

main::IO()
main=do
  nk<-getLine
  let n:k:[]= map read (words nk)
  dat<-forM [1..n] (\_-> do
                    s<-getLine
                    return (read s))
  print (solver dat k)


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

using namespace std;

int main() {
    // Input
    int N, M;
    vector<int> A;

    cin >> N;
    A = vector<int>(N - 1);
    for (int i = 0; i < N - 1; i++) cin >> A[i];

    // Process
    vector<int> ans = vector<int>(N);
    for (int a : A) ans[a - 1]++;

    // Output
    for (int n : ans) cout << n << endl;

    return 0;
}


Measured memory_bytes: 4828
// template version 1.14
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

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

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  vector<int> a(n);
  multiset<int> ms;
  rep(i, n) {
    cin>>a[i];
    ms.insert(a[i]);
  }
  dump(a);
  sort(all(a));

  vi used(n);
  int ans = 0;
  auto iter = ms.end();
  iter--;
  while(true){
    int v = *iter;
    dump(v, ms);
    iter = ms.erase(iter);
    int k = 1;
    while (k<=v){ k *= 2; }
    dump(v, k);
    if (ms.find(k-v)!=ms.end()){
      ans++;
      used[posl(a, k-v)] = 1;
      auto riter = ms.find(k-v);
      ms.erase(riter);
    }
    dump(ms);
    if (sz(ms)<=1) break;
    iter--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,W;
    cin>>n>>W;
    vl w(n),v(n);
    REP(i,n){
        cin>>w[i]>>v[i];
    }
    vvl dp(2,vl(W+1));
    REP(i,n){
        REP(j,W+1){
            if(j+w[i]<=W){
                chmax(dp[(i+1)%2][j+w[i]],dp[i%2][j]+v[i]);
            }
            chmax(dp[(i+1)%2][j],dp[i%2][j]);
        }
    }
    cout<<*max_element(all(dp[n%2]));
    return 0;
}

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

int n, m, k;
vector<int> dsu;
vector<set<int>> fr, bl;

int parent(int u) {
	if (dsu[u] < 0) return u;
	return (dsu[u] = parent(dsu[u]));
}

void merge(int u, int v) {
	u = parent(u); v = parent(v);
	if (u==v) return;
	if (dsu[u] > dsu[v]) swap(u,v);
	dsu[u] += dsu[v];
	dsu[v] = u;
}

bool query(int u, int v) {
	return (parent(u) == parent(v));
}

int main() {
	cin >> n >> m >> k;
	dsu.resize(n, -1);
	fr.resize(n); bl.resize(n);
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		u--, v--;
		fr[u].insert(v);
		fr[v].insert(u);
		merge(u, v);
	}
	for (int i = 0; i < k; i++) {
		int u, v; cin >> u >> v;
		u--, v--;
		bl[u].insert(v);
		bl[v].insert(u);
	}
	for (int i = 0; i < n; i++) {
		int s = -1*dsu[parent(i)] - fr[i].size();
		// cout << parent(i) << " " << fr[i].size() << "\n";
		for (int v : bl[i]) {
			if (query(i, v)) s--;
		}
		cout << s-1 << " ";
	}
}


Measured memory_bytes: 29312
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int N = sc.nextInt();
	  Set<String> hina = new HashSet<>();
	  for(int i = 0; i < N; i++) {
		  hina.add(sc.next());
	  }
	  String ans = "Three";
	  if(hina.size() == 4) {
		  ans = "Four";
	  }
	  System.out.println(ans);
	}
}

Measured memory_bytes: 35764
import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))
val = x
val_neg = x
val_pos = x
i = 1
while True:
    if val not in p:
        print(val)
        sys.exit()
    else:
        if val_neg not in p:
            print(val_neg)
            sys.exit()
        elif val_pos not in p:
            print(val_pos)
            sys.exit()
        else:
            val_neg -= i
            val_pos += i


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

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


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, w int
	fmt.Scan(&n, &w)
	elements := make([]element, n)
	for i := 0; i < n; i++ {
		var w, v int
		fmt.Scan(&w, &v)
		elements[i] = element{w, v}
	}
	memo := make([][]int, n + 1)
	for i := 0; i < n + 1; i++ {
		memo[i] = make([]int, w + 1)
	}
	for i := 0; i < n; i++ {
		e := elements[i]
		for j := w; j >= 0; j-- {
			if j - e.weight >= 0 {
				memo[i + 1][j] = max1(memo[i][j], memo[i][j - e.weight] + e.value)
			} else {
				memo[i + 1][j] = memo[i][j]
			}
		}
	}
	fmt.Println(memo[n][w])
}

type element struct {
	weight, value int
}

func max1(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

Measured memory_bytes: 81792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

bool tri(const vector<ll> &x)
{
    return x[0]+x[1]>x[2];
}

bool check(const vector<ll> &v)
{
    // dbg(v);
    int comb = (1<<3) - 1;
    while(comb < (1<<6)-1)
    {
        vector<ll> p,q;
        rep(i,6)
        {
            if(comb>>i&1) p.pb(v[i]);
            else q.pb(v[i]);
        }
        // dbg(p);dbg(q);
        if(tri(p) && tri(q)) return true;

        int x = comb & -comb, y = comb + x;
        comb = ((comb & ~y) / x>>1) | y;
    }
    return false;
}

ll SUM(const vector<ll> &v)
{
    ll ret = 0;
    for(ll i:v) ret += i;
    return ret;
}

int main()
{
    int n;
    cin >>n;
    vector<ll> a(n);
    rep(i,n) cin >>a[i];
    sort(all(a));

    vector<int> ok;
    for(int i=2; i<n; ++i)
    {
        vector<ll> v;
        rep(j,3) v.pb(a[i-2+j]);
        if(tri(v)) ok.pb(i);
    }

    ll ans = 0;
    rep(i,n-5)
    {
        vector<ll> v;
        rep(j,6) v.pb(a[i+j]);
        if(check(v)) ans = max(ans,SUM(v));
    }

    if(ok.size()>0)
    {
        for(int i=n-1; i>=2; --i)
        {
            if(*lower_bound(all(ok),i) == i)
            {
                int idx = lower_bound(all(ok),i-2)-ok.begin();
                --idx;
                if(idx>=0)
                {
                    vector<ll> v;
                    rep(j,3) v.pb(a[ok[idx]-2+j]);
                    rep(j,3) v.pb(a[i-2+j]);
                    ans = max(ans,SUM(v));
                }
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4328
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {

	int a[200], n, i, mod=0, count=0;

	scanf("%d", &n);

	
	for (i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	for (i = 0; i < n; i++) {

		mod += a[i] % 2;
	}

	while (mod == 0) {

		for (i = 0; i < n; i++) {

			a[i] /= 2;
		}

	count++;
	    for (i = 0; i < n; i++) {

		mod += a[i] % 2;
	    }
	}
	
	printf("%d", count);
	
		
	return 0;

}

Measured memory_bytes: 128
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

n = int(rl())

li = list(map(int, rl().split()))
if n == 0 and li[0] == 1:
    print(1)
    exit()

can = [1-li[0]]

a = can[0]
for i in range(1, n+1):
    a = a*2
    can.append(a)
    a -= li[i]
    if a < 0:
        print(-1)
        exit()

ans = 0
can.reverse()
li.reverse()
temp = 0
for i in range(n+1):
    temp += li[i]
    ans += min(can[i], temp)
print(ans)

Measured memory_bytes: 692244
#include<stdio.h>
int main(void)
{
	int a,c[6]={0},d;
	double b;
	scanf("%d",&a);
	for(d=0;d<a;d++)
	{
		scanf("%lf",&b);
		if(b<165)
			c[0]++;
		else if(b<170)
			c[1]++;
		else if(b<175)
			c[2]++;
		else if(b<180)
			c[3]++;
		else if(b<185)
			c[4]++;
		else
			c[5]++;
	}
	for(d=0;d<6;d++)
	{
		printf("%d:",d+1);
		for(a=0;a<c[d];a++)
			printf("*");
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
#define ll              long long
#define PII             pair<int, int>
#define rep(i,a,b)      for(int  i=a;i<=b;i++)
#define dec(i,a,b)      for(int  i=a;i>=b;i--)
#define pb              push_back
#define mk              make_pair
using namespace std;
int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846;
const int mod = 998244353;
const int N = 50 + 5;
//if(x<0 || x>=r || y<0 || y>=c)

inline ll read()
{
	ll x = 0; bool f = true; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return f ? x : -x;
}

ll gcd(ll m, ll n)
{
	return n == 0 ? m : gcd(n, m % n);
}
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}

int main()
{
	string s;
	cin >> s;
	map<int, int> mp;
	mp[0] = 1;
	int x = 0, ans = 0, cnt = 1;
	for (int i = s.size()-1; i >=0 ; i--)
	{
		x = ((s[i] - '0')*cnt + x)%2019;
		ans += mp[x];		
		mp[x]++;
		cnt = cnt * 10 % 2019;
	}
	cout << ans << endl;
	return 0;
}



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

int main(void) {
  int v = 4280;
  int w, sum, ans;
  while(cin >> w, w != -1) {
    sum = 0;
    if(w < 10) sum += 1150;
    if(10 <= w && w < 20) {
      sum += 1150;
      sum += (w % 10) * 125;
    }
    if(20 <= w && w < 30) {
      sum += 2400;
      sum += (w % 10) * 140;
    }
    if(30 <= w) {
      sum += 3800;
      sum += (w - 30) * 160;
    }
    ans = v - sum;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var n, l int
	fmt.Scan(&n, &l)
	var s []string
	for i := 0; i < n; i++ {
		var tmp string
		fmt.Scan(&tmp)
		s = append(s, tmp)
	}
	sort.Strings(s)
	fmt.Println(strings.Join(s, ""))
	return
}


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

using namespace std;

typedef long long ll;

typedef long double ld;

const int N = 105;

int n;
int a[N];
int b[N];

int c[N];
int d[N];

int visID;
int used[N];
int with[N];

bool match(int idx){
    for(int i = 1; i <= n; i++){
        if(a[idx] < c[i] && b[idx] < d[i] && used[i] != visID){
            used[i] = visID;
            if(!with[i] || match(with[i])){
                with[i] = idx;
                return true;
            }
        }
    }
    return false;
}

int main(){
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        scanf("%d%d" , &a[i] , &b[i]);
    }
    for(int i = 1; i <= n; i++){
        scanf("%d%d" , &c[i] , &d[i]);
    }
    int bst = 0;
    for(int i = 1; i <= n; i++){
        visID++;
        if(match(i))
            bst++;
    }
    printf("%d\n" , bst);
}


Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
#define all(x) (x).begin(),(x).end()
using namespace std;
int x[100010];
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a*b/gcd(a,b);
}
signed main(){
	int a,ans;
	cin>>a;
	f(i,a){
		cin>>x[i];
		if(i)ans=lcm(ans,x[i]);
		else ans=x[i];
	}
	int cnt=0;
	f(i,a){
		cnt+=ans/x[i];
	}
	printf("%.100lf\n",(double)ans/cnt);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define max 200009
map<long,long>mp;

int main()
{
    long i,j,t,a,b,n,c,temp,m;
    t=1;
    // cin>>t;
    while(t--)
    {
       cin>>n>>m;
       vector<vector<long>> arr(n+1);
       for(i=0;i<m;i++)
       {
           cin>>a>>b;
           arr[a].push_back(b);
           arr[b].push_back(a);
       }
       int flag=0;
       for(i=0;i<arr[1].size();i++)
       {
           temp=arr[1][i];
           for(j=0;j<arr[temp].size();j++)
           {
               if(arr[temp][j]==n)flag=1;
           }
       }
       if(flag)cout<<"POSSIBLE";
       else cout<<"IMPOSSIBLE";
    }
}

Measured memory_bytes: 12776
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

int main()
{
  ll a, b;
  cin >> a >> b;
  if (a < b)
  {
    ll t = a;
    a = b;
    b = t;
  }
  vector<ll> c;
  ll t = gcd(a, b);
  for (ll i = 1; i * i < t + 1; ++i)
  {
    if (t % i == 0)
    {
      c.push_back(i);
      if (i * i != t)
      {
        c.push_back(t / i);
      }
    }
  }
  sort(c.begin(), c.end());
  ll cnt = 0;
  for (ll i = 0; i < c.size(); ++i)
  {
    if (c[i] <= 2)
    {
      cnt++;
      continue;
    }
    if (c[i] % 2 == 0)
      continue;
    bool f = false;
    for (ll j = 3; j * j <= c[i] + 1; j += 2)
    {
      if (c[i] % j == 0)
      {
        f = true;
        break;
      }
    }
    if (f)
      continue;
    cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N ,K ;
    cin >>N >> K ;
    string str ;
    cin >> str;
    str[K-1] -= ('A'-'a');

    cout << str << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

int main(){
	int a,b,c,x;

	cin >> a >> b >> c;

	if ( a>b ) {
		x=a; a=b; b=x;
	}
	if ( b>c ) {
		x=b; b=c; c=x;
	} 
	if ( a>b )
	{
		x=a; a=b; b=x;
	}
	cout << a <<" " <<  b <<" " << c << endl;
    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    while(1){
        int n; cin >> n;
        if(n==0) break;
        vector<int> v(n);
        ll sum=0;
        for(int i=0;i<n;i++){
            cin >> v[i];
            sum+=v[i];
        }
        double ave=(double)sum/n;
        int cnt=0;
        for(int i=0;i<n;i++){
            if(v[i]<=ave) cnt++;
        }
        cout << cnt << endl;
    }

}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

int main () {
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i,n) cin >> p[i];
  vector<double> q(n);
  rep(i,n) q[i] = (1+p[i])/2;
  vector<double> csum(q.size()+1);
  rep(i,q.size()) {
    csum[i+1] = csum[i] + q[i];
  }
  double ans = 0;
  rep(i,n) {
    if (i+k >= n+1) break;
    double s = csum[i+k] - csum[i];
    ans = max(ans, s);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

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

int main() {
    string S,T; cin >> S >> T; bool can2=false;
    for(int i=S.size()-T.size();i>=0;i--){
        bool can =true; 
        rep(j,T.size()){
            if(S[i+j]!=T[j] && S[i+j]!='?')
            {can=false;}
        }
        if(can){
            rep(s,T.size()){
                S[i+s]=T[s];
            }
            can2=true;
            break;
        }
    }
    if(!can2){cout << "UNRESTORABLE" << endl;}
    else{
        rep(i,S.size()){
        if(S[i]=='?')cout << 'a' << flush;
        else cout << S[i] << flush;
    }
    cout << endl;

      }
    

    return 0;
}

Measured memory_bytes: 256
import sys
DBG =  not True
R = 1000000007
MAXN = 200000
n = int(input())
c = []
for i in range(n):
    c.append(int(input()))
tot = 1
s = [0] * (MAXN+1)
for i in range(n):
    if i > 0 and c[i] == c[i-1]:
        continue
    x = s[c[i]]
    tot = (tot + x) % R
    s[c[i]] = tot
    if DBG:
        print("i {} sci {} tot {} newt {}".format(i,x,s[c[i]],tot))
        print(s)
print(tot)


Measured memory_bytes: 16548
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
#include<set>
#include<map>
using namespace std;
//---------------------------------------------------------------------------
int n, w, dp[105][10005];
vector<pair<int, int>>p;

int sol(int tc, int wl) {
	if(dp[tc][wl] != -1)return dp[tc][wl];
	if(tc*wl == 0)return dp[tc][wl] = 0;
	dp[tc][wl] = sol(tc - 1, wl);
	if (wl - p[tc-1].second >= 0) {
		dp[tc][wl] = max(dp[tc][wl],sol(tc - 1, wl-p[tc-1].second)+p[tc-1].first);
	}
	return dp[tc][wl];
}

int main() {
	cin >> n >> w;
	for (int i = 0; i < n; i++) {
		int va, we;
		cin >> va >> we;
		p. push_back(make_pair(va, we));
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= w; j++)dp[i][j] = -1;
	}
	sort(p.begin(), p.end());
	cout << sol(n, w) << endl;
	return 0;
}



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

using namespace std;

int main(void)
{
    string s;
    cin >> s;
    if (s.length() % 2 == 1)
    {
        cout << "No" << endl;
    }
    else
    {
        for (int i = 0; i < (int)s.length(); i += 2)
        {
            if (s[i] != 'h' || s[i + 1] != 'i')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
string str[N];
int n;
ll ans=0;
char buf[100];
int cmp(const void* a, const void* b) {
    return *((char*)a) - *((char*)b);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
      scanf("%s", buf);
      int len = strlen(buf);
      qsort(buf, len, sizeof(char), cmp);
      str[i] = string(buf);
  }
  sort(str + 1, str + n+1);
  int i = 1, j = 1;
  for (;i<=n; i=j+1) {
      while (j+1 <= n && str[i] == str[j+1]) {
          j++;
      }
      ll d = j - i + 1;
      ans += d*(d-1)/2;
  }
  cout << ans;
}

Measured memory_bytes: 5760
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n = readline()
    if n[1] == n[2] == n[3] || n[2] == n[3] == n[4]
        println("Yes")
    else
        println("No")
    end
end
main()

Measured memory_bytes: 163208
S = gets.chomp.split("").map(&:to_s)
T = gets.chomp.split("").map(&:to_s)
ans = T.length

(0..S.length-T.length).each do |i|
num = 0
x = 0

(i..i+T.length-1).each do |n|
  if S[n] != T[x]
      num += 1
  end
  x += 1
end

if num < ans
  ans = num
end
end

puts ans

Measured memory_bytes: 14408
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	if N%K == 0 {
		fmt.Fprintln(wtr, 0)
	} else {
		rest1 := N % K
		rest2 := K*(N/K+1) - N
		fmt.Fprintln(wtr, min(rest1, rest2))
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstring>

#define LP(i,n) for(int i = 0; i < n; i++)

using namespace std;

int s;
int x[4][2];

void comb(int y[8], int n){
	if(n == 8){
		int p[4][4];
		memset(p,0,sizeof p);
		int idx = 0;
		for(int j = 0 ; j< 4 ;j++){
			for(int i = 0; i < 4; i++){
				if(p[i][j]==0){
					if(0<=i+x[y[idx]][0]&&i+x[y[idx]][0]<4&&0<=j+x[y[idx]][1]&&j+x[y[idx]][1]<4&&p[i+x[y[idx]][0]][j+x[y[idx]][1]] == 0){
						p[i+x[y[idx]][0]][j+x[y[idx]][1]] = ++idx;
					}else return;
				}
			}
		}
		s++;
		return;
	}
	for(int i = 0; i < 4; i++){
		y[n] = i;
		comb(y,n+1);
	}
}

int main(){
	cin >> **x;
	while(**x < 5){
		s = 0;
		for(int i = 1; i < 8; i++){
			cin >> *(*x+i);
		}
		int y[8];
		comb(y,0);
		cout << s << endl;
		cin >> **x;
	}
}

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

typedef pair<int, int> P;

int H, W;
string canv[51];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };

int dfs(int y, int x) {
	queue<P> que;
	que.push(P(y, x));
	canv[y][x] = '.';
	int res = 1;

	while (!que.empty()) {
		P now = que.front(); que.pop();
		for (int i = 0; i < 4; i++) {
			int ny = now.first + dy[i];
			int nx = now.second + dx[i];
			if (0 <= ny && ny < H && 0 <= nx && nx < W) {
				if (canv[ny][nx] == '#') {
					que.push(P(ny, nx));
					canv[ny][nx] = '.';
					res++;
				}
			}
		}
	}

	return res;
}

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> canv[i];

	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			if (canv[y][x] == '#' && dfs(y, x) == 1) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
 
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1
 
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
 
print(ans)

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

int main(){
    int r, g, b;
    cin >> r >> g >> b;

    //判定する対象
    int k = 100 * r + 10 * g + b;
    if (k % 4 == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
/*
  Aizu Vol-1 0118: Property Distribution 
  2017.8.14 bal4u@uu
  ??£??\??????????¨???????????????¨?????????Union??????????????°???
*/

#include <stdio.h>
#include <ctype.h>

char *gets(char *);
char buf[30], *bp;

int getInt(void)
{
	int n = 0;
	while (isspace(*bp)) bp++;
	while (isdigit(*bp)) n = 10 * n + (*bp++ - '0');
	return n;
}

#define N 100			// >= 100+2
#define MAX 10000		// >= N*N

/* UNION-FIND library */
int p[MAX+10], rank[MAX+10];

void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1; }
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

char map[N + 5][N + 5];
int H, W;

int main()
{
	int r, c, k, s;

	while (1) {
		gets(bp = buf), H = getInt(), W = getInt(); if (!H && !W) break;
		for (k = r = 0; r < H; r++) {
			gets(map[r]);
			for (c = 0; c < W; c++) make_set(k++);
		}
		for (c = 0; c < W; c++) map[H][c] = 0;

		for (s = 0, r = 0; r < H; r++, s += W) {
			for (c = 0; c < W; c++) {
				if (map[r][c] == map[r][c + 1]) {
					if (find_set(s + c) != find_set(s + c + 1)) union_set(s + c, s + c + 1);
				}
				if (map[r][c] == map[r + 1][c]) {
					if (find_set(s + c) != find_set(s + c + W)) union_set(s + c, s + c + W);
				}
			}
		}
		for (s = 0, k = 0; k < H*W; k++) if (p[k] != k) s++;
		printf("%d\n", H*W - s);
	}
	return 0;
}

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

int a[100006];
int cnt[100006];

int main(){
  int n;
  int i;

  scanf("%d", &n);

  for(i = 0;i <= 100000;i++) cnt[i] = 0;
  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }

  ll ans = 0;
  ll t = 0;
  for(i = 1;i <= 100000;i++){
    if(cnt[i] % 2 == 1) ans++;

    else if(cnt[i] >= 2){
      t++;
    }
  }

  if(t % 2 == 0) ans += t;

  else ans += t - 1;

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

  return 0;
}

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


int main(){
    ll n,m;cin>>n>>m;
    ll a[100010];
    map<ll,ll> mp;
    rep(i,0,n){
        cin>>a[i];
        if(i==0){mp[a[i]%m]++;continue;}
        a[i]+=a[i-1];
        mp[a[i]%m]++;
    }
    ll an=0;
    for(auto i:mp){
        ll b=i.first,cn=i.second;
        if(b==0){
            if(cn!=0)an+=(cn+1)*cn/2;
        }
        else{
            an+=cn*(cn-1)/2;
        }
    }
    cout<<an<<endl;
}

    









Measured memory_bytes: 4992
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[110000][2];
char c[110000];
int cnt[2100][2100][2];
int ll[2100][2100][2];

int cal(int x1,int y1,int x2,int y2,int c)
{
  int ans;
  if (x2<x1) return 0;
  if (y2<y1) return 0;
  ans=ll[x2][y2][c];
  if (x1-1>=0) ans-=ll[x1-1][y2][c];
  if (y1-1>=0) ans-=ll[x2][y1-1][c];
  if ((x1-1>=0)&&(y1-1>=0)) ans+=ll[x1-1][y1-1][c];
  return ans;
}

char s[100];

int main()
{
  int i,j,k,o,n,best,ans,c0,c1;
  int k2,tmp;
  scanf("%d%d",&n,&k);
  k2=k+k;
  c0=0;c1=0;
  for (i=0;i<n;i++)
  {
    scanf("%d%d%s",&a[i][0],&a[i][1],s);
    c[i]=s[0];
    if (c[i]=='B') c0++;
    else c1++;
  }
  memset(cnt,0,sizeof(cnt));
  for (i=0;i<n;i++)
  {
    if (c[i]=='B')
      cnt[a[i][0]%k2][a[i][1]%k2][0]++;
    else cnt[a[i][0]%k2][a[i][1]%k2][1]++;
  }
  for (i=0;i<k2;i++)
    for (j=0;j<k2;j++)
      for (o=0;o<2;o++)
      {
        ll[i][j][o]=0;
        if (i>0) ll[i][j][o]+=ll[i-1][j][o];
        if (j>0) ll[i][j][o]+=ll[i][j-1][o];
        if ((i>0)&&(j>0)) ll[i][j][o]-=ll[i-1][j-1][o];
        ll[i][j][o]+=cnt[i][j][o];
      }
  best=0;
  for (i=0;i<k;i++)
    for (j=0;j<k;j++)
    {
      tmp=cal(0,0,i-1,j-1,0);
      tmp+=cal(i,j,i+k-1,j+k-1,0);
      tmp+=cal(i+k,j+k,k2-1,k2-1,0);
      tmp+=cal(i+k,0,k2-1,j-1,0);
      tmp+=cal(0,j+k,i-1,k2-1,0);
      ans=tmp;
      tmp=cal(0,0,i-1,j-1,1);
      tmp+=cal(i,j,i+k-1,j+k-1,1);
      tmp+=cal(i+k,j+k,k2-1,k2-1,1);
      tmp+=cal(i+k,0,k2-1,j-1,1);
      tmp+=cal(0,j+k,i-1,k2-1,1);
      tmp=c1-tmp;
      ans+=tmp;
      if (ans>best) best=ans;
      ans=n-ans;
      if (ans>best) best=ans;
    }
  printf("%d\n",best);
  return 0;
}

Measured memory_bytes: 70016
#include<stdio.h>

int main()
{
	int a, b, d, r;
	double f;
	scanf("%d %d", &a, &b);

	d = a / b;
	r = a%b;
	f = (double)a/b;
	printf("%d\n%d\n%lf\n",d,r,f);
}

Measured memory_bytes: 2720
N,t,i,j,a[50][20];
main(){
    char c[2]="",s[4]="SHCD";
    for(scanf("%d",&N);N--;){
        scanf("%s%d",c,&t);
        switch(c[0]){
            case'S':a[0][t-1]=1;break;
            case'H':a[1][t-1]=1;break;
            case'C':a[2][t-1]=1;break;
            case'D':a[3][t-1]=1;break;
        }
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(a[i][j]==0)
            printf("%c %d\n",s[i],j+1);
        }
    }
}

Measured memory_bytes: 1852
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int N;
    string[] X;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        X = readln.chomp.split(" ").array;
        return true;
    }
    void solve() {
        int l = 0, r = 0;
        int p = 0;
        int C = 0;
        foreach (i; 0 .. N) {
            if (X[i][0] == 'l') {
                l = !l;
            } else {
                r = !r;
            }
            if (l == !p && r == !p) {
                C++;
                p = l;
            }
        }
        C.writeln;
    }
    while (input) solve;
}

Measured memory_bytes: 1524
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
    long N;
    std::cin >> N;
    std::string S;
    std::cin >> S;
    int flag=0;
    if(S.length()%2==0)
    for(long i=0; i<S.length()/2; i++){
        if(S[i]!=S[S.length()/2+i]){
            break;
        }
        if(i==S.length()/2-1){
            flag=1;
        }
    }
    if(flag==0){
        std::cout << "No" << std::endl;
    }else{
        std::cout << "Yes" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
n,m = map(int,input().split())
if n < 2 and m <2:
    print(0)
elif n < 2 and m >= 2:
    print((math.factorial(m) // ((math.factorial(2))*(math.factorial(m-2)))))
elif m <2 and n >=2:
    print((math.factorial(n) // ((math.factorial(2))*(math.factorial(n-2)))))
else:
    print((math.factorial(m) // ((math.factorial(2))*(math.factorial(m-2))))+((math.factorial(n) // ((math.factorial(2))*(math.factorial(n-2))))))

Measured memory_bytes: 3064
s=input()
ans=[0]*len(s)
rl_list=[]
ind=[]
rl=s[0]
c=0
for i,ts in enumerate(s[1:]):
  c+=1
  if rl!=ts:
    rl_list.append(c)
    if ts=='L':
      ind.append(i+1)
    rl=ts
    c=0
rl_list.append(c+1)
for i in range(0,len(rl_list),2):
  index=ind[i//2]
  num=rl_list[i]//2
  if rl_list[i]%2==0:
    ans[index]+=num
    ans[index-1]+=num
  else:
    ans[index-1]+=num+1
    ans[index]+=num
  num=rl_list[i+1]//2
  if rl_list[i+1]%2==0:
    ans[index-1]+=num
    ans[index]+=num
  else:
    ans[index]+=num+1
    ans[index-1]+=num
print(*ans)
    

Measured memory_bytes: 9016
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  int k;
  cin >> k;

  for(int i = 0;i < s.size();i++){
    int margin = (int)(26 - s[i] + 'a');
    if(margin <= k && s[i] != 'a'){
      s[i] = 'a';
      k -= margin;
    }
  }

  if(k != 0)s[s.size() - 1] = 'a' + (s[s.size() - 1] - 'a' + k) % 26;  

  cout << s << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef pair<ul, ul> P;
 
int main()
{
    int n;
    cin >> n;
    if(n==7||n==5||n==3){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int t1[200005],t2[200005];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(a>b)swap(a,b);
		if(a==1)t1[b]=1;
		if(b==n)t2[a]=1;
	}
	for(int i=2;i<n;i++)if(t1[i]&&t2[i])
	{
		puts("POSSIBLE");
		return 0;
	}
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VLL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	int A, B, C;
    cin >> A >> B >> C;
    string ans = "No";
    if(A == B){
        if(A != C){
            ans = "Yes";
        }
    }else{
        if(B == C){
            ans = "Yes";
        }else{
            if(A == C){
                ans = "Yes";
            }
        }
    }

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


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

typedef long long ll;
ll k, n, c[100010] = {0};
vector<int> pri;
ll ans = 0;
const int M = 1e9 + 7;
int main() {
    cin >> n >> k;
    for(int i = k; i >= 1; i--) {
        ll a = k / i, s = 1;
        for(int j = n; j > 0; j >>= 1, a = a * a % M)
            if(j & 1) s = s * a % M;
        for(int j = 2 * i; j <= k; j += i) s -= c[j];
        c[i] = (s % M + M) % M;
        ans = (ans + c[i] * i) % M;
    }
    cout << ans;
}

Measured memory_bytes: 4396
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
set<int> s;
int a[200010];
int dp[200010];
vector<int> v[200010];
int main(){
	long long i,n,k;
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> a[i];
		v[a[i]].push_back(i);
	}
	dp[n] = 0;
	for(i=n - 1;i>=0;i--){
		int x = a[i];
		if(v[x].back()==i){
			dp[i] = x;
		}else{
			int y = upper_bound(v[x].begin(),v[x].end(),i) - v[x].begin();
			dp[i] = dp[v[x][y] + 1];
		}
	}
	int l = 0,r = n;
	for(i=1;i<=n + 1;i++){
		if(l==0) l = dp[0];
		else l = dp[v[l][0] + 1];
		if(l==0){
			r = i;
			break;
		}
	}
	k = k%r;
	l = 0;
	for(i=1;i<k;i++){
		if(l==0) l = dp[0];
		else l = dp[v[l][0] + 1];
		if(l==0){
			r = i;
			break;
		}
	}
	vector<int> w;
	if(l!=0){
		w.push_back(l);
		s.insert(l);
	}
	for(i=0;i<n;i++){
		if(s.count(a[i])){
			while(1){
				int x = w.back();
				s.erase(x); w.pop_back();
				if(x==a[i]) break;
			}
		}else{
			s.insert(a[i]);
			w.push_back(a[i]);
		}
	}
	for(i=0;i<w.size();i++){
		cout << w[i] << " ";
	}
	cout << endl;
}
	

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

int main(){
	double v,t,y;
	int N;
	while(0<=scanf("%lf",&v)){
		t=v/9.8;
		y=4.9*t*t;
		for(N=0;5*N-5<y;N++){
		}
		printf("%d\n",N);
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([0 for j in range(10)])
l_set=set([])
r_set=set([])
for i,(r,l) in enumerate(zip(S_riv,S)):
  l_lis[i]=l_set.copy()
  r_lis[i]=r_set.copy()
  l_set.add(l)
  r_set.add(r)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  length=len(l_lis[i])
  ans+=(length-mat[s])*len(r_lis[i])
  mat[s]=length
  
print(ans)

Measured memory_bytes: 48136