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

int main(){
  int n,cnt=0,ans=1;
  string s;
  cin>>n;
  while(n--){
    cin>>s;
    if(s=="A")cnt++;
    else{
      if(!cnt)ans=0;
      else cnt--;
    }
  }
  if(cnt)ans=0;
  if(ans)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 3120
fn main() {
    proconio::input! {
        n: usize,
        x: proconio::marker::Chars,
    }
    fn power_of_2_mod_bit_count(n: u64, bit_count: u64) -> Vec<u64> {
        let mut v = vec![0; n as usize];
        if bit_count == 0 {
            return v;
        }
        let mut tmp = 1;
        for i in 0..n {
            tmp %= bit_count;
            v[n as usize - i as usize - 1] = tmp;
            tmp <<= 1;
        }
        v
    }
    fn f(x: u64) -> u64 {
        let count = x.count_ones() as u64;
        x % count
    }
    let count_ones = x.iter().filter(|x| **x == '1').count() as u64;
    let ms_plus1 = power_of_2_mod_bit_count(n as u64, count_ones + 1);
    if count_ones == 0 {
        for _ in 0..n {
            println!("1");
        }
        return;
    }
    let ms_minus1 = power_of_2_mod_bit_count(n as u64, count_ones - 1);
    let m_plus1 = ms_plus1
        .iter()
        .zip(x.iter())
        .map(|(i, c)| if *c == '1' { *i } else { 0 })
        .sum::<u64>()
        % (count_ones + 1);
    let m_minus1 = if count_ones - 1 == 0 {
        0
    } else {
        ms_minus1
            .iter()
            .zip(x.iter())
            .map(|(i, c)| if *c == '1' { *i } else { 0 })
            .sum::<u64>()
            % (count_ones - 1)
    };
    for i in 0..n {
        let (count_ones, is_minus1) = if x[i] == '1' {
            (count_ones - 1, true)
        } else {
            (count_ones + 1, false)
        };
        if count_ones == 0 {
            println!("0");
        } else {
            let mut x = if is_minus1 {
                (m_minus1 + count_ones - ms_minus1[i]) % count_ones
            } else {
                (m_plus1 + ms_plus1[i]) % count_ones
            };
            let mut count = 1usize;
            while x != 0 {
                x = f(x);
                count += 1;
            }
            println!("{}", count);
        }
    }
}


Measured memory_bytes: 6176
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define N 998244353
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<long long>
#define INF 1000000000
 
ll modInverse(ll a, ll m);
ll gcd(ll a, ll b);
ll power(ll x, unsigned ll y, unsigned ll m);
ll logint(ll x,ll y);
 
 
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
 
ll power(ll x, unsigned ll y, unsigned ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;
 
    return (y%2 == 0)? p : (x * p) % m;
}
 
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
      return 0;
 
    while (a > 1)
    {
        // q is quotient
        ll q = a / m;
        ll t = m;
 
        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;
 
        // Update y and x
        y = x - q * y;
        x = t;
    }
 
    // Make x positive
    if (x < 0)
       x += m0;
 
    return x;
}
 
void pairsort(ll a[],ll b[], ll n)
{
    pair<ll, ll> pairt[n];
 
    // Storing the respective array
    // elements in pairs.
    for (ll i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
 
    // Sorting the pair array.
    sort(pairt, pairt + n);
 
    // Modifying original arrays
    for (ll i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<x;i++)
    {
        if(x<=a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
bool dp[1001][1001];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
    string a, b;
    cin>>a>>b;
    ll ans=0;
    REP(i, 0, 3){
        if(a[i]==b[i]){
            ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
S = input() #入力
m = 0 #最大
n = 0 #現在
a = [] #判別用
for i in range(len(S)):
  if S[i] == "A" or S[i] == "T" or S[i] == "C" or S[i] == "G":
    a.append(1)
  else:
    a.append(0)
for i in range(len(S)):
  if a[i] == 1:
    n += 1
    if n >= m:
      m = n
  else:
    n = 0
print(m)

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

// Dice サイコロ構造体
type Dice struct {
	val []int
}

// NewDice サイコロ構造体の生成
func NewDice() *Dice {
	dice := new(Dice)
	dice.val = make([]int, 7)

	return dice
}

// Throw サイコロを振る
func (d Dice) Throw(direction string) {

	tmp := 0

	switch direction {
	case "N":
		tmp = d.val[6]
		d.val[6] = d.val[5]
		d.val[5] = d.val[1]
		d.val[1] = d.val[2]
		d.val[2] = tmp
		break
	case "E":
		tmp = d.val[6]
		d.val[6] = d.val[3]
		d.val[3] = d.val[1]
		d.val[1] = d.val[4]
		d.val[4] = tmp
		break
	case "S":
		tmp = d.val[6]
		d.val[6] = d.val[2]
		d.val[2] = d.val[1]
		d.val[1] = d.val[5]
		d.val[5] = tmp
		break
	default:
		tmp = d.val[6]
		d.val[6] = d.val[4]
		d.val[4] = d.val[1]
		d.val[1] = d.val[3]
		d.val[3] = tmp
		break
	}
}

// Slide サイコロをスライドさせる
func (d Dice) Slide(direction string) {

	tmp := 0

	switch direction {
	case "L":
		tmp = d.val[2]
		d.val[2] = d.val[3]
		d.val[3] = d.val[5]
		d.val[5] = d.val[4]
		d.val[4] = tmp
		break
	default:
		tmp = d.val[2]
		d.val[2] = d.val[4]
		d.val[4] = d.val[5]
		d.val[5] = d.val[3]
		d.val[3] = tmp
		break
	}
}

func (d Dice) isFrontDirection(a, b int) bool {

	pattern := [][]int{{1, 2}, {2, 6}, {6, 5}, {5, 1}, {2, 4}, {4, 5}, {5, 3}, {3, 2}}

	for _, v := range pattern {

		if d.val[v[0]] == a && d.val[v[1]] == b || d.val[v[1]] == a && d.val[v[0]] == b {
			return true
		}

	}

	return false

}

func (d Dice) isFrontDirectionW(a, b int) bool {

	pattern := [][]int{{1, 2}, {2, 6}, {6, 5}, {5, 1}}

	for _, v := range pattern {

		if d.val[v[0]] == a && d.val[v[1]] == b {
			return true
		}

	}

	return false

}

func (d Dice) isFront(a, b int) bool {
	return d.val[1] == a && d.val[2] == b
}

func (d Dice) changeFront(a, b int) {
	for !d.isFrontDirection(a, b) {
		d.Slide("L")
	}

	for !d.isFrontDirectionW(a, b) {
		d.Throw("W")
	}

	for !d.isFront(a, b) {
		d.Throw("S")
	}
}

func main() {

	dice := NewDice()

	fmt.Scan(&dice.val[1], &dice.val[2], &dice.val[3], &dice.val[4], &dice.val[5], &dice.val[6])

	var q int

	fmt.Scan(&q)

	put := make([]int, q)

	for i := 0; i < q; i++ {

		var a, b int

		fmt.Scan(&a, &b)

		dice.changeFront(a, b)

		put[i] = dice.val[3]
	}

	for i := 0; i < q; i++ {
		fmt.Println(put[i])
	}
}



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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, p;
string s, t;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	vpll a;
	for(ll i=0;i<n;i++) {
		cin>>x>>k;
		a.pb({x,k});
	}
	sort(all(a));
	reverse(all(a));

	cout<<a[0].f + a[0].s;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define output(x) cout<<x<<endl;
#define fre(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define frd(i, a, b) for (int i = (int)(a); i >= b; --i)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int,int> > vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

const int maxn = 110000;

stack<int>s;
vi v[maxn];
int ans[maxn];
bool visited[maxn];

void dfs(int id){
	visited[id]=1;
	for(auto i:v[id]){
		if(!visited[i]) dfs(i);
	}
	s.push(id);
}

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);	
	int n,m;
	cin>>n>>m;
	for (int i = 0; i < m; ++i)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}
	fre(i,1,n){
		if(visited[i]) continue;
		dfs(i);
	}
	int tot=0;
	while(!s.empty()){
		int curr=s.top();
		s.pop();
		for(auto i:v[curr]){
			ans[i]=max(ans[i],1+ans[curr]);
		}
	}
	fre(i,1,n){
		tot=max(tot,ans[i]);
	}
	output(tot);
	return 0;
}

Measured memory_bytes: 8960
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]){
        int l=0;
        long l3=0;
        double v=0.0;

        scanf("%d", &l);
        l3 = l*l*l;
        v = l3/27.0;
        printf("%.12lf\n", v);
        return 0;

}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct UnionFind {
  vector<int> data;
  UnionFind(int n):data(n, -1){}
  int find(int x){ return data[x] < 0 ? x : data[x] = find(data[x]); }
  bool same(int x, int y){ return find(x) == find(y); }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return false;
    if(data[x] < data[y]) swap(x, y);
    data[x] += data[y]; data[y] = x;
    return true;
  }
};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, k, l;
  cin >> n >> k >> l;
  UnionFind road(n);
  rep(i, k) {
    int p, q;
    cin >> p >> q;
    --p, --q;
    road.unite(p, q);
  }
  UnionFind line(n);
  rep(i, l) {
    int r, s;
    cin >> r >> s;
    --r, --s;
    line.unite(r, s);
  }
  map<pair<int, int>, int> mp;
  rep(i, n) {
    mp[make_pair(road.find(i), line.find(i))]++;
  }
  rep(i, n) {
    if(i) cout << " ";
    cout << mp[make_pair(road.find(i), line.find(i))];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 15104
import sys

def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし

L = LI2()
l = len(L)
mod = 10**9+7

A = []
for i in range(l):
    if L[i] == 1:
        A.append(l-i-1)
A.append(0)

ans = 0
for i in range(len(A)):
    ans += pow(3,A[i],mod)*pow(2,i,mod)
    ans %= mod

print(ans)

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

int main() {
  string S, T;
  cin >> S >> T;
  bool a = true;
  char s, t;
  
  for (int i = 0; i < S.size(); i++) {
    s = S.at(i);
    t = T.at(i);
    if (s != t) {
      a = false;
    }
  }
  
  if (a) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}

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

bool compare(const pair<int,int> &a,const pair<int,int> &b){
    return a.first<b.first;
}

int main()
{
    int i,j,k,n; cin>>n;
    vector<pair<int,int>> vec;
    for(i=0;i<n;i++)
    {
        int a,b;cin>>a>>b;
        vec.push_back(make_pair(b,a));
    }
    sort(vec.begin(),vec.end());
    int s=0; bool f=true;
    sort(vec.begin(),vec.end());

    for(i=0;i<n;i++)
    {
        s+=vec[i].second; if(vec[i].first<s) {f=false; break;}
    }
    cout<<(f ? "Yes":"No");



    return 0;

}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
typedef long long ll;
typedef long double ld;
const int MAXN = 200005;
int par[MAXN], P[MAXN], V[MAXN];
ll num0[MAXN], num1[MAXN], val[MAXN];
int root(int a) {
	if (par[a] == a) return a;
	return par[a] = root(par[a]);
}
struct cmp {
	bool operator()(int a, int b) {
		ll va = num0[a] * num1[b], vb = num0[b] * num1[a];
		if (va != vb) return va > vb;
		return a < b;
	}
};
int main() {
	int N;
	scanf("%d", &N);
	for (int i = 2; i <= N; ++i) scanf("%d", &P[i]);
	for (int i = 1; i <= N; ++i) scanf("%d", &V[i]);
	for (int i = 1; i <= N; ++i) {
		par[i] = i;
		if (V[i] == 1) ++num1[i];
		else ++num0[i];
	}
	set<int, cmp> S;
	for (int i = 2; i <= N; ++i) {
		S.insert(i);
	}
	while (!S.empty()) {
		int x = *S.begin();
		S.erase(S.begin());
		int y = root(P[x]);
		S.erase(y);
		par[x] = y;
		val[y] += val[x] + num1[y] * num0[x];
		num0[y] += num0[x];
		num1[y] += num1[x];
		if (y != 1) S.insert(y);
	}
	printf("%lld\n", val[1]);
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 2e5 + 5;
int st[maxn], tot;
int a[maxn];
int n;
int L[maxn], R[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    tot = 0;
    st[++tot] = 0;
    a[0] = 0;
    for(int i = 1;i <= n;i++){
        while(tot > 0 and a[st[tot]] > a[i]){
            tot--;
        }
        L[i] = st[tot] + 1;
        st[++tot] = i;
    }
    a[n + 1] = 0;
    tot = 0;
    st[++tot] = n + 1;
    for(int i = n;i >= 1;i--){
        while(tot > 0 and a[st[tot]] > a[i]){
            tot--;
        }
        R[i] = st[tot] - 1;
        st[++tot] = i;
    }
    ll ans = 0;
    for(int i = 1;i <= n;i++){
        ans += 1LL * a[i] * (i - L[i] + 1) * (R[i] - i + 1);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	get(a);
	get(b);
	get(c);

	cout << (a*b)/2 << endl;

	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N;
  cin >> N;
  bool a[110]={0};
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      a[i*j] = true;
    }
  }
  if(a[N]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
ll N, C;
ll x[100003], v[100003], r[100003], l[100003];

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

  cin >> N >> C;
  rep(i,N) cin >> x[i] >> v[i];

  ll ans = 0;

  // r[i]はOから反時計回りのvalueの総和
  // l[i]はOから時計回りのvalueの総和

  // 一回も折り返さなかった時の場合
  ll y = 0, z = 0;
  rep(i,N) {
    y += v[i];
    z += v[N-1-i];
    r[i+1] = max(r[i], y - x[i]);
    l[i+1] = max(l[i], z - (C - x[N-i-1]));
    ans = max(ans, max(r[i+1], l[i+1]));
  }

  // 一回折り返した時の場合
  y = 0, z = 0;
  rep(i,N) {
    y += v[i];
    z += v[N-1-i];
    ans = max(ans, y - 2*x[i] + l[N-i-1]);
    ans = max(ans, z - 2*(C - x[N-1-i]) + r[N-i-1]);
  }

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


Measured memory_bytes: 3328
x1, y1, x2, y2 = gets.split(' ').map(&:to_i)
diff_x = x2 - x1
diff_y = y2 - y1
x3 = x2 - diff_y
x4 = x1 - diff_y
y3 = y2 + diff_x
y4 = y1 + diff_x

puts "#{x3} #{y3} #{x4} #{y4}"

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int main() {
    int n, w; cin >> n >> w;
    vector<pair<int, int>> ns(n); // value, weight
    for (auto &x: ns) cin >> x.first >> x.second;

    vector<vector<int>> memo(n+1, vector<int>(w+1, 0));

    for (int i=0; i<n; i++) {
        for (int l=0; l<w+1; l++) {
            if (l-ns[i].second >= 0) {
                memo[i+1][l] = max(memo[i][l], memo[i][l-ns[i].second]+ns[i].first);
            } else {
                memo[i+1][l] = memo[i][l];
            }
        }
    }

    /*
    for (auto line: memo) {
        for (auto value: line) {
            cout << setw(4) << value;
        }
        cout << endl;
    }
    */

    cout << memo[n][w] << endl;
}



Measured memory_bytes: 6840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.ArrayList;
 
public class Main {
	public static void main(String args[])throws IOException  {
 
	
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		long ans = -1;
		long n=in.nextInt();
		long p=in.nextInt();
		String s = in.nextString();
		String t = in.nextString();

		
		ans = findAns(n,p,s,t);
		
		//ans = findAns(n,p,out);

		out.print(ans);
		out.close();
	}

	static long findAns(long n,long p, String s, String t){
		long ans = -1;
		boolean findSame = true;		
		long gcd = gcd(n,p);
		long lcm = n*p/gcd;
		
		n=n/gcd;
		p=p/gcd;
		for(int i=0; i<gcd;i++){
			if(s.charAt((int)n*i) != t.charAt((int)p*i)){
				findSame = false;
				break;
			}
		}
		if(findSame)
			ans = lcm;
		else
			ans = -1;		
		
		return ans;
	}
	
    static long gcd(long a, long b) 
    { 
        return b>0?gcd(b, a%b):a; 
    } 

    static long lcm(long a, long b) 
    { 
        return (a*b)/gcd(a, b); 
    } 

	
	
	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;
 
		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}
 
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
 
		public long nextLong() {
			return Long.parseLong(nextString());
		}
 
		public double nextDouble() {
			return Double.parseDouble(nextString());
		}
 
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}
 
		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}
 
		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}
 
		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}
 
		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}
 
		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}
 
		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}
 
		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}
 
	
}


Measured memory_bytes: 25172
a = int(input())
y=[]
# for i in range(0, 100000):
	# y.append(1000000000000000000)
x = list(map(int, input().split())) 
x.sort()
# for i in x:


	# print(i)
prod=1
f=0
for i in x:
	prod*=i
	if(prod>1000000000000000000):
		f=1
		print(-1)
		break
if(f!=1): 
	print(prod)
# print(prod)
# if(prod>1000000000000000000):
# 	print(-1)
# else: 
# 	print(prod)


Measured memory_bytes: 21700
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;
const ll mod=1000000007;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n;cin>>n;
 bool a[n+10];
 rep(i,1,n+1)sc(a[i]);
 ll box[n+10]={0},c,sum=0;

 rrp(i,n+1,1){
  c=0;
  for(j=2;j*i<=n;j++)c+=box[j*i];
  if(c%2!=a[i]){
   box[i]=1;
   sum++;
  }
 }
 pr(sum);
 rep(i,1,n+1){
  if(box[i]!=0)cout<<i<<" ";
 }
  pnn;
return 0;}


Measured memory_bytes: 5404
from collections import defaultdict


def solve():
    N = int(input())
    X, Y = defaultdict(list), defaultdict(list)
    dx, dy = defaultdict(list), defaultdict(list)
    for i in range(N):
        x, y, U = list(input().split())
        x, y = int(x), int(y)
        X[x].append((y, U))
        Y[y].append((x, U))
        dy[x+y].append((x-y, U))
        dx[x-y].append((x+y, U))
    ans = float("inf")
    for key in X.keys():
        X[key].sort()
        for i in range(1, len(X[key])):
            y1, dir1 = X[key][i-1]
            y2, dir2 = X[key][i]
            if dir1 == "U" and dir2 == "D":
                ans = min(ans, 5*y2-5*y1)
    for key in Y.keys():
        Y[key].sort()
        for i in range(1, len(Y[key])):
            y1, dir1 = Y[key][i-1]
            y2, dir2 = Y[key][i]
            if dir1 == "R" and dir2 == "L":
                ans = min(ans, 5*y2-5*y1)
    for key in dx.keys():
        dx[key].sort()
        for i in range(1, len(dx[key])):
            y1, dir1 = dx[key][i-1]
            y2, dir2 = dx[key][i]
            if (dir1 == "U" and dir2 == "L") or (dir1 == "R" and dir2 == "D"):
                ans = min(ans, 5*y2-5*y1)
    for key in dy.keys():
        dy[key].sort()
        for i in range(1, len(dy[key])):
            y1, dir1 = dy[key][i-1]
            y2, dir2 = dy[key][i]
            if (dir1 == "R" and dir2 == "U") or(dir1 == "D" and dir2 == "L"):
                ans = min(ans, 5*y2-5*y1)
    if ans == float("inf"):
        print("SAFE")
    else:
        print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 186152
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;

int main(){
	vector<int>a;
	int n;
	bool v = true;
	int x, y, z;
	int k, s, ans;
	k = 0;
	s = 0;
	ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &x);
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	ans++;
	for (int i = 1; i < n; i++){
		if (a[i] > a[i - 1])ans++;
	}

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

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
x,b = [0]+a+[0],0
for i in range(1,n+2):
  b += abs(x[i]-x[i-1])
for i in range(n):
	if x[i]<=x[i+1]<=x[i+2] or x[i]>=x[i+1]>=x[i+2]: print(b)
	else: print(b-(abs(x[i]-x[i+1])+abs(x[i+2]-x[i+1]))+abs(x[i+2]-x[i]))

Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(ll i=(a);i<=(b);i++)
#define repi(i,n) fori(i,0,(n)-1)
#define forr(i,a,b) for(ll i=(b);i>=(a);i--)
#define repr(i,n) forr(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

void solve(){
    ll n,m;
    cin>>n>>m;
    vec a(n);
    repi(i,n)cin>>a[i];
    
    ll g=a[0]/2;
    repi(i,n)g=lcm(g,a[i]/2);
    repi(i,n){
        if(g%a[i]==0){
            cout<<0<<endl;
            return;
        }
    }
    cout<<(g+m)/(2*g)<<endl;
}

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


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


Measured memory_bytes: 25196
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 1001;
const int V = 5001;

int n;
vector <int> a, v[N];

pair <int, int> dfs(int node){
    vector <int> dp(V);
    dp[0] = 1;
    int all = 0;
    for(auto &i : v[node]){
        auto cur = dfs(i);
        all += cur.first + cur.second;
        vector <int> new_dp(V);
        for(int i = 0 ; i < V ; i++){
            for(auto &j : {cur.first, cur.second}){
                if(i >= j && dp[i - j]) new_dp[i] = 1;
            }
        }
        swap(dp, new_dp);
    }
    int h = -1;
    for(int i = a[node] ; i >= 0 ; i--){
        if(dp[i]){
            h = i;
            break;
        }
    }
    if(h == -1){
        cout << "IMPOSSIBLE" << endl;
        exit(0);
    }
    h = all - h;
    return make_pair(a[node], h);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1 ; i < n ; i++){
        int x;
        cin >> x;
        x--;
        v[x].push_back(i);
    }
    a.resize(n);
    for(auto &i : a) cin >> i;
    dfs(0);
    cout << "POSSIBLE" << endl;
}


Measured memory_bytes: 11804
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define N 100010
ll X,K,e[N],p[N],q;
struct qry{
    ll t,a,id;
    bool operator<(const qry&key)const{
        return this->t<key.t;
    }
};
qry qs[N];
ll ans[N];
int main(){
  cin>>X>>K;
  p[0]=0,e[0]=0;
  for(int i=1;i<=K;i++){
      cin>>e[i];
      if(i%2==1)p[i]=p[i-1]-(e[i]-e[i-1]);
      if(i%2==0)p[i]=p[i-1]+(e[i]-e[i-1]);
  }
  cin>>q;
  for(int i=0;i<q;i++){
      qs[i].id=i;
      cin>>qs[i].t>>qs[i].a;
  }
  sort(qs,qs+q);
  ll u=0,v=X;
  for(int i=0,j=1;i<q;i++){
      for(;j<=K&&e[j]<=qs[i].t;j++){
          if(j%2==1){
              u-=(e[j]-e[j-1]); chmax(u,0LL);
              v-=(e[j]-e[j-1]); chmax(v,0LL);
          }
          if(j%2==0){
              u+=(e[j]-e[j-1]); chmin(u,X);
              v+=(e[j]-e[j-1]); chmin(v,X);
          }
      }
      ll ideal=qs[i].a+p[j-1];
      //cout<<qs[i].t<<" "<<qs[i].a<<":"<<ideal<<" "<<u<<" "<<v<<endl;
      chmin(ideal,v);
      chmax(ideal,u);
      if(j%2==1)ideal-=qs[i].t-e[j-1];
      if(j%2==0)ideal+=qs[i].t-e[j-1];
      chmin(ideal,X);
      chmax(ideal,0LL);
      ans[qs[i].id]=ideal;
  }
  for(int i=0;i<q;i++){
      cout<<ans[i]<<endl;
  }
  return 0;
}


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

int main(void) {
  std::string s;
  std::cin >> s;
  bool c[4] = {false, false, false, false};
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'N') c[0] = true;
    if (s[i] == 'W') c[1] = true;
    if (s[i] == 'S') c[2] = true;
    if (s[i] == 'E') c[3] = true;
  }
  if (!c[0] && !c[2]) c[0] = c[2] = true;
  if (!c[1] && !c[3]) c[1] = c[3] = true;
  
  if (c[0] && c[1] && c[2] && c[3]) std::cout << "Yes \n";
  else std::cout << "No \n";
  
  return 0;
}
  

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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
    ll MAX_A = 2000007;
    
    ll n;cin>>n;
    ll tmp;
    vector<ll>a(MAX_A,0);
    
    rep(i,n){
        cin>>tmp;
        a[tmp]+=1;
    }
    
    for(ll i=1;i<=MAX_A;++i){
        if(a[i]>=1){
          ll res = i;
            for(ll j = 2;j*res<=MAX_A;++j){
                a[j*res]=0;
            }
//            if(a[i]>=2)a[i]=0;
        }
    }
    rep(i,a.size())if(a[i]>=2)a[i]=0;
    ll ans = 0;
    rep(i,a.size())ans+=a[i];
    
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 18832
i=1
n=int(input())
for i in range(1,n+1):
    a,b,c=map(int,input().split())
    if a==0 or b==0 or c==0:
        break
    else:
        if a>b:
            a,b=b,a
        else:
            a,b=a,b
        if b>c:
            b,c=c,b
        else:
            b,c=b,c
        if a>b:
            a,b=b,a
        else:
           a,b=a,b
        if a**2+b**2==c**2:
            print("YES")
        else:
            print("NO")


Measured memory_bytes: 5596
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    int ans = 2*n;
    rep(i,n+1){
        string k = s.substr(0,i)+t;
        if (k.substr(0,n) == s) chmin(ans,(int)k.length());
    }
    PRINT(ans);
}


Measured memory_bytes: 3596
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int maxn;
int main()
{         
	int n;
	cin>>n;
	string a;
	cin>>a;
	int ans=0;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]=='I')ans++;
		else if(a[i]=='D') ans--;
		
		if(maxn<ans) maxn=ans;
	}
	cout<<maxn;
	return 0; 
}

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

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

	if (d == 25) cout << "Christmas" << endl;
	else if (d == 24) cout << "Christmas Eve" << endl;
	else if (d == 23) cout << "Christmas Eve Eve" << endl;
	else cout << "Christmas Eve Eve Eve" << endl;

	return 0;
}

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

#define NIL -1

int dp[100];

int fib(int n){
    if(dp[n] == NIL) dp[n] = fib(n-1) + fib(n-2);
    return dp[n];
}

int main(){
    int n;
    cin >> n;
    for(int i=0; i<100; i++){
        dp[i] = NIL;
    }
    dp[0] = 1;
    dp[1] = 1;
    for(int i=0; i<n; i++){
        fib(i);
    }
    cout << fib(n) << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
//#define int long long

signed main(){
    int a[5];
    rep(i,5) cin >> a[i];
    
    int min = -1;
    rep(i,5){
        if(a[i] % 10 == 0) continue;
        if(min == -1) min = i;
        else if(a[min] % 10 > a[i] % 10) min = i;
    }
    
    int ans = 0;
    rep(i,5){
        if(i == min) continue;
        ans += ceiv(a[i], 10) * 10;
    }
    
    cout << ans + (min != -1 ? a[min] : 0) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define t 1000000

int x[t], n;

int search(int key) {
	
	int mid;
	
	int left = 0;
	
	int right = n;
	
	while(left < right) {
		mid = (left + right ) / 2;
		if( x[mid] == key) {
			return 1;
		}
		if ( key > x[mid] ) {
			left = mid + 1;
		} else if( key < x[mid] ) {
			right = mid;
		}
	}
		return  0;
}

int main() {
	int i, q, l, sum = 0;
	
	scanf("%d", &n);
	for( i = 0; i < n; i++) {
		scanf("%d",&x[i]);
	}
	
	scanf("%d", &q);
	for( i = 0; i < q; i++) {
		scanf("%d", &l);
		if( search( l )) {
			sum = sum + 1;
		}
	}
	printf("%d\n", sum);
	
	return 0;
	
}

Measured memory_bytes: 2080
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);    
    long long a,b;
    cin>>a>>b;
    cout<<a*b/euclidean_gcd(a,b);

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>

#include <stdio.h>
#include <math.h>

using namespace std;

int main(){

    int N;
    int per_num = 0;
    double sum_len = 0.0;
    double point[8][2];
    int permutation[8];

    cin >> N;

    iota(permutation, permutation+8, 0);

    for(int i = 0; i < N; i++){
        cin >> point[i][0] >> point[i][1];
    }

    do{

        per_num++;

        for(int i = 0; i < N - 1; i++){
            sum_len += sqrt(pow(point[permutation[i+1]][0]-point[permutation[i]][0], 2.0) + pow(point[permutation[i+1]][1]-point[permutation[i]][1], 2.0));
        }
    }while(next_permutation(permutation, permutation+N));

    printf("%.10lf\n", sum_len / per_num);

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i32 n, m; cin >> n >> m;
  vi64 a(n); rep(i, n) cin >> a[i];
  vi64 sums(n + 1, 0);
  rep(i, n) sums[i + 1] = (sums[i] + a[i]) % m;
  map<i64, i64> mp;
  rep(i, n + 1) mp[sums[i]]++;
  i64 ans = 0;
  for (auto v: mp) {
    ans += v.second * (v.second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


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

namespace Atcoder
{   
   class B
   { 
     static void Main(string[] args)
     {  
       int N = int.Parse(Console.ReadLine());
       
       string[] token = Console.ReadLine().Split();
       
       int[] a = new int[N];
       
       for(int i=0;i<N;i++){
         a[i] = int.Parse(token[i]);
       }
       
       Array.Sort(a);
       int As = 0;
       int Bs = 0;
       bool even = N%2==0;
       for(int i=N-1;i>=0;i--){
           if(i%2==0){
             As += a[i];
           }else{
             Bs += a[i];
           }
       }
       
       Console.WriteLine(Math.Abs(As-Bs));
     }
   }
}

Measured memory_bytes: 11092
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(Q)]

ans = 0
for A in combinations_with_replacement(range(1, M+1), N):
  tmp = 0
  for a, b, c, d in query:
    if A[b-1] - A[a-1] == c:
      tmp += d
  ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

void solve(int tc) {
	long double r;
	cin>>r;
	cout<<6.283185*r<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    for(int tc=1; tc<=t; ++tc) {
        solve(tc);
    }    
    return 0;
}

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

using namespace std;
typedef long long LL;

#define MAXN 200001
#define MOD 1000000007

int N;
int A[MAXN];
int B[MAXN];

int main(int argc, char** argv) {
#ifdef OJ	
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false);

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

    int mx = 0;
    for (int i = 0; i < N; i++) {
        int a = A[i];
        B[a] = B[a-1] + 1;
        mx = max(mx, B[a]);
    }

    cout << N - mx << endl;
    return 0;
} 

Measured memory_bytes: 1920
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
else:
  print(x)
  exit()
  
def arimasuka(num,sign):
  if num in p:
    k=arimasuka(num+sign,sign)
  else:
    return num
  return k

p.sort()
ans1=arimasuka(x,1)
ans2=arimasuka(x,-1)
if abs(ans1-x)>=abs(ans2-x):
  print(ans2)
  exit()
else:
  print(ans1)
  exit()

Measured memory_bytes: 9196
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = N // 4 + 1
    B = N // 7 + 1

    for a in range(A):
        for b in range(B):
            if a * 4 + b * 7 == N:
                print('Yes')
                exit()
    else:
        print('No')


if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  int m =99999;
  for(int i=1;i<N;i++){
    int a =i;
    int b= N-i;
    int da=0,db=0;
    while (a>0) {
      da += a%10;
      a /= 10;
    }
    while (b>0) {
      db += b%10;
      b /= 10;
    }
    m = min(m, da+db);
    //cout << i <<endl;
  }
  cout << m <<endl;

  }


Measured memory_bytes: 256
import math
import statistics

n = int(input())

xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

p1 = 0
p2 = 0
p3 = 0
plist = []

for x, y in zip(xlist, ylist):
    p1 += abs(x - y)
    p2 += (abs(x - y)**2)
    p3 += (abs(x - y)**3)
    plist.append(abs(x - y))

p2 = math.sqrt(p2)
p3 = math.pow(p3, 1/3)
p4 = max(plist)

print(p1)
print(p2)
print(p3)
print(p4)


Measured memory_bytes: 6932
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#define N 1001
using namespace std;
int n;
struct node {int x,y,h;}p[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].h);
	for(int Cx=0;Cx<=100;Cx++)
		for(int Cy=0;Cy<=100;Cy++)
		{
			bool flag=1;int mn=2000000000,H=-1;
			for(int i=1;i<=n;i++)
				if(p[i].h==0)mn=min(mn,abs(p[i].x-Cx)+abs(p[i].y-Cy));
				else if(H==-1)H=p[i].h+abs(p[i].x-Cx)+abs(p[i].y-Cy);
				else if(H!=p[i].h+abs(p[i].x-Cx)+abs(p[i].y-Cy))flag=0;
			if(!flag)continue;if(mn<H)continue;
			if(H==-1)H=mn; if(H<1)continue;
			printf("%d %d %d\n",Cx,Cy,H);exit(0);
		}
}

Measured memory_bytes: 256
N=int(input())
a=[]
a=input().split()
cnt=3**N
b=[]
for i in range(N):
    if int(a[i])%2==0:
        b.append(2)
    else:
        b.append(1)
ans=1
for i in range(N):
    ans*=b[i]
print(cnt-ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

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

ll N;
string S;

bool check(ll idx, const V<char> &lis) {
    ll pre = (idx - 1 + N) % N;
    ll nxt = (idx + 1) % N;
    return lis[idx] == 'S' ? (S[idx] == 'o' ? lis[pre] == lis[nxt] : lis[pre] != lis[nxt])
                           : (S[idx] == 'o' ? lis[pre] != lis[nxt] : lis[pre] == lis[nxt]);
}

bool check_list(ll idx, V<char> &result) {
    if(idx == N) return check(N - 1, result) && check(0, result);
    result[idx] = 'S';
    if(check(idx - 1, result)) {
        return check_list(idx + 1, result);
    } else {
        result[idx] = 'W';
        return check_list(idx + 1, result);
    }
}

int main() {
    init_io();
    cin >> N >> S;
    for(ll i = 0; i <= 1; i++) {
        for(ll j = 0; j <= 1; j++) {
            V<char> result(N);
            result[0] = (i == 0 ? 'S' : 'W');
            result[1] = (j == 0 ? 'S' : 'W');
            if(check_list(2, result)) {
                for(char c : result) cout << c;
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,i;
    cin>>n>>i;
    cout<<n-i+1<<endl;
 
    return 0;
}

Measured memory_bytes: 256