akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#define NOT_E 200

double cequal(double *a,double *b,double *c,double *aa,double *bb,double *cc);
double equal(double a,double b,double c,double aa,double bb,double cc);
double answer(double x1,double x2,double y1,double y2,double *a,double *b);
int swap(double *a,double *b);

int main(){
	int i,cnt;
	double x1,x2,x3,y1,y2,y3,xp,yp/*¦*/,a1,a2,b1,b2,xm1,ym1,xm2,ym2,r;
	
	scanf("%d",&cnt);
	for(i=0;i<cnt;i++){
		
		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
		
		xp=equal(y1,y2,y3,x1,x2,x3);
		yp=equal(x1,x2,x3,y1,y2,y3);
		
		
		if (xp==NOT_E || yp==NOT_E){
			if(xp==NOT_E){
				cequal(&x1,&x2,&x3,&y1,&y2,&y3);
			}else if(yp==NOT_E){
				cequal(&y1,&y2,&y3,&x1,&x2,&x3);
			}
			answer(x3,x2,y3,y2,&a1,&b1);
			answer(x3,x1,y3,y1,&a2,&b2);
			
			xp=(b2-b1)/(a1-a2);
			yp=a1*xp+b1;
			
		}
		
		if(xp==x1){
			r=sqrt((xp-x1)*(xp-x1));
		}else if(yp==y2){
			r=sqrt((yp-y1)*(yp-y1));
		}else{
			r=sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
		}
		
		printf("%.3f %.3f %.3f\n",xp,yp,r);

	}
	return 0;
}
			
			
			
			

double cequal(double *a,double *b,double *c,double *aa,double *bb,double *cc){	/*a1=a2,a3ÆÈéæ¤ÉÀÑÖ¦é*/
	if(*a==*b){
	}else if (*b==*c){
		swap(a,c);
		swap(aa,cc);
	}else if (*c==*a){
		swap(b,c);
		swap(bb,cc);
	}else{
		return NOT_E;
	}
	
	return (*a+*b)/2;
}


double equal(double a,double b,double c,double aa,double bb,double cc){	/*ÀÑÖ¦È¢*/
	if(a==b){
	}else if (b==c){
		swap(&a,&c);
		swap(&aa,&cc);
	}else if (c==a){
		swap(&b,&c);
		swap(&bb,&cc);
	}else{
		return NOT_E;
	}
	return (aa+bb)/2;
}



double answer(double x1,double x2,double y1,double y2,double *a,double *b){	/*(x1,y1)Æ(x2,y2)Ì¼ñªüy=ax+bÌa,bð|C^ÅÔ·*/
	double xm,ym;
	*a=(x1-x2)/(y2-y1);
	xm=(x2+x1)/2;
	ym=(y2+y1)/2;
	*b=ym-*a*xm;
	return 0;
}

int swap(double *a,double *b){
	double temp;
	temp=*a;
	*a=*b;
	*b=temp;
	return 0;
}
	/*
	a2=(y1-y3)/(x3-x1);
	xm2=(x1+x3)/2;
	ym2=(x1+y3)/2;
	b2=ym2-a3*xm2;*/
	

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    char c[10];
    scanf("%s", c);
    
    // 2. '2' の 個数.
    int ans = 0;
    rep(i, 4) if(c[i] == '2') ans++;
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

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

using namespace std;

int main() {
	string str, m_str = "", ans = "";
	map<string, int> word;
	while (cin >> str) {
		word[str]++;
		if (str.size() > m_str.size()) m_str = str;
		if (word[str] > word[ans]) ans = str;
	}
	cout << ans << " " << m_str << endl;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,d,a,ans[105]={};
	cin>>n>>k;
	for(int i=0;i<k;i++){
		cin>>d;
		for(int j=0;j<d;j++){
			cin>>a;
			if(ans[a]==0){
				n--;
				ans[a]++;
			}
		}
	}
	cout<<n<<endl;
  return(0);
}

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

int main(void){
	string s;
	while(getline(cin,s),s!="."){
		vector<int> cnt;
		cnt.clear();
		for(int i = 0 ; i < s.size() ; i ++){
				if(s[i] == '[')
					cnt.push_back(1);	
				if(s[i] == ']'){
					if(cnt.size()==0){
						cnt.push_back(1);
						break;
					}
					if(cnt[cnt.size()-1] == 1)
						cnt.pop_back();
					else break;
				}
				
				if(s[i] == '(')
					cnt.push_back(2);
				if(s[i] == ')'){
					if(cnt.size()==0){
						cnt.push_back(2);
						break;
					}
					if(cnt[cnt.size()-1] == 2)
						cnt.pop_back();
					else break;
				}
//				cout<<s[i]<<" "<<sika<<" "<<maru;
		}
		if(cnt.size())
			cout<<"no";
		else 
			cout<<"yes";
		cout<<endl;
	}
} 

Measured memory_bytes: 1196
import sys

d = {'A': 0, 'C': 1, 'G': 2, 'T': 3}

the_hash = [None for _ in 'ACGT']

def insert(s):
    h = the_hash
    for c in s:
        if h[d[c]] is None:
            h[d[c]] = [None, None, None, None, False]
        h = h[d[c]]
    h[4] = True

def find(s):
    h = the_hash
    for c in s:
        if h[d[c]] is None:
            return False
        else:
            h = h[d[c]]
    else:
        return h[4]

n = int(input())
for _ in range(n):
    command, s = sys.stdin.readline().split()
    if command[0] == 'i':    # insert
        insert(s)
    elif find(s):   # find
        print('yes')
    else:
        print('no')



Measured memory_bytes: 41920
#include<stdio.h>

int main(){
  int n, i, j;
  scanf("%d", &n);
  
  for(i=1; i < 10; i++){
    for(j=1; j < 10; j++){
      if(n == i * j){
      	printf("Yes");
        exit(0);
      }
    }   
  }
  printf("No");
  exit(0);
}


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

using namespace std;

int main()
{
    long long int amt,cnt=0,amt1;
    cin>>amt;
    amt1=amt;
    amt=100;
    while(amt<amt1)
    {
        amt = amt * 1.01 ;
        cnt++;
    }
    cout<<ceil(cnt)<<endl;
    return 0;
}

Measured memory_bytes: 3776
#include <stdio.h>
int main(void)
{
	int n,k,l[100001],i,j,tmp,a=0;
	scanf("%d%d",&n,&k);
	for(i=0; i<n; i++){
		scanf("%d",&l[i]);
	}
	for(i=0; i<n; i++){
		for(j=i+1; j<n; j++){
			if(l[i]<l[j]){
				tmp=l[i];
				l[i]=l[j];
				l[j]=tmp;
			}
		}
	}
	for(i=0; i<k; i++){
		a=a+l[i];
	}
	printf("%d\n",a);
	return 0;
}

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

int main(){
    long long n_list[5] = {0};
    int N;
    string S;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> S;
        switch(S[0]){
            case 'M':
                n_list[0]++;
                break;
            case 'A':
                n_list[1]++;
                break;
            case 'R':
                n_list[2]++;
                break;
            case 'C':
                n_list[3]++;
                break;
            case 'H':
                n_list[4]++;
                break;
        }
    }
    long long ans = 0;
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans += n_list[i]*n_list[j]*n_list[k];
            }
        }
    }
    cout << ans;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod2 998244353
#pragma GCC optimize("-O2")
#define mod3 127
#define mod 1000000007
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector<vector<int>>
#define v4096 vector<vector<lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli, lli>
#define m32 map<int, int>
#define m64it map<lli, lli>::iterator
#define m32it map<int, int>::iterator
#define fastio                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ist insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define p_q priority_queue
#define min_p_q priority_queue<int, vt<int>, greater<int>>
using namespace std;
using namespace __gnu_pbds;
lli tmod(lli x, lli y)
{
    return (x % y + y) % y;
}
template <typename T>
void DEBUG_ARR(vt<T> a)
{
    f(i, 0, a.size()) cout << a[i] << " ";
    cout << "\n";
}
lli power(lli x, lli y) 
{
    lli res = 1;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;
    }
    if(res<0)res+=mod;
    return res; 
}

int main()
{   
    fastio;
    int h,n;
    cin>>h>>n;
    int x=0;
    f(i,0,n){
        int y;cin>>y;
        x+=y;
    }
    if(x>=h)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

using namespace std;

typedef long long ll;

ll dp[101010][2];
ll n;

int main()
{
	ll i,a;
	
	scanf("%lld",&n);
	
	dp[0][1] = -1e18;
	for(i=1;i<=n;i++){
		scanf("%lld",&a);
		if(a == 0){
			dp[i][1] = -1e18;
			dp[i][0] = max(dp[i-1][1], dp[i-1][0]);
		}
		else{
			dp[i][1] = max(dp[i-1][1] + 1 + (a-2)/2, dp[i-1][0] + (a-1)/2);
			dp[i][0] = max(dp[i-1][1] + 1 + (a-1)/2, dp[i-1][0] + a/2);
		}
	}
	
	printf("%lld\n",max(dp[n][0], dp[n][1]));
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint x(N+2);
    for(int i=1;i<=N;i++) cin>>x[i];

    int sum=0;
    REP(i,N+1) sum+=abs(x[i+1]-x[i]);
    
    for(int i=1;i<=N;i++){
        int cost=sum-(abs(x[i]-x[i-1])+abs(x[i+1]-x[i]))+abs(x[i+1]-x[i-1]);
        cout<<cost<<endl;
    }
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    string s;cin >> s;
    vvl dp(s.size()+10,vl(3));
    
    //dp[i][1,2]…i文字目までで、直近の文字の長さが1or2
    dp[1][0] = dp[2][1] = 1;
    for (int i = 0; i <= s.size(); i++) {
        if (i >= 1 && s[i - 1] != s[i])  // 1→1
            chmax(dp[i + 1][1], dp[i][1] + 1);
        if (i >= 2 && s[i - 2] != s[i] || s[i - 1] != s[i + 1])  // 2→2
            chmax(dp[i + 2][2], dp[i][2] + 1);
        chmax(dp[i + 2][2], dp[i][1] + 1);  // 1→2
        chmax(dp[i + 1][1], dp[i][2] + 1);  // 2→1
    }
    
    cout << max(dp[s.size()][1], dp[s.size()][2]) << endl;
}

Measured memory_bytes: 11412
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC142D
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            long[] ab = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            long gcd = Gcd(ab[0], ab[1]);
            var primes = FactorizePrimes(gcd);
            Console.WriteLine(primes.Distinct().Count() + 1);
        }

        public static long Gcd(long a, long b)
        {
            Func<long, long, long> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }

        static IEnumerable<long> FactorizePrimes(long n)
        {
            long i = 2;
            long temp = n;
            while (i < Math.Sqrt(n))
            {
                if (temp % i == 0)
                {
                    temp /= i;
                    yield return i;
                }
                else i++;
            }
            if (temp != 1) yield return temp;
        }
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int N = 1e3 + 1;
const int INF = 1 << 29;
 
struct IOsetup{
  IOsetup(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed;
    cout << setprecision(20);
  }
} IO;

int32_t main(){
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++){
    int x; cin >> x;
    m[x]++;
  }
  bool ok = true;
  for (auto it : m){
    if (it.second > 1){
      ok = false;
      break;
    }
  }
  cout << (ok ? "YES" : "NO") << endl;
}

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

int main() {
  double n, d;
  cin >> n >> d;
  vector<vector<int>> vec(n, vector<int>(d));
  
  for (int i = 0; i < n; i++){
    for (int j=0; j< d; j++){
      cin >> vec.at(i).at(j);
    }
  }
  
  int sum = 0;
  
  for (int i = 0; i < n; i++){
    for (int j=i + 1; j < n; j++){
      int a = 0;
      for (int h = 0; h < d; h++){
        a += (vec.at(i).at(h) - vec.at(j).at(h)) * (vec.at(i).at(h) - vec.at(j).at(h));
      }
      for (int k = 0; k <= a; k++){
        if (k*k == a){
          sum++;
        }
      }
    }
  }
  cout << sum << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
     
    using namespace __gnu_pbds;
    using namespace std;
     
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
    #define all(a) a.begin(),a.end()
    #define F first
    #define S second
    #define pb push_back
    #define ll long long
    #define vi vector<int>
    #define pi pair<int,int>
    #define mp make_pair
     
    #ifdef LOCAL
    #include "debug.h"
    #else
    #define debug(...) 42
    #endif
     
    const int mod=1e9+7;
     
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
    template<typename A> istream& operator>>(istream&,vector<A>&);
    void add(int&,int);
    int mul(int,int);
    int powz(int,int);
    template<typename A> ostream& operator<<(ostream&,vector<A>&);
     
    const int N=500001;
     
    int dp[100001][101][2];
    string k;
    int d,n,ans;
     
    int rec(int pos,int sum,int flag){
    	if(dp[pos][sum][flag]!=-1)return dp[pos][sum][flag];
    	dp[pos][sum][flag]=0;
    	if(pos==n){
    		if(sum%d==0)return dp[pos][sum][flag]=1;
    		return dp[pos][sum][flag]=0;
    	}
    	int ans=0;
    	int LMT=k[pos]-'0';
    	if(flag)LMT=9;
    	for(int i=0;i<=LMT;i++){
    		if(flag){
    			add(dp[pos][sum][flag],rec(pos+1,(sum+i)%d,flag));
    		}
    		else{
    			if(i<LMT){
    				add(dp[pos][sum][flag],rec(pos+1,(sum+i)%d,1));
    			}
    			else{
    				add(dp[pos][sum][flag],rec(pos+1,(sum+i)%d,flag));
    			}
    			
    		}
    			
    	}
    	return dp[pos][sum][flag];
    }
    	
     
     
    void solve(){
    	cin>>k>>d;
    	n=k.length();
      
    	for(int i=0;i<=n;i++){
    		for(int j=0;j<d;j++){
    			dp[i][j][1]=dp[i][j][0]=-1;
    		}
    	}
    	cout<<(rec(0,0,0)-1+mod)%mod;
    	
    }
    	
    signed main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	int tc=1;
    	//~ cin>>tc;
    	for(int _=0;_<tc;_++){
    		//~ cout<<"Case #"<<_+1<<": ";
    		solve();
    		if(_!=tc-1)
    		cout<<"\n";
    	}
    }
     
    int mul(int a,int b)
    {
    	return ((a)*1ll*(b))%mod;
    }
     
    void add(int &a,int b)
    {
    	a+=b;
    	if(a>=mod)a-=mod;
    	
    }
     
    int powz(int a,int b)
    {
    	int res=1;
    	while(b)
    	{
    		if(b&1)res=mul(res,a);
    		b/=2;
    		a=mul(a,a);
    	}
    	return res;
    }
     
    template <typename A, typename B>
    istream& operator>>(istream& input,pair<A,B>& x) {
    	input>>x.F>>x.S;
    	return input;
    }
     
    template <typename A>
    istream& operator>>(istream& input,vector<A>& x) {
    	for(auto& i:x)
    		input>>i;
    	return input;
    }
     
    template<typename A>
    ostream& operator<<(ostream& output,vector<A>& x) {
    	for(auto& i:x)
    	    output<<i<<' ';
    	return output;	
    }

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> h(n+1);
  int sum = 0;
  for (int i=0; i<n; i++) {
    cin >> h[i];
    sum += h[i];
  }
  h[n] = 0;
  int i = 0;
  bool flag = false;
  int ans = 0;
  if (sum==0) {
    cout << "0" << endl;
    return 0;
  }
  while (sum) {
    if (h[i%(n+1)]>0) {
      h[i%(n+1)]--;
      sum--;
      flag = true;
    }
    else {
      if (flag) ans += 1;
      flag = false;
    }
    i++;
  }
  cout << ans+1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
 
#define INF 1e9+7
#define mp make_pair
#define pii pair<int,int>
#define st first
#define nd second
#define pb push_back
 
typedef long long int lint;
typedef unsigned long long int ulint;
 
 
int main()
{
    int n;
    cin >> n;
 
    int arr[n+10];
    int dp[n+10];
 
    for (int i=1; i<n+1; i++)
        cin >> arr[i];
 
    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);
 
    for (int i=3; i<n+1; i++)
    {
        dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]));
    }
 
    cout << dp[n];
 
    return 0;
}

Measured memory_bytes: 1024
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K=MI()
    A=LI_()
    dist = [inf]*N

    now = 0
    flag = False
    start = 0
    for i in range(N+2):
        if(dist[now] != inf):
            cycle = i - dist[now]
            # print(cycle)
            # print(i,dist[now])
            if(K<dist[now]):
                flag = True
            else:
                K-=dist[now] ##出発点をnowにする
                start = now
                K%=cycle
            break
        dist[now] = i
        now = A[now]
    # print(K,start)
    for i in range(K):
        start = A[start]
    print(start+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 100016
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int main(void) {

  int n, C, d[501][501], c[501][501];
  cin >> n >> C;
  rep(i, C) rep(j, C) cin >> d[i][j];
  rep(i, n) rep(j, n) {
    cin >> c[i][j];
    c[i][j]--;
  }

  vector<int> col[3];
  rep(i, n) rep(j, n) col[(i + j) % 3].push_back(c[i][j]);

  int ans[3][40] = {};
  rep(i, C) {
    rep(j, 3) rep(k, col[j].size()) ans[j][i] += d[col[j][k]][i];
  }

  int a =INT_MAX;
  rep(i, C) rep(j, C) rep(k, C) {
    if (i != j && j != k && k != i) {
      a = min(a, ans[0][i]+ans[1][j]+ans[2][k]);
    }
  }
  cout << a << endl;

  return 0;

}


Measured memory_bytes: 2544
n = int(input())
s = [input() for _ in range(n)]

d = [float("inf")]*26
for i in range(n):
    e = [0]*26
    for si in s[i]:
        e[ord(si) - 97] += 1
    for i in range(26):
        d[i] = min(d[i], e[i])

ans = ""
for i in range(26):
    ans += chr(i + 97) * d[i]

print(ans)

Measured memory_bytes: 38896
//Number 1165

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  int n, i, j, sq, dir, height_u, height_d, width_r, width_l;
  int pos[2][200];

  while(1)
    {
      height_u = 0;
      height_d = 0;
      width_r = 0;
      width_l = 0;
      for(i=0; i<2; i++)
	for(j=0; j<200; j++)
	  pos[i][j] = 0;
      
      scanf("%d", &n);
      if(n==0)
	break;

      for(i=1; i<n; i++)
	{
	  scanf("%d %d", &sq, &dir);

	  
	  if(dir==0)
	    {
	      pos[0][i] = pos[0][sq]-1;
	      pos[1][i] = pos[1][sq];
	      if(width_l<abs(pos[0][i]) && pos[0][i]<0)
		width_l = abs(pos[0][i]);
	    }
	  else if(dir==1)
	    {
	      pos[0][i] = pos[0][sq];
	      pos[1][i] = pos[1][sq]-1;
	      if(height_d<abs(pos[1][i]) && pos[1][i]<0)
		height_d = abs(pos[1][i]);
	    }
	  else if(dir==2)
	    {
	      pos[0][i] = pos[0][sq]+1;
	      pos[1][i] = pos[1][sq];
	      if(width_r<abs(pos[0][i]) && pos[0][i]>0)
		width_r = abs(pos[0][i]);
	    }
	  else if(dir==3)
	    {
	      pos[0][i] = pos[0][sq];
	      pos[1][i] = pos[1][sq]+1;
	      if(height_u<abs(pos[1][i]) && pos[1][i]>0)
		height_u = abs(pos[1][i]);
	    }
	}
      
      printf("%d %d\n", width_l+width_r+1, height_u+height_d+1);

    }
  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace d
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s[0] == s[1])
            {
                Console.WriteLine("1 2");
                return;
            }
            for (int i = 0; i < s.Length - 2; i++)
            {
                string t = s.Substring(i, 3);
                if (t[0] == t[1] || t[1] == t[2] || t[2] == t[0])
                {
                    Console.WriteLine("{0} {1}", i + 1, i + 3);
                    return;
                }
            }
            Console.WriteLine("-1 -1");
        }
    }
}


Measured memory_bytes: 6232
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

ll n,k;
vvi E(111111);
ll dp[111111];

ll dfs(ll now, ll par,ll num){
  ll kake = 1,minus=0;
  if(par != -1)minus++;
  for(auto e:E[now]){
    if(e == par)continue;
    kake *= (dfs(e, now, k-minus-1))%MOD;
    //cout<<e<<" "<<now<<" "<<k-minus<<endl;
    kake %= MOD;
    minus++;
  }
  //    cout<<now<<" "<<par<<" "<<kake<<endl;
  return (dp[now] = max(0LL,(kake*num)%MOD));
}
int main(){
  cin>>n>>k;
  for(int i = 0;i < n-1;i++){
    ll a,b;cin>>a>>b;
    a--;b--;
    E[a].pb(b);
    E[b].pb(a);
  }
  cout<<dfs(0,-1,k)<<endl;
  return 0;
}


Measured memory_bytes: 12672
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, k, m;
        String[] input;
        while (true) {
            input = sc.nextLine().trim().split(" ");
            n = Integer.parseInt(input[0]);
            k = Integer.parseInt(input[1]);
            m = Integer.parseInt(input[2]);

            if (n == 0) break;
            List<Integer> clock = new ArrayList<>();
            for (int i = 1; i <= n; i++) {
                clock.add(i);
            }

            // Initial removal
            clock.remove(m-1);
            int idx = m-1;

            while (clock.size() > 1) {
                idx = (idx + k - 1) % clock.size();
                clock.remove(idx);
            }

            System.out.println(clock.get(0));
        }
    }
}

Measured memory_bytes: 44240
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define vi vector<int>
#define Sort(v) sort(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;




int main(){
    double r; cin >> r;
    
    double pi = 3.141592653589;
    double s = r*r*pi;
    double l = 2*r*pi;
    
    cout << fixed;
    cout <<setprecision(17) << s << " " << l << endl;
    
    
}









Measured memory_bytes: 3288
#include <bits/stdc++.h>  // ver2.2.8
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  
  vector<VVi> name(4,VVi(4,Vi(4,1))),now;
  
  name[0][1][2] = 0;
  name[0][2][1] = 0;
  name[1][0][2] = 0;
  
  rep(QW,0,n-3){
    now = name;
    
    rep(i,0,4){
      rep(j,0,4){
        rep(k,0,4){
          name[j][k][i] = (now[0][j][k]+now[1][j][k]+now[2][j][k]+now[3][j][k])%MOD;
        }
      }
    }
    
    name[0][1][2] = 0;
    name[0][2][1] = 0;
    name[1][0][2] = 0;
    
    name[3][1][2] -= now[0][3][1];
    name[1][3][2] -= now[0][1][3];
    name[1][1][2] -= now[0][1][1];
    
  }
  
  int ans=0;
  
  rep(i,0,4){
    rep(j,0,4){
      rep(k,0,4){
        ans += name[i][j][k];
        ans %= MOD;
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n, k, q = map(int, input().split())
aq = [int(input()) for i in range(q)]
point = [k for i in range(n)]
correct_ans = [0 for i in range(n)]

for i in range(q):
    correct_ans[aq[i] - 1] += 1
    
point = ['Yes'  if p - (q - ca) > 0 else 'No' for (p, ca) in zip(point, correct_ans)]

for p in point:
    print(p)

Measured memory_bytes: 9468
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    // A > B で考える
    ll cnt ;
    ll A,B,C;
    for(ll A=2;A<=N;A++){
        for(ll B=1;B<A;B++){
            if((N - (A*B) )> 0){
                cnt++;
            }
            else{
                break;
            }
        }
    }
    // 
    cnt = cnt* 2;
    //
    ll n;
    for(ll i=1;i<=N;i++){
        if(i*i > N){
            n = i-1;
            break;
        }
    }
    //
    for(ll i=1;i<=n;i++){
        if( ( N - (i*i)) > 0){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

#define ll long long
//~ #define endl '\n'

void solve(){
	int k; cin>>k;
	int num = 0;
	for(int i = 1; i<=10000007; i++){
		num = num * 10;
		num = num + 7;
		num = num % k;
		if(num == 0){
			cout<<i<<endl;
			return;
		}
	}
	cout<<-1<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1; //cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define int ll
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
/*inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}*/
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RANK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
signed main(){
    string s;
    cin >> s;
    if(s == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
    } else if(s.size() == 26){
        int num = 0;
        for(int i = 25; i >= 0; i--){
            if(s[i-1] < s[i]){
                num = i-1;
                break;
            }
        }
        string g = s.substr(0,num);
        cout << g;
        for(char x = s[num] + 1; x <= 'z'; x++){
            int found = 0;
            for(int j = 0; j < g.size(); j++){
                if(g[j] == x) found = 1;
            }
            if(!found){
                cout << x << endl;
                break;
            }
        }
    } else {
        cout << s;
        for(char x = 'a'; x <= 'z'; x++){
            int found = 0;
            for(int j = 0; j < s.size(); j++){
                if(s[j] == x) found = 1;
            }
            if(!found){
                cout << x << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		
	Scanner sc=new Scanner(System.in);
	     int n=sc.nextInt();
	     int m=sc.nextInt();
	     ArrayList<ArrayList<Integer>> a=new ArrayList<>();
for(int i=0;i<n;i++) {
	a.add(new ArrayList<Integer>());
}
for(int j=0;j<m;j++) {
	int x=sc.nextInt()-1;
	int y=sc.nextInt()-1;
	a.get(x).add(y);
	a.get(y).add(x);
}
boolean vis[]=new boolean[n];
ans=0;
	System.out.println(dfs(a,0,vis,1,n));
	}
static int ans=0;	
	static int dfs(ArrayList<ArrayList<Integer>> a,int src,boolean vis[],int count,int n) {
		vis[src]=true;
		for(int i:a.get(src)) {
			if(vis[i]==false) {
				
				dfs(a,i,vis,count+1,n);
			}
		}
		if(count==n) {
		ans++;
		vis[src]=false;
			}else {
				vis[src]=false;
			}
		
		return ans;
	}
	static int[] arr(int n,Scanner sc) {
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		return a;
}

}


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

int main(void)
{
	int n;
	int a, b, c, d, e;
	
	while (cin >> n, n){
		int ma, mi;
		cin >> a >> b >> c >> d >> e;
		ma = mi = a + b + c + d + e;
		for (int i = 0; i < n - 1; i++){
			cin >> a >> b >> c >> d >> e;
			int sum = a + b + c + d + e;
			ma = max(ma, sum);
			mi = min(mi, sum);
		}
		cout << ma << " " << mi << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
			System.out.println((long)Math.pow(k-1, n-1)*k);
	}
}

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

using namespace std;

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

const int64_t MOD = 1'000'000'007L;

int64_t dpow(int64_t x, int64_t y) {
  if (y == 0) {
    return 1;
  }
  if (y % 2 == 0) {
    return dpow(x * x % MOD, y / 2);
  } else {
    return x * dpow(x, y - 1) % MOD;
  }
}

int64_t inv(int64_t x) { return dpow(x, MOD - 2); }

int main() {
  int64_t n, k;
  cin >> n >> k;

  vector<int64_t> fact(n + 1);
  fact[0] = 1;
  rep(i, n) { fact[i + 1] = fact[i] * (i + 1) % MOD; }

  int64_t result = 0;
  irep(i, min(n - 1, k)) {
    int64_t comb1 = fact[n] * inv(fact[i]) % MOD * inv(fact[n - i]) % MOD;
    int64_t comb2 =
        fact[n - 1] * inv(fact[n - i - 1]) % MOD * inv(fact[i]) % MOD;
    result += comb1 * comb2 % MOD;
    result %= MOD;
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int n;cin >> n;
    if (n <= 999)
        cout << "ABC" << endl;
    else
        cout << "ABD" << endl;
    return 0;
}


Measured memory_bytes: 3600
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
x_diff = sorted([x[i+1]-x[i] for i in range(m-1)], reverse=True)
if n >= m:
    print(0)
else:
    print(x[-1]-x[0] - sum(x_diff[:n-1]))

Measured memory_bytes: 58920
#include<stdio.h>

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	int arr[n];
	for(int i=0; i<n; i++){
		scanf("%d", &arr[i]);
 	}
	for(int i=0; i < n-k; i++){
		if(arr[i] < arr[i+k]){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 2396
#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

typedef long long ll;

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

const int INF = 100000000;
const int MOD = 1000000007;
/////////////////////////////////////////


bool isUnb(string s){
  if (s[0]==s[1]||s[0]==s[2]||s[1]==s[2])
    return true;
  else
    return false;
}

int main(){
  int a = -1, b = -1;
  string s;
  cin >> s;
  if (s.length() > 2) {
    for (int i = 0; i < s.length() - 2; i++) {
      if (isUnb(s.substr(i, i+2))) {
        a = i + 1;  b = i + 3;
        break;
      }
    }
  } else if (s.length() == 2) {
    if (s[0] == s[1]){
      a = 1;  b = 2;
    }
  }
  printf("%d %d\n", a, b);
  return 0;
}


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

int main(int argc, char** argv) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int cnt[n][26];
    memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (char ch : s) cnt[i][ch - 'a']++;
    }
    for (int i = 0; i < 26; ++i) {
        int mn = cnt[0][i];
        for (int j = 1; j < n; ++j) mn = min(mn, cnt[j][i]);
        for (int j = 0; j < mn; ++j) cout << (char)('a' + i);
    }
    cout << endl;
    return 0;
}


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

int main(int argc, char const* argv[])
{
	int n, b, f, r, v, bill[4][3][10] = {{{}}};
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> b >> f >> r >> v;
		bill[b-1][f-1][r-1] += v;
	}
	

	for (int i=0; i<4; i++) {
		for (int j=0; j<3; j++) {
			for (int k=0; k<10; k++) {
				cout << " " << bill[i][j][k];
			}
			cout << endl;
		}
		if (i==3) return 0;
		cout << "####################" << endl;
	}
	return 0;
}


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

int main() {
  ll n, ans = 0;
  cin >> n;

  vector<string> s(n);
  map<string, ll> p;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    p[s[i]]++;
  }

  for (int i = 0; i < n; i++) {
    if (p.count(s[i])) {
      ans += (p[s[i]] * (p[s[i]] - 1)) / 2;
      p.erase(s[i]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 18176
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static final long MOD = 1000000007;
    private static long[] x;
    private static long[] y;
    private static int N;
    private static int N1;
    private static int N2;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());

	x = new long[N+2];	// x[i] = i!, i=0..N+1
	y = new long[N+2];	// y[i] = (i!)^-1, i=0..N+!
	x[0] = 1;
	for (int i = 1; i < N+2; i++) {
	    x[i] = (i * x[i-1]) % MOD;
	}
	// y[N+1] = pow(x[N+1], MOD-2) % MOD;
	// for (int i = N; i >= 0; i--) {
	//     y[i] = ((i+1) * y[i+1]) % MOD;
	// }
	for (int i = 0; i < N+2 ; i++) {
	    y[i] = pow(x[i], MOD-2) % MOD;
	}

	int[] a = new int[N+1];	// 0..N
	for (int i = 0; i < N+1; i++) {
	    a[i] = -1;
	}
	int index1 = 0;
	int index2 = 0;
	for (int i = 0; i < N+1; i++) {
	    int num = Integer.parseInt(scan.next());
	    if(a[num] < 0) a[num] = i;
	    else {
		index1 = a[num];
		index2 = i;
		break;
	    }
	}
	N1 = index1;
	N2 = N - index2;

	for (int k = 1; k <= N+1; k++) {
	    long result = combination(N+1, k) % MOD;
	    result = (result - combination(N1+N2, k-1) + MOD) % MOD;
	    // result = result - combination(index1-1+N-index2, k-1);	    
	    // for (int i = 1; i <= k; i++) {
	    // 	result = result - (combination(N1, i-1) * combination(N2, k-i)) % MOD;
	    // }
	    System.out.println(result);
	}
	scan.close();
    }

    private static long pow(long x, long y) {
	if(y == 0) return 1;

	if(y % 2 == 0) {
	    long x2 = pow(x, y/2);
	    return (x2 * x2) % MOD;
	} else {
	    long x2 = pow(x, y/2);
	    return (((x * x2) % MOD) * x2) % MOD;
	}
    }

    private static long combination(int n, int r) {
	if(n < r) return 0;
	
	return (((x[n] * y[r]) % MOD) * y[n-r]) % MOD;
    }
}


Measured memory_bytes: 53884
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back

#define rep(i, n) for (int i=0;i<(n);++i)
#define rep2(i, s, n) for (int i=s;i<(n);++i)
#define rev(i, n) for (int i=(n);i>0;--i)
#define INF (1e9+1e9)

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

    rep2(i,1,3501) rep2(j,1,3501) {
        ll r = 4*i*j-N*i-N*j, l = N*i*j;
        if (r > 0 && l % r == 0) {
            cout << i << " " << j << " " << l/r << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import qualified Data.IntMap as IM

solve :: Int -> Maybe (Int, [[Int]])
solve n = do
  k <- getK n
  let mp0 = foldr op (IM.fromList (zip [1..k] (repeat [])))
            $ zip [1..] [(p,q) | q <- [k,k-1..2], p <- [1..q-1]]
      op :: (Int, (Int,Int)) -> IM.IntMap [Int] -> IM.IntMap [Int]
      op (m, (p,q)) mp = IM.adjust (m:) p $ IM.adjust (m:) q mp
  return (k, map ((k-1):) (map snd (IM.toList mp0)))

getK :: Int -> Maybe Int
getK n = let k = ceiling (sqrt (fromIntegral (2*n)))
         in if k*(k-1) == 2*n then Just k
            else if (k+1)*k == 2*n then Just (k+1)
                 else Nothing

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Maybe (Int, [[Int]])
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
  in solve n

outAnswer :: Maybe (Int, [[Int]]) -> IO ()
outAnswer Nothing = putStrLn "No"
outAnswer (Just (n, xs)) = do
  putStrLn "Yes"
  putStrLn (show n)
  putStr (unlines (map (unwords . map show) xs))

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 15228
n = int(input())
ary = [int(input()) for _ in range(n)]
total = sum(ary)
ans = 0
if total % 10 != 0:
    print(total)
    exit()
for i in ary:
    a = total - i
    if a % 10 != 0:
        ans = max(ans,a)
print(ans)

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll L, R;
    cin >> L >> R;

    ll ans;

    if (R - L + 1 >= 2019) {
        ans = 0;
    }
    else {
        ans = 2018;
        for (ll i = L; i < R; i++) {
            for (ll j = i + 1; j <= R; j++) {
                ans = min(ans, i * j % 2019);
            }
        }
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

int main() {
	// your code goes here
	int n, i, j, k;
	cin >> n;
	cin >> k;
	int arr[n];
	for(i = 0; i<n; i++) cin >> arr[i];
	int ans[n] = {0};
	ans[0] = 0;
	
	for(i = 1; i<n; i++){
		int prev = INT_MAX;
		for(j = min(i,k); j >= 0; j--){
			ans[i] = min(prev, ans[i-j] + abs(arr[i] - arr[i-j]));
			prev = ans[i];
		}
	}

	cout << ans[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

using namespace std;

struct Node{
    int parent;
    int left;
    int right;
};

Node nodes[25];

void preorder(int current){
    printf(" %d", current);
    if(nodes[current].left != -1){
        preorder(nodes[current].left);
    }
    if(nodes[current].right != -1){
        preorder(nodes[current].right);
    }
}

void inorder(int current){
    if(nodes[current].left != -1){
        inorder(nodes[current].left);
    }    
    printf(" %d", current);
    if(nodes[current].right != -1){
        inorder(nodes[current].right);
    }
}

void postorder(int current){
    if(nodes[current].left != -1){
        postorder(nodes[current].left);
    }
    if(nodes[current].right != -1){
        postorder(nodes[current].right);
    }    
    printf(" %d", current);
}

int main(){
    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        nodes[i].parent = nodes[i].left = nodes[i].right = -1;
    }

    for(int i = 0; i < n; i++){
        int id;
        scanf("%d", &id);
        scanf("%d %d", &nodes[id].left, &nodes[id].right);
        if(nodes[id].left != -1){
            nodes[nodes[id].left].parent = id;
        }
        if(nodes[id].right != -1){
            nodes[nodes[id].right].parent = id;
        }
    }

    int root;
    for(int i = 0; i < n; i++){
        if(nodes[i].parent == -1){
            root = i;
            break;
        }
    }

    printf("Preorder\n");
    preorder(root);
    printf("\n");

    printf("Inorder\n");
    inorder(root);
    printf("\n");

    printf("Postorder\n");
    postorder(root);
    printf("\n");
}


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

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

    vector<int> a(1);
    a.push_back(s);

    for(int i = 2; i <= 1000001; i++){
        int n = a[i - 1];
        if(n % 2 == 0) a.push_back(n / 2);
        else a.push_back(3 * n + 1);

        for(int j = 1; j < i; j++){
            if(a[j] == a[i]){
                cout << i << endl;
                return 0;
            }
        }
    }
}

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 ;
const int mod=1000000007 ;

void solve(){
	
	int n ;
	cin>>n ;


	ll ans=1 ;

	for(int i=1;i<=n;i++)	
	{
		ans=(ans*i)%mod ;
	}

	cout<<ans ;
}


int main(){
	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<pair<int,int> > xy(n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin >> x >> y;
		xy[i]=make_pair(x,y);
	}

	vector<pair<int,int> > pq;

	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			if(i==j)continue;
			pq.push_back(make_pair(xy[i].first-xy[j].first,xy[i].second-xy[j].second));
		}
	
	sort(pq.begin(),pq.end());

	int ans=1;
	int tmp=1;
	pair<long long,long long> bef=make_pair(-10000000000000,-10000000000000);
	for(int i=0;i<pq.size();i++)
	{
//		cout << " * " << pq[i].first << " : " << pq[i].second << endl;
		if(bef.first==pq[i].first and bef.second==pq[i].second)
		{
			tmp++;
		}
//		else if(bef.first*(-1)==pq[i].first and bef.second*(-1)==pq[i].second)
//		{
//			tmp++;
//		}
		else
		{
			if(tmp>=ans)
			{
//				cout << pq[i-1].first << " : " << pq[i-1].second << " : " << tmp << endl;
				ans=tmp;
			}
			tmp=1;
		}
		bef=pq[i];
	}
	if(tmp>=ans)
	{
//		cout << pq[n-1].first << " : " << pq[n-1].second << " : " << tmp << endl;
		ans=tmp;
	}


//	cout << ans << endl;
//	cout << n-ans << endl;
	cout << max(1,n-ans) << endl;
		
	


	
}

Measured memory_bytes: 256