akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        var cin = new Scanner(System.in);
        var cout = new OutputWriter(System.out);
        int n = cin.nextInt();
        long ans = 0;
        for(int i = 1;i <=n;i++){
            if(i%3!=0 && i%5!=0){
                ans += i;
            }
        }
        cout.print(ans+"\n");
        cout.close();
    }
}


class Scanner{
    public BufferedReader reader;
    public StringTokenizer st;

    public Scanner(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream));
        st = null;
    }

    public String next(){
        while(st == null || !st.hasMoreTokens()){
            try{
                String line  = reader.readLine();
                if(line == null) return null;
                st =  new StringTokenizer(line);
            }catch (Exception e){
                throw (new RuntimeException());
            }
        }
        return st.nextToken();
    }

    public int nextInt(){
        return Integer.parseInt(next());
    }
    public long nextLong(){
        return Long.parseLong(next());
    }
    public double nextDouble(){
        return Double.parseDouble(next());
    }
}

class OutputWriter{
    BufferedWriter writer;

    public OutputWriter(OutputStream stream){
        writer = new BufferedWriter(new OutputStreamWriter(stream));
    }

    public void print(int i) throws IOException {
        writer.write(i);
    }

    public void print(String s) throws IOException {
        writer.write(s);
    }

    public void print(char []c) throws IOException {
        writer.write(c);
    }
    public  void close() throws IOException {
        writer.close();
    }

}

Measured memory_bytes: 36520
X,Y = map(int,input().split())

sa = abs(abs(X)-abs(Y))

if Y>X>0:
    print(sa)
    exit()
elif X>Y>0:
    print(sa+2)
    exit()
elif Y<X<0:
    print(sa + 2)
    exit()
elif X<Y<0:
    print(sa)
    exit()
elif X>0 and Y<0:
    print(sa + 1)
    exit()
elif X<0 and Y>0:
    print(sa + 1)
    exit()
elif X == 0:
    if Y>0:
        print(sa)
        exit()
    else:
        print(sa+1)
        exit()
elif Y == 0:
    if X>0:
        print(sa+1)
        exit()
    else:
        print(sa)
        exit()

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

int main() {
  int A,B;
  cin >> A >> B;

  int ans{};
  for (auto i = A; i <= B; ++i) {
    string str = to_string(i);
    if (equal(ALL(str),rbegin(str))) ++ans;
  }

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


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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    int ans=0;
    for(int i=0; i<3; i++){
        if(s[i]=='R'){
            int count=1;
            for(int j=i+1; j<3; j++){
                if(s[j]=='R'){
                    count++;
                }else{
                    break;
                }
            }
            ans=max(ans,count);
        }
    }   
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#define N 10000

int arrayA[2000001],arrayC[N+1],arrayB[2000001];
int main()
{

  int k,i,j,max=0;
  //int arrayA[2000001],arrayC[N+1],arrayB[2000001];

  scanf("%d",&k);
  for(i = 0 ; i < k ; i++) 
    {
      scanf("%d",&arrayA[i]);
      if(max<arrayA[i])max = arrayA[i];
    }

  


  for(i = 0 ; i <= max ; i++) arrayC[i] = 0;


  for(j = 0 ; j < k ; j++) arrayC[arrayA[j]]++;



  for(i = 1 ; i <= max ; i++)arrayC[i] = arrayC[i] + arrayC[i-1];

  

  for(j = k-1 ; j >= 0 ; j--)
    { 
      arrayB[arrayC[arrayA[j]]]= arrayA[j];
      arrayC[arrayA[j]]--;
      
    }






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

  return 0;
}

Measured memory_bytes: 16268
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

bool check(int A, int B)
{
  for (int C = 1; C <= 3; ++C) {
    if (A * B * C % 2 == 1) return true;
  }
  return false;
}

int main()
{
  int A, B;
  cin >> A >> B;
  cout << (check(A, B) ? "Yes" : "No") << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
  }
  
  int ans = 0;
  
  for (int i = 0; i < n; i++){
    if (v.at(i) > c.at(i)) {
      ans += v.at(i) - c.at(i);
    }
  }
 
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> g(n+1);
    for (int i=0; i<m; i++) {
        int a,b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for (int i=1; i<=n; i++)
        cout << g[i].size() << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a * b % 2 == 0) cout << "Even";
    else cout << "Odd";
}

Measured memory_bytes: 3664
n = int(input())
flag = 0
max_ = 0
for i in range(n):
    d = list(map(int, input().split()))
    if d[0] == d[1]:
        flag += 1
    else:
        flag = 0

    if max_ < flag:
        max_ = flag

if max_ >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
import math

l = []
ans = []
x = int(input())

a = int( (x) ** (1/5) )

for i in range(a - 1000, a + 1000):
    l.append(i)

for i in range(1,len(l)):
    for j in range(len(l)):
        tmp = math.pow(l[j],5) - math.pow(l[i],5)
        if tmp == x:
            print(l[j],l[i])
            break
    else:
        continue
    break


Measured memory_bytes: 9500
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    if(n==k){
        cout<<0<<endl;
    }else if(k==1){
        cout<<0<<endl;
    }else{
        int ans = k-1;
        int diff = n-ans;
        cout<<diff-1<<endl;
    }
    
    return 0;
    
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

map<pair<int,int>,int> mp;
vector<int> cnt(101010);
vector<int> v[101010];
int main(){
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        --x;--y;
        v[x].push_back(y);
        v[y].push_back(x);
        ++cnt[x];
        ++cnt[y];
    }
    rep(i,n)if(i%2)reverse(v[i].begin(),v[i].end());
    rep(i,n){
        if(cnt[i]%2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    rep(_,3){
        int cur=-1;
        rep(i,n){
            if(cnt[i]){
                cur=i;
                if(cur%2==0)break;
            }
        }
        if(cur==-1){
            cout<<"No"<<endl;
            return 0;
        }
        vector<int> used(n);
        int st=cur;
        while(1){
            used[cur]=1;
            for(auto to : v[cur]){
                if(mp[{cur,to}]>=1)continue;
                mp[{cur,to}]=2;
                mp[{to,cur}]=2;
                //--cnt[cur];--cnt[to];
                cur=to;
                break;
            }
            if(used[cur])break;
        }
        rep(i,n)used[i]=false;
        int ok=false;
        while(1){
            if(st==cur)ok=1;
            used[st]=1;
            for(auto to : v[st]){
                if(mp[{st,to}]==1)continue;
                else if(mp[{st,to}]==2){
                    mp[{st,to}]=ok;
                    mp[{to,st}]=ok;
                    cnt[st]-=ok;
                    cnt[to]-=ok;
                    st=to;
                    break;
                }
            }
            if(used[st])break;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 19064
#coding:utf-8
#1_10_B 2015.4.14
import math

a,b,c = list(map(int,input().split()))
S = a * b * math.sin(math.radians(c)) / 2
L = a + b + math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(c)))
h = S * 2 / a
print('{:.10f}\n{:.10f}\n{:.10f}'.format(S,L,h))

Measured memory_bytes: 6868
n, m = raw_input().strip().split(' ')

n = int(n)
m = int(m)

a = [0] * n
b = [0] * m
c = [0] * n
ans = 1
ansv = 0

for i in range(n) :
	a[i] = input()

for i in range(m) :
	b = input()
	for j in range(n) :
		if (a[j] <= b) :
			c[j] += 1;
			if (c[j] > ansv) :
				ansv = c[j]
				ans = j + 1
			break

print ans

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

int main() {
  int N,M;
  string S;
  cin >> S;
  
  N=S.size();
  for(int i=0;i<N/2;i++){
    if(S.at(i) == S.at(N-1-i)) continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  
  M=(N-1)/2;
  for(int i=0;i<M/2;i++){
    if(S.at(i) == S.at(M-1-i)) continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  
  for(int i=0;i<((N-(N+3)/2)/2);i++){
    if(S.at(((N+3)/2)-1+i) == S.at(N-1-i)) continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

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

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m; cin >> n >> m;
  vector<vi> s(m);
  rep(i, m) {
    int k; cin >> k;

    rep(j, k) {
      int x; cin >> x;
      s[i].eb(x-1);
    }
  }

  vi p(m);
  rep(i, m) cin >> p[i];
  int ans = 0;

  rep(bit, 1<<n) {
    bool ok = true;
    rep(i, m) {
      int sum = 0;
      rep(j, si(s[i])) if (bit & (1<<s[i][j])) ++sum;

      if (sum % 2 != p[i]) ok = false;
    }

    if (ok) ++ans;
  }

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

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

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b >= c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int x[5],y[5];
    cin >> x[1] >> y[1] >> x[2] >> y[2];
    int dx = x[2] - x[1];
    int dy = y[2] - y[1];
    int ddx = abs(dx);
    int ddy = abs(dy);
    if(dx >= 0){
        //(+,+)
        if(dy >= 0){
            swap(ddx, ddy);
            x[3] = x[2] - ddx;
            y[3] = y[2] + ddy;
            swap(ddx, ddy);
            x[4] = x[3] - ddx;
            y[4] = y[3] - ddy;
        }
        //(+,-)
        else{
            swap(ddx, ddy);
            x[3] = x[2] + ddx;
            y[3] = y[2] + ddy;
            swap(ddx, ddy);
            x[4] = x[3] - ddx;
            y[4] = y[3] + ddy;
        }
    }
    else{
        //(-,+)
        if(dy >= 0){
            swap(ddx, ddy);
            x[3] = x[2] - ddx;
            y[3] = y[2] - ddy;
            swap(ddx, ddy);
            x[4] = x[3] + ddx;
            y[4] = y[3] - ddy;

        }
        //(-,-)
        else{
            swap(ddx, ddy);
            x[3] = x[2] + ddx;
            y[3] = y[2] - ddy;
            swap(ddx, ddy);
            x[4] = x[3] + ddx;
            y[4] = y[3] + ddy;
        }
    }
    cout << x[3] << " " << y[3] << " " << x[4] << " " << y[4] << endl;
}



Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a,b,c,d;
	scanf("%d" "%d" "%d",&a,&b,&c);
	d = a - (b + c);
	if (d < 0) printf("%d",abs(d));
	else
	{
		printf("%d",0);
		/* code */
	}
	
	

}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 int main() {
	 int A, B;
	 cin >> A >> B;
	 int ans = 0;
	 for (int i = A; i <= B; i++) {
		 string s = to_string(i);
		 string t = s;
		 reverse(t.begin(), t.end());
		 if (s == t) ans++;
	 }
	 cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  int n;
  cin >> n;

  vector<int> a(n), b(n);
  for (auto &x : a) cin >> x;
  for (auto &x : b) cin >> x;

  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    c[i] = b[i] - a[i];
  }

  long long inc = 0;
  for (int i = 0; i < n; ++i) {
    if (c[i] < 0) {
      inc += abs(c[i]);
    } else {
      inc -= abs(c[i]) / 2;
    }
  }

  if (inc > 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}


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

using namespace std;

int main() {
    int ans = 1;
    long long int n, p;

    cin >> n >> p;

    if (n == 1)  {
        cout << p << endl;
        return 0;
    }

    long long int tmp;
    int cont;
    for (int i=2; i<=sqrt(p)+1; i++) {
        tmp = p;
        cont = 0;
        while (tmp%i == 0) {
            cont++;
            tmp = tmp/i;
        }
        if (cont >= n) ans = i;//i * (cont/n);
    }

    cout << ans << endl;

    return 0;
}

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



Measured memory_bytes: 2052
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	string N,H;
	cin >> N>>H;
	if (N == H)
		cout << 'H' << endl;
	else
		cout << 'D' << endl;
	return 0;
}



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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int r; cin >> r;
  if(r < 1200) cout << "ABC" << endl;
  else if(r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}

Measured memory_bytes: 3584
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n,c=0;
    cin>>n;
    vi a(n);
    FOR(i,0,n){
        cin>>a[i];
        if(((i&1)==0)&&((a[i]&1)==1)){
            c++;
        }
    }
    cout<<c<<endl;

}


Measured memory_bytes: 3564
#include <stdio.h>

int main()
{
    int N;
    scanf("%d\n", &N);
    double x;
    char u[5];
    
    double sum = 0;
    for(int i = 0; i < N; i++){
        scanf("%lf %s\n", &x, u);
        if(u[0] == 'J' && u[1] == 'P' && u[2] == 'Y'){
            sum += x;
        }
        else if(u[0] == 'B' && u[1] == 'T' && u[2] == 'C'){
            sum += x * 380000.0;
        }
        else{
           (void)0; //NO STATEMENT
        }
    }
    printf("%.8f",sum);
    return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	L := nextInt()
	R := nextInt()
	mod := 2019

	from := L % mod
	len := min(R, L+mod-1) - L + 1
	m := mod

	for i := 0; i < len-1; i++ {
		l := (from + i) % mod
		for j := i + 1; j < len; j++ {
			r := (from + j) % mod
			v := (l * r) % mod

			if v < m {
				m = v
			}
			if v == 0 {
				break
			}
		}
	}

	fmt.Println(m)
}

var stdin = initStdin()

func min(n, m int) int {
	if n < m {
		return n
	}
	return m
}

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define pii pair < int, int >
typedef vector<int> vi;
typedef   long long ll;
const int mod =1e9+7;




void solve(){
	ll a;
	long double b;
	cin>>a>>b;
	ll x=a*b*1ll;
	cout<<x;
}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 3748
N, K = map(int,input().split())
h = list(map(int,input().split()))

INF = 10e9
dp=[INF]*N
dp[0]=0

for i in range (0,N):
    for j in range(i+1, min(N,i+K+1)):
        dp[j] = min(abs(h[i]-h[j])+dp[i],dp[j])

print(dp[N-1])


Measured memory_bytes: 55264
def rec(pos, used, s):
    if pos == n:
        print(s)
        return
    for i in range(used):
        rec(pos + 1, used, s + chr(ord('a') + i))
    rec(pos + 1, used + 1, s + chr(ord('a') + used))

n = int(input())
rec(0, 0, "")

Measured memory_bytes: 57816
#include<bits/stdc++.h>
using namespace std;
#define ld float
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1) 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second
#define all(a) a.begin(),a.end()
#define rev(a) reverse(all(a))
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mod 998244353
#define inf 2000000000
#define limit 200005
#define minval -100000000000000000
#define maxval 1000000000000000
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,int exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}

void solve(int test_case)
{
    lli n, x, m;
    cin >> n >> x >> m;

    lli i = 1, tmp = x;
    vlli a;
    vlli fre(m, 0);
    while(i < 50000000)
    {
        if(fre[tmp] == 1)
            break;
        fre[tmp]++;
        a.pb(tmp);
        tmp = (tmp * tmp)%m;
        i++;
    }

    i = 0;
    lli ans = 0;
    while(a[i] != tmp)
    {
        ans += a[i];
        i++;
    }
    
    lli s = 0;
    loop(j,i,(int)a.size(),1)
        s += a[j];
    
    i++;
    lli l = (int)a.size()-i+1;
    lli k = (n-i)/l;
    ans += s * k;

    lli cnt = n - (i + k * l) + 1;
    loop(j,i-1,i-1+cnt,1)
        ans += a[j];
    cout << ans << '\n';
}

int main()
{
   /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
   */
    fastio();
    int q = 1;
    //cin >> q;
    rep(i,q)
        solve(i+1);
}


Measured memory_bytes: 4632
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
H = LIST()
I = []

if N == 1:
  print(0)
  exit()
  
i = 0
 
while i < N :
  c = 0
  j = 0
  while j < N-i-1 and H[i+j] >= H[i+j+1] :
    c += 1
    j += 1
    
  I.append(c)
  i += c+1
  
print(int(max(I)))

Measured memory_bytes: 16312
n,m=map(int, input().split())

oks = [True]*(n+1)
for _ in range(m):
    broken = int(input())
    oks[broken] = False

dp = [0]*(n+2)
dp[1] = 1

for i in range(1, n+1):
    if oks[i]:
        dp[i+1] = dp[i-1] + dp[i]
    else:
        dp[i+1] = 0


mod = 10**9+7
print(dp[n+1]%mod)



Measured memory_bytes: 460788
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

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

#define fs first
#define sc second

int main(){
    int N;
    cin >> N;
    int a[1000100];
    for(int i = 0; i < N; i++){
        int x;  cin >> x;
        a[i] = x;
    }

    int res = 0;
    for(int i = 1; i < N; i++){
        if(a[i-1] == a[i]){
            res++;
            a[i] = -1;
        }

    }

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
// const int N = 100005;

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);

    int n,m;
    cin >> n >> m;

    vector<int> a(m);
    rep(i,m) cin >> a[i];
    sort(all(a));
    vector<int> gp(m-1);
    repA(i,1,m-1) {
    	gp[i-1] = a[i] - a[i-1]; 
    }

    sort(all(gp));
    
    int ans = 0;
    rep(i,m-n) {
    	ans += gp[i];
    }
    cout << ans << '\n';
}

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {


			//テンプレート
			//// 整数の入力
			//int a = int.Parse(Console.ReadLine());
			//// スペース区切りの整数の入力
			//string[] input = Console.ReadLine().Split(' ');
			//int b = int.Parse(input[0]);
			//int c = int.Parse(input[1]);
			//// 文字列の入力
			//string s = Console.ReadLine();
			////出力
			//Console.WriteLine(a + b + c + " " + s);

			string input = Console.ReadLine();
			char[] input_char = input.ToCharArray();
			var hash = input_char.Distinct().ToArray();

			if (input_char.Length == 4 && hash.Length == 2)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}


        }
    }
}


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

N = int(input())
L = [int(v) for v in input().split()]

m = [{}, {}]
vm = [[(0, 0), (0, 0)], [(0, 0), (0, 0)]]

for i in range(N):
    if m[i % 2].get(L[i]) != None:
        m[i % 2][L[i]] += 1
    else:
        m[i % 2][L[i]] = 1

for i in range(N):
    k = L[i]
    v = m[i % 2][k]
    t1 = vm[i % 2][0]
    t2 = vm[i % 2][1]
    
    if t1[1] < v:
        vm[i % 2][1] = [t1[0], t1[1]]
        vm[i % 2][0] = [k, v]
    elif t2[1] < v and t1[0] != k:
        vm[i % 2][1] = [k, v]
        
f1 = vm[0][0]
f2 = vm[0][1]
s1 = vm[1][0]
s2 = vm[1][1]

p = 0
if f1[0] != s1[0]:
    p = N - f1[1] - s1[1]
else:
    p = N - max([f1[1] + s2[1], f2[1] + s1[1]])
    
print(p)

Measured memory_bytes: 17696
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
char str[310000];
set<int>S;
int segtree[1048576];
int getmin(int a,int b,int c,int d,int e,int f){
	if(d<a||b<c||c>d)return 1000000007;
	if(c<=a&&b<=d)return f+segtree[e];
	return min(getmin(a,(a+b)/2,c,d,e*2,f+segtree[e]),getmin((a+b)/2+1,b,c,d,e*2+1,f+segtree[e]));
}
void add(int a,int b,int c,int d,int e,int f){
	if(c>d)return;
	if(d<a||b<c)return ;
	if(c<=a&&b<=d){
		segtree[e]+=f;
		return;
	}
	add(a,(a+b)/2,c,d,e*2,f);
	add((a+b)/2+1,b,c,d,e*2+1,f);
	if(segtree[e*2]>0&&segtree[e*2+1]>0){
		int val=min(segtree[e*2],segtree[e*2+1]);
		segtree[e]+=val;
		segtree[e*2]-=val;
		segtree[e*2+1]-=val;
	}
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	scanf("%s",str);
	for(int i=0;i<a;i++)if(str[i]==')')S.insert(i);
	int now=0;
	for(int i=0;i<a;i++){
		if(str[i]=='(')now++;
		else now--;
		add(0,524287,i+1,i+1,1,now);
	}
	for(int i=0;i<b;i++){
		int c;scanf("%d",&c);c--;
		if(str[c]=='('){
			S.insert(c);
			str[c]=')';
			int at=*(S.begin());
			printf("%d\n",at+1);
			str[at]='(';
			S.erase(at);
			add(0,524287,at+1,c,1,2);
		}else{
			S.erase(c);
			str[c]='(';
			add(0,524287,c+1,a,1,2);
			int L=-1;
			int R=c;
			while(L+1<R){
				int M=(L+R)/2;
				int val=getmin(0,524287,M+1,c+1,1,0);
				if(val>=2)R=M;
				else L=M;
			}
			printf("%d\n",R+1);
			str[R]=')';
			S.insert(R);
			add(0,524287,R+1,a,1,-2);
		}
	}
	
}

Measured memory_bytes: 11600
# B
n = int(input())

a = list(map(int,input().split()))

  

  

maxa = 10 **18

ans = 1
if min(a) == 0:
  ans = 0

for i in a:
  ans = ans * i
  if ans > maxa:
    print(-1)
    break
else:
  print(ans)


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

using namespace std ; 

const int N =1e6 + 7 ; 

int n , k ;  
long long C ; 


typedef long long LL;

#define MAXLC 1000000000
#define INF (1LL<<60)

inline LL f(LL m, LL b, int x) {
        return m * x + b;
}

struct lc_node {
        LL m = 0, b = INF;
        lc_node *l = nullptr, *r = nullptr;

        ~lc_node() { delete l; delete r; }

        void add_line(LL nm, LL nb, int lo=-MAXLC, int hi=MAXLC) {
                int mid = (lo + hi) / 2;
                bool bl = f(nm, nb, lo) < f(m, b, lo);
                bool bm = f(nm, nb, mid) < f(m, b, mid);
                bool bh = f(nm, nb, hi) < f(m, b, hi);
                if (bm) {
                        swap(nm, m);
                        swap(nb, b);
                }
                if (lo == hi || nb == INF)
                        return;
                else if (bl != bm) {
                        if (!l) l = new lc_node;
                        l->add_line(nm, nb, lo, mid - 1);
                }
                else if (bh != bm) {
                        if (!r) r = new lc_node;
                        r->add_line(nm, nb, mid + 1, hi);
                }
        }

        LL get(int x, int lo=-MAXLC, int hi=MAXLC) {
                int mid = (lo + hi) / 2;
                LL ret = f(m, b, x);
                if (l && x < mid)
                        ret = min(ret, l->get(x, lo, mid - 1));
                if (r && x > mid)
                        ret = min(ret, r->get(x, mid + 1, hi));
                return ret;
        }

        void clear() {
                delete l; delete r;
                m = 0, b = INF, l = nullptr, r = nullptr;
        }

} lc;

long long dp[N] ;

int main(){

        ios_base::sync_with_stdio(0) ; 
        cin.tie(0) ; 
        //freopen("in.in" , "r" ,stdin) ; 

        cin >> n >> C ;
        lc.clear() ;
        for(int i = 0 ;i < n;i++){
                long long x ; 
                cin>> x ; 

                if(i){
                        dp[i] = 1LL * x * x + lc.get(x)  + C ; 
                }

                lc.add_line( -2LL * x, dp[i] + x * x ) ; 
        }

        cout<< dp[n-1] ; 
        return 0; 
}


Measured memory_bytes: 14612
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
  string s;
  cin >>s;
  if(s=="AKIHABARA"){
    cout <<"YES"<<endl;
    return 0;
  }
  if(s.find("KIH")==string::npos||s.find("AA")!=string::npos) {
    cout<<"NO"<<endl;
    return 0;
  }
  ll ss=s.size();
  if(ss>=9){
    cout<<"NO"<<endl;
    return 0;
  }
  else{
    string t;
    for(ll i=0;i<ss;i++){
      if(s[i]!='A'&&s[i]!='K'&&s[i]!='I'&&s[i]!='H'&&s[i]!='B'&&s[i]!='R'){
        cout<<"NO"<<endl;
        return 0;
      }
      if(s[i]!='A') t+=s[i];
    }
    if(t!="KIHBR"){
        cout <<"NO"<<endl;
        return 0;
      }
      cout <<"YES"<<endl;
  }
}


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

int main(){
	int n;cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	sort(v.begin(), v.end());
	int mid=v.size()/2;
	int ans=v[mid]-v[mid-1];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)

using ll = int64_t;
using ld = long double;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

constexpr ll inf = 2e18;
constexpr int M = 1e9 + 7;

const int N = 310;
ld dp[N][N][N];

int n;
ld E(int i, int j, int k) {
	if (i < 0 || j < 0 || k < 0) return 0;
	auto &x = dp[i][j][k];
	if (x == -1) {
		ld s = i + j + k;
		x = n / s;
		x += i * E(i - 1, j, k) / s;
		x += j * E(i + 1, j - 1, k) / s;
		x += k * E(i, j + 1, k - 1) / s;
	}
	return x;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n;
	int cnt[3] = {0, 0, 0};
	rep(i, 0, n) { int a; cin >> a; --a; ++cnt[a]; }
	rep(i, 0, n + 1) rep(j, 0, n + 1) rep(k, 0, n + 1) dp[i][j][k] = -1;
	dp[0][0][0] = 0;
	cout << fixed << setprecision(18) << E(cnt[0], cnt[1], cnt[2]);
}

Measured memory_bytes: 452864
//#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int car[100];
  int n,i=0;
  while(cin>>n){
    if(n==0){
      cout<<car[i]<<endl; i--;
    }
    else {
      i++; car[i]=n;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){

//	vector<int> a(n);

  int n,cnt=0,tmp;

  cin >> n;

  for(int i=1;i<n;i++){
    for(int j=i;j<n;j++){
      tmp = n - i*j;
      if(tmp > 0){
        if(i == j){
          cnt = cnt + 1;
        }else{
          cnt = cnt + 2;
        }
      }
      if(i*j >= n){
        break;
      }
    }
  } 

  cout << cnt << endl; 

}

Measured memory_bytes: 3632
N, C = map(int, input().split())
X = []
V = []
for _ in range(N):
  x, v = map(int, input().split())
  X.append(x)
  V.append(v)

A = [0] * (N + 1)
A_max = [0] * (N + 1)
B = [0] * (N + 1)
B_max = [0] * (N + 1)
a_sum = 0
b_sum = 0
for i in range(N):
  a_sum += V[i]
  A[i + 1] = a_sum - X[i]
  A_max[i + 1] = max(A_max[i], A[i + 1])
  b_sum += V[- i - 1]
  B[i + 1] = b_sum - (C - X[- i - 1])
  B_max[i + 1] = max(B_max[i], B[i + 1])

X = [0] + X
V = [0] + V

m = max(0, A_max[-1], B_max[-1])
for i in range(1, N + 1):
  m = max(m, A[i] + B_max[N - i] - X[i], B[i] + A_max[N - i] - (C - X[N - i + 1]))

print(m)

Measured memory_bytes: 21344
N,K=list(map(int, input().split()))
P=list(map(int, input().split()))
L=[0]*(N+1)
ans=[0]*(N-K+1)
for i in range(N):
  L[i+1]=(P[i]+1)/2 + L[i]
for j in range(N-K+1):
  ans[j]=L[j+K]-L[j]
print(max(ans))

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

int main(){
  int N,candy=0,tmp=0;
  cin>>N;
  vector<int> d0(N);
  vector<int> d1(N);
  for(int i=0;i<N;i++){
    cin>>d0.at(i);
    tmp+=d0.at(i);
  }
  for(int i=0;i<N;i++){
    cin>>d1.at(i);
  }
  tmp+=d1.at(N-1);
  candy=tmp;
  for(int i=0;i<N-1;i++){
    tmp-=d0.at(N-1-i);
    tmp+=d1.at(N-2-i);
    candy=max(candy,tmp);
  }
  cout<<candy<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000+20;
const int INF = 0x3f3f3f3f;
int p[maxn], v[maxn];
int dp[20000+50];
int main()
{
    int n, m;
    while(scanf("%d %d", &m, &n)!=EOF) {
        for(int i = 1; i <= n; i++) {
            scanf("%d %d", &v[i], &p[i]);
        }
        memset(dp, INF, sizeof(dp));
        dp[0] = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = v[i]; j <= 20000; j++) {
                dp[j] = min(dp[j], dp[j-v[i]] + p[i]);
            }
        }

        int maxx = dp[m];
        int ans = m;
        for(int i = m; i <= 10000; i++) {
            if(dp[i] <= maxx) {
                maxx = dp[i];
                ans = i;
            }
        }
        printf("%d\n",maxx);

    }


    return 0;
}



Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    string s,t;
    cin>>s;
    t+=s[0];
    int n=s.size(),sum=0;
    for(int i=1;i<n-1;i++) sum++;
    t+=to_string(sum);
    t+=s[n-1];
    cout<<t;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,k,a[200010],b[200010],l[400010],r[400010],ll[200010],rr[200010];
int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++) cin>>a[i];
	while (k--)
	{
		int p=0;
		for (int i=0;i<=n;i++) 
		{
			b[i]=0;
			ll[i]=0;
			rr[i]=0;
		}
		for (int i=1;i<=n;i++)  
		{
			l[i]=max(0LL,i-a[i]);
			r[i]=min(n+1,i+a[i]+1);
			ll[l[i]]++;
			rr[r[i]]++;
		}	
		for (int i=1;i<=n;i++)
		{
			ll[i]=ll[i-1]+ll[i];
			rr[i]=rr[i-1]+rr[i];
			b[i]=ll[i]-rr[i];
		}	
		for (int i=1;i<=n;i++) if (a[i]!=b[i]) p=233;
		for (int i=1;i<=n;i++) if (a[i]!=b[i]) a[i]=b[i];
		if (p==0)
		{
			for (int i=1;i<=n;i++) printf("%lld ",a[i]);
			return 0;
		}
		//for (int i=1;i<=n;i++) printf("%lld %lld ",ll[i],rr[i]);
		//printf("\n");
		//for (int i=1;i<=n;i++) if (a[i]>hhh||hhh==0) hhh=a[i];
	}
	for (int i=1;i<=n;i++) printf("%lld ",a[i]);
	return 0;
}



Measured memory_bytes: 12976
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(16);

    int n,x;
    cin >> n >> x;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
        cin >> l[i];

    vector<int> csl(n + 1);
    csl[0] = 0;
    for (int i = 0; i < n; i++)
        csl[i + 1] = csl[i] + l[i];

    int count=0;
    for (auto &&csli : csl)
    {
        if(csli<=x)
            count++;
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

const int Mod = 1000003;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long pow_mod(int n, int k)
{
	long long N, ans = 1;
	for (N = n; k > 0; k >>= 1, N = N * N % Mod) if (k & 1) ans = ans * N % Mod;
	return ans;
}

int main()
{
	int q, Q, x, d, n;
	scanf("%d", &Q);

	int i;
	long long fact[1000003], fact_inv[1000003];
	for (i = 1, fact[0] = 1; i < Mod; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = Mod - 2, fact_inv[Mod-1] = div_mod(1, fact[Mod-1], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;

	long long y;
	for (q = 1; q <= Q; q++) {
		scanf("%d %d %d", &x, &d, &n);
		if (d == 0) {
			printf("%lld\n", pow_mod(x, n));
			continue;
		} else if (x == 0) {
			printf("0\n");
			continue;
		}
		
		y = div_mod(x, d, Mod);
		if (y + n > Mod) printf("0\n");
		else printf("%lld\n", fact[y+n-1] * fact_inv[y-1] % Mod * pow_mod(d, n) % Mod);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 17352
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N =sc.nextInt();
    int M[]= new int[N];
    int P[] =new int[N];
    int x=0;
    for(int i=0;i<N;i++){
      M[i]=i+1;
      P[i]=sc.nextInt();
      if(!(M[i]==P[i])){x=x+1;}}
    if(x<=2){System.out.println("YES");}
    else{System.out.println("NO");}
  }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
#include<bitset>
#include<string>
using namespace std;
#include <numeric> 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using pi=pair<long long,long long>;
#define pii 3.1415926536
#define binary
#define mod 1000000007
typedef long long ll;
typedef long double ld;
bool sortbysec(const pair<long long,long long> &a, 
              const pair<long long,long long> &b) 
{ 
    return (a.first < b.first); 
}
bool compare(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll>&b)
{
    if(a.first.first==b.first.first)return (a.first.second<b.first.second);
    return (a.first.first < b.first.first); 
}
 int lcm(int a, int b)  
 {  
    return (a*b)/__gcd(a, b);  
 }  
 int Kad(ll dp[],ll n)
{
  ll curr_max=0,maxx=INT_MIN;
  for(int i=0;i<n;i++)
  {
    curr_max=curr_max+dp[i];
    if(curr_max>maxx)
      maxx=curr_max;

    if(curr_max<0)
      curr_max=0;
   
  }

  return maxx;
}

/*void dfs(int u)
{
    vis[u]=true;
    //cout<<u<<" ";
    std::vector<ll> ::iterator i;
     for (i = g[u].begin(); i != g[u].end(); ++i) 
        if (!vis[*i]) 
            dfs(*i); 
    for(int i=1;i<g[u].size();i++)
    {
        if(!vis[g[u][i]])
        {
            dfs(i);
        }
    }
}*/
/*void build_tree(ll tree[],ll a[],ll start,ll end,ll node)
{
    if(start==end)
    {
        tree[node]=a[start];
        return;
    }
    int mid=(start+end)/2;
    build_tree(tree,a,start,mid,2*node);
    build_tree(tree,a,mid+1,end,2*node+1);
    tree[node]=min(tree[2*node],tree[2*node+1]);
}
ll query_tree(ll tree[],ll a[],ll qs,ll qe,ll start,ll end,ll node)
{
    if(start>=qs && end<=qe)
    {
        return tree[node];
    }
    if(start>qe || end<qs)
        return INT_MAX;
    int mid=(start+end)/2;
    int left_tree=query_tree(tree,a,qs,qe,start,mid,2*node);
    int right_tree=query_tree(tree,a,qs,qe,mid+1,end,2*node+1);

    return min(left_tree,right_tree);
}*/


int main()
{

 #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
  #endif  
  IOS;
 ll n;
 cin>>n;
 ll a[n];
 ll sum=0;
 for (int i = 0; i < n; ++i)
 {
     cin>>a[i];
     sum=(((sum+mod)%mod)+((a[i]+mod)%mod))%mod;
 }
 ll ans=0;
 for(int i=0;i<n;i++)
 {
    sum=(((sum+mod)%mod)-((a[i]+mod)%mod))%mod;
    ans=(((ans+mod)%mod)+((((a[i]+mod)%mod)*((sum+mod)%mod))%mod))%mod;
 }
 cout<<((ans+mod)%mod)<<endl;

}
                                  
   

  

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
 
ll gcd(ll a,ll b){
    if(a%b==0){
        return b;
    }else{
        return gcd(b,a%b);
    }
}
 
bool IsPrime(long long num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
 
    // 素数である
    return true;
}
 
int main(){
    ll A,B,C,total=1;
    cin >> A >> B;
    C=gcd(A,B);
    bool hantei=0;
    
    hantei = IsPrime(C);
    
    if(!hantei){
    for(ll i=2 ; i*i<=C ; i++){
        if(C%i==0){
            total++;
            while(C%i==0) C/=i;
        }
    }
    if(C!=1) total++;
    }
    
    
    if(!hantei) cout << total << endl;
    else if (C==1) puts("1");
    else puts("2");
    return 0;
}

Measured memory_bytes: 384