akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int INF = 1<<29;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする



int main(){
	int n,i,j,ans=INF;
	cin>>n;
	int a[105];
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	int sum=0,flag=INF;
	for(i=-100;i<=100;i++){
		for(j=0;j<n;j++){
			sum += (a[j]-i)*(a[j]-i);
		}
		if(sum<ans){
			ans = sum;
		}
		sum = 0;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  
  int n;
  cin>>n;
  vector<int> vec;
  for(int i=0;i<n;i++){
      int g;
      cin>>g;
      vec.push_back(g);
  }
  vector<int> ans(n);
//   void constructXOR(int A[], int n) 
// { 
    // calculate xor of array 
    int XOR = 0; 
    for (int i = 0; i < n; i++) 
        XOR ^= vec[i]; 
  
    // update array 
    for (int i = 0; i < n; i++) 
        vec[i] = XOR ^ vec[i]; 
        
    for(int i=0;i<n;i++){
        cout<<vec[i]<<" ";
    }
} 


Measured memory_bytes: 4836
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())
 
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int main() {
    int N,K;
    cin>>N>>K;
    char a[K];
    REP(i,K){
        cin>>a[i];
    }
    int i;
    for(i=N; i<10*N;i++){
        unsigned int f = 0;
        REP(j,K){
            if(toString(i).find(a[j])!=string::npos){
                f++;
            }
        }
        if(f){
            continue;
        }
        break;
    }
    cout <<  i<<endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

bool prime(int n){
  bool x = true;
  for(int i=2;i*i<=n;i++)
    if(n%i==0) x = false;
  return x;
}

int main(){
  int N;
  cin >> N;
  int i;
  for(i=N;;i++)
    if(prime(i)){
      cout << i << endl;
      break;
    }
}

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

string s;
int a[26];
signed main(){
	cin>>s;
	rep(i,s.size()){
		a[s[i]-'a']++;
	}
	int ans=s.size()*(s.size()-1)/2;
	rep(i,26){
		ans-=a[i]*(a[i]-1)/2;
	}
	cout<<ans+1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int n, r[16][16];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    for (int j = 0; j < a; ++j) {
      int x, y;
      cin >> x >> y;
      r[i][x - 1] = y == 1 ? 1 : -1;
    }
  }

  int ans = 0;
  for (int s = 0; s < (1 << n); ++s) {
    bool ok = true;
    for (int i = 0; i < n; ++i) {
      if (s & (1 << i)) {
        for (int j = 0; j < n; ++j) {
          if (r[i][j] == 1) {
            if (!(s & (1 << j))) ok = false;
          }
          if (r[i][j] == -1) {
            if (s & (1 << j)) ok = false;
          }
        }
      }
    }
    if (ok) {
      int scr = 0;
      for (int b = 1; b <= s; b <<= 1) {
        if (b & s) scr++;
      }
      ans = max(ans, scr);
    }
  }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int array[] = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		selectionSort(array, n);
	}

	public static void selectionSort(int array[], int n) {
		int count = 0;
		int min;
		for (int i = 0; i < n; i++) {
			min = i;
			for (int j = i; j < n; j++) {
				if (array[j] < array[min]) {
					min = j;
				}
			}
			if (min != i) {
				swap(array, i, min);
				count++;
			}
		}
		printArray(array, n);
		System.out.println(count);
	}

	public static void printArray(int array[], int n) {
		for (int i = 0; i < n - 1; i++) {
			System.out.print(array[i] + " ");
		}
		System.out.println(array[n - 1]);
	}

	public static void swap(int array[], int a, int b) {
		int tmp = array[a];
		array[a] = array[b];
		array[b] = tmp;
	}
}



Measured memory_bytes: 26208
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>

#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[])
{
  int n;
  cin >> n;
  vector<int> v(n), c(n);
  REP(i, n)
  {
    cin >> v[i];
  }
  REP(i, n)
  {
    cin >> c[i];
  }
  int res = 0;
  REP(i, pow(2, n))
  {
    int cost = 0;
    int value = 0;
    REP(j, n)
    {
      if (i >> j & 1 == 1)
      {
        value += v[j];
        cost += c[j];
      }
    }
    res = max(res, value - cost);
  }
  cout << res << endl;
  return 0;
}


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

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

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

int main(int argc, char *argv[]){
  int w, h;
  while(cin >> h >> w, h){
    string torus[30];
    string s[2222];
    for (int i = 0; i < h; i++) {
      cin >> torus[i];
    }
    int l = lcm(w, h);
    int num = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        for (int k = 0; k < h; k++) {
          s[num].push_back(torus[(h + i + k)%h][j]);
          s[num + 1].push_back(torus[(h + i - k)%h][j]);
        }
        
        for (int k = 0; k < w; k++) {
          s[num + 2].push_back(torus[i][(w + j + k)%w]);
          s[num + 3].push_back(torus[i][(w + j - k)%w]);
        }
        
        for (int k = 0; k < l; k++) {
          s[num + 4].push_back(torus[(l*h + i + k)%h][(l*w + j + k)%w]);
          s[num + 5].push_back(torus[(l*h + i - k)%h][(l*w + j + k)%w]);
          s[num + 6].push_back(torus[(l*h + i + k)%h][(l*w + j - k)%w]);
          s[num + 7].push_back(torus[(l*h + i - k)%h][(l*w + j - k)%w]);
        }
        num += 8;
      }
    }
    sort(s, s + 8*w*h);
    string ans = "";
    for (int i = 0; i < 8*w*h - 1; i++) {
      int length = 0;
      for (int j = 0;
           j < min(s[i].length(), s[i + 1].length()); j++) {
        if(s[i][length] == s[i + 1][length])length++;
        else break;
      }
      if(length > ans.length())ans = s[i].substr(0,length);
    }
    if(ans.length() > 1)std::cout << ans << std::endl;
    else std::cout << 0 << std::endl;
  }
  return 0;
}

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

using namespace std;

const int N = 110;

int n;
string s;

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

    if(n & 1)
    {
        puts("No");
        return 0;
    }

    int l = s.size() / 2;
    for(int i = 0; i < s.size() / 2; i++)
        if(s[i] != s[i + l])
        {
            puts("No");
            return 0;
        }
    puts("Yes");
    return 0;
}


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


#define dhai_machli ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;


bool f[100001];
int c[100002];

int n, l, r;

using namespace std;

int main()
{



   dhai_machli;



   for ( int i = 2; i <= 100000; i ++) if (! f [ i ]) 
      for ( int j = i + i ; j <= 100000; j += i )
            f[ j ] = true ;
   for ( int i = 3; i <= 100000; i += 2) 

      if (! f [ i ] && ! f [( i + 1) / 2]) c [ i ]++;

   for ( int i = 3; i <= 100000; i ++) c [ i ] += c [i - 1];

      
   cin >> n;
   while (n--)
   {
      cin >> l >> r;

      cout << c[r] - c[l - 1] << endl;
   }


   return 0;
}


Measured memory_bytes: 4092
#import <iostream>
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b){
    if(b==c||a==c){
      cout << 1;
    }else{
      cout << 2;
    }
    }else if(a==c){
      if(b==c||a==b){
        cout<<1;
      }else{
        cout<<2;
      }
    }else if(b==c){
      if(a==c||a==b){
        cout<<1;
      }else{
        cout<<2;
      }
    }else{
      cout<<3;
    }
  
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
int main() {
	int one, two, three, four, five, six,up,suu,copy;
	char mozi[100];
	cin >> one >> two >> three >> four >> five >> six;
	cin >> mozi;
	suu = strlen(mozi);
	up = one;
	for (int i = 0; i < suu; i++) {
		switch (mozi[i]) {
		case 'E':copy=one;
			one = four;
			four = six;
			six = three;
			three = copy;
			break;
		case 'N':copy=five;
			five = one;
			one = two;
			two = six;
			six = copy;
			break;
		case 'S':copy=two;
			two = one;
			one = five;
			five = six;
			six = copy;
			break;
		case 'W':copy=four;
			four = one;
			one = three;
			three = six;
			six = copy;
		}
		up = one;
	}
	cout << up << endl;
	return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a + b > c  + d) {
    cout << "Left" << endl;
  }
  else if(a + b < c + d){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (int i = (a); i <= (b); i+=x)
#define debug(x) cerr << #x << " is= " << x << endl; //use for debugging
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 5] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
 
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vov        vector<vector<int>> 
#define pr         pair<int,int>
#define vpll       vector<pair<ll,ll>>
#define all(v)     v.begin(),v.end()
#define rall(v)    v.rbegin(),v.rend()  //reverse of above;
#define sz(container) int((container).size())
#define cut(x) {cout<<x<<"\n"; return;}
#define setprec(x) cout << fixed << showpoint << setprecision(8)<<x<<endl;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl "\n"
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
//*s.find_by_order() ->returns an iterator to the k-th largest element (counting from zero);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
//sort(a+1,a+n+1,[](ll x,ll y){return abs(x)>abs(y);});
//sort(v.begin(), v.end(), greater<int>()); 
const int N=1e5+5;

void solve()
{

}
int main()
{
  fast_io;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  int ans=0;
  read(n);
  reads(s);
  s='#'+s;
  FOR(i,1,n-2)
  if(s[i]=='A' and s[i+1]=='B' and s[i+2]=='C') ans++;
  cout<<ans;
}

Measured memory_bytes: 3656
L, R = map(int, input().split())
diff = R - L

min_temp = 10000
if diff <= 2019:
    for i in range(L, R + 1):
        for j in range(L, R + 1):
            if i == j:
                continue
            x = (i * j) % 2019
            min_temp = min(x, min_temp)
else:
    for i in range(L, L + 1 + 2019):
        for j in range(L, L + 1 + 2019):
            if i == j:
                continue
            x = (i * j) % 2019
            min_temp = min(x, min_temp)
print(min_temp)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(void)
{
	int n;
	scanf("%d",&n);
	int *a,*b,*c;
	a = (int*)malloc(sizeof(int)*(n));
	b = (int*)malloc(sizeof(int)*(n));
	c = (int*)malloc(sizeof(int)*(n));
	int i = 0;
	int j = 0;

	while (i < n)
	{
		scanf("%d",&a[i]);
		i++;
	}

	i = 0;
	while (i < n)
	{
		scanf("%d",&b[i]);
		i++;
	}
	
	i = 0;
	while (i < n-1)
	{
		scanf("%d",&c[i]);
		i++;
	}
	i = 1;
	int st = b[a[0]-1];
	while (i < n)
	{
		st+=b[a[i]-1];
		if(a[i] == a[i-1]+1)
			st+=c[a[i-1]-1];
		//printf("st:%d, i:%d, a[i]:%d\n",st,i,a[i]);
		i++;
	}
	printf("%d\n",st);
	return(0);
}


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

// #define set unordered_set
#define map unordered_map

using namespace std;

class UnionFind {
private:
	int size;
	int parent[40000];
	int rank[40000];

public:
	UnionFind() {}
	UnionFind(int sz) {
		init(sz);
	}
	void init(int sz) {
		size = sz;
		fill(rank, rank+sz, 0);
		for (int i = 0; i < sz; ++i) {
			parent[i] = i;
		}
	}
	int root(int n) {
		if (parent[n] == n) return n;
		return parent[n] = root(parent[n]);
	}
	void unite(int n, int m) {
		int x = root(n);
		int y = root(m);
		if (x == y) return;

		if (rank[x] < rank[y]) {
			parent[x] = y;
		}
		else if (rank[x] > rank[y]) {
			parent[y] = x;
		}
		else {
			parent[x] = y;
			++rank[y];
		}
	}
	bool isUnited(int n, int m) {
		return root(n) == root(m);
	}
};


typedef pair<int, int> P;

struct Query {
	int type, u, v;
};

typedef vector< set<int> > Graph;

const int bucket = 150;

map<int, int> make_table(set<P>& use) {
	map<int, int> res;
	set<int> s;
	for (P p : use) {
		s.insert(p.first);
		s.insert(p.second);
	}
	int n = 0;
	for (int v : s) {
		res[v] = n++;
	}
	return res;
}
Graph trim(Graph& G, set<P>& use, map<int, int>& tbl) {
	tbl = make_table(use);

	int i = 0;
	Graph res(tbl.size());
	UnionFind uf(G.size());
	for (int i = 0; i < G.size(); ++i) {
		for (int v : G[i]) {
			if ( !use.count( P(i, v) ) ) {
				uf.unite(i, v);
			}
		}
	}
	for (P p1 : tbl) {
		for (P p2 : tbl) {
			int a = p1.first, b = p2.first;
			if ( uf.isUnited(a, b) ) {
				tbl[a] = tbl[b];
			}
		}
	}
	for (P p1 : tbl) {
		for (P p2 : tbl) {
			int a = p1.first, b = p2.first;
			if ( G[b].count(a) ) {
				res[tbl[b]].insert(tbl[a]);
			}
		}
	}
	return res;
}
void unite(Graph& G, int u, int v) {
	G[u].insert(v);
	G[v].insert(u);
}
void remove(Graph& G, int u, int v) {
	G[u].erase(v);
	G[v].erase(u);
}
bool judge(Graph& G, int v, int t, vector<bool>& reached) {
	if (v == t) return true;
	reached[v] = true;
	for (int to : G[v]) {
		if ( !reached[to] ) {
			if ( judge(G, to, t, reached) ) return true;
		}
	}
	return false;
}
bool judge(Graph& G, int s, int t) {
	vector<bool> reached(G.size(), false);
	return judge(G, s, t, reached);
}

int main() {
	int N, M; cin >> N >> M;
	Query Q[40000];
	set<P> Use[40000/bucket+1];
	for (int i = 0; i < M; ++i) {
		int t, u, v; scanf("%d%d%d", &t, &u, &v);
		Q[i] = (Query){t, u, v};
	}
	for (int i = 0; i < M; ++i) {
		int type = Q[i].type, u = Q[i].u, v = Q[i].v;
		Use[i/bucket].insert( P(u, v) );
		Use[i/bucket].insert( P(v, u) );
	}
	Graph G(N);
	Graph g;
	map<int, int> tbl;
	for (int i = 0; i < M; ++i) {
		int type = Q[i].type, u = Q[i].u, v = Q[i].v;
		if (i % bucket == 0) {
			g = trim(G, Use[i/bucket], tbl);
		}
		switch (type) {
		case 1: // unite
			unite(G, u, v);
			unite(g, tbl[u], tbl[v]);
			break;
		case 2: // remove
			remove(G, u, v);
			remove(g, tbl[u], tbl[v]);
			break;
		case 3: // judge
			if ( judge(g, tbl[u], tbl[v]) ) {
				cout << "YES" << endl;
			}
			else {
				cout << "NO" << endl;
			}
			break;
		}
	}
}

Measured memory_bytes: 11880
#include <iostream>
using namespace std;
int main() {
    int n;
    string s;
    cin >> n >> s;
    int r=0,b=0;
    for(int i=0;i<n;i++) {
        if(s[i]=='R') {
            r++;
        } else if (s[i]=='B') {
            b++;
        }
    }
    if (r-b>0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int x = 0, ma = 0;
    for (char c: s) ma = max(ma, x += (c == 'I') - (c == 'D'));
    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from functools import cmp_to_key
    n=int(input())
    B=[list(map(int,input().split())) for _ in range(n)]
    def cmp(a,b):
        va=min(a[1],b[1]-a[0])
        vb=min(b[1],a[1]-b[0])
        if(va==vb): return 0
        return -1 if(va>vb) else 1
    B.sort(key=cmp_to_key(cmp))
    dp=[-INF]*(30101)
    dp[0]=0
    for i in range(n):
        w,s,v=B[i]
        ndp=dp[:]
        for total in range(20101):
            if(total<=s):
                ndp[total+w]=max(ndp[total+w],dp[total]+v)
        dp=ndp[:]
    print(max(dp[:20101]))
resolve()

Measured memory_bytes: 135688
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
a,b,c,d,e,f = LI()
a *= 100
b *= 100
ans = [a,0]
for i in range(f//a+1):
    for j in range((f-a*i)//b+1):
        for k in range((f-a*i-b*j)//c+1):
            for l in range((f-a*i-b*j-c*k)//d+1):
                if i or j or k or l:
                    s = c*k+d*l
                    w = a*i+b*j
                    q = w*e//100
                    if s <= q:
                        if w+s <= f:
                            if ans[1]/ans[0] < s/(s+w):
                                ans = [w+s,s]
print(*ans)
"""

#D
n = I()
d = LIR(n)
l = [[1 for j in range(n)] for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k]+d[k][j]:
                print(-1)
                quit()
            if d[i][j] == d[i][k]+d[k][j]:
                l[i][j] = l[i][k]+l[k][j]

ans = 0
for i in range(n):
    for j in range(n):
        if l[i][j] == 4:
            ans += d[i][j]
ans //= 2
print(ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 44892
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
	//freopen("in.txt","r",stdin);
	int a,b,c;scanf("%d %d %d",&a,&b,&c);
	int last=a-b;
	int change=min(last,c);
	printf("%d",c-change);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>

#include <cmath>
#include <string>

#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

const long long MOD = 1000000007;

vector<int> edges[100005];
long long w[100005];
long long b[100005];

void dfs(int src, int par) {
	w[src] = 1;
	b[src] = 1;

	for (int i = 0; i < edges[src].size(); i++) {
		if (edges[src][i] == par) continue;
		dfs(edges[src][i], src);
		w[src] *= (w[edges[src][i]] + b[edges[src][i]]);
		b[src] *= (w[edges[src][i]]);
		w[src] %= MOD;
		b[src] %= MOD;
	}
}

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

	int n;
	int u, v;
	cin >> n;

	for (int i = 0; i < n-1; i++) {
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}

	dfs(1, 0);

	cout << (w[1] + b[1]) % MOD << endl;

	return 0;
}


Measured memory_bytes: 14208
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int n, x;
    while (1) {
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i+1; j <= n; j++) {
                for (int k = j+1; k <= n; k++) {
                    if (i+j+k == x) ans++;
                }
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3096
# A Frog 1

n = int(input())
h_list = [int(x) for x in input().split()]

dp = [float('Inf')]*(n)
dp[0] = 0
dp[1] = abs(h_list[1] - h_list[0])

for i in range(2,n,1):
    dp[i] = min(dp[i-2]+abs(h_list[i]-h_list[i-2]), dp[i-1]+abs(h_list[i]-h_list[i-1]))

print(dp[n-1])

Measured memory_bytes: 13928
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();
 
            Console.ReadKey();
        }
 
        static void Solve()
        {
            var str = IO.GetIntList();
            var ans = str[0] <= str[2] && str[2] <= str[0] + str[1] ? "YES" : "NO";
 
            Console.Write(ans);
        }
    }
 
 
    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 11220
# -*- coding: utf-8 -*-
import math
from pprint import pprint

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

xy = {}
for h in range(H):
    for w in range(W):
        xy[A[h][w]] = (h,w)

xy[0] = xy[D]

width = math.ceil(H*W/D)
rui_xy = [[0 for _ in range(width+1)] for _ in range(D)]
for d in range(D):
    rui_cost = 0
    x,y = xy[d]
    for w in range(width+1):
        if w*D+d > H*W:
            break
        i,j = xy[w*D+d]
        rui_cost += abs(x-i) + abs(y-j)
        rui_xy[d][w] = rui_cost
        x,y = i,j

for l,r in LR:
    if l == r:
        print(0)
        continue

    print(rui_xy[r % D][r//D] - rui_xy[l % D][l//D])


Measured memory_bytes: 51252
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.List (sortBy)
import Data.Tuple (swap)
import Data.Function (on)

main :: IO ()
main = do
  let
    f :: Int -> [(Int, Int)] -> Int
    f = go 0
      where
        go :: Int -> Int -> [(Int, Int)] -> Int
        go s k ((i, j) : rest) | j < k     = go (s + i * j) (k - j) rest
                               | otherwise = s + i * k
        go s _ _                           = s
  [n, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    as' = map (flip (,) 1) $ as :: [(Int, Int)]
  bcs <- map (unsafeListToPair . map unsafeTextToInt . T.words) . T.lines <$> T.getContents :: IO [(Int, Int)]
  let
    cbs = map swap $ bcs :: [(Int, Int)]
  print . f n . sortBy (flip compare `on` fst) $ cbs ++ as'

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 74092
// H - Grid 1 https://atcoder.jp/contests/dp/tasks/dp_h
/* 入力例
3 4
...#
.#..
....
// →出力　3
*/
#include <bits/stdc++.h>
using namespace std;
vector<string> grid;
int mem[1001][1001];
int pathcount(int r,int c){
    if(mem[r][c]>=0)return mem[r][c];
    if(r==0 && c==0){
        mem[r][c]=1;
        return mem[r][c];
    }
    else if(r==0 && c>0){
        if(grid[r][c-1]=='.')mem[r][c]=pathcount(r,c-1);
        else mem[r][c]=0;
        return mem[r][c];
    }
    else if(r>0 && c==0){
        if(grid[r-1][c]=='.')mem[r][c]=pathcount(r-1,c);
        else mem[r][c]=0;
        return mem[r][c];
    }
    else{
        int temp=0;
        if(grid[r-1][c]=='.')temp+=pathcount(r-1,c);
        if(grid[r][c-1]=='.')temp+=pathcount(r,c-1);
        mem[r][c]=temp%1000000007;
        return mem[r][c];
    }
    
}

int main(void) {
    int H,W;
    cin >> H >> W;
    for(int i=0;i<H;i++){
        string temp;
        cin >> temp;
        grid.push_back(temp);
    }
    //cout << grid[H-1][W-1];//一番右下
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            mem[i][j]=-1;
        }
    }

cout << pathcount(H-1,W-1) << endl;
    
    return 0;
}


Measured memory_bytes: 5376
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();

        var d = new int[26];
        for (int i = 0; i < s.Length; i++)
        {
            d[s[i] - 'a']++;
        }

        for (int i = 1; i < n; i++)
        {
            var t = new int[26];
            s = Console.ReadLine();
            for (int j = 0; j < s.Length; j++)
            {
                t[s[j] - 'a']++;
            }
            for (int j = 0; j < 26; j++)
            {
                d[j] = Math.Min(d[j], t[j]);
            }
        }

        for (int i = 0; i < 26; i++)
        {
            for (int j = 0; j < d[i]; j++)
            {
                Console.Write((char)(i + 'a'));
            }
        }
        Console.WriteLine();
    }
}


Measured memory_bytes: 13140
def main():
  k = int(input())
  a, b = map(int, input().split())
  
  m = []
  
  for i in range(a, b+1):
    if i%k == 0:
      m.append(i)
      break
    
  if len(m)>0:
    print('OK')
  else:
    print('NG')
  
main()

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
vector<int> G[MAX_N];
bool visit_f[MAX_N],visit_s[MAX_N];
int df[MAX_N],ds[MAX_N];

void dfs_f(int n, int d)
{
	if (visit_f[n]) return;
	visit_f[n] = true;
	df[n] = d;
	d++;
	rep(i,G[n].size())
	{
		dfs_f(G[n][i],d);
	}
}

void dfs_s(int n, int d)
{
	//cout << "visit:" << n << endl;
	if (visit_s[n]) return;
	//cout << "a" << endl;
	visit_s[n] = true;
	ds[n] = d;
	d++;
	rep(i,G[n].size())
	{
		dfs_s(G[n][i],d);
	}
}

int main()
{
	int N;
	cin >> N;
	rep(i,N-1)
	{
		int a,b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs_f(0,0);
	dfs_s(N-1,0);
	/*
	rep(i,N) cout << df[i] << " ";
	cout << endl;
	rep(i,N) cout << ds[i] << " ";
	cout << endl;
	*/
	int cnt_f = 0, cnt_s = 0;
	rep(i,N)
	{
		if (df[i] <= ds[i]) cnt_f++;
		else cnt_s++;
	}
	if (cnt_f > cnt_s) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
	return 0;
}

Measured memory_bytes: 11392
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define MAX_V 100005

int main(void){
	string s,t;
	cin>>s;
	cin>>t;
	int map[26];
	rep(i,26){
		map[i] = -1;
	}
	rep(i, s.size()){
		if(map[s[i]-'a'] == -1){
			map[s[i]-'a'] = t[i]-'a';
		}else{
			if(map[s[i]-'a'] != t[i]-'a'){
				cout<<"No"<<endl;
				//cout<<s[i]<<map[s[i]]<<t[i]<<endl;
				return 0;
			}
		}
	}
	bool check[26];
	rep(i,26){
		check[i] = false;
	}
	rep(i,26){
		if(map[i] == -1){
			continue;
		}
		if(check[map[i]]){
			cout<<"No"<<endl;
			return 0;
		}
		check[map[i]] = true;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<cstdio>
#include<deque>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    priority_queue<int>pq;
    int n,m;cin>>n>>m;int  ans=0;
    while(n--){int ch;cin>>ch;pq.push(ch);}
    while(m--){ans+=pq.top();pq.pop();}
    cout<<ans<<'\n';
 return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		if (A.charAt(0)=='H') {
			System.out.println(B);
		} else if (B.charAt(0)=='H') {
			System.out.println('D');
		} else {
			System.out.println('H');
		}
	}
}

Measured memory_bytes: 21844
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long calA = A;
		long calB = B;
		long tmp;
		while (true) {
			tmp = calB;
			calB = calA%calB;
			calA = tmp;
			if (calB == 0) {
				break;
			}
		}
		System.out.println(A * B / tmp);
	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  vector<int> p(N);
  rep(i, N) { cin >> p[i]; }

  vector<int> e(N + 1);
  e[0] = 0;
  rep(i, N) { e[i + 1] = e[i] + p[i] + 1; }

  int result = 0;
  rep(i, N + 1) {
    if (i - K >= 0) {
      int cand = e[i] - e[i - K];
      result = max(result, cand);
    }
  }

  cout << fixed << result / 2.0 << endl;

  return 0;
}

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

typedef long long ll;
const ll MOD = 1000000007;

ll Pow(ll a, ll b)
{
	ll ans = 1;
	for(; b; b >>= 1)
	{
		if(b & 1) ans = ans * a % MOD;
		a = a * a % MOD;
	}
	return ans;
}

int n, m, a[18];
ll f[18][1 << 16];
ll fac[100010], inv[100010];

ll C(int n, int m)
{
	if(n < 0 || m < 0 || m > n) return 0;
	return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

int main()
{
	fac[0] = 1; for(int i = 1; i <= 100000; ++i) fac[i] = fac[i - 1] * i % MOD;
	inv[100000] = Pow(fac[100000], MOD - 2);
	for(int i = 99999; ~i; --i) inv[i] = inv[i + 1] * (i + 1) % MOD;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + 1 + m); reverse(a + 1, a + 1 + m);
	f[0][0] = 1;
	for(int i = 1; i <= m; ++i)
		for(int s = 0; s < (1 << n); ++s)
		{
			(f[i][s] += f[i - 1][s]) %= MOD;
			int t = (1 << n) - s - a[i];
			for(int j = 0; j < n; ++j)
			{
				if(s & (1 << j)) continue;
				(f[i][s | (1 << j)] += f[i - 1][s] * C(t, (1 << j) - 1) % MOD * fac[1 << j] % MOD) %= MOD;
			}
		}
	ll ans = 0;
	for(int s = 0; s < (1 << n); ++s)
	{
		ll sum = f[m][s] * fac[(1 << n) - s - 1] % MOD;
		int num = 0;
		for(int j = 0; j < n; ++j) if((s >> j) & 1) ++num;
		if(num & 1) ans = (ans - sum) % MOD;
		else ans = (ans + sum) % MOD;
	}
	ans = (ans + MOD) % MOD;
	printf("%lld\n", ans * (1 << n) % MOD);
	return 0;
}

Measured memory_bytes: 9984
fun main(args: Array<String>) {
val read = readLine()!!.reader().readText().split(" ")
    val a = read[0].toInt()
    val b = read[1].toInt()
    val max = if (a < b) b else a

    if (a != b) {
        repeat(max) {
            val x = Math.abs(a - it)
            val y = Math.abs(b - it)
            if (x == y) {
                println(it)
                return
            }
        }
        println("IMPOSSIBLE")
    } else {
        println("IMPOSSIBLE")
    }
}

Measured memory_bytes: 35820
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n+1];
        long[] b = new long[n];
        for(int i = 0; i <= n; i++){
            a[i] = sc.nextLong();
            
        }
        for(int i = 0; i < n; i++){
            b[i] = sc.nextLong();
        }
        long ans = 0;
        for(int i = 0; i < n; i++){
            if(a[i] <= 0){
                if(a[i+1] <= b[i]){
                    ans += a[i+1];
                    a[i+1] = 0;
                }else{
                    ans += b[i];
                    a[i+1] -= b[i];
                }
            }else if(a[i] < b[i]){
                b[i] -= a[i];
                ans += a[i];
                if(a[i+1] <= b[i]){
                    ans += a[i+1];
                    a[i+1] = 0;
                }else{
                    ans += b[i];
                    a[i+1] -= b[i];
                }
            }else{
                ans += b[i];
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 82628
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        if (n >= 3 && n <= 10000)
        {
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0 || i % 10 == 3 ||i%100==3||i%1000==3||i/10==3||i/100==3||i/1000==3||i/10%10==3||i/10/10%10==3)
                {
                    Console.Write(" ");
                    Console.Write(i);
                }
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 15944
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
ll mod = 1000000007;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T;
    T=1;
    start:
    while(T--)
    {
        ll n,m;
        cin>>n>>m;
        ll a[n];
        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        ll dp[m+1];
        for(ll i=0;i<a[0];i++)
        {
            dp[i] = 2;
        }
        for(ll i=a[0];i<=m;i++)
        {
            dp[i]=2;
            for(ll j=0;j<n;j++)
            {
                if(a[j]<=i)
                {
                    ll t = dp[i-a[j]];
                    if(t==2){dp[i]=1;break;}
                }
                else
                {
                    break;
                }
            }
            //cout<<i<<"--"<<dp[i]<<endl;
        }
        if(dp[m]==2){cout<<"Second"<<endl;}
        else{cout<<"First"<<endl;}
    }
    return 0;
}

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

vector<string> a= {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
int main(){
    string s;
    cin >> s;
    if(find(a.begin(),a.end(),s)==a.end()){
        cout << "a" <<endl;
    }else{
        cout << "A" << endl;
    }
}
    

Measured memory_bytes: 3632
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

N = int(input())
zero = 0
d = defaultdict(lambda: [0, 0])
for i in range(N):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = gcd(x, y)
    x //= g
    y //= g
    if y < 0:
        x = -x
        y = -y
    if y == 0 and x < 0:
        x = -x
    rotate = x <= 0
    if rotate:
        x, y = y, -x
        d[(x, y)][0] += 1
    else:
        d[(x, y)][1] += 1

ans = 1
for v in d.values():
    now = 1
    now += (2 ** v[0] - 1) % MOD
    now += (2 ** v[1] - 1) % MOD
    ans *= now
    ans %= MOD
print((ans - 1 + zero) % MOD)


    



Measured memory_bytes: 60720
#include <iostream>
#include <string>
#include <utility>
#define MAX 10
using namespace std;

pair<string, string> dt[MAX];
string start, goal;
int N;

string rep(string base, pair<string, string> tf) {
	int pos=0;
	while ((pos = base.find(tf.first, pos)) < base.size()) {
		base = base.replace(pos, tf.first.size(), tf.second.c_str());
		pos += tf.second.size();
	}
	return base;
}

int dfs(string now, int d) {
	if (d > MAX) return -1;
	if (now == goal) return d;
	if (now.size() > goal.size()) return -1;
	for (int i=0; i<N; i++) {
		if (!(now.find(dt[i].first, 0) < now.size())) continue;
		int res;
		if ((res=dfs(rep(now, dt[i]), d+1)) == -1) continue;
		return res;
	}
	return -1;
}

int main() {
	while (cin >> N, N!=0) {
		for (int i=0; i<N; i++)
			cin >> dt[i].first >> dt[i].second;
		cin >> start;
		cin >> goal;
		cout << dfs(start, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 932
#include<bits/stdc++.h>
using namespace std ;
int main()
{
   int d , s , e , count = 0 ;
   cin>>s>>e>>d ;
   for(int i = s ; i<=e ; i++)
   {
       if(i%d==0)
       {
           count++ ;
       }
   }
   cout<<count<<endl ;

    return 0 ;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,i,y,mac;
    double s1,s2,s3;
    mac = 0;
    s1=0;s2=0;
    s3=0;
    cin >> n;
    vector<int> x(n);
    for(i=0;i<n;i++) cin >> x.at(i);
    for(i=0;i<n;i++){
        cin >> y;
        x.at(i) -= y;
        x.at(i)=abs(x.at(i));
        if(mac < x.at(i))mac = x.at(i);
        s1 += x.at(i);
        s2 += x.at(i)*x.at(i);
        s3 += x.at(i)*x.at(i)*x.at(i);
    }
    s2 = sqrt(s2);
    s3 = cbrt(s3);
    printf("%.5lf\n%.5lf\n%.5lf\n%.5lf",s1,s2,s3,double(mac));
    return 0;
}


Measured memory_bytes: 3356
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=5005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=2;i<M;i+=2) F[i]=F[i-2]*(i-1)%mod;
}
 
int n;
vvi g;
vvl dp;

int dfs(int v,int p){
	int S=1,B=0;
	vl DP;
	for(auto u:g[v]) if(u!=p){
		int N=dfs(u,v);
		S+=N;
		vl DP_(S+1);
		if(!B){
			for(int i=1;i<=N;i++){
				DP_[i+1]=dp[u][i]%mod;
				if(i%2==0) (DP_[1]+=dp[u][i]*F[i]%mod*(mod-1))%=mod;
			}
			B=1;
		}
		else{
			for(int i=1;i<=S-N;i++) for(int j=1;j<=N;j++){
				(DP_[i+j]+=DP[i]*dp[u][j])%=mod;
				if(j%2==0) (DP_[i]+=DP[i]*dp[u][j]%mod*F[j]%mod*(mod-1))%=mod;
			}
		}
		DP=DP_;
	}
	if(S==1){
		DP=vl(2);
		DP[1]++;
	}
	dp[v]=DP;
	return S;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	Init();
	cin>>n;
	g=vvi(n);
	dp=vvl(n,vl(n+1));
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0,-1);
	ll res=0;
	for(int i=2;i<=n;i+=2) (res+=dp[0][i]*F[i])%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 198912
n,x=map(int,input().split())
k=[1]*51
d=[1]*51
for i in range(1,51):
    k[i]=2*k[i-1]+3
    d[i]=2*d[i-1]+1
def f(n,x):
    if n==0:
        return 1
    if x==1:
        return 0
    if x<2+k[n-1]:
        return f(n-1,x-1)
    if x==2+k[n-1]:
        return d[n-1]+1
    if x<2+2*k[n-1]:
        return d[n-1]+1+f(n-1,x-2-k[n-1])
    else:
        return 2*d[n-1]+1
print(f(n,x))

Measured memory_bytes: 3316
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main(){
  int len, i=0, num, diff;
  char s[10];
  cin >> s;
  while(s[i] != '\0') i++;
  len = i;
  for(i=0; i<len-2; i++){
    num = 100*(s[i] - '0')+ 10*(s[i+1] - '0') + (s[i+2] - '0');
    if(i == 0) diff = abs(num - 753);
    else{
      if(diff > abs(num-753)) diff = abs(num-753);
    }
  }
  cout << diff << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <stack>
#include <queue>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
using namespace std;

const int MAX_SIZE = 1000010;
const long long MOD = 1000000007;

long long inv[MAX_SIZE];
long long fact[MAX_SIZE];
long long factinv[MAX_SIZE];

void init() {
  inv[1] = 1;
  for (int i=2; i<MAX_SIZE; i++) {
    inv[i] = ((MOD - inv[MOD%i]) * (MOD/i))%MOD;
  }
  fact[0] = factinv[0] = 1;
  for (int i=1; i<MAX_SIZE; i++) {
    fact[i] = (i * fact[i-1])%MOD;
    factinv[i] = (inv[i] * factinv[i-1])%MOD;
  }
}

long long C(int n, int k) {
  if (n >=0 && k >= 0 && n-k >= 0) {
    return ((fact[n] * factinv[k])%MOD * factinv[n-k])%MOD;
  }
  return 0;
}

long long power(long long x, long long n) {
  if (n == 0) {
    return 1;
  } else if (n%2 == 1) {
    return (x * power(x, n-1)) % MOD;
  } else {
    long long half = power(x, n/2);
    return (half * half) % MOD;
  }
}

long long gcm(long long a, long long b) {
  if (a < b) {
    return gcm(b, a);
  }
  if (b == 0) return a;
  return gcm(b, a%b);
}

typedef long long ll;

int N, X, Y, Z;
int haiku;
const int nagasa = (1 << 17) - 1;

ll dp[50][nagasa];

bool ishaiku(int bit) {
  return ((bit & haiku) == haiku);
}

int main() {
  init();
  //cerr << (1 << 1) << endl;
  //cerr << (1 << 2) << endl;
  cin >> N >> X >> Y >> Z;
  haiku = 0;
  haiku += (1 << (X+Y+Z-1));
  haiku += (1 << (Y+Z-1));
  haiku += (1 << (Z-1));
  fill(&dp[0][0], &dp[0][0]+50*nagasa, 0);
  dp[0][0] = 1;
  for (auto i = 0; i < N; i++) {
    for (auto j = 0; j < nagasa; j++) {
      if (dp[i][j] == 0) continue;
      for (auto k = 1; k <= 10; k++) {
        int ind = (((j << k) + (1 << (k-1))) & nagasa);
        if (!ishaiku(ind)) {
          dp[i+1][ind] += dp[i][j];
          dp[i+1][ind] %= MOD;
        }
      }
    }
  }
  ll negative = 0;
  for (auto i = 0; i < nagasa; i++) {
    negative += dp[N][i];
    negative %= MOD;
  }
  ll ans = ((power(10, N) + (MOD - negative)))%MOD;
  cout << ans << endl;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> p( N );
	for( int i = 0; i < N; i ++ ) {
		cin >> p[i];
	}

	int ans = 0;
	for( int i = 0; i < N; i ++ ) {
		if( p[i] == i + 1 ) {
			ans++;
			if( i == N - 1 ) swap( p[i], p[i - 1] );
			else swap( p[i], p[i + 1] );
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll cal(ll n,ll p){
    ll res=0;
    while(n)res+=n/p,n/=p;
    return res;
}
int main(){
    scanf("%lld",&n);
    if(n&1)printf("0\n");
    else{
        ll c2=n/2+cal(n/2,2);
        ll c5=cal(n/2,5);
        printf("%lld\n",min(c2,c5));
    }
    return 0;
}

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

int H, W, c['z' - 'a' + 1], even = 0, two = 0;
string a[100];

int main() {
	cin >> H >> W;
	bool flag = false;

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

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			c[a[i][j]-'a']++;
		}
	}

	for (int i = 0; i < 'z' - 'a' + 1; i++) {
		if (c[i] % 2 == 1) {
			even++;
			c[i]--;
		}

		c[i] -= c[i] / 4 * 4;
		two += c[i];
	}

	if (W % 2 == 1) {
		if (H % 2 == 1) {
			if (even == 1 && W + H - 2 >= two && (W + H - 2 - two) % 4 == 0)flag = true;
		}
		else {
			if (even == 0 && H >= two && (H - two) % 4 == 0)flag = true;
		}
	}
	else {
		if (H % 2 == 1) {
			if (even == 0 && W >= two && (W - two) % 4 == 0)flag = true;
		}
		else {
			if (even == 0 && two == 0)flag = true;
		}
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
#define SIZE 100

int main()
{
	int i, j;
	char s[SIZE];
	cin >> s;
	i = strlen(s);
	int sum;
	for (j = 1; j < i; j++)
		if (s[j] != '9')
			break;
	sum = 9 * (i - 1) + (s[0] - '0');
	if (j == i)
		cout << sum;
	else
		cout << sum - 1;
}

Measured memory_bytes: 256
S = input()
S = S[::-1]

DEBUG = False

if DEBUG:
    print("S: {}".format(S))
while True:
    if DEBUG:
        print("S[:7]: {}".format(S[:7]))
    if len(S) >= 5:
        if S[:7] == "remaerd":
            S = S[7:]
        elif S[:6] == "resare":
            S = S[6:]
        elif S[:5] == "maerd" or S[:5] == "esare":
            S = S[5:]
        else:
            print("NO")
            exit()
    else:
        break
if DEBUG:
    print("S: {}".format(S))
if len(S) == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188