akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    PrintWriter out = new PrintWriter(System.out);

    String s;
    String sl[];

    s = r.readLine();
    //sl = s.split(" ");

    int zeroes = 0;
    int ones = 0;
    int n = s.length();

    for(int i = 0; i < n; i++)
    {
      if(s.charAt(i) == '0')
      {
        zeroes++;
      }
      else
      {
        ones++;
      }
    }
    out.println(n - Math.abs(zeroes - ones));
    out.flush();
  }

}

Measured memory_bytes: 30432
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int a, b, v, w, t;
	cin >> a >> v >> b >> w >> t;
	if(v > w && abs(b - a) <= (v - w) * t) cout << "YES\n";
	else cout << "NO\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define YES { cout << "YES\n"; exit(0); }
#define NO { cout << "NO\n"; exit(0); }

using namespace std;

char a[15][15];
int n, m, i, j;
bool used[15], used2[15];
vector< pair<int,int> > p;

void solve()
{
    int i, j, k;
    memset(used2, 0, sizeof(used2));

    for(i=1; i<=m; ++i)
        if(!used2[i])
        {
            for(j=1; !used2[i] && j<=m; ++j)
                if(i != j && !used2[j])
                {
                    bool match = 1;
                    for(k=0; match && k<p.size(); ++k)
                        match &= (a[p[k].first][i] == a[p[k].second][j] && a[p[k].second][i] == a[p[k].first][j]);

                    if(match) used2[i] = used2[j] = 1;
                }
        }

    int id = 0;
    for(i=1; i<=m; ++i)
        if(!used2[i])
        {
            if(id) return;
            id = i;
        }

    if(!id) YES;

    bool match = 1;
    for(k=0; k<p.size(); ++k)
        match &= (a[p[k].first][id] == a[p[k].second][id]);

    if(match) YES;
}

void tracktor(int l)
{
    if(l == n+1)
    {
        solve();
        return;
    }

    if(!used[l])
    {
        int i;
        used[l] = 1;
        for(i=l+1; i<=n; ++i)
            if(!used[i])
            {
                used[i] = 1;
                p.push_back({l, i});
                tracktor(l+1);

                used[i] = 0;
                p.pop_back();
            }
        used[l] = 0;
    }
    else tracktor(l+1);
}

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

    cin >> n >> m;
    for(i=1; i<=n; ++i) cin >> (a[i]+1);

    if(n&1)
    {
        p.push_back({0,0});
        for(i=1; i<=n; ++i)
        {
            used[i] = 1;
            p[0] = {i, i};
            tracktor(1);
            used[i] = 0;
        }
    }
    else tracktor(1);

    NO;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 500000
int H;
void maxHeapify(int *,int);
void buildMaxHeap(int *);
int main(){
  int i;
  int Heap[MAX+1];
    scanf("%d",&H);
    for(i=1;i<=H;i++){
        scanf("%d",&Heap[i]);
    }

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

void maxHeapify(int *A,int i){
    int l,v,r,b;
    l=2*i;
    r=2*i+1;
    if(l<=H && A[l]>A[i]){
      b = l;
    }
    else b = i;
    if(r<=H && A[r]>A[b]){
    b = r;
  }
    if(b!=i){
        v=A[i];
        A[i]=A[b];
        A[b]=v;
        maxHeapify(A,b);
    }
}

void buildMaxHeap(int *A){
    int i;
    for(i=H/2;i>=1;i--){
        maxHeapify(A,i);
    }
}



Measured memory_bytes: 3676
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main(void) {

	int hantei[2] = { 0,0 };
	int hantei_num = 0;
	int swap = 0;
	int decision = 0;
	int N = 0;
	scanf("%d", &N);
	

	int* array = (int*)malloc(N * sizeof(int));
	for (int i = 0; i < N; i++) {
		scanf("%d", array + i);
	}
	
	for (int i = 0; i < N; i++) {
		if (hantei_num >= 2) { break; }
		if (*(array + i) != (i + 1)) {
			hantei[hantei_num] = i;
			hantei_num++;
			continue;
		}
	}

	swap = *(array + hantei[0]);
	*(array + hantei[0]) = *(array + hantei[1]);
	*(array + hantei[1]) = swap;
	
	for (int i = 0; i < N; i++) {
		if (*(array + i) != (i + 1)) {
			decision = 1;
			break;
		}
	}

	if (decision == 0) {
		printf("YES");
	}
	else {
		printf("NO");
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <ctime>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef tuple<int, int, int> T;
typedef pair<int, int> P;
 
int n;
int a[200000];
int b[200000];
int cntA[200001];
int cntB[200001];
priority_queue<T> queA;	//(count(num, A+B), count(num, A), num)
priority_queue<T> queB; //(count(num, A+B), count(num, B), num)
bool eraseA[200001];
vector<P> pa;			//(numA, numB)
 
signed main() {
	int i;
	clock_t start_time = clock();
	
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	
	rep(i, n) {
		cntA[a[i]]++;
		cntB[b[i]]++;
	}
	
	for (i = 1; i <= n; i++) {
		if (cntA[i] > 0) {
			queA.push(T(cntA[i] + cntB[i], i, cntA[i]));
		}
		else {
			eraseA[i] = true;
		}
		if (cntB[i] > 0) {
			queB.push(T(cntA[i] + cntB[i], i, cntB[i]));
		}
	}
	
	while (!queA.empty()) {
		T tupA = queA.top(); queA.pop();
		T tupB = queB.top(); queB.pop();
		
		if (get<1>(tupA) == get<1>(tupB)) {
			if (queB.empty()) {
				cout << "No" << endl;
				return 0;
			}
			T tupB2 = queB.top(); queB.pop();
			
			//use(tupA, tupB2)
			pa.push_back(P(get<1>(tupA), get<1>(tupB2)));
			if (get<2>(tupA) - 1 > 0) {
				queA.push(T(get<0>(tupA) - 1, get<1>(tupA), get<2>(tupA) - 1));
			}
			else {
				eraseA[get<1>(tupA)] = true;
			}
			queB.push(T(get<0>(tupB) - 1, get<1>(tupB), get<2>(tupB)));
			
			if (get<2>(tupB2) - 1 > 0) {
				queB.push(T(get<0>(tupB2) - 1, get<1>(tupB2), get<2>(tupB2) - 1));
			}
			if (eraseA[get<1>(tupB2)] == false) {
				if ((double)(clock() - start_time) / CLOCKS_PER_SEC < 1.7) {
					vector<T> vec;
					while (!queA.empty()) {
						T now = queA.top(); queA.pop();
						if (get<1>(now) == get<1>(tupB2)) {
							vec.push_back(T(get<0>(now) - 1, get<1>(now), get<2>(now)));
							break;
						}
						else {
							vec.push_back(now);
						}
					}
					rep(i, vec.size()) {
						queA.push(vec[i]);
					}
				}
			}
		}
		else {
			//use(tupA, tupB)
			pa.push_back(P(get<1>(tupA), get<1>(tupB)));
			if (get<2>(tupA) - 1 > 0) {
				queA.push(T(get<0>(tupA) - 1, get<1>(tupA), get<2>(tupA) - 1));
			}
			else {
				eraseA[get<1>(tupA)] = true;
			}
			if (get<2>(tupB) - 1 > 0) {
				queB.push(T(get<0>(tupB) - 1, get<1>(tupB), get<2>(tupB) - 1));
			}
		}
	}
 
	sort(pa.begin(), pa.end());
	
	cout << "Yes" << endl;
	for (int i = 0; i < (int)pa.size(); i++) {
		cout << pa[i].second;
		if (i + 1 < pa.size()) cout << " ";
	}
	cout << endl;
	return 0;
}

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

count = []
for i in range(len(S) - len(T) + 1):
    match_count = 0
    for s, t in zip(S[i:i+len(T)], T):
        if s in t:
            match_count += 1
    count.append(match_count)

print(len(T) - max(count))

Measured memory_bytes: 9000
/*************************************************************************
    > File Name: A.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com 
    > Created Time: 2019年02月16日 星期六 20时04分07秒
 ************************************************************************/

#include<iostream>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

using namespace std;

int main()
{

	int a,b;
	cin >> a >> b;
	if(b % a == 0) 
	{
		cout << a + b << endl;
	}else{
		cout << b - a << endl;
	}
    return 0;
}


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

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

 if(S=="MON"){cout<<"6";}
 else if(S=="TUE"){cout<<"5";}
 else if(S=="WED"){cout<<"4";}
 else if(S=="THU"){cout<<"3";}
 else if(S=="FRI"){cout<<"2";}
 else if(S=="SAT"){cout<<"1";}
 else if(S=="SUN"){cout<<"7";}


 }


Measured memory_bytes: 3596
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int x, a, b;
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M =1000000007;
//MOD??
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
ll mpow(ll x, ll n){ //x^n(mod M) ????pow(x,n)?????????????mod??
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
int main (){
  int i;
  int a,b;
  cin>>a>>b;
  cout<<a*b<<endl;
  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int A,B;
    cin >> A >> B;
    if(B%A==0)cout << A+B << endl;
    else cout << B-A << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    fast
    ll n,i,j;
    cin>>n;

    ll ans=0;

    for(i=1;i<=n;i++)
    {
        ll a = i;
        ll d = i;
        ll an =0;
        if(n%a==0)
        {
            an = n;
        }
        else
        {
            an = (n/a)*a;
        }
        ll no = (an-a)/d +1;

        ll sum = ((a+an)*no)/2;
//                cout<<"a"<<a<<" "<<"d"<<" "<<d<<" "<<"an"<<" "<<an<<" "<<"no"<<" "<<no<<" "<<"sum"<<sum<<endl;

        ans+=sum;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3584
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=a*c;
	ans=max(ans,a*d);
	ans=max(ans,b*c);
	ans=max(ans,b*d);
	cout<<ans<<endl;
	return 0;	
}


Measured memory_bytes: 3684
import sys
input=sys.stdin.readline
from bisect import bisect_left
n,q=map(int,input().split())
stop=[]
for i in range(n):
	s,t,x=map(int,input().split())
	stop.append((s,t,x))
stop.sort(key=lambda x:x[2])
d=[int(input())for i in range(q)]
R=[-1]*q
ans=[-1]*q
for s,t,x in stop:
	#lからrにある区間のansをxに更新したい
	l=bisect_left(d,s-x)
	r=bisect_left(d,t-x)
	while l<r:
		if R[l]==-1:#最左がまだ確定していない場合
			ans[l]=x
			R[l]=r
			l+=1
		else:
			l=R[l]#確定しているところを飛ばす
for x in ans:
	print(x)


Measured memory_bytes: 56176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    private final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    private final PrintWriter out = new PrintWriter(System.out);

    public void solve() throws IOException {
        String[] vals = in.readLine().split(" ");
        out.println(Integer.parseInt(vals[0]) * Integer.parseInt(vals[1]));
    }

    private void go() throws IOException {
        solve();
        in.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().go();
    }
}

Measured memory_bytes: 32680
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
  int n;
  cin >> n;
  int a[110];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int m = *min_element(a, a+n);
  int M = *max_element(a, a+n);
  cout << M-m << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] input2 = input.Split();
            int[] A=new int[input2.Length];
            int B;
            int C;
            int count;
            count = 0;

            for (int i = 0; i < input2.Length; i++)
            {
                switch (input2[i])
                {
                    case "+":
                        count--;
                        C = A[count];
                        count--;
                        B = A[count];
                        A[count] = B + C;
                        count++;
                        break;
                    case "-":
                        count--;
                        C = A[count];
                        count--;
                        B = A[count];
                        A[count] = B - C;
                        count++;
                        break;
                    case "*":
                        count--;
                        C = A[count];
                        count--;
                        B = A[count];
                        A[count] = B * C;
                        count++;
                        break;
                    default:
                        A[count] = int.Parse(input2[i]);
                        count++;
                        break;
                }
            }

            Console.WriteLine(A[0]);
            Console.ReadLine();
        }
    }
}
            
 

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

using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int d[5];
    int count =0;
    int n;
    for (int i = a; i <= b; i++){
        n=i;
        for (int i = 0; i < 5; i++){
            d[i]=n%10;
            n/=10;
        }
        if(d[0]==d[4] && d[1]==d[3]) count++;
    }
    cout << count <<"\n";
}

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

n, a, b = [int(i) for i in input().split()]

ans = 0
if a == 0 and b == 0:
    print(ans)
    sys.exit(0)

full = n // (a + b)
ans += a * full

partial = n % (a + b)
if partial >= a:
    ans += a
else:
    ans += partial

print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define Task "D"

using namespace std;
const int maxN = 1e5 + 5;
int n, m;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    int val = 0;
    priority_queue<int> pq;
    for(int i = 1; i<=n; ++i){
        cin >> val;
        pq.push(val);
    }
    for(int i = 1; i<=m; ++i){
        int Top = pq.top(); pq.pop();
        pq.push(Top/2);
    }
    long long res = 0;
    while (!pq.empty()) res += pq.top(), pq.pop();

    cout << res;

    return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool a[10];
bool right(int n){
  while(n>0){
    if(a[n%10]==1)return true;
    n/=10;
  }
  return false;



}
int main()
{
   int n,k;
   cin>>n>>k;
   //int a[10];
   for(int i=0;i<k;i++){
      int s;
      cin>>s;
      a[s]=1;
   }
   while(right(n)){
    n++;
   }
   cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
const int N=14;
int n;
int s[N];
void dfs(int len,int up)
{
    if(len==n+1)
    {
        for(int i=1;i<=n;i++)
            putchar(s[i]+'a');
        putchar('\n');return;
    }
    for(int i=0;i<=up;i++)
    {
        s[len]=i;
        dfs(len+1,min(25,max(up,i+1)));
    }
}
int main()
{
    scanf("%d",&n);
    dfs(1,0);
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>  
#include<set>
#include<iterator>
#include<list>
#include<utility>
#include<cstdlib>
#include<queue>
#include<stack>
#include<bitset>
//#include<bits/stdc++.h>
#define PI  2*acos(0.0)
#define pb push_back

       
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;



int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
/*
ll a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

ll size=sizeof(a)/sizeof(a[0]);
*/

ll a,b,ans;
cin>>a>>b;


ans=a*b;
if(ans&1)
{
	ans+=1;
}

if(a==1 || b==1)
{
	cout<<1<<"\n";
	return 0;
}



cout<<ans/2<<"\n";











	
	
	return 0;
	
	
	       /***Israil Hosen
	            Computer Science & Engineering
	         University Of Rajshahi.
	         ***/
	
	
	
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define ss second
#define ff first

 using namespace std;
 
 const ll MOD = 1000000007LL;
 
ll ar[500056],br[500056];


vector<ll> vec,pec;
set<ll> st;
map<ll,ll> has;


vector<pair<ll,ll> > vp;




int main() 
{
	
//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
    
    ll n,p,t,j,a,x,y=0,k,l,m,z,b,c,e,f,q,s,flag=0,sum=0,res=0,num,g,h;
	ll i,u,v,w,ans,maxm=0,r,minm=999999999999,maxi;
	bool fl=0;
	ll d;
	string str;
	
	cin>>n>>a>>b;
	
	cout<<min(n*a,b);
	
	

	
    return 0;
}    




Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;

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

    int k, a, b;
    cin >> k >> a >> b;
    for(int i = 0;; ++i) {
        if(i * k >= a && b >= i * k) {
            cout << "OK" << endl;
            return 0;
        }
        if(i * k > b)
            break;
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_M = 10005;
const int MAX_N = 5005;

int p[MAX_M];
int sump[MAX_M];
int c[MAX_N];
int e[MAX_N];
int dp[MAX_N][MAX_M];
int m,n;

int main()
{
	scanf("%d%d",&m,&n);
	rep(i,m){
		scanf("%d",&p[i]);
	}
	rep(i,n){
		scanf("%d%d",&c[i],&e[i]);
	}
	sort(p,p+m,greater<int>());
	sump[0] = p[0];
	for(int i=1;i<m;i++){
		sump[i] += sump[i-1] + p[i];
	}
	rep(i,n+1){
		rep(j,m+1){
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	rep(i,n+1){
		rep(j,m+1){
			dp[i+1][j] = min(dp[i][j],dp[i][max(j-c[i],0)]+e[i]);
		}
	}
	int ans = 0;
	rep(i,m){
		ans = max(ans,sump[i] - dp[n][i+1]);
	}
	printf("%d\n",max(ans,0));
	return 0;
}

Measured memory_bytes: 22992
n, m = map(int, input().split())
a = [input().split() for i in range(m)]
wa =[0]*n #ACまでのWA数
ac = [0]*n

for i in range(m):
    if a[i][1] == 'AC':
      ac[int(a[i][0])-1] = 1
    else:
      if ac[int(a[i][0])-1]==0:
        wa[int(a[i][0])-1] +=1
cnt1, cnt2= 0,0
for i in range(n):
  if ac[i] ==1:
    cnt1 += ac[i]
    cnt2 += wa[i]
        
print(cnt1, cnt2)

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

namespace AtCoderBeginnerContest162
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = ReadInt();
			var result = 0L;
			for(var i = 1; i <= input; i++)
			{
				if(i % 3 != 0 && i % 5 != 0)
				{
					result += i;
				}
			}
			Console.WriteLine(result);
		}

		public static int ReadInt()
			=> int.Parse(Console.ReadLine());

		public static int[] ReadIntArray()
			=> Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

		public static long ReadLong()
			=> long.Parse(Console.ReadLine());

		public static long[] ReadLongArray()
			=> Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

		public static string ReadString()
			=> Console.ReadLine();

		public static string[] ReadStringArray()
			=> Console.ReadLine().Split();
	}
}


Measured memory_bytes: 27392
# -*- coding: utf-8 -*-
 
 
def main(n):
    lst = [1, 1]
    for i in range(2, n + 1):
        lst.append(lst[i - 2] + lst[i - 1])
    return lst[n]
 

if __name__ == '__main__': 
    n = int(input())
    print(main(n))

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

const bool DEBUG = false;

// 直感的には均せばよさそう．最終的な金額がなるべく等しくなるように
// largestから順番に叩いていくのが最適解っぽい気がする

template <typename T>
void print_vector(const vector<T>& v) {
  for (auto elem : v) {
    cout << elem << ", ";
  }
  cout << endl;
}

int main(int argc, char const* argv[]) {
  int N, M;
  cin >> N >> M;
  long long A_first, A_second;
  // priority_queue<long long, vector<long long>, greater<long long>> A;
  priority_queue<long long> A;
  for (int i = 0; i < N; i++) {
    cin >> A_first;
    A.push(A_first);
  }

  if (N == 1) {
    cout << (long long)(A_first / pow(2, M)) << endl;
    return 0;
  }

  A_first = A.top();
  A.pop();

  while (M > 0) {
    A_second = A.top();
    A.pop();
    if (DEBUG) {
      cout << "M: " << M << " A.size(): " << A.size() << " first: " << A_first
           << " second: " << A_second << endl;
    }
    while (M > 0 && A_first >= A_second) {
      A_first /= 2;
      M -= 1;
    }
    A.push(A_first);
    A_first = A_second;
  }
  A.push(A_first);

  // int first = 0;
  // int second = 1;
  // while (M > 0) {
  //   for (int i = 1; i < N; i++) {
  //     if (A[i] > A[first]) {
  //       second = first;
  //       first = i;
  //     } else if (A[i] > A[second]) {
  //       second = i;
  //     }
  //   }
  //   if (DEBUG) cout << M << ", " << first << ", " << second << endl;
  //   while ((M > 0) && (A[first] >= A[second])) {
  //     A[first] /= 2;
  //     M -= 1;
  //   }
  //   first = 0;
  //   second = 1;
  //   if (DEBUG) {
  //     cout << "A: ";
  //     print_vector(A);
  //   }
  // }

  long long total = 0;
  for (int i = 0; i < N; i++) {
    if (DEBUG) cout << A.top() << ", ";
    total += A.top();
    A.pop();
  }
  if (DEBUG) cout << endl;
  cout << total << endl;

  return 0;
}


Measured memory_bytes: 1400
void main(){
	int n = inelm();
	( 800*n - (n/15).to!int()*200).writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    int count = 0;
    rep(i, n) cin >> vec.at(i);
    rep(i, n - 2) {
        int x = vec.at(i + 1);
        if (vec.at(i) < x && x < vec.at(i + 2)) count++;
        else if (vec.at(i) > x && x > vec.at(i + 2)) count++;
        else continue;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<string>
#include<iomanip>
#include<cmath>
#include <iostream>
using namespace std;

int main()
{
    int n, m;
    int neteisingi[105000] = {0};
    bool teisingi[105000];
    cin >> n >> m;
    int WA = 0;
    int AC = 0;

    for(int i = 1; i <= n; i++)
    {
        neteisingi[i] = 0;
        teisingi[i] =false;
    }

    while(m--)
    {
        int p;
        string s;
        cin >> p >> s;
        if(teisingi[p])continue;//apie sita nepagalvojau, kaip nepriskaiciuot jeigu true
        if(s == "AC")
        {
            teisingi[p] =true;//nepagalvojau vien tik true masyva daryt
            AC ++;
            WA+=neteisingi[p];
        }
        else if (s  == "WA")
        {
            neteisingi[p]++;//kiekvienai koordinatei padaroma vieta storint wa skaiciu, mes dedame i ta masyva tol kol teisingi[p] == true;
        }

    }
    cout << AC << " " << WA;

}



Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
const ll INF = ll(1e18);
const int MOD = 998244353;

const int MAXN = 100005;

int cnt[1000005];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	ll a[n];
	forn(i,0,n){ cin>>a[i]; cnt[a[i]]++; }
	sort(a,a+n);
	
	int ans=0;
	forn(z,0,n){
		bool ok=1;
		for(ll i=1;i*i<=a[z];i++){
			if(a[z]%i!=0) continue; //watch(s.count(a[z]/i)); watch(a[z]/i);
			if(a[z]==1){
				if(cnt[1]>1) ok=0;
			}
			else if(cnt[i] || cnt[a[z]/i]>bool(i==1)){
				ok=0; break;
			}
		}
		if(ok){
			//cout<<"i="<<z<<'\n';
			ans++;
		}
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 9108
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define MAX_M 16
#define MAX_N 20010
#define INF 1e8
 
int N, M, C[MAX_M], x[MAX_N];
int dp[MAX_N][256];
 
int main(){
    while(cin >> N >> M , (N | M)){
	for(int i = 0 ; i < M ; i++){
	    cin >> C[i];
	}
  
	for(int i = 1 ; i <= N ; i++){
	    cin >> x[i];
	}
	int ans = INF;
	fill(dp[0], dp[MAX_N], INF);
	dp[0][128] = 0;
	for(int i = 1 ; i <= N ; i++){
	    for(int j = 0 ; j <= 255 ; j++){
		for(int k = 0 ; k < M ; k++){
		    int t = j + C[k];
		    if(t < 0) t = 0;
		    if(t > 255) t = 255;
		    dp[i][t] = min(dp[i][t], dp[i-1][j] + (t-x[i])*(t-x[i]));
		}
	    }
	}
	for(int i = 0 ; i <= 255 ; i++){
	    ans = min(ans, dp[N][i]);
	} 
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 23176
//fBNÌZpè
//Dirichlet's Theorem on Arithmetic Progressions
#include<iostream>
#include<cmath>
#define NUM 1000000
using namespace std;
int p[NUM];
int main(){
	int a,d,n;
	int i,j;
	int cnt;

	/*fe[uì¬*/
	p[0]=0;
	p[1]=0;
	for(i=2;i<NUM;i++)p[i]=1;

	for(i=2;i<sqrt(NUM)+1;i++){
		if(p[i]){
			for(j=i*2;j<NUM;j+=i){
				p[j]=0;//{Í­
			}
		}
	}
	while(cin>>a>>d>>n,(a||d||n)){
		cnt=0;
		for(i=a;;i+=d){
			if(p[i]==1)cnt++;
			if(cnt==n)break;
		}
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ncr(ll a, ll b)
{
  ll res=1;
  for(ll i=1;i<=b;i++)
  {
    res *= a-i+1;
    res /= i;
  }
  return res;
}
int main()
{
  ll n;
  cin>>n;
  vector<ll>a(n);
  for(ll i=0;i<n;i++)
    cin>>a[i];
  unordered_map<ll ,ll>mp;
  for(ll i=0;i<n;i++)
  	mp[a[i]]++;
  unordered_map<ll,ll>mp2, mp3;
  ll s2=0,s3=0;
  for(auto it=mp.begin(); it!=mp.end(); it++)
  {
    ll r=it->second;
    //r--;
    ll x=ncr(r,2);
    s2+=x;
    //cout<<it->first<<" "<<x<<"\n";
    mp2.insert(make_pair(it->first, x));
    r--;
    x=ncr(r,2);
    s3+=x;
    //cout<<it->first<<" "<<x<<"\n";
    mp3.insert(make_pair(it->first, x));
  }
  for(ll i=0;i<n;i++)
  {
    cout<<s2-mp2[a[i]]+mp3[a[i]]<<"\n";
  }
  return 0;
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  a--; b--;
  
  const int maxh = 100, maxw = 100;
  vector<vector<char>> ans(maxh, vector<char>(maxw, '.'));
  rep(i, maxh/2) rep(j, maxw) ans[i][j] = '#';
  
  for(int i = 0; i < maxh/2; ++++i)
  {
    for(int j = 0; j < maxw; ++++j)
    {
      if(a == 0) break;
      ans[i][j] = '.';
      a--;
    }
    if(a == 0) break;
  }
  
  for(int i = maxh-1; i > maxh/2; ----i)
  {
    for(int j = 0; j < maxw; ++++j)
    {
      if(b == 0) break;
      ans[i][j] = '#';
      b--;
    }
    if(b == 0) break;
  }
  
  cout << maxh << " " << maxw << "\n";
  rep(i, maxh)
  {
    rep(j, maxw) cout << ans[i][j];
    cout << "\n";
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
h=list(map(int,input().split()))
m=max(h)
c=0
for i in range(1,m+1):
    if h[0]>=i:
        c+=1
    for j in range(1,n):
        if h[j]>=i and h[j-1]<i:
            c+=1
print(c)

Measured memory_bytes: 9352
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

vector<int> cand(0);

void push(int a,int n){
    if(n == 0) return;
    n--;
    cand.push_back(10*a+3);
    cand.push_back(10*a+5);
    cand.push_back(10*a+7);

    push(10*a+3,n);
    push(10*a+5,n);
    push(10*a+7,n);
  }

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

  push(3,8);
  push(5,8);
  push(7,8);

  int ans = 0;
  sort(cand.begin(),cand.end());
   
  for(int i = 0;i < cand.size();i++) {
    vector<bool> check(3,false);
    if(cand.at(i) < 100) continue;
    if(cand.at(i) > N) break;

    while(cand.at(i) > 0) {
      if(cand.at(i) % 10 == 3) check.at(0) = true;
      if(cand.at(i) % 10 == 5) check.at(1) = true;
      if(cand.at(i) % 10 == 7) check.at(2) = true;
      cand.at(i) /= 10;
    }

    if(check.at(0) && check.at(1) && check.at(2)) ans++;
  }

  cout << ans << endl;
  
}




Measured memory_bytes: 512
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static void kMarsh(String[] grid) {
        int n=grid.length;
        int m=grid[0].length();
        char[][] mat=new char[n][m];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                mat[i][j]=grid[i].charAt(j);
            }
        }
        int[][] first=new int[m][n];
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                int ind=n;
                for(int k=j;k<n;k++)
                {
                    if(mat[k][i]=='x')
                    {
                        ind=k;
                        break;
                    }
                }
                first[i][j]=ind;
            }
        }
        boolean[][][] there=new boolean[n][m][m];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                for(int k=j;k<m;k++)
                {
                    boolean b1=(mat[i][k]=='x')?false:true;
                    boolean b2=true;
                    if(k!=j)
                    b2=there[i][j][k-1];
                    if(!b1 || !b2)
                    there[i][j][k]=false;
                    else
                    there[i][j][k]=true;
                }
            }
        }
        int ans=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(mat[i][j]=='x')
                continue;
                int f1=first[j][i]-1;
                for(int k=j+1;k<m;k++)
                {
                    if(mat[i][k]=='x')
                    break;
                    int f2=first[k][i]-1;
                    int x=Math.min(f1,f2);
                    if(x==i)
                    continue;
                    if(!there[x][j][k])
                    continue;
                    int p=2*(x-i+k-j);
                    // System.out.println(i+" "+x+" "+k+" "+j+" "+p);
                    ans=Math.max(ans,p);
                }
            }
        }
        if(ans!=0)
        System.out.println(ans);
        else
        System.out.println("impossible");
    }
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		int n=cin();
		int[]arr=split();
		long[] cnt=new long[n+1];
		for(int i=0;i<n;i++)
		{
			cnt[arr[i]]++;
		}
		long tot=0;
		for(int i=0;i<=n;i++)
		{
			if(cnt[i]==0)
				continue;
			tot=tot+((cnt[i])*(cnt[i]-1))/2;
		}
		for(int i=0;i<n;i++)
		{
			long x=cnt[arr[i]]-1;
			long y=tot-((cnt[arr[i]])*(cnt[arr[i]]-1))/2;
			y=y+(x*(x-1))/2;
			System.out.println(y);
		}
	}
}


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

map<int, ll> mp;
void prime_factorize(long long N) {
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        mp[a] += ex;
    }
    if (N != 1) mp[N]++;
    return;
}

int main() {  
    int n; cin >> n;
    for(int i=1; i<=n; i++) prime_factorize(i);
    ll res = 1;
    for(auto m: mp){
        res = res * (m.second+1) % MOD;
    }
    cout << res << ln;
}




Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 100005

int n,m;
char s[maxn];

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

inline void print(int x){
	if (x<0){putchar('-'); x=-x;}
	if (x>=10) print(x/10);
	putchar(x%10+'0');
}

int main(){
	scanf("%s",s+1); n=strlen(s+1); int ans=(n+1)>>1;
	if (n&1){
		int mid=(n>>1)+1; char pps=s[mid];
		for (int i=mid-1,j=mid+1;j<=n;j++,i--){
			if (s[i]!=pps||s[j]!=pps) break;
			ans++;
		}
		printf("%d\n",ans);
	}
	else{
		int mid1=(n>>1),mid2=mid1+1;
		for (int i=mid1,j=mid2;j<=n;j++,i--){
			if (s[i]!=s[j]||s[i]!=s[mid1]) break;
			ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 384
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> x >> y;
	cout << x*y;
}
//.........

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

int n;

long long a[3010];
long long memo[3010][3010][2];

long long dp(int l, int r, int t){
  if(l > r) return 0;

  if(memo[l][r][t] != LLONG_MIN) return memo[l][r][t];

  if(t == 0){
    return memo[l][r][t] = max(dp(l+1, r, 1) + a[l], dp(l, r-1, 1) + a[r]);
  }else{
    return memo[l][r][t] = min(dp(l+1, r, 0) - a[l], dp(l, r-1, 0) - a[r]);
  }
}

int main(){
  cin >> n;

  for(int i = 0;i < n;i++){
    cin >> a[i];
  }

  for(int i = 0;i < 3010;i++){
    for(int j = 0;j < 3010;j++){
      for(int k = 0;k < 2;k++){
        memo[i][j][k] = LLONG_MIN;
      }
    }
  }

  cout << dp(0, n-1, 0) << endl;

  return 0;
}


Measured memory_bytes: 142080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
   cin >> A >> B >> C >> D ;
 if ( A + B > C + D ){
   cout << "Left" << endl;
 }
  if ( A + B < C + D ){
   cout << "Right" << endl;
 }
  if ( A + B == C + D ){
   cout << "Balanced" << endl;
 } 
}

Measured memory_bytes: 3568
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define N_MAX 2001
#define MOD 1000000007

int N, M;
int S[N_MAX], T[N_MAX];
long long int memo[N_MAX][N_MAX];

long long int func(int x, int y)
{
	if (x < 0) return 0;
	if (y < 0) return 0;
	if (-1 != memo[x][y]){
		return memo[x][y];
	}

	long long int ret = 0;
	ret = (ret + func(x - 1, y)) % MOD;
	ret = (ret + func(x, y - 1)) % MOD;
	ret = (ret - func(x - 1, y - 1) + MOD) % MOD;

	if (S[x] == T[y]){
		ret = (ret + func(x - 1, y - 1) + 1) % MOD;
	}

	return memo[x][y] = ret;
}

void solv()
{
	scanf("%d%d", &N, &M);
	int tail = 0;
	for (int i = 0; i < N; i++){
		scanf("%d", S + i);
	}
	for (int i = 0; i < M; i++){
		scanf("%d", T + i);
	}

	for (int i = 0; i < N_MAX; i++){
		fill(memo[i], memo[i] + N_MAX, -1);
	}

	printf("%lld", func(N-1, M-1) + 1);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 31744
#include <iostream>
using namespace std;
long long i,j,mod=1e9+7,n,m,dp[2][5005];
string s;
int main(){
	cin>>n>>s;
	m=s.size();
	dp[0][0]=1;
	for (i=1;i<=n;i++){
		dp[i&1][0]=(dp[(i-1)&1][0]+dp[(i-1)&1][1]*2)%mod;
		for (j=1;j<=n;j++){
			dp[i&1][j]=(dp[(i-1)&1][j-1]+dp[(i-1)&1][j+1]*2)%mod;
		}
	}
	cout<<dp[n&1][m]<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std ;
int main () {
  string N;
  cin>>N;
  int cnt1 = 0;
  int cnt2 = 0;
  for(char c:N){
    if(c == '+') cnt1++;
    else cnt2++;
  }
  cout<<cnt1-cnt2<<endl;
}

Measured memory_bytes: 256
// 7/1 解き直し
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

ll dp[100010];

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    rep(i, M) cin >> a[i];
    a.push_back(N+1);

    rep(i, 100010) dp[i] = 1;
    dp[1] = 1;
    dp[2] = 2;
    for (int i = 3; i <= N; i++) {
        dp[i] = dp[i - 1] + dp[i - 2];
        dp[i] %= mod;
    }

    ll res = 1;
    ll prev = 0;
    for (int i = 0; i <= M; i++) {
        int distance = a[i] - 1 - prev;
        if (distance < 0) {
            cout << 0 << endl;
            return 0;
        }
        res *= dp[distance];
        res %= mod;
        prev = a[i] + 1;
        // printf("distance, dp[distance], res = %d, %d, %d\n", distance, dp[distance], res);
    }

    cout << res << endl;
}

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

#define N 2000000
#define INFTY (1<<30)
int H, Heap[N+1];

void maxHeapify(int i){
  int largest, tmp;
  int l = 2 * i;
  int r = 2 * i + 1;

  if(l <= H && Heap[l] > Heap[i]){
    largest = l;
  }
  else{
    largest = i;
  }

  if(r <= H && Heap[r] > Heap[largest]){
    largest = r;
  }

  if(largest != i){
    tmp = Heap[i];
    Heap[i] = Heap[largest];
    Heap[largest] = tmp;
  
    maxHeapify(largest);
  }
}

void increaseKey(int i, int key){
  int tmp;
  if(key < Heap[i]){
    return;
  }

  Heap[i] = key;

  while(i > 1 && Heap[i/2] < Heap[i]){
    tmp = Heap[i];
    Heap[i] = Heap[i/2];
    Heap[i/2] = tmp;
    i /= 2;
  }
}

void insert(int key){
  H++;
  Heap[H] = -INFTY;
  increaseKey(H, key);
}

int extract(){
  int max;
  if(H < 1){
    return -INFTY;
  }
  max = Heap[1];
  Heap[1] = Heap[H--];
  maxHeapify(1);
  return max;
}

int main(){
  int key;
  string status;

  while(1){
    cin >> status;
    if(status == "end"){
      break;
    }

    if(status == "insert"){
      cin >> key;
      insert(key);
    }
    else{
      cout << extract() << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 5300
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    L, R = input_nums()
    MOD = 2019
    ans = 2019
    for i in range(L, R):
        for j in range(i+1, R+1):
            ans = min(ans, (i*j)%MOD)
            if ans == 0:
                print(ans)
                exit(0)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
/*
AOJ - ITP1_5_D
Date: 20180923
Author: Mikoron
 */

#include<stdio.h>
#include<stdbool.h>

#define SUITS 4
#define RANKS 14

int main(void) {
        int n, i, j, rank;
        //[0][rank] = S, [1][rank] = H, [2][rank] = C, [3][rank] = D
        bool cards[SUITS][RANKS];
        char suit;

        //initialize
        for(i = 1; i < RANKS; i++) {
                cards[0][i] = cards[1][i] = cards[2][i] = cards[3][i] = false;
        }

        scanf("%d\n", &n);
        for(i = 0; i < n ; i++) {
                scanf("%c %d\n", &suit, &rank);
                switch(suit) {
                        case 'S':
                                cards[0][rank] = true;
                                break;
                        case 'H':
                                cards[1][rank] = true;
                                break;
                        case 'C':
                                cards[2][rank] = true;
                                break;
                        case 'D':
                                cards[3][rank] = true;
                                break;

                }
        }

        for(i = 0; i < SUITS; i++) {
                for(j = 1; j < RANKS; j++) {
                        if(cards[i][j] == false) {
                                switch(i) {
                                        case 0:
                                                suit = 'S';
                                                break;
                                        case 1:
                                                suit = 'H';
                                                break;
                                        case 2:
                                                suit = 'C';
                                                break;
                                        case 3:
                                                suit = 'D';
                                                break;

                                }
                                printf("%c %d\n", suit, j);
                        }
                }
        }

        return 0;
}



Measured memory_bytes: 2124
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: u64 = read_as_vec::<u64>()[0];

    let mut ans: (u64, u64) = (n, n);
    for i in 1..(n as f64).sqrt().ceil() as u64+1{
        if n%i != 0{
            continue;
        }
        let j = n/i;

        if ans.0 + ans.1 > i + j{
            ans = (i, j);
        }
    }
    println!("{}", ans.0 + ans.1 - 2);
 }


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(9);
    
    int N;
    cin >> N;
    int L[10];
    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> L[i];
        sum += L[i];
    }
    for(int i=0; i<N; i++){
        if(L[i] >= sum-L[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()

res = 0
for bit in range(1<<len(S)-1):
  last = 0  # 最後に+を入れた位置を記録する
  for i in range(len(S)-1):
    if bit & (1<<i):
      res += int(S[last:i+1])
      # print(f'S[last:i+1]={S[last:i+1]}')
      last = i + 1
  res += int(S[last:])
  # print(f'S[last:] = {S[last:]}')
  
print(res)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;

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

    ll out = 0;
    for (int i = 0; i < 1000; i++){
      int c[3] = {i / 100, (i / 10) % 10, i % 10};
      ll idx = 0;
      for (int j = 0; j < N; j++) {
        if (c[idx] + '0' == S[j]) idx++;
        if (idx == 3) break;
      }
      if (idx == 3) out++;
    }
    cout << out << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	
	if((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5))
		printf("YES\n");
	else
		printf("NO\n");
	
	return 0;
}

Measured memory_bytes: 256