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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

vint pos(5);
int k;
bool check=true;

int main(){
    int x;
    cin>>x;
    if(x==1)cout<<"Hello World"<<endl;
    else{
        int y,z;
        cin>>y>>z;
        cout<<y+z<<endl;
    }
}

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



}


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

using namespace std;

#define ll long long
#define ss stringstream
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;

int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("outcout<<put.txt","w",stdin);*/
	int a,b,c;
	cin>>a>>b>>c;
	int d=abs(b-a)+abs(c-b),
		e=abs(c-a)+abs(b-c),
		f=abs(a-b)+abs(c-a);
	cout<<(min(d,min(e,f)));
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    int computeMaxProfit(int n, int[] R){
        int maxProfit = -999999999;
        int minPrice = R[0];
        for(int i = 0; i < n - 1; i++){
            if(R[i] < minPrice){
                minPrice = R[i];
            }
            maxProfit = Math.max(maxProfit, R[i+1] - minPrice);
        }
        return maxProfit;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = scanner.nextInt();
        int[] R = new int[size];
        
        for(int i = 0; i < size; i++){
            R[i] = scanner.nextInt();
        }
        Main test = new Main();
        System.out.println(test.computeMaxProfit(size, R));
    }
}


Measured memory_bytes: 100576
(defun div2count (N)
  (let ((str (format nil "~B" N)))
    (1- (- (length str)
	   (position #\1 str :from-end t)) )))


(defun solve (l)
  (reduce (lambda (x y) (+ x (div2count y)))
	  l :initial-value 0) )

(princ (solve (loop :repeat (read) :collect (read))))

Measured memory_bytes: 24936
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int H = sc.nextInt();
        int W = sc.nextInt();
 
        long r1 = calc(H, W);
        long r2 = calc(W, H);
        _out.println(Math.min(r1, r2));
    }
    private long calc(long w, long h) {
        if (w % 3 == 0 || h % 3 == 0) {
            return 0;
        }
 
        long res = Long.MAX_VALUE;
        for (long i = h / 3; i <= h / 2; ++i) {
            {
                long a1 = i * w;
                long a2 = ((h - i) / 2) * w;
                long a3 = (h - i - ((h - i) / 2)) * w;
                long max = Math.max(a1, Math.max(a2, a3));
                long min = Math.min(a1, Math.min(a2, a3));
                res = Math.min(res, max - min);
            }
            {
                long a1 = i * w;
                long a2 = (h - i) * (w / 2);
                long a3 = (h - i) * (w - w / 2);
                long max = Math.max(a1, Math.max(a2, a3));
                long min = Math.min(a1, Math.min(a2, a3));
                res = Math.min(res, max - min);
            }
        }
        return res;
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    string S;
    cin >> S;
    if(S == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  ll N,M;
  scanf("%lld%lld", &N,&M);
  
  ll sum = N*2+M;
  cout << min(sum/4,M/2) << endl;

}



Measured memory_bytes: 256
n = input()
l = len(n) - 1

for i in range(2 ** l):
    ans: int = int(n[0])
    num = n[0]
    for j in range(l):
        if (i >> j) & 1:
            num += "+"
            num += n[j + 1]
        else:
            num += "-"
            num += n[j + 1]
    for k in range(1, len(num), 2):
        if num[k] == "-":
            ans -= int(num[k+1])
        else:
            ans += int(num[k+1])
    if ans == 7:
        print(num + "=7")
        break


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

//curという変数に「最後の壁から何マス来たのかを格納しておいて、iが壁なら0に戻し、iが通路ならお￥インクリメントする
//4方向分のcurの情報をleft,right,up,downに格納する
int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];
int h, w;

int main(){
    
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s.at(i);

    //前処理
    rep(i,h){
        int cur=0;
        rep(j,w){
            if(s[i][j] == '#') cur=0;
            else cur++;
            Left[i][j] = cur;
        }
    }
    rep(i,h){
        int cur=0;
        for(int j=w-1;j>=0;j--){
            if(s[i][j] =='#') cur=0;
            else cur++;
            Right[i][j] = cur;
        }
    }
    rep(j,w){
        int cur=0;
        rep(i,h){
            if(s[i][j]=='#') cur=0;
            else cur++;
            Up[i][j] = cur;
        }
    }
    rep(j,w){
        int cur=0;
        for(int i=h-1;i>=0;i--){
            if(s[i][j]=='#') cur=0;
            else cur++;
            Down[i][j]=cur;
        }
    }

    //集計
    int res=0;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#') continue; //壁に光源は置けないので無視
            res = max(res, Left[i][j]+Right[i][j] +Up[i][j] +Down[i][j]-3);
        }
    }
    cout << res << endl;

}

Measured memory_bytes: 76812
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define M 1000000007
typedef long long ll;
int main() { 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t,a[1000000],n,i,j,c,k,m,x,y;
    string s;
    cin>>s;
    n=s.length();
    c=0;
    for(i=0;s[i];i++){
        if(s[i]=='A')
        c++;
    }
    if(c==0 || c==n)
    cout<<"No";
    else
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char**args) {
	int a, b;

	scanf("%d%d", &a, &b);

	if (a <= 5) {
		printf("%d", 0);
		return 0;
	} else if (a <= 12) {
		printf("%d", b / 2);
		return 0;
	} else {
		printf("%d", b);
		return 0;
	}
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

long long int c(long long int a, long long int b) {
	long long int res = 1;
	for (int i = 0; i < b; i++) {
		res *= (a - i);
	}
	for (int i = 1; i <= b; i++) {
		res /= i;
	}
	return res;
}

int main(int argc, char *argv[]) {

	string s;
	cin >> s;
	int k;
	cin >> k;
	int kk = k;
	long long int res = 0;
	for (int i = k; i < s.size(); i++) {
		long long int ret = c(i - 1, k - 1);
		ret *= pow(9, k);
		res += ret;
	}

	for (int i = 0; i < s.size(); i++) {
		int start = 0;
		if (i == 0) {
			start = 1;
		}
		for (int j = start; j < s[i] - '0'; j++) {
			if (j > 0 && k == 0) continue;
			long long ret;
			if (j == 0) {
				ret = c(s.size() - i - 1, k);
				ret *= pow(9, k);
			}
			else {
				ret = c(s.size() - i - 1, k - 1);
				ret *= pow(9, k - 1);
			}
			res += ret;
		}
		if (s[i] != '0') k--;
	}
	int c = 0;
	for (auto ss : s)
		if (ss != '0')
			c++;
	if (c == kk)
		res++;
	cout << res << endl;
}









Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,res=100000;
  cin>>N;
  
  for(int i=0; i<=N; i++){
    int cc=0;
    int t=i;
    while(t>0) cc+=t%6,t/=6;
    t=N-i;
    while(t>0) cc+=t%9,t/=9;
    if(res>cc) res=cc;
  }
  
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 10056
#define mod2 20071027
//#define mod 1000074259
#define base 139
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case %lld:\n", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
const ll N=300010;
ll a, b, k;
int main()
{
    cin>>a>>b>>k;
    ll c =min(a, k);
    k-=c;
    a-=c;
    c = min(b,k);
    b-=c;
    cout<<a<<" "<<b<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int f(int x )
{
	return x*x;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.Integral", "r", stdin );
	string str = "";

	while (getline (cin, str ) ){ 
		stringstream ss (str );
		int d;
		ss >> d;
		int area = 0;
		for (int x = d; x <= 600 - d; x += d ){
			area += d*f(x);
		} // end for
		cout << area << endl;
	} // end loop
		
	return 0;
}

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

const int mod = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  long long int ans = 1;
  for(int i=1;i<=N;i++) {
    ans *= i;
    ans = ans % mod;
  }

  cout << ans << endl;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int n; cin >> n;
    double res = 0;
    rep(i, n){
        double a; cin >> a;
        res += 1/a;
    }
    cout << 1/res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int MAXC = 1e9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> ids(n);
    iota(ids.begin(), ids.end(), 0);

    vector<ll> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }
    sort(ids.begin(), ids.end(), [&](int i1, int i2){
        return d[i1] < d[i2];
    });

    if (d[ids[0]] != d[ids[1]]) {
        cout << -1 << "\n";
        return 0;
    }

    vector< vector<int> > g(n);
    vector<int> u(m), v(m);
    map<P, int> memo;
    for (int i = 0; i < m; ++i) {
        cin >> u[i] >> v[i];
        u[i]--; v[i]--;
        if (u[i] > v[i]) swap(u[i], v[i]);
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }

    vector<int> c(n, -1);
    for (int ii = 0; ii < n; ++ii) {
        int i = ids[ii];
        if (c[i] != -1) continue;

        for (int j : g[i]) {
            if (c[j] == -1) continue;
            c[i] = 1 - c[j];
            memo[minmax(i, j)] = d[i];
            break;
        }

        if (c[i] == -1) {
            for (int j : g[i]) {
                if (d[i] != d[j]) continue;
                c[i] = 0;
                c[j] = 1;
                memo[minmax(i, j)] = d[i];
                break;
            }
        }

        if (c[i] == -1) {
            cout << -1 << "\n";
            return 0;
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << "BW"[c[i]];
    }
    cout << "\n";

    for (int i = 0; i < m; ++i) {
        P tar(u[i], v[i]);
        cout << (memo.find(tar) != memo.end() ? memo[tar] : MAXC) << "\n";
    }
    return 0;
}

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

using namespace std;

int D, N;
vector<int> MaxTempInfo;
vector<pair<int, int> > ColthesTempInfo;
vector<int> ColorInfo;
int DpColor[201][201];

void solve() {
	int curTemp, minTemp, maxTemp;

	fill(DpColor[0], DpColor[0] + 201 * 201, -1);
	curTemp = MaxTempInfo[0];
	for (int j = 1; j <= N; ++j) {
		minTemp = ColthesTempInfo[j - 1].first;
		maxTemp = ColthesTempInfo[j - 1].second;
		if (curTemp < minTemp || curTemp > maxTemp) {
			continue;
		}
		DpColor[1][j] = 0;
	}
	for (int i = 2; i <= D; ++i) {
		curTemp = MaxTempInfo[i - 1];
		for (int j = 1; j <= N; ++j) {
			minTemp = ColthesTempInfo[j - 1].first;
			maxTemp = ColthesTempInfo[j - 1].second;
			if (curTemp < minTemp || curTemp > maxTemp) {
				continue;
			}
			for (int k = 1; k <= N; ++k) {
				if (DpColor[i - 1][k] == -1) {
					continue;
				}
				DpColor[i][j] = max(DpColor[i][j], DpColor[i - 1][k] + abs(ColorInfo[j - 1] - ColorInfo[k - 1]));
			}
		}
	}
	
	cout << *max_element(DpColor[D], DpColor[D] + N) << endl;
}

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

	cin >> D >> N;
	for (int i = 0; i < D; ++i) {
		cin >> temp;
		MaxTempInfo.push_back(temp);
	}
	for (int i = 0; i < N; ++i) {
		cin >> a >> b >> c;
		ColthesTempInfo.push_back({ a,b });
		ColorInfo.push_back(c);
	}
	solve();
	
	return 0;
}


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

int main(){
    int a,b;
    scanf("%d %d", &a, &b);
   
    if(a == 1)
        a = 14;
    
    if(b == 1)
        b = 14;

    if(a == b){
        printf("Draw");
    }else if(a > b){
        printf("Alice");
    }else{
        printf("Bob");
    }
    
    printf("\n");
    return 0;    
}

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

template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

bool used[256];
string s;

int main() {
    cin >> s;
    for (auto i:s) {
        if (used[i]) {cout << "no" << endl; return 0;}
        used[i] = true;
    }

    cout << "yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define MX 50
#define EPS 0.00000000001
#define MOD 1000000007
#define PI acos(-1)
#define INF 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int k,n;
    cin>>k>>n;
    int a[n];
    loop(i,0,n) cin>>a[i];

    int ans = INT_MAX, diff;
    loop(i,0,n)
    {
        if(i) {diff = k - (a[i] - a[i-1]); ans = min(ans,diff);}
        else {diff = a[n-1] - a[0]; ans = min(ans,diff);}
    }

    cout<<ans<<'\n';

    return 0;
}


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

int main() {
	int n;
	cin>>n;
	int cnt=0;
	int f=0;
	for(int i=0;i<n;i++)
	{
	    int a,b;
	    cin>>a>>b;
	    if(a==b)
	    cnt++;
	    else
	    cnt=0;
	    
	    if(cnt>=3)
	    f=1;
	}
	if(f)
	cout<<"Yes\n";
	else
	cout<<"No\n";
	return 0;
	
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

int N, W, w, v, num;
vector<vector<int>> vec(4);
int f(int a, int b, int c, int d){
  int res = 0;
  vector<int> v = {a, b, c, d};
  REP(i, 4) chmin(v[i], (int)vec[i].size());
  REP(i, 4){
    REP(j, v[i]){
      res += vec[i][j];
    }
  }
  return res;
}

signed main() {
  cin >> N >> W;

  REP(i, N){
    cin >> w >> v;
    if(i == 0) num = w;
    vec[w-num].push_back(v);
  }

  REP(i, 4) sort(ALL(vec[i]), greater<int>());

  int ans = 0;
  REP(i, N+1){
    if(num*i > W) break;
    REP(j, N+1){
      if(num*i+(num+1)*j > W) break;
      REP(k, N+1){
        if(num*i+(num+1)*j+(num+2)*k > W) break;
        REP(l, N+1){
          if(num*i+(num+1)*j+(num+2)*k+(num+3)*l > W) break;
          ans = chmax(ans, f(i, j, k, l));
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;

class Sobaya
{
    static void Main(){
      new Sobaya().calc();
      return;
    }
      
    Scanner cin;
    
    void calc(){
        cin = new Scanner();
        string s = cin.next();
        int n = s.Length;
        
        int ans1 = 0;
        int ans2 = 0;
        
        for(int i1=0; i1<n; i1++) if((i1%2==0 && s[i1]=='1')||(i1%2==1 && s[i1]=='0')) ans1++;
        for(int i1=0; i1<n; i1++) if((i1%2==0 && s[i1]=='0')||(i1%2==1 && s[i1]=='1')) ans2++;
        
        int ans = ans1<ans2 ? ans1 : ans2;
        Console.WriteLine(ans);

    }
}




class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13664
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll p[20],c[20];
int main(){
    ll d,g,ans=1e9;
    cin>>d>>g;
    rep(i,0,d)cin>>p[i]>>c[i];
    for(int mask = 0; mask < (1 << d); mask++){
        ll tmp=0,cnt=0,big=0;
        rep(i,0,d){
            if(mask&(1<<i)){tmp+=p[i]*(i+1)*100+c[i];cnt+=p[i];}
            else big=i;
        }
        if(tmp<g){
            ll a=(big+1)*100;
            ll sum=(g-tmp+a-1)/a;
            if(sum>=p[big])cnt=1e9;
            else cnt+=sum;
        }
        ans=min(ans,cnt);
    }
    cout<<ans;
}

Measured memory_bytes: 256
import sys
#import time
import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
#import time

input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def find(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # ノードxが属する木のサイズを返す
    def size(self, x):
        return -self.root[self.find(x)]


n = ri()
d1=[tuple(rl())+tuple((i,)) for i in range(n)]
d2=copy.deepcopy(d1)

d1.sort(key=lambda x:x[0])
d2.sort(key=lambda x:x[1])
edge=[]
for i in range(n-1):
    edge.append((d1[i+1][2], d1[i][2],d1[i+1][0]-d1[i][0]))
    edge.append((d2[i+1][2], d2[i][2],d2[i+1][1]-d2[i][1]))


    
edge.sort(key=lambda x: x[2])
res=0
uf = UnionFind(n)
for e in edge:
    if uf.same(e[0], e[1]):
        continue
    uf.unite(e[0], e[1])
    res+=e[2]
print(res)

Measured memory_bytes: 137864
#include <iostream>

using namespace std;

#define MAX 100000
#define rep(i,n) for(int i=0;i<(n);++i)

int parent(int i) {return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i + 1;}

int main(){
    int H , A[MAX+1];

    cin >> H;
    for(int i=1; i<=H; ++i) cin >> A[i];

    for(int i=1; i<= H; ++i){
        cout << "node " << i  << ": key = " << A[i] << ", ";
        if(parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
        if(left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
        if(right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }

    return 0;
}


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

#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
	int n,s=0;
	map<int,int> mp;
	cin>>n;
	for(int i=0,x;i<n;++i){
		cin>>x;
		s+=x;
		mp[x]++;
	}
	int q;
	cin>>q;
	while(q--){
		int b,c;
		cin>>b>>c;
		s=s-(b*mp[b]);
		s=s+(c*mp[b]);
		mp[c]+=mp[b];
		mp[b]=0;
		cout<<s<<endl;
	}
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 9508
def slove():
    import sys
    input = sys.stdin.readline
    n, a, b = list(map(int, input().rstrip('\n').split()))
    if a > b:
        print(0)
    elif a == b:
        print(1)
    elif n - 2 < 0:
        print(0)
    else:
        c = n - 2
        print(abs(a * c - b * c) + 1)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
while True:
    try:
        card = list(str(input()))
        if card[0] == '-':
            break
        m = int(input())
        h = [0]*m
        for i in range(m):
            h[i] = int(input())
        for i in range(len(h)):
            tmp = card[0:h[i]]
            card = card[h[i]:]+tmp

        for i in range(len(card)-1):
            print(card[i],end = '')
        print(card[-1])
    except EOFError:
        break

Measured memory_bytes: 7576
def solve(n, k, a)
  return 1 if n == 0
  return 0 if k == 0
  ret = 0
  t = [a, Math.sqrt(n).to_i].min
  t.downto(t/k) do |x|
    ret += solve(n - x * x, k - 1, x)
  end
  ret
end

while n = gets.to_i
  break if n == 0
  puts solve(n, 4, n)
end

Measured memory_bytes: 8728
#include <stdlib.h>
int main() {
  int n,a[100000],i,d=0,x=1;
  scanf("%d",&n);
  for (i=0;i<n;i++) {
    scanf("%d",&a[i]);
  }
  for (i=1;i<n;i++) {
    if (d==0&&a[i]-a[i-1]!=0) {
      d=(a[i]-a[i-1])/(abs(a[i]-a[i-1]));
    }
    if (d*(a[i]-a[i-1])<0) {
      x++;
      d=0;
    }
  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, M , K;
  cin >> N >> M >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<ll> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  partial_sum(begin(A),end(A),begin(A));
  partial_sum(begin(B),end(B),begin(B));

  int ans = upper_bound(begin(B),end(B),K)-begin(B);
  for (int i = 0; i != N; ++i) {
    if (K < A[i]) break;
    ans = max(ans, 1+i+int(upper_bound(begin(B),end(B),K-A[i])-begin(B)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 6424
N=int(input())
v=[int(i) for i in input().split()]
if N==2:
    if v[0]==v[1]:
        print(1)
        exit()
    else:
        print(0)
        exit()
A=dict()
B=dict()
L=0
R=0
def inc(D,k):
    if k in D:
        D[k]+=1
    else:
        D[k]=1
for i in range(N):
    if i%2==0:
        L+=1
        inc(A,v[i])
    else:
        R+=1
        inc(B,v[i])
X=[(L,-1)]
Y=[(R,-2)]
for i in A:
    X.append((L-A[i],i))
for i in B:
    Y.append((R-B[i],i))
X.sort(reverse=True)
Y.sort(reverse=True)
while(True):
    if X[-1][1]!=Y[-1][1]:
        print(X[-1][0]+Y[-1][0])
        exit()
    else:
        vl=X[-1][0]+Y[-2][0]
        vr=X[-2][0]+Y[-1][0]
        if vl<vr:
            Y.pop()
            R-=1
        else:
            X.pop()
            L-=1

    

Measured memory_bytes: 25568
import java.util.Scanner;

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

        if(a < b){
            if(b < c){
                System.out.printf("%d %d %d"+kc, a, b, c);
            }else{ 
                if(a < c){
                    System.out.printf("%d %d %d"+kc,a, c, b);
                }else{
                    System.out.printf("%d %d %d"+kc,c, a, b);
                }
            }
        }else{
             if(a < c){
                System.out.printf("%d %d %d"+kc,b, a, c );
             }else{
                 if(c > b){
                     System.out.printf("%d %d %d"+kc,b, c, a);
                 }else{
                     System.out.printf("%d %d %d"+kc,c, b, a);
                 }
             }
        }
        sc.close();
    }
}




Measured memory_bytes: 26228
n, l = map(int, input().split())
a = list(map(int, input().split()))
ma = 0
midx = 0
for i in range(n - 1):
  if ma < a[i] + a[i + 1]:
    midx = i
    ma = a[i] + a[i + 1]
if l > ma:
  print('Impossible')
else:
  print('Possible')
  for i in range(midx):
    print(i + 1)
  for i in range(n - 1, midx, -1):
    print(i)
  

Measured memory_bytes: 14060
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

ll dp[1010][30303];

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i <= 30000; ++i) {
    dp[0][i] = 1e18;
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= 30000; ++j) {
      if (j < a[i]) {
        dp[i + 1][j] = dp[i][j];
      } else {
        dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
      }
    }
  }
  ll ans = 1e18;
  for (int i = h; i <= 30000; ++i) {
    ans = min(ans, dp[n][i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 237824
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){

    string s;
    cin >> s;
    ll n = s.size();
    ll ans[n] = {};

    ll cnt = 0;ll memo_index = 0,border_index = -1;
    rep(i,0,n-1){
        cnt++;
        if(s[i] == 'R' && s[i+1] == 'L'){
            memo_index = i;
        }
        else if(s[i] == 'L' && s[i+1] == 'R'){
            ans[memo_index] = cnt/2;
            ans[memo_index+1] = cnt - cnt/2;
            if((memo_index-border_index) % 2) swap(ans[memo_index],ans[memo_index+1]);
            cnt = 0;
            border_index = i;
        }
    }
    cnt++;
    ans[memo_index] = cnt/2;
    ans[memo_index+1] = cnt - cnt/2;
    if((memo_index-border_index) % 2) swap(ans[memo_index],ans[memo_index+1]);

    rep(i,0,n) cout << ans[i] << (i-n+1?" ":"");
    cout << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct edge{
  int from, to, cost;
  edge () {}
  edge(int from, int to, int cost) :
    from(from), to(to), cost(cost) {}
  bool operator < (const edge& r) const {
    return cost != r.cost ? cost > r.cost : from != r.from ? from < r.from : to < r.to;
  }
};

typedef vector<edge> edges;
typedef vector<edges> graph;

int main(){
  int N, M, K;
  while(cin>>N>>M>>K && N){
    graph g(N);
    REP(i, M){
      int a, b, c;
      cin>>a>>b>>c;
      a--; b--;
      g[a].push_back(edge(a, b, c));
      g[b].push_back(edge(b, a, c));
    }
    vector<int> dist(N, INF);
    REP(iter, K){
      int s; cin>>s; s--;
      queue<int> que;
      que.push(s);
      dist[s] = 0;
      while(!que.empty()){
        int u = que.front(); que.pop();
        FORIT(it, g[u]){
          int next = dist[u] + it->cost;
          if(next < dist[it->to]){
            dist[it->to] = next;
            que.push(it->to);
          }
        }
      }
    }
    int ans = 0;
    REP(u, N)FORIT(it, g[u]){
      int d1 = dist[u];
      int d2 = dist[it->to];
      int tmp = it->cost - abs(d1 - d2);
      assert(tmp >= 0);
      if(tmp % 2) tmp += 1;
      int mans = max(d1, d2) + tmp / 2;
      ans = max(ans, mans);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << "Christmas";
    for (int i = 24; i >= n; --i)
        cout << " Eve";
}


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

int main(){
  int N;
  cin >> N;
  int a[N] = {0};
  int temp = 0;
  for (int i = 0; i < N - 1; i++){
    cin >> temp;
    a[temp - 1]++;
  }
  for(int i = 0; i < N; i++)
    cout << a[i] << endl;
  return 0;
}

Measured memory_bytes: 4412
program main;
var
	a,b,c,d:integer;
	k:boolean;
begin
	k:=false;
	readln(a,b,c,d);
    while (a>0) and (c>0) do begin
    	if k then a:=a-d else c:=c-b;
    	k:=k xor true;
    end;
    if k then writeln('Yes') else writeln('No');
end.

Measured memory_bytes: 1324
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int cnt[200010][26];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	string s; cin >> s;
	int n = s.size();
	rep(i, n){
		cnt[i + 1][s[i] - 'a']++;
		rep(j, 26) cnt[i + 1][j] += cnt[i][j];
	}
	ll ans = 1;
	rep(i, n){
		rep(j, 26) if(s[i] != 'a' + j) ans += cnt[n][j] - cnt[i][j];
	}
	cout << ans << endl;
	return 0;
}

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

int num[10000001] = {} ;

void f(){
	num[0] = num[1] = 1 ;
	for( int i=2 ; i<10000001 ; i++ ){
		if( !num[i] ){
			for( int j=2 ; i*j<10000001 ; j++ ) num[i*j] = 1 ;
		}
	}
}

main(){
	
	f() ;
	int n ;
	while( cin >> n , n ){
		while( !( !num[n] && !num[n-2] && !num[n-6] && !num[n-8] ) ) n-- ;
		cout << n << endl ;
	}
	
}

Measured memory_bytes: 40220
N,M=map(int,input().split())
l=list(map(int,input().split()))
mem=[0]*N
def f(n):
   return n*(n-1)//2
s=0
for i in range(N):
   s+=l[i]
   mem[i]=s
mem=[i%M for i in mem]
from collections import Counter
mem=Counter(mem)
ans=mem[0]
mem=list(mem.values())
for i in mem:
   ans+=f(i)
print(ans)

Measured memory_bytes: 23592
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+4;
int n,m;
int a[N],b[N];
int cnt[N];
ll sum;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int main() {
//	freopen("in.txt","r",stdin);
	n=read();
	for (register int i=1;i<=n;++i) {
		a[i]=read();
		++cnt[a[i]];
		sum+=a[i];
	}
	m=read();
	for (register int i=0;i<m;++i) {
		int x=read(),y=read();
		sum+=1ll*cnt[x]*(y-x);
		cnt[y]+=cnt[x];
		cnt[x]=0;
		printf("%lld\n",sum);
	}
	return 0;
}

Measured memory_bytes: 4460
S = input()
T = input()

max_equal = 0

for i in range(len(S)-len(T)+1):
    tmp = 0
    for j in range(len(T)):
        tmp += (S[i:len(T)+i][j] == T[j])
    max_equal = max(max_equal, tmp)
    
print(len(T) - max_equal)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  vl a(n);
  bool b=false;
  rep(i,n){
    cin >> a[i];
    if(a[i]==1){
      b=true;
    }
  }
  if(!b){
    cout << -1 << endl;
  }
  else{
    ll ans=0;
    ll k=1;
    rep(i,n){
      if(a[i]==k){
        k++;
      }
      else{
        ans++;
      }
    }
    cout << ans << endl;
  }
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

struct S {
    long long zero, one, ans;
};

S op(S l, S r) {
    return {l.zero + r.zero, l.one + r.one, l.ans + r.ans + l.one * r.zero};
}

S e() {
    return {0, 0, 0};
}

using F = bool;

S mapping(F f, S x) {
    if (f) return {x.one, x.zero, x.zero * x.one - x.ans};
    return x;
}

F composition(F f, F g) {
    return f ^ g;
}

F id() {
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, q;
    cin >> n >> q;
    vector<S> a(n);
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        if (x) a[i].one = 1;
        else a[i].zero = 1;
    }

    lazy_segtree<S, op, e, F, mapping, composition, id> st(a);
    for (int i=0; i<q; i++) {
        int t, l, r;
        cin >> t >> l >> r;
        l--;
        if (t == 1)
            st.apply(l, r, true);
        else
            cout << st.prod(l, r).ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 20340
#include <bits/stdc++.h>  // ver1.9.1
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(15);
  int n,h,w;
  cin >> n >> h >> w;
  int ans =0;
  int qw,er;
  
  rep(i,0,n){
    cin >> qw >> er;
    if(qw>=h && er>=w) ans++;
  }
  
  cout << ans << 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 all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)


int main(){
  int x,y,z,k;
  cin >> x >> y >> z >> k;
  vector<ll> a(1010),b(1010),c(1010);
  rep(i,x){
    cin >> a[i];
  }
  rep(i,y){
    cin >> b[i];
  }
  rep(i,z){
    cin >> c[i];
  }

  vector<ll> ab;
  rep(i,x){
    rep(j,y){
      ab.push_back(a[i]+b[j]);
    }
  }
  sort(all(ab));
  reverse(all(ab));

  vector<ll> ans;
  rep(i,min(k,x*y)){
    rep(j,z){
      ans.push_back(ab[i]+c[j]);
    }
  }
  sort(all(ans));
  reverse(all(ans));
  rep(i,k){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 43228
import sys

suits = ["S", "H", "C", "D"]
check = [[False]*14 for _ in range(4)]

def get_row(arg_ch):
    for i in range(len(suits)):
        if arg_ch == suits[i]:
            return i

N = int(input())

for _ in range(N):
    tmp = input().split()
    check[get_row(tmp[0])][int(tmp[1])] = True


for row in range(4):
    for col in range(1,14):
        if check[row][col] == False:
            print("%s %d"%(suits[row],col))


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int H, W, a, b, dp[105][105];
char chars[105][105];
int main()
{
  cin >> H >> W;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> chars[i][j];
    }
  }
  if (chars[0][0] == '#')
  {
    dp[0][0] = 1;
  }
  for (int i = 1; i < H; i++)
  {
    if (chars[i][0] == '#')
    {
      if (chars[i - 1][0] == '#')
      {
        dp[i][0] = dp[i - 1][0];
      }
      else
      {
        dp[i][0] = dp[i - 1][0] + 1;
      }
    }
    else
    {
      dp[i][0] = dp[i - 1][0];
    }
  }
  for (int j = 0; j < W; j++)
  {
    int i = 0;
    if (chars[0][j] == '#')
    {
      if (chars[0][j - 1] == '#')
      {
        dp[0][j] = dp[0][j - 1];
      }
      else
      {
        dp[0][j] = dp[0][j - 1] + 1;
      }
    }
    else
    {
      dp[i][j] = dp[0][j - 1];
    }
  }
  for (int i = 1; i < H; i++)
  {
    for (int j = 1; j < W; j++)
    {
      if (chars[i][j] == '#')
      {
        if (chars[i - 1][j] == '#')
        {
          a = dp[i - 1][j];
        }
        else
        {
          a = dp[i - 1][j] + 1;
        }
        if (chars[i][j - 1] == '#')
        {
          b = dp[i][j - 1];
        }
        else
        {
          b = dp[i][j - 1] + 1;
        }
        dp[i][j] = min(a, b);
      }
      else
      {
        dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  cout << dp[H - 1][W - 1] << endl;
  return 0;
}

Measured memory_bytes: 256