akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


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


const int MAX_DIGIT = 50;
long long dp[100][2];

void solve() {
    long long N, K; cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    memset(dp, -1, sizeof(dp));

    dp[0][0] = 0;
    for (int d = 0; d < MAX_DIGIT; d++) {
        long long mask = 1LL << (MAX_DIGIT - d - 1);

        int num = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] & mask) num++;
        }

        long long cost0 = mask * num;
        long long cost1 = mask * (N - num);

        // なんでもOK
        if (dp[d][1] != -1) {
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1));
        }

        if (dp[d][0] != -1) {
            // d+1桁目をKより小さくして次からはなんでもOK
            if (K & mask) chmax(dp[d+1][1], dp[d][0] + cost0);

            // d+1桁目までKと一緒
            // 1
            if (K & mask) chmax(dp[d+1][0], dp[d][0] + cost1);
            // 0
            else chmax(dp[d+1][0], dp[d][0] + cost0);
        }
    }

    long long ans = max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]);

    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 55;

using namespace std;

ll x[N];
ll dp[N][N*N];

main()
{
    fast;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    int n,a,i,j,k;
    cin>>n>>a;
    for (i=1;i<=n;i++)
        cin>>x[i];
    for (i=1;i<=n;i++)
    {
        for (j=i-1;j>=0;j--)
        {
            for (k=0;k<N*N;k++)
                dp[j+1][k+x[i]]+=dp[j][k];
        }
    }
    ll ans=0;
    for (i=1;i<=n;i++)
        ans+=dp[i][i*a];
    cout<<ans<<endl;
}

Measured memory_bytes: 1536
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353


S = input() + "0"
mod = 2019

dp = [0]
a = 1
for i in range(len(S)-1):
    dp.append((dp[-1] + int(S[len(S)-2-i])*a%mod) % mod)
    a = (a * 10) % mod

count = Counter(dp)

ans = 0
for v in list(count.values()):
    ans += v*(v-1)//2
print(ans)


Measured memory_bytes: 90520
/*
Written By mafailure
*/
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long 
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set; 
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int power(int x, int y)
{ 
	if(y==0)return 1;
	int u=power(x,y/2);
	u=(u*u)%mod;
	if(y%2)u=(x*u)%mod;
	return u;
    
}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
	
	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
signed main()
{
	IOS
	string s;
	cin>>s;
	int n=s.length();
	int sum=0;
	fr(i,0,n)
	{
		sum+=(s[i]-'0');
		
	}
cout<<(	sum%9?"No\n": "Yes\n");
	
	
}



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, M; scanf("%d %d", &N, &M);
  vector<pair<int, int>> A(N), C(M);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &A[i].first, &A[i].second);
  }
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &C[i].first, &C[i].second);
  }

  vector<int> ans(N);
  for (int i = 0; i < N; ++i) {
    int diff = INF, cp = -5;
    for (int j = 0; j < M; ++j) {
      if (abs(A[i].first - C[j].first) + abs(A[i].second - C[j].second) < diff) {
        diff = abs(A[i].first - C[j].first) + abs(A[i].second - C[j].second);
        cp = j;
      }
    }
    ans[i] = cp + 1;
  }
  for (int i = 0; i < N; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    bool ise = true;
    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            if (!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) ise = false;
        } else {
            if (!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) ise = false;
        }
    }
    cout << (ise ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A_dash = []
for i, A_i in enumerate(A):
    A_dash.append(A_i-(i+1))
A_dash.sort()

med = A_dash[N//2]

ans = 0
for i, A_i in enumerate(A_dash):
    ans += abs(A_i - (med))

print(ans)

Measured memory_bytes: 26356
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;

ll C[100][100];

void comb_table(ll N) {
	for (ll i = 0; i <= N; i++) {
		for (ll j = 0; j <= i; j++) {
			if (j == 0 || j == i) {
				C[i][j] = 1LL;
			}
			else {
				C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
			}
		}
	}
}

int main()
{
	int N, P;
	cin >> N >> P;
	int A[51];

	comb_table(N);

	ll ans = 0;
	int g = 0, k = 0;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] % 2 == 0)g++;
		else k++;
	}

	if (P == 1) {
		for (int j = 1; j <= k; j+=2) {
			for (int i = 0; i <= g; i += 1) {
				ans += C[k][j] * C[g][i];
			}
		}
	}
	else {
		for (int j = 0; j <= k; j += 2) {
			for (int i = 0; i <= g; i += 1) {
				ans += C[k][j] * C[g][i];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps 1e-6
#define ll long long
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define int long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define fi first
#define se second
#define endl "\n"
#define pii pair<int,int>
#define fi first
#define se second
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll Max(ll a,ll b){return a>=b?a:b;}
ll Min(ll a,ll b){return a<=b?a:b;}
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res,t;res=1;t=a%c;while(b){if(b&1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
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;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
//head file

int a[10001]={0};
int main()
{
    int n;
    cin>>n;
    int i,j,k;
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                int dex=i*i+j*j+k*k+i*j+i*k+j*k;
                if(dex<=10000)
                a[dex]++;
            }
        }
    }
    rep(i,1,n+1)
    {
        cout<<a[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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


    char a = n+1;
    cout<< a << endl;

    return 0;
}

Measured memory_bytes: 256
from math import sqrt
# エラトステネスのふるい
def sieve(n):
  if n <2:
    return [False]*(n)
  is_prime = [True]*(n)
  is_prime[0], is_prime[1] = False, False
  for i in range(2, int(sqrt(MAX))):
    if is_prime[i]:
      for j in range(i*2, n, i):
        is_prime[j] = False
  return is_prime
    
# 2017-like 数かどうか
MAX = 10**5
is_prime = sieve(MAX)
a = [0]*(MAX)
for i in range(MAX):
  if i%2 == 0:
    continue
  if is_prime[i] and is_prime[(i+1)//2]:
    a[i] = 1

#  累積和
s = [0]*(MAX+1)
for i in range(MAX):
  s[i+1] = s[i] + a[i]
  
# クエリ処理
Q = int(input())
for q in range(Q):
  l, r = map(int, input().split())
  print(s[r+1] - s[l])


Measured memory_bytes: 7892
//author:luckYrat(twitter:@luckYrat_)
//#include <tourist>

//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
template <typename T>
T gcd(T a,T b){
  if(!(a*b))return 1;
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n,m;cin>>n>>m;
  for(int i = 1; (1<<n) > i; i++){
    for(int j = 1; (1<<m) > j; j++){
      int nwi = i;
      int nwj = j;
      int z = 0;
      int x = gcd(nwi,nwj);
      
      while(!(x%2))z++,x/=2;
      if(!(z%2)){
        cout << "1";
      }else{
        cout << "0";
      }

    }
    cout << endl;
  }

}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

struct Edge {
    int a;
    int b;
    int color;
};

bool visited[100010];

void dfs(int v, vector<vector<reference_wrapper<Edge>>> &edges, int color, int maxEdgeColor) {
    if (visited[v]) {
        return;
    }
    visited[v] = true;
    for (Edge &e: edges[v]) {
        if (e.color == 0) {
            color++;
            if (color > maxEdgeColor) color = 1;
            e.color = color;
            int nv = e.a;
            if (nv == v) nv = e.b;
            dfs(nv, edges, color, maxEdgeColor);
        }
    }
}

int main() {
    int N;
    cin >> N;
    vector<Edge> edges(N - 1);
    vector<vector<reference_wrapper<Edge>>> v(N);
    vector<int> count(N);
    int maxEdgeCount = 0;
    rep(i, N - 1) {
        int a;
        int b;
        cin >> a >> b;
        a--;
        b--;
        edges[i].a = a;
        edges[i].b = b;
        v[a].push_back(edges[i]);
        v[b].push_back(edges[i]);
        count[a]++;
        count[b]++;
        chmax(maxEdgeCount, count[a]);
        chmax(maxEdgeCount, count[b]);
    }

    dfs(0, v, 0, maxEdgeCount);

    cout << maxEdgeCount << endl;
    for (Edge e: edges) {
        cout << e.color << endl;
    }
}


Measured memory_bytes: 8192
#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>
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 ;
 
int main(){
  int n;
  cin >> n;
  string s[n];
  rep(i,n)cin >> s[i];
  int a=0,b=0,c=0,ans=0;
  rep(i,n){
    if(s[i][s[i].size()-1]=='A' &&s[i][0]!='B')a++;
    if(s[i][0]=='B' && s[i][s[i].size()-1]!='A')b++;
    if(s[i][s[i].size()-1]=='A' &&s[i][0]=='B')c++;
    for(int j=0;j+1<s[i].size();j++){
      if(s[i][j]=='A' && s[i][j+1]=='B')ans++;
    }
  }
  if(a==0 && b==0 && c>0){
    cout << ans+c-1 << endl;
    return 0;
  }
  else if(a==0 && b==0 && c==0){
    cout << ans << endl;
    return 0;
  }
    ans+=min(a,b)+c;
  cout << ans << endl;
return 0;}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 998244353
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

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

using namespace std;

bool ispa(string s)
{
    ll n = s.length();
    bool pos = 1;
    rep(n)
        if(s[i]!=s[n-1-i])
            pos = 0;
    return pos;        
}

int main()
{
   FAST/**/
   
   ll n,s;
   cin>>n>>s;
   ll arr[n];
   rep(n)
        cin>>arr[i];
   
   ll dp[n][s];
   memset(dp,0,sizeof(dp));
   if(arr[0]<s)
     dp[0][arr[0]] = 1;
   ll ans = 0;
   if(arr[0] == s)
        ans+=n, ans%=mod;        
   for(ll i=1;i<n;i++)
   {
       ll rways = n-i;
       if(s-arr[i]>0){
           ans+=((rways*dp[i-1][s-arr[i]])%mod), ans%=mod;
       }
       if(arr[i] == s)
       {
           ans+=(((i+1)*rways)%mod), ans%=mod;
       }
       for(ll prev = 1;prev<s;prev++)
           dp[i][prev] = dp[i-1][prev];
       if(arr[i]<s){
       dp[i][arr[i]] += (i+1);
       dp[i][arr[i]]%=mod;
       }
       
       for(ll prev = 1;prev<s-arr[i];prev++)
       {
           dp[i][prev+arr[i]]+=dp[i-1][prev];
           dp[i][prev+arr[i]]%=mod;
       }
               
   }
   ans%=mod;
   if(ans<0)
        ans+=mod;
   cout<<ans;
   return 0;        
}  
   

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

int main() {
  int n,k,p,i,count=0,j;
  cin >> n >> k;
  int a[n];
  for(i=0;i<n;i++)
    a[i]=0;
  int d;
  for(i=0;i<k;i++)
  {
	cin >> d;
    for(j=0;j<d;j++){
      cin >> p;
      a[p-1]++;
    }
  }
  for(i=0;i<n;i++)
  {
    if(a[i]==0)
      count++;
  }
  cout << count << "\n";
}

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

int main(){
    int n,m;
    cin>>n>>m;
    string s1="",s2="";
    for(int i=0;i<n;i++)
        s1+=m+'0';
    for(int i=0;i<m;i++)
        s2+=n+'0';
    //cout<<s2;

    if(s1<s2)
        cout<<s1;
    else
        cout<<s2;


}

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

 int n;
int k;
 int dp[100005];

int solve(int a[])
{
	dp[0] = 0;
  	dp[1] = dp[0]+abs(a[1]-a[0]);
  for(int i=2;i<n;i++)
  {
    dp[i] = abs(a[i]-a[i-1])+dp[i-1];
    for(int j=1;j<=k;j++)
    {
      if(i<j) break;
      if(dp[i]>(abs(a[i]-a[i-j])+dp[i-j]))
      {
        dp[i] = abs(a[i]-a[i-j])+dp[i-j];
      }
    } 
    
  } 
  return dp[n-1];
}
  

int main()
{
  cin>>n>>k;
 int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  
  cout<<solve(a)<<endl;
  return 0;
}
  

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int h[20];
    cin>>n;
    REP(i,n)cin>>h[i];
    int ans = 0;
    REP(i,n){
        bool able = true;
        for(int j = 0; j < i; j++){
            if(h[i] < h[j])able = false;
        }
        if(able)ans++;
    }
    PUTS(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {-1, 0, 1, 0};

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> field(H);
  for(int i=0; i<H; i++){
    cin >> field[i];
  }
  bool ans = true;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(field[i][j] == '#'){
        bool res=false;
        for(int dir=0; dir<4; dir++){
          int nh = i + dy[dir];
          int nw = j + dx[dir];
          if(nh<0 || nh>=H || nw<0 || nw>=W){
            continue;
          }
          if(field[nh][nw] == '#'){
            res = true;
            break;
          }
        }
        if(!res){
          ans = false;
        }
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    cout << (1000 - n % 1000) % 1000 << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//const ll mx=1e5;
//bool prime[100009];
//void seive()
//{
//    prime[1]=true;
//    for(int i=2;i*i<=mx;i++){
//        if(prime[i]==false){
//            for(int j=i*i;j<=mx;j+=i) prime[j]=true;
//        }
//    }
//}
int main(){
	ll r,b,g,n;
	cin>>r>>b>>g>>n;
	ll cnt=0;
	vector<ll>v;
	for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            ll total=r*i+b*j;
            //cout<<total<<" ";
            if(total>n)continue;
            v.push_back(total);
        }
	}
	for(auto x: v){
        if((n-x)%g==0)cnt++;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 67168
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    int a;
    map<int, int> mp;
    int b = 0;

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

        cin >> a;
        mp[a]++;
    }

    cout << mp.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cstring>

// ---------- PBDS -----------------

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
// slow but fast ORZ :)
// ----------------------------------

using namespace std;
using namespace __gnu_pbds; 

#define MEM(a, b) memset(a, (b), sizeof(a))
#define ALL(a) a.begin(), a.end()
#define MP(a, b) make_pair(a, b)
#define PB(a) push_back(a)
#define EB(a) emplace_back(a) // care when use
#define boost ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0),cout << fixed << setprecision(10);
// #define ll long long int
#define int long long int

#define DEBUG

#ifdef DEBUG

    #define debug(args...)(Debugger()) , args

    class Debugger{
        public:
        Debugger(const std::string& _separator = " | ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std::cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std::cerr << std::endl;}

        private:
        
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)
#endif

void solve(){

	int l, r, d;
	cin >> l >> r >> d;

	int ans = 0;

	for(int i = l; i <= r; ++i){
		if(i % d == 0)
			ans++;
	}

	cout << ans << "\n";

}


int32_t main(){

	boost;
	
	int T;

	// cin >> T;
	T = 1;
	
	while(T--){
		solve();
	}
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;


int main(){
	char _;	
	int n=0;
	double x[21],y[21];
	while(cin>>x[n]>>_>>y[n])n++;
	x[n]=x[0];y[n]=y[0];
	double s=0;
	for(int i=0;i<n;i++){
		s += x[i]*y[i+1] - y[i]*x[i+1];
	}
	printf("%.6f\n",abs(s/2));
	return 0;
}

Measured memory_bytes: 1240
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

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

    string S;
    cin >> S;
    string ans = "Good";
    for( ll ni = 0 ; ni <=2 ; ni++ ){
        string S1 = S.substr(ni,1);
        string S2 = S.substr(ni+1,1);
        if(S1==S2) ans = "Bad";
    }
    cout << ans << endl;

    

}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int n,m,T,a[1005],s;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i],
		s+=a[i];
	sort(a,a+n);
	reverse(a,a+n);
	if (a[m-1]*4*m >= s) {
		cout << "Yes";
	}
	else cout <<"No";
	return 0;
		
}

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

using namespace std;

typedef long long int ll;

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

  int x;
  cin >> x;
  x /= 100;
  int a = 6, ans = 8;
  while (x >= a) {
    a += 2;
    ans--;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}

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

Measured memory_bytes: 3652
# N = 2000
# Y = 20000000
N,Y = map(int, input().split())
ans= [-1, -1, -1]

for x in range(N+1):
    for y in range(N-x+1):
        price = x*10000 + y*5000 + int(N-x-y)*1000
#         print(x,y,N-x-y)
        if price == Y:
            ans = [x,y,N-x-y]
            break
            
    if price == Y: 
        break

print(ans[0], ans[1], ans[2])

Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
int w,h,x,y,r;
bool out(int x,int y){
	return !(x>=0&&x<=w&&y>=0&&y<=h);
}
int main(){
	cin>>w>>h>>x>>y>>r;
	if(out(x+r,y)||out(x,y+r)||out(x-r,y)||out(x,y-r))puts("No");
	else puts("Yes");
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int DAYMAX = 100005;
const int ACTIONMAX = 3;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<vector<int>> happiness(N, vector<int>(ACTIONMAX));
    for (int i = 0; i < N; i++)
        for (int j = 0; j < ACTIONMAX; j++)
        cin >> happiness[i][j];

    vector<int> dp(ACTIONMAX, 0);
    vector<int> tmp(ACTIONMAX, 0);
    for (int d = 0; d < N; d++) {
        for (int todayAction = 0; todayAction < ACTIONMAX; todayAction++) {
            for (int yesterdayAction = 0; yesterdayAction < ACTIONMAX; yesterdayAction++) {
                if (todayAction == yesterdayAction) continue;
                tmp[todayAction] = max(tmp[todayAction],
                                        dp[yesterdayAction] + happiness[d][todayAction]);
            }
        }
        for (int i = 0; i < ACTIONMAX; i++) {
            dp[i] = tmp[i];
            tmp[i] = 0;
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << '\n';
}


Measured memory_bytes: 8796
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, m; cin>>n>>m;
    string s; cin>>s;

    reverse(s.begin(), s.end());
    
    int cur = 0;
    vector<int> ans;
    bool valid = true;
    while(cur != n && valid){
        for(int i=min(cur+m, n); i>=cur+1; i--){
            if(s[i] == '0'){
                ans.emplace_back(i - cur);
                cur = i;
                break;
            }

            if(i == cur + 1) valid = false;
        }
    }

    if(!valid){
        cout << -1 << endl;
        return 0;
    }

    reverse(ans.begin(), ans.end());

    for(int i=0; i<ans.size(); i++){
        cout << ans[i] << " \n"[i == ans.size() - 1]; 
    }

    return 0;
}

Measured memory_bytes: 1096
while true do
    a,op,b = gets.split
    case op
    when '+' then
      puts "#{a.to_i+b.to_i}"
    when '-' then
        puts "#{a.to_i-b.to_i}"
    when '*' then
        puts "#{a.to_i*b.to_i}"
    when '/' then
        puts "#{(a.to_i/b.to_f).floor}"
    when '?' then
        break
    end
end


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

using namespace std;

int n;
int h[100001];
int f[100001];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&h[i]);
	f[1]=0;
	f[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++)
		f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int r,c,a,sum = 0;
    cin >> r >> c;
    int l[r+1][c+1];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> a;
            l[i][j] = a;
            sum += a;
        }
        l[i][c] = sum;
        sum = 0;
    }
    for(int i = 0; i <= c; i++){
        for(int j = 0; j < r; j++){
            sum += l[j][i];
        }
        l[r][i] = sum;
        sum = 0;
    }
     for(int i = 0; i <= r; i++){
        for(int j = 0; j < c; j++){
            cout << l[i][j] << " ";
        }
        cout << l[i][c] << endl;
    }
    return 0;
}


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

int main() {
  int N;
  int L;
  cin >> N;
  cin >> L;
  
  if(L >= 0 && L + N - 1 >= 0)
  {
    cout << (N-1)*(0.5*N+L) << endl;
  }
    if(L <= 0 && L + N - 1 <= 0)
  {
    cout << (N-1)*(0.5*N+L-1) << endl;
  }  
  if(L < 0 && L + N - 1 > 0)
  {
    cout << (N-1)*(0.5*N+L)+L << endl;
  }
 
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int num,i,q,o,sign=0;
    char map[100][4],line[50];
    for(;scanf("%d%c",&num,&map[0][0]),num;){
        for(i=0;i<num;i++){
            fgets(map[i],10,stdin);
        }
        scanf("%d%c",&q,&line[0]);
        for(i=0;sign=0,i<q;i++){
            fgets(line,50,stdin);
            for(o=0;o<num;o++)
                if(map[o][0]==line[0]){
                    printf("%c",map[o][2]);
                    sign=1;
                }
            if(sign==0)
                printf("%c",line[0]);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 592
#include <stdio.h>

int main()
{
    int w;
    int i, j;

    scanf("%d", &w);

    while (w != -1) {
        int rate = 1150;

        for (i = 11; i <= 20 && i <= w; i++) {
            rate += 125;
        }
        for (i = 21; i <= 30 && i <= w; i++) {
            rate += 140;
        }
        for (i = 31; i <= w; i++) {
            rate += 160;
        }

        printf("%d\n", 4280 - rate);

        scanf("%d", &w);
    }

    return 0;
}



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

public class Main {
    public static void main(final String[] args) {
        final FastReader s=new FastReader();
        long x = Math.abs(s.nextLong());
        long k = s.nextLong();
        long d = s.nextLong();
        
        long min = x/d;
        
        if(min>k){
            System.out.println(x-(k*d));
            return;
        }
        k=k-(x/d);
        x=x-(d*(x/d));

        if(k%2!=0) x = d-x;

        System.out.println(x);

    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try { st = new StringTokenizer(br.readLine()); }
                catch (final IOException  e) { e.printStackTrace(); }
            }
            return st.nextToken();
        }
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
        String nextLine() {
            String str = "";
            try { str = br.readLine(); }
            catch (final IOException e) { e.printStackTrace(); }
            return str;
        }
    }
}

Measured memory_bytes: 25388
read input
p=0
[[ $( echo ${input} | cut -c1 ) -eq 1 ]] && p=1
[[ $( echo ${input} | cut -c2 ) -eq 1 ]] && p=$(( ${p} + 1 ))
[[ $( echo ${input} | cut -c3 ) -eq 1 ]] && p=$(( ${p} + 1 ))
echo ${p}

Measured memory_bytes: 764
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int mod = 1000000007;
int main() {
    int N;
    cin >> N;
    vector<string> tp(N);
    for(int i = 0; i < N; ++i) {
        cin >> tp[i];
    }
    vector<vector<int> > g(N);
    for(int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b; --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    function<int(int, int)> rec = [&](int pos, int pre) {
        int ans = 0;
        if(tp[pos][0] == 'E') {
            ans = 1;
            for(int i : g[pos]) {
                if(i != pre) {
                    ans = 1LL * ans * rec(i, pos) % mod;
                }
            }
        }
        if(tp[pos][0] == 'R') {
            ans = 1;
            for(int i : g[pos]) {
                if(i != pre) {
                    ans = 1LL * ans * (rec(i, pos) + (tp[i].find("?") != string::npos ? 0 : 1)) % mod;
                }
            }
            ans = (ans + mod - 1) % mod;
        }
        if(tp[pos][0] == 'A') {
            ans = 0;
            for(int i : g[pos]) {
                if(i != pre) {
                    ans = (ans + rec(i, pos)) % mod;
                    if(tp[i].find("?") != string::npos) {
                        ans = (ans + mod - 1) % mod;
                    }
                }
            }
        }
        if(tp[pos].find("?") != string::npos) {
            ans = (ans + 1) % mod;
        }
        return ans;
    };
    int ans = rec(0, -1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3420
#include <bits/stdc++.h>
using namespace std;
long long n,m,x;

int main()
{
    cin>>n>>m;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
        v[i]--;
    }

    vector<int>mvs,nms(n);
    int cr=0;
    while(1){
        if(nms[v[cr]]){
            cr=v[cr];
            break;
        }

        mvs.push_back(v[cr]);
        cr=v[cr];
        nms[cr]=1;
    }
    int i=0;
    int f=0;
    while(m--){
        if(m==0){
            cout<<mvs[i]+1<<'\n';
            f=1;
            break;
        }
        if(mvs[i]==cr){
            break;
        }

        i++;

    }
    if(f==0){
        int rm=mvs.size()-i;
        cout<<mvs[i+m%rm]+1<<'\n';
    }
    return 0;

}
/***
4 5
3 2 4 1
*/


Measured memory_bytes: 5864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node
{
    int x;
    ll v;
    bool operator < (const node& b)const
    {
        return v<b.v;
    }
};
priority_queue<node>q;
int main()
{
    int n,m;
    int x;
    ll v;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&v);
        q.push({1,v});
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%d%lld",&x,&v);
        q.push({x,v});
    }
    ll ans=0;
    while(1)
    {
        node now=q.top();
        q.pop();
        if(n<=now.x)
        {
            ans+=n*now.v;
            break;
        }
        else
        {
          n-=now.x;
          ans+=now.x*now.v;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main() {

    int n,l;

    cin >> n >> l;

    vector<string> v;

    while(n--){
        string s;
        cin >> s;
        v.push_back(s);
    }

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

    for(auto i : v){
        cout << i;
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
$<.each_line do |line|
	h, w = line.split.map(&:to_i)
	break if h.zero? && w.zero?

	puts '#' * w
	if 2 <= h
		(h - 2).times do
			print '#'
			if 2 <= w
				print '.' * (w - 2)
				print '#'
			end
			puts
		end
		puts '#' * w
	end

	puts
end

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

int main() {

  int N;
  cin >> N;
  
  vector<int> L(N);
  for(int i=0; i<N; i++) cin >> L.at(i);
//for(int i=0; i<N; i++) cout << L.at(i);  
  
  sort(L.begin(), L.end());
  reverse(L.begin(), L.end());
//for(int i=0; i<N; i++) cout << L.at(i);
  
  int ans=0;
  
  for(int i=0; i<N; i++) {
    for(int j=0; j<N; j++) {
      for(int k=0; k<N; k++) {
        if(L.at(i)>L.at(j) && L.at(j)>L.at(k)) {
          int A = max(max(L.at(i),L.at(j)),L.at(k));
          if(A < L.at(i)+L.at(j)+L.at(k)-A) {
            ans++;
          }
        }
      }
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N+1),B(N+1);
  for(long long i=0;i<N;i++){cin >> A[i] >> B[i];}
  long long count=0;
  for(long long i=N-1;i>=0;i--){
    A[i]+=count;
    if(A[i]%B[i]!=0){count+=B[i]-A[i]%B[i];}
  }
  cout << count << endl;
}

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

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int N = sc.NextInt();
        int[] H = sc.IntArray();

        int[] ans = new int[N];
        for (int i = 1; i < N; i++)
        {
            if (H[i - 1] >= H[i])
            {
                ans[i] = ans[i - 1] + 1;
            }
            else
            {
                ans[i] = 0;
            }
        }

        Console.WriteLine(ans.Max());
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 27484
import java.util.*;
import java.io.*;
class Main{
  static int q;
  public static void main(String args[])throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    q = Integer.parseInt(br.readLine());
    // Scanner sc = new Scanner(System.in);
    // q = sc.nextInt();
    String s[] = new String[2];
    for(int i = 0; i<q; i++){
      s[0] = br.readLine();
      s[1] = br.readLine();
      System.out.println(LCSLength(s[0] , s[1]));
    }
  }


  static int LCSLength(String X, String Y){
    int m = X.length();
    int n = Y.length();
    int c[][] = new int[m+1][n+1];
    for(int i =0; i<=m; i++){
      c[i][0] = 0;
    }
    for(int j = 0; j<=n; j++){
      c[0][j] = 0;
    }

    for(int i = 1; i<=m; i++){
      for(int j = 1; j<=n; j++){
        if(X.charAt(i-1) == Y.charAt(j-1)){
          c[i][j] = c[i-1][j-1] +1;
        }else if(c[i -1][j] >=c[i][j-1]){
          c[i][j] = c[i-1][j];
        }else{
          c[i][j] = c[i][j-1];
        }
      }
    }
    return c[m][n];
  }

}


Measured memory_bytes: 64780
#include <stdio.h>

int main(void)
{
  int a = 0;
  int op;
  int b = 0;

  do {
  scanf("%d %c %d", &a, &op, &b);

  if (op == '?')
    break;
  if ( op == '+')
  printf("%d\n", a + b);

  if ( op == '-')
  printf("%d\n", a - b);

  if ( op == '*')
  printf("%d\n", a * b);

  if ( op == '/')
  printf("%d\n", a / b);

  } while(1);
  
  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;

namespace ALDS1_3_A
{
    class Program
    {
        static void Main(string[] args)
        {
            Stack<int> numbers = new Stack<int>();
            string[] str = Console.ReadLine().Split(' ');
            for (int i = 0; i < str.Length; i++)
            {
                switch(str[i])
                {
                    case "+":
                        {
                            numbers.Push(numbers.Pop() + numbers.Pop());
                            break;
                        }
                    case "-":
                        {
                            int a = numbers.Pop();
                            numbers.Push(numbers.Pop() - a);
                            break;
                        }
                    case "*":
                        {
                            numbers.Push(numbers.Pop() * numbers.Pop());
                            break;
                        }
                    default:
                        {
                            numbers.Push(int.Parse(str[i]));
                            break;
                        }
                }
            }
            Console.WriteLine(numbers.Pop());
        }
    }
}


Measured memory_bytes: 20456
import java.util.*;

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int H = sc.nextInt(); //0~11
		int M = sc.nextInt(); //0~59
		double Mr = (double) M*6;
      	double Hr = H*30 + Mr/12;
		
		double diffr = 0.0;
		if(Hr>Mr){
			diffr = Hr - Mr;
		}else{
			diffr = Mr - Hr;
		}
		
		double ans = 0.0;
		if(diffr == 90){
			ans = Math.sqrt(Math.pow(A,2) + Math.pow(B,2));
			System.out.println(ans);
			return;
		}
      
      	if(diffr == 180){
			System.out.println(A+B);
			return;
		}
      
      	if(diffr > 180){
			diffr = 360 - diffr;
		}

		double mid = 2*(A*B)*Math.cos(Math.toRadians(diffr));
		ans = Math.sqrt(Math.pow(A,2) - mid + Math.pow(B,2));
		System.out.println(ans);
		return;

	}
}

Measured memory_bytes: 36096
import sys

sys.setrecursionlimit(100000)

while True:
  h, w = map(int, input().split())
  if not h:
    break

  mp = [list("X" + input() + "X") for _ in range(h)]
  mp.insert(0, ["X"] * (w + 2))
  mp.append(["X"] * (w + 2))
  
  direct = ((0, 1), (0, -1), (1, 0), (-1, 0))

  def search(x, y, target):
    mp[y][x] = "X"
    for dx, dy in direct:
      nx, ny = x + dx, y + dy
      if mp[ny][nx] == target:
        search(nx, ny, target)
  
  ans = 0

  for x in range(1, w + 1):
    for y in range(1, h + 1):
      target = mp[y][x]
      if target != "X":
        search(x, y, target)
        ans += 1
  
  print(ans)


Measured memory_bytes: 15904
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c] += 1
    s = sum(sorted(d.values(), reverse=True)[:k])

    return n - s



print(main())




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

int main(){
  int x,y;
  cin >> x >> y;
  int sum = 0;
  switch (x) {
    case 3: sum += 100000;break;
    case 2: sum += 200000;break;
    case 1: sum += 300000;break;
    default: break;
  }
  switch (y) {
    case 3: sum += 100000;break;
    case 2: sum += 200000;break;
    case 1: sum += 300000;break;
    default: break;
  }
  if (x == 1 && y == 1) {
    sum += 400000;
  }
  cout << sum << endl;
  return 0;
}


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

int main () {
  int a, b, c;
  cin >> a >> b >> c;

  if (a < c && c < b) {
    cout << "Yes" << endl;
  } else if (b < c && c < a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256