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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

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

  vvi f(n), b(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    f[--x].pb(--y);
    f[y].pb(x);
  }
  
  rep(i, k) {
    int x, y;
    cin >> x >> y;
    b[--x].pb(--y);
    b[y].pb(x);
  }

  vi cnt(n, -1);
  rep(i, n) {
    if (cnt[i] != -1) continue;

    set<int> curVisit;

    function<void (int)> dfs = [&](int r) {
      curVisit.insert(r);
      for (auto& j : f[r]) {
        if (curVisit.count(j)) continue;

        dfs(j);
      }
    };
    dfs(i);

    for (auto& j : curVisit) {
      cnt[j] = sz(curVisit) - 1;
      
      for (auto& r : f[j]) {
        if (curVisit.count(r)) cnt[j]--;
      }
      
      for (auto& r : b[j]) {
        if (curVisit.count(r)) cnt[j]--;
      }
    }
  }

  rep(i, n) cout << cnt[i] << ' ';

  return 0;
}


Measured memory_bytes: 19468
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <deque>
#include <set>
#include <map>
using namespace std;
typedef long long int lli;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000000
#define IOS ios_base::sync_with_stdio(0); cin.tie(0) //making cin faster
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FOR_R(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define REP_R(i,n)   FOR_R(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SIZ(x) ((int)(x).size())

void insertionSort( vector<int>& , int);

int main(void)
{
  int N;
  scanf("%d\n",&N);
  
  vector<int> A(N);
  REP(i,N)
    {
      if(i != N-1 )
	{
	  scanf("%d ",&A[i]);
	}
      else
	{
	  scanf("%d\n",&A[i]);
	  
	}
    }

  insertionSort(A,N);
  
  
  
  
}

void insertionSort( vector<int>& A , int N )
{
  int v;
  int j;

  REP(i,N)
    {
      if(i != N-1 )
	{
	  printf("%d ",A[i]);
	}
      else
	{
	  printf("%d\n",A[i]);
	  
	}
    }

  FOR(i,1,N)
    {
      v = A[i];
      j = i-1;

      while( j >= 0 and A[j] > v )
	{

	  A[j+1] = A[j];
	  -- j;
	  
	}

      A[j+1] = v;

      REP(i,N)
	{
	  if(i != N-1 )
	    {
	      printf("%d ",A[i]);
	    }
	  else
	    {
	      printf("%d\n",A[i]);
	  
	    }
	}
      
      
      
    }
}



Measured memory_bytes: 3192
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    try:
        s = input('')
    except:
        break

    n_joi = 0
    n_ioi = 0
    for i in range(len(s[:-2])):
        cut_s = s[i:i+3]
        if cut_s == 'JOI':
            n_joi += 1
        if cut_s == 'IOI':
            n_ioi += 1

    print(n_joi)
    print(n_ioi)

Measured memory_bytes: 6748
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {
        
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        
         String[] ab = in.readLine().split(" ");

         int a= Integer.parseInt(ab[0]);
         int b= Integer.parseInt(ab[1]);
         
        System.out.println(a*b +" " + 2*(a+b));
        
	}

}

Measured memory_bytes: 17088
#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define NON -1
typedef pair < int , int > Pi;
typedef pair < Pi , int > Pii;
vector< Pii > memory; //セクタの状態
void write( int l, int sum){ //書き込む
  for(int i = 0; sum > 0 ; i++){
    if(memory[i].sc != NON) continue;
    int kazu = memory[i].fr.sc - memory[i].fr.fr + 1;
    if(kazu <= sum){
      memory[i].sc = l, sum -= kazu;
    }else{
      memory.insert( memory.begin() + i, Pii( Pi( memory[i].fr.fr, memory[i].fr.fr + sum - 1), l));
      memory[++i].fr.fr = memory[i - 1].fr.sc + 1;
      sum = 0;
    }
  }
}
void erase( int idx){ //消す
  for(int i = 0; i < memory.size() ; i++){
    if(memory[i].sc == idx) memory[i].sc = NON;
  }
}
void read( int idx){ //読み込む
  int pos = 0;
  while(memory[pos].fr.sc < idx) pos++;
  cout << memory[pos].sc << endl;
}


int main(){
  int n;
  while(cin >> n, n){
    memory.clear();
    memory.push_back( Pii( Pi( 0, 1000000001), NON));
    while(n--){
      char buff;
      cin >> buff;
      if(buff == 'W'){ //write
        int a, b;
        cin >> a >> b;
        write(a,b);
      }else if(buff == 'D'){ //delete
        int a;
        cin >> a;
        erase(a);
      }else{ //read
        int a;
        cin >> a;
        read(a);
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 1328
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    string s,t;
    cin >> s>> t;
    int a = 0;
    rep(i,0,3)if(s[i] == t[i])a++;
    P(a);
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define eb emplace_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cinarr(A,len) for(int i=0;i<len;i++){cin>>A[i];}
#define coutarr(A,len) for(int i=0;i<len;i++){cout<<A[i]<<' ';}cout<<endl
#define coutin(V) for(auto& i : V){cout << i << ' ';}cout<<endl // for vect and set
#define coutmap(U) for(auto& i : U){cout << i.first << "->" << i.second << ", ";}cout<<endl // for map
#define deb(x) cerr << #x << '\t' << x << endl
const int imax = numeric_limits<int>::max(), imin = numeric_limits<int>::min();
const long long	lmax = numeric_limits<long long>::max(), lmin = numeric_limits<long long>::min();
/*========================================================================*/
/* strategi/note:



/================================*/



bool Svd=0;
void solve(){Svd=1;
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll a = 1; a<=n; a++){
        //cout << a << ' ' << b << ' ' << n-a*b << endl;
        ans += (n/a)-(n%a==0?1:0);
    }
    cout << ans << endl;
}


/*========================================================================*/

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
//cout<<fixed<<setprecision( ); // iomanip **

 solve();
 //int t;cin>>t;while(t--){solve();}

if(!Svd)cout<<"solve() function blm dipanggil!"<<endl;
//cout.flush(); cin.get();
return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    // first and result.
    n-=2;

    int first;
    cin >> first;
    vector<int> V(n);
    for(int i=0;i<n;i++){
        cin >> V[i];
    }
    int result;
    cin >> result;

    vector<ll> O(21);
    O[first] = 1;
    for(int i=0;i<n;i++){
        vector<ll> NO(21);
        for(int j=0;j<=20;j++){
            for(int sign=-1;sign<=1;sign+=2){
                int ne = j + sign * V[i];
                if(0 <= ne and ne <= 20){
                    NO[ne] += O[j];
                }
            }
        }
        O.swap(NO);
    }
    cout << O[result] << endl;
}

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

map<int,int>mp1,mp2;
int n,T,a[202000],b[202000],cnt;
ll sum=0,bas=0;

void add(int x){
	if (x>=0) ++mp1[x], sum+=x, ++cnt;
	else ++mp2[-x];
}
void del(int x){
	if (x>=0){
		sum-=x, --cnt;
		if (!(--mp1[x])) mp1.erase(x);
	}else{
		if (!(--mp2[-x])) mp2.erase(-x);
	}
}

ll doit(){
	if (!(cnt&1)) return sum;
	return sum+max(-mp1.begin()->first,-mp2.begin()->first);
}

int main(){
	cin>>n>>T; n<<=1;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	for (int i=2;i<n;i++) add(a[i]-b[i]), bas+=b[i];
	for (int p,x,y;T--;){
		scanf("%d%d%d",&p,&x,&y);
		if (p!=1&&p!=n){
			del(a[p]-b[p]); bas-=b[p];
			add((a[p]=x)-(b[p]=y));	bas+=b[p];
		}
		a[p]=x, b[p]=y;
		printf("%lld\n",bas+a[1]+a[n]+doit());
	}
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
//     int tc = 1;
//     cin >> tc;
//     while(tc--) {
        
//     }
    
    int n, x, t;
    cin >> n >> x >> t;
    int res = 0, curr = 0;
    while(curr < n) {
        curr += x;
        res += t;
    }
    cout << res << endl;
    
    return 0;
}

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

int main() {
	long long n,m, ans=0;
    cin >> n >> m;
    vector<pair<long long,long long>> vec(n);
    for (int i=0; i<n; ++i) {
        cin >> vec[i].first >> vec[i].second;
    }
    sort(vec.begin(), vec.end());
    int i = 0;
    while(m != 0) {
        if(vec[i].second <= m) {
            ans += vec[i].first * vec[i].second;
            m -= vec[i].second;
        }
        else {
            ans += vec[i].first * m;
            m=0;
        }
        i++;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define INF 100000000
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //n????????????k??????
ll gcd(ll n,ll m){
	if(n<m){ll a=m;m=n;n=a;}
	ll r=n%m;
	while(r!=0){
		n=m;
		m=r;
		r=n%m;
	}
	return m;
}
ll lcm(ll n,ll m){
	return n*m/gcd(n,m);
}
int main(){
	char s[1010];
	cin>>s;
	int x[26]={0};
	int a;
	rep(i,1010){
		if(s[i]=='\0'){
			break;
		}
		x[int(s[i])-97]++;
	}
	int odd=0;
	rep(i,26){
		if(x[i]%2==1){
			odd++;
		}
	}
	cout<<odd/2<<endl;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

vector<pll> v;

ll N,K;
cin >> N >> K;
rep(i,N) {
    int a,b;
    cin >> a >> b;
    v.push_back(make_pair(a,b));
}
sort(all(v));

ll ans;
rep(i,N) {
    if(K <= v[i].second) {
        ans = v[i].first;
        break;
    }
    else {
        K -= v[i].second;
    }
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 2420
// Author : Syed Mujtaba
// Seek knowledge from the Cradle to the Grave !!
// https://www.linkedin.com/in/syed-mujtaba

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define int             long long
#define ld              long double
#define ll              long long
#define pb              push_back
#define fi              first
#define se              second
#define mod              //1000000007  //998244353// 1e9 + 7
#define inf             1000000007 // 1e9 + 7
#define MAX             10000007   // 1e7 + 7
#define MAXN 			10000004
#define mt 				make_tuple
#define eps             1e-6
#define endl			'\n'
#define test            int t; cin>>t; while(t--)
#define fast_io         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define tree            tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
// int fact[1000007]={0};
// int spf[(int)(1e7) + 20];
// bool prime[(int)((1e7) + 20)];
// int gcd(int a,int b){if(b==0)return a; return gcd(b,a%b);}
// void sp(int n){spf[1]=1;for(int i=2;i<n;i++)spf[i]=i;for(int i=4;i<n;i+=2)spf[i]=2;for(int i=3;i*i<n;i++){if(spf[i]==i){for(int j=i*i;j<n;j+=i)if(spf[j]==j)spf[j]=i;}}}
// void sieve(int n){memset(prime,true,sizeof(prime) );for(int p=2;p*p<=n;p++){if(prime[p]==true)for(int i=p*p;i<=n;i+=p)prime[i]=false;}prime[0]=false;prime[1]=false;}
// int xyp(int x,int y){int res=1;while(y>0){if(y%2==1) res=(res*x)%mod;x=(x*x)%mod;y/=2;}return res%mod;}
// int inv(int x){return xyp(x,mod - 2);}
// void init() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
// int ncr(int n,int r) {int res=1; res=fact[n]; res=(res*(xyp(fact[r],mod-2)))%mod; res=(res*(xyp(fact[n-r],mod-2)))%mod; return res;}
// int npr(int n,int r) {int res=1; res=fact[n]; res=(res*(xyp(fact[n-r],mod-2)))%mod; return res; }
// bool isp(int a){if(a == 2)return true;if(a == 1)return false;for(int x= 2; x <= sqrt(a) + 1; x++)if(a % x == 0)return false;return true;}
// int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
// int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
// int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
// #define p_set tree< pair<int,int> ,  null_type ,  less<pair<int,int>> ,  rb_tree_tag ,  tree_order_statistics_node_update>
// #define i_set tree< int ,  null_type ,  less< int > ,  rb_tree_tag ,  tree_order_statistics_node_update>
// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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


signed main()
{
	fast_io
	// test
	{
		int x;
		cin >> x;
		int ans = 0;
		ans += (x / 500)*1000;
		x %= 500;
		ans += (x / 5)*5;
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>

#define N 100
int A[N + 1][N + 1];
int p[N + 1];

int solve(int i, int j)
{
    if(!(A[i][j] < 0)){ return A[i][j]; }
    if(j == i){ A[i][i] = 0; return 0; }
    if(j == i + 1){
        A[i][j] = p[i - 1] * p[i] * p[i + 1];
        return A[i][j];
    }
    int min = -1, x;
    for(int k = i; k < j; k++){
        x = solve(i, k) + solve(k + 1, j) + p[i - 1] * p[k] * p[j];
        if(min < 0){ min = x; }
        else{ if(min > x) min = x; }
    }
    A[i][j] = min;
    return min;
}

int main()
{
    int i, j, n;
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        scanf("%d %d", &p[i - 1], &p[i]);
        for(j = 1; j <= n; j++){
            A[i][j] = -1;
        }
    }
    printf("%d\n", solve(1, n));
    return 0;
}

Measured memory_bytes: 1072
#line 1 "main.cpp"

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { ++i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const noexcept { return l; }
  constexpr iterator end() const noexcept { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { --i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const noexcept { return r; }
  constexpr iterator end() const noexcept { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  size_t N;
  std::cin >> N;
  std::vector<bool> flip(N);
  std::vector<i32> A(N);
  for (auto i: range(0, N)) {
    if (i > 0) {
      char c;
      std::cin >> c;
      flip[i] = (c == '-');
    }
    std::cin >> A[i];
  }
  std::vector<std::array<i64, 3>> dp(N + 1);
  for (auto &arr: dp) {
    arr.fill(-inf64);
  }
  dp[0][0] = 0;
  for (auto i: range(0, N)) {
    for (auto k: { 0, 1 }) {
      chmax(dp[i + 1][k + flip[i]], dp[i][k] + ((k + flip[i]) % 2 == 0 ? 1 : -1) * A[i]);
    }
    chmax(dp[i + 1][2], dp[i][2] + A[i]);
    chmax(dp[i + 1][0], dp[i + 1][1]);
    chmax(dp[i + 1][1], dp[i + 1][2]);
  }
  std::cout << std::max({ dp[N][0], dp[N][1], dp[N][2] }) << '\n';
  return 0;
}

/**
 * @title Template
 */


Measured memory_bytes: 5912
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
map<ll,ll> counter;
ll fastexpo(ll x,ll y,ll m)
{
	ll temp=1;
	while(y>0)
	{
		if(y&1)temp = ((temp%m)*(x%m))%m;
		x = ((x%m)*(x%m))%m;
		y>>=1;
	}return temp;
}
void fff()
{
	ll n;
	cin >> n;
	if(n%1000 == 0)
	{
		cout << 0;
		return;
	}
	cout << 1000 - (n%1000) << ln;	
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 3648
#include<algorithm>
#include<cmath>
#include<functional> //sortのgreater
#include<iostream>
#include <math.h>
#include<numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include<string> //文字列
#include<vector>

using namespace std;
typedef long long ll;

int main()
{
    // Input
    ll x;
    cin >> x;

    ll ans = 0;
    double stock = 100;

    while (stock < x) {
        stock = floor(stock * 1.01);
        // cout << stock << endl;
        ans++;
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 3224
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());

		int[] xlist = new int[n];
		int[] ylist = new int[n];

		for(int i = 0; i < n; i++) {

			String[] temp = scanner.nextLine().split(" ");

			xlist[i] = Integer.parseInt(temp[0]);
			ylist[i] = Integer.parseInt(temp[1]);

		}


		double ans = 0;

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {

				ans += Math.sqrt(Math.pow(xlist[i] - xlist[j], 2) + Math.pow(ylist[i] - ylist[j], 2));

			}
		}



		System.out.println(ans / n);
	}

}


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

int main() {
	int n,x;
	cin>>n>>x;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int d[n+1];
	d[0] = 0;
	for(int i=1;i<n+1;i++){
		d[i] = d[i-1] + a[i-1];
	}
	int cnt = 0;
	for(int i=0;i<n+1;i++){
	//	cout<<d[i]<<" ";
		if(x >= d[i]) cnt++;
	}
	cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
map<i64,i64> Map;
int main(){
	i64 s = 0;
	int n,x;
	scanf("%d",&n);
	Map[s] ++;
	for(int i=1; i<=n; i++){
		scanf("%d",&x);
		s += x;
		Map[s]++;
	}
	i64 res = 0;
	for(auto p : Map){
		i64 r = p.second;
		res += r * (r-1)/2;
	}
	cout << res << endl;
	return 0;
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

signed main() {
  uint64_t w,h,x,y,r;
  cin >> w >> h >> x >> y >> r;
  
  if(x>=r&&w-r>=x&&y>=r&&h-r>=y) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

using namespace std;

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

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

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

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec a(n);
    cin>>a;
    ll c = n/2;
    Vec ans(n);
    rep(i,n){
        if(i%2==0){
            ans[c+i/2] = a[i];
        }else{
            ans[c-(i+1)/2] = a[i];
        }
    }
    if(n%2==1){
        reverse(ALL(ans));
    }
    rep(i,n){
        cout<<ans[i]<<" ";
    }
    return  0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <cmath>
#define ll long long int
using namespace std;

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	ll *a = new ll[n];
	ll max = -1;
	int max_id = 0;
	for(int i = 0; i < n; i++){
			cin >> a[i];
			if(a[i] > max){
				max = a[i];
				max_id = i;
			}
	}
	ll least = 1000000001;
	int least_id = 0;
	for(int i = 0; i < n; i++){
			if(i == max_id)continue;
			if(abs(max - a[i] * 2) < least){
					least = abs(max - a[i]*2);
					least_id = i;
			}
	}
	cout << a[max_id] << " " << a[least_id] << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=998244353;
const long double eps=1e-60;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll solve(ll i,ll j){
    if(j==0||j==4)return i;
    if(j==1||j==3){
        if(i)return i%2;
        return 2;
    }
    return 1-i%2;
}
int main(){
    ll n;cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    vvi dp(n+1,vi(5,inf));
    dp[0][0]=0;
    rep(i,n)rep(j,5){
        REP(k,j,5){
            chmin(dp[i+1][k],dp[i][j]+solve(v[i],k));
        }
    }
    ll ans=inf;
    rep(i,5)chmin(ans,dp[n][i]);
    out(ans);
}

Measured memory_bytes: 15872
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int A,B;
    char op;
    cin>>A>>op>>B;
    if(op=='+') cout<<A+B<<endl;
    else if( op=='-' ) cout<<A-B<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = rl()
A = [rl() for _ in range(N)]
answer = 300
while A[0]:
    s = set()
    l = []
    #print(answer)
    for i in range(N):
        x = A[i][0]
        s.add(x)
        l.append(x)
    
    c = Counter(l)
    y = c.most_common(1)[0]
    answer = min(answer, y[1])
    for i in range(N):
        A[i].remove(y[0])

print(answer)

#40

Measured memory_bytes: 4584
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <sstream>
#include <limits>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#define PI (acos(-1.0))
#define Abs(a) (((a)<0) ? (-(a)) :(a) )
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define Rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i,n) for(int i=((n)-1);i>=0;i--)
#define rrep(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define Pii pair<int,int>
#define PB push_back
#define Size(x) ((int)(x.size()))
using namespace std;
typedef long long mint;
typedef unsigned long long umint;
int main()
{
    //freopen("in.txt","r",stdin);
    int n;
    cin >> n;
    int od = 0, a;
    Rep(i,n)
    {
        scanf("%d",&a);
        if(a%2)
        {
            od++;
        }
    }
    if(n == 1 || od%2 == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
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 int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;
typedef long long ll ;
# define rep (i , n ) for ( int i =0; i < n ; i++)
# define _sort(arg) sort(begin(arg), end(arg))

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

	int N, K;
	cin >> N >> K;

	std::vector<ll> v;

	for (int i = 0; i < N; i++)
	{
		ll tmp;
		cin >> tmp;
		v.push_back(tmp);
	}

	sort(v.begin(), v.end());

	std::vector<ll> v2;
	for (int i = K-1; i < N; i++)
	{
		int diff = v[i] - v[i - (K-1)];
		v2.push_back(diff);
	}

	sort(v2.begin(), v2.end());

	cout << v2[0] << endl;

	return 0;
}

Measured memory_bytes: 2548
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

struct WeightedUnionFind
{
	std::vector<int> par,weight,size;
	WeightedUnionFind(int n) : par(n),weight(n,0),size(n,1) {
		std::iota(par.begin(),par.end(),0);
	}
	int find(int i) {
		if(par[i]==i) return i;
		int x=find(par[i]);
		weight[i]+=weight[par[i]];
		return par[i]=x;
	}
	int unite(int i, int j, int w) {
		if(same(i,j)) {
			if(diff(i,j)!=w) {
				return 1;
			} return 0;
		}
		int x=find(i), y=find(j);
		if(size[x]<size[y]) {
			std::swap(x,y);
			std::swap(i,j);
			w=-w;
		}
		par[y]=x;
		weight[y]=w+weight[i]-weight[j];
		return 0;
	}
	int diff(int i, int j) {
		return weight[j]-weight[i];
	}
	bool same(int i, int j) {
		return find(i)==find(j);
	}
};

signed main() {
	int n,m;
	std::cin >> n >> m;
	WeightedUnionFind uf(n);
	rep(i,m) {
		int l,r,d;
		std::cin >> l >> r >> d;
		l--;r--;
		if(uf.unite(l,r,d)) {
			print("No");
			return 0;
		}
	}
	print("Yes");

	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(void){
    int i, j;
    int sublen = 0;
    char str[11];
    scanf("%s", str);
    for (i = 0; i < 11; i++){
        if(str[i] == 'A' || str[i] == 'C' || str[i] == 'G' || str[i] == 'T'){
            for(j = i + 1; j < 11; j++){
                if(str[j] != 'A' && str[j] != 'C' && str[j] != 'G' && str[j] != 'T'){
                    if((j - i) > sublen) sublen = (j - i);
                    break;
                }
            }
        }
    }
    printf("%d\n", sublen);

    return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  int64 n, k;
  cin >> n >> k;
  n %= k;
  cout << min(n, k - n) << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
//	"strconv"
//	"sort"
//	"math"
//	"regexp"
)


var x,y int

func main(){
	fmt.Scan(&x,&y)

	if x == 2 && y==2 {
		fmt.Println("Yes")
	}else if (x == 4 ||x == 6||x == 9||x == 11) && (y == 4||y == 6||y == 9||y==11){
		fmt.Println("Yes")
	}else if (x == 1 ||x == 3||x == 5||x == 7||x == 8||x == 10||x == 12) && (y == 1 ||y == 3||y == 5||y == 7||y == 8||y == 10||y == 12){
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}



Measured memory_bytes: 512
/*
ID: arthurc4
TASK: test
LANG: C++11
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++)
#define REPb(j, d, c) \
for (int j = int(d); j >= int(c); j--)
#define pb \
push_back
#define ff \
first
#define ss \
second

ll dp_min_weight[100001];
ll dp_item_used[100001][100];

int main()
{
	//ifstream cin("input.txt");
	//ifstream cin("test.in");
	//ofstream cout("test.out");

	// some initialisation ...

	REP(i,1,1e5)
	{
		dp_min_weight[i]=1e18;
	}

	int n, W;
	cin >> n >> W;

	vector<pair<ll,ll>> VW;

	REP(i,1,n)
	{
		ll w, v;
		cin >> w >> v;

		VW.pb({v,w});
	}

	sort(VW.begin(),VW.end());

	ll global_max_value=0;

	REP(i,1,100000)
	{
		// can we achieve value i (and if so, what's the minimum weight?)
	
		ll current_min_weight=1e18;
		ll current_item_used=-1;

		REP(j,0,n-1)
		{
			if(VW[j].ff > i) break;
			if(dp_item_used[i-VW[j].ff][j]) continue;

			// if(i==2 && j==0) cout << "Hello" << endl;

			if(VW[j].ss + dp_min_weight[i-VW[j].ff] < current_min_weight)
			{
				current_min_weight = VW[j].ss + dp_min_weight[i-VW[j].ff];
				current_item_used = j;
			}
		}

		if(current_item_used!=-1)
		{
			dp_min_weight[i]=current_min_weight;

			dp_item_used[i][current_item_used]=true;

			REP(k,0,99)
			{
				if(dp_item_used[i-VW[current_item_used].ff][k]) dp_item_used[i][k]=true;
			}
		}

		if(current_min_weight <= W) 
		{
			global_max_value=i;
			//cout << i << endl;
		}
	}

	cout << global_max_value << endl;

	// cout << endl;

	// for(auto e:VW)
	// {
	// 	cout << e.ff << " " << e.ss << endl;
	// }

	// cout << endl;

	return 0;
}

Measured memory_bytes: 76928
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

long dp[51][2501] = {0};

int main(){
	int N,A;
	int x[51];
	long ans = 0;
	
	cin >> N >> A;
	for(int i=1; i<=N; i++){
		cin >> x[i];
	}
	
	dp[0][0] = 1;
	
	for(int y=1; y<=N; y++){
		for(int iy=y-1; iy>=0; iy--){
			for(int ix=0; ix<=iy*50; ix++){
				dp[iy+1][ix+x[y]] += dp[iy][ix];
			}
		}
	}
	
	for(int iy=1; iy<=N; iy++){
		ans += dp[iy][iy * A];
	}
	
	cout << ans << endl;
    
	
    return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int[] xz = new int[N];
        for (int i = 0; i < N; i++) {
            xz[i] = sc.nextInt();
        }
        int[] xzDiff = new int[N];
        for (int i = 0; i < N; i++) {
            xzDiff[i] = Math.abs(xz[i] - X);
        }

//        System.out.println(gcd(7,25));

        int divisor = 0;
        if (N == 1){
            System.out.println(Math.abs(xz[0] - X));
            System.exit(0);
        }
        for (int i = 1; i < N; i++) {
            if (i == 1){
                divisor = gcd(xzDiff[i - 1], xzDiff[i]);
            } else {
                divisor = gcd(divisor, xzDiff[i]);
            }
        }
        System.out.println(divisor);
    }

    public static int gcd(int a, int b){
        if (a == 0) return b;
        if (b == 0) return a;

        int tmp = 0;
        if (a > b){
            tmp = a;
            a = b;
            b = tmp;
        }
        return gcd(a, b % a);
    }

}

Measured memory_bytes: 58856
def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 0;
    m = 0
    for i, p in enumerate(P):
        if p < m or i == 0:
            m = p
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
    string s;
    cin >> s;
    deque<char> deck;
    rep(i, s.size()) {
        deck.push_back(s[i]);
    }
    int q;
    cin >> q;
    int cnt_rev = 0;
    rep(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            cnt_rev++;
            continue;
        } else {
            int f;
            cin >> f;
            char c;
            cin >> c;
            if (f == 1) {
                if (cnt_rev % 2 == 0) {
                    deck.emplace_front(c);
                } else {
                    deck.emplace_back(c);
                }
            } else {
                if (cnt_rev % 2 == 0) {
                    deck.emplace_back(c);
                } else {
                    deck.emplace_front(c);
                }
            }
        }
    }
    if (cnt_rev % 2 == 0) {
        rep(i, deck.size()) {
            cout << deck[i];
        }
    } else {
        for (int i = deck.size() - 1; i >= 0; --i) {
            cout << deck[i];
        }
    }
    cout << endl;
}

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

def gcd(x, y):
    while y != 0:
        x, y = y, x%y
    return x

def lcm(x, y):
    return x * y // gcd(x, y)


def f(x, c, d):
    num_c = x // c
    num_d = x // d
    num_c_d = x // lcm(c,d)

    return x - num_c - num_d + num_c_d

print( f(B, C, D) - f(A-1, C, D) )


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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

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

  int a[n][m]={0}, b[m]={0};
  rep(i, n) rep(j, m) cin >> a[i][j];
  rep(i, m) cin >> b[i];

  int c[n]={0};
  rep(i, n) rep(j, m) c[i] += a[i][j] * b[j];

  rep(i, n) cout << c[i] << endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

// dist[v] に頂点 s から頂点 v への距離を入れる関数
void dijkstra(int s, Graph &G, vector<ll> &dist){
  fill(all(dist), INF);
  dist[s] = 0;

  priority_queue<P, vector<P>, greater<P>> pq;//距離が小さい順に取り出す
  pq.push(P(0,s)); // 頂点 s からスタート

  while (!pq.empty()) {
    P p = pq.top(); pq.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;// 既に v に辿り着く短い経路有ならスルー (これはただの高速化)

    for(auto e : G[v]){// v から行ける頂点 nv 達を走査
      int nv = e.to;
      ll w = e.weight;
      if(dist[nv] > dist[v] + w){
        dist[nv] = dist[v] + w;
        pq.push(P(dist[nv], nv));
      }
    }
  }
}

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};



int main(){
  int n; cin >> n;
  vector<string> s(n);
  vi t(n);
  rep(i,n) cin >> s[i] >> t[i];
  string X; cin >> X;
  rep(i,n) {
    if(s[i] == X){
      int ans = 0;
      for(int j = i+1; j < n; j++) {
        ans += t[j];
      }
      cout << ans << endl;
      break;
    }
  }
}

Measured memory_bytes: 256