akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

int n, k;

void read()
{
	cin >> n >> k;
}

void solve()
{
	int64_t answer = 0;

	if(k % 2 == 1)
	{
		int cnt = n / k;
		answer = cnt * 1ll * cnt * 1ll * cnt;
	}
	else
	{
		int cnt = n / (k / 2), cnt2 = n / k;
		cnt -= cnt2;
		
		answer = cnt * 1ll * cnt * 1ll * cnt;
		answer += cnt2 * 1ll * cnt2 * 1ll * cnt2;
	}

	cout << answer << endl;
}

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

	read();
	solve();
	return 0;
}



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

int main() {
  int N,Z=0;
  cin>>N;
  vector<int> p(N+1);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }
  p.at(N)=2000000;
  vector<int> q(1000002);
  sort(p.begin(), p.end());
  for(int i=0;i<N;i++){
    if(q.at(p.at(i))==0){
      if(p.at(i)!=p.at(i+1)){
        Z++;
      }
      int D=p.at(i);
      while(D<1000002){
        q.at(D)++;
        D+=p.at(i);
      }
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 8008
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
  int a,b;
  int d,r;
  double f;
  cin>>a>>b;

  d=a/b;
  r=a%b;
  f=1.0*a/b;

  printf("%d %d %lf\n",d,r,f);

  return 0;
}


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

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

class Pos
{
public:
	int x,y,c;
	Pos(int x, int y, int c)
	:x(x), y(y), c(c)
	{}
};

class Robot
{
public:
	int p,c,h;
	
	Robot(int p, int c, int h)
	:p(p),c(c),h(h)
	{}
	
	bool operator<(const Robot& r) const
	{
		return c>r.c;
	}
};

int main()
{
	int fx,fy;
	while(cin >> fx >> fy, (fx||fy))
	{
		int N=1;
		int f[21][21],c[12][12];
		
		for(int j=0; j<fy; j++)
		{
			string s;
			cin >> s;
			for(int i=0; i<fx; i++)
			{
				if(s[i]=='o')
				{
					f[i][j]=0;
				}
				else if(s[i]=='*')
				{
					f[i][j]=N;
					N++;
				}
				else if(s[i]=='x')
				{
					f[i][j]=-2;
				}
				else f[i][j]=-1;
			}
		}
		
		for(int j=0; j<N; j++)
		for(int i=0; i<N; i++)
			c[i][j]=-1;
			
		for(int i=0; i<N; i++)
		{
			queue<Pos> q;
			for(int x=0; x<fx; x++)
			for(int y=0; y<fy; y++)
			{
				if(f[x][y] == i)
				{
					q.push(Pos(x,y,0));
				}
			}
			
			bool tf[21][21]={0};
			while(!q.empty())
			{
				Pos p=q.front(); q.pop();
				if(f[p.x][p.y] >= 0 && f[p.x][p.y] <= 9)
				{
					c[i][f[p.x][p.y]] = p.c;
					c[f[p.x][p.y]][i] = p.c;
				}
				tf[p.x][p.y]=1;
				
				for(int j=0; j<4; j++)
				{
					int tx=p.x+dx[j], ty=p.y+dy[j];
					if(tx<0||ty<0||tx>=fx||ty>=fy) continue;
					if(tf[tx][ty]) continue;
					if(f[tx][ty]==-2) continue;
					
					tf[tx][ty]=1;
					
					q.push(Pos(tx,ty,p.c+1));
				}
			}
		}
		
		priority_queue<Robot> q;
		q.push(Robot(0,0,1));
		
		bool g=false;
		bool v[11][1<<11]={0};
		while(!q.empty())
		{
			Robot r=q.top(); q.pop();
			if(v[r.p][r.h]) continue;
			v[r.p][r.h]=1;
			if(r.h==(1<<N)-1)
			{
				g=true;
				cout << r.c << endl;
				break;
			}
			
			for(int i=1; i<N; i++)
			{
				if(c[r.p][i]==-1) continue;
				if(r.h&(1<<i)) continue;
				int th=r.h|(1<<i);
				if(v[i][th]) continue;
				
				q.push(Robot(i, r.c+c[r.p][i], th));
			}
		}
		
		if(!g) cout << -1 << endl;
	}
}

Measured memory_bytes: 1048
#include <stdio.h>

void selection(int *arr, int size){
	int count = 0;
	int min = 0;
	for(int i=0; i< size;i++){
		min = i;
		for(int j=i; j<size; j++){
			if(arr[j] < arr[min]){
				min = j;
				
			}
		}
		if(i != min) count++;
		int tmp = arr[i];
		arr[i] = arr[min];
		arr[min] = tmp;
		
	}
	for(int k=0; k<size; k++){
		if(k!=size-1){
			printf("%d ", arr[k]);
		}
		else if(k==size-1){
			printf("%d\n", arr[k]);
		}
	}
	printf("%d\n", count);
}

int main(){
	int size=0;
	scanf("%d", &size);
	int num[size];
	for(int i=0;i<size; i++){
		scanf("%d", &num[i]);
	}
	selection(num, size);
	return 0;
}


Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, w;
  cin >> n >> w;
  vector <ll> v(n);
  vector <ll> u(n);
  rep(i, n) cin >> v.at(i) >> u.at(i);
  vector <vector <ll>> dp(n+1, vector <ll> (w+1, 0));
  rep(i, n) {
    for (ll j = 0; j <= w; j++) {
      if (j < u.at(i)) {
        dp.at(i+1).at(j) = dp.at(i).at(j);
      } else {
        dp.at(i+1).at(j) = max(dp.at(i).at(j), dp.at(i).at(j-u.at(i)) + v.at(i));
      }
    }
  }
  cout << dp.at(n).at(w) << endl;
}


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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int m1, d1, m2, d2;

signed main()
{
    cin >> m1 >> d1 >> m2 >> d2;

    if (m1 != m2)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }

    return 0;
}


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

#define debug(x) cerr << #x << ": " << x << endl

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << (a * b) - a - b + 1 << '\n';    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()
 
int main(void) {
    ll a, b; cin >> a >> b;
    ll val, iter;
    if (a < b) {
        val = a;
        iter = b;
    } else {
        val = b;
        iter = a;
    }
    rep(i, 0, iter) {
        cout << val;
    }
    cout << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b ;
    scanf("%d %d",&a,&b);
    if (a > b){
        printf("a > b\n");
    }
    else if (a < b){
        printf("a < b\n");
    }
    else {
        printf("a == b\n");
    }
        return 0 ;    
    
}



Measured memory_bytes: 2612
#include <iostream>;
#include <ostream>;
#include <queue>;
#include <string>;
#include <vector>;
using namespace std;

const int INF = 1000000;

int main() {
	int a[5];
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
	}
	int b[5];
	for (int i = 0; i < 5; i++)
	{
		b[i] = a[i] % 10;
	}
	int k, l;
	k = 0;
	l = INF;
	for (int i = 0; i < 5; i++)
	{
		if (b[i] != 0) {
			l = min(l, b[i]);
			k++;
		}
	}
	int res = 0;
	for (int i = 0; i < 5; i++)
	{
		res += a[i] / 10;
	}
	if (l != INF) cout << 10*(res+k-1)+l << endl;
	else cout << 10 * res << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nabc = readln.split.to!(long[]);
    auto N = nabc[0];
    auto A = nabc[1];
    auto B = nabc[2];
    auto C = nabc[3];

    string[] ss;
    foreach (_; 0..N) ss ~= readln.chomp;

    string[] rs;
    bool was_same;
    foreach (i, s; ss) {
        switch (s) {
            case "AB":
                if (A == 0 && B == 0) {
                    writeln("No");
                    return;
                }
                was_same = false;
                if (A > B) {
                    --A; ++B;
                    rs ~= "B";
                } else {
                    if (A == B) was_same = true;
                    ++A; --B;
                    rs ~= "A";
                }
                break;
            case "AC":
                if (A == 0 && C == 0) {
                    if (was_same && ss[i-1] == "BC") {
                        B -= 2;
                        C += 2;
                        rs[i-1] = "C";
                    } else {
                        writeln("No");
                        return;
                    }
                }
                was_same = false;
                if (A > C) {
                    --A; ++C;
                    rs ~= "C";
                } else {
                    if (A == C) was_same = true;
                    ++A; --C;
                    rs ~= "A";
                }
                break;
            default:
                if (B == 0 && C == 0) {
                    if (was_same) {
                        if (ss[i-1] == "AB") {
                            A -= 2;
                            B += 2;
                            rs[i-1] = "B";
                        } else if (ss[i-1] == "AC") {
                            A -= 2;
                            C += 2;
                            rs[i-1] = "C";
                        }
                    } else {
                        writeln("No");
                        return;
                    }
                }
                was_same = false;
                if (B > C) {
                    --B; ++C;
                    rs ~= "C";
                } else {
                    if (B == C) was_same = true;
                    ++B; --C;
                    rs ~= "B";
                }
        }
    }
    
    writeln("Yes");
    foreach (r; rs) writeln(r);
}

Measured memory_bytes: 7788
n,c=gets.split.map(&:to_i)

ds = []
c.times do
  ds << gets.split.map(&:to_i)
end


def unique(xs)
  h = {}
  xs.each do |x|
    h[x] ||= 0
    h[x] += 1
  end
  h
end

def score(ds,h,c)
  t = 0
  h.each do |k,v|
    t += ds[k-1][c-1] * v
  end
  t
end

cs = []
n.times do
  cs << gets.split.map(&:to_i)
end

xs = [[],[],[]]

cs.each_with_index do |row,i|
  row.each_with_index do |x,j|
    xs[(i+1+j+1)%3] << x
  end
end

hs = xs.map{|xs_|unique(xs_)}

ret = 2**31
1.upto(c) do |i|
  1.upto(c) do |j|
    1.upto(c) do |k|
      next if i == j || j == k || i == k
      s = score(ds, hs[0],i) + score(ds, hs[1],j) + score(ds, hs[2],k)
      # p [i,j,k,s]
      ret = s if s < ret
    end
  end
end

p ret

Measured memory_bytes: 6552
using System;

namespace abc047A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            int d = (a + b + c) / 2;
            int e = (a + b + c) % 2;
            if ((a == d || b == d || c == d) && e == 0)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
const int maxn=60,p=9,maxl=2e5+5;
long long l[maxl];
long long ans=0;
int nx[maxl],ny[maxl];
int a[maxn][maxn];
int n,it=0;
long long read()
{
	long long digit=0;int cnt=0,f=0;
	char ch=getchar();
	while(ch>'9'||ch<'0') ch=getchar();
	while((ch<='9'&&ch>='0')||ch=='.')
	{
		if(f) ++cnt;
		if(ch=='.') f=1;
		else digit=10*digit+ch-'0';
		ch=getchar();
	}
	for(int i=1;i<=9-cnt;i++) digit*=10;
	return digit;
}
int main()
{
	memset(nx,0,sizeof(nx));
	memset(ny,0,sizeof(ny));
	memset(a,0,sizeof(a));
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		long long x;
		x=read();//printf("%lld\n",x);
		while(x%2==0) ++nx[i],x/=2;
		while(x%5==0) ++ny[i],x/=5;
		++a[nx[i]][ny[i]];
	}
	for(int i=maxn-2;i>=0;i--)
		for(int j=maxn-2;j>=0;j--)
			a[i][j]+=a[i+1][j]+a[i][j+1]-a[i+1][j+1];
	for(int i=1;i<=n;i++)
	{
		ans+=a[max(2*p-nx[i],0)][max(2*p-ny[i],0)];
		if(nx[i]>=p&&ny[i]>=p) --ans;
	}
	printf("%lld\n",ans/2);
	return 0;
}

Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
int A,B,C,D,N,M;
int E, K;
int a[10];
int main() {
  ios::sync_with_stdio(false);
  cin >> A >> B >> C >> D >> E >>K;
  if(E-A > K) cout << ":(";
  else cout << "Yay!";


  return 0;
}


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

ll r, c, k = 0;
ll mp[3005][3005] = {};

ll dp[3005][3005][4];
bool v[3005][3005][4] = {};

ll solve(ll x, ll y, ll items) {
  if (v[x][y][items]) {
    return dp[x][y][items];
  }
  if (x > c || y > r) return 0;

  ll ret = 0;
  ret = max(ret, solve(x + 1, y, items));
  ret = max(ret, solve(x, y + 1, 0));
  if (items < 3 && mp[x][y] != 0) {
    ret = max(ret, solve(x + 1, y, items + 1) + mp[x][y]);
    ret = max(ret, solve(x, y + 1, 0) + mp[x][y]);
  }
  v[x][y][items] = true;
  return dp[x][y][items] = ret;
}

int main() {
  cin >> r >> c >> k;
  ll ri, ci, vi;
  rep(i, k) {
    cin >> ri >> ci >> vi;
    mp[ci][ri] = vi;
  }
  cout << solve(1, 1, 0) << endl;
  return 0;
}

Measured memory_bytes: 391384
#include<stdio.h>


#define N 8
#define M 15
int row[N];
int col[N];
int dpos[M];
int dneg[M];
int IN[N];
int k;

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}


int check(int q){
  int l;
  for(l=0;l<k;l++){
      if(IN[l]==q) {
	q=check(q+1);
      }
    }
  return q;
}
//Not free=1,Free=0
void putQueen(int i){
  int j;
  i=check(i);
  if(i==N){
    printBoard();
    return;
  }
  
  for(j=0;j<N;j++){
    if(col[j]==1||dpos[i+j]==1||dneg[i-j+N-1]==1){
      continue;
    }
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=1;
    putQueen(i+1);
    
    col[j]=dpos[i+j]=dneg[i-j+N-1]=0;    
  }
  
  
}

int main(){
  int i;
  int b;
  int a;
  

  for(i=0;i<N;i++){
    row[i]=col[i]=0;
  }
  for(i=0;i<M;i++){
    dpos[i]=dneg[i]=0;
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&a,&b);
    IN[i]=a;
    row[a]=b;
    col[b]=dpos[a+b]=dneg[a-b+N-1]=1;
  }
  putQueen(0);
  return 0;
}



Measured memory_bytes: 2112
#include<stdio.h>

int gcd(int a, int b)
{
  int c;

  if (a < b) {
    a+=b; b=a-b; a-=b;
  }

  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }

  return a;

}
int main(){
  int x,y,maxnum;
  scanf("%d%d",&x,&y);
  maxnum = gcd(x,y);
  printf("%d\n",maxnum);

  return 0;
}

Measured memory_bytes: 592
#agc023a

n=int(raw_input())
a=map(int,raw_input().split())
s=[0]
for i in xrange(n):
 s.append(s[i]+a[i])
b={}
for i in s:
 if i not in b:
  b[i]=1
 else:
  b[i]+=1
res=0
for i in b:
 res+=b[i]*(b[i]-1)/2
print res


Measured memory_bytes: 34800
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) lli(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))

typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
lli t[1000001][26],p[1000001][26],p1[1000001],par[1000001],co=1;
lli arr[26],ans=0;
void add(lli node,string &s,lli j)
{
	for(lli i=0;i<26;++i)
		if(arr[i]>0)
			p[node][i]++;
	p1[node]++;
	if(node!=0)
		arr[s[j]-'a']--;
	if(j==s.size()-1)
		return;
	if(t[node][s[j+1]-'a']==0)
	{
		par[co]=node;
		t[node][s[j+1]-'a']=co++;
	}
	add(t[node][s[j+1]-'a'],s,j+1);
}
vector<string> v;
void qu(lli node,string &s,lli j)
{
	if(j!=s.size()-1)
	{
		qu(t[node][s[j+1]-'a'],s,j+1);
		return;
	}
	ans+=p1[node]-1;
	for(lli i=0;i<26;++i)
		if(i!=s[j]-'a'&&t[par[node]][i]!=0)
		{
			ans+=p[t[par[node]][i]][s[j]-'a'];
		}
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli n;
  cin>>n;
  for(lli i=0;i<n;++i)
  {
  	string s;
  	cin>>s;
  	reverse(all(s));
  	memset(arr,0,sizeof(arr));
  	for(lli j=0;j<s.size();++j)
  		arr[s[j]-'a']++;
  	add(0,s,-1);
  	v.pb(s);
  }
  for(lli i=0;i<n;++i)
  {
  	qu(0,v[i],-1);
  }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 425792
// Copyright 2020 yaito3014
#include <iostream>

int main() {
  int N;
  long long D;
  std::cin >> N >> D;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
  	long long X, Y;
  	std::cin >> X >> Y;
  	if (X * X + Y * Y <= D * D) ++ans;
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  
  REP(i,H){
    REP(j,W){
      string S;
      cin>>S;
      if(S=="snuke"){
        char a=j+'A';
        cout<<a<<i+1<<endl;
      }
    }
  }
  
}


Measured memory_bytes: 256
# 2019-11-23 21:00:35(JST)
import sys

def main():
    xy = map(int, sys.stdin.readline().split())
    ans = 0
    for i in xy:
        if i == 1:
            ans += 3 * 10 ** 5
        if i == 2:
            ans += 2 * 10 ** 5
        elif i == 3:
            ans += 1 * 10 ** 5
    
    if ans == 6 * 10 ** 5:
        ans = 1 * 10 ** 6
    
    print(ans)

if __name__ == '__main__':
    main()


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

int N,M,Q;
vector<vector<int>> q;

void f(vector<int> p){
  if((int)p.size()==N){
    q.push_back(p);
  }else{
    for(int i=p[p.size()-1]; i<=M; i++){
      vector<int> pp=p;
      pp.push_back(i);
      f(pp);
    }
  }
}

int main(){
  cin >> N >> M >> Q;
  vector<int> a(Q),b(Q),c(Q),d(Q);
  for(int i=0; i<Q; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  
  for(int i=1; i<=M; i++) f(vector<int>{i});
  
  long long result=0;
  for(int i=0; i<(int)q.size(); i++){
    long long tmp=0;
    for(int j=0; j<Q; j++){
      if(q[i][b[j]-1]-q[i][a[j]-1]==c[j]) tmp+=d[j];
    }
    result=max(result,tmp);
  }
  cout << result << endl;
}

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

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

    vector<double> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());

    double sum = 0;
    int count1 = 0;
    for(int i=0; i<a; i++){
        sum += v[i];
        if(v[i] == v[a-1]) count1 += 1;
    }
    double av = sum / (double)a;
    cout << fixed << setprecision(10) << av << endl;

    vector<vector<long long int>> c(51,vector<long long int>(51));
    for(int i=0; i<=50; i++){
        for(int j=0; j<=i; j++){
            if(j == 0 || j == i) c[i][j] = 1LL;
            else c[i][j] = c[i-1][j-1] + c[i-1][j];
        }
    }

    int count2 = 0;
    for(int i=0; i<n; i++){
        if(v[i] == v[a-1]) count2 += 1;
    }

    long long int ans = 0;
    if(v[0] != v[a-1]) ans = c[count2][count1];
    if(v[0] == v[a-1]){
        for(int i=a; i<=b; i++) ans += c[count2][i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
   int N, L;

   cin>>N>>L;

   int diff = 1e8;
   int taste = 0;
   int sum = 0;
   for(int i = 1;i <= N;i++) {
       sum += L+i-1;
   }

   int eat = 0;
   for(int j = 1;j <= N;j++) {
       eat = sum-(L+j-1);
       if(abs(sum-eat) < diff) {
           diff = abs(sum-eat);
           taste = eat;
       }
   }

   cout<<taste<<endl;

   return 0;
}


Measured memory_bytes: 256
from collections import *
n = int(input())
a = list(map(int, input().split()))
x = Counter(a)
if len(x) == 1:
    print(x[0][1]**2)
    exit()
d2 = deque()
d4 = deque()
for i in x.most_common():
    if i[1] > 3:
        d2.append(i[0])
        d4.append(i[0])
    elif i[1] > 1:
        d2.append(i[0])
    else:
        break
D2 = sorted(list(d2))
D4 = sorted(list(d4))
ans = 0
if len(D2) > 1:
    ans = D2[-1] * D2[-2]
if len(D4) > 0:
    ans = max(ans, D4[-1]**2)
print(ans)


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

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

    // init
    int ans = 0;
    int zero_area_cnt = 0, r = 0;
    for(int i = 0; i < N; ++i) {
        if(S[i] == '1'){ 
            r = i; break;
        } else { zero_area_cnt = 1;}
    }
    
    // calc using shakutori hou
    for(int l=0; l < N; ++l) {
        while(zero_area_cnt < K && r < N - 1) {
            ++r;
            if(S[r-1] == '1' && S[r] == '0') { // enter 0 area
                ++zero_area_cnt;
                while(!(S[r] == '1' && S[r+1] == '0') && r < N - 1) ++r;
            }
        }

        ans = max(ans, r - l + 1);

        while(!(S[l] == '0' && S[l+1] == '1') && l < N - 1) ++l; // leave 0 area
        --zero_area_cnt;
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int fun(long long a,int n){
	a=a/20*21;
	if(a%1000!=0){
		a=a/1000*1000+1000;
	}
	n--;
	if(n==0){
		return a;
	}
	else{
		return fun(a,n);
	}
}

signed main(){
	int n;
	long long a;
	scanf("%d",&n);
	a=fun(100000,n);
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 2688
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, M = map(int, raw_input().split())
cost = [0,2,5,5,4,5,6,3,7,6]
A = sorted(map(int, raw_input().split()))

DP = [0] + [-1] * N
ans = [0, 0] * N

for i in range(1, N + 1):
    for j in A:
        pos = i - cost[j]
        if pos < 0 or DP[pos] < 0:
            continue
        if DP[i] <= DP[pos] + 1:
            DP[i] = DP[pos] + 1
            ans[i] = j

S = ""
pos = N
while pos:
    S += str(ans[pos])
    pos -= cost[ans[pos]]

print S

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

int main() {
    int x;
    cin >> x;
    
    string s;
    if (x == 3 || x == 5 || x == 7) {
        s = "YES";
    } else {
        s = "NO";
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n,m; cin >> n>> m;
    vector<int> a(m);
    rep(i,m) cin >> a[i];
    int s = 0;
    rep(i,m) s+=a[i];
    if (s>n) cout << "-1" << endl;
    else cout << (n-s) << endl;
    return 0;
}


























Measured memory_bytes: 3668
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){

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

    /*
    //t_sumをllにする必要があった。
    vector<ll> sum_a;
    for (int i = 0; i < N; i++){
        for (int k = i; k < N; k++){
            ll t_sum = 0;
            for (int p = i; p <= k; p++){
                t_sum += a[p];
            }
            sum_a.push_back(t_sum);
        }
    }
    */
    vector<ll> sum_a;
    for (int i = 0; i < N; i++){
        ll sum = 0;
        for (int k = i; k < N; k++){
            sum += a[k];
            sum_a.push_back(sum);
        }
    }

    /*
    int x = 0;
    int t = 40;
    while(t != 0){
        int cnt = 0;
        ll prov = x + pow(2,t-1);
        for (int i = 0; i < sum_a.size(); i++){
            if ((prov & sum_a[i]) == prov){
                cnt++;
            }
        }
        if (cnt >= K){
            x += prov -x;
        }
        t--;
    }

    cout << x << endl;
    */
    ll ans = 0;
    for (int lg = 50; lg >= 0; lg--) {
        ll nans = ans | (1LL << lg);
        int cnt = 0;
        for (ll d: sum_a) {
            if ((nans & d) == nans) cnt++;
        }
        if (cnt >= K) ans = nans;
    }
    cout << ans << endl;
}



Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll n, k;
    cin >> n >> k;
    vec a(n);
    loop(i, n) cin >> a[i];
    sort(all(a));
    ll ans = 0;
    loop(i, k) ans += a[i];
    putout(ans);
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, prod = 1;
  bool zerojudge = 0, overflowjudge = 0;
  cin >> N;
  vector<ll> A(N);
  for(ll i = 0; i < N; i++) {
    cin >> A.at(i);
    if(A.at(i) == 0) {
      cout << 0 << endl;
      zerojudge = 1;
    }
  }
  if(zerojudge == 0) {
    for(ll i = 0; i < N; i++) {
      if(A.at(i) <= 1000000000000000000 / prod) prod *= A.at(i);
      else {
        overflowjudge = 1;
        break;
      }
    }
    if(overflowjudge == 0) cout << prod << endl;
    else cout << -1 << endl;
  }
}

Measured memory_bytes: 3944
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;
ll n,k,x,y;
 
int main(){
  
  ll ans=llMIN;
  cin >> n >> k;
  
  vi p(n),c(n);
  REP(i,n){
    cin>>p[i];
    p[i]--;
    }
  REP(i,n) cin>>c[i];
  vvi data(n, vi(n,llMIN));  // N * M の2次元配列
 
  ll nowmasu=-1;
  ll score=0;
  for(ll i=0;i<n;i++){//最初に選ぶマス
    nowmasu=i;
    score=0;
    //data[i][i]=0;//score
    ll cnt=0;
    for(ll j=0;j<min(k,n);j++){
      if (data[i][p[nowmasu]]!=llMIN)break;
      nowmasu=p[nowmasu];
      score+=c[nowmasu];
      cnt++;
      data[i][nowmasu]=score;
      ans=max(ans,score);
    }
    //今のnowmasuは必ず最初の地点
    if (k!=cnt){
      ll nnum=(k-cnt)/cnt;
      score*=nnum;
      if (nnum!=0)ans=max(ans,score);
      ll kk=k-nnum*cnt;
      
      for(ll j=0;j<kk;j++){
        nowmasu=p[nowmasu];
        score+=c[nowmasu];
        ans=max(ans,score);
      }
    }
 
    
 
  }
 
 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 198836
# -*- coding: utf-8 -*-

N = int(input())
S = input().strip()

max_cnt = -1

for k in range(1,N):
    s1 = S[:k]
    s2 = S[k:]
    # print(s1, s2)

    cnt = len(set(s1) & set(s2))
    max_cnt = max(max_cnt, cnt)

print(max_cnt)


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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (i % 2 == 0) continue;
        int cnt = 0;
        for (int j = 1; j * j <= i; ++j) {
            if (i % j == 0) {
                if (j * j == i)
                    ++cnt;
                else
                    cnt += 2;
            }
        }
        if (cnt == 8) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef queue<ll> ql;
typedef set<ll> sl;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll inf = 1LL << 60;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll max = 500010;
ll num, M, N, ans=0, count=0;
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if(a+b < c &&(c-a-b)*(c-a-b)-4*a*b > 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

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

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

int inv(int x) {
  return power(x, mod - 2);
}

void precalc() {
}

const int maxn = 1e5 + 100;

int n;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  return true;
}

void solve() {
  sort(a, a + n);
  ll sum = 0;
  int res = n;
  for (int i = 0; i < n; i++) {
    ll wass = sum;
    sum += a[i];
    if (sum > wass * 3) {
      res = min(res, n - i);
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



Measured memory_bytes: 640
//kuch tho karna hai 
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		char x;
		cin >> x;
		if(x>='a' && x<='z')cout <<"a";
		else
			cout<<"A";

	
	}
	return 0;
}

Measured memory_bytes: 3640
import math

def str2list(str):
	result = []
	for value in str.split(' '):
		result.append(int(value))
	return result

def distance1(n, x, y):
	result = 0
	for i in range(n):
		result += abs(x[i] - y[i])
		
	return result
	
def distance2(n, x, y):
	result = 0
	for i in range(n):
		result += (x[i] - y[i]) * (x[i] - y[i])
		
	return math.sqrt(result) if result != 0 else 0
	
def distance3(n, x, y):
	result = 0
	for i in range(n):
		result += math.pow(abs(x[i] - y[i]), 3)
		
	return math.exp(math.log(result)/3) if result != 0 else 0
	
def distanceInf(n, x, y):
	result = 0
	for i in range(n):
		new_result = abs(x[i] - y[i])
		result = new_result if new_result > result else result
		
	return result

n = int(input());
x = str2list(input())
y = str2list(input())

print('%.6f'%distance1(n, x, y))
print('%.6f'%distance2(n, x, y))
print('%.6f'%distance3(n, x, y))
print('%.6f'%distanceInf(n, x, y))

Measured memory_bytes: 7984
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>

using namespace std;
#define SAY_YES cout<<"YES"<<endl;
#define SAY_Yes cout<<"Yes"<<endl;
#define SAY_NO cout<<"NO"<<endl;
#define SAY_No cout<<"No"<<endl;
#define IFYES(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} 
#define IFYes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} 
#define IFyes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} 
#define DEBUG_OUTPUT_ARRAY(XXX,ONE) for(int i=0;i<(ONE);i++){cout<<"DEBUG: i = "<<i<<" -> "<<XXX[i]<<endl;}
#define DEBUG_OUTPUT_ARRAY2(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<"<<< i = "<<i<<" >>>"<<endl;for(int j=0;j<(TWO);j++){cout<<"DEBUG: j = "<<j<<" -> "<<XXX[i][j]<<endl; } }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<i<<"  ";for(int j=0;j<(TWO);j++){cout<<XXX[i][j]<<" "; } cout<<endl;}

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


const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int N,M,L,X,a[10005],res=0,tmp=0;
bool dp[1005]={};
int main() {
	cout << fixed << setprecision(18);
    
    cin>>N;
    for(int i=1;i<=N;i+=2){
        tmp=0;
        for(int j=1;j<=i;j++){
            if(i%j==0){tmp++;}
            
            
        }
        if(tmp==8)res++;
    }
    cout<<res<<endl;
} 


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

typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> c(26, 0), d(26, 0);
    for (int i = n - 1; i >= 0; i--) {
        rep(j, 26) {
            c[j]++;
            if (s[i] - 'a' == j) c[j] = 0;
            d[j] = max(d[j], c[j]);
        }
    }
    int ans = n;
    rep(i, 26) ans = min(ans, d[i]);
    cout << ans << "\n";
    //rep(i, 26) cout << d[i] << "\n";
}

Measured memory_bytes: 256
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

k=int(input())
ans=0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      ans+=gcd(gcd(a,b),c)
print(ans)

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)

ll n, c, good, all_ways, we, le, m2, wc, Len[7], p[7];

signed main()
{
    cin >> n >> c, c *= n;
    ll k = (1 << (n - 1));
    forn(i, n) cin >> Len[i], Len[i] *= n;
    sort(Len, Len + n);
    iota(p, p + n - 1, 0);
    do {
        all_ways++;
        vector<vector<ll> > dp(c + 1, vector<ll>(k));
        dp[Len[n - 1]][0] = 1;
        forn(i, c)
        {
            if (i % n == 0) continue;
            we = p[i % n - 1];
            le = Len[we];
            forn(mask, k)
            {
                if ((1 << we) & mask) continue;
                m2 = mask + (1 << we);
                for (ll ac = i; ac <= c; ac++)
                {
                    wc = max(ac, min(c, le + i));
                    dp[wc][m2] += dp[ac][mask];
                }
            }
        }
        good += dp[c][k - 1];
    } while (next_permutation(p, p + n - 1));
    printf("%.15f", 1.0 * good / all_ways / pow(c / n, n - 1));
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    set<int> se;
    int ans=0;
    REP(i,n){
        int t=0;
        cin>>t;
        if(t/400>=8){
            ans++;
        }else{
            se.insert(t/400);
        }
    }
    cout<<max((int)se.size(),1)<<" "<<se.size()+ans<<endl;
    return 0;
}

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


int main(){
    int h, w, d;
    cin >> h >> w >> d;
    unordered_map<int, pair<int, int> > table;
    rep(i,h){
        rep(j,w){
            int a;
            cin >> a;
            table[a] = make_pair(i,j);
        }
    }
    vector<int> cost(h*w+1, 0);
    for(int t = d+1; t < h*w+1; t++){
        cost[t] = cost[t-d]
                + abs(table[t].first - table[t-d].first)
                + abs(table[t].second - table[t-d].second);
    }
    int q;
    cin >> q;
    while(q--){
        int l, r, ans = 0;
        cin >> l >> r;
        cout << cost[r] - cost[l] << endl;
    }
}


Measured memory_bytes: 5284
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;

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

void ansYES(bool flag){
    if (flag) cout << "YES" << endl; else  cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

struct datas{
    Int max;
    Int size;
};


int main(void) {
    Int n, a , b;
    cin >> n >> a >>b;
    Int ans = 0;
    ans += (n / (a + b)) * a;
    ans += min((n % (a + b)),a);
    cout << ans << endl;
}




Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, M;

int main() {

	cin >> N >> M;

	if (N <= M) {
		rep(i, M) cout << N;
	}
	else {
		rep(i, N) cout << M;
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
/*input
8
1 2 1 4 2 1 4 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    ll sum = 0;
    vector<int> a(n);
    vector<ll> freq(n + 1, 0);
    for(int i = 0; i < n; i++)
    {
    	cin >> a[i];
    	freq[a[i]]++;
    }
    for(int i = 1; i < n + 1; i++) sum += (freq[i] * (freq[i] - 1))/2;
    for(int i = 0; i < n; i++) cout << sum - freq[a[i]] + 1 << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

    
int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    
    rep(i, N){
        cin >> A[i] >> B[i];
    }
    rep(i, N - 2){
        if (A[i] == B[i] && A[i + 1] == B[i + 1] && A[i + 2] == B[i + 2]){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
const int md=1e9+7;
const int maxm=4001000;
const int maxn=2001;
int read(){
	int x=0,flag=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if (ch=='-') flag=-1,ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch-'0'),ch=getchar();
	return x*flag;
}
ll fac[maxm],inv[maxm];
ll ksm(ll a,ll b){
	ll res=1;
	while(b){
		if (b&1) res=res*a%md;
		a=a*a%md;b>>=1;
	}
	return res;
}
void init(int n){
	fac[0]=1;
	for (int i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%md;
	inv[n]=ksm(fac[n],md-2);
	for (int i=n;i;--i)
		inv[i-1]=inv[i]*i%md;
}
ll c(int n,int m){
	return fac[n]*inv[m]%md*inv[n-m]%md;
}
int n,k,f[maxn][maxn];
int main(){
	n=read(),k=read();
	if (k==1) return puts("1"),0;
	init(n*k);
	f[0][0]=1;
	for (int i=1;i<=n;++i){
		for (int j=0;j<=i;++j){
			f[i][j]=f[i-1][j];
			if (!j) continue;
			(f[i][j]+=1ll*f[i][j-1]*(n-j+1)%md*
			c(n-i+(n-j+1)*(k-1)-1,k-2)%md)%=md;
		}
	}
	printf("%d\n",f[n][n]);
}

Measured memory_bytes: 77568
def euclid_gcd(v1, v2, counter):
  if v2 == 0:
    return (v1, counter)
  else:
    return euclid_gcd(v2, v1 % v2, counter + 1)

while True:
  a, b = map(int, input().split())
  if a == 0:
    break

  a, b = max(a, b), min(a, b)
  print(*euclid_gcd(a, b, 0))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller(char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    string S;
    cin>>N>>S;
    vi a(26,0),b(26,0);
    int ans=0;
    rrep(i,N) {
        string f=S.substr(0,i);
        string s=S.substr(i);
        rep(j,f.size()) {
            a[f[j]-'a']++;
        }
        rep(j,s.size()) {
            b[s[j]-'a']++;
        }
        int counter=0;
        rep(j,26) {
            if(a[j]>0&&b[j]>0) counter++;
        }
        ans=max(ans,counter);
        counter=0;
        rep(j,26) {
            a[j]=0; b[j]=0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256