akhauriyash/Code-Regression huggingface dataset:
/*input
999
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e5+5;
const ll maxlg=__lg(maxn)+2; 
int main(){
	double n;
	cin>>n;
	double x=n/3,y=n/3,z=n/3;
	cout<<fixed<<setprecision(10)<<x*y*z;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if(a-b>k || a-c>k || c-a>k|| a-d>k || d-a>k|| a-e>k || e-a>k || b-c>k || c-b>k || b-d>k || d-e>k || b-e>k || e-b>k || c-d>k || d-c>k || c-e>k || e-c>k || d-e>k || e-d>k)
    {
        cout<<":("<<endl;
        return 0;
    }
    else
        {
            cout<<"Yay!"<<endl;
            return 0;
        }
    }


Measured memory_bytes: 3596
<?php  
list($n, $total) = explode(' ', trim(fgets(STDIN))); 
//list($n, $total) = str_split(trim(fgets(STDIN)), 2);

$sum_ratio = 0;
for($i = $n; $i > 0; $i--){
  $curr_total = $i;
  $a = 1/$n;
  //for($j = 1; $j < 50; $j++){
  while(true){
    if($total > $curr_total){
      $curr_total *= 2;
      $a *= (1/2);
    }else{
     break;
    }
  }
  $sum_ratio += $a;
}
        printf($sum_ratio);


?>

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

int main(){
    int l,r;
    cin >> l >> r;
    int ans = 2019;
    if (r < l + 2019){
        for (int i=0;i<=r-l;i++){
            for (int j=i+1;j<=r-l;j++){
                int le = (l+i) % 2019;
                int re = (l+j) % 2019;
                ans = min(ans, le * re % 2019);
            }
        }
    }
    else{
        ans = 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
    ll n,suma=0,sumb=0;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    REP(i,0,n){
        cin>>a[i];
        suma+=a[i];
    }
    REP(i,0,n){
        cin>>b[i];
        sumb+=b[i];
        c[i]=a[i]-b[i];
    }
    if(suma<sumb){cout<<-1<<ENT;return 0;}
    
    ll tarinai=0,ans=0;
    SORTV(c);
    for(ll i=0; c[i]<0; ++i){
        tarinai += c[i];
        ans++;
    }
    reverse(ALL(c));
    for(ll i=0; tarinai<0; ++i){
        tarinai += c[i];
        ans++;
    }
    cout<<ans<<ENT;
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int satisfaction = a * c;
        System.out.println(satisfaction <= b ? c : b / a);
    }
}


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

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

int main() {

    int k; cin >> k;

    int d[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cout << d[k-1] << endl;
}

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

int main() {
  int a, b , k;
  cin >> a >> b;
  rep(i, 1000000000) {
    if (abs(a - i) == abs(b - i)) {
    cout << i << endl;
    return 0;
  }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

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

int main(){

        ios::sync_with_stdio(false);
        cin.tie(0);
	
	int n;
	cin >> n;
	
	double ans= 2*M_PI*n;
	cout<<setprecision(14)<<ans;
	


	return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int s = 0;
    int div = 1;
    while(n/div > 0){
        s += (n/div)%10;
        div *= 10;
    }
    cout << (n%s == 0 ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<string>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())

int main(){
	int n;
	cin>>n;
	vi b(10010);
  REP(i,1,n) cin>>b[i];
  b[0]=b[1];
  b[n]=b[n-1];
  int ans=0;
  rep(i,n){
    ans+=min(b[i],b[i+1]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;


int main()
{
  ll s;
  cin>>s; 
  vector<vector<ll>> dp(s+10,vector<ll>(s+10,0));

  // init
  for (int j = 3; j <= s; ++j)
  {
    dp[1][j]=1;
  }
  ll ans=dp[1][s];
  for (int i = 2; 3*i <= s; ++i)
  {
    dp[i][3*i]=1;
    for (int k = 1; 3*i+k <= s; ++k)
    {
      dp[i][3*i+k]=dp[i][3*i+k-1]+dp[i-1][3*i-3+k];
      dp[i][3*i+k]%=mod;
    }
    ans+=dp[i][s]%mod;
    ans%=mod;
  }
  // for (int i = 0; i < dp.size(); ++i)
  // {
  //   for (int j = 0; j < dp[i].size() ; ++j)
  //   {
  //     cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }

  cout<<ans<<endl;
}

Measured memory_bytes: 34736
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int d(int n,int k){
	if(!n){
		return 0;
	}
	else {
		return 1 + d(n/k,k);
	}
}

int32_t main(){
	int n,k;
	cin>>n>>k;
	cout<<d(n,k);
}


Measured memory_bytes: 256
def main():
    """
    1 <= i < j < k <= |T|
    Ti = A
    Tj = B
    Tk = C
    """
    S = input()
    ans = editorial(S)

    print(ans)


def editorial(S):
    MOD = 10 ** 9 + 7
    n = len(S)
    dp = [[0] * (3+1) for _ in range(n+1)]

    for i in range(n, -1, -1):
        for j in range(3, -1, -1):
            if i == n:
                x = int(j == 3)
                # ≠3: 丸を3個つける前に最後の文字まで見終わってしまい、手遅れ
                # =3: 処理が正常終了
                dp[i][j] = x
            else:
                m1 = 1
                if S[i] == "?":
                    m1 = 3

                if j == 3:
                    # 丸は3個つけ終わったので、あとは?を置換するのみ
                    dp[i][j] = m1 * dp[i+1][j]
                else:
                    m2 = int(S[i] == "?" or S[i] == "ABC"[j])
                    # 前半:i文字目に丸をつけない場合, 後半:丸をつける場合に対応
                    dp[i][j] = m1 * dp[i+1][j] + m2 * dp[i+1][j+1]

                dp[i][j] %= MOD

    ans = dp[0][0]
    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 27588
#include <bits/stdc++.h>
using namespace std;
 
using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);
 
int main () {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll a;
  cin >> a;
  // vector<ll> A(n);
  // for (ll i = 0; i < n; ++i) cin >> A[i];
  cout << (a + a*a + a*a*a) << endl;
  

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9+7;
ll n;
string x;
ll dp[3001][3001];

int main() {
    cin >> n;
    cin >> x;
    
    dp[1][1] = 1;
    for(ll i = 2 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= i-1 ; j++)
        {
            dp[i-1][j] += dp[i-1][j-1];
            if(dp[i-1][j] >= mod)
            dp[i-1][j] -= mod;
        }
        for(ll j = 1 ; j <= i ; j++)
        {
            if(x[i-2] == '<')
            {
                dp[i][j] += dp[i-1][j-1];
                if(dp[i][j] >= mod)
                dp[i][j] -= mod;
            }
            else
            {
                ll temp = (dp[i-1][i-1]-dp[i-1][j-1]);
                if(temp < 0)
                temp += mod;
                dp[i][j] += temp;
                if(dp[i][j] >= mod)
                dp[i][j] -= mod;
            }
        }
    }
    ll ans= 0;
    for(ll i = 1; i <= n ; i++)
    {
        ans += dp[n][i];
        if(ans >= mod)
        ans -= mod;
    }
    cout << ans;
}


Measured memory_bytes: 49772
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
// const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
const ll MOD = 998244353;

ll ppow(ll a, ll b) {
  a %= MOD;
  ll res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % MOD;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}

const int MAX = 1010101;

long long fac[MAX], finv[MAX], inv[MAX];

void binom_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long binom(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll N, M, K;

int main() {
  binom_init();
  cin >> N >> M >> K;

  ll ans = 0;
  for (ll k = K; k >= 0; --k) {
    ll comb = binom(N - 1, k);
    ll patterns = M * ppow(M - 1, N - k - 1) % MOD;
    ll add = comb * patterns % MOD;
    ans += add;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 27312
#include <stdio.h>

int main(void) {
	double x[4],y[4];
	int yes;
	while(1) {
		if(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
			&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])==-1)break;
		if(x[0]==x[1]) {
			if(y[2]==y[3])yes=1; else yes=0;
		} else if(x[2]==x[3]) {
			if(y[0]==y[1])yes=1; else yes=0;
		} else {
			if(((y[0]-y[1])/(x[0]-x[1]))*((y[2]-y[3])/(x[2]-x[3]))==-1)
				yes=1;
			else yes=0;
		}
		printf("%s\n",yes?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>

#define MAX 10000
#define NIL -1

using namespace std;

struct Node {
	int parent, left, right;
};

Node *binaryTree;

void PreParse (int id) {
	if (id == NIL) {
		return;
	}

	printf(" %d",id);

	PreParse(binaryTree[id].left);
	PreParse(binaryTree[id].right);
}

void InParse (int id) {
	if (id == NIL) {
		return;
	}

	InParse (binaryTree[id].left);
	printf (" %d", id);
	InParse (binaryTree[id].right);
}

void PostParse (int id) {
	if (id == NIL) {
		return;
	}

	PostParse (binaryTree[id].left);
	PostParse (binaryTree[id].right);
	
	printf (" %d", id);
}

int main() {
	int n;
	cin >> n;
	binaryTree = new Node[n];

	for (int i = 0; i < n; i++) {
		binaryTree[i].parent = NIL;
	}

	int id, left, right;
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &id, &left, &right);

		binaryTree[id].left = left;
		binaryTree[id].right = right;

		if (left != NIL) {
			binaryTree[left].parent = id;
		}
		if (right != NIL) {
			binaryTree[right].parent = id;
		}
	}

	int root = 0;
	for (int i = 0; i < n; i++) {
		if (binaryTree[i].parent == NIL) {
			root = i;
		}
	}

	printf("Preorder\n");
	PreParse(root);
	cout << endl;
	printf ("Inorder\n");
	InParse (root);
	cout << endl;
	printf ("Postorder\n");
	PostParse (root);
	cout << endl;


	return 0;
}


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  vector<vector<int>> c(3,vector<int>(3)); REP(i,3) REP(j,3) cin>> c[i][j];
  vector<int> a(3), b(3); a[0] = 0;
  REP(i,3) b[i] = c[0][i] - a[0];
  a[1] = c[1][0] - b[0]; a[2] = c[2][0] - b[0];
  bool f = true;
  REP(i,3) REP(j,3) {
    if (c[i][j] != a[i] + b[j]) f = false;
  }
  if (f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys



def solve(vals, queries):
    nv = len(vals)
    nq = len(queries)
    # get freqs
    freqs = {}
    tot0 = 0
    for v in vals:
        if not v in freqs:
            freqs[v] = 1
        else:
            freqs[v] += 1
        tot0 += v

    for b,c in queries:
        if b in freqs:
            tot0 += freqs[b]*(c-b)
            if not c in freqs:
                freqs[c] = 0
            freqs[c] += freqs[b]
            del freqs[b]
        print(tot0)
        

        


if __name__ == '__main__':
    IN = [x.strip() for x in sys.stdin.readlines()]

    N = int(IN[0])
    vals = [int(x) for x in IN[1].split(' ')]
    Q = int(IN[2])
    queries = []
    for i in range(Q):
        b,c = [int(x) for x in IN[3+i].split(' ')]
        queries.append((b,c))
    solve(vals, queries)


Measured memory_bytes: 106316
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
map<string,int> mp;
vector<string> ans;
int main(){
	int Max=0, N;
	cin>>N;
	for(int i=0;i<N;i++){
		string s;
		cin>>s;
		mp[s]++;
		if(mp[s]>=Max){
			if(mp[s]>Max) ans.clear();
			ans.push_back(s);
			Max=mp[s];
		}
	}
	sort(ans.begin(),ans.end());
	for(string s : ans) cout<<s<<'\n';
}

Measured memory_bytes: 26736
from sys import stdin
import fractions

a,b,k = [int(x) for x in stdin.readline().rstrip().split()]

li = [a,b]
def gcd_all(list):
    return gcd_all([fractions.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()  
    return divisors
            
l = gcd_all(li)

lin = make_divisors(l)

print(lin[-1*k])

Measured memory_bytes: 5332
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val sList = (1..n).map { readLine()!!.toCharArray() }
    sList.forEach { it.sort() }
    val sortedList = sList.map { it.joinToString() }.sorted()

    val groupedMap = sortedList.groupBy { it }

    val count = groupedMap.map { calcCombination(it.value.size.toLong()) }.sum()

    println(count)
}

fun calcCombination(n: Long): Long {
    return if (n == 1.toLong()) {
        0
    } else {
        n - 1 + calcCombination(n - 1)
    }
}


Measured memory_bytes: 89936
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define inf 1e18+9
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define umap unordered_map<ll,ll>
#define lpq priority_queue<ll,vector<ll>,greater<ll>>
ll globe=0;
ll powe(ll n,ll r){if(!r)return 1;else if(r%2==0)return powe(n*n,r/2);else return n*powe(n*n,(r-1)/2);}

bool pali(string &a){
    ll i=0,j=a.size()-1;
    while(i<=j){
        if(a[i]!=a[j])
            return false;
        i++;
        j--;
    }
    return true;
}

int32_t main(){
 
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
 
	ll t=1;
	//cin>>t;
	while(t--){
	    double L;
	    cin>>L;
	    cout<<setprecision(7)<<(L/3)*(L/3)*(L/3)<<endl;
	}
 
	return 0;
 
}
//BitMasking->setBit: n|(1<<i); unsetBit: n&!(1<<i); checkBit: n&(1<<i);
//ll idx=upper_bound(v.begin(),v.end(),val)-v.begin();
//v.erase(unique(v.begin(),v.end()),v.end());
//ll cnt=count(v.begin(),v.end(),val);
//bool f=find(v.begin(),v.end(),val);

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
 
int main(){
    int n;
    cin >> n;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for(auto p: mp) mx = max(mx, p.second);
    for(auto p:mp){
        if(p.second != mx)continue;
        else cout << p.first << endl;
    }
    return 0;
}


  

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

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

    if (s[1] == s[2] && (s[0] == s[1] || s[2] == s[3])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)


int n;
int a[101010];
vector<int> G[101010];

bool dfs(int v){
	for (int i = 0; i < G[v].size(); i++){
		int u = G[v][i];
		if ((a[u] < a[v]) && (!dfs(u))) return true;
	}
	return false;
}

int main() {
	cin >> n;
	REP(i, n)cin >> a[i];
	REP(i, n - 1) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		G[x].emplace_back(y);
		G[y].emplace_back(x);
	}
	bool isfirst = true;
	REP(i, n) {
		if (dfs(i)) {
			if (!isfirst) {
				cout << " ";
			}
			cout << i + 1;
			isfirst = false;
		}
	}
	cout << endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

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

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, k, q;

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

  cin >> n >> k >> q;

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

  REP(i, q) {
    int b;
    cin >> b;
    a[b]++;
  }

  FOR(i, 1, n + 1) {
    cout << (k - (q - a[i]) > 0 ? "Yes" : "No") << endl;
  }
}


Measured memory_bytes: 1024
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (std::decay_t<decltype(k)> i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
template <class F>
class fixed_point {
    F f;
    public:
    fixed_point(F&& f_) : f(f_) {}
    template <class... Args> auto operator() (Args... args) { return f(f, args...); }
};
template <class F> auto make_fixed_point(F&& f) { return fixed_point<F>(std::forward<F&&>(f)); }
auto cmn = [](auto& x, auto y){ if (x>y) { x=y; return true; } return false; };
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    u64 n; std::cin >> n;
    vec<vec<diag_pair<u64>>> g(n);
    LOOP (n-1) {
        u64 u, v, w; std::cin >> u >> v >> w, u--, v--;
        g.at(u).emplace_back(v, w);
        g.at(v).emplace_back(u, w);
    }

    u64 ans = 0, min = numr<u64>::max();
    vec<u64> sz(n, 1);
    make_fixed_point([&](auto&& dfs, u64 x, u64 p) -> void {
        bool has_large = false;
        for (auto&& e: g.at(x)) {
            u64 y, w; std::tie(y, w) = e;
            if (y==p) continue;
            dfs(dfs, y, x);
            if (2*sz.at(y)==n) min = w;
            has_large |= n<=sz.at(y)*2;
            ans += w * 2 * std::min(sz.at(y), n - sz.at(y));
            sz.at(x) += sz.at(y);
        }
        if (!has_large && n<2*sz.at(x)) {
            for (auto&& e: g.at(x)) cmn(min, e.second);
        }
    })(0, 0);

    ans -= min;

    std::cout << ans << '\n';
}


Measured memory_bytes: 20816
#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef pair<int,int> P;

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

    vector<set<P> > kugi(N+1);

    for(int i=0; i<=N; ++i) {
        kugi[i].insert(P(0,i+1)); // [0,i+1)
    }

    int ans=0;
    for(int i=0; i<M; ++i) {
        int A,B,X;
        cin >> A >> B >> X;

        for(int j=0; j<=X; ++j) {
            int l=B-1, r=B+j; // [B-1,B+j) is rubber band area
            set<P>::iterator itr=kugi[A+j-1].begin();
            while(!kugi[A+j-1].empty() && itr!=kugi[A+j-1].end()) {
                if(r <= itr->first) break;
                if(itr->second <= l) {
                    ++itr;
                    continue;
                }
                if(l<=itr->first && itr->second<=r) {
                    ans+=itr->second-itr->first;
                    itr=kugi[A+j-1].erase(itr);
                    if(kugi[A+j-1].empty()) {
                        break;
                    }
                } else if(itr->first>=l && itr->second>r) {
                    int temp=itr->second;
                    ans+=r-itr->first;
                    kugi[A+j-1].erase(itr);
                    kugi[A+j-1].insert(P(r,temp));
                    break;
                } else if(itr->first<l && itr->second<=r) {
                    int temp=itr->first;
                    ans+=itr->second-l;
                    itr=kugi[A+j-1].erase(itr);
                    kugi[A+j-1].insert(P(temp,l));
                } else if(itr->first<l && itr->second>r) {
                    int templ=itr->first, tempr=itr->second;
                    ans+=r-l;
                    kugi[A+j-1].erase(itr);
                    kugi[A+j-1].insert(P(templ,l));
                    kugi[A+j-1].insert(P(r,tempr));
                    break;
                }
            }
        }
    }

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


Measured memory_bytes: 4488
import java.util.*;


class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();


        if(n>=10){
            System.out.println(k);
            return;
        }

        int hoge=k+100*(10-n);
        System.out.println(hoge);


    }
}

Measured memory_bytes: 24148
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < static_cast<ll>(n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= static_cast<ll>(n); ++i)
#define RRANGE(i, m, n) for(ll i = static_cast<ll>(m); i >= static_cast<ll>(n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll N;
    in >> N;
    vector<ll> v(N);
    REP(i, N) {
        in >> v[i];
    }
    ll ans = 0;
    std::sort(v.begin(), v.end());
    if (N <= 2) {
        out << 0 << endl;
        return 0;
    }
    REP(i, N-2) RANGE(j, i+1, N-1) RANGE(k, j+1, N-1) {
        if (v[i] != v[j] && v[j] != v[k] && v[k] != v[i] && v[i]+v[j] > v[k]) {
            ans++;
        }
    }
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 3628
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    int n;
    cin >> n;
    int nc2 = n*(n-1)/2;
    v2<int> id = fill(n, n, -1);
    int num = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            id[i][j] = num;
            id[j][i] = num;
            ++num;
        }
    }
    
    v2<int> a = fill(n, n, -1);
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n-1; ++j){
            cin >> a[i][j];
            --a[i][j];
        }
    }

    v2<int> adj(nc2);
    vector<int> indeg(nc2);
    for(int i = 0; i < n; ++i){
        for(int j = 1; j < n-1; ++j){
            int gf = id[i][a[i][j-1]], gs = id[i][a[i][j]];
            adj[gf].push_back(gs);
            ++indeg[gs];
        }
    }

    queue<int> q;
    vector<int> day(nc2,0);
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            int g = id[i][j];
            if(indeg[g]==0){
                q.push(g);
                day[g]=1;
            }
        }
    }

    while(!q.empty()){
        int cur = q.front();
        q.pop();
        for(int next : adj[cur]){
            --indeg[next];
            if(indeg[next]==0){
                q.push(next);
                day[next] = 1+day[cur];
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < nc2; ++i){
        if(day[i]==0){
            cout << "-1\n";
            return;
        }
        ans = max(ans, day[i]);
    }
    cout << ans << '\n';
}

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

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

using namespace std;

string s;

int main(){
  cin >> s;
  int N = s.size();
  
  int counter1 = 0;
  int counter2;
  
  while(true){
    bool flag = false;
    if (s[counter1] == 'A') flag = true;
    if (flag == true) break;
    ++counter1;
  }
  
  for(int i=0; i<N; ++i){
    if (s[i] =='Z') counter2 = i;
  }
  
  int ans = counter2 - counter1;
  
  cout << ans + 1 << endl;
  return 0;
}
    

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define nn 400008
#define pii pair<int,int>
#define mp make_pair
int n,m;int q;pii from[nn],dest[nn];
int ans[nn];
int dir[2][nn];
vector<int> path[2][2];
/*
0...
....
...1

0->
1|
*/
void bb(vector<int> &v)
{
	sort(v.begin(),v.end());
	v.resize(unique(v.begin(),v.end())-v.begin());
}
int lb(int x,vector<int> &v) {if(v.size()==0 or v[0]>x) return x;return v[upper_bound(v.begin(),v.end(),x)-v.begin()-1];}
int ub(int x,vector<int> &v) {if(v.size()==0 or v[v.size()-1]<x) return x;return v[lower_bound(v.begin(),v.end(),x)-v.begin()];}
int trcyx(pii a,pii b) {return abs(a.first-b.first)+abs(a.second-b.second);}

int tot;
vector<int> v[nn],c[nn];
void clear()
{
	for(int i=0;i<=tot;i++) v[i].clear(),c[i].clear();
	tot=0;
}
void link(int x,int y,int w)
{
	v[x].push_back(y);c[x].push_back(w);
}


int dist[nn];
int dj(int x,int y)
{
	for(int i=1;i<=tot;++i) dist[i]=1e9;
	dist[x]=0;priority_queue<pii> pq;pq.push(mp(-dist[x],x));
	while(pq.size()) 
	{
		int z=pq.top().second;//if(pq.top().first!=-dist[x]) {pq.pop();continue;}
		pq.pop();
		for(int i=0;i<v[z].size();i++)
		{
			int w=v[z][i];
			if(dist[w]>dist[z]+c[z][i])
			{
				dist[w]=dist[z]+c[z][i];
				pq.push(mp(-dist[w],w));
			}
		}
	}
	return dist[y];
}
void solve()
{
	for(int i=1;i<=n;i++)
		path[0][dir[0][i]].push_back(i);
	for(int i=1;i<=m;i++)
		path[1][dir[1][i]].push_back(i);
	
	for(int i=1;i<=q;i++)
	{
		clear();
		vector<int> allx,ally;int x,y;
		
		x=from[i].first,y=from[i].second;
		for(int j=0;j<2;j++) allx.push_back(lb(x,path[0][j])),allx.push_back(ub(x,path[0][j]));
		for(int j=0;j<2;j++) ally.push_back(lb(y,path[1][j])),ally.push_back(ub(y,path[1][j]));
		
		
		x=dest[i].first,y=dest[i].second;
		for(int j=0;j<2;j++) allx.push_back(lb(x,path[0][j])),allx.push_back(ub(x,path[0][j]));
		for(int j=0;j<2;j++) ally.push_back(lb(y,path[1][j])),ally.push_back(ub(y,path[1][j]));
		
		
		sort(allx.begin(),allx.end());allx.resize(unique(allx.begin(),allx.end())-allx.begin());
		sort(ally.begin(),ally.end());ally.resize(unique(ally.begin(),ally.end())-ally.begin());
		
		
		map<pii,int> id;
		for(int i=0;i<allx.size();i++)
			for(int j=0;j<ally.size();j++)
				id[mp(allx[i],ally[j])]=++tot;
		
		for(int i=0;i<allx.size();i++)
			for(int j=1;j<ally.size();j++)
			{
				pii a=mp(allx[i],ally[j-1]),b=mp(allx[i],ally[j]);
				if(!dir[0][allx[i]]) swap(a,b);
				link(id[a],id[b],trcyx(a,b));
			}
			
		for(int j=0;j<ally.size();j++)
			for(int i=1;i<allx.size();i++)
			{
				pii a=mp(allx[i-1],ally[j]),b=mp(allx[i],ally[j]);
				if(!dir[1][ally[j]]) swap(a,b);
				link(id[a],id[b],trcyx(a,b));
			}
		
		ans[i]=dj(id[from[i]],id[dest[i]]);
	}
	
}
char buf[nn];
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	scanf("%s",buf+1);for(int i=1;i<=n;i++) dir[0][i]=(buf[i]=='E');
	scanf("%s",buf+1);for(int i=1;i<=m;i++) dir[1][i]=(buf[i]=='S');
	
	for(int i=1;i<=q;i++) ans[i]=1e9,scanf("%d%d%d%d",&from[i].first,&from[i].second,&dest[i].first,&dest[i].second);	
	solve();
	
	for(int i=1;i<=q;i++) if(ans[i]<1e7)printf("%d\n",ans[i]);else printf("%d\n",-1);
	return 0;
} 


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


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

    int cnt = 0;
    rep(i, n){
        if(x < A[i]) break;
        x -= A[i];
        cnt++;
    }
    if(cnt == n && x > 0) cnt--;
    cout << cnt << ln;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()


class DIJKSTRA {
  typedef long long ll;

  private:
    ll N;
    std::vector<ll> from;
    std::vector<ll> cost;
    std::vector<std::unordered_map<ll, ll>> direction;
    ll start;
    bool directed;

  public:

    DIJKSTRA ( ll N_ , bool dir = false ) : N(N_), directed(dir) {
      from.assign(N, std::numeric_limits<ll>::max());
      cost.assign(N, std::numeric_limits<ll>::max());
      direction.resize(N);
    }

    void push ( ll i, ll j, ll x ) {
      direction[i][j] = x;
      if ( !directed ) direction[j][i] = x;
    }

    void Reset (ll i) {
      from.assign(N, std::numeric_limits<ll>::max());
      cost.assign(N, std::numeric_limits<ll>::max());
      SetStart(i);
    }

    void SetStart( ll i ) {
      start = i;
      cost[i] = 0;
      from[i] = i;
    }

    void Go () {
      std::priority_queue<std::pair<ll,ll>> pq;
      pq.push( {0, start} );

      while(!pq.empty()){
        auto cur = pq.top(); pq.pop();
        if ( cost[cur.second] < (cur.first * -1) ) continue;
        for(auto itr = direction[cur.second].begin(); itr != direction[cur.second].end(); ++itr) {
          if ( cost[itr->first] > cost[cur.second]+itr->second ) {
            cost[itr->first] = cost[cur.second]+itr->second;
            from[itr->first] = cur.second;
            pq.push( { (cost[itr->first]*-1), itr->first } );
          }
        }
      }
      return;
    }

    ll get_cost ( ll i ){
      return cost[i];
    }

    std::vector<ll> get_path ( ll i ) {
      std::vector<ll> rtn;
      rtn.push_back(i);
      ll cur = i;
      while( from[cur] != cur ) {
        rtn.push_back(from[cur]);
        cur = from[cur];
      }
      return rtn;
    }
};


int main (void) {

  typedef long long ll;

  int N, M; std::cin >> N >> M;

  DIJKSTRA d(N);
  std::vector<std::vector<ll>> memo(N); for(int i=0; i<N; i++) memo[i].assign(N,0);

  for(int i=0; i<M; i++) {
    int a, b, c;  std::cin >> a >> b >> c;
    d.push(a-1, b-1, c);
    memo[a-1][b-1] = 1;
  }

  int ans = 0;
  for(int i=0; i<N; i++){
    d.Reset(i); d.Go();
    for(int j=i+1; j<N; j++){
      if ( d.get_cost(j) == std::numeric_limits<ll>::max() ) continue;
      auto v = d.get_path(j);
      for(int k=(v.size()-1); k>0; k--) {
        if ( memo[v[k]][v[k-1]] == 1 || memo[v[k-1]][v[k]] == 1 ){
          memo[v[k]][v[k-1]] = 0;
          memo[v[k-1]][v[k]] = 0;
          ans++;
        }
      }
    }
  }

  std::cout << M - ans << std::endl;
  return 0;
}

Measured memory_bytes: 384
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    input! {
       N: usize,
       a :[usize;N],
    }

    let mut ans: usize = 0;
    let mut m: usize = 0;
    for i in 0..N {
        let b = a[i];
        ans += m.saturating_sub(b);
        m = max(m, b);
    }

    echo!(ans);
}


Measured memory_bytes: 5640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define N 100005
ll n,m;
ll ara[N],sum[N];
map<ll,ll> mp;

int main(){
    fastio;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>ara[i];
        sum[i]=ara[i]+sum[i-1];
    }
    for(int i=0;i<=n;i++){
        sum[i]%=m;
        mp[sum[i]]++;
    }
    ll ans=0;
    for(int i=0;i<=n;i++){
        mp[sum[i]]--;
        ans+=mp[sum[i]];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9144
N = int(input())
L = list(map(int, input().split()))
count = 0

def calc(a, b, c):
    max = a
    mid = b
    min = c

    if a < b:
        max = b
        mid = a
        min = c
    if a < c:
        max = c
        mid = a
        min = b
    if abs(mid-min) < max and max < mid + min:
        return True
    else:
        return False

for i in range(0, N):
    for k in range(i + 1, N):
        for l in range(k+ 1, N):
            if L[i] != L[k] and L[k] != L[l] and L[l] != L[i]:
                if calc(L[i], L[k], L[l]) == True:
                    count += 1
print(str(count))


Measured memory_bytes: 9224
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
//#include <unordered_map>
//#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;

int main()
{
    int n,k,mi=2333333,ma=-1;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&k);
        mi=min(k,mi);
        ma=max(k,ma);
    }
    cout<<ma-mi<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
N,D = map(int,input().split())
array = []
        

def dist(arr1,arr2):
    tmp = 0
    for i in range(D):
        tmp += (arr1[i] - arr2[i])**2

    return math.sqrt(tmp)

for i in range(N):
    array.append(list(map(int,input().split())))

count = 0
for i in range(N-1):
    for j in range(i+1,N):
        a = dist(array[i],array[j])
        if a//1 == a:
            count += 1

print(count)


    
        




    
        




Measured memory_bytes: 3064
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {

        static void Main(string[] args)
        {
          var N = long.Parse(Console.ReadLine());
          //var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          //Console.WriteLine((long)Math.Ceiling(123456789.0/-2.0));
         // Console.WriteLine(hihur(123456789,-2));
//Console.WriteLine(hihur(123456789,-2));
          if(BaseM2(N) == ""){
            Console.WriteLine(0);
          }else{
            Console.WriteLine(BaseM2(N));
          }
         
        }
        
        static string BaseM2(long N){
          if(N == 0){
            //return (hihur(N,-2)).ToString();
            return "";
          }else{
            return BaseM2(hihu(N,-2))+(hihur(N,-2)).ToString();
          }
        }
  
  　　　 static long hihu(double m , double n){
        	if(m < 0 && n < 0){
              return (long) (Math.Ceiling(m/n));
            }
      //  Console.WriteLine(m/n);
        long ans = (long) (Math.Ceiling(m/n));
            return ans;
        }
  
        static long hihur(long m, long n){
          return m-hihu(m,n)*n;
        }
  

}







Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int k;
    scanf("%d",&k);
    printf("%d\n",(k/2)*(k-k/2));
	return 0 ;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    char s[3];
    scanf("%s", s);
    
    if(strcmp(s,"AAA")==0 || strcmp(s,"BBB")==0){
        puts("No");
    }else{
        puts("Yes");
    }

    return 0;

}


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

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; }

constexpr int INF = (1 << 29);

inline void warshall_floyd(vector<vector<int>> &mat) {
	const int n = mat.size();
	for(int k = 0; k < n; ++k) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				chmin(mat[i][j], mat[i][k] + mat[k][j]);
			}
		}
	}
}

int tsp(int limit, const vector<int> &s_cost, const vector<vector<int>> &mat, const vector<int> &eat) {
	const int n = mat.size();
	vector<vector<int>> dp(1 << n, vector<int>(n, INF));
	for(int v = 0; v < n; ++v) {
		dp[1 << v][v] = s_cost[v] + eat[v];
	}

	int res = 0;
	for(int used = 1; used < (1 << n); ++used) {
		for(int v = 0; v < n; ++v) {
			if(!(used & (1 << v)) || dp[used][v] + s_cost[v] > limit) continue;
			chmax(res, __builtin_popcount(used));

			for(int to = 0; to < n; ++to) {
				if(used & (1 << to)) continue;
				chmin(dp[used | (1 << to)][to], dp[used][v] + mat[v][to] + eat[to]);
			}
		}
	}

	return res;
}

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

	for(int n, m, l, s, t; cin >> n >> m >> l >> s >> t && n;) {
		--s;
		vector<vector<int>> mat(n, vector<int>(n, INF));
		for(int i = 0; i < n; ++i) {
			mat[i][i] = 0;
		}

		for(int i = 0; i < m; ++i) {
			int a, b, c;
			cin >> a >> b >> c;
			--a; --b;
			mat[a][b] = mat[b][a] = c;
		}

		warshall_floyd(mat);

		vector<int> jiro(l);
		vector<int> eat_time(l);

		for(int i = 0; i < l; ++i) {
			cin >> jiro[i] >> eat_time[i];
			--jiro[i];
		}

		vector<vector<int>> mat_jiro(l, vector<int>(l));
		for(int i = 0; i < l; ++i) {
			for(int j = i + 1; j < l; ++j) {
				mat_jiro[i][j] = mat_jiro[j][i] = mat[jiro[i]][jiro[j]];
			}
		}

		vector<int> s_cost(l);
		for(int i = 0; i < l; ++i) {
			s_cost[i] = mat[s][jiro[i]];
		}

		cout << tsp(t, s_cost, mat_jiro, eat_time) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 8132
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		int pos = S.length - 1 ;
		
		while(pos>=0){
			int offset = pos;
			boolean flag = true;
			for(int i=T.length-1 ; i>=0; i--){
				char c = T[i];
				if (offset < 0){
					flag = false;
					pos = -1;
					break;
				}
				if(S[offset]=='?' || S[offset]==c){
					offset--;
				}else{
					pos--;
					flag = false;
					break;
				}
			}
			if(flag){
				pos = pos-T.length+1;
				for(char c : T){
					S[pos] = c;
					pos++;
				}
				for(char c : S){
					if(c == '?'){
						System.out.print("a");
					}else{
						System.out.print(c);
					}
				}
				return;
			}
				
		}
		
		System.out.println("UNRESTORABLE");
		
		sc.close();
	}
}


Measured memory_bytes: 21844
import collections

N = int(input())
S = []
for i in range(N):
    S.append(input())

c = collections.Counter(S)
values, counts = zip(*c.most_common())
c_most = []
for s in range(len(values)):
    if counts[0] == counts[s]:
        c_most.append(values[s])
    else:
        break
ans = sorted(c_most)
for j in range(len(ans)):
    print(ans[j])

Measured memory_bytes: 59504
#include<bits/stdc++.h>
 
using namespace std;
 
void solve(int TestCase) {
    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;

    auto A = vector<vector<int>>(n, vector<int>(n));
    for(auto i = 0; i < n; ++i)
    {
        for(auto j = 0; j < n; ++j)
        {
            A[i][j] = abs(i - j);
        }
    }

    A[x][y] = A[y][x] = 1;

    for(auto p = 0; p < 2; ++p)
    {
        int node = p ? x : y;
        for(auto i = 0; i < n; ++i)
        {
            for(auto j = 0; j < n; ++j)
            {
                A[i][j] = min(A[i][j], A[i][node]  + A[node][j]);
            }
        }
    }

    auto ret = vector<int>(n+1);
    for(auto i = 0; i < n; ++i)
    {
        for(auto j = i+1; j < n; ++j)
        {
            ret[A[i][j]]++;
        }
    }

    for(auto i = 1; i < n; ++i)
    {
        cout << ret[i] << endl;
    }
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 16000