akhauriyash/Code-Regression huggingface dataset:
/*

                                  In the name of Allah, Most Gracious, Most Merciful


*/
#include<bits/stdc++.h>
#include<numeric>
using namespace std;

//*** constant value ***
const long double PI = 3.141592653589793238;
const double EPS = 1e-6 ;
//*** constant value ***

//****** define ********
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define dd double
#define vll vector<ll>
#define vs vector<string>
#define fn(i,n) for(ll i = 0; i<n; i++)
#define f(i,a,b) for(i=a;i<b;i++)
#define f1(i,a,b) for(i=b-1;i>=a;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define vpl vector<pll>
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define tt cout<<"Came here"<<endl;
//****** define ********
void solve()
{
   ll n,k;
   cin>>n>>k;
   vll v(n);
   fn(i,n)
   cin>>v[i];
   sort(v.begin(),v.end());
   ll sum = 0;
   fn(i,k)
   sum += v[i];

   cout<<sum<<endl;

}

int main()
{
    IOS;
    ll tc = 1;
    while(tc--)
    {
        solve();
    }


return 0;
}



Measured memory_bytes: 3620
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion

#pragma region MODint
// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp
{
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v % MOD)
	{
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept
	{
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept
	{
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept
	{
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept
	{
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept
	{
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b)
		{
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept
	{
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept
	{
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept
	{
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
	{
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

// 愚直計算による二項係数計算
mint com(long long n, long long r)
{
	mint res = 1;
	for (long long i = 0; i < r; ++i)
	{
		res *= (n - i);
		res /= (i + 1);
	}
	return res;
}
#pragma endregion

int main()
{
	ll n, a, b; cin >> n >> a >> b;
	mint res = modpow(mint(2), n) - 1;
	res -= com(n, a) + com(n, b);
	cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int sum;
	int num = 1;

	scanf("%c", &num);
	while (num != '0')
	{
		sum = 0;
		while (num != '\n')
		{
			num -= 48;
			sum += num;
			scanf("%c", &num);
		}
		printf("%d\n", sum);
		scanf("%c", &num);
	}
	return 0;
}


Measured memory_bytes: 2032
N,X = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
count = 0
for i in A:
    if X >= i:
        X = X - i
        count += 1
    else:
        break
if X > 0 and count == N:
    count -= 1
print(max(count,0))

Measured memory_bytes: 38256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
int ans[11];
int main()
{
//	setfile();
	R int n = F() - 3, k = F();
	R int now = 4;
	for (R int i = 0; i < 11; ++i, now = (now + 8) % 11)
		for (R int j = 1, tmp = now; j <= 5; ++j, tmp = (tmp + 9) % 11)
			if (tmp == k) ++ans[i];
	for (R int i = 1; i < 11; ++i) ans[i] += ans[i - 1];
	printf("%d\n", ans[10] * (n / 11) + ans[n % 11]);
	return 0;
}

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

namespace ConsoleApp15
{
    class MainClass
    {
        static void Main()
        {
            var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int x = xy[0];
            int y = xy[1];
            if (y % 2 == 0)
            {
                if (x * 2 <= y && y <= x * 4)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 28144
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		BTree t=new BTree();
		boolean ct=false;

		for(int i=0;i<n;i++) {
			String odr=in.next();

			if(odr.equals("insert")) {
				int key=Integer.parseInt(in.next());
				t.insert(key);
			}
			else if(odr.equals("print")) {
				PrintWriter out=new PrintWriter(System.out);
				//out.println(t.size);
				Queue<Integer> Q=new ArrayDeque<>(t.walk('I'));
				while(!Q.isEmpty())out.print(" "+Q.remove());
				out.println();
				Q=new ArrayDeque<>(t.walk('P'));
				while(!Q.isEmpty())out.print(" "+Q.remove());
				out.println();
				out.flush();
			}
		}
	}

}

class BTreeNode{
	int key=-2000000001;

	BTreeNode Parent,Left,Right;

	BTreeNode(int k){
		key=k;
	}

	void setParent(BTreeNode P) {
		this.Parent=P;
	}

	void setLeft(BTreeNode L) {
		this.Left=L;
	}

	void setRight(BTreeNode R) {
		this.Right=R;
	}
}

class BTree{
	int size=0;
	int NIL=-2000000001;
	Queue<Integer> Q;

	BTreeNode dummy;
	BTreeNode r;
	BTree(){
		dummy=new BTreeNode(NIL);
		r=new BTreeNode(NIL);
		r.setParent(dummy);
		r.setLeft(dummy);
		r.setRight(dummy);
	}

	void insert(int k) {

		if(size==0) {
			r.key=k;
			size++;
			return;
		}

		BTreeNode n=new BTreeNode(k);
		n.setLeft(dummy);
		n.setRight(dummy);

		BTreeNode s=r;
		BTreeNode p=r;
		while(s.key!=NIL) {
			p=s;
			if(k<s.key)s=s.Left;
			else s=s.Right;
		}

		n.setParent(p);
		size++;

		if(k<p.key) p.setLeft(n);
		else p.setRight(n);
	}

	Queue<Integer> walk(char odr){
		Q=new ArrayDeque<>();
		if(odr=='I')inoderWalk(r);
		if(odr=='P')preoderWalk(r);
		return Q;
	}

	void preoderWalk(BTreeNode n) {
		Q.add(n.key);
		if(n.Left.key!=NIL)preoderWalk(n.Left);
		if(n.Right.key!=NIL)preoderWalk(n.Right);
	}
	
	void inoderWalk(BTreeNode n) {
		if(n.Left!=dummy)inoderWalk(n.Left);
		Q.add(n.key);
		if(n.Right!=dummy)inoderWalk(n.Right);
	}
}


Measured memory_bytes: 216788
//                               //
    // author : samars_diary //
    // 18-09-2020 │ 19:55:52 //
//                               //

#include <iostream>
using namespace std;

void solve(){
    long long int a,b;
    cin>>a>>b;
    cout<<a*b;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    //#endif

    int t = 1;
    while(t--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
#define INDEX 10
void sort(int array[],int n){
int i,j;
for(i=0;i<n-1;i++){
for(j=n-1;j>i;j--){
if(array[j-1]>array[j]){
int t=array[j-1];
array[j-1]=array[j];
array[j]=t;
}
}
}
}
int main(){
int height[10];
int i;
for(i=0;i<INDEX;i++){
scanf("%d",&height[i]);
}
sort(height,INDEX);
for(i=0;i<3;i++){
printf("%d\n",height[INDEX-i-1]);
}
return 0;
}

Measured memory_bytes: 600
function AA(){
   for(var i=1;i<arr.length-1;i++){
      if(arr[i]==0){arr[i]="A";return;}
   }
}
function BB(){
   for(var i=arr.length-2;i>=1;i--){
      if(arr[i-1]!="A" && arr[i]==0 && arr[i+1]!="A"){arr[i]="B";return;}
   }
   for(var i=1;i<arr.length-1;i++){
      if(arr[i]==0){arr[i]="B";return;}
   }
}
function CC(){
   for(var i=1;i<arr.length-1;i++){
      if(arr[i]!=0 && arr[i+1]==0){arr[i+1]="C";return;}
      if(arr[i]!=0 && arr[i-1]==0){arr[i-1]="C";return;}
   }
   if(n%2==1)arr[(n-1)/2+1]="C";
   if(n%2!=1)arr[n/2+1]="C";
}
function DD(){
   var max=[0,0];
   for(var i=1;i<arr.length-1;i++){
      if(arr[i]!=0)continue;
      var jA=i;
      var jB=i;
      var cnt=0;
      while(true){
               if(arr[jA]!="X")jA--;
               if(arr[jB]!="X")jB++;
               if(arr[jA]=="X" && arr[jB]=="X")break;
               if(arr[jA]!="X" && arr[jA]!=0)break;
               if(arr[jB]!="X" && arr[jB]!=0)break;
               cnt++;
               if(max[1]<cnt)max=[i,cnt];
      }
   }
   if(max[0]!=0 && max[1]!=0){arr[max[0]]="D";return}
   for(var i=1;i<arr.length-1;i++){
      if(arr[i]==0){arr[i]="D";return;}
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.trim().split("\n");
while(true){
   var nm=Arr.shift().split(" ").map(Number);
   var n=nm[0];
   var m=nm[1];
   if(n==0 && m==0)break;
   var arr=[];
   for(var i=0;i<n;i++)arr.push(0);
   arr.unshift("X");
   arr.push("X");
   for(var i=0;i<m;i++){
      var v=Arr.shift();
      if(v=="A")AA();
      if(v=="B")BB();
      if(v=="C")CC();
      if(v=="D")DD();
   }
   arr.shift();
   arr.pop();
   console.log(arr.join("").replace(/0/g,"#"));
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n) {
        ans++;
        while (i+1<n && a[i] == a[i+1]) ++i;
        if (i == n-1) break;
        if (a[i] < a[i+1]) {
            while (i+1<n&&a[i]<=a[i+1]) ++i;
        }
        else {
            while (i+1<n&&a[i]>=a[i+1]) ++i;
        }
    }
    cout << ans << endl;
    return 0;
}


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




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

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

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

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<ll,ll>;

/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}



const int INF = 1001001001;



int main() {
	int d, n;
	cin >> d >> n;
	ll ans = 0;
	if (n == 100) {
		ans = pow(100, d) * 101;
			cout << ans;
	}
	else cout << pow(100, d) * n;
	return 0;
}













Measured memory_bytes: 3924
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	char buf[101];
	int i,j,mae,a,wa;

	while(scanf("%s",buf)!=EOF){
		i=0;
		j=0;
		mae=0;
		wa=0;
		while(buf[i]!='\0'){
			if(buf[i]=='I')
				a=1;
			else if(buf[i]=='V')
				a=5;
			else if(buf[i]=='X')
				a=10;
			else if(buf[i]=='L')
				a=50;
			else if(buf[i]=='C')
				a=100;
			else if(buf[i]=='D')
				a=500;
			else if(buf[i]=='M')
				a=1000;
			if(mae>a)
				wa+=j*mae;
			else
				wa-=j*mae;
			mae=a;
			j=1;
			while(buf[i]==buf[i+1]){
				i++;
				j++;
			}
			i++;
		}
		wa+=j*mae;
		printf("%d\n",wa);
	}	
	return 0;
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, a = 0, num = 1;
    cin >> n;
    vector<vector<int>> c(10, vector<int>(10, 0));
    for(int i = 1; i <= n; i++){
        if(i % num == 0){
            a++;
            if(i % (num*10) == 0){
                a=1;
                num*=10;
            }
        }
        c[a][i%10]++;
    }
    ll ans = 0;
    REP(i, 9){
        REP(j, 9)ans += c[i][j]*c[j][i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int h,n;
    cin>>h>>n;
    int a[n];
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    int s=0;
    for(int i=0;i<n;++i)
    {
        s=s+a[i];
    }
    if(h<=s)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n == 1) System.out.println("Hello World");
		else {
			System.out.println(sc.nextInt()+sc.nextInt());
		}
	}
}

Measured memory_bytes: 21332
fun main(args: Array<String>) {
  val sc = java.util.Scanner(System.`in`)
  val A = sc.nextInt()
  val B = sc.nextInt()
  val K = sc.nextInt()
  var aa = A + K - 1
  if (aa > B) {
    aa = B
  }
  var bb = B - K + 1
  if (bb <= aa) {
    bb = aa + 1
  }
  ((A..aa) + (bb..B)).forEach(::println)
}


Measured memory_bytes: 31648
class BinaryIndexTree:  # 1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def Alp(s):
    return ord(s)-ord("a")


if __name__ == "__main__":
    N = int(input())
    S = list(input())
    Q = int(input())

    bit = [BinaryIndexTree(N) for _ in range(26)]
    for i, s in enumerate(S, start=1):
        bit[Alp(s)].add(i, 1)

    ans = []
    for _ in range(Q):
        q = input().split()
        if q[0] == "1":
            i = int(q[1]) - 1
            c = q[2]

            bit[Alp(c)].add(i+1, 1)
            bit[Alp(S[i])].add(i+1, -1)
            S[i] = c
        else:
            l = int(q[1])
            r = int(q[2])
            tmp = 0
            for i in range(26):
                b = bit[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    tmp += 1
            ans.append(tmp)

    print(*ans, sep="\n")


Measured memory_bytes: 168348
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int mod = 998244353, maxn = 1e5+10;
int N, M, K;
int a[maxn], b[maxn], c[maxn], dp[maxn][3];

int main()
{
    memset(dp, 0x3f,sizeof(dp));
    scanf("%d", &N);
    for(int i = 1; i <= N; i++)
        scanf("%d %d %d", &a[i], &b[i], &c[i]);
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for(int i = 1; i <= N; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c[i];
    }
    printf("%d\n", max(dp[N][0], max(dp[N][1], dp[N][2])));
    return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

ll a[5005];
ll p[5005];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i=0 ; i<n ; i++) {
		scanf("%lld", p+i);
		p[i]--;
	}
	ll sol = -INF;
	for (int i=0 ; i<n ; i++) {
		scanf("%lld", a+i);
		sol = max(sol, a[i]);
	}
	for (int i=0 ; i<n ; i++) {
		int pos = i;
		vector <ll> pref;
		ll cnt = 0;
		int m = 0;
		do {
			m++;
			cnt += a[pos];
			pref.pb(cnt);
			pos = p[pos];
		} while (pos != i);
	//	cout <<"cnt = "<<cnt<<endl;
		if (cnt > 0) {
			ll rez = cnt*(k/m-1);
			ll maxx = 0;
			for (int j=0 ; j<m ; j++) {
				maxx = max(maxx, pref[j]);
			}
			sol = max(sol, rez+maxx);
			rez = cnt*(k/m);
			maxx = 0;
			for (int j=0 ; j<k%m ; j++) {
				maxx = max(maxx, pref[j]);
			}
			sol = max(sol, rez+maxx);
		}
		for (int j=0 ; j<min(k, m) ; j++) {
			sol = max(sol, pref[j]);
		}
	//	cout <<"sol = "<<sol<<endl;
	}
	cout <<sol<<endl;
	return 0;
}

Measured memory_bytes: 3868
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

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

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n,m;
char s[5005];


template<lint mod>
struct Int_{
  unsigned x;
  unsigned mpow(Int_ a,unsigned k){
    Int_ res=1;
    while(k){
      if(k&1) res=res*a;
      a=a*a;
      k>>=1;
    }
    return res.x;
  }
  unsigned inverse(Int_ a){
    return mpow(a,mod-2);
  }
  Int_(): x(0) { }
  Int_(long long sig) {
    int sigt=sig%mod;
    if(sigt<0) sigt+=mod;
    x=sigt;
  }
  unsigned get() const { return (unsigned)x; }
  
  Int_ &operator+=(Int_ that) { if((x += that.x) >= mod) x -= mod; return *this; }
  Int_ &operator-=(Int_ that) { if((x += mod - that.x) >= mod) x -= mod; return *this; }
  Int_ &operator*=(Int_ that) { x = (unsigned long long)x * that.x % mod; return *this; }
  Int_ &operator=(Int_ that) { x=that.x; return *this;}
  Int_ &operator/=(Int_ that) { x=(unsigned long long) x * inverse(that.x)%mod; return *this;}
  bool operator==(Int_ that) const { return x==that.x; }
  bool operator!=(Int_ that) const { return x!=that.x; }

  Int_ operator-() const { return Int_(0)-Int_(*this);}
  Int_ operator+(Int_ that) const { return Int_(*this) += that; }
  Int_ operator-(Int_ that) const { return Int_(*this) -= that; }
  Int_ operator*(Int_ that) const { return Int_(*this) *= that; }
  Int_ operator/(Int_ that) const { return Int_(*this) /= that; }

};

namespace std{
  template<lint mod>
  ostream &operator <<(ostream& out,const Int_<mod>& a){
    out<<a.get();
    return out;
  }
  template<lint mod>
  istream &operator >>(istream& in,Int_<mod>& a){
    in>>a.x;
    return in;
  }
};

typedef Int_<1000000007> Int;

Int dp[5005][5005];
int main(){
  cin>>n;
  scanf("%s",s);
  m=strlen(s);

  dp[0][0]=1;
  REP(i,n) REP(j,n+1) if(dp[i][j].x){
    dp[i+1][max(0,j-1)]+=dp[i][j];
    dp[i+1][j+1]+=dp[i][j]*2;
  }
  Int res=dp[n][m];
  REP(j,m) res/=2;
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 98176
#include<bits/stdc++.h>
using namespace std;
const long long int d=1000000007;
long long int mod(long long int x)
{
    return (x%d+d)%d;
}
int main()
{
    int h,w;
    cin>>h>>w;
    char grid[h+1][w+1];
    long long int dp[h+1][w+1];

    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>grid[i+1][j+1];
        }
    }

    bool flag=false;
    for(int i=1;i<=w;i++)
    {
        if(grid[1][i]=='#')
            flag=true;
        if(flag)
        {
            dp[1][i]=0;
        }
        else
        {
            dp[1][i]=1;
        }
    }

    flag=false;
    for(int i=1;i<=h;i++)
    {
        if(grid[i][1]=='#')
            flag=true;
        if(flag)
        {
            dp[i][1]=0;
        }
        else
        {
            dp[i][1]=1;
        }
    }

    for(int i=2;i<=h;i++)
    {
        for(int j=2;j<=w;j++)
        {
            if(grid[i][j]=='#')
                dp[i][j]=0;
            else
            {
                dp[i][j]=mod(dp[i-1][j]+dp[i][j-1]);
            }
            
        }
    }

    cout<<dp[h][w]<<endl;
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

int main(){
    ll n,m;
    cin >>n>>m;
    cout << n*(n-1)/2+m*(m-1)/2;
}

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, k;
    cin >> n >> k;

    ll tmp = n / k;

    ll ans = min(n - k * tmp, abs(n - k*(tmp+1)));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n: u32 = read();
    let a: u32 = read();
    println!("{}", n * n - a);
}

Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int m,int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(m,n / 2);
	x *= x;
	if (n % 2 == 1)x *= m;
	return x;
}
ll max(ll a, ll b) {
	if (a < b)return b;
	else return a;
}

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = d - b;
	int y = c - a;
	rep(i, 0, x)cout << "U";
	rep(i, 0, y)cout << "R";
	rep(i, 0, x)cout << "D";
	rep(i, 0, y+1)cout << "L";
	rep(i, 0, x + 1)cout << "U";
	rep(i, 0, y + 1)cout << "R";
	cout << "DR";
	rep(i, 0, x + 1)cout << "D";
	rep(i, 0, y + 1)cout << "L";
	cout << "U" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int g[100000];
int bfs[100000];
int v[100000];
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",g+i);
	deque<int>Q;
	for(int i=0;i<a;i++)bfs[i]=99999999;
	Q.push_back(0);
	bfs[0]=0;
	while(Q.size()){
		int at=Q.front();
		Q.pop_front();
		if(v[at])continue;
		v[at]=1;
		if(g[at]){
			if(bfs[at+g[at]]>bfs[at]){
				bfs[at+g[at]]=bfs[at];
				Q.push_front(at+g[at]);
			}
		}else{
			for(int i=1;i<7;i++){
				if(at+i<a){
					if(bfs[at+i]>bfs[at]+1){
						bfs[at+i]=bfs[at]+1;
						Q.push_back(at+i);
					}
				}
			}
		}
	}
	printf("%d\n",bfs[a-1]);
}

Measured memory_bytes: 2228
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

const ll mod = 1e9 + 7;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
   // cin >> T;
    T = 1;
    for(int cs = 1; cs <= T; cs++)
    {
        int n,m,c;
        cin >> n >> m >> c;
        int cnt = 0;
        int b[m+2];
        for(int i = 0; i < m; i++){
             cin >> b[i];   
            }
        while(n--){
            int sum = 0;
            for(int i = 0; i < m; i++){
               int x;
               cin >> x;
               sum += x * b[i]; 
            }
            if(sum+c > 0) cnt++;
        }
        cout << cnt << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz 10010
#define MOD 1000000007
#define ll long long

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


	ll a, b; cin >> a >> b;
	cout << (a * b);


	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
 
int main(void)
{
    long a, b;
    long d, r;
    double f;
 
    scanf("%ld %ld", &a, &b);
    d = a / b;
    r = a % b;
    f = (double)a / b;
    printf("%ld %ld %.5lf\n", d, r, f);
 
    return 0;
}

Measured memory_bytes: 640
N ,K = map(int, input().split())
a = [int(input()) for i in range(N)]
a = sorted(a)
res = float('inf')

for i in range(N - K + 1):
  if res > a[i+K-1] - a[i]:
    res = a[i+K-1] - a[i]

print(res)


Measured memory_bytes: 8280
#include <iostream>
using namespace std;
int main () {
	int n, w;
	cin >> n >> w;
	pair<int, int> items[n+1];
	for (int i=1; i<=n; i++) {
		cin >> items[i].first >> items[i].second;
	}
	long long dp[n+1][110000];
	dp[0][0] = 0;
	for (int i=1; i<110000; i++) {
		dp[0][i] = 1e13;
	}
	int best = 0;
	for (int i=1; i<=n; i++) {
		for (int j=0; j<items[i].second; j++) {
			dp[i][j] = dp[i-1][j];
		}
		for (int j=items[i].second; j<110000; j++) {
			dp[i][j] = min(dp[i-1][j], dp[i-1][j-items[i].second]+items[i].first);
			if (dp[i][j] <= w) {
				best = max(best, j);
			}
		}
	}
	cout << best << endl;
}

Measured memory_bytes: 87040
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<ll>>;

int bounce[100000] = {};
int n;
vector<int> l;
int x;

int main(){
  cin >> n >> x;
  l.resize(n);
  for (auto &&i : l)
  {
    cin >> i;
  }
  long long sum = 0;
  for (auto &&i : l)
  {
    bounce[sum + i]++;
    sum += i;
  }
  int ans = 0;
  for (size_t i = 0; i <= x; i++)
  {
    if (bounce[i] == 1)
    {
      ans++;
    }
    
  }
  
  
  cout << ++ans << endl;

}

Measured memory_bytes: 3596
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n,m,ans;
int main() {
	scanf("%lld %lld",&n,&m);
	if (m/2>=n)
		ans=n+(m-n*2)/4;
	else ans=m/2;
	printf("%lld\n",ans);
	return 0;
}

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

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

  if (S == "Sunny") cout << "Cloudy" << endl;
  if (S == "Cloudy") cout << "Rainy" << endl;
  if (S == "Rainy") cout << "Sunny" << endl;
  return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

int inf = 100000001;
int A[1001];
int B[1001];
int C[1001][13];
int J[1001];
int DP[1001][4096];

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

    fill(J, J + 1001, 0);

    for (int i = 1; i <= M; ++i) {
        cin >> A[i] >> B[i];

        for (int j = 1; j <= B[i]; ++j) {
            cin >> C[i][j];
            J[i] |= 1 << (C[i][j] - 1);
        }
    }

    int NJ = (1 << N) - 1;
    DP[0][0] = 0;

    for (int i = 1; i <= M; ++i) {
        DP[i][0] = 0;
    }

    for (int j = 1; j <= NJ; ++j) {
        DP[0][j] = inf;
    }

    for (int i = 1; i <= M; ++i) {
        for (int j = 1; j <= NJ; ++j) {
            if (j & J[i]) {
                int prev = DP[i - 1][j & ~J[i]];
                DP[i][j] = prev == inf ? inf : min(DP[i - 1][j], prev + A[i]);
            }
            else {
                DP[i][j] = DP[i - 1][j];
            }
        }
    }

    cout << (DP[M][NJ] == inf ? -1 : DP[M][NJ]) << endl;

    return 0;
}


Measured memory_bytes: 16384
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#include <time.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;

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

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    int i;
    vector<int> a(n);
    ll sum=0;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        sum+=(a[i]+1)%2;
    }
    int flag=0;
    while(sum==n-1 && n%2) {
        int tmp=0;
        for(i=0; i<n; i++) {
            if(a[i]%2) {
                if(a[i]==1) break;
                a[i]--;
            }
            if(i==0) tmp=a[i];
            else tmp=gcd(tmp,a[i]);
        }
        if(i==n) {
            sum=0;
            for(i=0; i<n; i++) {
                a[i]/=tmp;
                if(a[i]%2==0) sum++;
            }
            flag=1-flag;
            continue;
        }
        break;
    }

    if((sum+flag)%2) {
        printf("First\n");
    }
    else {
        printf("Second\n");
    }

    return 0;
}


Measured memory_bytes: 640
total, num, cnt = 0, 0, 0
try:
    while True:
        n, m = map(int, input().split(","))
        total += n*m
        num += m
        cnt += 1
except EOFError:
    print(total)
    n = num/cnt
    n = int(n) if n%1 < 0.5 else int(n)+1
    print(n)


Measured memory_bytes: 5612
n,k=map(int,input().split())
a=list(map(int,input().split()))
visited=set()
new=0
c=0
while not new in visited and c<k:
  visited.add(new)
  new=a[new]-1
  c+=1
if c==k:
  print(new+1)
else:
  start=new
  d=0
  visited=set()
  while not new in visited and d<k-c:
    visited.add(new)
    new=a[new]-1
    d+=1
  if k-c==d:
    print(new+1)
  else:
    new=start
    for i in range((k-c)%d):
      new=a[new]-1
    print(new+1)

Measured memory_bytes: 35580
import java.util.*;

public class Main {

    public static String isGood(int A, int B, String S) {
        if (S.length() != A + B + 1) {
            return "No";
        } else {
            for (int i = 0; i < A + B + 1; i++) {
                if (i == A) {
                    if (S.charAt(i) != '-') {
                        return "No";
                    }
                } else {
                    if (!('0' <= S.charAt(i) && S.charAt(i) <= '9')) {
                        return "No";
                    }
                }
            }
            return "Yes";
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        String S = sc.next();
        System.out.println(isGood(A, B, S));
    }

}


Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int n = Integer.valueOf(sc.next());
        final int a = Integer.valueOf(sc.next());
        final int b = Integer.valueOf(sc.next());
        int count=0;
        int allDigits=0;
        for(int i=1; i<=n; i++){
            allDigits = sumAllDigits(i);
            count += (b >= allDigits && allDigits >= a)? i:0;
        }
        System.out.println(count);
        sc.close();
    }       

    public static int sumAllDigits(int num) {
        int result = 0;
        while(num >= 10) {
            result += num % 10;
            num = num/10;
        }
        return result + num;
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;
    cin>>n>>s;
    ll ans=0;
    for(int i=0; i<n-2; i++) {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            ans++;
        }
    }
    cout<<ans<<endl;
    return  0;
}


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

const int maxn = 2 * 100000 + 5;

int rail_par[maxn];
int par[maxn];

void init(int *p){//初期化
    for(int i=0;i<maxn;i++){
        p[i] = -1;
    }
}

int find(int *p,int x){//探索
    if(p[x] < 0){
        return x;
    }
    return p[x] = find(p,p[x]);
}

void unite(int *p,int x,int y){//連結

    x = find(p,x);
    y = find(p,y);
    if(x == y ) return;

    if (p[x] > p[y]) swap(x, y);

    //大体p[x]は負の値になり親となる。 負の値を足している。
    p[x] += p[y];

    //yが子になり、xが親になる。
    p[y] = x;

}

int main() {

    int n,k,l;

    cin >> n >> k >> l;

    init(par);
    init(rail_par);

    for(int i=0; i<k; i++){
        int p,q;
        cin >> p >> q;
        unite(par,p,q);
    }

    for(int i=0; i<l; i++){
        int r,s;
        cin >> r >> s;
        unite(rail_par,r,s);
    }

    map<pair<int,int>,int> m;

    for(int i=1; i<=n; i++){
        m[make_pair(find(par,i),find(rail_par,i))]++;
    }

    for(int i=1; i<=n; i++){
        cout << m[make_pair(find(par,i),find(rail_par,i))];
        if(i!=n){
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 13696
from itertools import permutations as per
h,w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
ans = 0
mc = [0]*10
for i in range(10):
  mc[i] = c[i][1]
for i in range(1,10):
  for j in per([0,2,3,4,5,6,7,8,9],i):
    cur = 0
    for k in range(1,i):
      cur += c[j[k-1]][j[k]]
    cur += c[j[i-1]][1]
    mc[j[0]] = min(mc[j[0]],cur)
for i in range(h):
  a = list(map(int,input().split()))
  for j in a:
    if j != -1:
      ans += mc[j]
print(ans)

Measured memory_bytes: 42524
#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define th(n) cout<<n<<endl
#define gc getchar_unlocked
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
#define upper(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define lower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define print(arr) for(auto el: arr) cout<<el<<" ";cout<<endl
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
#define formatrix(i,n) for(ll i=0;i<n;i++, cout<<"\n")
#define eof (scanf("%d" ,&n))!=EOF
// declaration shortcuts
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>> 
#define pll pair<ll,ll>
#define ppl pair<ll,pp>
#define ull unsigned long long
#define ll long long
#define mll map< ll, ll > 
#define sll set< ll > 
#define uni(v) 	v.erase(unique(v.begin(),v.end()),v.end());
#define ini(a, v)       memset(a, v, sizeof(a))
using namespace std;
int main(){
    
    ll n,m,ma=1e18;
    cin>>n>>m;
    if((n/2019)!=(m/2019))
     cout<<0;
     else{
         
         for(int i=n;i<m;i++)
         {
             for(int j=i+1;j<=m;j++)
             {
                 ma=min(ma,(ll)((i%2019)*(j%2019))%2019);
             }
             
         }
         cout<<ma;
     }
    return 0;
}

Measured memory_bytes: 256
k = gets.split[1].to_i
as_orig = as = gets.split.map(&:to_i)

max_bit = k.to_s(2).length
max_k = (0..max_bit).reverse_each.inject(0) do |res, i|
  sq = 2**i
  calculated = as.map do |a|
    [a % sq, a / sq]
  end

  as, counts = calculated.transpose
  cond = counts.count(0) >= counts.count(1) && res + sq <= k
  cond ? res + sq : res
end
puts as_orig.map { |a| a ^ max_k }.inject(&:+)


Measured memory_bytes: 24332
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, m;
	while (cin >> n >> m){
		if (n == 0 && m == 0)return 0;
		pair<int, int>l[1000];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int a; cin >> a;
				if (i == 0) {
					l[j].first = j + 1;
					l[j].second = 0;
				}
				if (a == 1) {
					l[j].second++;
				}
			}
		}
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < m - i - 1; j++) {
				if (l[j].second < l[j + 1].second) {
					swap(l[j], l[j + 1]);
				}
				else if (l[j].second == l[j + 1].second&&l[j].first>l[j + 1].first) {
					swap(l[j], l[j + 1]);
				}
			}
		}
		for (int i = 0; i < m; i++) {
			cout << l[i].first;
			if (i != m - 1)cout << ' ';
			else cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3096
# -*- coding: utf-8 -*-

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    from collections import Counter

    n = int(input())
    a = [0] + list(map(int, input().split()))
    s = [0] * len(a)

    for i in range(1, n + 1):
        s[i] += s[i - 1] + a[i]

    print(sum([si * (si - 1) // 2 for si in Counter(s).values()]))


Measured memory_bytes: 40824
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main()
{
    ll N;
    cin >> N;
    string S;
    cin >> S;

    ll num = 1;

    char ch = S[0];
    for(ll i = 1;i<S.length();i++)
    {
        char temp = S[i];
        if(ch == temp)
        {
            continue;
        }
        else
        {
            ch = temp;
            num++;
        }
        
    }
    
    cout << num << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll mul(ll a,ll b,ll mod) {
    ll d=((long double)a*b+0.5)/mod,ret=a*b-d*mod;
    return (ret%mod+mod)%mod;
}
vector<ll> fac;
ll qpow(ll a,ll b,ll mod) {
    ll ret=1;
    while(b) {
        if(b&1) ret=mul(ret,a,mod);
        a=mul(a,a,mod); b>>=1;
    }
    return ret;
}
bool pri(ll n) {
    if(n==2) return 1;
    for(int T=1;T<=10;T++) {
        ll a=rand()%(n-2)+2;
        if(qpow(a,n-1,n)!=1) return 0;
        ll p=n-1;
        while(!(p&1)) {
            p>>=1;ll x=qpow(a,p,n);
            if(mul(x,x,n)==1&&x!=1&&x!=n-1) return 0;
        }
    }
    return 1;
}
ll rho(ll n,ll c) {
    ll i=0,k=2,x=rand()%(n-1)+1,y=x;
    while(1) {
        x=(mul(x,x,n)+c)%n;
        ll gg=__gcd((y-x+n)%n,n);
        if(gg!=1&&gg!=n) return gg;
        if(x==y) return n;
        ++i;if(i==k) y=x,k<<=1;
    }
}
void fact(ll n,ll c) {
    if(n==1) return;
    if(pri(n)) { fac.pb(n);return; }
    ll p=n;while(p==n) p=rho(n,c--);
    fact(p,c);fact(n/p,c);
}
ll n,k,mod,p[N],tot=0,ans=0,a[N];
ll g(ll n) { return qpow(k,(n+1)/2,mod); }
ll h(ll n) { return (n&1)?n%mod:(n/2)%mod; }
void dfs(int i,ll x,ll Mul) {
    if(i==tot+1) {
        if((n/x)%2==1&&x%2==0) return;
        ans=(ans+1ll*g(n/x)*h(n/x)%mod*Mul%mod)%mod;
        return;
    }
    dfs(i+1,x,Mul);
    Mul=1ll*Mul*(1-p[i]%mod+mod)%mod;x*=p[i];
    for(int j=1;j<=a[i];j++) dfs(i+1,x,Mul),x*=p[i];
}
void work() {
    tot=ans=0;cin>>n>>k;mod=1e9+7;k%=mod;
    fac.clear();fact(n,141905);
    sort(fac.begin(),fac.end());
    for(int i=0,siz=fac.size();i<siz;i++) {
        if(!i || fac[i]!=fac[i-1]) p[++tot]=fac[i],a[tot]=1;
        else a[tot]++;
    }
    dfs(1,1,1);printf("%lld\n",ans);
}
int main() {
	work();
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 2304
n = int(input())
A =list(map(int, input().split()))
d = {}
for i in range(n):
    if A[i] not in d:
        d[A[i]] = 1
    else:
        d[A[i]] += 1

s = []
t = []
for k, v in d.items():
    if v >= 4:
        s.append(k)
        t.append(k)
    elif v >= 2:
        t.append(k)

if len(s) == 0 and len(t) < 2:
    print(0)
else:
    if len(s) == 0:
        t.sort(reverse=True)
        print(t[0]*t[1])
    elif len(t) < 2:
        s.sort(reverse=True)
        print(s[0]**2)
    else:
        t.sort(reverse=True)
        s.sort(reverse=True)
        print(max(t[0]*t[1], s[0]**2))


Measured memory_bytes: 17936
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), s(n + 1);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) s[i + 1] = s[i] + a[i];

  ll ans = INFL;
  rep(i, 1, n) ans = min(ans, abs(s[i] - (s[n] - s[i])));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6416
#define M 100
char m[M][M],s[M][M][M],r[M],*z;
cmp(char *p,char *q){int r=0;
	for(;*p=='0';p++);for(;*q=='0';q++);
	return (r=strlen(p)-strlen(q))?r:strcmp(p,q);
}
main(w,h,i,j,k,l){
	for(;scanf("%d%d",&w,&h),w;puts(z)){
		for(memset(s,0,sizeof(s)),memset(r,0,sizeof(r)),j=1;j<=h;j++)scanf("%s",m[j]+1);
		for(i=1;i<=w;i++)for(j=1;j<=h;j++){
			if(!isdigit(m[j][i]))continue;
			if(cmp(s[j][i-1],s[j-1][i])>0)strcpy(s[j][i],s[j][i-1]),s[j][i][strlen(s[j][i])]=m[j][i];
			else strcpy(s[j][i],s[j-1][i]),s[j][i][strlen(s[j][i])]=m[j][i];
			if(cmp(s[j][i],r)>0)strcpy(r,s[j][i]);
		}
		for(z=r;*z=='0';z++);
	}
return 0;}

Measured memory_bytes: 0