akhauriyash/Code-Regression huggingface dataset:
/*
        ######## ##   ## #######          ##########
           ##    ##   ## ##                 ##    ##
           ##    ####### ######             ##    ##
           ##    ##   ## ##                 ##    ##
           ##    ##   ## ####### ######## ##########
    */
    #include<bits/stdc++.h>
    #include <iomanip>
    #define int         long long
    #define ll          long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         std::vector<vector<int> > v;
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
    #define sz(x)       (int)x.size()
    #define hell        1000000007
    #define rep(i,a,b)    for(int i=a;i<b;i++)
    #define lbnd        lower_bound
    #define ubnd        upper_bound
    #define bs          binary_search
    #define mp          make_pair
    #define maxc(v)     max_element(all(v))
    #define minc(v)     min_element(all(v))
    #define endl        "\n"
    using namespace std;
    #define N  100005
    //#define M  1000003
    #define rn return
    #define B 100000000
    int modularExponentiation(int x,int n,int M = hell)
	{
    	if(n==0)
        	return 1;
    	else if(n%2 == 0)
        	return modularExponentiation((x*x)%M,n/2,M);
    	else
        	return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

	}
	int abs(int a, int b){
        if(a>b) return a-b;
        else return b-a;
    }
    void solve();
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        //cin>>TESTS;
        while(TESTS--)
        {
            solve();
        }
        return 0;
    }
    void solve(){
    	int n,k = 2;
    	cin>>n>>k;
    	int h[n], dp[n];
    	rep(i,0,n) {
    		cin>>h[i];
    		dp[i] = hell;
    	}
    	dp[0] = 0;
    	rep(i,1,n){
    		for(int j = 1; j <= min(i, k); j++){
    			dp[i] = min(dp[i],dp[i-j] + abs(h[i], h[i-j]));
    		}
    	}
    	cout<<dp[n-1]<<endl;
    }

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int a, b, k;
    int mmax, mmin;
    
    scanf("%d%d%d", &a, &b, &k);
    
    mmax=b-k+1;
    mmin=a+k-1;
    
    for (int i=a; i<=b; i++) {
        if (i>=mmax||i<=mmin) {
            printf("%d\n", i);
        }
    }
    
    return 0;
}


Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    if( S[S.size() - 1] == '2'){
        cout << "hon" << endl;
    }
    else if( S[S.size() - 1] == '4'){
        cout << "hon" << endl;
    }
    else if( S[S.size() - 1] == '5'){
        cout << "hon" << endl;
    }
    else if( S[S.size() - 1] == '7'){
        cout << "hon" << endl;
    }
    else if( S[S.size() - 1] == '9'){
        cout << "hon" << endl;
    }
    else if( S[S.size() - 1] == '0'){
        cout << "pon" << endl;
    }
    else if( S[S.size() - 1] == '1'){
        cout << "pon" << endl;
    }
    else if( S[S.size() - 1] == '6'){
        cout << "pon" << endl;
    }
    else if( S[S.size() - 1] == '8'){
        cout << "pon" << endl;
    }
   
    else{
        cout << "bon" << endl;
    }
   
 

   
}


Measured memory_bytes: 3624
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
V<int> v(n),c(n);
for(int i=0;i<n;i++)cin>>v[i];
for(int i=0;i<n;i++)cin>>c[i];
ll ans=0;
for(int i=0;i<n;i++){
	if(v[i]-c[i]>0)ans+=v[i]-c[i];
}
cout<<ans<<endl;
}



Measured memory_bytes: 256
/**     Md. Mujahedul Azad (Turin)
        Hajee Mohammad Danesh Science & Technology University **/

#include <map>
#include <math.h>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

template<class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template<class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template<typename T> T power(T val, T p, T mod){val%=mod; T result=1; while(p>0){if(p&0x1)result=(result*val)%mod;val=(val*val)%mod;p>>=1;}return result;}
template<typename T> inline void read(T &res){int sign=1; res=0;char ch = getchar();while(true){if(ch == '-') break;if(ch >= '0' && ch <='9') break;ch = getchar();}if(ch == '-') sign = -1;else res = ch-'0';while(true){ch = getchar();if(ch < '0' || ch > '9') break;res = (res * 10 + (ch - '0'));}res *= sign;}

#define ff                  first
#define se                  second
#define sfr(a)              read(a)
#define G()                 getchar()
#define pb                  push_back
#define pi                  acos(-1.0)
#define sq(x)               ((x) * (x))
#define sfi(x)              scanf("%d", &x)
#define sfrr(a,b)           read(a), read(b)
#define inOut               {input; output;}
#define SZ(x)               ((int) (x).size())
#define all(x)              (x).begin(), (x).end()
#define mem(a,b)            memset((a),(b),sizeof(a))
#define Case                printf("Case %d: ", cases)
#define input               freopen("input.txt","r",stdin)
#define output              freopen("output.txt","w",stdout)

#define PF                  printf
#define CASE                printf("Case %d: ", cs);
#define CASEN               printf("Case %d:\n", cs);

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

const double eps=3e-8;
const int mx = 2e5+5;

ll n, k;
ll a[mx], f[mx];

struct node{
    ll x, y, val;
    node(ll x=0, ll y=0):
        x(x), y(y){val=x*y;}
    bool operator < (const node &ot) const{
        if(val != ot.val) return val < ot.val;
        if(x != ot.x) return x < ot.x;
        return y < ot.y;
    }
};
priority_queue<node> pq;

bool safe(ll v){
    ll kk = k;
    priority_queue<node> q = pq;
    while(q.size()){
        node tmp = q.top(); q.pop();
        if(tmp.val <= v) return true;
        ll x1 = v / tmp.y;
        if(tmp.x - x1 > kk) return false;
        kk -= (tmp.x - x1);
        q.push(node(x1, tmp.y));
    }
    return true;
}

int main(){
    sfrr(n, k);
    for(int i=0; i<n; i++) sfr(a[i]);
    for(int i=0; i<n; i++) sfr(f[i]);

    sort(a, a+n, greater<ll>());
    sort(f, f+n);
//
//    for(int i=0; i<n; i++) PF("%lld ", a[i]); puts("");
//    for(int i=0; i<n; i++) PF("%lld ", f[i]); puts("");

    for(int i=0; i<n; i++)
        pq.push(node(a[i], f[i]));
    ll lw = 0, hh = 1e12+1, ans;
    while(lw<=hh){
        ll m = (lw+hh); m>>=1;
        if(safe(m)) ans = m, hh=m-1;
        else lw = m+1;
    }
    PF("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 13804
#include<stdio.h>
int main()
{
  int a[50];
  int count[11];
  int i,j;
  int max,min;
  int l;
  int ll,x;
  for(;;)
  {
    for(i=0;i<50;i++)
      a[i]=0;
    scanf("%d %d",&a[0],&l);
    if(a[0]==0 && l==0)
      return 0;
    for(i=1;;i++)
    {
      for(j=0;j<11;j++)
        count[j]=0;
      ll=a[i-1];
      while(ll>0)
      {
        count[ll%10]++;
        ll/=10;
      }
      min=max=0;
      for(j=0;j<11;j++)
      {
        while(count[j]>0)
        {
          min*=10;
          min+=j;
          count[j]--;
        }
      }
      ll=a[i-1];
      for(j=0;j<11;j++)
        count[j]=0;
      while(ll>0)
      {
        count[ll%10]++;
        ll/=10;
      }
      ll=l;
      for(j=10;j>0;j--)
      {
        while(count[j]>0)
        {
          max*=10;
          max+=j;
          ll--;
          count[j]--;
        }
      }
      while(ll>0)
      {
        max*=10;
        ll--;
      }
      x=0;
      for(j=0;j<i;j++)
      {
        if(a[j]==max-min)
        {
          printf("%d %d %d\n",j,max-min,i-j);
          x=4649;
          break;
        }
      }
      if(x>0)
        break;
      a[i]=max-min;
    }
  }
}


Measured memory_bytes: 2036
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;


bool solve(){
	string str;
	cin>> str;
	
	int ans = 0;
	vector<string> vs;
	
	for(int i=0;i<str.size();i++){
		string s1, s2;
		string t1, t2;
		s1 = str.substr(0,i);
		s2 = str.substr(i);
		t1 = s1;
		t2 = s2;
		reverse(t1.begin(), t1.end());
		reverse(t2.begin(), t2.end());
		
		vector<string> vs2;
		vs2.push_back(s1 + s2);
		vs2.push_back(t1 + s2);
		vs2.push_back(s1 + t2);
		vs2.push_back(t1 + t2);
		vs2.push_back(s2 + s1);
		vs2.push_back(t2 + s1);
		vs2.push_back(s2 + t1);
		vs2.push_back(t2 + t1);
		
		for(int k=0;k<8;k++){
			bool flag = true;
			for(int j=0;j<vs.size();j++){
				if(vs[j] == vs2[k]){
					flag = false;
					break;
				}
			}
			if(flag){
				vs.push_back(vs2[k]);
				ans++;
			}
		}		
	}
	
	cout<< ans<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	int n;
	cin>> n;
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}

 

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


using namespace std;
using lint = long long;


#define MOD (lint)(1e9+7)


lint fac[2001], finv[2001], inv[2001];

void COMinit()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;

	for (int i = 2; i < 2001; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

lint nCr(int n, int r){
	if (n < r) return 0;
	if (n < 0 || r < 0) return 0;
	return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}


int main(void)
{
	lint N, K;
	cin >> N >> K;

	COMinit();

	lint cnt = 0;
	for (lint i = 1; i <= K; i++){
		cnt = nCr(N-K+1, i) * nCr(K-1, i-1) % MOD;
		//cout << nCr(N-K+1 , i) << " " << nCr(K - 1, i - 1) << endl;
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def color(s):
    if s < 400:
        return 0
    if s < 800:
        return 1
    if s < 1200:
        return 2
    if s < 1600:
        return 3
    if s < 2000:
        return 4
    if s < 2400:
        return 5
    if s < 2800:
        return 6
    if s < 3200:
        return 7
    return 8


N = int(input())

a = [color(int(i)) for i in input().split()]
ans = 0
table = [False for i in range(10)]
for i in a:
    if i == 8:
        ans += 1
    else:
        table[i] = True

ret = 0
for f in table:
    if f:
        ret += 1

ans1 = max(ret,1)
ans2 = ret+ans

print(ans1,ans2)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, K;
	int ans = 0;
	
	cin>>N>>K;
	
	while(N){
		ans++;
		N /= K;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

int main() {
  int N,X;
  cin>>N>>X;
  
  vector<int> m(N);
  for(int i=0;i<N;++i){
    cin>>m[i];
  }
  
  int sum=0;
  int min=1000000;
  for(int i=0;i<N;++i){
    sum+=m[i];
    if(m[i]<min)
      min=m[i];
  }
  
  int ans=N+(X-sum)/min;
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll N,M,ans=0;
    cin >> N >> M;

    if(2 * N <=  M){
        ans += N;
        M -= 2 * N;
        ans += floor(M / 4.0);
    }else{
        ans += floor(M /2.0);
    }

    cout << ans << endl;




    
}

Measured memory_bytes: 3688
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

string S; int pre[500009], n, dp[500009];

int main() {
	cin >> n >> S;
	pre[n] = n;
	for (int i = n - 1; i >= 0; i--) {
		if (S[i] == '1')pre[i] = pre[i + 1];
		else pre[i] = i;
	}
	for (int i = 0; i < n - 2; i++) {
		dp[i + 1] = max(dp[i + 1], dp[i]);
		if (S[i] == '0') continue;
		if (S[i + 1] == '1') {
			int to = pre[i];
			if (to + 1 >= S.size() || S[to + 1] == '0') continue;
			dp[to + 2] = max(dp[to + 2], dp[i] + (to - i));
		}
		else {
			if (S[i + 2] == '0') continue;
			dp[i + 3] = max(dp[i + 3], dp[i] + 1);
			int to = pre[i + 2];
			dp[to] = max(dp[to], dp[i] + (to - i - 2));
			if (to - i - 3 >= 1) dp[to - 1] = max(dp[to - 1], dp[i] + (to - i - 3));
		}
	}
	int ret = 0;
	for (int i = 0; i <= n; i++) ret = max(ret, dp[i]);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

const int MAX_N = 7 + 100;
///----------------------------------------------
int dig[MAX_N];
int main() {

	///read
	int n; cin>>n;
	rep(i,0,n) scanf("%d",&dig[i]);

	///work
	int ans=10000000;
	rep(i,-100,101) {
		int tmp=0;
		rep(j,0,n) tmp+=(dig[j]-i)*(dig[j]-i);
		ans=min(ans,tmp);
	}

	///print
	cout << ans;
	


}


Measured memory_bytes: 256
A, B, C = map(int, input().split())

if A==B==C:
    if A%2==0:
        print(-1)
    else:
        print(0)

else:
    for i in range(1000000000):
        if A %2==0 and B%2==0 and C%2==0:
            a = A/2
            b = B/2
            c = C/2
            A = b+c
            B = a+c
            C = a+b
        else:
            print(i)
            exit()



Measured memory_bytes: 3060
import java.util.*;

public class Main{
  static int H, W;
  static char[][] field;
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    int N = sc.nextInt();
    Set<String> set = new HashSet<>();
    for(int i = 1; i <= N; i++){
      for(int j = 0; j < S.length()-i+1; j++){
        set.add(S.substring(j,j+i));
      }
    }
    List<String> list = new ArrayList<>(set);
    Collections.sort(list);
    System.out.println(list.get(N-1));
  }
}
      

Measured memory_bytes: 24524
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    string s; cin >> s;
    if(s == "SSS"){
        cout << 0 << endl;
    }else if(s == "SSR"){
cout << 1 << endl;
    }else if(s == "SRS"){
cout << 1 << endl;
    }else if(s == "SRR"){
cout << 2 << endl;
    }else if(s == "RSS"){
cout << 1 << endl;
    }else if(s == "RSR"){
cout << 1 << endl;
    }else if(s == "RRS"){
cout << 2 << endl;
    }else if(s == "RRR"){
cout << 3 << endl;
    }
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        int A = in.nextInt(), B = in.nextInt(), C = in.nextInt();
        long AB = (C % 2 > 0) ? (long) A * B : 0;
        long BC = (A % 2 > 0) ? (long) B * C : 0;
        long CA = (B % 2 > 0) ? (long) C * A : 0;
        long ans = Math.min(AB, Math.min(BC, CA));
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll INF = 1ll << 60;

ll getmin(const vector<ll>& a, ll x) {
  int A = a.size();
  int right = distance(a.begin(), lower_bound(a.begin(), a.end(), x));
  int left = right - 1;
  ll res = INF;
  if (right < A) chmin(res, a[right] - x);
  if (left >= 0) chmin(res, x - a[left]);
  return res;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int A, B, Q;
  while (cin >> A >> B >> Q) {
    vector<ll> a(A), b(B);
    for (int i = 0; i < A; i++) cin >> a[i];
    for (int i = 0; i < B; i++) cin >> b[i];
    for (int q = 0; q < Q; q++) {
      ll x;
      cin >> x;
      int rightA = distance(a.begin(), lower_bound(a.begin(), a.end(), x));
      int leftA = rightA - 1;
      int rightB = distance(b.begin(), lower_bound(b.begin(), b.end(), x));
      int leftB = rightB - 1;
      ll res = INF;
      if (rightA < A) chmin(res, getmin(b, a[rightA]) + a[rightA] - x);
      if (leftA >= 0) chmin(res, getmin(b, a[leftA]) + x - a[leftA]);
      if (rightB < B) chmin(res, getmin(a, b[rightB]) + b[rightB] - x);
      if (leftB >= 0) chmin(res, getmin(a, b[leftB]) + x - b[leftB]);
      cout << res << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 500010
#define SQ 750
using namespace std;
ll n,q,col[N],num[N],ans[N];
vector<pair<pair<ll,ll>,ll> > qu;
bool cmp(pair<pair<ll,ll>,ll> a,pair<pair<ll,ll>,ll> b)
{
	if(a.F.F/SQ<b.F.F/SQ)
	{
		return true;
	}
	if(a.F.F/SQ>b.F.F/SQ)
	{
		return false;
	}
	if(a.F.S<b.F.S)
	{
		return true;
	}
	return false;
}
int main(){
	ll i,l,r,x=0;
	scanf("%lld%lld",&n,&q);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&col[i]);
		col[i]--;
	}
	for(i=0;i<q;i++)
	{
		scanf("%lld%lld",&l,&r);
		l--;
		qu.push_back(make_pair(make_pair(l,r),i));
	}
	sort(qu.begin(),qu.end(),cmp);
	l=r=0;
	for(i=0;i<qu.size();i++)
	{
		while(l>qu[i].F.F)
		{
			l--;
			num[col[l]]++;
			if(num[col[l]]==1)
			{
				x++;
			}
		}
		while(l<qu[i].F.F)
		{
			num[col[l]]--;
			if(num[col[l]]==0)
			{
				x--;
			}
			l++;
		}
		while(r>qu[i].F.S)
		{
			r--;
			num[col[r]]--;
			if(num[col[r]]==0)
			{
				x--;
			}
		}
		while(r<qu[i].F.S)
		{
			num[col[r]]++;
			if(num[col[r]]==1)
			{
				x++;
			}
			r++;
		}
		ans[qu[i].S]=x;
	}
	for(i=0;i<q;i++)
	{
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 27304
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


typedef struct Node {
  int key;
  struct Node *right, *left, *parent;
} Node;

Node *root, *NIL;

Node * treeMinimum(Node *x){
  
  while(x->left != NIL){
    x = x->left;
  }
    return x;
}

Node * find(Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key){ 
      u = u->left; 
    }else{
      u = u->right;
    }
  }
  return u;
}


Node * treeSuccessor(Node *x){
  if(x->right != NIL){
    return treeMinimum(x->right);
  }

  Node *y = x->parent;
  while(y !=NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z){
  
  Node *x;
  Node *y;
  


  if(z->left == NIL || z->right == NIL){
    y = z;
  }else{
    y = treeSuccessor(z);
  }

  if(y->left != NIL){
    x = y->left;
  }else{
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL){
    root = x;
  }else{
    if(y == y->parent->left){ 
      y->parent->left = x;
    }else{
      y->parent->right = x;
    }
  }
  
  if(y != z){
    z->key = y->key;
  }

  free(y);

} 

void insert(int k) {
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
     x = x->right;
    }
  }
  
  z->parent = y;
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }

}

void inorder (Node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right); 
}

void preorder(Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

  
int main(void){

  int n, i, x;
  char str[32];
 
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s",str);
    if(str[0] == 'f'){
      scanf("%d", &x);
      struct Node *t = find(root, x);
      if(t != NIL){
         printf("yes\n");
      }else{
         printf("no\n");
      }
    }else if(strcmp(str,"insert") == 0){
      scanf("%d", &x);
      insert(x);
    }else if(strcmp(str,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(strcmp(str,"delete") == 0){
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }

return 0;


}



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

int main(){
    long long A;
    string B;
    cin>>A>>B;
    long long B100 = (B[0]-'0')*100 + (B[2]-'0')*10 + (B[3]-'0');
    cout << A * B100 / 100 << endl;
}

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

typedef long long ll;
const int N(1e5 + 9);
const int mod(1e9 + 7);

int n, m;
ll ans, f[N][2];
int vis[N];
vector <int> a[N];

ll dfs(int u, int color)
{
	vis[u] = 1;
	if (f[u][color]) return f[u][color];
	bool pd = 1;
	ll ans0 = 1, ans1 = 1;
	for (int i = 0; i < a[u].size(); i++)
	{
		int v = a[u][i];
		if (vis[v]) continue;
		pd = 0;
		ans0 *= dfs(v, 0) + dfs(v, 1);
		ans0 %= mod;
		ans1 *= dfs(v, 0);
		ans1 %= mod;
	}
	f[u][0] = ans0;
	f[u][1] = ans1;
	return f[u][color];
}
int main()
{
	cin>>n;
	for (int i = 1; i < n; i++)
	{
		int u, v;
		cin>>u>>v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	dfs(1, 0);
	ans += f[1][0] + f[1][1];
	ans %= mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 16000
#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 lli long long int
    #define fr(i,a,b) for(lli i=a;i<b;i++)
    #define bfr(i,a,b) for(lli i=a;i>=b;i--)
    #define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
    #define tc int t;cin>>t;while(t--)
    #define mod 1000000007LL
    #define mod2 998244353LL
    #define all(vec) vec.begin(),vec.end()  
    #define ld long double
    #define pb push_back

    #define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 


    int main()
    {
                           
             

          
                        
              fio

             lli n,m;
             cin>>n>>m;
             lli a[n],sum=0;
             fr(i,0,n){cin>>a[i];sum+=a[i];}
             sort(a,a+n,greater<lli>());
            // cout<<m<<'\n';
             fr(i,0,m)
             if(a[i]*4*m<sum){cout<<"No";return 0;}
             cout<<"Yes";




              
              
return 0;}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int K = Integer.parseInt(scanner.next());
        char[] S = scanner.next().toCharArray();
        scanner.close();

        S[K - 1] = String.valueOf(S[K-1]).toLowerCase().charAt(0);

        System.out.println(String.valueOf(S));
    }
}


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

int main(){
    
    int H,W;
    
    while(1){
        cin>>H>>W;
        if (H==0&&W==0) break;
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if (i==0||i==H-1||j==0||j==W-1){
                    cout<<"#";
                }else{
                    cout<<".";
                }
            }
            cout<<"\n";
        }
        cout<<endl;
    }
    return 0;
}


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

const int64_t maxDist = (int64_t)1000 * 1000 * 1000 * 1000;
const int maxRefill = 400;

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

  vector<vector <int64_t>> dist(n, vector<int64_t>(n, maxDist));
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    dist[a - 1][b - 1] = c;
    dist[b - 1][a - 1] = c;
  }

  for (int i = 0; i < n; i++)
    dist[i][i] = 0;

  int queries; cin >> queries;
  vector<pair <int, int>> q(queries);
  for (int i = 0; i < queries; i++)
    cin >> q[i].first >> q[i].second;

  //we find out the minimum distance between every pair of towns
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
  }

  //we mark each pair of cities that we can reach with one tank
  vector<vector <int>> refill(n, vector<int>(n, maxRefill));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dist[i][j] <= l)
        refill[i][j] = 1;
      if (i == j)
        refill[i][j] = 0;
    }
  }

  //we see how many cities we can reach with the minimum numbers of refills
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++)
        refill[i][j] = min(refill[i][j], refill[i][k] + refill[k][j]);
    }
  }

  //we mark the cities that are unreachable with our tank capacity
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (refill[i][j] == maxRefill) {
        refill[i][j] = -1;
      }
    }
  }

  //we start with the tank full, so we substract 1 from the answer
  for (int i = 0; i < queries; i++) {
    int count = refill[q[i].first - 1][q[i].second - 1];
    if (count > 0)
      count -= 1;
    cout << count << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define space putchar(' ')
#define endl putchar('\n')
#define debug puts("------------------------")
#define F(i,x,n) for(int i=x;i<=n;++i)
#define F_(i,x,n) for(int i=x;i>=n;--i)
using namespace std;
inline void read(int &a) {a=0;int c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b; }
inline int  Rem() {int a=0,c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*=b; }
inline void write(int x) {if(x>9)write(x/10);putchar('0'+x%10);}
inline void W(int x) {if(x<0){putchar('-'),x=-x;}write(x);}
/**/
const int N=1e5+5;
int n,ans;
char c[N];
/**/
int main()
{
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    read(n);scanf("%s",c+1);
    for(int i=1;i<=n;i++)
    {
        if(c[i]!=c[i-1]) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 384
import math

def order(A, B):
    ord_A = int(math.log10(A) + 1)
    ord_B = int(math.log10(B) + 1)
    return max(ord_A, ord_B)

def solve():
    N = int(input())
    d = 10**12
    i = 1
    while i**2 <= N:
        if N % i == 0:
            d = min(d, order(i, N//i))
        i += 1
        
    print(d)
    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main() {
    string s;
    int n;
    cin >>n >>s;
    if(n%2) {
        cout <<"No" << endl;
        return 0;
    }
    for(int i=0; i<n/2; i++) {
        if(s[i] != s[i+(n/2)]) {cout <<"No" <<endl; return 0;}
    }
    cout <<"Yes" <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        long sum = IntStream.range(0, N).mapToLong(i -> Integer.parseInt(sc.next())).sum();
        out.println(sum - N);
        
        out.flush();
    }
}

Measured memory_bytes: 30544
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int S(char p,string s){
  int cnt = 0;
  while(1){
    bool ok = true;
    rep(i,(int)s.size() - 1)if(s[i] != s[i + 1])ok = false;
    if(ok)break;
    string tmp;
    rep(i,(int)s.size() - 1){
      if(s[i] == p || s[i + 1] == p)tmp.push_back(p);
      else tmp.push_back(s[i]);
    }
    s = tmp;
    cnt++;
  }
  return cnt;
}
int main(){
  string s;
  cin >> s;
  int ans = INF;
  rep(i,26){
    char p = 'a' + i;
    ans = min(ans,S(p,s));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.util.function.*;

class Main {
    static Scanner scanner = new Scanner();
    static int mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = scanner.nextInt() + scanner.nextInt() + scanner.nextInt();
        System.out.println(n >= 22 ? "bust" : "win");
    }

    public static void main(String[]$) {
        try {
            new Main().solve();
            System.out.flush();
        } catch (Throwable t) {
            System.out.flush();
            t.printStackTrace();
        }
    }
}

class System {
    static PrintWriter out = new PrintWriter(java.lang.System.out);

    static void exit() {
        java.lang.System.exit(0);
    }
}

class Scanner {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}


Measured memory_bytes: 21332
import java.util.Scanner;

public class Main{

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

	private Scanner scan;

	private void mainrun() {
		scan = new Scanner(System.in);

		for(int N = scan.nextInt();N != 0;N = scan.nextInt()) {
			looprun(N);
		}

	}

	private void looprun(int N) {
		int Ans = Integer.MIN_VALUE;
		int max = 0;

		for(int i = 0;i < N ;i++) {
			int a = scan.nextInt();

			max = Math.max(max + a,a);
			Ans = Math.max(max, Ans);
		}

		System.out.println(Ans);
	}
}


Measured memory_bytes: 34740
#include <stdio.h>

int binarysearch(int right, int s[], int key){
    int left = 0;
    int mid;
	while(left<right){
        mid = (left + right) / 2;
        if(s[mid] == key){
            return 1;
        }else if( key < s[mid]){
            right = mid;
        }else{
            left = mid + 1;
    	}
    }
	return 0;
}

int main(void){
    int rt, lt = 0;
    int key, mid;
    int n, q, count=0;
    int i,j;
	int t[100001];
	int s[100001];
	scanf("%d", &n);
    for (i=0; i<n; i++){
    	scanf("%d", &s[i]);
    }
	scanf("%d", &q);
    for (i=0; i<q; i++){
    	scanf("%d", &t[i]);
    }
    for(i=0; i<q;i++){
    	if (binarysearch(n, s, t[i])){
    		count++;
    	}
    }
	printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 2372
#include<bits/stdc++.h>
using namespace std;
#define Min(i,j,k) min(i,min(j,k))
int dp[1005][1005];
string s1,s2;
signed main(void){
    cin>>s1>>s2;
    memset(dp,0x3f,sizeof(dp));
    for(int i=0;i<s1.length();i++)
        dp[i][0]=i;
    for(int i=0;i<s2.length();i++)
        dp[0][i]=i;
    for(int i=1;i<=s1.length();i++)
        for(int j=1;j<=s2.length();j++){
            if(s1[i-1]==s2[j-1])
                dp[i][j]=Min(dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]);
            else
                dp[i][j]=Min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])+1;
        }
    cout<<dp[s1.length()][s2.length()]<<endl;
    return 0;
} 

Measured memory_bytes: 7152
#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 2000+10;

int dp[maxn][maxn];

int32_t main(){
	fast_io;
	int s;
	cin >> s;
	if(s < 3) pret(0);
	fo(i, 3, maxn - 1) dp[1][i] = 1;
	int ans = 1;
	fo(i, 1, s) dp[1][i] += dp[1][i - 1];
	fo(i, 2, s){
		fo(j, 3, s){
			dp[i][j] = dp[i - 1][j - 3];
		}
		ans = (ans + dp[i][s]) % MOD;
		fo(j, 1, s){
			dp[i][j] += dp[i][j - 1];
			dp[i][j] %= MOD;
		}
	}
	show(ans);
	return 0;
}

Measured memory_bytes: 35016
#include <iostream>
#include <set>
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    
    ll place[N + 1];
    
    for (int i = 1; i <= N; ++i) {
        ll a;
        cin >> a;
        place[a] = i;
    }

    ll ans = 0;
    set<ll> used = {0, N + 1};
    
    for (int i = 1; i <= N; ++i) {
        ll r, l;
        
        auto itr = used.lower_bound(place[i]);
        r = *itr;
        l = *(--itr);
        ans += i * (place[i] - l) * (r - place[i]);
        used.insert(place[i]);
    }

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

Measured memory_bytes: 11136
#include <iostream>

using namespace std;

int main(void) {
  int n, x;
  while(cin >> n >> x && (n || x)) {
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
      for(int j = 1; j <= n; j++) {
        for(int k = 1; k <= n; k++) {
          if(i < j && j < k && i + j + k == x) {
            cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int, int> ii;

const int mod = 1e9 + 7;
const ll INF = (1LL<<50);
const double EPSILON = 0.001;
const int N = 200005;
int see[N];
int main(){
	fastio;
	ll n,k;
	cin >> n >> k;
	vi v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	int atual = 1;
	while(true){
		see[atual]++;
		if(see[atual] == 3)break;
		atual = v[atual-1];
	}
	vi v1, v2;
	atual = 1;
	int aux = 1;
	while(true){
		if(see[atual] == 1)v1.pb(atual);
		else v2.pb(atual);
		atual = v[atual-1];
		if(see[atual] == 3 and !aux)break;
		if(see[atual] == 3)aux = 0;
	}
	for(auto i:v1){
		cerr<< i <<" ";
	}cerr<< endl;
	for(auto i:v2){
		cerr<< i <<" ";
	}cerr<< endl;
	if(k < (ll)sz(v1)){
		cout << v1[(k%((ll)sz(v1)))] << '\n';
	}else{
		k -= (ll)sz(v1);
		cout << v2[(k%((ll)sz(v2)))] << '\n';
	}
	return 0;
}


Measured memory_bytes: 6708
def war(d,N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d



def main():
    H, W = map(int, input().split())

    c = [list(map(int, input().split())) for i in range(10)]

    c = war(c,10)

    A = [list(map(int, input().split())) for i in range(H)]
    ans = 0

    for i in range(H):
        for j in range(W):
            if A[i][j] == -1 or A[i][j] == 1:
                continue
            else:
                ans += c[A[i][j]][1]

    print(ans)


main()

Measured memory_bytes: 40668
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

ll dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    ll n, m;
    cin>>n>>m;
    map<int, int> mp;
    f(i, m){
        int u;
        cin>>u;
        mp[u]++;
    }
    dp[0] = 1;
    for(int i = 1; i <= n; i++) {
        dp[i] = dp[i - 1];
        if(i > 1) dp[i] = add(dp[i - 2], dp[i]);
        if(mp.find(i) != mp.end()) dp[i] = 0;
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 5760
# @author 

import sys

class JSushi:
    def solve(self):
        n = int(input())
        a = [int(_) for _ in input().split()]

        u, v, w = a.count(1), a.count(2), a.count(3)

        dp = [[[0] * (n + 2) for _ in range(n + 2)] for _ in range(n + 2)]
        for k in range(n + 1):
            for j in range(n + 1 - k):
                for i in range(n + 1 - j - k):
                    if i == j == k == 0:
                        continue
                    s = i + j + k
                    x = 0
                    x += dp[i][j + 1][k - 1] * k
                    x += dp[i + 1][j - 1][k] * j
                    x += dp[i - 1][j][k] * i
                    x += n
                    x /= s
                    dp[i][j][k] = x

        print(dp[u][v][w])


solver = JSushi()
input = sys.stdin.readline

solver.solve()


Measured memory_bytes: 608904
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("\\s");
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
	    
		if(0 <= x + r  && x + r <= W && 0 <= y + r && y + r <= H && 0 <= x - r && x - r <= W && 0 <= y - r && y - r <= H)
		{
			System.out.println("Yes");
		}else
		{
			System.out.println("No");
		}
		
		}
	}

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

int dp[5][1<<15 + 1];
int main(){
	dp[0][0] = 1;

	for(int i = 1; i * i <= (1<<15); i++){
		for(int j = 0; j < 4; j++){
			for(int k = i * i; k <= (1<<15); k++){
				dp[j + 1][k] += dp[j][k - i*i];

			}
		}
	}
	

	int N;
	while(cin >> N, N){
		int ans = 0;
		for(int i = 0; i < 5; i++){
			ans += dp[i][N];
		}
		cout << ans << endl;
	}

}

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

using namespace std;

typedef long long ll;

signed main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> b(n);
    for(ll i = 0; i < n; ++i)
        cin >> a[i] >> b[i];
    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, -1));
    dp[0][0] = 0;
    for(ll i = 0; i < n; ++i){
        for(ll j = 0; j <= m; ++j){
            if(dp[i][j] == -1)
                continue;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if(j + a[i] <= m)
                dp[i + 1][j + a[i]] = max(dp[i + 1][j + a[i]], dp[i][j] + b[i]);
        }
    }
    cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
}


Measured memory_bytes: 80256
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    public static long mod = (long) (1e9+7);
    public final static int MAX = (int) 90000000;
  // static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
	 int n = sc.nextInt();
	 long sum = 0;
	 while(n>0) {
		 sum+=n%10;
		 n/=10;
	 }
	 if(sum == 1) sum = 10;
	 out.print(sum);
	 
	 
	
	 out.close();
		
	}
	
}

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

int main(){
    long long ans = 0;
    int n;
    cin >> n;
    
    long long prev = 0, next;
    for (int i = 0; i < n; i++) {
        cin >> next;
        if (prev > next) ans += (prev - next);
        prev = max(prev, next);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3596
#create date: 2020-04-04 21:11

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    print(min(n%k, k-(n%k)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060