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

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int n;
int a[100001];
int suf[100002];
int pref[100001];

void solve(){
	cin >> n;
	RE(i,n)cin >> a[i];
    pref[0] = 0;
    suf[n+1] = 0;
    RE(i,n)pref[i] = __gcd(pref[i-1],a[i]);
    RED(i,n)suf[i] = __gcd(suf[i+1],a[i]);
    int ans = INF;
    RE(i,n){
    	ans = min(ans,__gcd(pref[i-1],suf[i+1]));
    	ans = min(ans,a[i]);
    } 
    debug(pref[n]);
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

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

int main(){
	string s;
	cin >> s;
	int cnt1 = 0, cnt0 = 0;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == '0') cnt0++;
		else cnt1++;
	}
	if(cnt0 > cnt1) cout << cnt1 * 2 << endl;
	else if (cnt0 == cnt1) cout << cnt0 * 2 << endl;
	else cout << cnt0 * 2 << endl;
}


Measured memory_bytes: 512
s = gets.chomp
count = 0
a = s[0...s.length/2].split('')
b =
  if s.length.even?
    s[s.length/2..-1].reverse.split('')
  else
    s[s.length/2+1..-1].reverse.split('')
  end
a.each.with_index do |chr, i|
  if chr != b[i]
    b[i] = chr
    count += 1
  end
end
puts count


Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;

int main(){
string s;
cin >> s;
sort(s.begin(),s.end());
int check =1;
bool ans =true;
if( s.size()==1){
    cout <<"No"<<endl;
    ans =false;
}
if(ans){
for(int i=0;i<s.size()-1;i++){
    if(s.at(i)==s.at(i+1)){
        check++;
    }
    else {
        if(check%2 !=0){
            cout <<"No"<<endl;
            ans =false;
            break;
        }
        else {
            check =1;
        }
    }
}
}
if(ans){
    cout << "Yes"<<endl;
}
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1e9  //
#define INFLL 4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define PB(a) push_back(a)
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

//------------------------------------------------------

int main() {
    int n, m;
    cin >> n >> m;
    int road[n] = {};

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        road[a - 1]++;
        road[b - 1]++;
    }

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

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int L[] = new int[N];
        int max = 0;
        int count = 0;
        int sum = 0;
        for (int i = 0; i < N; i++) {
            L[i] = Integer.parseInt(scanner.next());
        }
        scanner.close();

        if (N > 2) {
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    for (int k = j + 1; k < N; k++) {
                        if (L[i] != L[j] && L[j] != L[k] && L[i] != L[k]) {
                            max = Math.max(L[i], Math.max(L[j], L[k]));
                            sum = L[i] + L[j] + L[k] - max;
                            if (max < sum) {
                                count++;
                                //System.out.println(L[i] + ":" + L[j] + ":" + L[k]);
                            }
                        }
                        max = 0;
                        sum = 0;
                    }
                }
            }
        }
        System.out.println(count);
    }
}


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

UL N;
ULL dp[101][101];
ULL R[100][2];

int main() {
 cin>>N;
 rep(i,N) rep(j,2) cin>>R[i][j];
 rep(i,N+1) rep(j,N+1) dp[i][j]=1000000000000;
 rep(i,N) dp[i][i+1]=0;
 for(UL j=2; j<=N; j++) for(UL i=j-2; i!=~0u; i--){
  for(UL k=i+1; k<=j-1; k++){
   dp[i][j]=min(dp[i][j],
    dp[i][k]+dp[k][j]+R[i][0]*R[j-1][1]*R[k][0]
   );
  }
 }
 cout<<dp[0][N]<<endl;
 return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
//const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

ll mod_pow(ll x,ll n,ll MOD){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

ll ans;
string S;
int N;
ll P;

ll iten[200010];

void solve(int l,int r){
    if(l>=r) return;
    if(l+1==r){
        if((S[l]-'0')%P==0) ans++;
        return;
    }

    int m=(l+r)/2;
    solve(l,m);
    solve(m+1,r);

    map<int,int> mp;
    mp[0]=1;
    int ten=1;
    int pre=0;
    for(int i=m-1;i>=l;i--){
        int now=pre+ten*(S[i]-'0');
        now%=P;
        mp[now]++;

        ten=ten*10%P;
        pre=now;
    }

    int val=0;
    for(int i=m;i<r;i++){
        val=val*10+(S[i]-'0');
        val%=P;

        ll tar=(P-val)%P;
        tar=tar*iten[i-m+1]%P;
        if(mp.count(tar)) ans+=mp[tar];
    }
    return;
}

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

  cin>>N>>P;
  cin>>S;

  if(P==2||P==5){
    ll ans=0;
    for(int i=0;i<N;i++){
      if((S[i]-'0')%P==0) ans+=(i+1);
    }
    cout<<ans<<endl;
    return 0;
  }

  iten[0]=1;
  ll inv=mod_pow(10,P-2,P);
  for(int i=1;i<=N;i++) iten[i]=iten[i-1]*inv%P;

  solve(0,N);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2452
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1]==s[2] && s[2]==s[3]){
        cout<<"No"<<endl;
        return 0;
    }
    if((s[0]==s[1] && s[2]==s[3]) || (s[0]==s[2] && s[1]==s[3]) || (s[0]==s[3] && s[1]==s[2]))cout << "Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
    int gyo,retu;
    cin >> gyo >> retu;
    vector<vector<char>> array(gyo,vector<char>(retu));
    rep(i,gyo){
        rep(j,retu){
            cin >> array[i][j];
        }
    }
    
    bool deleg[gyo],deler[retu];
    rep(i,gyo) deleg[i] = false;
    rep(i,retu) deler[i] = false;
    
    rep(i,gyo){
        rep(j,retu){
            if(array[i][j] == '#'){
                deleg[i] = true;
                break;
            }
        }
    }
    
    rep(i,retu){
        rep(j,gyo){
            if(array[j][i] == '#'){
                deler[i] = true;
                break;
            }
        }
    }
    bool sw = false;
    int size = array.at(0).size();
    rep(i,gyo){
        rep(j,retu){
            if(deleg[i] && deler[j]){
                cout << array[i][j];
                sw = true;
            }
            if(j == size - 1 && sw){
                cout << endl;
                sw = false;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(void){
    // Your code here!
    int n,x,y;  //nはいくつか、x,yはベクトルの要素
    int xi[101], yi[101];
    double p1=0, p2=0, p3=0, infinity=0;   // 求める値、それぞれp＝１のときｐ＝２、ｐ＝３、ｐ＝∞
    cin >> n;
    
    for(int i = 0;i < n; i++){ //xを箱に入力
        cin >> x;
        xi[i] = x;
        
        //cout << "xi[" << i << "] " << int(xi[i]) << endl;
    }
    
    for(int j = 0; j < n;j++){ //yを箱に入力
        cin >> y;
        yi[j] = y;
        //cout << "yi[" << j << "] " << int(yi[j]) << endl;
    }
    
    double z;
    
    for(int k = 0; k < n; k++){
        p1 += abs(xi[k] - yi[k]);
        p2 += abs( (xi[k] - yi[k]) * (xi[k] - yi[k]) );
        p3 += abs( (xi[k] - yi[k]) * (xi[k] - yi[k]) * (xi[k] - yi[k]) );
        
        z = abs(xi[k] - yi[k]);
        if(infinity < z) infinity = abs(xi[k] - yi[k]);   //大きいほうを無限にいれる
    }
    
    printf("%lf\n", p1);
    printf("%lf\n", pow(p2, 1.0/2) );
    printf("%lf\n", pow(p3, 1.0/3) );
    printf("%lf\n", infinity);
    
}



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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl

const long long MOD = 1000000007;


int main(){
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll> > vp(n);
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        vp[i] = make_pair(a, b);
    }
    sort(all(vp), greater<>());
//    rep(i, n){
//        debug(vp[i].first);
//        debug(vp[i].second);
//    }

    ll r = 0;
    priority_queue<ll> q;
    for(int i = 1; i <= m; i++){
        while(!vp.empty() && vp.back().first <= i){
            q.push(vp.back().second);
            vp.pop_back();
        }
        if(!q.empty()) {
            r += q.top();
            q.pop();
        }
    }

    cout << r << endl;
    
    return 0;
}


Measured memory_bytes: 3064
import itertools
n,d = map(int,input().split())
li = [list(map(int,input().split())) for i in range(n)]
nnn = [i for i in range(n)]
cnt = 0
for i,j in itertools.combinations(nnn,2):
  dis = 0
  for di in range(d):
    dis += (li[i][di]-li[j][di])**2
  if int(dis**(1/2))**2 == dis:
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int md=1e9+7,N=2e5+5;
typedef long long LL;
int mn[N],n,X,Y,a[N],w[N],tot[N],fac[N],iv[N],m,s,c=1,k;
inline int pow(int a,int b){int r=1;for(;b;b>>=1,a=(LL)a*a%md)if(b&1)r=(LL)r*a%md;return r;}
int main(){
	scanf("%d%d%d",&n,&X,&Y);
	memset(mn,0x3f,sizeof mn);
	for(int i=*fac=1;i<=n;++i)fac[i]=(LL)fac[i-1]*i%md;
	iv[n]=pow(fac[n],md-2);
	for(int i=n-1;~i;--i)iv[i]=(i+1LL)*iv[i+1]%md;
	for(int i=1;i<=n;++i){
		scanf("%d%d",a+i,w+i);
		mn[a[i]]=min(mn[a[i]],w[i]);
	}
	int ps=min_element(mn+1,mn+n+1)-mn;m=mn[ps];
	mn[ps]=0x3f3f3f3f;
	k=*min_element(mn+1,mn+n+1);
	mn[ps]=m;
	for(int i=1;i<=n;++i)tot[a[i]]+=(mn[a[i]]+w[i]<=X)||((mn[a[i]]==m?k:m)+w[i]<=Y);
	for(int i=1;i<=n;++i)if(mn[i]+m<=Y)s+=tot[i],c=(LL)c*iv[tot[i]]%md;
	c=(LL)c*fac[s]%md;
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string S, T;
	cin >> S >> T;
	int cnt = 0;
	rep(i, 3) {
		if (S[i] == T[i]) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

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

using namespace std;

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(s.substr(0,n/2)==s.substr(n/2,n/2) && (n%2==0))
        cout << "Yes\n";
    else
        cout << "No\n";
}


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

int main() {
	int n;
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++){
	    cin>>a[i]>>b[i];
	}
	int flag=0;
	for(int i=2;i<n;i++){
	    if(a[i]==b[i]&&a[i-1]==b[i-1]&&a[i-2]==b[i-2])
	    {
	        flag=1;
	        break;
	    }
	}
	if(flag){
	    cout<<"Yes\n";
	    
	}
	else{
	    cout<<"No\n";
	}
	return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include <vector>
using namespace std;
int main(){
	int d, n, div_cnt, n_cnt, ans, x;
	cin >> d >> n;
	div_cnt = 0;
	n_cnt = 0;
	for(int i = 1; i <= 100000000000; i++){
		x = i;
		div_cnt = 0;
		if(n_cnt == n){
			ans = x-1;
			break;
		}
		while(x%100 == 0){
			x = x/100;
			div_cnt++;
		}
		if(div_cnt == d){
			n_cnt++;
		}
	}
	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i,j;
  VI v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  k--;
  cout<<v[k]<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

typedef struct count_val {
  i32 cnt;
  i32 val;
} node;

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  node *p = (node *) calloc (n, sizeof (node));
  i64 sum = 0;
  i64 ans = 0;
  i32 len = 0;
  for (i32 i = 0; i < n; ++i) {
    i32 a;
    scanf ("%" SCNi32, &a);
    node t = {1, a};
    while (len > 0 && p[len - 1].val > a) {
      t.cnt += p[--len].cnt;
      sum -= (i64) p[len].cnt * p[len].val;
    }
    p[len++] = t;
    sum += (i64) t.cnt * t.val;
    ans += sum;
  }
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
/*
シカのAtCoDeerくんは二つの正整数 a,b を見つけました。 a と b
の積が偶数か奇数か判定してください。
制約

    
≤ a,b ≤ 10000
a,b
は整数
*/

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string
int digitsum(int a){
  int b=0;
  while(a){
    b+=a%10;
    a/=10;
  }
  return b;
}
signed main(){
  int N,M,O,P=0,c=0,co=0,cou=0,minN=mod;
  double D,Do;
  char C,Ca;
  str S,T;
  cin>>N;
  rep(1,N){
    int j=N-i;
    minN=min(digitsum(i)+digitsum(j),minN);
  }
  cout<<minN<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<iostream>
using namespace std;
const int N=2e5+5,p=1e9+7;
typedef long long ll;
struct node {
    int a,b,c;
    void operator +=(const node &x){
        c=((ll)(a+b+c)*x.c+(ll)(b+c)*x.b+c*(ll)x.a)%p;
        b=((ll)a*x.b+(ll)b*x.a)%p;
        a=(ll)a*x.a%p;
    }
}v;
vector<node> q[N];
int h[N],l[N],r[N],t;
void dfs(int x){
    if(!h[x]){
        q[r[x]=++t].push_back(v);
        return;
    }
    int m=0,y,z;
    for(int i=h[x];i;i=l[i]){
        dfs(i);
        if(i==h[x]){r[x]=r[i];continue;}
        y=q[r[x]].size(),z=q[r[i]].size();
        m=max(m,min(y,z));
        if(y<z) swap(y,z),swap(r[x],r[i]);
        for(int j=1;j<=z;++j)
            q[r[x]][y-j]+=q[r[i]][z-j];
    }
    m=q[r[x]].size()-m;
    for(int j=q[r[x]].size()-1;j>=m;--j){
        q[r[x]][j].a=(q[r[x]][j].a+q[r[x]][j].c)%p;
        q[r[x]][j].c=0;
    }
    q[r[x]].push_back(v);
}
ll P(int y){ll x=2,z=1;for(;y;y>>=1,x=x*x%p) if(y&1) z=z*x%p;return z;}
int main(){
    int n,x,s=0;
    scanf("%d",&n);
    v=(node){p+1>>1,p+1>>1,0};
    for(int i=1;i<=n;++i){
        scanf("%d",&x);
        l[i]=h[x],h[x]=i;
    }
    dfs(0);
    for(int i=q[r[0]].size()-1;i>=0;--i) s=(s+q[r[0]][i].b)%p;
    printf("%d\n",(ll)s*P(n+1)%p);
    return 0;
}

Measured memory_bytes: 23412
import collections 
cnt = collections.Counter({0:1})
n,m = map(int,input().split())
a = [0] + [int(x) for x in input().split()]
ans = 0
for i in range(1,n+1):
    a[i] += a[i-1]
    a[i] %= m
    ans += cnt[a[i]]
    cnt[a[i]]+=1
print(ans)

Measured memory_bytes: 14636
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


def main():
    diff = [A[i] - B[i] for i in range(N)]
    if sum(diff) < 0:
        return(-1)

    diff.sort()

    minus = sum([d for d in diff if d < 0])
    result = len([d for d in diff if d < 0])

    for d in diff[::-1]:
        if minus >= 0:
            break
        minus += d
        result += 1

    return(result)

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 19660
import sys
input = lambda: sys.stdin.readline().rstrip()
n=int(input())
s=0 ; st=set() ; ans=[[] for i in range(n)] ; v=0
def dfs(g,v):
    global s,st,ans
    if v in st: return
    else: st.add(v)
    s+=1
    ans[v].append(s)
    for i in g[v]:
        dfs(g,i)
    s+=1
    ans[v].append(s)
g=[]
for _ in range(n):
    a=[int(i)-1 for i in input().split()]
    if a[1]==-1: g.append([])
    else: g.append(a[2:])
for i in range(n):
    if i in st : continue
    else : dfs(g,i)
for i in range(len(ans)):
    print(i+1,*ans[i])
    
    
    


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

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

    int d[N];
    for (int i=0; i<N; i++) cin >> d[i];

    sort(d,d+N);
    int ans=1;
    for (int i=0; i<N-1; i++){
        if (d[i]!=d[i+1]) ans+=1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import bisect
cnt=0
n=int(input())
a= sorted(list(map(int, input().split())))
b= sorted(list(map(int, input().split())))
c= sorted(list(map(int, input().split())))
ab=[0]*n
bc=[0]*n
for i in range(n):
    bc[i]=bisect.bisect_left(b,c[i]-0.5)
    ab[i]=bisect.bisect_left(a,b[i]-0.5)
for i in range(1,n):
    ab[i]+=ab[i-1]
for i in range(n):
    if bc[i]!=0:
        cnt+=ab[bc[i]-1]
print(cnt)

Measured memory_bytes: 26912
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;

int T[300010], n, m;

void update(int l, int r){
	for(int i=r;i;i-=(i&-i))T[i]++;
	for(int i=l-1;i;i-=(i&-i))T[i]--;
}

int read(int x){
	int res = 0;
	for(int i=x;i<=m;i+=(i&-i))res += T[i];
	return res;
}

void solve(){
	scanf("%d%d", &n, &m);
	Pi p[300010];
	rep(i, n){
		int x, y; scanf("%d%d", &x, &y);
		p[i] = Pi(x, y);
	}
	sort(p, p+n, [&](Pi a, Pi b){
		return (a.Se - a.Fi) < (b.Se - b.Fi);
	});
	for(int i=1, j=0;i<=m;i++){
		while(j < n && p[j].Se - p[j].Fi < i){
			update(p[j].Fi, p[j].Se);
			++j;
		}
		int cnt = n - j;
		for(int k=i;k<=m;k+=i){
			cnt += read(k);
		}
		printf("%d\n", cnt);
	}
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3712
n = gets.to_i
p = gets.split.map(&:to_i)
a = Array.new(n){|i|(i+1)*20010}
b = Array.new(n){|i|(n-i)*20010}
for i in 0..n-1
    a[p[i]-1] += i
end
puts a.join(" "),b.join(" ")

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

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

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

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, k;
  cin >> n >> k;
  int ans = INF;

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

    chmin(ans, (1<<i)+k*(n-i));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <math.h>
#include <iostream>
#include <map>

using namespace std;
using LL = long long;
const int P = (int)1e9 + 7;
const int MAXN = (int)1e5 + 35;
map<int,int> factor;
int jie[MAXN];

void Init(int n) {
  jie[1] = 1;
  for (int i = 2;i <= n; ++i) {
    jie[i] = (LL)jie[i - 1] * i % P;
  }
}

LL Pow(int x, int y) {
  LL res = 1;
  while(y > 0) {
    if (y & 1)
      res = res * x % P;
    x = (LL)x * x % P;
    y >>= 1;
  }
  return res;
}

void Factorization(int m) {
  factor.clear();
  int sq = sqrt(m + 0.5);
  for (int i = 2; i <= sq && i <= m; ++i) {
    while (m % i == 0) {
      factor[i] += 1;
      m /= i;
    }
  }
  if (m > 1)
    factor[m] = 1;
}

LL C(int x, int y) {
  if (x < y) return 0;
  if (y == 0 || y == x) return 1;
  return (LL)jie[x] * Pow(jie[y], P - 2) % P * Pow(jie[x - y], P - 2) % P;
}

LL Solve(int n, int m) {
  Init(n + 35);
  Factorization(m);
  LL res = 1;
  for (auto node : factor) {
    int cur = node.second;
    res = res * C(cur + n - 1, cur) % P;
  }
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  cout << Solve(n, m) << endl;
  return 0;
}


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

using namespace std;
typedef unsigned long long ull;

int main(){
    int N;
    ull A, B;
    cin >> N >> A >> B;
    vector<ull> X(N);
    for(int i=0;i<N;++i){
        cin >> X[i];
    }

    ull cost = 0;
    for(int i=0;i<N-1;++i){
        cost += min(B, (X[i+1] - X[i]) * A);
    }
    cout << cost << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};


int main() 
{
	// ios::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	
	ll n,k;
	cin>>n>>k;
	ll dp[n+1],v[n];
	memset(dp,0,sizeof(dp));
	loop(i,0,n)
		cin>>v[i];
	loop(i,2,n+1){
		dp[i] = LLONG_MAX;
		for(ll j = 1;j<k+1 && i-j>0;j++){
			dp[i] = min(dp[i],dp[i-j] + abs(v[i-1] - v[i-j-1]));
		}
	}

	cout<<dp[n];
}

Measured memory_bytes: 5176
#include <iostream>

using namespace std;

const int N = 1e5 + 7;

long long d[N];

int abs(int val) {
    return max(val, -val);
}

int main()
{
    int n, tw, val, cst;
    cin >> n >> tw;
    for (int i = 0; i < n; ++i) {
        cin >> val >> cst;
        for (int j = tw - val; j >= 0; --j)
            d[j + val] = max(d[j + val], d[j] + cst);
    }
    val = 1, cst = 0;
    for (int j = tw - val; j >= 0; --j)
        d[j + val] = max(d[j + val], d[j] + cst);
        cout << d[tw];
    return 0;
}


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

int mygcd(int a, int b) {
    return b ? mygcd(b, a%b) : a;
}

int main() {
    int n;
    cin >> n;
    int64_t ans = 0;
    for (int a = 1; a <= n; a++) {
        for (int b = 1; b <= n; b++) {
            for (int c = 1; c <= n; c++) {
                ans += mygcd(mygcd(a, b), c);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
S = input()

cnt_0 = 0
cnt_1 = 0

for i in range(len(S)):
    if S[i] == "0":
        cnt_0 += 1
    else:
        cnt_1 += 1

min_num = min(cnt_0, cnt_1)

if len(S) > 1:
    print(min_num * 2)
else:
    print(0)
        


Measured memory_bytes: 3188
#include<stdio.h>
int main(void){
int H,W,h,w;
while(1){
scanf("%d %d",&H,&W);
if(H==0&&W==0)break;
for(h=1;h<=H;h++){
for(w=1;w<=W;w++){
if(h==1||h==H||w==1||w==W)printf("#");
else printf(".");
}
printf("\n");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 1952
"use strict"

function main(input) {
  const N = ~~input
  const cake = 4
  const donut = 7
  // let ans;

  for (let i = 0; i <= Math.floor(N / cake); i++) {
    for (let j = 0; j <= Math.floor(N / donut); j++) {
      if (cake * i + donut * j === N) {
        console.log("Yes")
        return false
      }
    }
  }

  console.log("No")
}

main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 7372
#!/usr/local/gnu/bin/bash
read w
while((${#w}>0))
do
    c=`echo $w | cut -c 1`
    w_next=`echo $w | tr -d $c`
    (((${#w}-${#w_next})%2==0)) && w=$w_next || break
done
((${#w}==0)) && echo "Yes" || echo "No"


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	std::string s;

	std::cin >> s;

	s.push_back('T');

	int t_count = 0;
	int xxx, yyy;

	std::cin >> xxx >> yyy;

	std::map<int, int> x, y;

	int x_count = 0, y_count = 0;
	int init = 1;
	for (size_t i = 0; i < s.length(); i++)
	{
		if (s[i] == 'F') {
			if (t_count == 0) {
				x_count++;
			}
			else {
				y_count++;
			}
		}
		else { // T
			if (init == 1) {
				xxx -= x_count;
				init = 0;
			}
			else if (x_count != 0) {
				x[x_count]++;
			}
			else if (y_count != 0) {
				y[y_count]++;
			}

			t_count = (t_count + 1) % 2;
			x_count = y_count = 0;
		}
	}

	int xx = 0, yy = 0;

	std::vector<long long> v(20000, 0), vv(20000, 0);

	v[10000] = vv[10000] = 1;

	for (auto it = x.rbegin(); it != x.rend(); it++) {
		std::vector<long long> temp = v;
		for (size_t i = 0; i < it->second; i++)
		{
			for (size_t j = 0; j < 20000; j++)
			{
				if (v[j] != 0) {
					temp[j - it->first] = temp[j + it->first] = 1;
					temp[j] = 0;
				}
			}
			v = temp;
		}
	}

	for (auto it = y.rbegin(); it != y.rend(); it++) {
		std::vector<long long> temp = vv;
		for (size_t i = 0; i < it->second; i++)
		{
			for (size_t j = 0; j < 20000; j++)
			{
				if (vv[j] != 0) {
					temp[j - it->first] = temp[j + it->first] = 1;
					temp[j] = 0;
				}
			}
			vv = temp;
		}
	}

	//std::cout << xx << " " << yy << std::endl;

	if (v[xxx + 10000] == 1 && vv[yyy + 10000] == 1) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	
	return 0;

}


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

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

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int main() {
    int a = iin(), b = iin();
    if (a < b) {
        stout("a < b");
    } else if (a == b) {
        stout("a == b");
    } else if (a > b) {
        stout("a > b");
    }
    return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;

int main (){
    int k;
    
    VI a(5);
    for(int i=0; i<5 ;++i)cin >> a[i];
    cin >>k;
    for(int i=0; i<4; ++i){
        for(int j=i+1; j<5 ; ++j){
            if(abs(a[i] - a[j])>k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }

    cout << "Yay!" << endl;
    return 0;
}

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

int main(void){
  while(true){
    int n;
    cin >> n;
    if(n == 0){ break; }

    int t, b;
    vector<pair<int, int> > oldbridges;
    for(int i = 0; i < n; i++){
      cin >> t >> b;
      oldbridges.push_back(make_pair(b, t));
    }

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

    int sum = 0;
    bool flag = true;
    for(int i = 0; flag && i < n; i++){
      sum += oldbridges[i].second;
      flag = (sum <= oldbridges[i].first);
    }

    if(flag){ cout << "Yes" << endl; }
    else{ cout << "No" << endl; }
  }

  return 0;
}



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

int main()
{
    long int N;
  cin>>N;
  
  long int A[N],i,f=0;
  for(i=0;i<N;++i)
  {
  cin>>A[i];
    
  }
  
  for(i=0;i<N;++i)
  {
  if(A[i]%2==0)
  {
  if(A[i]%3==0||A[i]%5==0)
  {
    f=0;
  }
else
{f=1;
break;
}
  }
  }
  
  if(f==0)
  {cout<<"APPROVED"<<endl;
  }
  else
  {cout<<"DENIED"<<endl;
  }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    int ans = (k / 2) * ((k + 1) / 2);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;


int main(void)
{
	int N, M; cin >> N >> M;
	lli X = (1900 * M + 100 * (N - M))*pow(2, M);
	cout << X << endl;

	return 0;
}

Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let l: u64 = sc.read();
    let v = l * l * l;
    println!("{}", (v as f64) / 27.0);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	s := nextMega()
	var l, r int

	for l = 0; s[l] != 'A'; l++ {
	}
	for r = len(s) - 1; s[r] != 'Z'; r-- {
	}

	puts(r - l + 1)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static final long MAX_POINT = 1000000000L;

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		long S = sc.nextLong();

		if(S <= MAX_POINT) {
			System.out.println(0 + " " + 0 + " " + 1 + " " + 0 + " " + 0 + " " + S);
		}else {
			long x3 = -1;
			long y3 = -1;
			int i=0;
			while(x3 < 0 || y3 < 0) {
				y3 = (S / MAX_POINT) + i;
				x3 = (MAX_POINT * y3) - S;
				i++;
			}
			System.out.println(0 + " " + 0 + " " + MAX_POINT + " " + 1 + " " + x3 + " " + y3);
		}
	}

}


Measured memory_bytes: 21844
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
    val s = (0 until h).map { sc.next().toCharArray() }
    println(problem043a(h, w, s))
}

fun problem043a(h: Int, w: Int, s: List<CharArray>): Int {
    val dx = arrayOf(1, 0)
    val dy = arrayOf(0, 1)

    var res = 0
    val dist = Array(h) { Array(w) { -1 to 0 } }
    val queue = ArrayDeque<Pair<Int, Int>>()
    queue.offer(0 to 0)
    dist[0][0] = 0 to if (s[0][0] == '#') 1 else 0

    while (!queue.isEmpty()) {
        val current = queue.poll()

        val (x, y) = current
        for (direction in 0 until 2) {
            val nextX = x + dx[direction]
            val nextY = y + dy[direction]
            if (nextX >= h || nextY >= w) continue
//            debugLog(x, y, dist[x][y], nextX, nextY, dist[nextX][nextY])
            if (dist[nextX][nextY].first == -1 || dist[x][y].second < dist[nextX][nextY].second) {
                queue.offer(nextX to nextY)
                dist[nextX][nextY] = dist[x][y].first + 1 to if (s[x][y] != '#' && s[nextX][nextY] == '#') dist[x][y].second + 1 else dist[x][y].second
            }
        }
    }
//    dist.forEach { it.forEach { print(it) }; println() }
    return dist[h - 1][w - 1].second
}

Measured memory_bytes: 36220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n;
    cin >> n;
    int ans=1000-n%1000;
    if(n%1000==0) ans=0;
    cout << ans << endl;
    return 0;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  REP(i, N){
    cin >> d[i];
  }
  int ans = 0;
  REP(i, N-1){
    FOR(j, i+1, N){
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def is_in(min, i, max):
    if i < min:
        ret = False
    elif max <= i:
        ret = False
    else:
        ret = True
    return ret


def main():
    height, width = map(int, input().split())

    matrix = []
    for i in range(height):
        temp_s = input()
        matrix.append(list(temp_s))

    ans_matrix = []
    for i in range(height):
        temp_row = []
        for j in range(width):
            if matrix[i][j] == '#':
                string = '#'
            else:
                count = 0
                for x in range(-1, 2, 1):
                    for y in range(-1, 2, 1):
                        if x == 0 and y == 0:
                            continue

                        if is_in(0, i+x, height) and is_in(0, j+y, width):
                            temp = matrix[i+x][j+y]
                            if temp == '#':
                                count += 1
                string = str(count)
            temp_row.append(string)
        ans_matrix.append(temp_row[:])
    for i in range(height):
        print(''.join(ans_matrix[i]))
    print()


if __name__ == '__main__':
    main()


Measured memory_bytes: 42736
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MX 100005
ll dp[MX][101];
int wt[101], val[101];
int main() {
	int n, w;
	cin >> n >> w;
	for (int i = 1; i <= n; ++i)
			cin >> wt[i] >> val[i];
    for(int i = 1; i <= n; ++i) {
    	for (int j = 1; j <= w; ++j) {
             if(wt[i] > j)
                dp[j][i] = dp[j][i - 1];
             else
             	dp[j][i] = max(dp[j][i - 1], val[i] + dp[j - wt[i]][i - 1]);
    	}
    }
    cout << dp[w][n] << endl;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, a[4];
string s;
int main() {
    cin >> n;
    while (n--) {
        cin >> s;
        switch (s[0]) {
            case 'A': a[0]++; break;
            case 'W': a[1]++; break;
            case 'T': a[2]++; break;
            case 'R': a[3]++; break;
        }
    }
    cout << "AC x " << a[0] << "\n";
    cout << "WA x " << a[1] << "\n";
    cout << "TLE x " << a[2] << "\n";
    cout << "RE x " << a[3] << "\n";
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

bool is_ok(int t_diff, int d);

int main() {
  int n;
  cin >> n;
  int t[100001];
  int x[100001];
  int y[100001];

  t[0] = x[0] = y[0] = 0;
  // 入力
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> x[i] >> y[i];

  }
  // 確認
  for (int i = 0; i <= n-1; i++) {
    int t_diff, x_diff, y_diff;
    t_diff = t[i+1] - t[i];
    x_diff = x[i+1] - x[i];
    y_diff = y[i+1] - y[i];
    int d = abs(x_diff) + abs(y_diff);
    //cout << i << "," << t[i+1] << "," << t[i] << "," << t_diff << "," << d << "----" << endl;
    if (!is_ok(t_diff, d)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

bool is_ok(int t_diff, int d) {
  if (d > t_diff) {
    return false;
  }
  if (d % 2 != t_diff % 2) {
    return false;
  }
  return true;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<cmath>
#define MAX_LEN 200000

int main(){
    int n, i, d;
    long long c;
    long long sum = 0, digit_num=0;

    int check = scanf("%d", &n);

    for(i=0;i<n;i++){
        int check = scanf("%d %lld", &d,&c);
        sum += d * c;
        digit_num += c;
    }

    long long reduction_num = (sum-1) / 9;
    printf("%lld\n", digit_num - 1 + reduction_num);
    return 0;
}

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

int main(){
    int n;cin>>n;
    string s;cin>>s;
    int count,count_b,count_a;
    count=count_b=count_a=0;
    for(int i=0;i<n;i++){
        if(s[i]=='(') count++;
        else{
            if(count==0) count_b++;
            else count--;
        }
    }
    count=0;
    for(int i=n-1;i>=0;i--){
        if(s[i]==')') count++;
        else{
            if(count==0) count_a++;
            else count--;
        }
    }
    for(int i=0;i<count_b;i++) cout<<'(';
    cout<<s;
    for(int i=0;i<count_a;i++) cout<<')';
    cout<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int MAX = 1e6;
int N, M;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<int, int> prime_factor(int n) {
  map<int, int> ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}



int main() {
  INCANT;
  cin >> N >> M;
  if (M==1) {
    cout << 1 << endl;
    return 0;
  }
  COMinit();
  map<int, int> pf = prime_factor(M);

  ll ans = 1ll;
  for (auto p: pf) {
    ans*=COM(p.second+N-1, p.second);
    ans%=MOD;
  }

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

Measured memory_bytes: 27052
#include <iostream>

/// Calculate a^n in mod
long long modpow(int a, int n, int mod) {
  long long res = 1;
  long long apow = a; // a^1, a^2, a^4, ...
  while (n) {
    if (n & 1)
      res = (res * apow) % mod;
    apow = apow * apow % mod;
    n = n >> 1;
  }
  return res;
}

int main() {
  int m, n;
  std::cin >> m >> n;
  int MOD = 1000000007;
  std::cout << modpow(m, n, MOD) << std::endl;
}



Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
		if(a==0 && b==0) 	break;
			
			if(a>b)
				System.out.printf("%d %d\n",b,a);
			else
				System.out.printf("%d %d\n",a,b);
			
		}
	}
}



Measured memory_bytes: 41900
#include<bits/stdc++.h>
using namespace std;
#pragma 03
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef pair<int,int> ii ;
typedef vector<int> vi ;
 
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ll long long
#define rep(i,a,n) for(int i = a ; i <= n ; i++ )
#define REP(i,a,n) for(int i = n ; i >= a ; i-- )
#define fi first
#define se second
const int N = 1e5+5 ;
const int mod = 1e9+7 ;
#define int long long
int n,m,t,ans[N] ;
pair<int , long long> a[N] ; 
signed main() {
	//freopen("BIGNUM.inp","r",stdin);
	//freopen("BIGNUM.out","w",stdout);
	cin >> n ;
	rep(i,1,n) {
		cin >> a[i].fi ;
		a[i].se = i ; 
	}
	sort(a+1,a+n+1) ;
	a[0].fi = 0 ; 
	a[0].se = 0 ;
	int j = n,idx=a[n].se ; 
	while(j>0) {
		int i ; 
		for(i = j ; i > 0 && a[i].fi == a[j].fi ; i-- ) {
			idx = min(idx,a[i].se) ;  
		}
		int cnt = n-i ; 
		ans[idx] += cnt*(a[i+1].fi-a[i].fi) ;
		j = i ; 
	} 
	rep(i,1,n) cout << ans[i] << endl ; 
}
 

Measured memory_bytes: 5928
#include <cstdio>

const int MAXN = (1<<16);
const int MOD = int(1E9) + 7;

int pow_mod(int b, int p) {
	int ret = 1;
	while( p ) {
		if( p & 1 ) ret = 1LL*ret*b%MOD;
		b = 1LL*b*b%MOD;
		p >>= 1;
	}
	return ret;
}

int fct[MAXN + 5], ifct[MAXN + 5];
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAXN;i++)
		fct[i] = 1LL*fct[i-1]*i%MOD;
	ifct[MAXN] = pow_mod(fct[MAXN], MOD - 2);
	for(int i=MAXN-1;i>=0;i--)
		ifct[i] = 1LL*ifct[i+1]*(i+1)%MOD;
}
int comb(int n, int m) {
	return 1LL*fct[n]*ifct[m]%MOD*ifct[n-m]%MOD;
}

int f[MAXN + 5], dp[MAXN + 5];
int lowbit(int x) {
	return x & -x;
}

int A[16], N, M, t;
int main() {
	init();
	scanf("%d%d", &N, &M), t = (1 << N);
	for(int i=0;i<M;i++)
		scanf("%d", &A[i]);
	dp[0] = f[0] = 1;
	for(int i=1;i<t;i++)
		f[i] = 1LL*comb(i, lowbit(i))*f[i^lowbit(i)]%MOD;
	for(int i=M-1;i>=0;i--) {
		for(int s=t-1;s>=0;s--) {
			int p = (t - A[i]) - s;
			for(int j=0;j<N;j++) {
				int q = (1 << j);
				if( !(s & q) && p >= q - 1 )
					dp[s|q] = (dp[s|q] + MOD - 1LL*dp[s]*comb(p,q-1)%MOD) % MOD;
			}
		}
	}
	int ans = 0;
	for(int i=0;i<t;i++) ans = (ans + 1LL*dp[i]*f[t-1-i]%MOD) % MOD;
	for(int i=0;i<N;i++) ans = 1LL*ans*fct[1 << i] % MOD;
	printf("%lld\n", 1LL*ans*t%MOD);
}

Measured memory_bytes: 1152