akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
struct state { long long a, b; };
inline bool operator<(const state& s1, const state& s2) { return s1.a < s2.a; }
int N; long long D, A[33], B[33];
int cnt1, cnt2, cnt3, cnt4; state vl[14348922], vr[14348922]; // meet-in-the middle
int que[14348922]; // searching deque
int main() {
	scanf("%d%lld", &N, &D);
	for (int i = 0; i < N; i++) scanf("%lld%lld", &A[i], &B[i]);

	// Meet-in-the-middle Algorithm
	int sep1 = (N >> 1), sep2 = N - sep1;
	vector<long long> sa1(1 << sep1), sb1(1 << sep1);
	vector<long long> sa2(1 << sep2), sb2(1 << sep2);
	for (int i = 0; i < sep1; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa1[j] = sa1[j - b1] + A[i];
			sb1[j] = sb1[j - b1] + B[i];
		}
	}
	for (int i = 0; i < sep2; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa2[j] = sa2[j - b1] + A[i + sep1];
			sb2[j] = sb2[j - b1] + B[i + sep1];
		}
	}
	cnt1 = 0;
	for (int i = 0; i < 1 << sep1; i++) {
		int r = (1 << sep1) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa1[k] - sa1[j];
			long long r2 = sb1[k] - sb1[j];
			if (r1 >= 0) vl[cnt1++] = state{ r1, r2 };
			if (r1 > 0) cnt3++;
			j = (j - 1) & r;
		} while (j != r);
	}
	cnt2 = 0;
	for (int i = 0; i < 1 << sep2; i++) {
		int r = (1 << sep2) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa2[k] - sa2[j];
			long long r2 = sb2[k] - sb2[j];
			if (r1 >= 0) vr[cnt2++] = state{ r1, r2 };
			if (r1 > 0) cnt4++;
			j = (j - 1) & r;
		} while (j != r);
	}
	sort(vl, vl + cnt1); cnt1 += cnt3;
	sort(vr, vr + cnt2); cnt2 += cnt4;
	int cnt5 = cnt1 - cnt3;
	int cnt6 = cnt2 - cnt4;

	vector<state> wl(cnt1), wr(cnt2);
	for (int i = 0; i < cnt3; i++) wl[i] = state{ -vl[cnt5 - i - 1].a, -vl[cnt5 - i - 1].b };
	for (int i = 0; i < cnt4; i++) wr[i] = state{ -vr[cnt6 - i - 1].a, -vr[cnt6 - i - 1].b };
	copy(vl, vl + cnt5, wl.begin() + cnt3);
	copy(vr, vr + cnt6, wr.begin() + cnt4);

	// Searching with deque
	int cl = 0, cr = 0, dl = 0, dr = 0;
	long long ret = 0;
	for (int i = cnt2 - 1; i >= 0; i--) {
		while (cr < cnt1 && wl[cr].a + wr[i].a <= D) {
			while ((dr - dl) && wl[que[dr - 1]].b <= wl[cr].b) dr--;
			que[dr++] = cr++;
		}
		while (cl < cnt1 && wl[cl].a + wr[i].a < -D) {
			if ((dr - dl) && que[dl] == cl) dl++;
			cl++;
		}
		if (dr - dl) ret = max(ret, wr[i].b + wl[que[dl]].b);
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 681876
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

const ll INF = 100000000;
const ll MOD = 1000000007;

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //問題文中の添え字が0-indexか1-indexか確認!

    ll n;
    std::cin>>n;
    std::vector<ll> a(n);
    rep(i,0,n){
        std::cin>>a[i];
    }
    ll right=0,sum=0,ans=0;
    for(ll left=0;left<n;left++){
        while((right<n)&&(sum+a[right]==(sum^a[right]))){
            sum+=a[right];
            right++;
        }
        ans+=(right-left);

        if(right==left){
            right++;
        }else{
            sum-=a[left];
        }
    }
    std::cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
  
  static final int a = 1000000007;
  
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int M = Integer.parseInt(sc.next());
    long[] Ncount = new long[N+1];
    long[] Mcount = new long[M+1];
    Ncount[0] = Mcount[0] = 1;
    for (int i =1; i<=N; i++) {
      Ncount[i] = Ncount[i-1] * i;
      Ncount[i] %= a;
    }
    for (int i =1; i<=M; i++) {
      Mcount[i] = Mcount[i-1] * i;
      Mcount[i] %= a;
    } 
    long ans = Ncount[N] * Mcount[M];
    if (N == M) ans *= 2;
    if (Math.abs(N - M) >= 2) ans =0;
    System.out.println(ans % a);
  }
}

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

using namespace std;

const int max_n = 3000111, inf = 1000111222;

char buf[max_n];

string read() {
    scanf("%s", buf);
    return buf;
}

string s, t;

int z[max_n];

void get_z_function(const string &s, int z[]) {
    z[0] = 0;
    int l = 0, r = 0;
    for (int i = 1; i < s.length(); ++i) {
        z[i] = 0;
        if (i <= r) {
            z[i] = min(z[i - l], r - i + 1);
        }
        while (i + z[i] < s.length() && s[i + z[i]] == s[z[i]]) {
            ++z[i];
        }
        if (i + z[i] - 1 > r) {
            r = i + z[i] - 1;
            l = i;
        }
    }
}

int nxt[max_n], used[max_n], dp[max_n];

int dfs(int v) {
    if (v == -1 || nxt[v] == -1) {
        return 0;
    }
    if (used[v]) {
        return dp[v];
    }
    used[v] = 1;
    if (used[nxt[v]] == 1) {
        puts("-1");
        exit(0);
    }
    dp[v] = dfs(nxt[v]) + 1;
    used[v] = 2;
    return dp[v];
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    s = read();
    t = read();
    while (s.length() < t.length()) { // 10^6
        s += s;
    }
    int n = s.length();
    s += s; // 2 * 10^6
    string q = t + "#" + s; // 2,5 * 10^6
    get_z_function(q, z);
    for (int i = n - 1; i >= 0; --i) {
        if (z[t.length() + 1 + i] == t.length()) {
            nxt[i] = (i + t.length()) % n;
        } else {
            nxt[i] = -1;
        }
        //cout << i << " " << nxt[i] << endl;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = max(ans, dfs(i));
    }
    printf("%d\n", ans);
    return 0;
}


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int num = 0;
  ll ans = 0;
  rep(i,s.size()){
    int res = i;
    if(s[i] == 'W'){
      ans += res - num;
      num++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define len 4
#define inf 1e9
using namespace std;

struct data {
  int h, w;
};

long long n;
vector<long long> dp;
vector<data> v;
vector<string> c;
vector<vector<int>> num;

int calc(char x) {
  if(x == 'R') return 0;
  if(x == 'G') return 1;
  return 2;
}
long long solve(long long bit);

int main() {
  cin >> n;
  v.resize(n);
  for(int i = 0; i < n; ++i) cin >> v[i].h >> v[i].w;
  c.resize(len);
  for(int i = 0; i < len; ++i) cin >> c[i];
  num.assign(len, vector<int>(len, 0));
  for(int i = 0; i < len; ++i)
    for(int j = 0; j < len; ++j) num[i][j] = calc(c[i][j]);
  dp.assign(1 << (len * len), -1);
  dp[(1 << (len * len)) - 1] = 0;
  cout << solve(0) << endl;
  return 0;
}

long long solve(long long bit) {
  if(dp[bit] != -1) return dp[bit];
  long long res = inf;
  for(int i = 0; i < n; ++i)
    for(int col = 0; col < 3; ++col)
      for(int x = -3; x < len; ++x)
        for(int y = -3; y < len; ++y) {
          long long nextbit = bit;
          bool ch = 1;
          if(x + v[i].h <= 0 || y + v[i].w <= 0) continue;
          for(int j = 0; j < v[i].h; ++j)
            if(ch && x + j < len)
              for(int k = 0; k < v[i].w; ++k) {
                if(y + k >= len) break;
                if(x + j < 0 || y + k < 0) continue;
                int id = (x + j) * len + y + k;
                if(!(nextbit >> id & 1) &&
                   col == num[x + j][y + k])
                  nextbit += 1LL << id;
                if(!(nextbit >> id & 1) &&
                   col != num[x + j][y + k]) {
                  ch = 0;
                  break;
                }
              }
          if(nextbit == bit || !ch) continue;
          res = min(res, solve(nextbit));
        }

  return dp[bit] = res + 1;
}


Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	b=b/a;
	if(b>=c)
		printf("%d",c);
	else
		printf("%d",b);
    return 0;
}

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

int main(){
	int i,j,k,N,Y;
	int mannum,gosennum,sennum;
	int endflag = 0;
	
	scanf("%d",&N);
	scanf("%d",&Y);
	
	mannum = Y / 10000;
	gosennum = (Y - mannum*10000) / 5000;
	sennum = (Y - mannum*10000 - gosennum*5000) / 1000;
	
	
	for(i = mannum;i >= 0;i --){
		
		gosennum = (Y - i*10000) / 5000;
		
		for(j = gosennum; j >= 0;j--){
			k = (Y - i*10000 - j*5000) / 1000;
			if( ( (i*10000 + j*5000 + k*1000) == Y ) && ( (i+j+k) == N ) ){
				endflag =1;
				break;
			}
			if( (i+j+k) > N )break;
		}
		
		if(endflag == 1)break;
		
	}
	
	if( ( (i*10000 + j*5000 + k*1000) == Y ) && ( (i+j+k) == N ) ){
		printf("%d %d %d\n",i,j,k);
	}else printf("-1 -1 -1\n");
	
	return 0;
}

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

int main(){
    int n,h,m,s;
    cin >> n;

    h = n/3600;
    m = (n-h*3600)/60;
    s = (n-h*3600-m*60);

    cout << h <<":"<< m << ":" << s <<endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h> 
using namespace std; 
long long int n,m;
int solve(int source,vector<int> v[],vector<int> &dp)
{
    
    int count=0;
    if(dp[source]!=-1)
    return dp[source];
    for(int i=0;i<(int)v[source].size();i++)
    {
       count=max(count,1+solve(v[source][i],v,dp));
    }
    return dp[source]=count;
}
int main()
{
    cin>>n>>m;
    int x,y;
    vector<int> v[n+1];
    for(long long int i=0;i<m;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
    }
    int source=1;
   // vector<vector<long long int> > dp( n , vector<long long int> (w+1, -1));
   vector<int> dp(n+1,-1);
   int maxx=0;
   for(int i=1;i<=n;i++)
   {
      if(dp[i]==-1)
      {
        int m=solve(i,v,dp);
        //cout<<m<<endl;
        if(m>=maxx)
        maxx=m;
      }
   }
     cout<<maxx<<endl;
    //cout<<maxx<<endl;
}




Measured memory_bytes: 11696
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int ctoi(char c) {
  if(c>='0' && c<='9'){
    return c-'0';
  }
  return 0;
}
int main(){
  string s,memo;
  int a,b,c,d;
  
  cin>>s;
  a=ctoi(s[0]);
  b=ctoi(s[1]);
  c=ctoi(s[2]);
  d=ctoi(s[3]);
  
  if(a+b+c+d==7){cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";return 0;}
  if(a+b+c-d==7){cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";return 0;}
  if(a+b-c+d==7){cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";return 0;}
  if(a+b-c-d==7){cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";return 0;}
  if(a-b+c+d==7){cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";return 0;}
  if(a-b+c-d==7){cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";return 0;}
  if(a-b-c+d==7){cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";return 0;}
  if(a-b-c-d==7){cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";return 0;}

  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
 string s;
 int flag,flag1;
 cin >> s;
 for (int i = 0; i < s.length(); i++)
 {
  if (s[i] == 'A')
  {
   flag = i;
   break;
  }
 }
 for (int j = flag; j < s.length(); j++)
 {
  if (s[j] == 'Z')
  {
   flag1 = j;
  }
 }
 cout << flag1 - flag+1;
 return 0;

}

Measured memory_bytes: 640
#include <stdio.h>
int main(void)
{
  int i, j, seki;
  seki = 0;
  for(i = 1; i < 10; i++) {
    for(j = 1; j < 10; j++) {
      seki = i*j;
      printf("%dx%d=%d\n", i, j, seki);
    }
  }
  return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

int main(void) {
	long long n, m, ans;

	cin >> n >> m;

	ans = 0;

	ans += (1900 * m + 100 * (n - m))*pow(2, m);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

struct edge {int to; ll a, b;};

void solve() {
	int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s; --t;
    vector<edge> g[100100];
    rep(i, m) {
        int u, v; ll a, b; cin >> u >> v >> a >> b;
        --u; --v;
        g[u].pb(edge{v, a, b});
        g[v].pb(edge{u, a, b});
    }
    ll ds[100100], dt[100100];
    rep(i, 100100) {
        ds[i] = dt[i] = INF;
    }
    ds[s] = dt[t] = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pque;
    pque.push(make_pair(0, s));
    while(pque.size()) {
        auto p = pque.top(); pque.pop();
        int from = p.sc;
        if(ds[from] < p.fr) continue;
        for(auto&e : g[from]) {
            int to = e.to;
            ll a = e.a;
            if(ds[to] > ds[from] + a) {
                ds[to] = ds[from] + a;
                pque.push(make_pair(ds[to], to));
            }
        }
    }

    pque.push(make_pair(0, t));
    while(pque.size()) {
        auto p = pque.top(); pque.pop();
        int from = p.sc;
        if(dt[from] < p.fr) continue;
        for(auto&e : g[from]) {
            int to = e.to;
            ll b = e.b;
            if(dt[to] > dt[from] + b) {
                dt[to] = dt[from] + b;
                pque.push(make_pair(dt[to], to));
            }
        }
    }

    vector<ll> res(n, 1e+15);
    rep(i, n) {
        res[i] -= (ds[i] + dt[i]);
    }
    vector<ll> ans(n);
    ans[n - 1] = res[n - 1];
    per(i, n - 1) {
        ans[i] = max(ans[i + 1], res[i]);
    }
    rep(i, n) {
        cout << ans[i] << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 14456
N, K = map(int, input().split())
A = list(map(int, input().split()))
graph = [set() for i in range(N)]
for i, a in enumerate(A):
    graph[i].add(a - 1)

stack = [0]
seen = {0}
path = []
dist = [-1] * N
while stack:
    cur = stack.pop()
    if dist[cur] != -1:
        break
    dist[cur] = len(path)
    path.append(cur)
    for nei in graph[cur]:
        if nei not in seen:
            stack.append(nei)
            seen.add(nei)

not_loop = dist[graph[cur].pop()]
loop = len(path) - not_loop
if K < not_loop:
    print(path[K] + 1)
else:
    K -= not_loop
    K %= loop
    print(path[not_loop + K] + 1)

Measured memory_bytes: 90788
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>

using namespace std;

int main()
{
    int wa[100005];
    int n, q;

    string s;
    cin >> n >> q;

    cin >> s;
    wa[0] = 0;
    for (int i = 0; i < s.size()-1; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            wa[i + 1] = wa[i] + 1;
        }
        else {
            wa[i + 1] = wa[i];
        }
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;

        cout << wa[r - 1] - wa[l - 1] << endl;
    }

    return 0;
}



Measured memory_bytes: 4108
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool isprime(ll n) {
    if (n < 2) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*------------------------------------------------------------------------*/

constexpr ll MOD = 1e9 + 7;

void solve();

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

    solve();
}
void solve() {
    ll n;
    std::cin >> n;

    auto sieve = [](ll n) -> vll {
        vll v(n + 1, 1);
        for (ll i = 2; i * i <= n; i++) if (v[i] == 1)
            for (ll j = i * i; j <= n; j += i)
                v[j] = 0;

        vll res;
        for (ll i = 2; i <= n; i++)
            if (v[i] == 1) res.push_back(i);

        return res;
    };

    auto legendre = [&](ll n, ll p) -> ll {
        ll res = 0;
        for (ll i = p; i <= n; i *= p)
            res += n / i;

        return res;
    };

    ll ans = 1;
    for (ll p : sieve(n))
        (ans *= legendre(n, p) + 1) %= MOD;

    std::cout << ans << '\n';
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0) return 1;
	else if(N % 2 == 0) return power(MOD(a * a), N / 2);
	else return MOD(a * power(a, N - 1));
}

int inverse(int a){
	return power(a, p - 2);
}

int fact(int N){
	static vector<int> _fact(1, 1);
	for(int i = _fact.size(); i <= N; i++){
		_fact.push_back(MOD(i * _fact[i - 1]));
	}
	return _fact[N];
}
 
int fact_inv(int N){
	static vector<int> inv(2, 1), _fact_inv(2, 1);
	for(int i = inv.size(); i <= N; i++){
		inv.push_back(MOD(-(p / i) * inv[p % i]));
		_fact_inv.push_back(MOD(inv[i] * _fact_inv[i - 1]));
	}
	return _fact_inv[N];
}
 
int combination(int N, int k){
	if(k < 0 || N < k || N < 0) return 0;
	else return MOD(fact(N) * MOD(fact_inv(N - k) * fact_inv(k)));
}

signed main(){
	int N, K, i;
	scanf("%lld%lld", &N, &K);
	for(i = 1; i <= K; i++){
		if(N - K == 0 && i == 1){
			printf("1\n");
			continue;
		}
		int ans = MOD(combination(K - 1, i - 1) * MOD(combination(N - K - 1, i - 2) + 2 * combination(N - K - 1, i - 1) + combination(N - K - 1, i)));
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(v)	((v).begin()), ((v).end())
#define pb	push_back
#define mp	make_pair
#define mod 1000000007
#define debug(x)  cout<<#x<<" = "<<x<<" \n"
typedef long long ll;
void xin(){
	#ifndef ONLINE_JUDGE 
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

// int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
// inline bool valid(int x, int y, int v) {
//     return x >= 0 && x < n && y >= 0 && y < m && !visited[x][y] && grid[x][y] == v;
// }
int main()
{
  	xin();
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);

    ll d,t,s;
    cin>>d>>t>>s;
    if(t*s >= d)
    {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
   
}
    

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

int main () {

    int N, T;
    cin >> N >> T;

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

    int ans = 1000000;
    for (int i = 0; i < N; i++) {
        if (t[i] <= T) {
            ans = min(ans, c[i]);
        }
    }
    if (ans == 1000000) cout << "TLE" << endl;
    else cout << ans << endl;

    return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

ll N, A;
ll ret;
map<pair<ll,ll>, ll> dp;

ll calc(ll x, ll la)
{
	if (x >= N) return 1;
	if (dp.count(mp(x,la))) return dp[mp(x,la)];
	ll u = (N+x-1) / x;

	if (la == -1) {
		for (ll i = 2; i <= 1000010; ++i) {
			u = min(u, calc(i, i) + A + i);
		}
	} else {
		u = min(u, calc(x*la, la) + A + la);
		if (la > 2) u = min(u, calc(x*(la-1), la-1) + A + la-1);
	}

	return dp[mp(x,la)] = u;
}

int main() {
	cin >> N >> A;
	ret = N;
/*
	for (ll i = 2; i <= 1000010; ++i) {
		ll u = 1;
		ll m = LLONG_MAX;
		ll c = 0;

		while (true) {
			u *= i;
			c += A + i;

			m = min(m, c + (N+u-1)/u);

			if (u >= N) break;
		}

		ret = min(ret, m);
	}
*/
	cout << min(ret, calc(1,-1)) << endl;

	return 0;
}

Measured memory_bytes: 194432
n, W = map(int, input().split())
w, v = [0]*n, [0]*n
for i in range(n):
    w[i], v[i] = map(int, input().split())

dp = [[0]*(W+1) for i in range(n+1)]
#i品目までの中から重さwを超えないように選んだときの価値の総和の最大値
for i in range(1, n+1):
    for j in range(W+1):
        if j - w[i-1] >= 0:
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1])
        dp[i][j] = max(dp[i][j], dp[i-1][j])
print(max(dp[n]))



Measured memory_bytes: 150256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
using namespace std;

int inf = 1e9;
int mod = 1e9 + 7;
int64_t inf64 = 1e18;

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int N, M;
    cin >> N >> M;
    vector<int64_t> a(M), b(M), c(M);
    for(int i = 0; i < M; i++) cin >> a[i] >> b[i] >> c[i];

    // 0-index and cost to minus;
    for(int i = 0; i < M; i++){
        a[i]--;
        b[i]--;
        c[i] *= -1;
    }

    vector<int64_t> dist(N, inf64);
    dist.front() = 0;

    for(int v = 0; v < N; v++){
        for(int e = 0; e < M; e++){
            if(dist[a[e]] == inf64) continue;
            dist[b[e]] = min(dist[b[e]], dist[a[e]] + c[e]);
        }
    }

    vector<bool> negative(N, false);
    for(int v = 0; v < N; v++){
        for(int e = 0; e < M; e++){
            if(dist[a[e]] == inf64) continue;
            if(dist[b[e]] > dist[a[e]] + c[e]) negative[b[e]] = true;
            if(negative[a[e]] == true) negative[b[e]] = true;
        }
    }

    if(negative[N - 1]) cout << "inf" << endl;
    else cout << -dist[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_s
degit = n.length - 1
n = n.to_i

case degit
when 1
  result = n
when 2
  result = 9
when 3
  result = n - 100 + 10
when 4
  result = 909
when 5
  result = n - 10000 + 910
when 6
  result = 90909
end

puts result

Measured memory_bytes: 1788
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

lint MOD = (lint)1e9 + 7;

int main() {
	string L;
	cin >> L;
	int N = L.size();
	
	vector< lint > pow2(N+1, 0), pow3(N+1, 0);
	pow2[0] = pow3[0] = 1;
	for_(i,0,N) {
		pow2[i+1] = (pow2[i] * 2) % MOD;
		pow3[i+1] = (pow3[i] * 3) % MOD;
	}
	
	lint ans = 0, par = 1;
	for_(i,0,N) {
		if (L[i] == '1') {
			int b = N - i - 1;
			ans += (par * pow3[b]) % MOD;
			ans %= MOD;
			par = (par * 2) % MOD; // (0,1) or (1,0)
		}
	}
	modAdd(ans, par, MOD);
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

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

namespace myapp
{
    class Program
    {
        class Class1
        {
            public int prefectureNumber { get; set; }
            public int year { get; set; }
            public int inputNumber { get; set; }
        }

        class Class2
        {
            public int prefectureNumber { get; set; }
            public int cityOrder { get; set; }
            public int inputNumber { get; set; }
        }

        static void Main(string[] args)
        {
            IReadOnlyList<int> lineString = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToList();
            int prefectureCount = lineString[0];
            int cityCount = lineString[1];

            List<Class1> conditionList = new List<Class1>();
            for (int i = 0; i < cityCount; i++)
            {
                IReadOnlyList<int> conditionLine = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToList();
                conditionList.Add(new Class1
                {
                    prefectureNumber = conditionLine[0],
                    year = conditionLine[1],
                    inputNumber = i + 1
                });
            }

            int cityOrder = 1;
            int currentPrefecture = 0;
            List<Class2> orderedConditionList2 = new List<Class2>();
            foreach (var condition in conditionList.OrderBy(condition => condition.prefectureNumber).ThenBy(condition => condition.year).ToList())
            {
                if (condition.prefectureNumber != currentPrefecture)
                {
                    cityOrder = 1;
                }
                orderedConditionList2.Add(new Class2
                {
                    prefectureNumber = condition.prefectureNumber,
                    cityOrder = cityOrder,
                    inputNumber = condition.inputNumber
                });
                currentPrefecture = condition.prefectureNumber;
                cityOrder++;
            }

            foreach (var condition in orderedConditionList2.OrderBy(condition => condition.inputNumber).ToList())
            {
                Console.WriteLine($"{condition.prefectureNumber:D6}{condition.cityOrder:D6}");
            }
        }
    }
}

Measured memory_bytes: 36912
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String[] pa = a.split("");
		String b = sc.next();
		String[] pb = b.split("");
		if(pa.length == pb.length){
			for(int i=0;i<pa.length;i++){
				if(Integer.parseInt(pa[i]) > Integer.parseInt(pb[i])){
					System.out.println("GREATER");
					return;
				}else if(Integer.parseInt(pa[i]) < Integer.parseInt(pb[i])){
					System.out.println("LESS");
					return;
				}
			}
			System.out.println("EQUAL");
		}else if(pa.length > pb.length){
			System.out.println("GREATER");
			return;
		}else if(pa.length < pb.length){
			System.out.println("LESS");
			return;
		}
	}
}

Measured memory_bytes: 21844
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;

//DEBUG 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL //compile with -DLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 

#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define all(v) v.begin(),v.end()
#define se second
#define int long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 998244353;
int t,n,m,k,x,y;
 
 
int32_t main()
{
	IOS;
	vp32 v;
	cin>>n;
	forsn(i,1,n+1){
		cin>>k;
		v.pb({k,i});
	}
	sort(all(v),greater<p32>());
	vv32 dp(n+1,v32(n+1,-1e12));
	dp[0][0]=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(i+j <= n && (i+j)>0){
				int &ans=dp[i][j];
				if(i>0){
					ans=max(ans,dp[i-1][j]+v[i+j-1].fi*(v[i+j-1].se-i));
				}
				if(j>0){
					ans=max(ans,dp[i][j-1]+v[i+j-1].fi*(n+1-j-v[i+j-1].se));
				}
			}
		}
	}
	int ans=0;
	forn(i,n+1){
		forn(j,n+1){
			if(i+j==n) ans=max(ans,dp[i][j]);
		}
	}
	cout<<ans<<ln;
}


Measured memory_bytes: 34612
#include<iostream>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N]; //距離で訪問状態(color)を管理する

void bfs(int s) {
    queue<int> q;
    q.push(s);
    for(int i = 0; i < n; i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while(!q.empty()) {
        u = q.front();
        q.pop();
        for(int v = 0; v < n; v++) {
            if(M[u][v] == 0) continue;
            if(d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for(int i = 0; i < n; i++) {
        cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}

int main() {
    int u, k, v;
    
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    
    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    bfs(0);
    
    return 0;
} 


Measured memory_bytes: 3100
#include<stdio.h>
#define NIL -1 /*????????????¶??§???????*/
#define MAX 100
#define WHITE 1
#define GRAY 2
#define BLACK 3
 
struct node{
 int list2[MAX];  
  int color;
  int number;
};
 
 
typedef struct node  Node;/*list1??????????????????????????????*/
 
void dfs(Node *);
void visit(Node *,int);
 
Node list1[MAX];          /*?????????1??§???????*/
 
int num,degree,time,d[MAX],f[MAX];
main()
{
  int i,j;
  scanf("%d",&num);
  for(i=1;i<=num;i++)
    {
      scanf("%d",&list1[i].number);
      scanf("%d",&degree);
      list1[i].list2[degree+1] = NIL;  /*???list???degree??????????????????NIL?????\??????*/
      if(degree != 0)
    {
      for(j=1;j<=degree;j++)
        {
      scanf("%d",&list1[i].list2[j]);
        }
    }/*if degree ??????¨???*/
    }/*?????????§?????????????????????*/
 
  dfs(list1);
   
 
  for(i=1;i<=num;i++)
    {
      printf("%d %d %d\n",i,d[i],f[i]);
    }
  return 0;
}
 
void dfs(Node* list1)
{
  int i,j;
  for(i=1;i<=num;i++)
    {
      list1[i].color = WHITE;
      time = 0;
    }
 
  for(j=1;j<=num;j++)
    {
      if(list1[j].color==WHITE) visit(list1,j);
 
    }
}
 
void visit(Node* list1, int j)
{
  int i;
  list1[j].color = GRAY;
  d[j] = ++time;
  for(i=1;i<=MAX;i++)
    {
      if(list1[j].list2[i]==NIL)break;
      else if(list1[list1[j].list2[i]].color == WHITE) visit(list1,list1[j].list2[i]);
    }
   
  list1[j].color = BLACK;
  f[j] = ++time;
     
   
}

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

using namespace std;
using ll = long long;

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

  int x;
  cin >> x;
  if (x >= 30)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n;
    cin >> n;

    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }
    SORT(a);

    lint ans = 0;
    auto it = lower_bound(a.begin(), a.end(), 0LL);
    int m = it - a.begin();
    if(m == n){
        if(m % 2 == 0){
            rep(i, n){
                ans += abs(a[i]);
            }
        }else{
            rep(i, n - 1){
                ans += abs(a[i]);
            }
            ans += a[n - 1];
        }
    }else if(a[m] == 0LL || m % 2 == 0){
        rep(i, n){
            ans += abs(a[i]);
        }
    }else{
        rep(i, m - 1){
            ans += abs(a[i]);
        }
        ans += max(a[m - 1] + a[m], -a[m - 1] - a[m]);
        REP(i, m + 1, n){
            ans += a[i];
        }
    }

    cout << ans << endl;

    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        Scanner sc = new Scanner();
        int[] ny = sc.ReadIntArray();
        int n = ny[0];
        int y = ny[1];
        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= n; j++)
            {
                if (n < i + j) continue;
                if (10000 * i + 5000 * j + 1000 * (n - i - j) == y)
                {
                    Console.WriteLine(i + " " + j + " " + (n - i - j));
                    return;
                }
            }
        Console.WriteLine("-1 -1 -1");
    }
}

class Scanner
{
    public string[] ReadString()
        => Console.ReadLine().Split(' ');
    public int ReadInt()
        => int.Parse(Console.ReadLine());
    public long ReadLong()
        => long.Parse(Console.ReadLine());
    public decimal ReadDecimal()
        => decimal.Parse(Console.ReadLine());
    public int[] ReadIntArray()
        => Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    public long[] ReadLongArray()
        => Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
}

Measured memory_bytes: 13396
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val ss = readLine()!!

    val sumE = IntArray(n){0}
    val sumW = IntArray(n){0}

    sumE[0] = if (ss[0] == 'E') 1 else 0
    sumW[0] = if (ss[0] == 'W') 1 else 0

    for (i in 1 until n) {
        if (ss[i] == 'E') {
            sumE[i] = sumE[i-1] + 1
            sumW[i] = sumW[i-1]
        } else {
            sumE[i] = sumE[i-1]
            sumW[i] = sumW[i-1] + 1
        }
    }

    var min = sumE[n-1] - sumE[0]

    for (i in 1 until n) {
        min = Math.min(min, sumW[i-1] + sumE[n-1] - sumE[i])
    }

    println(min)
}

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

main() {
  int n;
  int d[3];
  cin>>n;
  for(int i=0;i<n;i++) {
    cin>>d[0]>>d[1]>>d[2];
    sort(d,d+3);
    printf("%s\n",d[2]*d[2]==d[0]*d[0]+d[1]*d[1]?"YES":"NO");
  }
}

Measured memory_bytes: 0
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.random;
  
void main() {
  auto x = readln.chomp.split.map!(to!int);
  auto a = x[0];
  auto b = x[1];
  auto op = a == b ? "==" : a > b ? ">" : "<";
  writeln("a ", op, " b");
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, e, distance, ab, bc, cd, de, ae;
    cin >> a >> b >> c >> d >> e >> distance;
    ab = b - a;
    bc = c - b;
    cd = d - c;
    de = e - d;
  ae = e - a;
    if(ae > distance){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }
}

Measured memory_bytes: 256
import sys


def resolve(in_):
    n = int(in_.readline())
    h = tuple(map(int, in_.readline().split()))

    answer = [0] * n

    answer[1] = abs(h[1] - h[0])
    for i in range(2, n):
        answer[i] = min(answer[i - 1] + abs(h[i] - h[i - 1]), answer[i - 2] + abs(h[i] - h[i - 2]))
    # print(h, answer)
    return answer[n - 1]


def main():
    ans = resolve(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()

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

int main() {

	int x, y;
	int root[12] = {1,2,1,4,1,4,1,1,4,1,4,1};

	cin >> x >> y;

	if (root[x - 1] == root[y - 1])cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll K;
    cin >> K;
    ll ans = 0;
    repe(i,1,K+1){
        repe(j,1,K+1){
            ll ij = gcd(i, j);
            repe(k,1,K+1){
                ans += gcd(ij, k);
            }
        }
    }
    cout << ans << endl;
}


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

typedef long long ll;

using vi = vector<int>;
using vl = vector<long long int>;
using vii = vector<vector<int>>;
using vll = vector<vector<long long int>>;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
       const int INF=1e9+7;
    ll n,k,temp=INF,w;
 
    cin>>n>>w;
    vii arr(n+1,vi(2));

for(int i=1;i<=n;i++)cin>>arr[i][0]>>arr[i][1];

// arr[i][0]-->weight,,,arr[i][1]-->value.

vll dp(n+1,vl(w+1));

for(int i=1;i<=n;i++)
{
    for(int j=1;j<=w;j++)
    {
        temp=arr[i][1]+dp[i-1][j-arr[i][0]];
        if(j-arr[i][0]<0)
        {
            temp=0;
        }
        
        dp[i][j]=max(dp[i-1][j],temp);
    }

}

cout<<dp[n][w]<<"\n";


return 0;

}


Measured memory_bytes: 80256
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll const MOD = 1e9+7;
int main() {
    string s;
    std::cin >> s;
    ll dp[100010][20];
    Fill(dp,0);
    
    int mv[100010][20];

    Fill(mv,0);
    ll n = s.length();
    
    // 0桁目がひとけた目
    for (int i = 0; i < 10; i++) {
        mv[0][i] = i%13;
    }
    
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            mv[i][j] = (mv[i-1][j]*10)%13;
        }
    }
  
  	
  	if(s[0] != '?'){
  	    dp[0][mv[n-1-0][(s[0]-'0')]]++;
  	}else{
  	    for (int i = 0; i < 10; i++) {
  	        dp[0][mv[n-1-0][(i)]]++;
  	    }
  	}
    
    for (int i = 1; i < n; i++) {
        if(s[i] != '?'){
            for (int j = 0; j < 13; j++) {
              dp[i][ ( j + mv[n-1-i][(s[i]-'0')] )%13 ] += dp[i-1][j];
              dp[i][ ( j + mv[n-1-i][(s[i]-'0')] )%13 ] %= MOD;
//              cout <<dp[i+1][ ( j + mv[n-1-i][(s[i]-'0')] )%13 ]<<endl;
            }
        }else{
            for (int j = 0; j < 13; j++) {
                for (int k = 0; k < 10; k++) {                  
                  dp[i][ (j + mv[n-1-i][k]) %13 ] += dp[i-1][j];
                  dp[i][ (j + mv[n-1-i][k]) %13 ] %= MOD;
//                  cout	<<dp[i+1][ (j + mv[n-1-i][k]) %13 ]<<endl;
                }
            }
        }
    }
  	cout<<dp[n-1][5] <<endl;
}


Measured memory_bytes: 23936
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n;cin>>n;
	vi a(n);
	rep(i,0,n) cin>>a[i];
	reverse(a.begin(), a.end());
	ll cnt=0,ans=-1;
	rep(i,0,n-1)
	{
		if(a[i]<=a[i+1]) cnt++;
		else ans=max(ans,cnt),cnt=0;
	} 
	ans=max(ans,cnt);
	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

static int dp[3000][3000][2];

int main(){
   int n, t;
   cin>>n>>t;
   vector<int> a(n), b(n);
   rep(i, n) cin>>a[i]>>b[i];

   // int dp[3000][2];
   rep(i, n) rep(j, t) rep(k, 2) dp[i][j][k]=0;

   auto upd=[](int& a, int b){a=max(a, b);};

   // dp[t-1][0]=0 start
   rep(i, n){
      rep(j, t){
         rep(k, 2) upd(dp[i][j][k], (i==0)?0:dp[i-1][j][k]);
         rep(k, 2) if(j-a[i]>=0) upd(dp[i][j-a[i]][k], ((i==0)?0:dp[i-1][j][k])+b[i]);
         upd(dp[i][j][1], ((i==0)?0:dp[i-1][j][0])+b[i]);
      }
   }

   int mx=0;
   rep(i, n) rep(j, t) rep(k, 2) mx=max(mx, dp[i][j][k]);

   cout<<mx<<endl;
   return 0;
}


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

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

int main() {
    int n, start;
    cin >> n >> start;
    int x[n];
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
        x[i] -= start;
    }
    int ans = abs(x[0]);
    for (int i = 1; i < n; ++i) ans = gcd(ans, abs(x[i]));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<ll,ll>
#define loop(i,begin,end) for(int i=begin;i<end;i++)
#define out(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
using namespace std;



int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
ll a,b;
  cin>>a>>b;
if(a<=9 and a>=1 and b<=9 and b>=1){
  ll x = a*b;
  cout<<x;}
else cout<<"-1";
   

}

Measured memory_bytes: 256
package main
 
import (
  "fmt"
)
 
func main() {
  var r int
  fmt.Scanf("%d", &r)

  ans := "ABC"
  if r >= 1200 {
    ans ="ARC"
  }
  if r >= 2800 {
    ans ="AGC"
  }
  
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1832
# author:  Taichicchi
# created: 29.09.2020 23:12:45

import sys
from collections import Counter

n = int(input())

S = []
for i in range(n):
    S.append(sorted(input()))

c = Counter(S[0])

for s in S[1:]:
    for k, v in c.items():
        c[k] = min(v, s.count(k))

ans = ""
c = dict(c)

for k, v in c.items():
    ans += k * v

ans = sorted(ans)

print("".join(ans))


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

using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    int ssize = s.size();
    int tsize = t.size();
    s += s;
    t += t;
    string st,tt;
    for(int i = 0; i < s.size()-ssize; i++){
        st = s.substr(i,ssize);
        for(int j = 0; j < t.size()-tsize; j++){
            tt = t.substr(j,tsize);
            if(st<tt){
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
}

Measured memory_bytes: 256