akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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 <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll A, B, C;
  cin >> A >> B >> C;
  ll a = C - A + B;
  if (a < 0) {
    COUT(0);
  } else {
    COUT(a);
  }
  return 0;
}

Measured memory_bytes: 256
x=int(input())
i=0
while True:
    i+=1
    for j in range(i):
        if i**5+j**5==x:
            print(i,-j)
            exit()
        elif i**5-j**5==x:
            print(i,j)
            exit()
        elif -i**5-j**5==x:
            print(-i,j)
            exit()
        elif -i**5+j**5==x:
            print(-i,-j)
            exit()
print(i,j)


Measured memory_bytes: 65872
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,cnt=0;
    long long int sum=0;
    cin >> n;
    vector<int> tmp(3*n);
    for(int i=0;i<3*n;i++)
        cin >> tmp.at(i);
    sort(tmp.begin(),tmp.end());
    for(int i=n;i<3*n;i++){
        if(cnt%2==0){
                sum+=tmp.at(i);
                cnt++;
        }
        else if(cnt<2)
            cnt++;
        else
            cnt = 0;
//        if(n%2==1&&i%2==0)
    }
    cout << sum << endl;    
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e18+1e18;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

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

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N, K;
	cin >> N >> K;
	vll count(N + 1);
	repn(i, N) {
		ll a;
		cin >> a;
		count[a]++;
	}
	sort(++count.begin(), count.end());
	ll ans = 0;
	repn(i, N - K)ans += count[i];
	cout << ans << endl;

}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using mat = vector<vector<lint> >;
constexpr lint MOD = 1000000007;

lint K, N;

lint solve()
{
    vector<lint> dp(N+2);
    dp[N+1] = 1;
    for (int k=1; k<=K; k++)
    {
        for (int j=N; j>=0; j--)
        {
            if (j > N + 1 - k) dp[j] = 0;
            else dp[j] = (dp[j] + dp[j+1]) % MOD;
        }
    }
    return dp[1];
}

int main()
{
    cin >> N >> K;
    lint ans = solve();
    for (int k=K+1; k<N; k++) ans = (ans * 2) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double PI=3.14159265358979323846;

int main(){
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  int total_time= 60*h + m;
  
  double angle;
  angle = abs(6*m-0.5*total_time);
  angle = angle*PI/180;
  
  double c;
  c = sqrt(a*a + b*b - 2*a*b*cos(angle));
  cout << fixed << setprecision(10);
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 4188
from decimal import Decimal, getcontext

d1 = Decimal(1)
while True:
    n, k, m, r = map(int, input().split())
    if not n:
        break
    getcontext().prec = r + 1
    ans = d1 / Decimal(n)
    if m:
        ans *= 1 + sum(d1 / Decimal(i) for i in range(1, n))
    print('{{:.{}f}}'.format(r + 1).format(ans)[:-1])

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repab(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
#define endl "\n"

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

//--//--//--//--//--//--//--//--//--//--//--//

int main(){

	//input//
	int n;
	cin >> n;
	vec<int> a(n);
    vec<int> b(n);
	rep(i, n){
		int x, y;
		cin >> x >> y;
		a.at(i) = x - y;
		b.at(i) = x + y;
	}
	sort(all(a));
	sort(all(b));

	cout << max(a.at(n-1)-a.at(0), b.at(n-1)-b.at(0)) << endl;

	return 0;
}

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

int main(){
	string a, b;
	cin>>a>>b;
	if(a.length() + 1 == b.length()){
		int i = 0;
		while(a[i] == b[i] && i < a.length()){
			i++;
		}
		if(i == a.length()) cout<<"Yes\n";
		else cout<<"No\n";
	}
	else{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 3592
function main(arg) {
    arg = arg.split("\n")[0]
    arg = arg.split(" ")
    
    if ((arg[0]*arg[1]*1) % 2 === 1) {
        console.log("Yes")
        return
    }
    if ((arg[0]*arg[1]*2) % 2 === 1) {
        console.log("Yes")
        return
    }
    if ((arg[0]*arg[1]*3) % 3 === 1) {
        console.log("Yes")
        return
    }
    console.log("No")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<iostream>
using namespace std;
int n, m, h, w, i, j;
int a[505][505];
int main(){
    cin>> n >> m >> h >> w;
    if(n % h == 0 && m % w == 0){
        cout<<"No\n";
        return 0;
    }
    if(n % h != 0){
        for(i = 1; i <= n; i += h){
            for(j = 1; j <= m; j++){
                a[i][j] = 501 * (h - 1) - 1;
            }
        }
        for(i = 1; i <= n; i++){
            if(a[i][1] == 0){
                for(j = 1; j <= m; j++){
                    a[i][j] = -501;
                }
            }
        }
    }
    else{
         for(i = 1; i <= m; i += w){
            for(j = 1; j <= n; j++){
                a[j][i] = 501 * (w - 1) - 1;
            }
        }
        for(i = 1; i <= m; i++){
            if(a[1][i] == 0){
                for(j = 1; j <= n; j++){
                    a[j][i] = -501;
                }
            }
        }
    }
    cout<<"Yes\n";
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cout<< a[i][j] <<" ";
        }
        cout<<"\n";
    }
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const int INF=1e9;
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 dp[100][4][4][4];

int main(int argc, char const *argv[]) {
  int n; std::cin >> n;
  dp[0][3][3][3]=1;

  for(int len=0; len<n; len++){//文字数
    for(int i=0; i<4; i++){//最後から1文字目
      for(int j=0; j<4; j++){//2文字目
        for(int k=0; k<4; k++){//3文字目
          if(dp[len][i][j][k]==0) continue;
          for(int a=0; a<4; a++){//追加する文字
            if(a==2 && i==1 && j==0) continue;
            if(a==2 && i==0 && j==1) continue;
            if(a==1 && i==2 && j==0) continue;
            if(a==2 && i==1 && k==0) continue;
            if(a==2 && j==1 && k==0) continue;

            dp[len+1][a][i][j]+=dp[len][i][j][k];
            dp[len+1][a][i][j]%=MOD;
          }
        }
      }
    }
  }
  ll ans=0;
  for(int i=0; i<4; i++){
    for(int j=0; j<4; j++){
      for(int k=0; k<4; k++){
        ans+=dp[n][i][j][k];
        ans%=MOD;
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,s=0;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    int p=i;
    string q;
    while(p)q+=(p%10)+'0',p/=10;
    int f=0;
    for(int j=0;j<q.size()/2;j++){
      if(q[j]!=q[q.size()-1-j])f++;
    }
    if(!f)s++;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($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)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $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, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        M: usize,
        AB: [(usize,usize); M]
    }
    let mut vecA = vec![false; N];
    let mut vecB = vec![false; N];
    for (a,b) in AB{
        if a==1{
            vecA[b-1] = true;
        }
        if b==N{
            vecB[a-1] = true;
        }
    }
    let mut ans = "IMPOSSIBLE";
    for i in 0..N{
        if vecA[i] && vecB[i]{
            ans = "POSSIBLE";
            break;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 8444
#include <stdio.h>
int main(){
  
  char S[10];
  int i = 0;
  int N = 0;
  
  scanf("%s", S);
  
  if (S[0] == 'o') ++i;
  if (S[1] == 'o') ++i;
  if (S[2] == 'o') ++i;
  
  N = 100*i + 700;
  
  printf("%d", N);
return 0;
}

Measured memory_bytes: 128
def get_pair():
    return map(int, input().split())

cnt = 0
ans = "No"
for idx in range(int(input())):
    D1, D2 = get_pair()
    if D1 == D2:
        cnt += 1
    else:
        cnt = 0

    if cnt >= 3:
        ans = "Yes"
        break
print(ans)

Measured memory_bytes: 9168
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var X = long.Parse(Console.ReadLine());
        var fifth = Enumerable.Range(0, 500).Select(i => ((long)i) * i * i * i * i).ToArray();
        var dict = fifth.Select((v, index) => new { index, v }).ToDictionary(kv => kv.v, kv => kv.index);
        var hash = new HashSet<long>(fifth);

        foreach (var a5 in fifth)
        {
            var b5 = a5 - X;
            var absB5 = Math.Abs(b5);
            if (hash.Contains(absB5))
            {
                var a = dict[a5];
                var b = dict[absB5];
                if (b5 < 0)
                {
                    b *= -1;
                }
                Console.WriteLine($"{a} {b}");
                return;
            }
        }
    }
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int n;
int d[105][2];

int main() {
	scanf("%d", &n);
	rep(i, n) scanf("%d %d", &d[i][0], &d[i][1]);
	rep(i, n - 2) {
		if (d[i][0] == d[i][1] &&
			d[i + 1][0] == d[i + 1][1] &&
			d[i + 2][0] == d[i + 2][1]) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  	cin>>n;
  int tot = 0;
  	for(int i=1;i<=n;i++){
    	if(i&1)tot++;
    }
  	printf("%f\n",1.0*tot/n);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
void GetDiv(int m, vector<int> &div) {
	for (int d = 1; d <= sqrt(m); d++) {
		if (m % d != 0) {
			continue;
		}
		div.push_back(d);
	}
}

int main (void) {
	int n, m; cin >> n >> m;

	vector<int> div;
	GetDiv(m, div);

	int mx = 1;

	for (int i = 0; i < div.size(); i++) {
		if (div[i] >= n) {
			if (mx < m/div[i]) {
				mx = m/div[i];
			}
		}
		if (m / div[i] >= n) {
			if (mx < div[i]) {
				mx = div[i];
			}
		}
	}
	cout << mx << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a[3][3]={0}, i, j, k;
    for(i=0; i<3; i++){
        for(j=0; j<3; j++){
            scanf("%d", &a[i][j]);
        }
    }
    int n, m;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d",&m);
        for(j=0; j<3; j++){
            for(k=0; k<3; k++){
                if(a[j][k]==m){ a[j][k]=0; }
            }
        }
    }
    int flag=0;
    for(i=0; i<3; i++){
        if( a[i][0]==0 && a[i][1]==0 && a[i][2]==0 ){ flag=1; }
        if( a[0][i]==0 && a[1][i]==0 && a[2][i]==0 ){ flag=1; }
    }
    if( a[0][0]==0 && a[1][1]==0 && a[2][2]==0 ){ flag=1; }
    if( a[0][2]==0 && a[1][1]==0 && a[2][0]==0 ){ flag=1; }

    if( flag ){ printf("Yes\n"); }
    else      { printf("No\n");  }
    return 0;
}

Measured memory_bytes: 1660
N = int(input())
W = list(map(int, input().split()))

ans = abs(W[0] - sum(W[1:]))
for i in range(1, N):
    if ans > abs(sum(W[:i+1]) - sum(W[i+1:])):
        ans = abs(sum(W[:i+1]) - sum(W[i+1:]))
    else:
        ans = ans
print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const long long MAXN=2000005,MOD=1e9+7;
long long x[7],y[7];
long long jc[MAXN],Inv[MAXN];
struct node
{
	long long x,y,c;
	node(){}
	node(long long xx,long long yy,long long cc)
	{
		x=xx,y=yy,c=cc;
	}
}a[4],b[4];
long long C(long long x1,long long y1,long long x2,long long y2)
{
	long long X=x2-x1;
	long long Y=y2-y1;
	return ((jc[X+Y]*Inv[X])%MOD*Inv[Y])%MOD;
}
long long ksm(long long x,long long y)
{
	long long k=1;
	while(y)
	{
		if(y&1)
			k=(k*x)%MOD;
		x=(x*x)%MOD;
		y>>=1;
	}
	return k;
}
void Init()
{
	jc[0]=1;
	for(long long i=1;i<MAXN;i++)
		jc[i]=(jc[i-1]*i)%MOD;
	Inv[MAXN-1]=ksm(jc[MAXN-1],MOD-2);
	for(long long i=MAXN-2;i>=0;i--)
		Inv[i]=(Inv[i+1]*(i+1))%MOD;
}
long long solve(node A,node B)
{
	long long x1=A.x,y1=A.y;
	long long x2=B.x,y2=B.y;
	long long re=0;
	for(long long i=x[3];i<=x[4];i++)
	{
		re+=((C(x1,y1,i,y[3]-1)*C(i,y[3],x2,y2))%MOD*(-i-y[3]))%MOD;
		re%=MOD;
	}
	for(long long i=y[3];i<=y[4];i++)
	{
		re+=((C(x1,y1,x[3]-1,i)*C(x[3],i,x2,y2))%MOD*(-i-x[3]))%MOD;
		re%=MOD;
	}
	for(long long i=x[3];i<=x[4];i++)
	{
		re+=((C(x1,y1,i,y[4])*C(i,y[4]+1,x2,y2))%MOD*(i+y[4]+1))%MOD;
		re%=MOD;
	}
	for(long long i=y[3];i<=y[4];i++)
	{
		re+=((C(x1,y1,x[4],i)*C(x[4]+1,i,x2,y2))%MOD*(i+x[4]+1))%MOD;
		re%=MOD;
	}
	return re;
}
int main()
{
	Init();
	for(long long i=1;i<=6;i++)
		scanf("%lld",&x[i]);
	for(long long i=1;i<=6;i++)
		scanf("%lld",&y[i]);
	a[0]=node(x[2]	,y[2]	,1);
	a[1]=node(x[2]	,y[1]-1	,-1);
	a[2]=node(x[1]-1,y[2]	,-1);
	a[3]=node(x[1]-1,y[1]-1	,1);
	b[0]=node(x[6]+1,y[6]+1	,1);
	b[1]=node(x[6]+1,y[5]	,-1);
	b[2]=node(x[5]	,y[6]+1	,-1);
	b[3]=node(x[5]	,y[5]	,1);
	long long ans=0;
	for(long long i=0;i<4;i++)
	{
		for(long long j=0;j<4;j++)
		{
			ans+=a[i].c*b[j].c*solve(a[i],b[j]);
			ans%=MOD;
		}
	}
	printf("%lld\n",(ans+MOD)%MOD);
}

Measured memory_bytes: 31360
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  vector<int> a(n);
  map<int, int> mp;
  rep(i, n) cin >> a[i];
  rep(i, n - 1) a[i + 1] += a[i];
  rep(i, n) {
    if (a[i] % m == 0) ans++;
    mp[a[i] % m]++;
  }
  for (auto x : mp) {
    if (2 <= x.second) {
      ans += (x.second) * (x.second - 1) / 2;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
A = list(ma())
tot = 1000
kab = 0
for i in range(n-1):
    tot += A[i]*kab
    kab = 0
    if A[i] > A[i+1]:
        pass
    if A[i] <= A[i+1]:#価値が上がるなら
         kab,tot = divmod(tot,A[i])
tot+=A[-1]*kab
print(tot)


Measured memory_bytes: 9472
#include <iostream>
#include <algorithm>

int h[101010];
int main()
{
	int n, mi = 2e9 + 1, k; std::cin >> n >> k;
	for (int i = 1; i <= n; ++i) std::cin >> h[i];
	std::sort(h + 1, h + n + 1);
	for (int i = k; i <= n; ++i)
		mi = std::min(mi, h[i] - h[i - k + 1]);
	std::cout << mi;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int a, b;
int main() {
	scanf("%d%d", &a, &b);
	printf("%d", a - 1 + (a <= b));
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  char** board = new char*[H];
  for (int i = 0; i < H; i++) {
      board[i] = new char[W];
      for (int j = 0; j < W; j++) {
          cin >> board[i][j];
      }
  }

  for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
          int count = 0;
          if (board[i][j] == '.') {
              int x, y;
              // 左上
              x = j - 1;
              y = i - 1;
              if (x >= 0 && y >= 0) {
                  if (board[y][x] == '#') {
                      count++;
                  }
              }
              // 左
              x = j - 1;
              y = i;
              if (x >= 0 && y >= 0) {
                  if (board[y][x] == '#') {
                      count++;
                  }
              }
              // 左下
              x = j - 1;
              y = i + 1;
              if (x >= 0 && y < H) {
                  if (board[y][x] == '#') {
                      count++;
                  }
              }
              // 右上
              x = j + 1;
              y = i - 1;
              if (x < W && y >= 0) {
                  if (board[y][x] == '#') {
                      count++;
                  }
              }
              // 右
              x = j + 1;
              y = i;
              if (x < W && y >= 0) {
                  if (board[y][x] == '#') {
                      count++;
                  }
              }
              // 右下
              x = j + 1;
              y = i + 1;
              if (x < W && y < H) {
                  if (board[y][x] == '#') {
                      count++;
                  }
              }
              // 上
              x = j ;
              y = i - 1;
              if (y >= 0) {
                  if (board[y][x] == '#') {
                      count++;
                  }
              }
              // 下
              x = j ;
              y = i + 1;
              if (y < H) {
                  if (board[y][x] == '#') {
                      count++;
                  }
              }
              cout << count;
          } else {
              cout << "#";
          }
      }
      cout << endl;
  }

  for (int i = 0; i < H; i++) delete [] board[i];
  delete [] board;
}


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

int main() {
  int N;
  std::cin >> N;
  int temp_min;
  int temp_max;
  for (int i=0; i<N; i++) {
    if (i == 0) {
      int n;
      std::cin >> n;
      temp_max = n;
      temp_min = n;
    }
    else {
      int n;
      std::cin >> n;
      temp_max = std::max(temp_max, n);
      temp_min = std::min(temp_min, n);
    }
  }
  std::cout << temp_max - temp_min << std::endl;
}

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

int main(){
	int N, i, ans = 0;
	scanf("%d", &N);
	vector<int> A(N), B(N), C(N);
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
		A[i]--;
	}
	for(i = 0; i < N; i++){
		scanf("%d", &B[i]);
	}
	for(i = 0; i < N - 1; i++){
		scanf("%d", &C[i]);
	}
	for(i = 0; i < N; i++){
		ans += B[i];
	}
	for(i = 0; i < N - 1; i++){
		if(A[i] + 1 == A[i + 1]){
			ans += C[A[i]];
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))

res = float('inf')
for i in range(n - k + 1):
    if x[i] <= 0 and x[i+k-1] <= 0:
        res = min(res, abs(x[i]))
    elif x[i] <= 0 and x[i+k-1] >= 0:
        res = min(res, 2 * abs(x[i]) + abs(x[i+k-1]), abs(x[i])+ 2 * abs(x[i+k-1]))
    else:
        res = min(res, abs(x[i+k-1]))

print(res)

Measured memory_bytes: 85396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,A,X=0;
  cin >>N>>M;
  for (int i=0;i<M;i++){
    cin>>A;
    X+=A;
  }
  if(X<=N){
    cout <<N-X<<endl;
  }
  else{
    cout<<"-1"<<endl;
  }
}

Measured memory_bytes: 3656
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    s = input().rstrip()

    n_R = s.count("R")
    n_B = s.count("B")
    if n_R > n_B:
        ans = "Yes"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#define MAX 200000
#define INFTY 2000000000
void Merge(int[MAX],int,int,int);
void MergeSort(int[MAX],int,int);
long long cnt = 0;

int main()
{
    int i, n;
    int A[MAX];
  
    scanf("%d", &n);
    for(i =0; i < n; i++)
        scanf("%d", &A[i]);
    MergeSort(A, 0, n);
    printf("%lld\n",cnt);
    return 0;
}
 
void Merge(int A[MAX], int left, int mid, int right)
{
  int i,j,k;
  int na,nb;
  
  na = mid - left;
  nb = right - mid; 
  int L[MAX], R[MAX];
  for(i = 0; i < na; i++)
    L[i] = A[left + i];
  for(i = 0; i < nb; i++)
    R[i] = A[mid + i];
  L[na] = INFTY; R[nb] = INFTY;
  i = 0;j = 0;
  for(k = left; k < right; k++)
  {
    if(L[i] <= R[j])
      A[k] = L[i++];
    else
    {
      A[k] = R[j++];
      cnt += na - i;
    }
  }
  
}
  
void MergeSort(int A[MAX], int left, int right)
{
  
  int mid;
  if((left + 1) < right)
  { 
    mid = (left + right) / 2; 
    MergeSort(A, left, mid);
    MergeSort(A, mid, right); 
    Merge(A, left, mid, right);
  
  }
  
}


Measured memory_bytes: 3284
#include <stdio.h>

#define N 100
#define INF 100000000
#define NIL -1
#define WHITE 1
#define BLACK 0

void prim(void);

int n,d[N],color[N],G[N][N],pi[N];

int main(){
    int i,j,u,k,v,c;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            G[i][j]=INF;
        }
    }

    for(i=0;i<n;i++){
        scanf("%d%d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d%d",&v,&c);
            G[u][v]=c;
        }
    }

    prim();

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

    return 0;
    
}

void prim(){
    int u,v,mincost,i;

    for(u=0;u<n;u++){
        d[u]=INF;
        pi[u]=NIL;
        color[u]=WHITE;
    }

    d[0]=0;

    while(1){
        mincost=INF;

        for(i=0;i<n;i++){
            if(color[i]!=BLACK && d[i]<mincost){
                mincost=d[i];
                u=i;
            }
        }

        if(mincost==INF) break;

        color[u]=BLACK;

        for(v=0;v<n;v++){
            if(G[u][v]!=NIL){
                if(color[v] != BLACK && d[u]+G[u][v] < d[v]){
                    pi[v]=u;
                    d[v]=d[u]+G[u][v];
                }
            }
        }
    }
}

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

int main(){
    int a, p;
    cin >> a >> p;
    cout << (a*3+p) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>

//定数
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
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; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl fact(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,O(logN)




signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl a[n];
    rep(i,n)cin >> a[i];
    intl cnt = 0;
    for(intl i = 0; i < n; i += 2){
        if(a[i] % 2)cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;
#define INF 10000000000000
#define DIM 100007
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define fi first
#define se second
#define mood 1000000007
#define PI 3.14159265358979323
typedef  pair< long long, pair<long long, long long> > ppll;
//20 05
long long  n,m,b,a,c,x,e,h,k,res1,a1,a2,w,a3,y,z,a4,a5,a6,a7,a8,a9,a10,last,LL,timer,start,finish,flag,step,tests,kilk;
string s,s1;
char t;
struct line{
    ll k,b;
};
line lines[200007];

ll mas[200007],dp[200007],benz[200007];
ll res;
ll nline;
ll check(line L1,line L2,line L3){
    return (ld)(L3.b-L1.b)/(ld)(L1.k-L3.k)>=(ld)(L3.b-L2.b)/(ld)(L2.k-L3.k);
}

void addline(ll k ,ll b){
    line L={k,b};
    while(nline>=2 && check(lines[nline-1],lines[nline],L))nline--;
    lines[++nline]=L;
}

ll F(ll num,ll x){
    return  lines[num].k*x+lines[num].b;
}

ll getmin(ll x){
    ll l=0;ll r=nline;
    while(r-l>1){
        ll mid=(l+r)/2;
        if(F(mid,x)<F(mid+1,x)){
            r=mid;
        }else{
            l=mid;
        }
    }
    return F(r,x);
}

int main()
{

    cin>>n>>c;
    for(int i=1;i<=n;i++)cin>>mas[i];
    //for(int i=1;i<=n;i++)cin>>benz[i];

    addline(-2*mas[1],mas[1]*mas[1]);
    for(int i=2;i<=n;i++){
        dp[i]=getmin(mas[i])+mas[i]*mas[i]+c;
        addline(-2*mas[i],dp[i]+mas[i]*mas[i]);
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<char> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  bool answer = false;
  for (char c : S) {
    if (c == 'Y') {
      answer = true;
      break;
    }
  }
  if (answer == false){
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
import sys
import collections
n = int(input())
d = list(map(int, input().split()))

if d[0] != 0:
    print("0")
    sys.exit()


d.sort()
c = collections.Counter(d)

if c[0] != 1:
    print("0")
    sys.exit()
    
ans = 1
for i in range(len(c)-1):
    x = c[i] ** c[i+1]
    ans *= x
    ans = ans % 998244353


print(ans)







        


    







        



Measured memory_bytes: 19936
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    //前２個、後ろ２個を取る。12を超えているかどうかで判定すればよい
    int a,b;
    a = (s.at(0)-'0')*10+(s.at(1)-'0');
    b = (s.at(2)-'0')*10+(s.at(3)-'0');
   // cout<<a<<" "<<b<<endl;
   //超えてる　超えてる　からやる。
   if((a==0&&b==0)||(a==0&&12<b)||(12<a&&b==0)||(12<a&&12<b)){
       cout<<"NA"<<endl;
   }
   else if((a==0&&0<b&&b<13)||(12<a&&0<b&&b<13)){
       cout<<"YYMM"<<endl;
   }
   else if((0<a&&a<13&&b==0)||(0<a&&a<13&&12<b)){
       cout<<"MMYY"<<endl;
   }
   else if(0<a&&a<13&&0<b&&b<13){
       cout<<"AMBIGUOUS"<<endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
    int n = 3;
    vector<int> A(n);
    for(int i=0; i<n; i++) cin >> A[i];
    sort(A.begin(), A.end());
    cout << A[0] << " " << A[1] << " " << A[2] << endl;
    return 0;
}

Measured memory_bytes: 3096
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  vector<vector<vector<long long> > > dp(n + 1, vector<vector<long long> >(n + 1, vector<long long>(n * n + 1, 0)));
  dp[0][0][0] = 1;
  REP(x, n) REP(y, x + 1) REP(z, n * n + 1) if (z + 2 * y <= n * n) {
    (dp[x + 1][y][z + 2 * y] += dp[x][y][z] * (2 * y + 1) % MOD) %= MOD;
    if (y > 0) (dp[x + 1][y - 1][z + 2 * y] += dp[x][y][z] * y % MOD * y % MOD) %= MOD;
    if (y < n) (dp[x + 1][y + 1][z + 2 * y] += dp[x][y][z]) %= MOD;
  }
  cout << dp[n][0][k] << '\n';
  return 0;
}


Measured memory_bytes: 52224
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n,k = gets.split.map(&:to_i)

h = []
n.times { h << gets.to_i}


# ary = h.combination(k).to_a
h.sort!


min = INF
0.upto(n-k) do |i|
  sa = (h[i] - h[i + k - 1]).abs
  
  if min > sa
    min = sa
  end
end

puts min


# 5 3
# 5   
# 5
# 7    
# 7
# 7



Measured memory_bytes: 4016
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        long[] A = new long[N];
        for(int i=0;i<N;i++){
            A[i] = int.Parse(str[i]);
        }
        int[] a = new int[N];
        for(int i=0;i<N;i++){
            a[i] = i;
        }
        Array.Sort(a,(x,y)=>(A[x] < A[y] ? 1 : (A[x] == A[y] ? 0 : -1)));
        long count = A[a[0]];
        int nowp = a[0];
        long[] ans = new long[N];
        for(int i=1;i<N;i++){
            if(nowp > a[i]){
                ans[nowp] = count - i*A[a[i]];
                count = (i+1)*A[a[i]];
                nowp = a[i];
            }
            else{
                count += A[a[i]];
            }
        }
        ans[nowp] = count;
        for(int i=0;i<N;i++){
            sb.Append(ans[i]+"\n");
        }
    }
}

Measured memory_bytes: 33492
a = input()
b = [int(e)-1 for e in raw_input().split(' ')]
count = 0
for i in xrange(a):
    if b[i] != -1:
        if b[b[i]] != -1:
            if b[b[i]] == i:
                count+=1
                b[b[i]] = -1
        b[i] = -1
print count

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int n,m;
map<string,int> mp;

int main(){
  cin >> n;
  REP(i,n){
    string s;
    cin >> s;
    if(mp.find(s) != mp.end()){
      mp[s]++;
    }else{
      mp[s] = 1;
    }
  }
  cin >> m;
  REP(i,m){
    string s;
    cin >> s;
    if(mp.find(s) != mp.end()){
      mp[s]--;
    }else{
      mp[s] = -1;
    }
  }
  int ma = 0;
  for(auto itr = mp.begin();itr != mp.end();++itr){
    ma = max(ma,itr->second);
  }
  cout << ma << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define pq          priority_queue
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define vll         vector<pll>
#define f           first
#define s           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
ll v[100005],k,n;
//ll dp[100005];
ll c1(ll a, ll b)
{
    if(a%b==0) return (a/b)-1;
    else return (a/b);
}
bool check(ll m)
{   ll s=0;
    for(int i=1;i<n;i++)
        s+=c1(v[i]-v[i-1],m);
    return s<=k;
}
bool ispalindrome(string s2)
{
    ll n=s2.size();
    ll l=0,h=n-1;
    while(h>=l)
        if(s2[l++]!=s2[h--]) return 0;
    return 1;
}
void solve()
{
 ll t,b,m;
 string s1;
 double x;
 cin>>n;
 x=(n/(double)3);
 //cout<<x;
 cout<<setprecision(15)<<x*x*x;

}   

int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}



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

inline std::unordered_map<std::int64_t, int_t> memo{};

int_t solve(std::int64_t N, int_t A, int_t B, int_t C, int_t D)
{
    if(N == 0)
    {
        return 0;
    }
    if(N == 1)
    {
        return D;
    }


    if(memo.count(N) != 0)
    {
        return memo.at(N);
    }

    const auto Nmod2 = N % 2;
    const auto Nmod3 = N % 3;
    const auto Nmod5 = N % 5;

    int_t tok2;


    if(Nmod2 == 0)
    {
        tok2 = std::min(A, D * (N / 2)) + solve(N / 2, A, B, C, D);
    }
    else
    {
        const int_t tok2p = D *      Nmod2  + std::min(A, D * (N-Nmod2  )/2) + solve((N - Nmod2)     / 2, A, B, C, D);
        const int_t tok2n = D * (2 - Nmod2) + std::min(A, D * (N-Nmod2+2)/2) + solve((N - Nmod2 + 2) / 2, A, B, C, D);
        tok2 = std::min(tok2p, tok2n);
    }

    int_t tok3;

    if(Nmod3 == 0)
    {
        tok3 = std::min(B, D * (2 * N / 3)) + solve(N / 3, A, B, C, D);
    }
    else
    {
        const int_t tok3p = D *      Nmod3  + std::min(B, D * (N-(N-Nmod3  )/3)) + solve((N - Nmod3)     / 3, A, B, C, D);
        const int_t tok3n = D * (3 - Nmod3) + std::min(B, D * (N-(N-Nmod3+3)/3)) + solve((N - Nmod3 + 3) / 3, A, B, C, D);
        tok3 = std::min(tok3p, tok3n);
    }

    int_t tok5;
    if(Nmod5 == 0)
    {
        tok5 = std::min(C, D*N*4/5) + solve(N / 5, A, B, C, D);
    }
    else
    {
        const int_t tok5p = D *      Nmod5  + std::min(C, D * (N-(N-Nmod5  )/5)) + solve((N - Nmod5)     / 5, A, B, C, D);
        const int_t tok5n = D * (5 - Nmod5) + std::min(C, D * (N-(N-Nmod5+5)/5)) + solve((N - Nmod5 + 5) / 5, A, B, C, D);
        tok5 = std::min(tok5p, tok5n);
    }
    const auto score = std::min(std::min(tok2, tok3), tok5);
    memo[N] = score;
    return score;
}

int main()
{
    std::size_t T;
    std::cin >> T;

    for(std::size_t t=0; t<T; ++t)
    {
        memo.clear();
        std::size_t N, A, B, C, D;
        std::cin >> N >> A >> B >> C >> D;
        std::cout << solve(N, A, B, C, D) << std::endl;
    }
    return 0;
}


Measured memory_bytes: 4088
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x);
		y = y >> 1;
		x = (x * x);
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s, t;
	ll ans = 0;
	cin >> s >> t;
	f(i, 0, 3)
	{
		if (s[i] == t[i])
			ans += 1;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

template<class T>
void maxi(T &a, const T &b){
   if(a < b) a = b;
}
template<class T>
void mini(T &a, const T &b){
   if(a > b) a = b;
}

int n, m;
int ss[11234], alone[11234];

void solve() {
    int ans = 0;
    REP(i,n) {
        REP(j,n) {
            if (i == j) continue;
            ans = max(ans, ss[i] - alone[j] + 1);
        }
    }
    cout << ans << endl;
}

int main(int argc, char *argv[]){
    while (cin >> n >> m, n && m) {
    REP(i, m){
        int s, k;
        int c[11234];
        cin >> s >> k;
        REP(j, k){
            cin >> c[j];
            --c[j];
        }
        REP(j, k) ss[c[j]] += s;
        if(k == 1) alone[c[0]] += s;
    }
    solve();
    REP(i, n){
        ss[i] = alone[i] = 0;
    }
    }
    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
	}
	if (n <= k) {
		cout << 1 << endl;
		return 0;
	}
	n -= k;
	if (n % (k - 1) == 0) cout << 1 + n / (k - 1) << endl;
	else cout << n / (k - 1) + 2 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();

		int[] bArray = new int[M];
		for(int i=0; i<M; i++) {
			bArray[i] = sc.nextInt();
		}


		int[][] aArray = new int[N][M];

		for(int i=0; i<N; i++) {
			for(int j=0; j<M; j++) {
				aArray[i][j] = sc.nextInt();
			}
		}

		int ans = 0;

		for(int i=0; i<N; i++) {
			int result=0;
			for(int j=0; j<M; j++) {
				result += aArray[i][j]*bArray[j];
			}
			ans += result + C >0 ? 1 : 0;
		}

		System.out.println(ans);
	}
}


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

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;

    if(e-a<=k){
        cout << "Yay!"<< endl;
    }else{
        cout << ":("<<endl;
    }
    return 0;
}

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

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
}



Measured memory_bytes: 256
#include <stdio.h> 
int main(){ 
     int i, n; 
     int arr[100]; 
     scanf("%d", &n); 
     for(i=0;i<n;i++){ 
         scanf(" %d", &arr[i]); 
     } 
     for(i=0;i<n;i++){ 
         if(i)printf(" "); 
         printf("%d", arr[n-i-1]); 
     } 
     printf("\n"); 
     return 0; 
 } 



Measured memory_bytes: 2124
#include <cstdio>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n,m;
vector<int> cell[5010];

int main(){
	rep(i,5010){
		rep(j,i+1) cell[i].push_back(0);
	}
	scanf("%d%d",&n,&m);
	rep(i,m){
		int a,b,x; scanf("%d%d%d",&a,&b,&x);
		a--; b--;
		cell[a][b] += 1; if(a>=b+1)cell[a][b+1] += -1;
		cell[a+x+1][b] += -1; cell[a+x+2][b+1] += 1;
		if(a+x+1>=b+x+2)cell[a+x+1][b+x+2] += 1; if(a+x+2>=b+x+2)cell[a+x+2][b+x+2] += -1;
	}
	rep(i,5010) for(int j = 1; j < 5010; j++){
		if(i<j||i<j-1)continue;
		cell[i][j] += cell[i][j-1];
	}
	rep(i,5010) for(int j = 1; j < 5010; j++){
			if(j<i||j-1<i)continue;
			cell[j][i] += cell[j-1][i];
	}
	for(int i = 1; i < 5010; i++) for(int j = 1; j < 5010; j++){
		if(i+j>5010) break;
		if(i+j-1<j||i+j-1<j-1) continue;
		cell[i+j-1][j] += cell[i+j-2][j-1];
	}
	int ans = 0;
	rep(i,5010) rep(j,5010){
		if(i<j)continue;
		ans+=(cell[i][j]!=0);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 62784
#include <stdio.h>

int main(void) {
int a, b;
char op;

while (op != '?') {
scanf("%d %c %d", &a, &op, &b);
if(op == '+') printf("%d\n", a + b);
else if(op == '-') printf("%d\n", a - b);
else if(op == '*') printf("%d\n", a * b);
else if(op == '/') printf("%d\n", a / b);

}

return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
using namespace std;
int main(){
    double W,L,x,y,u;
    int t=0;
    cin >> W >> L >> x >> y ;
    if(x*2==W && y*2==L){
        t=1;
    }
    u=W/2*L;
    printf("%f %d",u,t);
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
using namespace std;
typedef pair<int, int> P;
int main(){
    int N, M;
    cin >> N >> M;
    vector<P> Y(M);
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        Y[i] = P(a, b);
    }
    int cnt = 1;
    vector<int> ind(M);
    for(int i = 0; i < M; i++){
        ind[i] = i;
    }
    sort(ind.begin(), ind.end(), [&](int i, int j){
        if(Y[i].first != Y[j].first)return Y[i].first < Y[j].first;
        return Y[i].second < Y[j].second;
    });
    vector<string> ans(M);
    for(int i = 0; i < M; i++){
        string s1 = "000000", s2 = "000000";
        P v = Y[ind[i]];
        string t1 = to_string(cnt);
        string t2 = to_string(v.first);
        int te = 6;
        for(int i = 0; i < t1.size(); i++){
            s2[te - t1.size() + i] = t1[i];
        }
        for(int i = 0; i < t2.size(); i++){
            s1[te - t2.size() + i] = t2[i];
        }
        ans[ind[i]] = s1 + s2;
        if(i != M - 1 && Y[ind[i]].first == Y[ind[i + 1]].first) cnt++;
        else cnt = 1;
    }
    for(int i = 0; i < M; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 7488
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(M);
  vector<int> d(M);
  for(int i=0;i<N;i++){
    cin >> a.at(i) >> b.at(i);
  }
  for(int i=0;i<M;i++){
    cin >> c.at(i) >> d.at(i);
  }

  for(int i=0;i<N;i++){
    int ans=1000000000;
    int num=0;
    for(int j=0;j<M;j++){
      int x=abs(a.at(i)-c.at(j)) + abs(b.at(i)-d.at(j));
      if(ans>x){
        ans=x;
        num=j+1;
      }
    }
    cout << num << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256