akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
 
int n,nn;
struct node{int p,f,s;long long d,ss;};
node a[100010];
 
void qsort(int l,int r)
{
	int i,j;
	node m,t;
	i=l;j=r;
	m=a[(l+r)/2];
	while (i<=j)
	{
		while (a[i].d>m.d) i++;
		while (a[j].d<m.d) j--;
		if (i<=j)
		{
			t=a[i];a[i]=a[j];a[j]=t;
			i++;j--;
		}
	}
	if (l<j) qsort(l,j);
	if (i<r) qsort(i,r);
}

int find(long long x,int l,int r)
{
	int m=(l+r)/2;
	while (l<=r)
	{
		if (a[m].d==x) return m;
		if (a[m].d>x) l=m+1;
		else r=m-1;
		m=(l+r)/2;
	}
	return -1;
}
 
int main()
{
	scanf("%d",&n);
	nn=n-2;
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i].d);
		a[i].p=i;
		a[i].f=-1;
		a[i].s=1;
		a[i].ss=0;
	}
	qsort(1,n);
	bool ok=true;
	for (int i=1;i<n;i++)
	{
		long long fd=a[i].d-(n-a[i].s*2);
		int fn;
		fn=find(fd,i+1,n);
		if (fn==-1 || fd>a[i].d) {ok=false;break;}
		a[i].f=a[fn].p;
		a[fn].s+=a[i].s;
		a[fn].ss+=a[i].s+a[i].ss;
	}
	for (int i=1;i<=n;i++)
		if (a[i].f==-1 && a[i].ss!=a[i].d) {ok=false;break;}
	if (ok)
	{
		for (int i=1;i<=n;i++)
		{
			if (a[i].f!=-1) printf("%d %d\n",a[i].f,a[i].p);
		}
	}
	else printf("-1");
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int mod = 1e9+7;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	vector<int> candies(n+1,0);
	for(int i=1;i<=n;i++) {
		cin>>candies[i];
	}
	vector<vector<int>> dp(n+1,vector<int>(k+1));
	dp[0][0] = 1;
	for(int i=1;i<=k;i++) {
		dp[0][i] = 0;
	}
	for(int i=1;i<=n;i++) {
		vector<int> sum(k+1);
		sum[0] = dp[i-1][0];
		for(int j=1;j<=k;j++){
			sum[j] = (sum[j-1] + dp[i-1][j])%mod;
		}
		for(int j=0;j<=k;j++) {
			if(j<=candies[i]) {
				dp[i][j] = sum[j];
			}
			else {
				int uptill = j-candies[i]-1;
				dp[i][j] = (sum[j] - sum[uptill] + mod)%mod;
			}
		}
		sum.clear();
	}
	cout<<dp[n][k];
}

Measured memory_bytes: 43248
// Ki
// 所要時間 分
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> graph;
vector<int> cost, ans;

void dfs(int v, int c = 0, int pre = -1){
    c += cost[v];
    ans[v] += c;
    for(auto u : graph[v]){
        if(u == pre){
            continue;
        }
        dfs(u, c, v);
    }
}

int main() {

    int n, q;
    cin >> n >> q;
    graph.resize(n);
    cost.resize(n);
    ans.resize(n);
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    rep(i, q){
        int p, x;
        cin >> p >> x;
        cost[--p] += x;
    }
    dfs(0);

    rep(i, n){
        cout << ans[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 24320
N = int(input())

x = 1
i = 2
while N > 9:
  if N % i == 0:
    x = x * i
    N = N // i
  else:
    i += 1
  if i > 9:
    print("No")
    quit()
  if x > 9:
    print("No")
    quit()
  if N < 10:
    print("Yes")
    quit()

print("Yes")

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2



int main() {
	int N, Q;
	cin >> N >> Q;
	vector<vector<ll>>eve;
	rep(i, 0, N) {
		ll S, T, X;
		cin >> S >> T >> X;
		eve.pb({S-X,1,X});
		eve.pb({T-X,-1,X});
	}
	sort(all(eve));

	set<int>st;
	int cur = 0;
	rep(i, 0, Q) {
		int D;
		cin >> D;
		while (cur < eve.size() && eve[cur][0] <= D) {
			if (eve[cur][1] == 1) {
				st.insert(eve[cur][2]);
			}
			else {
				st.erase(eve[cur][2]);
			}
			cur++;
		}

		if (st.size() == 0) {
			cout << -1 << endl;
		}
		else {
			cout << *st.begin() << endl;
		}
	}



	return 0;
}


Measured memory_bytes: 33064
#include <cstdio>
#include <cmath>
#include <random>
#define REP(i,n) for (int i=0;i<(n);i++)
int F(double,double);
int main(){
	long long N;
	scanf("%lld",&N);
	int num=1145141919;
	for(int i=1;i<=100000;i++){
		if(N%i==0 && num>F(N/i,i)){
			num=F(N/i,i);
		}
	}
	printf("%d",num);
	return 0;
}


int F(double a,double b){
	a = log10(a)+1;
	b = log10(b)+1;
	if(a>b){
		return a;
	}else{
		return b;
	}
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, a[505][505];

void calc(const int &l, const int &r, const int &col){
	if(l == r) return; const int mid = l + r >> 1;
	for(register int i = l; i <= mid; i++)
		for(register int j = mid + 1; j <= r; j++) a[i][j] = col;
	calc(l, mid, col + 1), calc(mid + 1, r, col + 1);
}

int main(){
	getint(N), calc(1, N, 1);
	for(register int i = 1; i <= N; i++, puts(""))
		for(register int j = i + 1; j <= N; j++) printf("%d ", a[i][j]);
	return 0;
}

Measured memory_bytes: 1536
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
data=Counter(a)
two_i=[]
four_i=[]
for i,j in data.items():
    if 4<=j:
        four_i.append(i)
    elif 2<=j:
        two_i.append(i)
two_i.sort()
four_i.sort()
two_i.reverse()
four_i.reverse()
if len(four_i)==0:
    four_i.append(0)
if len(two_i)<=1:
    two_i.append(0)
    two_i.append(0)
four_area=four_i[0]*four_i[0]
two_area=two_i[0]*two_i[1]
mix_area=two_i[0]*four_i[0]
print(max(four_area,two_area,mix_area))


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

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

  if(a >= 0 && c >= 0){
    cout << b * d << endl;
  }

  else if(a >= 0 && c <= 0 && d >= 0){
    cout << b * d << endl;
  }

  else if(a >= 0 && d <= 0){
    cout << a * d << endl;
  }

  else if(a <= 0 && b >= 0 && c >= 0){
    cout << b * d << endl;
  }

  else if(a <= 0 && b >= 0 && c <=0 && d >= 0){
    cout << max(b * d, a * c) << endl;
  }

  else if(a <= 0 && b >= 0 && d <= 0){
      cout << a * c << endl;
  }

  else if(b <= 0 && c >= 0){
    cout << b * c << endl;
  }

  else if( b <= 0 && c <= 0 && d >=0){
    cout << a * c << endl;
  }

  else if(b <= 0 && d <= 0){
    cout << a * c << endl;
  }

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


int main(){
  
  int n;
  long long k;
  cin>>n>>k;
  long long a[n],b[n];
  REP(i,n){
    cin>>a[i]>>b[i];
  }
  
  long long ans = 0;
  long long type_;
  long long temp;
  REP(i,30){
    temp = 0;
    if((k>>i) & 1){
      type_ = ((k>>i)<<i) - 1;
      REP(j,n){
        if((a[j] | type_) == type_){
          temp += b[j];
        }
      }
      ans = max(ans, temp);
    }
  }
  
  type_ = k;
  temp = 0;
  REP(i,n){
    if((a[i] | type_) == type_){
      temp += b[i];
    }
  }
  ans = max(ans, temp);
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);
ll gcd(ll x, ll y){
  if(x%y==0)return y;
  else return gcd(y,x%y);
}
int main(){
  int n;
  cin >> n;
  vector<ll>a(n);
  rep(i,n) cin >> a[i];
  vector<ll>lg(n);
  vector<ll>rg(n);
  lg[0]=a[0];
  rg[0]=a[n-1];
  rep(i,n-1){
    lg[i+1]=gcd(lg[i],a[i+1]);
    rg[i+1]=gcd(rg[i],a[n-1-(i+1)]);
  }
  ll ans=0;
  rep(i,n){
    if(i==0)ans=max(ans,rg[n-2]);
    else if(i==n-1)ans=max(ans,lg[n-2]);
    else ans=max(ans,gcd(lg[i-1],rg[n-i-2]));
  }
  cout << ans << endl;
            
}


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

int main(){
  int h,w;
  while(true){
    cin >> h >> w;
    if(h == 0 && w == 0)break;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>

int main(void){
  
  int s1,s2,s3;
  scanf("%d %d %d",&s1,&s2,&s3);
  
  if (s1==s2){
    if(s2==s3){
      printf("No");
    }
    else{
      printf("Yes");
    }
  }
  
  else if(s1==s3){
   	if(s2==s3){
    	printf("No");
    }
    else{
      printf("Yes");
    }
  }
  
    else if(s2==s3){
   	if(s1==s2){
    	printf("No");
    }
    else{
      printf("Yes");
    }
  }
  
  else{
	printf("No");
    
  }
  
  return 0;
  
}

Measured memory_bytes: 128
object Main extends App {
  import scala.io.StdIn._
  val sentence = readLine().toList
  val target = readLine().toList
  matchPosition(sentence, target).reverse.foreach{
    println(_)
  }
  def matchPosition(sentence:List[Char], target:List[Char], index:Int = 0, res:List[Int] = Nil):List[Int] = {
    def matchPrefix(sentence:List[Char], target:List[Char]):Boolean = {
      (sentence, target) match{
        case (_, Nil) => true
        case (hs::ts, ht::tt) if hs == ht => matchPrefix(ts, tt)
        case _ => false
      }
    }
    sentence match{
      case Nil => res
      case _::t if matchPrefix(sentence, target) => matchPosition(t, target, index + 1, index :: res)
      case _::t => matchPosition(t, target, index + 1, res)
    }
  }
}



Measured memory_bytes: 44076
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  cout << N / (A + B) * A + min(A, N % (A + B)) << endl;
  return 0;
}


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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18;

int n, f[N], ans;

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);  

    cin >> n;
    FOR(i,1,n){
        int u;
        cin >> u;
        ans += u;
        f[u]++;
    }
    int q;
    cin >> q;
    while(q--){
        int b, c;
        cin >> b >> c;
        ans -= f[b] * b;
        f[c] += f[b];
        ans += f[b] * c;
        f[b] = 0;
        cout << ans << '\n';
    }
}


Measured memory_bytes: 4448
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 202020;
int n;
int a[N], b[N], c[N], d[N];

int main(){
	scanf("%d", &n);
	rep(i, 0, n) scanf("%d", a + i);
	rep(i, 0, n) scanf("%d", b + i);
	ll ans = 0;
	rep(bit, 0, 31) {
		ll up[4] = {1ll << bit};
		rep(i, 1, 4) up[i] = up[i - 1] + up[0];
		ll t = up[1] - 1; 
		rep(i, 0, n) c[i] = a[i] & t;
		rep(i, 0, n) d[i] = b[i] & t;
		sort(c, c + n);
		sort(d, d + n);
		ll cnt = 0;
		for(int j = 0; j < 3; j += 2) {
			rep(i, 0, n) {
				int l = 0, r = 0;
				l = lower_bound(d, d + n, up[j] - c[i]) - d;
				r = lower_bound(d, d + n, up[j + 1] - c[i]) - d;
				cnt += r - l;
			}
		}
	//	de(cnt);
		ans |= (1 << bit) * (cnt % 2);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int N = 3;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      char a;
      cin>>a;
      if(i==j)cout<<a;
    }
    
  }
  cout<<endl;
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

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

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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll a,b,c;
  cin >> a >> b >> c;
  if(b-a == c-b)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
from itertools import accumulate
n,m,k = map(int,input().split())
deskA = list(map(int,input().split()))
deskB = list(map(int,input().split()))
cumA = [0] + list(accumulate(deskA))
cumB = [0] + list(accumulate(deskB))
ans = 0
j = m
for i in range(n+1):
    if cumA[i] > k:
        continue
    while cumA[i] + cumB[j] > k:
        j -= 1
    ans = max(i+j,ans)
print(ans)

Measured memory_bytes: 135600
A = list(input())
B = list(input())
C = list(input())
s = A.pop(0)
while True:
    if A == [] and s == 'a':
        print('A')
        exit()
    elif B == [] and s == 'b':
        print('B')
        exit()
    elif C == [] and s == 'c':
        print('C')
        exit()
    if s == 'a':
        s = A.pop(0)
    elif s == 'b':
        s = B.pop(0)
    elif s == 'c':
        s = C.pop(0)

Measured memory_bytes: 61864
import fractions

a, b, c, d = map(int, input().split())

b_c = b//c - (a-1)//c
d_c = b//d - (a-1)//d
cd = (c * d) // fractions.gcd(c, d)
cd_c = b//cd - (a-1)//cd

print((b - a + 1) - (b_c + d_c - cd_c))


Measured memory_bytes: 5048
using System;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().OrderBy(x => x).ToArray();
            for (int i = 0; i < input.Length; i+=2)
            {
                if (input.Length ==1 || input.Length % 2 == 1  || input[i] != input[i + 1])
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 13268
MOD=10**9+7
N,K=map(int,input().split())

def powmod(a,p):
  if p==0:
    return 1
  elif p==1:
    return a
  else:
    pow2=powmod(a,p//2)
    if p%2==0:
      return (pow2**2)%MOD
    else:
      return (a*pow2**2)%MOD
def invmod(a):
  return powmod(a,MOD-2)

term1=N-K+1
term2=1
for i in range(1,K+1):  
  #print(term1,term2)  
  print((term1*term2)%MOD)

  term1=term1*(N-K+1-i)*invmod(i+1)%MOD
  term2=term2*(K-i)*invmod(i)%MOD

Measured memory_bytes: 3316
#include<stdlib.h>
#include<stdio.h>

int search(int a[], int n, int key)
{
    int i = 0;
    a[n] = key;
    while (a[i] != key)
    {
        i++;
    }
    return i != n;
}

int main()
{
    int a[10000 + 2], n, q, key, sum = 0;

    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    
    scanf("%d", &q);

    for (int i = 0; i < q; i++)
    {
        scanf("%d", &key);
        if(search(a, n, key))
        {
            sum++;
        }
    }

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


Measured memory_bytes: 2076
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int H, W, N;
    cin >> H >> W >> N;
    vector<int> v;
    REP(i, N) {
        int a;
        cin >> a;
        REP(j, a) { v.emplace_back(i + 1); }
    }

    vector<vector<int>> ans(H, vector<int>(W));
    int now  = 0;
    auto ume = [&](int x, int y) { ans[x][y] = v[now++]; };
    REP(i, H) {
        if (i % 2 == 0) {
            REP(j, W) { ume(i, j); }
        } else {
            RREP(j, W) { ume(i, j); }
        }
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define M 14

int main() {
	int A[M][M] = {};

	for (int x, y, size; scanf("%d,%d,%d", &x, &y, &size) != EOF;) {
		x += 2; y += 2;
		A[x][y]++;
		A[x + 1][y]++;
		A[x][y + 1]++;
		A[x - 1][y]++;
		A[x][y - 1]++;
		if (size == 1)continue;
		A[x + 1][y + 1]++;
		A[x + 1][y - 1]++;
		A[x - 1][y + 1]++;
		A[x - 1][y - 1]++;
		if (size == 2)continue;
		A[x + 2][y]++;
		A[x][y + 2]++;
		A[x - 2][y]++;
		A[x][y - 2]++;
	}

	int cnt = 100, MAX = 0;

	for (int x = 0; x < 10; x++) {
		for (int y = 0; y < 10; y++) {
			if (A[x + 2][y + 2]) {
				cnt--;
				MAX = max(MAX, A[x + 2][y + 2]);
			}
		}
	}
	cout << cnt << endl;
	cout << MAX << endl;
	return 0;
}

Measured memory_bytes: 1212
"use strict"

const main = (input) => {
    const N = parseInt(input, 10);
    let count = 0;

    for(let i = 1; i <= N; i++){
        let digitNumber = String(i).length;
        if(digitNumber % 2 !== 0){
            count += 1;
        }
    }

    console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const ll MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

ll modnPr(ll n, ll r) {
	int res = 1;
	for(ll i = 0; i < r; ++i) {
		res =  res * (n - i) % MOD;
	}
	return res;
}

int main() {
	ll N, M;
	scanf("%lld %lld", &N ,&M);
	if(abs(N - M) > 1) printf("%d\n", 0);
	else {
		if(N == M) {
			ll dog = modnPr(N, N) % MOD;
			ll monkey = modnPr(M, M) % MOD;
			ll ans = dog * monkey * 2 % MOD;
			printf("%lld\n", ans);
		}
		else {
			ll dog = modnPr(N, N) % MOD;
			ll monkey = modnPr(M, M) % MOD;
			ll ans = dog * monkey % MOD;
			printf("%lld\n", ans);
		}
	} 
	return 0;
}

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

using namespace std;

using ll = long long;

int n;

bool check(const vector<string> &ban, int k) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      if (ban[i][(j + k) % n] != ban[j][(i + k) % n])
        return 0;
    }
  }
  return 1;
}

int main() {
  cin >> n;
  vector<string> ban(n);
  for (int i = 0; i < n; ++i) {
    cin >> ban[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    if (check(ban, i)) {
      ans += n;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int n=in(),m=in();
	print((n-1)*(m-1));
	return 0;
}

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

 using namespace std;
 
 int main(){
     
   int x, y;
   string picture;

   cin>>x>>y;
  
   cout<<'#';
   
   for(int i=0;i<y;i++){
     cout<<'#';
   }
   cout<<'#'<<endl;
  
  
   for(int i=0;i<x;i++){
       cin>>picture;
       cout<<'#'<<picture<<'#'<<endl;
   }
 
   cout<<'#';
   for(int i=0;i<y;i++){
     cout<<'#';
   }
   cout<<'#'<<endl; 
   
   
   return 0;
    
 }

Measured memory_bytes: 3460
{-# LANGUAGE TypeApplications #-}

import Data.Maybe
import Data.List
import Control.Monad
import Data.Bifunctor
import Control.Applicative
import Data.Monoid
import Data.Coerce

main :: IO ()
main = do
    [n, m, x] <- fmap (read @Int) . words <$> getLine
    list <- replicateM n $ fromJust . uncons . fmap (read @Int) . words <$> getLine
    print $ solve x list

solve :: Int -> [(Int, [Int])] -> Int
solve x = fromMaybe (-1)
        . foldl1May min
        . map fst
        . filter (all (>= x) . snd)
        . id @[(Int, [Int])]
        . coerce
        . fmap mconcat
        . traverse (: [mempty])
        . id @[(Sum Int, Ap ZipList (Sum Int))]
        . coerce

foldl1May :: (a -> a -> a) -> [a] -> Maybe a
foldl1May f (x:xs) = Just $ foldl f x xs
foldl1May _ _ = Nothing


Measured memory_bytes: 5208
#include <iostream>
using namespace std;
int main()
{
  	string s,m;
  	getline(cin,s);
  	getline(cin,m);
  	int c=0;
  	for(int i=0;i<s.length();i++){
    	if(s[i]!=m[i])
          c++;
    }
  	cout << c;
	return 0;
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N,T;
    cin >>N>>T;
    int C[N];
    int Q[N];
    vector<int> memo(123456,12345678);
    int a = 0,b = 12345678;
    vector< tuple<int,int,int>>  A(N);
    for(int i = 0;i < N;i++){
        cin >> C[i] >> Q[i];
        if(Q[i] <= T){
            memo[i] = C[i];
            a++;
        }
        b = min(b,Q[i]);
    }
    int ans = 12345678;
    for(int i = 0;i < N;i++){
        ans = min(ans,memo[i]);
    }
    if(b > T) cout << "TLE" << endl;
    else cout << ans << endl;
 
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int n;
    while(sf("%d",&n)==1)
    {
        int t[n+5];
        int sum=0;
        for(int i=1;i<=n;i++)sf("%d",&t[i]),sum+=t[i];

        int m;
        sf("%d",&m);
        for(int i=1;i<=m;i++)
        {
            int p,x;
            sf("%d %d",&p,&x);
            int ans=sum-t[p];
            ans+=x;
            pf("%d\n",ans);
        }
    }
    return 0;
}
 









 




























Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())

ans1 = a*x + b*y

if x >= y:
    ans2 = 2*c*y + a*(x-y)
    ans3 = 2*x*c
else:
    ans2 = 2*c*x + b*(y-x)
    ans3 = 2*y*c

print(min(min(ans1, ans2), ans3))

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	string s;
	cin >> s;
	bool easy = true;

	rep(i, s.size()) {
		if (i % 2 == 0 && s[i] == 'L')easy = false;
		if (i % 2 == 1 && s[i] == 'R')easy = false;
	}

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

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	char str[101];
	int flag=0;
	scanf("%s",str);
	for(int i=0;str[i]!='\0';i++){
		if(str[i]=='C') flag=1;
		else if(flag&&str[i]=='F'){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


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

// #include "../../template-proj/myMente.h"

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

int main(){
	// int N; cin>>N;
	// int a,b,c; cin>>a>>b>>c;
	string s; cin>>s;
	string t; cin>>t;
	int hit = 0;
	if(s[0]==t[0])++hit;
	if(s[1]==t[1])++hit;
	if(s[2]==t[2])++hit;
	ote(hit);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>

using namespace std;

int main(){
  string s;
  cin >> s;
  int year, month, day;
  string temp;

  temp = s.substr(0,4);
  year = stoi(temp);
  temp = s.substr(5, 2);
  month = stoi(temp);
  if(year == 2019){
    if(month > 4){
      cout << "TBD" << endl;
    }else {
      cout << "Heisei" << endl;
    }
  } else if(year > 1029){
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			a.begin(), a.end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define	MAX_QWORD		((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int H, W, D;
	cin >> H >> W >> D;
	map<int, int> mp;
	REP(i, H) {
		REP(j, W) {
			int a;
			cin >> a;
			mp[a] = i * 1000 + j;
		}
	}

	vector<vector<int>> sum(D, vector<int>(H * W / D + 1));
	REP(i, D) {
		int cnt = 0;
		int prev = mp[i];
		sum[i][0] = 0;
		for (int mas = i + D; mas <= H * W; mas += D) {
			int now = mp[mas];
			int one = 0;
			one += abs(now % 1000 - prev % 1000);
			one += abs(now / 1000 - prev / 1000);
			sum[i][cnt + 1] = sum[i][cnt] + one;
			cnt++;
			prev = now;
		}
	}

	int Q;
	cin >> Q;
	REP(i, Q) {
		int L, R;
		cin >> L >> R;
		int ans = sum[R % D][R / D] - sum[L % D][L / D];
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 9600
use io::*;
use std::collections::HashMap;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let v = sc.next_vec::<i64>(n);
    let mut map: HashMap<i64,usize> = HashMap::new();
    for x in v {
        {
            let mut c = map.entry(x).or_insert(0);
            *c += 1;
        }
        {
            let mut c = map.entry(x-1).or_insert(0);
            *c += 1;
        }
        {
            let mut c = map.entry(x+1).or_insert(0);
            *c += 1;
        }
    }
    let ans = map.values().max().unwrap();
    println!("{}",ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 14588
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;

  if(u == s)
    a--;
  else
    b--;

  cout << a << ' ' << b << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;

template <typename T>
int Count(const vector<T> &v, T l,T r){
  //counting [l,r]
  auto L = lower_bound(v.begin(), v.end(), l );
  auto R = upper_bound(v.begin(), v.end(), r );
  // [l,r) change upper -> lower
  return R-L;
}

signed main(){
  int n,a=0;
  cin>>n;
  int m=n;
  while(m)a+=m%10,m/=10;
  cout<<(n%a?"No":"Yes")<<endl;
  return 0;
}


Measured memory_bytes: 256
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
if sum(a) == x:
    print(N)
    exit()
if sum(a) <= x:
    print(N-1)
    exit()
ans = 0
for i in range(N):
    ans += a[i]
    if ans == x:
        print(i+1)
        exit()
    if ans > x:
        print(i)
        exit()

Measured memory_bytes: 3064
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<ll, ll>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 15;
int n, m, a, b, req[5];

pls give {
    AC;
    cin >> n >> m;
    if (n == 1) {
        if (m == 1) {
            cin >> a >> b;
            cout << b;
            return 0;
        } else if (m) {
            cout << -1;
            return 0;
        } else {
            cout << 0;
            return 0;
        }
    }
    memset(req, -1, sizeof req);
    for (int i=0; i<m; i++) {
        cin >> a >> b;
        if (req[a] != -1 and req[a] != b) {
            cout << -1 << nl;
            return 0;
        }
        if (a == 1 and b == 0) {
            cout << -1 << nl;
            return 0;
        }
        req[a] = b;
    }
    for (int i=1; i<=n; i++) {
        if (i == 1 and req[i] == -1) cout << 1;
        else if (req[i] == -1) cout << 0;
        else cout << req[i];
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R register
#define LL long long
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
const int mod = 998244353;
const int maxn = 3e5+10;
LL n,a,b,k,ans;
LL flac[maxn],inv[maxn],invf[maxn],C[maxn],s[maxn];
inline LL calc(R LL x,R LL y){
	return C[x]*C[y]%mod;
}
int main(){
	read(n);read(a);read(b);read(k);
	for(R int i=(*flac=flac[1]=inv[1]=invf[1]=*inv=*invf=1)*2;i<=n;++i){
		flac[i]=flac[i-1]*i%mod;
		inv[i]=-(mod/i)*inv[mod%i]%mod;
		inv[i]=(inv[i]%mod+mod)%mod;
		invf[i]=invf[i-1]*inv[i]%mod;
	}
	for(R int i=1;i<=n;++i){
		C[i]=flac[n]*invf[n-i]%mod;
		C[i]=C[i]*invf[i]%mod;
	}
	C[0]=C[n]=1;
	for(R LL x=0,y;x<=n;++x){
		if((k-x*a)%b)continue;
		y=(k-x*a)/b;
		if(Max(x,y)>n)continue;
		if(x<0||y<0)continue;
		ans=(ans+calc(x,y))%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <map>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  string S[n];
  rep(i, n)
    cin >> S[i];
  //ここまで入力

  
  //アイデアは，n個の数字の最大公約数を取るイメージ
  
  
  //各文字列S[i]に対して，各アルファベットの登場回数を数える
  map<char, int> m[n];
  rep(i, n)
    rep(j, S[i].size() )
    m[i][S[i][j] ]++;

  //各アルファベットの登場回数の最小値を格納する
  //108で初期化（100以上ならなんでもいい）
  int count_min[26];
  rep(i, 26)
    count_min[i] = 108;

   //全ての文字列を見たときに，各アルファベットの登場回数の最小値を求める
  rep(i, 26)
    rep(j, n)
      if(m[j][i+'a' ] < count_min[i] )
	count_min[i] = m[j][i+'a' ];

  //解答
  rep(i, 26)
    rep(j, count_min[i])
    cout << (char)(i+'a') ;
  cout << endl;

  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

map<int, int> IR, ID;
set<int> ER, ED;
void insert_interval_down(pii interval) {
	ID[interval.second] = interval.first;
	ED.insert(interval.second);
}

void erase_interval_down(pii interval) {
	ID.erase(interval.first);
	ED.erase(interval.first);
}

pii get_interval_down(int x) {
	int e = *ED.lower_bound(x);
	return {ID[e], e};
}

void insert_interval_right(pii interval) {
	IR[interval.second] = interval.first;
	ER.insert(interval.second);
}

void erase_interval_right(pii interval) {
	IR.erase(interval.first);
	ER.erase(interval.first);
}

pii get_interval_right(int x) {
	int e = *ER.lower_bound(x);
	return {IR[e], e};
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N, Q;
	cin >> N >> Q;
	map<pii, int> VD, VR;
	VD[{1, N}] = N;
	VR[{1, N}] = N;
	insert_interval_down({1, N});
	insert_interval_right({1, N});
	ll ans = (N - 2);
	ans *= ans;
	
	//cout << "DEBUG:\n";
	//cout << "VD\n";
	//for (auto vd: VD) {
		//cout << vd.first.first << " " << vd.first.second << " " << vd.second << "\n"; 
	//} 
	//cout << "VR\n";
	//for (auto vr: VR) {
		//cout << vr.first.first << " " << vr.first.second << " " << vr.second << "\n"; 
	//} 
	//cout << endl;
	
	
	for (int query = 0; query < Q; query++) {
		int q, x;
		cin >> q >> x;
		if (q == 1) {
			pii interval = get_interval_down(x);
			int v = VD[interval];
			ans -= (v - 2);
			VD.erase(interval);
			erase_interval_down(interval);
			pii left = {interval.first, x};
			pii right = {x + 1, interval.second};
			VD[left] = v;
			VD[right] = v;
			insert_interval_down(left);
			insert_interval_down(right);
			if (left.first == 1) {
				assert(VR.find({1, v}) != VR.end());
				VR[{1, v}] = x;
			}
		} else {
			assert(q == 2);
			pii interval = get_interval_right(x);
			int v = VR[interval];
			ans -= (v - 2);
			VR.erase(interval);
			erase_interval_right(interval);
			pii left = {interval.first, x};
			pii right = {x + 1, interval.second};
			VR[left] = v;
			VR[right] = v;
			insert_interval_right(left);
			insert_interval_right(right);
			if (left.first == 1) {
				assert(VD.find({1, v}) != VD.end());
				VD[{1, v}] = x;
			}
		}
		//cout << "DEBUG:\n";
		//cout << "VD\n";
		//for (auto vd: VD) {
			//cout << vd.first.first << " " << vd.first.second << " " << vd.second << "\n"; 
		//} 
		//cout << "VR\n";
		//for (auto vr: VR) {
			//cout << vr.first.first << " " << vr.first.second << " " << vr.second << "\n"; 
		//} 
		//cout << endl;
	}
	cout << ans << endl;
}


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

const int mod = 1e9+7;
const ll INF = 2000000000;


int main() {
    int N,K;
    cin >> N >> K;
    vector<int> h(N,0);
    vector<ll> dp(N,INF);
    rep(i,N) cin >> h[i];
    dp[0]=0;
    for(int i=0;i<N;++i) {
        for(int j=1;j<=K;++j) {
            if(i+j>=N) break;
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j])); 
        }  
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int max;

int modulo(){
    char row[21000];
    char *tok;
    int sum = 0;
    int number;
    int i = 0;
    int check = 0;
    fgets(row, 21000, stdin);
    tok = strtok(row, " ");
    while(tok != NULL){
        //printf("%d\n", atoi(tok));
        number = atoi(tok) - 1;
        if(number < 1 || number > 100000){
            check = 1;
        }
        sum += number;
        tok = strtok(NULL, " ");
        i++;
    }
    max = sum;
    if(i == 1 || i == 0 || i > 3000){
        max = modulo();
    }
    if(check == 1){
        max = modulo();
    }

    return max;
}

int main(){
    max = modulo();
    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
AC;
int n,m,array[100],sum=0,i,counter=0;
double popularity[100];
scanf("%d %d",&n,&m);
for(i=0;i<n;++i){
    scanf("%d",&array[i]);
    sum+=array[i];
}
for(i=0;i<n;++i){
    popularity[i]=(double)((double)array[i]/(double)sum);
}
double result=(double)(1)/(double)(4*m);
for(i=0;i<n;++i){
    if(result<=popularity[i]){
        counter++;
    }
}
if(counter>=m){
    printf("Yes");
}
else{
    printf("No");
}





    return 0;
}


Measured memory_bytes: 256