akhauriyash/Code-Regression huggingface dataset:
#pragma comment (linker, "/STACK:256000000")
 
#define _USE_MATH_DEFINES
#define _CRT_NO_DEPRECEATE
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <memory.h>
#include <sstream>
#include <queue>
#include <cassert>
#include <ctime>
#include <complex>
#include <unordered_map>
#include <random>
 
using namespace std;
 
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int64, int64> pll;
typedef pair<int64, int> pli;
typedef pair<pii, pii> piiii;
typedef pair<int64, int> pli;
typedef pair<int, char> pic; 

#define pb push_back
#define sq(x) ((x)*(x))
#define cube(x) (((x)*(x))*(x))
#define tmin(x,y,z) (min(min((x),(y)),(z)))
#define rand32() (((unsigned int)(rand()) << 16) | (unsigned int)(rand()))
#define rand64() (((unsigned int64)(rand32()) << 16) | (unsigned int64)(rand32()))
#define bit(mask, b) ((mask >> b) & 1)
#define biton(mask, bit) (mask | (((uint64)(1)) << bit))
#define bitoff(mask, bit) (mask & (~(((uint64)(1)) << bit)))
#define bitputon(mask, bit) (mask |= (((uint64)(1)) << bit))
#define bitputoff(mask, bit) (mask &= (~(((uint64)(1)) << bit)))
#define FAIL() (*((int*)(0)))++
#define INF ((int)(1e9) + 1337)
#define EPS (1e-9)
#define y1 yy1
#define y0 yy0
#define j0 jj0

const long double PI = acosl((long double)-1.0);
const int64 LINF = (int64)4e18;//((1ull << 63) - 1ull);
const int MOD = 1000000007;
int test;

const int MAXN = 2005;

int n;
int64 x;
int64 a[MAXN];
int64 ans, cur;
int64 mn[MAXN];

void init()
{
	scanf ("%d%lld", &n, &x);
	for (int i = 1; i <= n; i++)
	{
		scanf ("%d", &a[i]);
	}
}

void solve()
{
	init();
	for (int i = 1; i <= n; i++)
	{
		mn[i] = a[i];
		cur += mn[i];
	}
	ans = cur;
	for (int i = 1; i < n; i++)
	{
		cur += x;
		for (int j = 1; j <= n; j++)
		{
			int64 delta = mn[j] - (a[(j - i + n - 1) % n + 1]);
			if (delta > 0LL)
			{
				cur -= delta;
				mn[j] -= delta;
			}
		}
		ans = min(ans, cur);
		
	}
	printf("%lld\n", ans);
}

void precalc()
{
	
}

void test_output()
{
	
}

int main()
{
	//srand(time(0)); test_output(100, 100, 100); 
    //ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _MY_DEBUG
    freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#else
    //freopen(TASK ".in", "rt", stdin); freopen(TASK ".out", "wt", stdout);
#endif
	double start = clock();
	precalc();
	int tests = 1;
	//scanf ("%d", &tests);
	for (test = 1; test <= tests; test++)
	{
		solve();
	}
	//fprintf(stderr, "%.5lf\n", (clock() - start) / CLOCKS_PER_SEC);
    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;
typedef pair<int, int> P;

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

  if ((s[0] == s[1] && s[2] == s[3]) || (s[0] == s[2] && s[1] == s[3]) ||
      (s[0] == s[3] && s[1] == s[2])) {
    if (s[0] == s[1] && s[1] == s[2] && s[2] == s[3]) {
      puts("No");
      return 0;
    } else {
      puts("Yes");
      return 0;
    }
  } else {
    puts("No");
    return 0;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#define N  200001

int main(void){
  char s[N] = { '\0' };
  scanf("%s", s);
  int a, z;
  int c = 1;
  while(s[c] != '\0') c++;
  for(int i = 0; i < c; i++){
    if(s[i] == 'A'){
      a = i;
      break;
    }
  }
  for(int i = c; i > a; i--){
    if(s[i] == 'Z'){
      z = i;
      break;
    }
  }
  printf("%d\n", z - a + 1);
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main(){
	long double a,b,h,m;
	cin >> a >> b >> h >> m;
	
	long double hang = h*30 + (m/60)*30;
	long double mang = m*6;
	long double ang = abs(mang - hang);
	long double pi = 3.14159265358979323846;
	long double cosang = cos(ang * pi/180);
	long double res = sqrt(a*a + b*b - 2*a*b*cosang);
	
	cout << fixed << showpoint;
	cout << setprecision(20);
	cout << res << endl;
	
	return 0;
	
	
} 

Measured memory_bytes: 4152
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 2e9
#define EPS 1e-9
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define FOR(i,a,b) for (long long i = a; i < b; i++)
#define REV(i,a,b) for (long long i = a; i > b; i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define fd(n) fixed<<setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<long long> vi;
typedef std::vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll solve(ll x,ull y,ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
   
       float s;
       cin>>s;
       
       float x= (float)s/(float)3;
       float v=(float)(x*x*x);
       
       cout<<fd(6)<<v;
}


Measured memory_bytes: 256
import java.util.Random;
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Random rand = new Random();
    Scanner stdIn = new Scanner(System.in);

    String line = stdIn.nextLine();
    String ans = "";
    for (int i = 0; i < line.length(); i++) {
      char ch = line.charAt(i);
      if (Character.isLowerCase(ch)) ans += Character.toUpperCase(ch);
      else if (Character.isUpperCase(ch)) ans += Character.toLowerCase(ch);
      else ans += ch;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 31588
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define qu queue
#define ps(x) push(x)
#define vec vector
#define ft() front()
#define mst(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
#define md 998244353
 
 
 
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }                     
    return gcd(b%a,a);
}
ll power(ll x,ll y){            
    ll res=1;
    while(y>0){
        if(y%2==1){
            res=((res)*(x))%mod;
        }
        x=((x)*(x))%mod;
        y=y/2;
    }
    return res;
}
 




 
  
int main(){
 
  /*#ifndef ONLINE_JUDGE
    
   freopen("input.txt", "r", stdin);
   
   freopen("output.txt", "w", stdout);
   #endif*/

   ll n,i,k;
   sfl(k);
   auto cmp=[](string a,string b){

      if(a.size()!=b.size())return (a.size()<b.size());

      else{
        int n=a.size();

        for(int i=0;i<n;i++){
            if(b[i]==a[i])continue;

            if(b[i]>a[i])return true;

            else return false;
        }
      }

   };
   set<string,decltype(cmp)>st(cmp);

   f(i,1,10){
      string s="0";
      s[0]+=i;

      st.insert(s);
   }
    string s;
   while(k){

      auto it =st.begin();

      k--;

      n=(*it).size();

       s=*it;
       st.erase(it);

      char c=s[n-1];

      st.insert(s+c);

      if(c!='0')st.insert(s+(char)(c-1));

      if(c!='9')st.insert(s+(char)(c+1));



   }

   cout<<s;

  

   


   return 0;
 
  
 
    
 }

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

top1= -10**10
bot1= 10**10
top2= -10**10
bot2= 10**10
for _ in range(n):
	
	x,y = map(int, input().split(' '))
	tot1= x+y
	tot2= x-y
	if tot1> top1:
		top1= tot1
	if tot1< bot1:
		bot1= tot1
	if tot2>top2:
		top2= tot2
	if tot2<bot2:
		bot2= tot2

print(max(top1-bot1, top2-bot2))

Measured memory_bytes: 9212
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) {
        int a;
        cin >> a;
        A[i] = a - i + 1;
    }

    SORT(A);
    int b = A[N / 2];

    ll ans = 0;
    REP(i, N) { ans += abs(A[i] - b); }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<time.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

int main(void){
    int n,ans=0;
    string s;
    cin>>n>>s;
    int m[26],tmp;
    

    rep(c,n){
        rep(i,26)m[i]=0;
        tmp=0;
        rep(i,c){
            REP(j,c,n){
                if (s[i]==s[j]){
                    if (m[s[i]-'a']==0)tmp+=1;
                    m[s[i]-'a']=1;
                }
            }
        }
        ans=max(ans,tmp);
    }
    cout<<ans;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
    long long a,b,c,f=0,i,j,n;
    string s;
    cin>>s;
    n=s.size();
    a=0;
    b=n-1;
    while(a<b){
        if(s[a]!=s[b])f++;
        a++;
        b--;
    }
    cout<<f<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  ll a,b,c;
  cin >> a >> b >> c;

  if (!(a % 2 == 0 and b % 2 == 0 and c % 2 == 0)) {
    cout << 0 << endl;
    return 0;
  }

  if (a == b and b == c) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  while (true) {
    ll ta = b / 2 + c / 2;
    ll tb = a / 2 + c / 2;
    ll tc = a / 2 + b / 2;
    if (ta % 2 == 0 and tb % 2 ==0 and tc % 2 == 0) {
      ans += 1;
    } else {
      break;
    }

    a = ta; b = tb; c = tc;
  }

  cout << ans+1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

template<class Abel> struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<Abel> diff_weight;

	UnionFind(int n = 1, Abel SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(int n = 1, Abel SUM_UNITY = 0) {
		par.resize(n); rank.resize(n); diff_weight.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			int r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	Abel weight(int x) {
		root(x);
		return diff_weight[x];
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, Abel w) {
		w += weight(x); w -= weight(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	}
};
int main() {
	UnionFind<int> tree(1000100);
	int n, q; cin >> n >> q;
	REP(i, q) {
		int x; cin >> x;
		if (x) {
			int X, Y; cin >> X >> Y;
			if (!tree.issame(X, Y)) {
				cout << '?' << endl;
			}
			else {
				cout << tree.diff(Y, X) << endl;
			}
		}
		else {
			int X, Y, Z; cin >> X >> Y >> Z;
			tree.merge(Y,X,Z);
		}
	}
	return 0;
}



Measured memory_bytes: 14268
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
int top[80][80][12801];
bool memoo[6400];
int n, m;
int red[80][80];
int blue[80][80];
int maxsteps = 0;
int func(int i, int j, int sum){
    if (i >= n || j >= m){
        return 1;
    }
    if (top[i][j][sum]){
        
        return 1;
    }
    if (sum > 6400){
        return 1;
    }
    // choose red
    int sum1 = sum;
    sum1 += red[i][j];
    sum1 -= blue[i][j];
    // go down
    sum1 = abs(sum1);
    func(i+1, j, sum1);
    // go right
    func(i, j+1, sum1);
    
    // choose blue
    int sum2 = sum;
    sum2 -= red[i][j];
    sum2 += blue[i][j];
    sum2 = abs(sum2);
    // go down
    func(i+1, j, sum2);
    // go right
    func(i, j+1, sum2);
    if (i == n-1 && j == m-1){
        memoo[sum2] = true;
    }
    top[i][j][sum] = 1;
    if (i == n-1 && j == m-1){
        memoo[sum1] = true;
        memoo[sum2] = true;
    }
    return 1; 
}

int main(){
  prep();
 
  cin >> n >> m;
  
  for (int i=0; i<n; i++){
      for (int j=0;j <m; j++){
          cin >> red[i][j];
      }
  }
  for (int i=0; i<n; i++){
      for (int j=0;j <m; j++){
          cin >> blue[i][j];
      }
  }
  func(0, 0, 0);
  int minnest = 1000000000;
  for (int i=0; i<=6400; i++){
      if (memoo[i]){
          minnest = i;
          break;
      }
      
  }
  cout << minnest;
  return 0; 
}


Measured memory_bytes: 318592
from collections import Counter
 
 
def solve(n, ddd):
    if ddd[0] != 0:
        return 0
    cnt = Counter(ddd)
    if cnt[0] != 1:
        return 0
    max_c = max(cnt)
    for i in range(max_c + 1):
        if i not in cnt:
            return 0
 
    MOD = 998244353
    ans = 1
    for i in range(max_c):
        prev = cnt[i]
        curr = cnt[i + 1]
        ans = ans * pow(prev, curr, MOD) % MOD
    return ans
 
 
n = int(input())
ddd = list(map(int, input().split()))
 
print(solve(n, ddd))

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

int main(){
  int N;
  cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int ans=0;
  sort(v.begin(),v.end());
  for(int i=0;i<N-1;i++)ans+=v[i];
  ans+=v[N-1]/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M_PI  3.1415926535
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
// -----------------------------------------------CKMKB-----------------------------------------------------------
// -----------------------------------------------PKMKB-----------------------------------------------------------
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1;
  //cin>>t;
  while(t--)
  {
      ll n;
      cin>>n;
      vector<ll> a(n);
      ll ans = 0 ;
      for( ll i = 0 ; i<n ; i++ ) { cin>>a[i]; if( i%2==0 && a[i]%2!=0 ) ans++ ;}
      cout<<ans;

  }
  return 0;

}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
typedef long long ll;

int N;
ll dp[21000];

struct Block{
    int w,s,v;
    Block(int w,int s,int v) : w(w),s(s),v(v){}
    bool operator<(const Block &b) const { return w+s < b.w+b.s;}
};
vector<Block> blocks;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> N;
    REP(i,N){
        int w,s,v;
        cin >> w >> s >> v;
        blocks.emplace_back(w,s,v);
    }
    sort(blocks.begin(),blocks.end());
    REP(i,N){
        for(int j = blocks[i].s; j>=0; --j){
            if(dp[j+blocks[i].w] < dp[j] + blocks[i].v){
                dp[j+blocks[i].w] = dp[j] + blocks[i].v;
            }
        }
    }
    cout << *(max_element(dp,dp+21000)) << endl;
    return 0;
}

Measured memory_bytes: 384
import heapq

n = int(input())
a = list(map(int, input().split()))
score = [[0, 0] for _ in range(n + 1)]
h1 = a[0 : n]
h2 = [-a[2 * n + i] for i in range(n)]
maxscore = sum(h1)
minscore = -sum(h2)
heapq.heapify(h1)
heapq.heapify(h2)
score[0][0] = maxscore
score[n][1] = minscore
for i in range(n):
    heapq.heappush(h1, a[n + i])
    heapq.heappush(h2, -a[2 * n - 1 - i])
    maxscore = maxscore + a[n + i] - heapq.heappop(h1)
    minscore = minscore + a[2 * n - 1 - i] + heapq.heappop(h2)
    score[i + 1][0] = maxscore
    score[n - 1 - i][1] = minscore
ans = -pow(10, 15)
for i in range(n + 1):
    ans = max(ans, score[i][0] - score[i][1])
print(ans)

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

int main(){
    int ans, N;
    string s;
    bool flag = true;
    cin >> s;
    for(int i=0; i<s.size(); i++){
	if(i%2 == 0){
	    if(s[i] == 'L')
		flag = false;
	}
	else{
	    if(s[i] == 'R')
		flag = false;
	}
    }
    cout << (flag ? "Yes": "No") << endl;    
}


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

using namespace std;

const int MOD = 1000000007;
const int MAXN = 2050;

vector<int> f(MAXN + 1, 1);
vector<int> invf(MAXN + 1, 1);

inline int mpow(int a, int n) {
  int res = 1;
  while (n > 0) {
    if (n % 2 == 1) {
      res = 1LL * res * a % MOD;
    }
    a = 1LL * a * a % MOD;
    n /= 2;
  }
  return res;
}

int comb(int n, int r) {
  if (r < 0 || n < r)
    return 0;
  else
    return 1LL * f[n] * invf[r] % MOD * invf[n - r] % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;

  f[0] = 1;
  for (int i = 1; i < MAXN; i++) {
    f[i] = 1LL * f[i - 1] * i % MOD;
  }
  invf[MAXN - 1] = mpow(f[MAXN - 1], MOD - 2);
  for (int i = MAXN - 1; i >= 0; i--) {
    invf[i - 1] = 1LL * invf[i] * i % MOD;
  }

  for (int i = 0; i < K; i++) {
    cout << 1LL * comb(K - 1, i) * comb(N - K + 1, i + 1) % MOD << '\n';
  }
  return 0;
}


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using plglg = pair<ll, ll>;
using tlglglg = tuple<ll, ll, ll>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    int n; cin >> n;
    int d1, d2;
    int cont = 0;

    REP(i, n) {
        cin >> d1 >> d2;
        if (d1 == d2) {
            cont += 1;
        } else {
            cont = 0;
        }
        if (cont >= 3) {
            print("Yes");
            return 0;
        }
    }

    print("No");

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3648
#!/usr/bin/env python3

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

S = input()

ans = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        s = S[i:j+1]
        a = s.count('A')
        g = s.count('G')
        c = s.count('C')
        t = s.count('T')
        if a+g+c+t == len(s) and len(s) > ans:
            ans = len(s)

print(ans)


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

const int N = 1e5 + 7, MAX = 1e9;

int mx_idx[N], a[N], ans[N], ptr = 1, c[N], s[N];

struct node{
	int sum = 0, cnt = 0, l = -1, r = -1;
}t[N * 30];


void update(int v, int l, int r, int x) {
	if(l == r) {
		t[v].sum += x;
		t[v].cnt += 1;
		return;
	}
	t[v].l = t[v].l > 0 ? t[v].l : ++ptr;
	t[v].r = t[v].r > 0 ? t[v].r : ++ptr;
	int mid = (l + r) >> 1;
	if(mid >= x) {
		update(t[v].l, l, mid + 0, x);
	} else {
		update(t[v].r, mid + 1, r, x);
	}
	t[v].sum = t[t[v].l].sum + t[t[v].r].sum;
	t[v].cnt = t[t[v].l].cnt + t[t[v].r].cnt;
} 

pair <int, int> query(int v, int l, int r, int b, int e) {
	if(v < 0 || l > e || r < b) {
		return make_pair(0, 0);
	}
	if(l >= b && r <= e) {
		return make_pair(t[v].sum, t[v].cnt);
	}
	int mid = (l + r) >> 1;
	auto p = query(t[v].l, l, mid, b, e);
	auto q = query(t[v].r, mid + 1, r, b, e);
	return make_pair(p.first + q.first, p.second + q.second);
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		mx_idx[i] = a[i] > a[mx_idx[i - 1]] ? i : mx_idx[i - 1];
	}

	for(int i = n; i >= 1; i--) {
		update(1, 1, MAX, a[i]); s[0] += a[i];
		auto q = query(1, 1, MAX, a[i], MAX);
		tie(s[i], c[i]) = q;
	}

	int cur = mx_idx[n], ss = 0;

	while(cur) {
		int prv = mx_idx[cur - 1];
		int k = s[prv] - ss - c[prv] * a[prv];
		ans[cur] = k;
		ss += k;
		cur = prv;
	}

	for(int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 71992
//package oct30;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static Scanner io = new Scanner(System.in);

    public static void main(String[] args) {

        int N = io.nextInt();
        int K = io.nextInt();
        io.nextLine();

        ArrayList<Integer> stones = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            stones.add(io.nextInt());
        }
        ArrayList<Integer> min = new ArrayList<>();
        min.add(0);
        min.add(Math.abs(stones.get(0) - stones.get(1)));

        for (int i = 2; i < N; i++) {
            min.add(Math.abs(stones.get(i)-stones.get(i-1))+min.get(i-1));
//            System.out.println("add initial " + min.get(i));
//            System.out.println("i-K=" + (i-K) + "; j=" + (i-2));
            for (int j = i-2; j >= i-K; j--) {
                if (j >= 0) {
                    int curr = min.get(i);
                    int check = Math.abs(stones.get(i) - stones.get(j)) + min.get(j);
                    min.set(i, Math.min(curr, check));
//                    System.out.println("set min: " + min.get(i));
                }

            }

//
//            System.out.print("array so far: ");
//            for (int j : min) System.out.print(j + " ");
//            System.out.println();
        }
        System.out.println(min.get(N-1));

    }
}


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

using namespace std;
using ll = long long;

const ll INF = 1ll << 60;

int main() {
  ll m = INF;
  int n;
  cin >> n;
  vector<int> xs(n);
  rep(i, n) cin >> xs[i];
  for (int i = 1; i <= 100; i++) {
    ll sum = 0;
    rep(j, n) { sum += (xs[j] - i) * (xs[j] - i); }
    m = min(m, sum);
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <ctype.h>
 
void MCXI(char* mcxi,int num){                         //????????°???MCXI??????????????????
  if(num>=1000){
    if(num>=2000)*(mcxi++)=(num/1000)+'0';             //??????????????????2??\????????´??????*mcxi??????????????????????????¨????????????????????§?????????????????????
    *(mcxi++)='m';                                     //????????????????????¨?????°???????????????m???????????????
    num%=1000;                                         //1000??§?????£????????????num?????´??°????¬?????????????????????????
  }
  if(num>=100) {                                       //?????????????????????????????????????????¨??????
    if(num>=200)*(mcxi++)=(num/100)+'0';
    *(mcxi++)='c';
    num%=100;
  }
  if(num>=10) {                                        //?????????????????????????????????????????¨??????
    if(num>=20)*(mcxi++)=(num/10)+'0';
    *(mcxi++)='x';
    num%=10;
  }
  if(num>=1) {                                         //?????????????????????????????????????????¨??????
    if(num>=2)*(mcxi++)=(num/1)+'0';
    *(mcxi++)='i';
    num%=1;
  }
  *mcxi=0;                                             //*mcxi?????????0??????????????????
}
 
int decimal(const char* mcxi) {
  const char* nowp=mcxi;
  int num=1;
  int decimal=0;
  for(;*nowp;nowp++) {
    switch(*nowp) {
    case 'm':
      decimal+=1000*num;                               //?????????decimal?????????????????????1000???????????????
      num=1;                                           //num???1???????????????
      break;
    case 'c':                                          //?????????????????????????????????????????¨??????
      decimal+=100*num;
      num=1;
      break;
    case 'x':                                          //?????????????????????????????????????????¨??????
      decimal+=10*num;
      num=1;
      break;
    case 'i':                                          //?????????????????????????????????????????¨??????
      decimal+=1*num;
      num=1;
      break;
    default:
      if(isdigit(*nowp))num=*nowp-'0';                 //?????????????????????????????°??????num???????????????
    }
  }
  return decimal;                                      //???????????????????????°??????????????¨????????????
}
 
int main(void) {
  int num,i;
  char MCXI_1[100],MCXI_2[100];
 
  struct{                                              //????????¨????§?????????????
    char sum[100];
  }SUM[9999];
 
  scanf("%d",&num);                                    //??????n???????????????
 
  for(i=0;i<num;i++){
    scanf("%s%s",MCXI_1,MCXI_2);                       //2??????MCXI????????????????????????
    MCXI(SUM[i].sum,decimal(MCXI_1)+decimal(MCXI_2));  //2??????MCXI????????????decimal??¢??°????????£???????????°?????????
  }                                                    //MCXI??¢??°????????£???MCXI????????????????????????????????????i???????§??????????????????\??????
 
  for(i=0;i<num;i++){
    printf("%s\n", SUM[i].sum);                        //??????
  }
 
  return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct edge {
  int to, cost;
  edge(){}
  edge(int to, int cost):to(to), cost(cost){}
};
using Graph = vector<vector<edge>>;

int n, m;
Graph graph;
vint s;

vector<int> vec;
int dp[2002];
void dfs(int u, int p) {
  dp[u] = 0;
  int mxch = -1;
  for(edge& e : graph[u]) {
    if(e.to == p) continue;
    dfs(e.to, u);
    if(dp[u] < dp[e.to]+e.cost) {
      mxch = e.to;
      dp[u] = dp[e.to]+e.cost;
    }
  }
  if(mxch == -1) return;
  for(edge& e : graph[u]) {
    if(e.to == p || e.to == mxch) continue;
    vec.push_back(dp[e.to]+e.cost);
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> n >> m;
  graph.resize(n);
  rep(i, n-1) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    graph[a].emplace_back(b, c);
    graph[b].emplace_back(a, c);
  }
  s.resize(n);
  priority_queue<int> que;
  rep(i, n) cin >> s[i];
  rep(i, n) {
    vec.clear();
    dfs(i, -1);
    //cout<<i<<":"<<endl;
    for(int v : vec) {
      que.push(v*s[i]);
      //cout<<v*s[i]<<endl;
    }
    //cout<<dp[i]*s[i]<<endl;
    que.push(dp[i]*s[i]);
  }
  int ans = 0;
  while(!que.empty() && m--) {
    ans += que.top(); que.pop();
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 36036
#include<bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef pair<ll,ll> P;
const int INF=INT_MAX / 3;
const ll LINF=LLONG_MAX / 3LL;
#define CONST 1000000007
#define EPS (1e-8)
#define PB push_back
#define MP make_pair
#define sz(a) ((int)(a).size())
#define reps(i,n,m) for(int i=(n);i<int(m);i++)
#define rep(i,n) reps(i,0,n)
#define SORT(a) sort((a).begin(),(a).end())
ll mod(ll a,ll m){return (a%m+m)%m;}
int dx[9]={0,1,0,-1,1,1,-1,-1,0},dy[9]={1,0,-1,0,1,-1,1,-1,0};
ll n,ma, mb;

int main(){
  vector<ll> as, bs, cs;
  cin >> n >> ma >> mb;
  ll suma = 0, sumb = 0;
  rep(i, n) {
    ll a, b, c;
    cin >> a >> b >> c;
    as.PB(a);
    bs.PB(b);
    cs.PB(c);
    suma += a;
    sumb += b;
  }

  map<P, ll> mp;
  for(ll x=0; x < (1<<(n/2)); ++x) {
    ll a = 0, b = 0, c = 0;
    rep(i, n/2) {
      if((x >> i) & 1LL) {
        a += as[i];
        b += bs[i];
        c += cs[i];
      }
    }
    if(mp[P(a,b)] == 0 || mp[P(a, b)] > c) {
      mp[P(a,b)] = c;
    }
  }


  ll ans = LINF;

  for(ll x=0; x < (1<<(n - n/2)); ++x) {
    ll a = 0, b = 0, c = 0;
    rep(i, n-n/2) {
      if((x >> i) & 1LL) {
        a += as[i+n/2];
        b += bs[i+n/2];
        c += cs[i+n/2];
      }
    }
    if (ans <= c) continue;

    for (int i = 1;; i++) {
      if (suma < i*ma || sumb < i*mb) break;
      ll xa = i * ma;
      ll xb = i * mb;
      ll da = xa - a;
      ll db = xb - b;

      if(da == 0 && db == 0) {
        ans = min(ans, c);
        continue;
      }
      if(da <= 0 || db <= 0) {
        continue;
      }
      if(mp[P(da, db)] != 0) {
        ans = min(ans, mp[P(da, db)] + c);
      }
    }
  }

  cout << ((ans==LINF) ? -1 : ans) << endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);

  int m;
  cin >> m;
  vector<string> t(m);
  rep(i, m) cin >> t.at(i);

  map<string, int> cards;
  rep(i, n) {
    string name = s.at(i);
    if (cards.count(name)) {
      cards.at(name)++;
    } else {
      cards[name] = 1;
    }
  }
  rep(i, m) {
    string name = t.at(i);
    if (cards.count(name)) {
      if (cards.at(name) > 0) cards.at(name)--;
    }
  }

  int max_val = 0;
  for (auto p : cards) {
    auto value = p.second;
    max_val = max(max_val, value);
  }
  cout << max_val << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

#define TRUE 1
#define FALSE 0

int isprime(int);
int main(){
  int i,n, num, count=0;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &num);
    if(isprime(num) == TRUE) count++;
  }

  printf("%d\n", count);
  return 0;
}
  
int isprime(int x){
  int i;
  if(x == 2) return TRUE;
  
  if(x < 2 || x % 2 == 0) return FALSE;

  i = 3;
  while(i <= (int)sqrt(x * 1.0)){
    if(x % i == 0) return FALSE;
    i = i + 2;
  }
  return TRUE;
}



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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int x;cin >> x;
    cout << "ai1333";
    inc(i, 0, x/100){
        cout << "3";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3220
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var w = ReadLine();
            var chars = new long[26];
            foreach(var c in w)
                ++chars[c - 'a'];
            if (0 != chars.Where(c => c % 2 == 1).Count())
                WriteLine("No");
            else
                WriteLine("Yes");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13268
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b == c || b + c == a || c + a == b ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
char p[1000000]={1,1};
int w[1000000]={0};
int main(){
  int i,j,a,b,c=0,d,e;
  for(i=2;i*i<999984;i++){
    if(p[i])continue;
    for(j=2;i*j<999984;j++)p[i*j]=1;
  }
  for(i=0;i<999984;i++){
    if(p[i]==0)c++;
    w[i]=c;
  }
  int n,s;
  while(scanf("%d",&n),n){
    s=0;
    while(n--){
      scanf("%d %d",&a,&b);
      d=a+b;
      if(999983<d)d=999983;
      e=a-b-1;
      if(e<0)e=0;
      s+=w[d]-w[e]-1;
    }
    printf("%d\n",s);
  }
  return 0;
}

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


int main() {
	
	int N,p;
	cin >> N;
	vector<int> dp(N+1);
	for (int i=0; i<=N; i++){
		
		dp.at(i) = i;
		int j = 1;
		while(i >= pow(6, j) ){
			p = pow(6, j);
			dp.at(i) = min( dp.at(i), dp.at(i - p) + 1 );
			j++;
		}
		j = 1;
		while(i >= pow(9,j) ){
			p = pow(9, j);
			dp.at(i) = min( dp.at(i), dp.at(i - p) + 1);
			j++;
		}
		
	}
	cout << dp.at(N) << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 303;
int n,k,mo,s[N][N],f[N][N];
inline void add(int &a, int b) {a=a+b<mo?a+b:a+b-mo;}
int main() {
	read(n);read(k);read(mo);
	rep(i,0,n) s[0][i]=1;
	rep(i,1,n) rep(j,0,n-i) {
		int v=1; rep(p,0,j) {add(s[i][j],1LL*s[i-1][j-p]*v%mo); v=1LL*v*(i+1)%mo;}
	//	printf("s[%d][%d]=%d\n",i,j,s[i][j]);
	}
	f[0][0]=1;
	rep(i,0,k) rep(j,0,n) if (f[i][j]) rep(k,j,n) add(f[i+1][k],1LL*f[i][j]*s[j][k-j]%mo);
	cout<<f[k][n];
	return 0;
}


Measured memory_bytes: 896
#include <vector>
#include <tuple>
#include <algorithm>

template<class T>
struct minimum_spanning_tree {
    using value_type = T;
private :
    struct edge {
        int src, dst;
        value_type cst;
        edge (int src, int dst, value_type cst) :
            src(src), dst(dst), cst(cst) { }
        bool operator< (const edge &rhs) const {
            return (cst < rhs.cst);
        }
    };
    std::vector<edge> edges;
    std::vector<int> uf;

    bool unite (int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (uf[x] > uf[y]) std::swap(x, y);
        uf[x] += uf[y];uf[y] = x; return true;
    }

    int root (int x) {
        if (uf[x] < 0) return x;
        return (uf[x] = root(uf[x]));
    }

public : 
    minimum_spanning_tree (int n) : uf(n, -1) { }

    void add_edge (int src, int dst, value_type cst) {
        edges.emplace_back(src, dst, cst);
    }

    value_type solve () {
        value_type cost = 0;
        std::sort(edges.begin(), edges.end());
        for (const edge &e : edges) {
            if (unite(e.src, e.dst)) {
                cost += e.cst;
            }
        }
        return cost;
    }

};

#include <bits/stdc++.h>

int main() {
    int n, m;
    std::cin >> n >> m;
    minimum_spanning_tree<long long> mst(n);
    for (int i = 0; i < m; i++) {
        int s, t, c;
        std::cin >> s >> t >> c;
        mst.add_edge (s, t, c);
    }

    std::cout << mst.solve() << '\n';

    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
using namespace std;
int main() {

	int N;
	cin >> N;
	int A[2][100];
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) cin >> A[i][j];
	}
	int max_sum = 0;
	for (int i = 0; i < N; i++) {  // どこで下の列に行くか
		int sum = 0;
		for (int j = 0; j <= i; j++) sum += A[0][j];
		for (int j = i; j < N; j++) sum += A[1][j];
		if (sum > max_sum) max_sum = sum;
	}
	cout << max_sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include<iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	ll x,y;cin >> x >> y;
	
	if(x == y || x % y == 0)
	{
		cout << -1 << endl;
		return 0;
	}
	
	for(ll i = x;i <= 1000000000000000000LL;i += x)
	{
		if(i % y != 0)
		{
			cout << i << endl;
			return 0;
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 384
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define ri register int

using namespace std;

const int mx = 10000007;

typedef long long lo;

inline char gch()
{
    static char buf[100010], *h = buf, *t = buf;
    return h == t && ((t = (h = buf) + fread(buf, 1, 100000, stdin), t == h)) ? EOF : *h ++;
}

inline void re(int &x)
{
    x = 0;
    char a = gch(); bool b = 0;
    while(a < '0' || a > '9')
    {
        if(a == '-')
            b = 1;
        a = gch();
    }
    while(a >= '0' && a <= '9')
        x = (x << 3) + (x << 1) + a - '0', a = gch();
    if(b == 1)
        x *= -1;
}

int n, tot = -1, de[500], ans, ret, head[500], q[100010], ta, he;

struct in
{
	int x, y;
}r[110], b[110]; 

struct es
{
	int to, ne, co;
}ter[30030];

inline void build(int f, int l, int c)
{
	ter[++ tot] = (es){l, head[f], c}, head[f] = tot;
	ter[++ tot] = (es){f, head[l], 0}, head[l] = tot;
}

inline bool bfs()
{
	ta = he = 1;
	memset(de, 0, sizeof(de));
	de[0] = 1, q[he] = 0;
	while(he <= ta)
	{
		int qaq = q[he ++];
		for(ri i = head[qaq]; i != -1; i = ter[i].ne)
		{
			int to = ter[i].to;
			if(ter[i].co && !de[to])
				de[to] = de[qaq] + 1, q[++ ta] = to;
		}
	}
	return ((de[300] > 0) ? 1 : 0);
}

int dfs(int no, int fl)
{
	if(no == 300)
		return fl;
	for(ri i = head[no]; i != -1; i = ter[i].ne)
	{
		int to = ter[i].to;
		if(de[to] == de[no] + 1 && ter[i].co > 0)
		{
			int re = dfs(to, min(fl, ter[i].co));
			if(re > 0)
			{
				ter[i].co -= re, ter[i ^ 1].co += re; return re;
			}
		}
	}
	return 0;
}

int main()
{
	memset(head, -1, sizeof(head));
	re(n);
	for(ri i = 1; i <= n; i ++)
		re(r[i].x), re(r[i].y), build(0, i, 1);
	for(ri i = 1; i <= n; i ++)
		re(b[i].x), re(b[i].y), build(i + n, 300, 1);
	for(ri i = 1; i <= n; i ++)
		for(ri j = 1; j <= n; j ++)
			if(r[i].x < b[j].x && r[i].y < b[j].y)
				build(i, j + n, 1);
	while(bfs())
		while(ret = dfs(0, 1000000007))
			ans += ret;
	printf("%d", ans); 
}

Measured memory_bytes: 384
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main() {
	int64_t n; cin >> n;
	int64_t cnt, ans = 1000000000000;

	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0) {
			cnt = i + n / i;
			ans = min(ans, cnt);
			cnt = 0;
		}
	}

	cout << ans - 2 << endl;
}


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

int main() {

    ll N;
    cin >> N;

    ll MOD = 1e9 + 7;
    ll sum = 0;

    vl A(N);
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    sum %= MOD;
    ll ans = 0;
    rep(i, N-1) {
        if (A[i] > sum) sum += MOD;
        sum -= A[i];
        ans += (sum*A[i]);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4820
def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  # sumA = sum(A)
  reversedIntegraA = [0] * len(A)
  reversedIntegraA[-1] = A[-1]
  base = 10**9+7

  for i in reversed(range(len(A) - 1)):
    reversedIntegraA[i] = reversedIntegraA[i+1] + A[i]

  result = 0
  for i in range(len(A) - 1):
    result += A[i] * reversedIntegraA[i+1]
    if result > base:
      result %= base
  print(result)


if __name__ == "__main__":
  resolve()

Measured memory_bytes: 98704
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
m = [[0]*3 for i in range(3)]
ans,l,r = 0,0,0
for _ in range(N):
  b = int(input())
  for i in range(3):
    if b in A[i]:
      m[i][A[i].index(b)]=1
                
for i in range(3):
  t = sum(m[i])
  l += m[i][i]
  y = 0
  for j in range(3):
    y += m[j][i]
    if i+j == 2:
      r += m[i][j]
  if t==3 or y==3 or r==3 or l==3:
    ans=1

print('Yes' if ans else 'No')

Measured memory_bytes: 3064