akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
//string binary = bitset<32>(n).to_string();
bool ps(lli x) 
{    
  lli sr = sqrt(x); 
  if(x%sr==0 && x/sr==sr)return true;
  else return false;
}   
int main() {
	ios::sync_with_stdio(0);
    cin.tie(0);
    lli n,d;
    cin>>n>>d;
    lli a[n][d];
    for(lli i=0;i<n;i++){
    	for(lli j=0;j<d;j++)cin>>a[i][j];
    }
	lli ans=0;
	for(lli i=0;i<n;i++){
		for(lli j=i+1;j<n;j++){
			lli temp=0;
			for(lli dt=0;dt<d;dt++)
				temp+=pow(a[i][dt]-a[j][dt],2);
	//		cout<<temp<<endl;
			if(ps(temp))ans++;


		}
	}
	cout<<ans;

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define M 1000000007
#define pi acos(-1)
/*ll power(ll a,ll b)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res*a)%M;
        a = (a*a)%M;
        b = b >> 1;
    }
    return res;
}*/
/*ll modinv(ll a)
{
   return power(a,M - 2); 
}*/
/*vector<ll> primes(ll n)
{
    bool *sieve = new bool[n + 1];
    ll i,j;
    vector<ll> v;
    for(i = 3; i <= n; i+=2)
        sieve[i] = true;
    sieve[2] = true;
    for(i = 3; i*i <= n; i+=2)
    {
        if(sieve[i])
            for(j = i*i; j <= n; j+=i)
                sieve[j] = false;
    }
    if(n >= 2)
    {
        v.pb(2);
        for(i = 3; i <= n; i+=2)
        {
            if(sieve[i])
                v.pb(i);
        }
    }
    return v;
}*/

/*class graph{
public:
    vector<ll> *g;
    ll n;
    graph(ll v)
    {
        n = v + 1;
        g = new vector<ll> [n];
    }
    void addegde(ll f,ll s)
    {
        g[f].pb(s);
        g[s].pb(f);
    }
    void dfs(bool *visited,ll sv)
    {
        visited[sv] = true;
        for(auto x: g[sv])
        {
            if(!visited[x])
            {
                dfs(visited,x);
            }
        }
    }
    void bfs(ll sv){
       queue<ll> q;
       bool visited[n] = {};
       q.push(sv);
       visited[sv] = true;
       while(!q.empty())
       {
           ll node = q.front();
           q.pop();
           for(auto x : g[node])
           {
               if(!visited[x])
               {
                   visited[x] = true;
                   q.push(x);
               }
           }
       }
    }
};*/
int main()
{
  fast;
    ll i,j,t;
    cin >> t;
    i = t/500;
    j = (t - i*500)/5;
    cout<<(i * 1000 + j *5)<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int N; cin >> N;
  int n=N;
  int tot=0;
  while(n>0) {
    tot+=n%10;
    n/=10;
  }
  COUT( N%tot ? "No" : "Yes");
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include "math.h"
#include <iostream>
using namespace std;

struct Vec2{
    double x;
    double y;
};

void kock(int n,Vec2 p1,Vec2 p2){
    if(n == 0){
        return;
    }
    Vec2 s,t,u;
    // s
    s.x = (2 * p1.x + 1 * p2.x) / 3;
    s.y = (2 * p1.y + 1 * p2.y) / 3;
    // t
    t.x = (1 * p1.x + 2 * p2.x) / 3;
    t.y = (1 * p1.y + 2 * p2.y) / 3;
    // u
    u.x = (t.x - s.x) * cos(60 * M_PI / 180) - (t.y - s.y) * sin(60 * M_PI / 180) + s.x;
    u.y = (t.x - s.x) * sin(60 * M_PI / 180) + (t.y - s.y) * cos(60 * M_PI / 180) + s.y;
    
    kock(n-1, p1, s);
    printf("%.8lf %.8lf\n",s.x,s.y);
    kock(n-1, s, u);
    printf("%.8lf %.8lf\n",u.x,u.y);
    kock(n-1, u, t);
    printf("%.8lf %.8lf\n",t.x,t.y);
    kock(n-1, t, p2);
}

int main(void){
    int n;
    cin >> n;
    Vec2 p1 = {0,0},p2 = {100,0};
    printf("%.8lf %.8lf\n",p1.x,p1.y);
    kock(n,p1,p2);
    printf("%.8lf %.8lf\n",p2.x,p2.y);
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     int n , a , b , c;
     cin >> n;
    int dp[3][n+1];
    dp[0][0] = dp[1][0] = dp[2][0] = 0;
    for(int i = 1 ; i <= n ; i++)
    {
        cin >> a >> b >> c;
        dp[0][i] = a + max(dp[1][i-1] , dp[2][i-1]);
        dp[1][i] = b + max(dp[0][i-1] , dp[2][i-1]);
        dp[2][i] = c + max(dp[1][i-1] , dp[0][i-1]);
    }


     cout<< max( dp[0][n] , max( dp[1][n] , dp[2][n]))  << endl;
     return 0;
 }

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

double distance(pair<int,int> a, pair<int,int> b){
  return sqrtl(powl((double)a.first-(double)b.first,2.0)+powl((double)a.second-(double)b.second,2.0));
}

int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> xy(N);
  for(int i=0;i<N;i++){
    cin>>xy.at(i).first>>xy.at(i).second;
  }
  
  double sum=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      sum+=distance(xy.at(i),xy.at(j));
    }
  }
  
  printf("%lf\n",sum*2.0/(double)N);
}

  

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

template <typename T>
void dump_vector(const std::vector<T>& src)
{
  for (int i = 0; i < src.size()-1; ++i)
  {
    std::cout << src[i] << ' ';
  }
  std::cout << src.back() << std::endl;
}

template <typename T>
void insertion_sort(std::vector<T>* xs)
{
  for (int i = 1; i < xs->size(); ++i) // xs[i-1]?????§?????????????????? ?????§?????????xs[i]???????´??????????
  {
    dump_vector(*xs);
    T target = (*xs)[i];
    int j = i-1;
    while (j >= 0  && target < (*xs)[j]) {
      (*xs)[j+1] = (*xs)[j];
      --j;
    }
    (*xs)[j+1] = target;
  }
  dump_vector(*xs);
}

int main()
{
  int n;
  std::vector<int> xs{};

  std::cin >> n;
  xs.resize(n);

  for (int i = 0; i < n; ++i)
  {
    std::cin >> xs[i];
  }

  insertion_sort(&xs);

  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,y[500010],n[500010];
ll end[500010],nosave[500010],dep[500010],ans[500010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N;
	rep(i,N-1)cin>>y[i]>>n[i],y[i]--,n[i]--;
	
	end[N-1]=1;
	for(int i=N-2;i>=0;i--){
		end[i] = end[y[i]] + end[n[i]];
	}
	
	nosave[N-1]=1;
	for(int i=N-2;i>=1;i--){
		nosave[i] = end[y[i]]+nosave[y[i]] + end[n[i]]+nosave[n[i]];
	}
	
	dep[0]=0;
	rep(i,N-1){
		dep[y[i]] = dep[n[i]] = dep[i]+1;
	}
	
	ans[N-1]=0;
	for(int i=N-2;i>=0;i--){
		ans[i] = min( 1+ans[y[i]] + dep[i] + 1+ans[n[i]], min(
			nosave[y[i]] + 1+ans[n[i]],
			nosave[n[i]] + 1+ans[y[i]]) );
	}
	cout<<ans[0]<<endl;
}

Measured memory_bytes: 20724
n=int(input())

word=[input() for _ in range(n)]
if len(word)!=len(set(word)):
    print("No")
else:
    isOK=True
    for i,j in zip(word[:-1], word[1:]):
        if i[-1]!=j[0]:
            isOK=False
    print("Yes") if isOK else print("No")
            

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <queue>
#include <numeric>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n + 2, 0);
  for (int i = 1; i <= n; i++)
  {
    cin >> v[i];
  }

  ll res = 0;
  for (ll b = n + 1; b >= min(n - k + 1, 1LL); b--)
  {
    for (ll a = 0; a <= min(k-(n-b+1), min(n,b-1)); a++)
    {
      ll tmpres = 0;
      std::priority_queue<ll, vector<ll>, std::greater<ll>> q;
      for (ll i = 1; i <= a; i++)
      {
        q.push(v[i]);
        tmpres += v[i];
      }
      for (ll i = n; i >= b; i--)
      {
        q.push(v[i]);
        tmpres += v[i];
      }
      REP(i, k - (a + n-b+1))
      {
        if (!q.empty() && q.top() < 0)
        {
        tmpres -= q.top();
          q.pop();
        }
        else {
          break;
        }
      }
      res = max(tmpres, res);
    }
  }


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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


int n;
int a[200010];


void solve(){
	deque<int> dq;
	repe(i, 1, n)
		if(i%2 == 1) dq.pb(a[i]);
		else dq.pf(a[i]);
	if(n%2 == 0){
		rep(i, 0, n){
			cout << dq[i];
			if(i != n) cout << ' ';
		}
		cout << endl;
	}
	else {
		reper(i, n-1, 0){
			cout << dq[i];
			if(i != 0) cout << ' ';
		}
		cout << endl;
	}
}


signed main(){
	cin >> n;
	repe(i, 1, n) cin >> a[i];

	solve();

	return 0;
}

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

int main(void) {
	string S;
	cin >> S;

	int a = S.size();

	for (int i = 0; i < a; i++) {
		S.pop_back();

		if (S.size() % 2 == 0) {
			int A = S.size() / 2;
			string Q = S.substr(0, A);
			string E = S.substr(A, A);
			if (Q == E) {
				cout << S.size() << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3604
H,W=map(int,input().split())
if H==1 or W==1:
    print(1)
elif H%2==0 and W%2==0:
    print((H*W)//2)
elif H%2==1 and W%2==0:
    print(H*(W//2))
elif H%2==0 and W%2==1:
    print((H//2)*W)
else:
    print((H*W)//2+1)


Measured memory_bytes: 2940
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
 
using namespace std;
 
#define memset_clear(_) memset(_,0,sizeof(_))
#define memset_clear_tre(_) memset(_,1,sizeof(_))
#define memset_clear_reg(_) memset(_,-1,sizeof(_))
#define memset_clear_max(_) memset(_,0x3f,sizeof(_))
#define memset_clear_min(_) memset(_,0x80,sizeof(_))
#define sqr(_) ((_)*(_))
 
#define int long long
 
const int maxn=100005;
int n,m;
int a[maxn];
 
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
 
signed main(){
	n=read();m=read();
	for (int i=1;i<=n;i++) a[i]=read();
	if (a[n]<0){
		for (int i=1;i<=n/2;i++) a[i]=-a[i],a[n-i+1]=-a[n-i+1],swap(a[i],a[n-i+1]);
	}
	int ans=(long long)1<<60;
	int x=0;
	if (x<a[1]) x=1; else
	if (x>a[n]) x=n; else
	for (int i=1;i<n;i++)
		if (a[i]<x && x<=a[i+1]) {x=i+1;break;}
	for (int i=x;i<=min(n,x+m-1);i++) if (i-m+1>0){
		if (a[i-m+1]<0){
			ans=min(ans,a[i]*2-a[i-m+1]);
			ans=min(ans,a[i]-a[i-m+1]*2);
		} else if (i>=m) ans=min(ans,a[i]);
	}
	if (ans==((int)1<<60)) printf("0\n"); else printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int D, C;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> D >> C;
    int ans = D * C;
    cout << ans << endl;
}



Measured memory_bytes: 3172
n,k = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
mita = [0]*n
a.sort(key = lambda x : -x[1])
ireta = [0]*n
tmp=[]
for c in range(n):
  i,j = a[c]
  if mita[i-1] == 0:
    mita[i-1] = 1
    ireta[c] = 1
    tmp.append([i-1,j])
  if len(tmp) >= k:
    break
c = 0
kazu = sum(mita)
while len(tmp) < k:
  if ireta[c]:
    c+=1
    continue
  ireta[c] = 1
  mita[a[c][0]-1] += 1
  tmp.append(a[c])
tmp.sort(key = lambda x: -x[1])
c = 0
kaku = []
flag = 0
for _ in range(n):
  b = tmp.pop()
  if mita[b[0]] >1:
    tmp.append(b)
    break
  while ireta[c]:
    c+=1
    if c >= n:
      flag = 1
      tmp.append(b)
      break
  if flag:
    break
  if kazu*kazu+b[1] < (kazu-1)**2+a[c][1]:
    kaku.append(a[c])
    ireta[c] = 1
    mita[a[c][0]-1] += 1
    kazu -= 1
  else:
    tmp.append(b)
    break
ans = kazu*kazu
for i,j in tmp:
  ans += j
for i,j in kaku:
  ans += j
print(ans)



Measured memory_bytes: 39948
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,b[105];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    cin>>n;;
    for(int i=1;i<n;i++){
        cin>>b[i];
    }  
    b[0]=1e9;
    b[n]=1e9;
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=min(b[i],b[i-1]);
    }
    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

ll dp[105][2];

void Main() {
    int N;
    cin >> N;
    vector<int> A1(N), A2(N);
    rep(i, N) cin >> A1[i];
    rep(i, N) cin >> A2[i];
    dp[0][0] = A1[0];
    dp[0][1] = dp[0][0] + A2[0];
    rep(i, N - 1) {
        dp[i + 1][0] += dp[i][0] + A1[i + 1];
        dp[i + 1][1] += max(dp[i + 1][0] + A2[i + 1], dp[i][1] + A2[i + 1]);
    }
    cout << dp[N - 1][1] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=ja
// Longest Common Subsequence
// LCS
//http://nocotan.github.io/%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0/2017/01/23/lcs-copy.html
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
void solve(){
    string X,Y; cin>>X>>Y;
    vector<vector<ll>> dp(X.size()+1,vector<ll>(Y.size()+1));
    //
    FOR(i,0,X.size()){
        FOR(j,0,Y.size()){
            if(X[i]==Y[j]) chmax(dp[i+1][j+1],dp[i][j]+1);
            chmax(dp[i+1][j+1],dp[i][j+1]);
            chmax(dp[i+1][j+1],dp[i+1][j]);
        }
    }
    cout<<dp[X.size()][Y.size()]<<endl;
}
int main() {
    ll q; cin>>q;    
    REP(i,q){
        solve();
    }
    return 0;
}


Measured memory_bytes: 10728
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let s = read::<u32>();
    let h = s / 3600;
    let h_rest = s % 3600;
    let m = h_rest / 60;
    let sec = h_rest % 60;

    println!("{}:{}:{}", h, m, sec);
}



Measured memory_bytes: 5020
#include<bits/stdc++.h>
using namespace std;
#define All(v) (v).begin(),(v).end()
typedef long long ll;
const ll d5 = 114514;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    vector<ll> V[d5];
    for(ll i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        a--;
        V[a].push_back(b);
    }
    priority_queue<ll> PQ;
    ll res = 0;
    for(ll i=0;i<m;i++){
        if(!V[i].empty()){
            for(auto it:V[i])PQ.push(it);
        }
        ll a=0;
        if(!PQ.empty()){
            a=PQ.top();
            PQ.pop();
        }
        res+=a;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 6016
#include <iostream>
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <numeric>
#include <vector>
#include <cmath>
using namespace std;

int main(){
int k;
cin >> k;
int arr[] ={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};
cout << arr[k-1] << endl;




}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



int clk;
int qry(string s) {
	cout<<"? "<<s<<endl;
	int t;
	cin>>t;
	return t;
}
char a[]="qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321";
string s[100];
int tot;
string merge(string &a, string &b) {
	string ret;
	while (a.size()&&b.size()) {
		string u = a+b.back()+ret;
		if (qry(u)+u.size()==tot) ret=b.back()+ret,b.pop_back();
		else ret=a.back()+ret,a.pop_back();
	}
	while (a.size()) ret=a.back()+ret,a.pop_back();
	while (b.size()) ret=b.back()+ret,b.pop_back();
	return ret;
}
int main() {
	REP(i,0,61) { 
		s[i] = string(128-qry(string(128,a[i])),a[i]);
		tot += s[i].size();
	}
	string ans;
	while (1) {
		int x=-1,y=-1;
		REP(i,0,61) if (s[i].size()) {
			if (y<0||s[y].size()>s[i].size()) y = i;
			if (x<0||s[x].size()>s[y].size()) swap(x,y);
		}
		if (y<0) {ans=s[x];break;}
		s[x] = merge(s[x],s[y]);
	}
	cout<<"! "<<ans<<endl;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
int main(){
 	int n,k,i,d,a;
  	cin>>n>>k;
  	vector<int> ans(n);
  	while(k--){
     	cin>>d; 
      	for(i=0;i<d;++i){
          cin>>a;
          ans[a-1]++;
        }
    }
  int res = 0;
  for(auto x:ans)
    if(x == 0)
      res++;
  cout<<res;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
char s[100000];
int main()
{
	int ans = 0;
	cin >> s;
	for(int i = 0;s[i + 1] != '\0'; i++)
		if(s[i] != s[i + 1]) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int S = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        if (S!=1000000000) {
            for (int i=0;i<K;i++) {
                sb.append(String.valueOf(S));
                if (i!=N-1) sb.append(" ");
            }
            for (int i=0;i<N-K;i++) {
                sb.append(String.valueOf(S+1));
                if (i!=N-K-1) sb.append(" ");
            }
        } else {
            for (int i=0;i<K;i++) {
                sb.append(String.valueOf(S));
                if (i!=N-1) sb.append(" ");
            }
            for (int i=0;i<N-K;i++) {
                sb.append(String.valueOf(1));
                if (i!=N-K-1) sb.append(" ");
            }
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 36016
import java.util.Scanner;

public class Main {
	private int calc(){
		Scanner scanner = new Scanner(System.in);
		int x =scanner.nextInt();
		return x*x*x;
	}
	
	public static void main(String[] args) {
		Main cubic =new Main();
		System.out.println(cubic.calc());

	}

}

Measured memory_bytes: 17356
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
int n,ans;
bool dp[10105];
int main(void){
    scanf("%d",&n);
    dp[0]=true;
    while(n--){
        int s;
        scanf("%d",&s);
        for(int i=10000;i>=0;i--)if(dp[i])dp[i+s]=true;
    }
    for(int i=10000;i>=0;i--){
        if(i%10&&dp[i]){
            ans=i;
            break;
        }
    }
    printf("%d\n",ans);
}

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

int main(){
  ll n,ans=0;
  cin >> n;
  vector<ll> A(n);
  for(ll &e:A)cin>>e;
  
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  for(ll i=0,j=0;i < n-1 ;i++){

    if(i%2 == 0){
      ans = ans + A[j];
      j++;
      }
    else{
      ans = ans +A[j];
    }  
   }
 cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4840
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
      	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
      	sc.close();
      	int y = 0;
      	int a = (x-x%100)/100;
      	int b = ((x-100*a)-(x-100*a)%10)/10;
      	int c = x-100*a-10*b;
      	if (a==1){
      		y=y+1;
      	}
      	if (b==1){
      		y=y+1;
      	}
      	if (c==1){
      		y=y+1;
      	}
      	System.out.println(y);
    }
}

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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;

#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const LL mod = 1000000007;

int main()
{
    int N;
    cin >> N;
    VI count(60, 0);
    REP(i, N) {
        LL A;
        cin >> A;
        REP(j, 60) if (A & (1LL << j)) count[j]++;
    }
    
    LL ans = 0;
    REP(i, 60) ans += (1LL<<i)%mod*count[i]%mod*(N-count[i])%mod;
    ans %= mod;

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {

	private static int A[] = new int[31];

	public static void main(String[] args) throws Exception {
		//Aiはi段目までの登り方の総数
		A[0] = 1;
		A[1] = 1;
		A[2] = A[0]+A[1];
		for(int i=3; i<A.length; i++) {
			for(int j=0; j<3; j++) {
				A[i] +=  A[i+j-3];
			}
		}
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for(;;) {
			int N = Integer.parseInt(br.readLine());
			if(N==0) break;
			System.out.println(year(N));
		}
	}

	private static int year(int n) {
		double year = A[n]/10.0/365;
		return (int)Math.ceil(year);
	}

}



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

void fnMaxProfit(const vector<int>& cnrvnValue, int& rnMinval, int& rnMaxProfit)
{
  for (int i = 1; i < cnrvnValue.size(); i++)
  {
    rnMinval = min(rnMinval, cnrvnValue[i-1]);
    int nMaxProfit = cnrvnValue[i] - rnMinval; 
    rnMaxProfit = max(rnMaxProfit, nMaxProfit);
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnVal;
  int nMaxSiz;
  
  cin >> nMaxSiz;
  for (int i = 0; i < nMaxSiz; i++)
  {
    int nVal;
    cin >> nVal;
    vnVal.push_back(nVal);
  }

  int nMinVal = vnVal[0];
  int nMaxPft = -1000000000;
  fnMaxProfit(vnVal, nMinVal, nMaxPft);
  cout << nMaxPft << endl;

  return 0;
}



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

int main(void)
{
	char b; scanf("%c", &b);
	char r = ' ';
	if (b == 'A') r = 'T';
	if (b == 'T')r = 'A';
	if (b == 'C')r = 'G';
	if (b == 'G')r = 'C';
	printf("%c\n", r);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <string>

using namespace std;

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

    set<int> d1, d2, d3;
    for (int i = 0; i < n; i++) {
        for (set<int>::iterator j = d2.begin(); j != d2.end(); j++) {
            d3.insert(10 * *j + (s[i] - '0'));
        }
        for (set<int>::iterator j = d1.begin(); j != d1.end(); j++) {
            d2.insert(10 * *j + (s[i] - '0'));
        }
        d1.insert(s[i] - '0');
    }

    cout << d3.size() << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>

using namespace std;

int main() {
	long long N = 0;
	long long Q = 0;
	string s;
	vector<long long> counter;
	map<int, int> acount;
	cin >> N >> Q;
	cin >> s;

	int k = 0;
	for (long long j = 1; j < s.length(); ++j) {
		if (s[j - 1] == 'A' && s[j] == 'C') {
			s[j - 1] = '1';
			s[j] = '1';
			acount[j] = 1;
		}
		acount[j] += acount[j - 1];
	}

	for (long long i = 0; i < Q; ++i) {
		string buf = "";
		long long min, max;
		cin >> min >> max;
		long long count = 0;
		count = acount[max - 1] - acount[min - 1];
		counter.push_back(count);
	}
	for (long long i = 0; i < counter.size(); ++i) {
		cout << counter[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 6516
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    W=list(map(int,input().split()))
    ans=float('inf')
    for i in range(N):
        ans=min(ans,abs(sum(W[:i+1])-sum(W[i+1:])))
    print(ans)


if __name__ == '__main__':
    main()


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

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

using namespace std;

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

	int ans1=100*a,ans2=0;
	rep(i,31) rep(j,31) rep(k,101) rep(l,101) {
		int water=100*(i*a+j*b);
		int sugar=k*c+l*d;
		if(sugar<=water/100*e && water+sugar<=f){
			if(ans2*(water+sugar)<ans1*sugar){
				ans1=water+sugar;
				ans2=sugar;
			}
		}
	}
	cout<<ans1<<' '<<ans2<<endl;

	return 0;
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

// clang-format off
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
// clang-format on

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

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

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vec p(n);
    init(p);
    vec a = p;
    sort(all(a));

    int dif = 0;
    rep (i, n) {
        if (a[i] != p[i]) dif++;
    }
    YN(dif <= 2);

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll N,cnt=0;
int num[]={3,5,7};

bool ck(ll n){
    map<int,int> dic;
    while(n>0){
        dic[n%10]++;
        n/=10;
    }
    return (dic.size()>=3);
}

void dfs(ll n,bool is753){
    if(N<n) return;
    if(!is753&&ck(n)) is753=1;
    cnt+=is753;
    n*=10;
    rep(i,3){
        dfs(n+num[i],is753);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    dfs(0,0);
    cout1(cnt)
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
q = [list(map(int, input().split())) for i in range(m)]

g = [[] for i in range(n+1)]

for i in range(m):
    a, b, c = q[i]
    g[a].append((b, c))
    g[b].append((a, -c))

people = [-10**10] * (n+1)

flag = 1
for i in range(1, n+1):
    if people[i] != -10**10:
        continue
    q = [i]
    people[i] = 0
    while q:
        now = q.pop()
        for next, dist in g[now]:
            if people[next] == -10**10:
                q.append(next)
                people[next] = people[now] + dist
            else:
                if people[next] == people[now] + dist:
                    continue
                else:
                    flag = 0
                    break
        if flag == 0:
            break

if max(people[1:]) - min(people[1:]) > 10**9:
    flag = 0

if flag == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 106076
g = [1, 3, 5, 7, 8, 10, 12]
a, b = map(int, input().split())
if a==2 or b == 2:
  print('No')
elif a in g and b in g:
  print('Yes')
elif a not in g and b not in g:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto H = RD;
	auto N = RD;
	auto A = RDA;

	foreach (e; A)
	{
		H -= e;
	}

	writeln(H <= 0 ? "Yes" : "No");
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 4272
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,q;
  cin >> N;
  vector<int> v(N);
  for(int i = 0;i < N;i++)cin >> v[i];
  vector<int> copy = v;
  sort(v.begin(),v.end());
  for(int i = 0;i < N;i++){
    if(copy[i] <= v[N/2 - 1])cout << v[N/2] << endl;
    else cout << v[N/2 - 1] << endl;
  }
}

Measured memory_bytes: 3712
#include <stdio.h>

int main()
{
	int i, j, N, D, X[11][11];
	scanf("%d %d", &N, &D);
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= D; j++) scanf("%d", &(X[i][j]));
	}
	
	int k, count = 0, sum;
	for (i = 1; i <= N; i++) {
		for (j = i + 1; j <= N; j++) {
			sum = 0;
			for (k = 1; k <= D; k++) sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			for (k = 1; k * k <= sum; k++) if (k * k == sum) count++;
		}
	}
	
	printf("%d\n", count);
	fflush(stdout);
	return 0;
}

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

int main() {
  int A, B, C, D, E, ans, num;
  cin >> A >> B >> C >> D >> E;
  if ((A % 10) != 0) {
    ans += (A / 10 + 1) * 10;
  }
  else {
    ans += A;
  }
  if ((B % 10) != 0) {
    ans += (B / 10 + 1) * 10;
  }
  else {
    ans += B;
  }
  if ((C % 10) != 0) {
    ans += (C / 10 + 1) * 10;
  }
  else {
    ans += C;
  }
  if ((D % 10) != 0) {
    ans += (D / 10 + 1) * 10;
  }
  else {
    ans += D;
  }
  if ((E % 10) != 0) {
    ans += (E / 10 + 1) * 10;
  }
  else {
    ans += E;
  }
  for (int i = 1; i <= 9; i++) {
    if (A % 10 == i || B % 10 == i || C % 10 == i || D % 10 == i || E % 10 == i) {
      num = i;
      break;
    }
  }
  if (num == 0) {
    cout << ans;
  }
  else {
    cout << ans - 10 + num;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)

H,W=map(int, input().split())  
S=[]
initB=0
for i in range(H):
    s=[0 if j=='.' else 1 if j=='#' else None for j in input()]
    initB+=sum(s)
    S.append(s)
#print(S)
from collections import deque
que=deque([(0,0)])
di=[-1,1,0,0]
dj=[0,0,-1,1]
S[0][0]=1
while que:
    h,w=que.popleft()
    for i,j in zip(di,dj):
        if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j]==0:
            S[h+i][w+j]= S[h][w]+1
            que.append((h+i,w+j))

if S[H-1][W-1]<2:
    print(-1)
else:
    print(H*W-S[H-1][W-1]-initB)
#print(S)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
vector<int>g[300100];
int book[300100];
int ans[300100];
struct node{
	int num;
	int father;
	node(int num = 0,int father = 0):num(num),father(father){};
}n1[300100];

void dfs(int x)
{
	book[x] = 1;
	for(int i = 0;i < g[x].size();i++){
		int v = g[x][i];
		if(book[v] == 0){
			ans[v] = ans[v] + ans[x];
			dfs(v);
		}
	}
}

int main()
{
	int n,q;
	cin >> n >> q;
	for(int i = 0;i < n-1 ;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		g[a].push_back(b);
	}
	for(int i = 0;i < q;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		ans[a] += b;
	}
	dfs(1);
	for(int i = 1;i <= n;i++){
		cout << ans[i] <<" ";
	}
	return 0;
}

Measured memory_bytes: 29696
#include<bits/stdc++.h>
using namespace std;
int a[200001];
int main(){
	int i,n,total=0,k=1;
	cin>>n;
	for(i=1;i<=n;i++) cin>>a[i];
	for(i=1;i<=n;i++){
		if(a[i]!=i) break;
		if(i==n){
		    cout<<"0"<<endl;
			return 0;
		}
	}
	for(i=1;i<=n;i++){
		if(a[i]==k){
			k++;
			total++;
		}
	}
	if(total==0){
		cout<<"-1"<<endl; return 0;
	}
	cout<<n-total<<endl;
	return 0;
}

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

long long weights[101];
long long values[101];
long long dp[101][100001];

int main()
{
    int n;
    long long W;
    cin >> n >> W;
    for(int i=0;i<n;i++){
        cin >> weights[i] >> values[i];
    }


    for(int i=0;i<n;i++){
        for(long long w=0;w<=W;w++){
            if(w>=weights[i]){
                dp[i+1][w] = max(dp[i][w-weights[i]] + values[i],dp[i][w]);
            }
            else{
                dp[i+1][w] = dp[i][w];
            }
        }
    }
    cout << dp[n][W];
}

Measured memory_bytes: 78336
//
// Created by PIIMUU on 8/29/2020.
//
#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
int bipow(int x, int y) {
    int ret = 1;
    while (y > 0) {
        if (y % 2 == 1) {
            ret = (1LL * ret * x) % MOD;
        }
        y /= 2;
        x = (1LL * x * x) % MOD;
    }
    return ret;
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> suff(n + 1);
    suff[n] = a[n];
    for (int i = n - 1; i >= 1; i--) {
        suff[i] = (0LL + a[i] + suff[i + 1]) % MOD;
    }
    int answer = 0;
    for (int i = 1; i <= n - 1; i++) {
        //cout << anser << '\n';
        answer = (0LL + answer + (1LL * a[i] * suff[i + 1]) % MOD) % MOD;
       // cout << answer << " " << suff[i + 1] << '\n';
    }
    cout << answer;
}



Measured memory_bytes: 4780
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int a[] = new int[n];
	int count = 0;

	for(int i=0;i<n;i++) {
		a[i] = sc.nextInt();
	}
	while(true) {
		boolean jud = false;
		for(int i=0;i<n;i++) {
			if(a[i]%2==1) {
				jud = true;
			}
		}
		if(jud==true) {break;}
		for(int i=0;i<n;i++) {
			a[i] = a[i]/2;
		}
		count++;
	}
			System.out.println(count);
	}
}

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

int main(){
	int n, k;
  	cin >> n >> k;
  	vector<int> h(n);
  	rep(i, n) cin >> h[i];
  	
  	sort(h.rbegin(), h.rend());
  	if(k > n) k = n;
  	rep(i, k) h[i] = 0;
  	
  	ll ans = 0;
  	rep(i, n) ans += h[i];
  	cout << ans << endl;
}

Measured memory_bytes: 3980
#include<stdio.h>

int main(){
	int N,i,j,k;
	scanf("%d",&N);
	int x[200][3]={},a[200][3]={},P[200]={};
	for(i=0;i<N;i++){
		scanf("%d %d %d",&x[i][0],&x[i][1],&x[i][2]);
	}
	for(i=0;i<3;i++){
		for(j=0;j<N;j++){
		for(k=0;k<N;k++){
			if(x[j][i]==x[k][i]){
				a[j][i]++;
			}
		}
		}
		for(j=0;j<N;j++){
			if(a[j][i]==1){
				P[j]=P[j]+x[j][i];
			}
		}
	}
	for(i=0;i<N;i++){
		printf("%d\n",P[i]);
	}
return 0;
}

Measured memory_bytes: 600
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(ReadLine());
        }

        public static long[] Reads()
        {
            return ReadLine().Split().Select(long.Parse).ToArray();
        }

        
         public static long gcd(long x, long y)
        {
            if (x < y) gcd(y, x);
            while (y != 0)
            {
                var z = x;
                x = y;
                y = z % y;
            }
            return x;
        }

        public static long C(long n, long k)
        {
            long x = 1;
            for (long i = 1; i <= k; i++)
            {
                x *= n - i + 1;
                x /= i;
            }
            return x;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();
            long ans = gcd(a[0],a[1]);
            for (int i = 2; i < n; i++)
            {
                ans = gcd(ans, a[i]);
            }
            WriteLine(ans);
            
           
            
            


            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 29224
N = int(input())
p = []
for i in range(N):
    x = int(input())
    p.append(x)

ans = 0
for i in range(N):
    if p[i] == max(p):
       ans += int(p[i]/2)
       p.append(max(p) + 1)
    else:
        ans += p[i]

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int a[3][3];
int main() {
  for (auto i = 0; i < 3; i++) for (auto j = 0; j < 3; j++) cin >> a[i][j];
  int n; cin >> n;
  for (auto k = 0; k < n; k++) {
    int b; cin >> b;
    for (auto i = 0; i < 3; i++) for (auto j = 0; j < 3; j++) {
      if (a[i][j] == b) a[i][j] = 0;
    }
  }
  if ((a[0][0] == a[0][1] && a[0][1] == a[0][2]) ||
      (a[1][0] == a[1][1] && a[1][1] == a[1][2]) ||
      (a[2][0] == a[2][1] && a[2][1] == a[2][2]) ||
      (a[0][0] == a[1][0] && a[1][0] == a[2][0]) ||
      (a[0][1] == a[1][1] && a[1][1] == a[2][1]) ||
      (a[0][2] == a[1][2] && a[1][2] == a[2][2]) ||
      (a[0][0] == a[1][1] && a[1][1] == a[2][2]) ||
      (a[2][0] == a[1][1] && a[1][1] == a[0][2])) {
    puts("Yes");
  } else {
    puts("No");
  }
}

Measured memory_bytes: 256
d, g = map(int, input().split())
p = []
c = []
ans = 10 ** 100
for _ in range(d):
    a, b = map(int, input().split())
    p.append(a)
    c.append(b)

for bit in range(1 << d):
    point, cnt = 0, 0
    for i in range(d):
        if bit >> i & 1:
            point += (i+1) * 100 * p[i] + c[i]
            cnt += p[i]

    if g <= point:
        ans = min(ans, cnt)
    else:
        for i in reversed(range(d)):
            if not(bit >> i & 1):
                for j in range(p[i]):
                    if point >= g:
                        break
                    point += 100 * (i+1)
                    cnt += 1
        ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 3064