akhauriyash/Code-Regression huggingface dataset:
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/30/2019 11:03:37 PM
*************************************************************************/
//#pragma GCC optimize(2)
//#pragma GCC diagnostic error "-std=c++11"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#include <numeric>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define MP(x,y) make_pair(x,y)
#define ll long long
#define ull unsigned long long
#ifdef WindCry1
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#endif
#define lowbit(x) x&(-x)
#define ls x<<1
#define rs x<<1|1
using namespace std;
template<typename T> inline T MIN(const T &a,const T &b) {return a<b?a:b;}
template<typename T> inline T MAX(const T &a,const T &b) {return a>b?a:b;}
template<typename T,typename ...Args> inline T MIN(const T &a,const T &b,Args ...args) {return MIN(MIN(a,b),args...);}
template<typename T,typename ...Args> inline T MAX(const T &a,const T &b,Args ...args) {return MAX(MAX(a,b),args...);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
ll dp[2010][2010];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef WindCry1
	freopen("C:/Users/LENOVO/Desktop/in.txt","r",stdin);
#endif
	int n;cin>>n;
	vector<pll> v;
	for(ll i=0,t;i<n;i++) cin>>t,v.push_back(MP(t,i));
	sort(ALL(v),greater<pll>());
	for(int i=0;i<n;i++){
		for(int j=0;j<n-i;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]+abs(i-v[i+j].second)*v[i+j].first);
			dp[i][j+1]=max(dp[i][j+1],dp[i][j]+abs((n-j-1)-v[i+j].second)*v[i+j].first);
		}
	}
	ll res=-1;
	for(int i=0;i<=n;i++) res=max(res,dp[i][n-i]);
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 26364
//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
ll dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy1[] = {0, 1, 1, 1, 0, -1, -1, -1};

ll dx2[] = {1, 0, -1, 0};
ll dy2[] = {0, 1, 0, -1};
ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;
    x = x % p;
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p;
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n,ll p) 
{ 
    return power(n, p-2, p); 
} 
ll ncrMod(ll n,ll r,ll p) 
{
   if (r==0) 
      return 1;
    ll fac[n+1]; 
    fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}
// a+b=xor(a,b)+2*(a&b)//

bool isPrime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
void solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
    a--;
    cout<<(b/c)-(a/c)<<endl;
}


int main()
{
	fio;
// 	#ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// 	#endif
 

	ll t=1;
// 	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3648
#define HAVE_STRUCT_TIMESPEC
#include <bits/stdc++.h>
using namespace std;
string s[200007];
map<string,int>mp;
int num[200007];
string ans[200007];
int vis[200007];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int cnt=0;
    for(int i=1;i<=n;++i){
        cin>>s[i];
        if(!mp[s[i]])
            mp[s[i]]=++cnt;
        ++num[mp[s[i]]];
    }
    int mx=0;
    for(int i=1;i<=n;++i){
        int x=mp[s[i]];
        mx=max(mx,num[x]);
    }
    int cnt2=0;
    for(int i=1;i<=n;++i){
        int x=mp[s[i]];
        if(!vis[x]&&num[x]==mx){
            vis[x]=1;
            ans[++cnt2]=s[i];
        }
    }
    sort(ans+1,ans+1+cnt2);
    for(int i=1;i<=cnt2;++i)
        cout<<ans[i]<<"\n";
    return 0;
}


Measured memory_bytes: 28544
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数
int N;
//ans2:3の倍数ではない、2の倍数の集合
//ans3:2の倍数ではない、3の倍数の集合
//ans5:2,3の倍数ではない、5の倍数の集合
vector<int> ans, ans2, ans3, ans5;
const int lim = 30000;




//サブ関数
//入力
void input()
{
	cin >> N;

}
void make_set()
{
	FOR(i, 1, lim / 2+1) {
		ans2.push_back(i * 2);
	}
	FOR(i, 1, lim / 3+1) {
		if (i % 2 == 0)continue;
		ans3.push_back(i * 3);
	}
}

void make_ans(int num2, int num3, int num5 = 0)
{
	REP(i, num2)ans.push_back(ans2[i]);
	REP(i, num3)ans.push_back(ans3[i]);
	REP(i, num5)ans.push_back(ans5[i]);
}


//計算
void calc()
{
	make_set();
	FOR(i, 1, 15001)FOR(j, 1, 5001) {
		if (i + j != N)continue;
		if (i % 3 == 1 || j % 2 != 0)continue;
		make_ans(i, j);
		//cerr << i << "  " << j << endl;
		return;
	}
	ans.push_back(2);
	ans.push_back(5);
	ans.push_back(63);
}


//出力
void output()
{
	for (auto num : ans) {
		cout << num << " ";
	}
	cout << endl;
}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#define swap(a,b) ((*a!=*b)&&(*a+=*b,*b=*a-*b,*a-=*b))
typedef long long LL;
const int IMIN=(1<<31);
const LL LINF=0x7fffffffffffffff;
#define rep(i,N) for(int i=0;i<(LL)N;i++)
#define array(N,t) (t*)calloc(N,sizeof(t))
inline LL IN(void)
{
  LL x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void Sort(unsigned *from,unsigned *to,unsigned bit)
{
  if(!bit||to<from+1)return;
  unsigned *left=from,*right=to-1;
  for(;;)
  {
    while(left<right&&!(*left&bit))left++;
    while(left<right&&(*right&bit))right--;
    if(left>=right)break;
    swap(left,right);
  }
  if(!(bit&*left)&&left<to)left++;
  bit>>=1;
  Sort(from,left,bit);
  Sort(left,to,bit);
}
static inline void Radix(int *array,const int len)
{
  unsigned *x=(unsigned*)array;
  rep(i,len)x[i]^=IMIN;
  Sort(x,x+len,IMIN);
  rep(i,len)x[i]^=IMIN;
}
int main(void)
{
  int N=IN(),i=0,m=0,p=0,z=0,temp,*A=array(N,int);
  LL K=IN(),low=-LINF/2,mid,high=LINF/2,count;
  rep(j,N){A[j]=IN();if(A[j]<0)m++;else if(A[j]>0)p++;else z++;}
  Radix(A,N);
  if(K>1ll*m*p&&K<1ll*m*p+1ll*z*(N-1)/2)return puts("0"),0;else temp=0;
  if(K<=1ll*m*p)high=1ll;else low=-1ll;
  while(high-low>1)
  {
    mid=(low+high)/2,count=0;
    if(!mid)count=1ll*m*p;
    else if(mid>0)
    {
      count=1ll*m*p+1ll*z*(m+p)+1ll*z*(z-1)/2;temp=N-1;i=m+z;
      while(i<N)
      {
        while(1ll*A[temp]*A[i]>=mid){temp--;}
        if(temp>i)count+=1ll*temp-i,i++;else break;
      }
      temp=0;i=m-1;
      while(i>=0)
      {
        while(1ll*A[temp]*A[i]>=mid){temp++;}
        if(temp<i)count+=1ll*i-temp,i--;else break;
      }
    }
    else
    {
      temp=m-1;i=N-1;
      while(i>=m+z)
      {
        while(temp>=0&&1ll*A[temp]*A[i]>=mid){temp--;}
        if(temp>=0){count+=1ll*temp+1;}i--;
      }
    }
    if(count<K)low=mid;else high=mid;
  }
  free(A);return printf("%lld\n",low),0;
}

Measured memory_bytes: 2288
#include <bits/stdc++.h>
#include <iterator>
#include <tuple>
using namespace std;
using ll = long long;

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

int main()
{
  int n;
  cin >> n;
  int xx;
  cin >> xx;
  vector<int> x;
  x.push_back(xx);
  for (int i = 0; i < n; ++i)
  {
    int tmp;
    cin >> tmp;
    x.push_back(tmp);
  }
  sort(x.begin(), x.end());
  vector<int> t;
  for (int i = 0; i < x.size() - 1; ++i)
  {
    t.push_back(x[i + 1] - x[i]);
  }
  int ans = t[0];
  for (int i = 1; i < t.size(); ++i)
  {
    if (ans < t[i])
      ans = gcd(t[i], ans);
    else
      ans = gcd(ans, t[i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1400
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 2000
#define mod 1000000007
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll K;int n,m,s[MN+5],can[MN+5],num,ans=1;
struct edge{int x,y,w;}e[MN+5];
inline int getfa(int x){return s[x]?s[x]=getfa(s[x]):x;}
bool cmp(const edge&x,const edge&y){return x.w<y.w;}
ll Solve(int must)
{
    memset(s,0,sizeof(s));ll res=0;
    if(must) s[e[must].x]=e[must].y,res+=e[must].w;
    for(int i=1;i<=m;++i)
    {
        int x=getfa(e[i].x),y=getfa(e[i].y);
        if(x!=y) s[x]=y,res+=e[i].w;
    }
    return res;
}
ll Calc()
{
    memset(s,0,sizeof(s));ll res=0;
    for(int i=1,j;i<=m;i=j+1)
    {
        for(j=i;j<m&&e[j+1].w==e[i].w;++j);
        for(int k=i;k<=j;++k) if(getfa(e[k].x)!=getfa(e[k].y)) can[k]=1,++num;
        for(int k=i;k<=j;++k)
        {
            int x=getfa(e[k].x),y=getfa(e[k].y);
            if(x!=y) s[x]=y,res+=e[i].w;
        }
    }
    return res;
}
inline int pow(int x,int k)
{
    int sum=1;
    for(;k;k>>=1,x=1LL*x*x%mod) if(k&1) sum=1LL*sum*x%mod;
    return sum;
}
int main()
{
    n=read();m=read();cin>>K;
    for(int i=1;i<=m;++i) e[i].x=read(),e[i].y=read(),e[i].w=read();
    sort(e+1,e+m+1,cmp);
    ll mnVal=Calc();
    if(mnVal>K) return 0*puts("0");
    if(mnVal==K) return 0*printf("%d\n",(pow(2,m)-pow(2,m-num+1)+mod)%mod);
    num=0;
    for(int i=1;i<=m;++i) if(!can[i])
    {
        ll Val=Solve(i);
        if(Val==K) ++num;
        else if(Val>K) ans=2*ans%mod;
    }
    printf("%d\n",2LL*ans*(pow(2,num)-1)%mod);
    return 0;
}

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

int main()
{
  int n;
  cin>>n;
  vector<int> a{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<a.at(n-1)<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <complex>
#include <cmath>
#include <iomanip>
using namespace std;
typedef complex<double> xy_t;


double cross_product(xy_t a, xy_t b);
xy_t P[110];

int main() {
	double x1,y1,x2,y2;
	double xin,yin;
	double sum = 0;
	int M =0;
	int count = 0;
	while(true) {

		int N = 0;
		double sum = 0;
		cin >> M;
		if(M == 0) break;
		cin >> xin >> yin;
		for(int i=0;i<M-2;i++) {
			cin >> x1 >> y1;
			//cout << x1 << " " <<  y1 << endl;
			if(N == 0) { 
				x2 = x1; y2 = y1; cin >> x1 >> y1;
				N++;
				//cout << x1 << " " <<  y1 << endl;
			}
			xy_t A(x1-xin,y1-yin);
			xy_t B(x2-xin,y2-yin);
			//cout << cross_product(A,B) << endl;
			sum += cross_product(A,B)/2;
			x2 = x1; y2 = y1;
			N++;
		}
		count++;
		cout << count << " ";
		cout << fixed << setprecision(1) << sum << endl;
	}
}

double cross_product(xy_t a, xy_t b) {
	return (conj(a)*b).imag();
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int l=0,cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='(') cnt++;
        else if(cnt==0) l++;
        else cnt--; 
    }
    cout<<string(l,'(')+s+string(cnt,')')<<endl;
    return 0;
}

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

int main(void){
	int n;
	int t[] = {5,7,5,7,7};
	while(cin >> n, n){
		vector<int> v(n);
		for(int i = 0; i < n; ++i){
			string s;
			cin >> s;
			v[i] = s.size();
		}
		for(int i = 0; i < n; ++i){
			bool a = true;
			int j = i;
			int tn = 0;
			while(tn < 5){
				int sum = 0;
				while(sum < t[tn]){
					sum += v[j];
					j++;
					if(j==n)break;
				}
				if(sum == t[tn]){
					tn++;
				}else{
					a = false;
					break;
				}
			}
			if(a && tn==5){
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <stdio.h>

using namespace std;

int partition(int *A ,int p ,int r){
  int x = A[r];
  int i = p-1;
  int tmp;
  for(int j=0;j<r;j++){
    if(A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  return i+1;
}

int main(){
  int n,q;
  int A[100000];

  while(scanf("%d",&n) != EOF){
    char c = ' ';
    for(int i=0;i<n;i++){
      cin >> A[i];
    }
    q = partition(A,0,n-1);
    for(int i=0;i<n;i++){
      if(i == n-1)
        c = '\n';
      if(i == q)
        //printf("[%d]%c",A[i],c);
        cout << '[' << A[i] << ']' << c;
      else
        //printf("%d%c",A[i],c);
        cout << A[i] << c;
    }
  }
  return 0;
}



Measured memory_bytes: 3520
/*
 * author: calgagi
 *         Calvin Gagliano 
 */
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define ar array
#define f first
#define s second
#define dd long double

int main() {
    ios_base::sync_with_stdio(false);  
    cin.tie(NULL);
    srand(chrono::steady_clock::now().time_since_epoch().count()); 
    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
    
    int k, a, b;
    cin >> k >> a >> b;

    if ((b/k)*k >= a) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
#include <cstdio>
using namespace std;

int x;
int y;
int h;
int w;
bool loop;
char symbols[] = "<^>v";
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
char field[1000][1000];
bool used[1000][1000];

int main() {
  while (1) {
    scanf("%d%d", &h, &w);
    if (w == 0 && h == 0) return 0;
    
    for (int i=0; i<h; i++) {
      for (int j=0; j<w; j++) {
        scanf(" %c", &field[i][j]);
        used[i][j] = false;
      }
    }

    x = 0;
    y = 0;
    loop = false;
    while (1) {
      if (field[y][x] == '.') break;
      if (used[y][x]) {
        loop = true;
        break;
      }
      used[y][x] = true;

      for (int i=0; i<4; i++) {
        if (field[y][x] == symbols[i]) {
          y += dy[i];
          x += dx[i];
          break;
        }
      }
    }

    if (!loop) printf("%d %d\n", x, y);
    else puts("LOOP");
  }
}

Measured memory_bytes: 2764
import random
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
ans = 0
a = []
last = [0]*26
for i in range(1,d+1):
    res = -float("inf")
    index = 0
    for k in range(26):
        x = k
        tnplast = last
        tnplast[x] = i
        tnp = 0
        tnp += s[i-1][x]
        for j in range(26):
            tnp -= c[j]*(i-last[j])
        if (tnp > res):
            res = tnp
            index = k+1
    ans += res
    a.append(index)

def rec(t,x,y,ans):
    ans -= s[x-1][t[x-1]-1]
    ans += s[x-1][y-1]
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==t[x-1]):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==t[x-1]):
            mi = j
            break
    ans -= c[t[x-1]-1]*(x-mi)*(ma-x)
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==y):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==y):
            mi = j
            break
    ans += c[y-1]*(x-mi)*(ma-x)
    return ans
    
for i in range(100000):
    x = random.randrange(1,d+1)
    y = random.randrange(1,27)
    t = a
    A = rec(t,x,y,ans)
    if (ans < A):
        t[x-1] = y
        a = t
        ans = A

print(*a ,sep="\n")


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpl = vector<pll>;
using vvll = vector<vll>;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(ll i=0;i<((ll)n);i++)
#define REP1(i,n) for(ll i=1;i<((ll)n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vll a(n);
  REP(i, n)cin >> a[i];

  sort(ALL(a), greater<ll>());
  vll remind(n + 1);
  REP(i, n)remind[i + 1] += remind[i] + a[i];

  auto check = [&](ll k) {
      if (k < p)
          return true;
	  if (m + a[k] < a[p - 1])
		  return false;

      ll can_vote = (p - 1) * m + (n - k) * m;
	  can_vote += (k - p + 1) * (m + a[k]) - (remind[k] - remind[p-1]);
	  return m * v <= can_vote;
  };

  ll ans = 0;
  REP(i, n) {
      if (check(i))
          ans++;
  }
  cout << ans << endl;

}


Measured memory_bytes: 4764
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def digit_sum(num:int, base:int) -> int:

    if num < base:
        return num
    else:
        return digit_sum(int(num/base), base) + (num % base)
    
n,a,b = li()

ans = 0
for i in range(n+1):
    if a <= digit_sum(i,10) <= b:
        ans += i
        
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <string>
#include <map>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
#include <string.h>
#include <set>
#include <cstdlib>
#include <iostream>
#include <bits/stdc++.h>
#define sz(x)       x.size()
#define pii         pair<int,int> 
#define ll          long long int 
#define sl(n)       scanf("%lld",&n)
#define s(n)        scanf("%d",&n)
#define f(i,n)      for(int i=0;i<n;++i)
#define fo(i,n)     for(int i=1;i<=n;++i)
#define fnm(n,m)    for(ll i=n;i<m+1;++i)
#define pb          push_back
#define pf          printf
#define F           first
#define S           second
#define srt(v)      sort(v.begin(),v.end());
#define srtc(v,cmp) sort(v.begin(),v.end(),cmp);
#define srta(v,n)   sort(v,v+n);
const ll            LL_INF=0x3f3f3f3f3f3f;
const ll            MOD=1073741824;


using namespace std;


int T;
int n,m,k;
ll inp;
int arr[200005];
int vis[200005]={0};
int sta;
map<int,int>mp;
vector<int>seq;
set<int>st;
string str;


void gen(int pos,int se){
    // pf("pos: %d, arr[pos]: %d, se: %d\n",pos,arr[pos],se);
    if(vis[arr[pos]]){
        sta=arr[pos];
        return;
    }
    if(sz(seq)>inp)return;
    vis[arr[pos]]=1;
    seq.pb(arr[pos]);
    mp[arr[pos]]=se+1;
    gen(arr[pos],se+1);
}

void solve(){
    s(n);
    sl(inp);
    vis[1]=1;
    seq.pb(1);
    mp[1]=0;
    fo(i,n){
        s(k);
        arr[i]=k;
    }
    gen(1,0);
    if(sz(seq)>inp)pf("%d",seq[sz(seq)-1]);
    else{
        int ans=(inp-mp[sta])%(sz(seq)-mp[sta]);
        pf("%d",seq[mp[sta]+ans]);
    }
}


int main(){
    // pf("\t\t\t***************************************************************************\n\n");
    // pf("\t\t\t***************************************************************************\n\n");
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // s(T);
    T=1;
    f(i,T)solve();
    pf("\n");

    return 0;
} 

Measured memory_bytes: 12856
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  string N;
  cin >> N;
  if(N[0] == N[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
H, W , D = map(int, input().split())
fields = []
X = []

# print(pairs)
def calc_dist(a,b):
    return abs(a//W-b//W) + abs(a%W-b%W)
for i in range(H):
    # fields.append(list(map(int, input().split())))
    X.extend(list(map(int, input().split())))
pairs = [(x-1,i) for i,x in enumerate(X)]
pairs.sort()
numbers = [p[1] for p in pairs]
# D個ずつの累積和を取る
# print(numbers)
from itertools import accumulate
from collections import defaultdict


d = defaultdict(list)
for i in range(D):
    prev = numbers[i]
    acc = 0
    d[i] = [0]
    for num in numbers[i+D:len(numbers):D]:
        acc += calc_dist(prev,num)
        d[i].append(acc)
        prev = num
# print(d)    
    


Q = int(input())
for i in range(Q):
    L1,R1 = map(int, input().split())
    L1 -= 1
    R1 -= 1
    acc = d[L1%D]
    # print("acc",acc)
    print(acc[R1//D]-acc[L1//D])        


Measured memory_bytes: 39880
#include <bits/stdc++.h>
using namespace std;
int n;
int main () {
	scanf("%d",&n);
	for (int i=1;i<=50000;i++) {
		if ((int)((double)i*1.08)==n) {
			printf("%d\n",i);
			return 0;
		}
	}
	printf(":(\n");
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    c = Counter(A)
    n = len(c.keys())
    ans = 0
    if not n <= K:
        for _, v in c.most_common()[::-1]:
            n -= 1
            ans += v
            if n <= K:
                break
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 39528
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };



static ll dp[180000];

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

	REP(i, 180000) {
		dp[i] = INF;
	}

	dp[0] = 0;
	REP(i, 100001) {
		dp[i + 1] = min(dp[i] + 1, dp[i+1]);
		
		dp[i + 6] = min(dp[i] + 1, dp[i + 6]);
		dp[i + 36] = min(dp[i] + 1, dp[i + 36]);
		dp[i + 216] = min(dp[i] + 1, dp[i + 216]);
		dp[i + 1296] = min(dp[i] + 1, dp[i + 1296]);
		dp[i + 7776] = min(dp[i] + 1, dp[i + 7776]);
		dp[i + 46656] = min(dp[i] + 1, dp[i + 46656]);

		dp[i + 9] = min(dp[i] + 1, dp[i + 9]);
		dp[i + 81] = min(dp[i] + 1, dp[i + 81]);
		dp[i + 729] = min(dp[i] + 1, dp[i + 729]);
		dp[i + 6561] = min(dp[i] + 1, dp[i + 6561]);
		dp[i + 59049] = min(dp[i] + 1, dp[i + 59049]);

	}

	cout << dp[n] << endl;
	

	return 0;
}

Measured memory_bytes: 1664
def dfs(s, n):
    if int(s) > n:
        return 0

    cnt = 0
    if all(s.count(c) > 0 for c in '753'):
        cnt += 1

    for c in '753':
        cnt += dfs(s + c, n)

    return cnt

def main():
    n = int(input())

    print(dfs('0', n))

if __name__ == "__main__":
    main()


Measured memory_bytes: 55004
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;

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

	cout << (N + 1) - K << endl;
}


Measured memory_bytes: 256
N, M, R = gets.split.map(&:to_i)
r = gets.split.map(&:to_i).map{ |i| i-=1 }

d = Array.new(N){ Array.new(N,10**9) }

M.times do
  a, b, c = gets.split.map(&:to_i)
  a-=1
  b-=1
  d[a][b] = c
  d[b][a] = c
end

(0...N).each{ |i| d[i][i] = 0 }

N.times do |k|  ## 中継点
  N.times do |i|
    N.times do |j|
      v = d[i][k]+d[k][j]
      d[i][j] = v if d[i][j] > v
    end
  end
end
# p d
p = r.permutation(R).to_a
ans = 10**9
# p p
p.each do |k|
  dist = 0
  (1...R).each do |i|
    dist += d[k[i]][k[i-1]]
  end
  # p dist
  ans = dist if ans > dist
end

p ans

Measured memory_bytes: 8572
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

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

    int sections = 0;
    rep (i, 0, S.size()-1) {
        if (S[i] != S[i+1]) ++sections;
    }

    cout << sections << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[15][6];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=a-1;i>=0;i--){
			for(int j=0;j<5;j++)scanf("%d",&b[i][j]);
		}
		bool chg=false;
		int ret=0;
		do{
			chg=false;
			for(int i=0;i<a;i++){
				int len=0;
				int now=0;
				for(int j=0;j<6;j++){
					if(now!=b[i][j]){
						if(~now&&len>=3){
							ret+=len*now;
							for(int k=j-len;k<j;k++)b[i][k]=-1;
							chg=true;
						}
						now=b[i][j];
						len=1;
					}else len++;
				}
			}
			for(int i=0;i<5;i++){
				int at=0;
				for(int j=0;j<a;j++){
					if(~b[j][i]){
						b[at++][i]=b[j][i];
					}
				}
				for(int j=at;j<a;j++)b[j][i]=-1;
			}
	//		for(int i=a-1;i>=0;i--){
	//			for(int j=0;j<5;j++)printf("%2d ",b[i][j]);
	//			printf("\n");
	//		}printf("\n");
		}while(chg);
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1012
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,K;
  cin>>N>>K;
  int h[N];
  rep(i,N) h[i]=0;
  rep(i,K){
    int d;
    cin>>d;
    rep(j,d){
      int a;
      cin>>a;
      h[a-1]=1;
    }
  }
  int ans=0;
  rep(i,N){
    if(h[i]==0)
      ans+=1;
  }
  cout<<ans<<endl;
      

}

Measured memory_bytes: 3608
#include <stdio.h>
#include<string.h>

int main()
{
    char a[101];
    scanf("%s", a);
    int len=strlen(a);
    int count=len;

    int ans=0;

    int right=len-1;
    int left=0;

    while(count>len/2){
        //printf("%c %c\n",a[left],a[right]);
        if(a[left]!=a[right]){
            ans++;
        }
        left++;
        right--;
        count--;
    }

    printf("%d\n",ans);
    
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44


/*const int MOD = 998244353;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}*/

using namespace std;


int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    //int ;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    ll s;
    cin >> s;

    int ct = 1e9;

    ll r = (ct - s % ct) % ct;
    ll a = (s + r) / ct, b = ct, c = 1, d = r;
    cout << 0 << " " << 0 << " " << a << " " << c << " " << d << " " << b;

    return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  ll x; cin >> x;

  map<ll, int> mp;
  for(ll i=-1000;i<=1000;++i) {
    ll tmp = i*i*i*i*i;
    mp[tmp] = i;
  }

  ll a = -LINF ,b = -LINF;
  for(auto &tmpa: mp) {
    ll tmpb = tmpa.first - x;
    if(mp.find(tmpb) != mp.end()) {
      a = tmpa.second;
      b = mp[tmpb];
      break;
    }
  }

  assert(a != -LINF || b != -LINF);
  cout << a << " " << b << endl;
}
























Measured memory_bytes: 3768
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
   
        cin>>a>>b>>c;
        //5 7 5, 5 5 7, 7 5 5
        if(a==5){
            if((b==5 && c==7) || (b==7 && c==5)){
                cout<<"YES";
                return 0;
            }
        }
        if(a==7 && b==5 && c==5){
            cout<<"YES";
            return 0;
        }
        
        
    cout<<"NO";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
typedef pair<int,int> P;
typedef pair<int,P> PP; 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1e9+7;

int cnt;
int d[11111];
vector<vector<int> > g(11111);
vector<int> c;

void dfs(int x=0){
  if(d[x]!=0)return;
  d[x]=c[cnt--];
  for(int i=0;i<sz(g[x]);i++){
    dfs(g[x][i]);
  }
}

signed main(){
  int n;
  cin>>n;
  for(int i=1;i<n;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  c=vector<int>(n);
  for(int i=0;i<n;i++)cin>>c[i];
  sort(all(c));
  int sum=0;
  for(int i=0;i<n-1;i++){
    sum+=c[i];
  }
  cnt=n-1;
  dfs();
  cout<<sum<<endl;
  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<d[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

void coch(double sx,double sy,double tx,double ty,int i,int n){
	if(i == n){
		return;
	}else{
		double xx = (tx-sx) / 3.0;	double yy = (ty-sy) / 3.0;
		double a = sqrt(3.0) * xx / 2.0;	double b = xx / 2.0;
		double c = sqrt(3.0) * yy / 2.0;	double d = yy / 2.0;
		coch(sx,sy,sx+xx,sy+yy,i+1,n);
		printf("%.8lf %.8lf\n",sx+xx,sy+yy);
		coch(sx+xx,sy+yy,sx+xx + b - c,sy + yy + a + d,i+1,n);
		printf("%.8lf %.8lf\n",sx+xx + b - c,sy+yy + a + d);
		coch(sx+xx + b - c,sy +yy + a + d,sx + 2.0*xx ,sy + 2.0*yy,i+1,n);
		printf("%.8lf %.8lf\n",sx + 2.0*xx ,sy + 2.0*yy);
		coch(sx + 2.0*xx ,sy + 2.0*yy,tx,ty,i+1,n);
	}
}

int main()
{
	int n;
	cin >> n;
	printf("0.00000000 0.00000000\n");
	coch(0.0,0.0,100.0,0.0,0,n);
	printf("100.00000000 0.00000000\n");
}

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

int main(int argc, char *argv[]) {
	int num_of_word = 0;
	std::cin >> num_of_word;

	bool is_shiritori(true);
	std::set<std::string> words;
	std::string current_word;
	std::string prev_word;

	for (int i = 0; i < num_of_word; i++) {
		std::cin >> current_word;
		if (i > 0) {
			if (words.count(current_word) > 0) {
				is_shiritori = false;
				break;
			}
			if (prev_word[prev_word.size() - 1] != current_word[0]) {
				is_shiritori = false;
				break;
			}
		}
		words.insert(current_word);
		prev_word = current_word;
	}

	std::cout << ((is_shiritori) ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())

# p:県　y:誕生年
py=[]

# [p y number]
for i in range(m):
    py.append(list(map(int,input().split())))
    py[i].append(i)
py=sorted(py,key= lambda x:(x[0],x[1]))

for i in range(m):
    if i==0:
        py[i][1]=1
    else:
        if py[i][0]==py[i-1][0]:
            py[i][1]=py[i-1][1]+1
        else:
            py[i][1]=1
py=sorted(py,key=lambda x:(x[2]))

for i in range(m):
    temp1="0"*(6-len(str(py[i][0])))+str(py[i][0])
    temp2="0"*(6-len(str(py[i][1])))+str(py[i][1])
    print(temp1+temp2)



Measured memory_bytes: 38824
#include<stdio.h>
#include<math.h>
int f(int);

int main(void){
    int a=0, b=600, x,d;
    int n,i;
    int s,sum;
    while(scanf("%d", &d)!= EOF) {
     n=(b-a)/d;
    
    sum=0.0;
    x=a;
        for(i=1; i<=n; i++){
            s=d*f(x);
            x+=d;
            sum+=s;
        }
    printf("%d\n", sum);
     if(d == 0) {
   break;
   }
    }
}
int f(int x){
    return x*x;
}



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

if A >= B :
    if N < B:
        print(int(A/B*N))
    else:
        print( int(A/B*(B-1)))

elif A < B:
    if N < B:
        print(int(A/B*N))
    else:
        print( int(A/B*(B-1)))

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int A[220000];
int ans[220000];
signed main() {
    cin >> N;
    for (int i = 2; i <= N; i++) {
        cin >> A[i];
        ans[A[i]]++;
    }
    reps(i, N) { cout << ans[i] << endl; }
}

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

using namespace std;

int N, X, Y, Z;
bool Data[3][100];

void solve() {
	int sum;

	sum = 0;
	for (int i = 0; i < N; ++i) {
		if ((!Data[0][i] && Data[2][i]) || (Data[1][i] && Data[2][i])) {
			++sum;
		}
	}
	cout << sum << endl;
}

int main() {
	int num;

	memset(Data, false, sizeof(Data));
	cin >> N >> X;
	for (int i = 0; i < X; ++i) {
		cin >> num;
		Data[0][num - 1] = true;
	}
	cin >> Y;
	for (int i = 0; i < Y; ++i) {
		cin >> num;
		Data[1][num - 1] = true;
	}
	cin >> Z;
	for (int i = 0; i < Z; ++i) {
		cin >> num;
		Data[2][num - 1] = true;
	}
	solve();

	return 0;
}



Measured memory_bytes: 3100
import sys
 
def isort(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j -= g
            cnt += 1
        a[j + g] = v
 
# input data
n = int(sys.stdin.readline())
a = []
for i in range(n):
    a.append(int(sys.stdin.readline()))
 
# determine m, g
g = [1]
m = 1
while True:
    x = 3 * g[m - 1] + 1
    if x >= n: break
    g.append(x)
    m += 1
g = g[::-1]
 
# 1 output m
print(m)
# 2 output g
print(' '.join(map(str, g)))
 
# sort it
cnt = 0
for i in range(m):
    isort(a, n, g[i])
 
# 3 output cnt
print(cnt)
# 4 output sorted a
print('\n'.join(map(str, a)))

Measured memory_bytes: 189888
#include <iostream>
#include <string>
#include <set>
#include <math.h>
using namespace std;

int main(int argc, const char * argv[]) {

    int N, A;
    cin >> N;
    cin >> A;

    for(int i = 0; i <= A; ++i){
        if( (N - i)%500 == 0 ){
            cout << "Yes" << endl;
            return 0;
        } 
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	ll k;
	cin >> k;
	int n = 50;
	vl a(n, n-1);
	ll b = k / n, m = k % n;
	rep(i, n) a[i] += b;
	rep(i, m) a[i] += n - (m-1);
	REP(i, m , n) a[i] -= m;
	cout << n << endl;
	rep(i, n) {
		cout << a[i];
		if(i == n -1) cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func is_prime(n int) bool {
	if n == 2 {
		return true
	}

	if n < 2 || n%2 == 0 {
		return false
	}

	end_num := int(math.Sqrt(float64(n)))

	for i := 3; i <= end_num; i += 2 {
		if n%i == 0 {
			return false
		}
	}

	return true
}

func main() {
	var n int
	var cn int

	fmt.Scanf("%d", &n)

	pn := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &cn)
		if is_prime(cn) {
			pn++
		}
	}

	fmt.Println(pn)
}


Measured memory_bytes: 1688
A = input().strip()
N = len(A)
tot = 1+(N*(N-1))//2
C = {chr(i):[] for i in range(97,123)}
for i in range(N):
    C[A[i]].append(i)
cnt = 0
for a in C:
    n = len(C[a])
    cnt += (n*(n-1))//2
print(tot-cnt)

Measured memory_bytes: 83900
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf (1ll<<60)
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std;
inline LL gi() {
	LL x=0,f=1;char ch=getchar();
	while (ch<'0' || ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int maxn=1000010;
LL a[maxn],b[maxn];
int n;

int main() {
	scanf("%d",&n);
	LL maxl=-inf;a[1]=gi();
	for (int i=2;i<=n;i++) a[i]=gi(),b[i]=a[i]-a[i-1],maxl=max(b[i],maxl);
	b[1]=a[1]-a[n];maxl=max(b[1],maxl);
	for (int i=1;i<=n;i++) b[i]-=maxl;
	LL cnt=0;
	for (int i=1;i<=n;i++) {
		if (b[i]%n!=0) {puts("NO");return 0;}
		cnt-=b[i]/n;
	}
	LL s=0,t=(LL)(1+n)*n/2;
	for (int i=1;i<=n;i++) {
		s+=a[i];
		cnt-=s/t,s-=s/t*t;
	}
	if (cnt>0 || (cnt<0 && -cnt%n!=0) || s!=0) puts("NO");
	else puts("YES");
   return 0;
}


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

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

int main() {
    int n;
    cin >> n;
    int a[n+1];
    rep(i,n) cin >> a[i+1];
    int ans[n+1];
    rep(i,n) ans[i+1] = 0;
    //rep(i,n) cout << a[i] << endl;
    for(int i = n; i >= 1; --i) {
        //printf("OK\n");
        for(int j = i; j <= n; j += i) {
            ans[i] = (ans[i]+ans[j])%2;
        }
        ans[i] = (ans[i]+a[i])%2;
        //printf("OK2\n");
    }
    //rep(i,n) cout << ans[i+1] << endl;
    int cnt = 0;
    rep(i,n) {
        if(ans[i+1]) cnt++;
    }
    if (cnt) {
        cout << cnt << endl;
        rep(i,n) {
            if (ans[i+1]) {
                printf("%d\n", i+1);
            }
        }
    } else cout << 0 << endl;
    return 0;
}


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

int A,B,C,K;

void imput(){
cin >> A >> B >> C >> K;
}

void solve(){
  int rem1,rem2;
  rem1 = K-A;
  rem2 = rem1-B;
  
  if(rem1<=0) cout << K << endl;
  else if(rem2<=0) cout << A << endl;
  else cout << A-rem2 << endl;
}

int main(){
imput();
solve();
}

Measured memory_bytes: 3672
#二分探索を使った解法
import bisect
N,M = map(int,input().split())
A = list(map(int,input().split()))

A.sort()
while M != 0:
    x = bisect.bisect_left(A,A[-1]//2)
    if N-x <= M:
        M -= N-x
        for i in range(x,N):
            A[i] = A[i]//2
        A.sort()
    else:
        for i in range(N-M,N):
            A[i] = A[i]//2
        M = 0
        A.sort()

print(sum(A))

Measured memory_bytes: 14484
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000;
int n;
bool is_ok( int t, int x, int y ){
  if( t-x-y >= 0 && (inf + t - x - y) % 2 == 0 ){
    return true;
  }
  return false;
}
int main(){
  cin >> n;
  bool f = true;
  int t = 0, x = 0, y = 0;
  for(int i = 0; i < n; i++){
    int s, v, w;
    cin >> s >> v >> w;
    f = f && is_ok( s-t, v-x, w-y );
    t = s;
    x = v;
    y = w;
  }
  if( f ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N, M;
const int MAX_NM = 100010;
vector<int> edges[MAX_NM];
int deg[MAX_NM];
int main()
{
    cin >> N >> M;
    for (int i = 0; i < N + M - 1; i++)
    {
        int A, B;
        cin >> A >> B;
        A--, B--;
        edges[A].push_back(B);
        deg[B]++;
    }
    queue<int> que;
    for (int i = 0; i < N; i++)
    {
        if (deg[i] == 0)
        {
            que.push(i);
            break;
        }
    }
    vector<int> answers(N, -1);
    while (!que.empty())
    {
        auto p = que.front();
        que.pop();
        for (auto &q : edges[p])
        {
            deg[q]--;
            if (!deg[q])
            {
                que.push(q);
                answers[q] = p;
            }
        }
    }
    for (auto &val : answers)
    {
        cout << val + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int q = 0; q < n; q++){
        cin >> a[q];
    }
    int ans = 0;
    for (int q = 0; q < n; q++){
        if (q % 2 == 0 && a[q] % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int x,y;
  	cin>>x>>y;
  
  bool turukame=false;
  
  rep(i,x){
  	rep(j,x){
    	if(i+j==x&&2*i+4*j==y){
        	turukame=true;
        }
    }
  }
  
  if(2*x==y||4*x==y){
  	turukame=true;
  }
  
  if(turukame){
  	cout<<"Yes"<<endl;
  }
  
  else{
  	cout<<"No"<<endl;
  }
  
  
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
int p[100010];
int x[100010], y[100010];
int par[100010];

int root(int x) {
  return par[x] == x ? x : par[x] = root(par[x]);
}

void merge(int x, int y) {
  x = root(x); y = root(y);
  if (x == y) return;
  par[y] = x;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    p[i]--;
    par[i] = i;
  }
  for (int i = 0; i < M; i++) {
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
    merge(x[i], y[i]);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (root(i) == root(p[i])) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792