akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
const ld pi=3.141592653589793238;

const ll N=2e5+5;
char s[N],res[N];

void func()
{
  ll n;
  cin>>n;
  ll cnt1=0,cnt2=0;
  f(i,1,n+1) 
  {
    cin>>s[i];
    if(s[i]=='R') cnt1++;
    else cnt2++;
  }
  f(i,1,cnt1+1) res[i]='R';
  f(i,cnt1+1,n+1) res[i]='W';
  ll ans=0;
  f(i,1,n+1) if(s[i]!=res[i]) ans++;
  ans/=2;
  cout<<ans<<"\n";
}   
     
     
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
       //cout<<"Case #"<<i<<": ";
       //cout<<"\n";
       func();
    }
     
    return 0;
}


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

ll lcm(ll x,ll y)
{
    return (x*y)/__gcd(x,y);
}
int main()
{
    ll x;
    cin>>x;
    ll res=0;
    if(x>=500)
    {
        ll y=x/500;
        res+=y*1000;
        x%=500;
    }
    if(x>=5)
    {

        ll y=x/5;
        res+=y*5;

    }
    cout<<res<<endl;
 return 0;
}


Measured memory_bytes: 256
/*
 * I'm strong. Stronger than all of you. Extremely strong.
 * I can kill all those Titans there. Even if I'm alone.
 * You're either incompetent or you're spineless cowards.
 * How pathetic.
 * You can sit here and suck on your fingers. Yeah, do that.
 * ~ Mikasa Ackerman
 */

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)

#define endl '\n'

int main() {
  fast_io;
  vector<LL> luc(100, 0);
  luc[1] = 1;
  luc[0] = 2;
  for (int i = 2; i < 100; i++)
    luc[i] = luc[i - 1] + luc[i - 2];
  int n;
  cin >> n;
  cout << luc[n] << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
write = sys.stdout.write
n = input()
i = 1
while i <= n:
	if i % 3 == 0:
		write(' ' + str(i))
	elif i % 10 == 3:
		write(' ' + str(i))
	else:
		j = i
		while j > 0:	
			j /= 10
			if j % 10 == 3:
				write(' ' + str(i))
				break;
	i += 1
print \

Measured memory_bytes: 4216
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>

using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	int ans[n];
	ans[0] = 2;

	int sq = sqrt(55555);
	int now = 1;
	for (int i = 11; i < 55555; i = i+10) {
		bool prime = true;
		for (int j = 2; j <= sqrt(i); j++) {
			if(i % j == 0){
				prime = false;
				break;
			}
		}
		if(prime) {
			ans[now] = i;
			now++;
		}
		if (now == n) {
			for (int i = 0; i < n; i++) {
				cout << ans[i] << " ";
			}
			return 0;
		}
	}
	cout << "error";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define mx          1000000000000000000
ll a[200010], res=0;

ll jogmod(ll a, ll b)
{
    if(b==0LL) return 0LL;
    ll x=jogmod(a, b/2);
    x=2*x;
    if(x>mx)
    {
        res=-1;
        return 0LL;
    }
    if(b%2)
    x=a+x;
    if(x>mx)
    {
        res=-1;
        return 0LL;
    }
    return x;
}

int main()
{
    ll t,n,i,j,k,l,mn=0,  cnt=0, ans=1;


    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]==0)
            cnt++;
    }
    if(cnt>0)
        cout<<0<<endl;
    else
    {
        for(int i=0; i<n; i++)
            ans=jogmod(ans, a[i]);
        if(res==-1)
            ans=-1;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 4360
#include <bits/stdc++.h>
#define f first
#define s second
#define INF 1e9
using namespace std;
typedef pair <double,double> P;
P dp[1<<15][15];

double get_time(double a,double b,double w){
  return abs(a-b)/(2000/(70+20*w));
}

int main(){
  int n,num[15];
  cin>>n;

  P x[15];
  for(int i=0,b,c;i<n;i++)cin>>num[i]>>b>>c,x[i]=P(b,c);
  
  for(int i=0;i<(1<<15);i++)for(int j=0;j<15;j++)dp[i][j]=P(INF,INF);
  for(int i=0;i<n;i++)dp[1<<i][i]=P(0,x[i].s);
  
  for(int i=0;i<(1<<n);i++)
    for(int k=0;k<n;k++){
      if(dp[i][k].f==INF)continue;
      for(int j=0;j<n;j++){
	if((i&(1<<j))) continue;
	int ni=i|(1<<j);
	double nw=dp[i][k].s+x[j].s;
	double nt=dp[i][k].f+get_time(x[k].f,x[j].f,dp[i][k].s);
	dp[ni][j]=min(dp[ni][j],P(nt,nw));
      }
    }

  
  vector <int> ans;
  int bit=(1<<n)-1;
  int na;
  P mnt=P(INF,INF);
  for(int i=0;i<n;i++) if(dp[bit][i]<mnt)mnt=dp[bit][i],na=i; 
  ans.push_back(na);
  bit-=(1<<na);
  
  while(bit){
    int nna;
    for(int i=0;i<n;i++){
      if((bit&(1<<i))==0)continue;
      int ni=bit|(1<<na);
      double nw=dp[bit][i].s+x[na].s;
      double nt=dp[bit][i].f+get_time(x[i].f,x[na].f,dp[bit][i].s);
      if(dp[ni][na]==P(nt,nw))nna=i;
    }
    na=nna;
    ans.push_back(na);
    bit-=(1<<na);
  }
  
  reverse(ans.begin(),ans.end());
  for(int i=0;i<n-1;i++) cout << num[ans[i]]<<" ";
  cout << num[ans[n-1]]<<endl;
  return 0;
}

Measured memory_bytes: 8896
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	string s;
	cin >> s;
	int n = SZ(s);
	LL ans = 0;
	REP(i,1<<(n-1)){
		LL num = 0;
		REP(j,n){
			num *= 10;
			num += s[j]-'0';
			if((i>>j)&1){
				ans += num;
				num = 0;
			}
		}
		ans += num;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#define siz 100005
const int maxn = 100000;
typedef long long LL;
using namespace std;
struct Edge{
   int to,w,next;
}edges[maxn*3];
int n,tot,q,k;
int head[maxn+5];
LL d[maxn+5];
void Addedge(int x,int y,int w)
{
    edges[++tot].to = y, edges[tot].w = w;
    edges[tot].next = head[x], head[x] = tot;
}
void dfs(int x,int fa)
{
    for(int i=head[x];i!=-1;i=edges[i].next)
    {
        int to = edges[i].to;
        if(to==fa) continue;
        d[to] = d[x] + edges[i].w*1ll;
        dfs(to,x);
    }
}
void Init()
{
    d[k] = 0;
    dfs(k,-1);
}
int main()
{
    int x,y,w;
    while(~scanf("%d",&n))
    {
        tot = 0;
        for(int i=1;i<=n;i++) head[i] = -1;
        for(int i=1;i<n;i++)
        {
            scanf("%d %d %d",&x,&y,&w);
            Addedge(x,y,w);
            Addedge(y,x,w);
        }
        scanf("%d %d",&q,&k);
        Init();
        for(int i=1;i<=q;i++)
        {
            scanf("%d %d",&x,&y);
            LL ans = d[x] + d[y];
            cout<<ans<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(c - (a - b), 0) << endl;
}

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

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        long x = sc.nextLong();
        long k = sc.nextLong();
        long d = sc.nextLong();

        if (x == 0) {
            System.out.println(k % 2 == 0 ? 0 : d);
            return;
        }

        long maxCount = Math.abs(x / d);
        long absD = x < 0 ? -d : d;
        if (maxCount >= k) {
            debug(1);
            System.out.println(Math.abs(x - k * absD));
        } else {
            long nokori = k - maxCount;
            if (nokori % 2 == 0) {
                debug(3);
                System.out.println(Math.abs(x % d));
            } else {
                debug(4);
                System.out.println(Math.abs(x % d - absD));
            }
        }
        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 35812
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int h,n; cin>>h>>n;
	int a,ret=0; 
	for (int i=0; i<n; i++)
		cin>>a, ret+=a;
	cout<<((h<=ret)?"Yes":"No");
	return 0;
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    ll N, K; cin >> N >> K;
    map<ll,ll> mp;
    REP(i, K){
        ll d; cin >> d;
        REP(j, d) {
            ll tmp; cin >> tmp;
            mp[tmp]++;
        }
    }
    cout << N - mp.size() << endl;
    return 0;
}


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

int main(){
  int n, m, a, b;
  cin >> n >> m;
  vector<int> city(n+1,0);
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    city[a]++;
    city[b]++;
  }
  for(int i = 1; i < n+1; i++){
    cout << city[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll h,w,n,sr,sc;
  string s,t;
  bool can = true;
  cin >> h >> w >> n >> sr >> sc >> s >> t;
  sr--;
  sc--;
  ll l=0,r=w;
  if(s.back()=='L') l++;
  if(s.back()=='R') r--;
  for(int i=n-2;i>=0;i--){
    if(t[i]=='L') r = min(r+1,w);
    if(t[i]=='R') l = max(0ll,l-1);

    if(s[i]=='L') l++;
    if(s[i]=='R') r--;
    if(l>=r) can = false;
  }
  if(l>sc||sc>=r) can = false;
  l=0,r=h;
  if(s.back()=='U') l++;
  if(s.back()=='D') r--;
  for(int i=n-2;i>=0;i--){
    if(t[i]=='U') r = min(r+1,h);
    if(t[i]=='D') l = max(0ll,l-1);

    if(s[i]=='U') l++;
    if(s[i]=='D') r--;
    if(l>=r) can = false;
  }
  if(l>sr||sr>=r) can = false;

  if(can) cout <<"YES\n";
  else cout <<"NO\n";
}


Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n;cin >> n;
    vl d(n);
    set<ll> st;
    st.ins(0);
    rep(i,n){
        cin >> d[i];
        if(d[i]==0)cout<< 0 <<endl,exit(0);
        if(d[i]==12){
            if(!st.count(d[i])){
                st.ins(d[i]);
                continue;
            }
            else{
                cout<< 0 <<endl,exit(0);
            }
        }
        else{
            if(!st.count(d[i])){
                st.ins(d[i]);
                continue;
            }
            if(st.count(d[i])&&!st.count(24-d[i])){
                st.ins(24-d[i]);
                continue;
            }
            if(st.count(24-d[i])){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    set<ll> tt;
    ll cnt=0;
    for(auto p:st){
        if(st.count(p)&&st.count(24-p))tt.ins(p);
        else {
            if(cnt%2==0)tt.ins(p);
            else tt.ins(24-p);
            cnt++;
        }
    }
    ll pre,res=inf;
    for(auto p:tt){
        if(p)chmin(res,p-pre);
        pre=p;
    }
    chmin(res,24-*tt.rbegin());
    cout << res <<endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 
typedef long double ld; 


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

    
  int h,w;
  cin>>h>>w;

  vector <string> vec(h);

  for(int i=0;i<h;i++)
  {
      cin>>vec[i];
  }

  vector < vector <int> > dp(h, vector <int>(w,1e9+5));

  dp[h-1][w-1] = 0;

  for(int i=h-1;i>=0;i--)
  {
      for(int j=w-1;j>=0;j--)
      {
          if(i==h-1 && j==w-1)
          {
              continue;
          }
          if(i!=h-1)
            dp[i][j] = min(dp[i][j],dp[i+1][j]+((vec[i][j]=='.')&&(vec[i+1][j]=='#')));
          if(j!=w-1)
            dp[i][j] = min(dp[i][j],dp[i][j+1]+((vec[i][j]=='.')&&(vec[i][j+1]=='#')));
          
      }
  }

  cout<<dp[0][0]+(vec[0][0]=='#')<<endl;


}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
typedef long long ll;
 
const int M = 1000000007;
 
int main()
{
    int n,k; cin>>n>>k;
 
    vector<ll> v(n);
    for(int i=0;i<n;++i) cin>>v[i];
 
    ll prod=1;
 
    sort(v.begin(),v.end());
 
    if(v[n-1]==0 && (k&1))
    {
        prod=0;
    }
    else if(v[n-1]<0 && (k&1))
    {
        for(int i=n-1;i>=n-k;--i) prod=((prod%M)*(v[i]%M))%M;
    }
    else{ 
        int i=0,j=n-1;
        if(v[n-1]>0 and k&1){ 
            prod = (prod*v[j])%M;
            k--;
            j--;
        }
    
    k=(k/2);
    for(int it=0;it<k;++it)
    {
        ll left_prod = v[i]*v[i+1];
        ll right_prod = v[j]*v[j-1];
 
        if(left_prod > right_prod)
        {
            prod = ((prod%M)*(left_prod%M))%M;
            i+=2;
        }
        else{
            prod = ((prod%M)*(right_prod%M))%M;
            j-=2;
        }
    }
    }
    prod = (prod + M)%M;
    cout<<prod;
}

Measured memory_bytes: 4840
// DP

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

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

long long dp[100010][3];

int main() {
  int n; cin >> n;
  int A[100010][3];
  rep(i,n) cin >> A[i][0] >> A[i][1] >> A[i][2];


  for (int i = 0; i < n; i++) {
    for(int j = 0; j < 3; j++) {
      for(int k = 0; k < 3; k++) {
        if(j != k)
        chmax( dp[i+1][k], dp[i][j] + A[i][k] );
      }
    }
  }
  cout << max( dp[n][0], max(dp[n][1],dp[n][2]) ) << endl;  
}

Measured memory_bytes: 7144
/*
[aising2019] C - Alternating Path
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_H = 400;
const int MAX_W = 400;

int H, W;
string S[MAX_H];
bool visited[MAX_H][MAX_W];

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

pii dfs(int h, int w) {
    if (visited[h][w]) {
        return {0, 0};
    }
    visited[h][w] = true;

    pii ret = ((S[h][w] == '#') ? pii{1, 0} : pii{0, 1});
    for (int k = 0; k < 4; k++) {
        if (0 <= h + dh[k] && h + dh[k] < H && 0 <= w + dw[k] &&
            w + dw[k] < W && S[h + dh[k]][w + dw[k]] != S[h][w]) {
            pii p = dfs(h + dh[k], w + dw[k]);
            ret.first += p.first;
            ret.second += p.second;
        }
    }

    return ret;
}

ll solve() {
    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            pii p = dfs(i, j);
            ans += 1LL * p.first * p.second;
        }
    }

    return ans;
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    cout << solve() << endl;

    return 0;
}


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


char grid[110][110];
int dp[110][110];
const int INF=INT_MAX;

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

int main(){
  int h,w;
  cin>>h>>w;
  rep(i,h)rep(j,w){
    cin>>grid[i][j];
    dp[i][j]=INF;
  }
  if(grid[0][0]=='#') dp[0][0]=1;
  else dp[0][0]=0;
  rep(i,h)rep(j,w){
    if(i==0&&j==0) continue;
    if(i==0){
      dp[i][j]=dp[i][j-1];
      if(grid[i][j]!=grid[i][j-1]) dp[i][j]++;
    }
    else if(j==0){
      dp[i][j]=dp[i-1][j];
      if(grid[i][j]!=grid[i-1][j]) dp[i][j]++;
    }else{
      int x = dp[i-1][j] + (grid[i][j]!=grid[i-1][j]);
      int y = dp[i][j-1] + (grid[i][j]!=grid[i][j-1]);
      dp[i][j]=min(x,y);
    }
  }
  if(grid[h-1][w-1]=='#') dp[h-1][w-1]++;
  cout<<(dp[h-1][w-1])/2<<endl;
}

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

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


int main(){
  cin >> n;
  int i,cnt = 0;
  for( i = 0; i < n; i++ ) cin >> A[i];
  int t; cin >> t;
  for( i = 0; i < t; i++ ){
    int q; cin >> q;
    if( binarySearch(q) ) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1548
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(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;

int H, W, N;

int main() {
	scanf("%d%d%d", &H, &W, &N);
	set <pii> Sx;
	for(int i=1;i<=N;i++) {
		int x, y; scanf("%d%d", &x, &y);
		Sx.insert(pii(x, y));
	}
	for(int i=1;i<=H+1;i++) Sx.insert(pii(i, W + 1));
	for(int i=1;i<=W;i++) Sx.insert(pii(H + 1, i));
	int c = 1;
	for(int i=1;i<=H+1;i++) {
		auto it = Sx.upper_bound(pii(i, -1));
		if(it->Fi == i && it->Se < c) {
			printf("%d\n", i - 1);
			return 0;
		}
		if(it->Fi == i && it->Se == c);
		else ++c;
	}
	return 0;
}


Measured memory_bytes: 28416
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    H, W = il()
    C = [iss() for _ in range(H)]

    for c in C:
        for _ in range(2):
            print(c)




if __name__ == '__main__':
    main()


Measured memory_bytes: 10056
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pair<int,int>> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(a) scanf("%d", &a)
#define rii(a,b) scanf("%d %d", &a, &b)
#define riii(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define rl(a) scanf("%lld", &a)
#define rll(a,b) scanf("%lld %lld", &a, &b)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second

const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int maxN = 1e5+10; // CAMBIAR ESTE

// GJNM
int father[maxN], siz[maxN];


// n es el primer elemento y m el ultimo, por ejemplo los nodos de un grafo desde el 1 al 10
void makeSet(int n, int m)
{
	for (int i = n; i <= m; ++i)
	{
		father[i] = -1;
		siz[i] = 0;
	}
}

int find(int x)
{
	if (father[x]==-1) return x;

	return father[x] = find(father[x]);
}

void unio(int x, int y)
{
	if (siz[x] > siz[y]) father[y] = x;
	else
	{
		father[x] = y;
		if ( siz[x] == siz[y] ) siz[y]++;
	}
}

int A[maxN];

int main(){
	int n,m;
	rii(n,m);
	FOR(i,0,n){
		int aux;
		ri(aux);
		A[aux] = i+1;
	}
	makeSet(1,n);
	FOR(i,0,m){
		int x,y;
		rii(x,y);
		x = find(x);
		y = find(y);
		if ( x != y )
			unio(x,y);
	}
	int ans = 0;
	ROF(i,n,0){
		if ( find(A[i]) == find(i) ){
			ans++;
		}
	}
	printf("%d\n",ans );
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll n,t,s=0;
  cin>>n>>t;
  ll a[n];
  for(int i=0;i<n;i++)
    {
      cin>>a[i];
    }
    for(int i=1;i<n;i++)
    {
        s+=min(t,a[i]-a[i-1]);
    }  
    cout<<s+t<<endl;

}
return 0;
}

Measured memory_bytes: 1792
n = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans_num = 0
ans_val = T - H[ans_num] * 0.006 - A
if ans_val < 0:
    ans_val *= -1
for i in range(1, len(H)):
    tmp = T - H[i] * 0.006 - A
    if tmp < 0:
        tmp *= -1
    if tmp < ans_val:
        ans_val = tmp
        ans_num = i
print(ans_num + 1)


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int mod = 1e9+7;

void add(int &a, int b) {
 	a += b;
 	if(a >= mod) a -= mod;
 }

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

  int H, W; cin >> H >> W;
  vector<string> a(H);
  rep(i, H) cin >> a[i];
  int dp[1100][1100] = {};
  dp[0][0] = 1;

  rep(i, H) rep(j, W) {
    if(i+1 < H && a[i+1][j] == '.') add(dp[i+1][j], dp[i][j]);
    if(j+1 < W && a[i][j+1] == '.') add(dp[i][j+1], dp[i][j]);
  }

  cout << dp[H-1][W-1] << '\n';
  return 0;
}


Measured memory_bytes: 6016
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

template <class T>
bool contain(const std::string &s, const T &v)
{
  return s.find(v) != std::string::npos;
}

int main()
{
  int n;
  cin >> n;
  string str = to_string(n);
  if (contain(str, "7"))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3132
import sys
INF = 10 ** 10
MOD = 10 ** 9 + 7
from collections import deque

def main():
    d = int(input())
    ans = ['Christmas']
    for i in range(d,25):
        ans.append('Eve')
    print(' '.join(ans))
if __name__ =='__main__':
    main()    

Measured memory_bytes: 3700
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;
void solve();
int main() {
	solve();
#ifdef DBG
	while (true);
#endif // DBG
}

void solve() {
	int A, B, C;
	ll K;
	scanf("%d %d %d %lld", &A, &B, &C, &K);

	if (K & 1)
		printf("%d\n", B - A);
	else
		printf("%d\n", A - B);
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int A = sc.nextInt();
      int B = sc.nextInt();
      double T = sc.nextInt();
      int time = 0 + A;
      int output = 0;
      while((T + 0.5) >= time){
        output += B;
        time += A;
      }
      System.out.println(output);
	}
}


Measured memory_bytes: 21588
#include<iostream>
#include<numeric>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    vector<vector<ll>> dp(100005,vector<ll>(2));
    dp[0][1]=-1e9;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i]);
        dp[i+1][1]=max(dp[i][0]-a[i],dp[i][1]+a[i]);
    }
    cout<<dp[n][0]<<endl;
}

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

int n;
int a[200010];

int main()
{int i,j,k,s;
 
 scanf("%d",&n);
 for(i=1;i<=n;i++) scanf("%d",&a[i]);
 sort(a+1,a+n+1);
 k=0;
 for(i=2;i<=n;i++)
 	if(a[i]!=a[1])
 	{	k=i;
 		break;
 	}
 if(k==0)
 {	if(a[1]==n-1)
 		printf("Yes\n");
	else if(a[1]*2<=n)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
 }
 for(i=k+1;i<=n;i++)
 	if(a[i]!=a[k])
	{	printf("No\n");
		return 0;
	}
 if(a[k]!=a[1]+1)
 {	printf("No\n");
 	return 0;
 }
 s=a[k]-(k-1);
 if(s>0 && s*2<=(n-k+1))
 	printf("Yes\n");
 else
 	printf("No\n");
 return 0;
}

Measured memory_bytes: 640
def main():
    a = list(map(int, input().split()))
    a1, a2 = a[1] - a[0], a[2] - a[1]

    b = list(map(int, input().split()))
    b1, b2 = b[1] - b[0], b[2] - b[1]

    c = list(map(int, input().split()))
    c1, c2 = c[1] - c[0], c[2] - c[1]

    if a1 == b1 == c1 and a2 == b2 == c2:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
    main()

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(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;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

mint mpow(int x, int n){
  if(n==0)return 1;

  mint y = mpow(x, n/2);
  y *= y;

  if(n%2==1) y *=x;
  return y;
}

int main(){
  int n,m;
  ll k;
  cin >> n >> m >> k;

  mint ans = 0;
  mint col = mpow(m-1, n-k-1) * m;

  for(int i=k; i >=0; i--){
    ans += col * c(n-1,i);
    col *= (m-1);
  }
  cout << ans.x << endl;
}



Measured memory_bytes: 6256
d,g = map(int, input().split())
pc = list(list(map(int,input().split())) for _ in range(d))
ans = float("inf")
          
for i in range(1<<d):
    count = 0
    sum = 0
    nokori = set(range(1, d+1))
    
    # ボーナスをもらえる解答のみでスコアを計算
    for j in range(d):
        if i & 1<<j:
            sum += pc[j][0]*(j+1)*100+pc[j][1]
            count += pc[j][0]
            nokori.discard(j+1)
            
    # スコアがG点に届かない場合
    if sum < g:
        use = max(nokori)
        n = min(pc[use-1][0], -(-(g-sum)//(use*100)))
        count += n
        sum += n*use*100
        
    # スコアがG点に届いた場合
    if sum >= g:
        ans = min(ans, count)
print(ans)

Measured memory_bytes: 9228
#include "bits/stdc++.h"

using namespace std;

int main() {
	string s;
	cin >> s;

	vector<char> ans;

	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == '0') ans.push_back('0');
		else if (s[i] == '1') ans.push_back('1');
		else if (ans.size() != 0) ans.erase(ans.end() - 1);
	}

	for (int i = 0; i < ans.size(); i++)
	{
		cout << ans[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int P=1e9+7;
int n,k;
vector<int> G[N];
long long ans;

void dfs(int x,int fa,int dep) {
	int now=k;
	if (dep<=1) now--; else now-=2;
	for (int i=0;i<G[x].size();i++) {
		int y=G[x][i];
		if (y==fa) continue;
		dfs(y,x,dep+1);
		ans=(ans*now)%P;
		now--;
	}
}

int main()
{
	cin>>n>>k;
	for (int i=1;i<n;i++) {
		int x,y; scanf("%d%d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	ans=k;
	dfs(1,0,1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
 
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

bool visited[8][8];
string map[8] = {};

int main(){
    int n,c,k; cin >> n >> c >> k;
    int ans = 0;
    int ti[n];rep(i,n){
      cin >> ti[i];
    }
    sort(ti, ti+n);
    int i = 0;
    while(i < n){
      int sum = 0;int max_time = ti[i]+k;
      while(sum < c && ti[i] <= max_time){
        sum += 1;
        i++;
      }
      ans += 1;
    }
    cout << ans << "\n";
}

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

import sys
input = sys.stdin.readline

def f(n):
    l = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            l.add(i)
            l.add(n // i)
            
    return l

a, b, c = map(int, input().split())
l = list(f(a) & f(b))
l.sort()
print(l[0 - c])


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
    using namespace std; 
    #define pb          push_back
    #define pf          push_front
    #define eb          emplace_back
    #define mp          make_pair
    #define ff          first
    #define ss          second
    #define popf()      pop_front()
    #define popb()      pop_back()
    #define ll          int64_t
    #define lli         long long int
    #define ld          long double
    #define mod         1000000007
    #define inf         1000000000000007
    #define ninf        -1000000000000007
    #define minf        1000000000000000007
    #define nl          cout<<"\n"
    #define dbg         cout<<"debug\n"
    #define all(v)      v.begin(),v.end()
    #define iter(it,v)  for(auto it=v.begin();it!=v.end();++it)
    #define riter(it,v) for(auto it=v.rbegin();it!=v.rend();++it)
    #define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i)
    #define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i)
    #define fastio()    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); 

    //-------------------------------L_I_Erq34-------------------------------

    const ll MAXN=107,MAXL=100007;
    ll dp[MAXN][MAXL];
    vector<pair<ll,ll>> v;

    bool comparell(pair<ll,ll> a,pair<ll,ll> b)
    {
        if(a.ff==b.ff)
            return a.ss>b.ss;
        return a.ff<b.ff;
    }

    int main()
    {
        ll n,t,i,w,a,b,j,k,z,m;
        cin>>n>>w;
        k=0;
        forn(i,0,n)
        {
            cin>>a>>b;
            v.pb(mp(a,b));
            k+=b;
        }
        forn(i,0,n+1)
            forn(j,0,k+7)
                dp[i][j]=inf;
        sort(all(v),comparell);
        m=0;
        dp[0][0]=0;
        forn(i,1,n+1)
        {
            forn(j,v[i-1].ss,k+7)
                dp[i][j]=min(dp[i][j],dp[i-1][j-v[i-1].ss]+v[i-1].ff);
            forn(j,0,MAXL)
                dp[i+1][j]=dp[i][j];
        }
        forn(j,0,k+7)
        {
            if(dp[n+1][j]<=w)
                m=j;
        }
        cout<<m<<"\n";
        return 0;
    }

Measured memory_bytes: 80128
import java.util.*;

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

    int n = sc.nextInt();
    int d = sc.nextInt();
    int[][] x = new int[n][d];
    double buf[][] = new double[n][n];
    int ans = 0;

    for(int i = 0; i < n; i++){
      for(int j = 0; j < d; j++){
        x[i][j] = sc.nextInt();
      }
    }

    for(int i = 0; i < n - 1; i++){
      for(int k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    }

    System.out.println(ans);
    
  }
}


Measured memory_bytes: 23764
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

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

		int num = sc.nextInt();
		List<HashMap<String, String>> input = new ArrayList<HashMap<String,String>>();


		for(int i=0;i<num;i++) {
			HashMap<String,String> tmp=new HashMap<String,String>();
			tmp.put("city", sc.next());
			tmp.put("score", sc.next());
			tmp.put("id", Integer.toString(i));
			input.add(tmp);
		}
		sc.close();

		int[] re=new int[num];

		for(int i=0;i<num;i++) {
			int ord=0;
			HashMap<String,String> tgt=input.get(ord);

			if(input.size()==0) {
				break;
			}else {
				for(int j=1; j<input.size();j++) {
					if(tgt.get("city").compareTo(input.get(j).get("city"))<0) {
						continue;
					}else if(tgt.get("city").compareTo(input.get(j).get("city"))>0) {
						tgt=input.get(j);
						ord=j;
					}else {
						if(Integer.parseInt(tgt.get("score"))<Integer.parseInt(input.get(j).get("score"))){
							tgt=input.get(j);
							ord=j;
						}
					}
				}
			}
			re[i]=Integer.parseInt(tgt.get("id"));
			input.remove(ord);
		}

		for(int c:re) {
			System.out.println(c+1);
		}


	}

}



Measured memory_bytes: 22100
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int M, N, K;

int J[1111][1111], O[1111][1111], I[1111][1111];

int main()
{
    cin >> M >> N >> K;
    vector<string> v(M);
    for (int i = 0; i < M; i++)
    {
        cin >> v[i];
    }
    //JOI
    for (int i = 0; i < M; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (v[i][j] == 'J')
                J[i + 1][j + 1]++;
            if (v[i][j] == 'O')
                O[i + 1][j + 1]++;
            if (v[i][j] == 'I')
                I[i + 1][j + 1]++;
        }
    }
    for (int i = 0; i <= M; i++)
    {
        for (int j = 0; j <= N; j++)
        {
            J[i + 1][j] += J[i][j];
            O[i + 1][j] += O[i][j];
            I[i + 1][j] += I[i][j];
        }
    }

    for (int j = 0; j <= N; j++)
    {
        for (int i = 0; i <= M; i++)
        {
            J[i][j + 1] += J[i][j];
            O[i][j + 1] += O[i][j];
            I[i][j + 1] += I[i][j];
        }
    }

    for (int i = 0; i < K; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--;
        cout << J[c][d] - J[a][d] - J[c][b] + J[a][b] << " ";
        cout << O[c][d] - O[a][d] - O[c][b] + O[a][b] << " ";
        cout << I[c][d] - I[a][d] - I[c][b] + I[a][b] << endl;
    }
}


Measured memory_bytes: 16696
function Main(input) {
  const N = parseInt(input.split(/\n| /)[0]);
  const K = parseInt(input.split(/\n| /)[1]);
  var p = input.split("\n")[1].split(" ").map(n => parseInt(n));
  p.sort(compareFunc);

  var result = p.slice(0, K).reduce((a, b) => { return a + b }, 0);
  console.log(result);

}

function compareFunc(a, b) {
  return a - b;
}

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

Measured memory_bytes: 29864
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}

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


int main() {
    int N; cin >> N;
    vector<int> T(N);
    for (int i = 0; i < N; ++i) cin >> T.at(i);

    int M; cin >> M;
    vector<vector<int>> PX(M, vector<int>(2, 0));
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < 2; ++j) {
            cin >> PX.at(i).at(j);
        }
    }

    for (int i = 0; i < M; ++i) {
        vector<int> tmp(N);
        copy(T.begin(), T.end(), tmp.begin());

        tmp.at(PX.at(i).at(0) - 1) = PX.at(i).at(1);
        int ans = 0;
        for (int j = 0; j < N; ++j) {
            ans += tmp.at(j);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    int mx = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (s.substr(i, n - i) == t.substr(0, n - i)) {
            mx = max(mx, n - i);
        }
    }
    cout << 2 * n - mx << endl;
    return 0;
}


Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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 Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  string s;
  cin>>n>>s;
  if(n>=3200) cout<<s<<endl;
  else cout<<"red"<<endl;
}

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

int main() {
    int number = 0;
    cin >> number;
    
    int64_t before = 2;
    int64_t after = 1;
    int64_t sum = 0;
    for (int i = 2; i < number+1; ++i) {
        sum = before + after;
        before = after;
        after = sum;
    }
    
    if (number == 0) {
        cout << before << endl;
    } else if (number == 1) {
        cout << after << endl;
    } else {
        cout << sum << endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  long long n,i,k,j,f;cin>>n;k=0;
  //caricurate
  for(i=1;i<n+1;i++){
    k+=i;if(k>=n){break;}
  }
  f=(k-n);  
  //output
  for(j=1;j<i+1;j++){
    if(j!=f){cout<<j<<endl;}
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int cmpint(const void *x, const void *y) {
	return *(int *)x - *(int *)y;
}
int main() {
	int n, r[100000][3] = {0}, armMax = -1e9, ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &r[i][1], &r[i][2]);
		r[i][0] = r[i][1] + r[i][2];
	}
	qsort(r, n, sizeof(r[0]), cmpint);
	for (int i = 0; i < n; i++) {
		if (armMax <= r[i][1] - r[i][2]) {
			ans++;
			armMax = r[i][0];
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2556