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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int n; string s; cin>>n>>s;
  int ans=0;
  for (int i=0; i+3<=n; i++) {
    ans += s.substr(i,3)=="ABC";
  }
  out(ans);
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); 
    string s, t;
    cin >> s >> t;
    int ans = 1e9;
    int n = s.size(), m = t.size();
    for(int i = 0; i + m - 1 < n; ++i) {
        int cost = 0;
        for(int j = 0; j < m; ++j) {
            if(t[j] != s[i + j])++cost;
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
N = int(input())
tmp1 = [0, 0, 0]
for i in range(N):
    tmp2 = [int(i) for i in input().split()]
    t = tmp2[0] - tmp1[0]
    x = abs(tmp2[1] - tmp1[1])
    y = abs(tmp2[2] - tmp1[2])
    j = t - x - y
    if j >= 0 and j % 2 == 0:
        tmp1 = tmp2
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3060
def main():
    n = int(input())
    blis = list(map(int, input().split()))

    alis = [blis[0], blis[0]]
    if n > 2 and alis[1] > blis[1]:
        alis[1] = blis[1]
    if n > 2:
        for i in range(3, n):
            alis.append(min(blis[i-2], blis[i-1]))
    if n > 2:
        alis.append(blis[n-2])
    print(sum(alis))


    


if __name__ == "__main__":
    main()


Measured memory_bytes: 61800
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<vector<char>> c(3,vector<char>(3));
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
            if(i == j) cout << c[i][j];
            if(i == 2 && j == 2) cout << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(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;}
typedef long long ll;

int n,m,k;
string s,t;

int main() {
  cin >> n;
  map<int,int> mp;  int d;
  rep(i,n){
    cin >> d; mp[d]++;
  }
  cin >> m;
  int t; bool ok=true;
  rep(i,m){
    cin >> t; mp[t]--;
    if(mp[t]<0) ok=false;
  }
  cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 9600
n,x = (int(i) for i in input().split())
listx=[int(i) for i in input().split()]
#print(n,x,listx)
listy=[abs(listx[i]-x) for i in range(n)]
listy.reverse()
#print(listy)

def gcd(y, x):
    if x == 0:
        return y
    else:
        return gcd(x, y % x) #再帰定義
if n==1:
  ans=listy[0]
else:
  if listy[1]==0:
    ans=listy[0]
  else:
    ans=gcd(listy[0],listy[1])
    if n > 2:
      for i in range(0,n-2):
        if listy[i+2]==0:
          ans=ans
        else:
          ans=gcd(ans,listy[i+2])
  
print(ans)

Measured memory_bytes: 14252
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VVI ct(10, VI(10, 0));
  REP2(int, i, 1, n+1)
  {

    int a = i, b = i%10;
    while(a >= 10) a /= 10;
    if (a == 0 || b == 0) continue;
    ++ct[a][b];
  }
  int ans = 0;
  REP2(int, i, 1, 10) REP2(int, j, 1, 10)
  {
    if (i != j) ans += ct[i][j] * ct[j][i];
    else ans += ct[i][j] * ct[i][j];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
typedef long long ll;
#define vll vector<long long> 
#define pll pair<ll,ll>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define F first
#define S second
#define pb(i) push_back(i)
#define mp(x,y) make_pair(x,y)
#define all(v)  (v).begin(),(v).end()
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main(){
	FIO;
	ll n;cin>>n;
	double dp[n+1][n+1],p[n],ans = 0.0;
	f(i,0,n) cin>>p[i];
	memset(dp,0.0,sizeof(dp));
	dp[0][0] = 1.0;
	f(i,1,n+1){
		f(j,0,n+1){
			if(j==0) dp[i][j] = dp[i-1][j]*(1.0-p[i-1]);
			else dp[i][j] = p[i-1]*dp[i-1][j-1] + (1.0-p[i-1])*dp[i-1][j];
		}
	}
	ll k = n/2;
	f(i,k+1,n+1) ans += dp[n][i];
	cout<<fixed<<setprecision(10)<<ans<<"\n";
}

Measured memory_bytes: 74132
#include <stdio.h>

int main()
{
   int n,k,q;
   int i,j;
   int num;
   scanf("%d %d %d",&n,&k,&q);
    int people[n];
    int score[n];

    for(i=0;i<n;i++)
    {
        people[i]=k-q;
    }

    for(i=0;i<q;i++)
    {
        scanf("%d",&num);
        people[num-1]++;
    }

    for(i=0;i<n;i++)
    {
        if(people[i]>0) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 896
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        a: usize, b: usize, m: usize,
        aa: [i64; a],
        bb: [i64; b],
        xyc: [(usize1, usize1, i64); m],
    }
    let mut mi: i64 = 1 << 50;
    for &(x, y, c) in &xyc {
        mi = min(mi, aa[x] + bb[y] - c);
    }
    let &ami = aa.iter().min().unwrap();
    let &bmi = bb.iter().min().unwrap();
    mi = min(mi, ami + bmi);
    puts!("{}\n", mi);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 14588
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

int n;
int A[100010];
vector <int> E[100010];
int D[100010];

void dfs(int x){
	vector <int> v;
	for(int e : E[x]){
		dfs(e);
		v.pb(D[e]);
	}
	if(sz(v) == 1)D[x] = v[0] + 1;
	else{
		sort(all(v)); reverse(all(v));
		for(int i=0;i<sz(v);i++){
			D[x] = max(D[x], v[i] + i + 1);
		}
	}
}

void solve(){
	scanf("%d", &n);
	for(int i=2;i<=n;i++){scanf("%d", A+i), E[A[i]].pb(i);}
	dfs(1);
	printf("%d\n", D[1]);
}

int main(){
	int Tc = 1; // scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

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

using namespace std;

#define N 4050

int n,x,a[N],b[N],f[N][N],g[N][N],h[N][N];
char ch;

void upd(int &x,int y){x=min(x,y);}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n*2;++i){
		for (ch=getchar();ch!='B'&&ch!='W';ch=getchar());
		scanf("%d",&x);
		memcpy(g[i],g[i-1],sizeof g[i]);
		memcpy(h[i],h[i-1],sizeof h[i]);
		if (ch=='B'){
			a[x]=i;
			for (int j=1;j<=x;++j) ++g[i][j];
		}
		else{
			b[x]=i;
			for (int j=1;j<=x;++j) ++h[i][j];
		}
	}
	memset(f,0x3f,sizeof f); f[0][0]=0;
	for (int i=0;i<=n;++i)
		for (int j=0;j<=n;++j){
			if (i!=n) upd(f[i+1][j],f[i][j]+g[a[i+1]-1][i+1]+h[a[i+1]-1][j+1]);
			if (j!=n) upd(f[i][j+1],f[i][j]+g[b[j+1]-1][i+1]+h[b[j+1]-1][j+1]);
		}
	printf("%d\n",f[n][n]);
	
	return 0;
}
			

Measured memory_bytes: 192512
import scala.io.StdIn._
import scala.math.abs

object Main extends App {
  val N = readLine.toInt
  val A = readLine.split(' ').map(s => s.toLong)

  def calcAbsSum(a: Array[Long]): Long = a.map(abs(_))sum

  if (A.exists(x => x == 0)) {
    println(calcAbsSum(A))
  } else if (A.filter(x => x < 0).size % 2 == 0) {
    println(calcAbsSum(A))
  } else {
    val min_v = A.map(abs(_)).min
    println(calcAbsSum(A) - min_v*2)
  }
}

Measured memory_bytes: 53004
#include "bits/stdc++.h"
using namespace std;

int main()
{

    long long int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    long long ans[10];
    ans[0]=max(x,y)*2*c;
    if(x>y)
        ans[1]=a*abs(x-y)+2*c*min(x,y);
    else
        ans[1]=b*abs(x-y)+2*c*min(x,y);
    ans[2]=x*a+y*b;
    sort(ans,ans+3);
    cout<<ans[0];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

map<string,int> ms,mt;
set<string> st;
int main(){
    int n,m;
    string s;
    cin>>n;
    rep(i,n){
        cin>>s;
        ++ms[s];
        st.insert(s);
    }
    cin>>m;
    rep(i,m){
        cin>>s;
        ++mt[s];
        st.insert(s);
    }
    int mx=0;
    for(auto it:st){
        mx=max(mx,ms[it]-mt[it]);
    }
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 3005;
const int mod = 1e9 + 7;

int n, m, a[MAXN], s[MAXN], f[MAXN][MAXN];
char c[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read();
	scanf("%s", c + 1);
	for (int i = 1; i <= n; i ++)
		a[i] = i, s[i] = s[i - 1] + (c[i] == '1');
	f[0][0] = 1;
	for (int i = 1, l, r; i <= m; i ++)
		l = Read(), r = Read(), a[l] = max(a[l], r);
	for (int i = 0, r = a[1]; i < n; i ++, r = max(r, a[i + 1]))
		for (int j = 0; j <= s[r]; j ++)
			if (f[i][j])
			{
				if (s[r] - j < r - i)
					f[i + 1][j] = (f[i + 1][j] + f[i][j]) % mod;
				if (s[r] - j)
					f[i + 1][j + 1] = (f[i + 1][j + 1] + f[i][j]) % mod;
			}
	return printf("%d\n", f[n][s[n]]), 0;
}


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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

ll pre_func(string s) {
    ll n = s.size();
    vi p(n, 0);
    REP(i, 1, n) {
        ll j = p[i-1];
        while (j > 0 && s[j] != s[i])
            j = p[j-1];
        if (s[i] == s[j])
            j++;
        p[i] = j;
    }
    return p[n-1];
}

int main() {
    fast;
    ll x, y, r, g, c, a;
    cin >> x >> y >> r >> g >> c;
    vii arr;
    REP(i, 0, r) {
        cin >> a;
        arr.pb({a, 0});
    }
    REP(i, 0, g) {
        cin >> a;
        arr.pb({a, 1});
    }
    REP(i, 0, c) {
        cin >> a;
        arr.pb({a, 2});
    }
    sort(all(arr), greater<pi>());
    ll i = 0, ans = 0;
    ll t = x+y;
    while(i < arr.size()) {
        if (t == 0)
            break;
        if (arr[i].second == 0 && x > 0) {
            ans += arr[i].first;
            x--;
            t--;
        }
        else if (arr[i].second == 1 && y > 0) {
            ans += arr[i].first;
            y--;
            t--;
        }
        else if (arr[i].second == 2) {
            ans += arr[i].first;
            t--;
        }
        i++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 10348
def main():
    n = int(input())
    b_list = list(map(int, input().split()))
    a_list = []

    previous = 10 ** 5

    for b in b_list:
      a = min(previous, b)
      a_list.append(a)
      previous = b
      
    a_list.append(b_list[-1])
    print(sum(a_list))
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int N, R;
    cin >> N >> R;
    int ans = R + (100 * max(0, 10 - N));
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import copy
input = sys.stdin.readline

N = int(input())

if N == 1:
    print('a')
    exit()
if N == 2:
    print('aa')
    print('ab')
    exit()

ans = ['aaa', 'aab', 'aba', 'abb', 'abc']
alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
length = 3

while length < N:
    ans2 = []
    for value in ans:
        flag = False
        for letter in alph:
            if flag:
                break
            ans2.append(value + letter)
            if letter not in value:
                flag = True
    length += 1
    ans = copy.deepcopy(sorted(ans2))

for value in ans:
    print(value)

Measured memory_bytes: 15564
#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<complex>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
const ll mod=998244353;

ll  MOD(ll  a,ll  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
ll  max3(ll  a,ll  b,ll c)
{
    return max(c,max(a,b));
}
ll min3(ll a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y )
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);//%mod;
        y = y>>1;
        x = (x*x);//%mod;
    }
    return res;//%mod;
}
ll  power1(ll  x,ll  y )
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res%mod;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x)
{
    return power1(x,mod-2);
}
ll dp[101][100001];

vll v;
vll weight;
ll solve(int i,ll x)
{
    if(x<0||i<0)
    {
        return 0;
    }
    else
    {
        if(dp[i][x]!=-1)
        {
            return dp[i][x];
        }
        else
        {
            if(weight[i]<=x)
            {
                dp[i][x]=max(dp[i][x],max(solve(i-1,x),solve(i-1,x-weight[i])+v[i]));
            }
            else
            {
                dp[i][x]=max(dp[i][x],solve(i-1,x));
            }
            return dp[i][x];
        }
    }
}
int main()
{
    int n;
    cin>>n;
    ll w;
    cin>>w;
    for(int i=0;i<101;i++)
    {
        for(int j=0;j<100001;j++)
        {
            dp[i][j]=-1;
        }
    }
    v.resize(n);
    weight.resize(n);
    for(int i=0;i<n;i++)
    {
        cin>>weight[i];
        cin>>v[i];
    }
    cout<<solve(n-1,w);
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

ll n, m;
bool graph[60][60];
bool vis[60];

void dfs(ll x){
  if(vis[x]) return;
  vis[x] = true;
  for(ll i = 0; i < n; i++){
    if(graph[x][i]){
      dfs(i);
    }
  }
}

int main(){
  cin >> n >> m;
  vector<ll> a(m), b(m);
  for(ll i = 0; i < m; i++){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  ll ans = 0;

  for(ll i = 0; i < m; i++){
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    for(ll j = 0; j < n; j++) vis[j] = false;
    dfs(0);
    bool conect = false;
    for(ll i = 0; i <n; i++){
      if(!vis[i]) conect = true;
    }
    if(conect) ans++;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  cout << ans << endl;
  return 0;
}

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

namespace Test
{
   static class AtCorder
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
            var vals = Console.ReadLine().Split(' ').Select(long.Parse);
            var sum = 0L;
            var isEaven = true;
            var min = long.MaxValue;
            foreach (var item in vals)
            {
                var num = item;
                if (num < 0) {
                    isEaven = !isEaven;
                    num = -num;
                }
                if (num < min) min = num;
                sum += num;
            }

            if (!isEaven)
                sum -= 2 * min;

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 30428
N = int(input())
len = len(str(N))
a = list(str(N))
b =0
for i in range(1,len)[::-1]:
  if a[i] == -1:
    a[i] == '9'
  if a[i] != '9':
    b += (int(a[i])+1) * (10**(len-1-i))
    a[i-1] = str(int(a[i-1])-1)
a = list(str(N-b))
b = 0
for i in a:
  b += int(i)
print(b)

Measured memory_bytes: 3064
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}
unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
#define int ll
void solve() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int> inputs;
    while (n != 0) {
        int hoge = 0;
        for (int q = max(0LL, n - m); q < n; ++q) {
            if (s[q] == '0') {
                inputs.push_back(n - q);
                n = q;
                hoge = 1;
                break;
            }
        }
        if (hoge == 0) {
            cout << -1 << endl;
            return;
        }
    }
    reverse(ALL(inputs));
    REP(i, inputs.size()) {
        cout << inputs[i] << " ";
    }
    cout << endl;
}
#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 1464
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}

fn main() {
    let v: Vec<i32> = read_vec();
    let a: i32 = if (v[2] % v[1]) == 0 {
        v[2] / v[1]
    } else {
        v[2] / v[1] + 1
    };
    let b = if v[0] % v[3] == 0 {
        v[0] / v[3]
    } else {
        v[0] / v[3] + 1
    };
    if a <= b {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

signed main(){
	fastio
	int x;
	cin >> x;
	cout << (x>=30 ? "Yes\n" : "No\n");
}

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

int n,ans; 

int main()
{
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=0;i<100;i++)
	{
		int sum=0;
		for(int j=0;j<n;j++)
			sum += (a[j]-i)*(a[j]-i);
		if(!i)
			ans=sum;
		else
			ans=min(sum,ans);
	} 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
using vi = vector<int>;
using vll = vector<ll>;
const ll INF = 1LL<<60;

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

  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int ans = 0;

  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      int now = abs(a[i] - a[j]);
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	string s, t;	cin >> s >> t;
  	int dg = s.size();
  	if(s == t.substr(0,dg)) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<int> adj[n];
	queue<int> q;
	q.push(0);
	int p[n];
	bool visited[n];
	for (int i = 0; i < n; i++) {
		visited[i] = false;
	}
	visited[0] = true;
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		a--, b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	while (!q.empty()) {
		int node = q.front();
		q.pop();
		for (int nb: adj[node]) {
			if (!visited[nb]) {
				visited[nb] = true;
				p[nb] = node;
				q.push(nb);
			}
		}
	}
	
	for (bool c: visited) {
		if (!c) {
			cout << "No";
			return 1;
		}
	}
	cout << "Yes" << "\n";
	for (int i = 1; i < n; i++) {
		cout << p[i] + 1 << "\n";
	}
}

Measured memory_bytes: 10564
#include <iostream>
#include <iomanip>

using namespace std;

int main() {

  int a, b, c;
  //cin >> a >> b;
  double ans, ra, rb;
  string dolphinManJotaro;
  cin >> dolphinManJotaro;
  for(int i = 0;i < dolphinManJotaro.size();i++){
    if(dolphinManJotaro[i] == ','){
      cout << " ";
    }else{
      cout << dolphinManJotaro[i];
    }
  }
  return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int s;
  cin >> s;
  map<int, int> mp;
  int ans = 1;
  while (!mp[s]) {
    mp[s] = 1;
    if (s & 1)
      s = 3 * s + 1;
    else
      s = s / 2;
    ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

int main(){
    int n = 0;
    cin >> n;
    std::vector<int> vec(n);
    for(int i=0;i<n;i++)cin >> vec[i];
    sort(vec.begin(),vec.end());
    vector<bool> answers((*vec.rbegin()) +1);
    fill(answers.begin(),answers.end(),true);

    for(int i=0;i<n;i++){
        int times = vec[i];
        for(int j=2*times;j<answers.size();j+=times){
            answers[j] = false;
        }
    }
    int count = 0;
    for(int i=0;i<n;i++){
        if(i>0 && vec[i]==vec[i-1])continue;
        if(i+1<n && vec[i]==vec[i+1])continue;
        if(answers[vec[i]])count++;
    }
    cout << count << endl;


    return 0;
}

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

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////


#define LL long long
const int MAXN = 212345;
const int INF  = 0x3f3f3f3f;




int main () {

	ios_base::sync_with_stdio(false);  cin.tie(NULL); 

	int n;
	cin >> n;

	int cnt = 0;

	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
	
		while (x % 2 == 0) {
			++cnt;
			x /= 2;
		}
	}
	cout << cnt << '\n';



	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long AB = A+B;
    if(A+B >= C){
      System.out.println(B+C);
    }else{
      System.out.println(A + 2 * B + 1);
    }
  }
}

Measured memory_bytes: 23252
N,M=gets.split.map(&:to_i)
S=gets.chop.reverse
ans=[]
s=g=0
S.chars.each.with_index do |c,i|
  g=i if c==?0
  if i-s==M
    if g==s
      p -1
      exit
    end
    ans << g-s
    s=g
  end
end
ans << g-s if s!=g
puts ans.reverse*" "

Measured memory_bytes: 11516
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)

class Ford_Fulkerson:
    def __init__(self,G,N,s,t,check):
        self.G,self.N,self.s,self.t,self.check=G,N,s,t,check
        for v in range(self.N):
            if v==s or v==t:
                continue
            for nv,cap in self.G[v].items():
                self.G[nv][v]=0
            if self.check(v):
                self.G[s][v]=1
                self.G[v][s]=0
            else:
                self.G[v][t]=1
                self.G[t][v]=0
        self.max_f=self.Max_Flow(self.G,self.s,self.t)
        
    def dfs(self,G,v,t,f,used):
        if v==t:
            return f
        used[v]=True
        for nv,cap in G[v].items():
            if not used[nv] and cap>0:
                d=self.dfs(self.G,nv,t,min(f,cap),used)
                if d>0:
                    self.G[v][nv]-=d
                    self.G[nv][v]+=d
                    return d
        return 0

    def Max_Flow(self,G,s,t):
        flow=0
        while(True):
            used=[False]*(2*N+2)
            f=self.dfs(self.G,self.s,self.t,float('inf'),used)
            if f==0:
                return flow
            flow+=f

N=int(input())
G=[defaultdict(int) for i in range(2*N+2)]
arr=[]
for i in range(2*N):
    x,y=map(int,input().split())
    arr.append((x,y))

for i in range(N,2*N):
    for j in range(N):
        a,b=arr[i]
        c,d=arr[j]
        if a>c and b>d:
            G[i+1][j+1]=1

def check(i):return i>=1+N
MF=Ford_Fulkerson(G,2*N+2,0,2*N+1,check)
print(MF.max_f)

Measured memory_bytes: 76480
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, K, S; cin >> N >> K >> S;
    vector<int> A;
    rep(i,K) A.push_back(S);
    int L = (S == 1000000000) ? 1 : S + 1;
    rep(i,N-K) A.push_back(L);
    rep(i,N) {
        cout << A[i];
        if (i != N-1) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3928
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h[10001],i,j,z[10001];
	scanf("%d",&a);
	for(i=1;i<=a;i++){
		z[i]=1;
		//printf("%d\n",z[4]);
	}
//	printf("%d\n",z[4]);
	for(i=1;i<=a*(a-1)/2;i++){
		h[i]=0;
	}
	for(i=1;i<=a*(a-1)/2;i++){
		scanf("%d %d %d %d",&s,&d,&f,&g);
		if(f<g){
			h[d]=h[d]+3;
		}
		else if(f>g){
			h[s]=h[s]+3;
		}
		else if(f==g){
			h[d]++;
			h[s]++;
		}
	}
	for(i=1;i<=a;i++){
		for(j=1;j<=a;j++){
			if(h[i]<h[j]){
				z[i]++;
			//	printf("z[%d]=%d\n",i,z[i]);
			}

		}
	}
	for(i=1;i<=a;i++){
		printf("%d\n",z[i]);
	}
	return 0;
}

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

int main() {
    int m, f, r;
    int cnt = 0;
    while (true) {
        cin >> m >> f >> r;
        if ((m == -1) && (f == -1) && (r == -1)) {
            break;
        }
        if ((m == -1) || (f == -1)) {
            cout << "F" << endl;
        }
        else if (m + f >= 80) {
            cout << "A" << endl;
        }
        else if (m + f >= 65) {
            cout << "B" << endl;
        }
        else if (m + f >= 50) {
            cout << "C" << endl;
        }
        else if (m + f >= 30) {
            if (r >= 50) {
                cout << "C" << endl;
            }
            else {
                cout << "D" << endl;
            }
        }
        else if (m + f < 30) {
            cout << "F" << endl;
        }
        cnt++;
        if (cnt > 1000000) {
            break;
        }
    }
}



Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;


int main() {
	//cout << fixed << setprecision(10);
	string str;
	long long int n, m, res[300101] = {}, x, h[30], w, cou = 0, Ma = 0, k, memo[300100] = {};
	cin >> n>>k>>str;
	memo[0] = 1;
	for (int i = 1; i < n; i++) {
		if (str[i] != str[i - 1]) {
			cou++;
		}
		memo[cou]++;
	}

	if (str[0] == '0') {
		for (int i = 0; i < 2 * k; i++) {
			res[0] += memo[i];
		}
		res[1] = res[0] - memo[0] + memo[2 * k] + memo[2 * k + 1];
		int p = 1;
		while (cou>2*(k+p)-12) {
			p++;
			res[p] = res[p - 1] - memo[2 * p - 3] - memo[2 * p - 2]+memo[2*(k+p)-1]+ memo[2 * (k+p) - 2];
		}
		sort(res, res + p+1);
		cout << res[p];
	}
	else {
		for (int i = 0; i <= 2 * k; i++) {
			res[0] += memo[i];
		}
		int p = 0;
		while (cou > 2 * (k + p) - 12) {
			p++;
			res[p] = res[p - 1] - memo[2 * p - 2] - memo[2 * p - 1] + memo[2 * (k + p) - 1] + memo[2 * (k + p) ];
		}
		sort(res, res + p + 1);
		cout << res[p];
	}


}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<list>
using namespace std;
int n,q;
main()
{
	cin>>n>>q;
	vector<list<int> >s(n);
	for(int i=0;i<q;i++)
	{
		int c;cin>>c;
		if(c==0)
		{
			int t,x;cin>>t>>x;
			s[t].insert(s[t].end(),x);
		}
		else if(c==1)
		{
			int t;cin>>t;int f=0;
			for(int j:s[t])cout<<(f++?" ":"")<<j;
			cout<<endl;
		}
		else
		{
			int S,t;cin>>S>>t;
			s[t].splice(s[t].end(),s[S],s[S].begin(),s[S].end());
			s[S].clear();
		}
	}
}


Measured memory_bytes: 18648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    rrep(i, n - 1) {
        if (h[i + 1] >= h[i]) continue;
        h[i]--;
        if (h[i + 1] < h[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

bool water[100], sugar[4000];

int main() {
  int a, b, c, d, e, f, wa, su;
  double ans = -1000000;
  scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
  water[0] = sugar[0] = 1;
  for (int i = 0; i <= 50 - a; i ++)
    if (water[i]) water[i + a] = 1;
  for (int i = 0; i <= 50 - b; i ++)
    if (water[i]) water[i + b] = 1;
  for (int i = 0; i <= 3000 - c; i ++)
    if (sugar[i]) sugar[i + c] = 1;
  for (int i = 0; i <= 3000 - d; i ++)
    if (sugar[i]) sugar[i + d] = 1;
  for (int i = 0; i <= 3000; i ++)
    if (sugar[i])
      for (int j = 1; j <= 50; j ++)
	if (water[j]) {
	  double tmp = 10000.0 * i / (j * 100 + i);
	  if (tmp <= ans || j * 100 + i > f) break;
	  if (j * e < i) continue;
	  ans = tmp;
	  wa = j * 100;
	  su = i;
	}
  printf("%d %d\n", wa + su, su);
  return 0;
}


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

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

    long long n, m;
    cin >> n >> m;
    vector<long long> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    vector<long long> B(n + 1, 0);
    for(int i = 1; i <= n; i++){
        B[i] += B[i - 1] + A[i - 1];
    }

    long long ans = 0;
    map<long long, long long> mp;
    for(auto x : B){
        mp[x % m]++;
    }

    for(auto x : mp){
        ans += x.second * (x.second - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
import numpy as np

N=int(input())
A=list(map(int, input().split()))
A=sorted(A, reverse=True)

#print(now) #普通に全部食える


cum=np.cumsum(A[::-1])[::-1]
adds=[-1]*(N)
adds[0]=cum[0]
for i in range(1,N):
    if cum[i]*2>=A[i-1]:
        adds[i]=adds[i-1]
    else:
        adds[i]=cum[i]
#print(A)
#print(cum)
#print(adds)
adds=np.array(adds)
ans=(adds==cum[0]).sum()

print(ans)

Measured memory_bytes: 23116
S=int(input())
mod = 10**9+7
F = [1]
for i in range(1,S+1):
  F.append((F[-1]*i)%mod)

def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
def comb(n,k,p):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a,b,c=F[n],F[k],F[n-k]
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

ans = 0  
for i in range(S//3):
  ans = (ans + comb(S-3*(i+1)+i,i,mod))%mod
  #print(i,ans)
print(ans)

Measured memory_bytes: 9260
n = gets.to_i
array = Array.new(n){Array.new}
ans = 0
n.times do |i|
  a = gets.to_i
  a.times do
    array[i] << gets.chomp.split.map(&:to_i)
  end
end
[0,1].repeated_permutation(n).each do |permu|
  cnt = 0
  flag = true
  array.each_with_index do |a,i|
    next if permu[i] == 0

    a.each do |x,y|
      if permu[x-1] != y
        flag = false
      end
    end
  end
  if flag
    ans = [permu.inject(:+),ans].max
  end
end

puts ans
      

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define Fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
const int sz=1e5+10;
int ara[sz];
int dp[sz];
int n,k;
int inf=1e9;
int fun(int i)
{
    if(i==n-1)  return 0;
    else if(dp[i] != -1)  return dp[i];
    int a=inf,b=inf,x,ans=inf;
    for(int j=1;j<=k;j++){
    if(i+j<n){
            x=abs(ara[i]-ara[i+j]);
        if(dp[i+j]==-1){
            dp[i+j]=fun(i+j);
        }
       a=x+dp[i+j];
       ans=min(ans,a);
    }
    }
    return dp[i]=ans;

}
int main()
{
    Fast;
    int a,b,i,j,m,p,q,x,y,ct,t,w,sum,mx,clr,ans;
    string str;
    cin>>n>>k;
    for(i=0;i<n;i++)  cin>>ara[i];
    memset(dp,-1,sizeof dp);
    ans=fun(0);
    cout<<ans<<endl;
}


Measured memory_bytes: 7296
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  if (*(long long int*)a - *(long long int*)b > 0)
    return 1;
  else if(*(long long int*)a - *(long long int*)b < 0)
    return -1;
  else 
    return 0;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define INF 1000000000000000000

typedef long long int lli;

int main(void) {
  int n;
  long long int sum = 1;
  long long int a[MAX];

  scanf("%d", &n);
  rep(i, 0, n) scanf("%lld", &a[i]);
  qsort(a, n, sizeof(lli), acs);
  rep(i, 0, n) {
    if (sum == 0) {
      sum = 0;
      break;
    }
    if (a[i] > INF / sum) {
      sum = -1;
      break;
    }
    sum *= a[i];
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 3100
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2050;
//ここまでテンプレ
int main(){
	int a,b,c,d;
	scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
	vector<string> v;
	for(int i=0;i<8;i++){
		string S;
		S+=a+'0';
		if(i&(1<<0))
			S+='+';
		else
			S+='-';
		S+=b+'0';
		if(i&(1<<1))
			S+='+';
		else
			S+='-';
		S+=c+'0';
		if(i&(1<<2))
			S+='+';
		else
			S+='-';
		S+=d+'0';
		v.pb(S);

		int now=0;
		if(i&(1<<0))
			now=a+b;
		else
			now=a-b;
		if(i&(1<<1))
			now+=c;
		else
			now-=c;
		if(i&(1<<2))
			now+=d;
		else
			now-=d;

		if(now==7){
			cout<<S<<"="<<now<<endl;
			return 0;
		}
		//cout<<now<<endl;
	}

	return 0;
}

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

using namespace std;
int main(){
    int N;
    string item;
    set<string> S;

    cin>>N;

    for(int i = 0; i<N; i++){
        cin>>item;
        S.insert(item);
    }
    cout<<S.size()<<"\n";

    return 0;
}



Measured memory_bytes: 19120
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int count = 0;
    rep(i, 0, n-2){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static int N;
	static int[][] v;
	static boolean[][] left;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		N = sc.nextInt();
		int[] P = new int[N*N];
		for(int i=0; i<N*N; i++)
			P[i] = sc.nextInt()-1;

		v = new int[N][N];
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				v[i][j] = Math.min(Math.min(i, N-i-1), Math.min(j, N-j-1))+1;
			}
		}
		left = new boolean[N][N];
		
		int ans = 0;
		for(int i=0; i<N*N; i++) {
			int y = P[i]/N;
			int x = P[i]%N;
			ans += v[y][x]-1;
			left[y][x] = true;

			int min = N;
			for(int d=0; d<4; d++) {
				int ny = y + dy[d];
				int nx = x + dx[d];
				if(0<=ny && ny<N && 0<=nx && nx<N) {
					min = Math.min(min, v[ny][nx]);
				} else {
					min = 0;
				}
			}

			dfs(y, x, min);
			
		}
		System.out.println(ans);
		
		sc.close();
	}
	
	static int[] dx = { 0, 1, 0, -1};
	static int[] dy = { 1, 0, -1, 0};
	
	static void dfs(int y, int x, int value) {
		v[y][x] = value;
		for(int d=0; d<4; d++) {
			int ny = y + dy[d];
			int nx = x + dx[d];
			if(0<=ny && ny<N && 0<=nx && nx<N) {
				if(left[ny][nx] && v[ny][nx] > v[y][x]) {
					dfs(ny, nx, value);
				} else if(!left[ny][nx] && v[ny][nx] > v[y][x]+1) {
					dfs(ny, nx, value+1);
				}
			}
		}
	}
}


Measured memory_bytes: 59196
import sys
from collections import deque, defaultdict
import copy
import bisect
#input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


N = int(input())
res = []
for i in range(N):
    S, P = list(input().split())
    bisect.insort(res, (S, -int(P), i + 1))
for i in range(len(res)):
    print(res[i][2])







Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 998244353

int main(){
    int N;
    cin >> N;
    vector<int> D(N+1);
    vector<int> count(N);
    ll ans = 1;
    int m = -1;
    for(int i=1;i<=N;i++){
        cin >> D[i];
        count[D[i]]++;
        if(m<D[i])m=D[i];
    }
    if(D[1]!=0){
        cout << 0 << endl;
        return 0;
    }

    sort(D.begin(),D.end());
    if(D[2]==0){
        cout << 0 << endl;
        return 0;
    }
    for(int i=1;i<=N;i++){
        if(D[i-1]-D[i] < -1){
            cout << 0 << endl;
            return 0;
        }
    }

    if(count[2]==0){
        cout << 1 << endl;
        return 0;
    }

    for(int i=2;i<=N;i++){
        if(D[i]==1) continue;
        ans*=count[D[i]-1];
        ans%=MOD;
    }

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

Measured memory_bytes: 1024