akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//BEGIN CUT HERE
template<typename T,T MOD,T B>
struct RollingHash{
  vector<T> hash,p;
  RollingHash(){}
  RollingHash(const string &s){
    int n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=(hash[i]*B+s[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(int l,int r){
    T res=hash[r]+MOD-hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};

const int MOD = 1e9+7;
const int MOD2 = 1e9+9;
const int B = 1777771;
using RH = RollingHash<int, MOD, B>;
using RH2 = RollingHash<int, MOD2, B>;
RH s;
RH2 t;
int N;
string S;

bool check(int x) {
  if ( x > N ) return false;
  map<int, int> cnt;
  for ( int i = 0; i < N; i++ ) {
    if ( i+x > N ) break;    
    cnt[s.find(i, i+x)] = i;    
  }
  for ( int i = 0; i < N; i++ ) {
    if ( i+x > N ) break;
    if ( cnt[s.find(i, i+x)] >= i+x ) return true;
  }

  return false;  
}

bool check2(int x) {
  if ( x > N ) return false;
  map<int, int> cnt;
  for ( int i = 0; i < N; i++ ) {
    if ( i+x > N ) break;    
    cnt[t.find(i, i+x)] = i;    
  }
  for ( int i = 0; i < N; i++ ) {
    if ( i+x > N ) break;
    if ( cnt[t.find(i, i+x)] >= i+x ) return true;
  }

  return false;  
}

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

  cin >> N >> S;
  s = RH(S);
  t = RH2(S);  

  int l = 0, r = N+1;
  while ( r-l > 1 ) {
    int mid = (l+r)/2;
    if ( check(mid) && check2(mid) ) l = mid;
    else r = mid;    
  }

  cout << l << endl;  
  
  return 0;
}


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

int main() {
    ll n;
    std::cin >> n;
    vector<vector<ll>> edges(n);
    for (int i = 0; i < n-1; i++) {
        ll a,b;
        std::cin >> a>>b;
        a--;b--;
        
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    
    ll start = 0;
    
    // p,n,d;
    queue<tuple<ll,ll,ll>> q;
    q.push({-1,start,0});
    ll last;
    while(q.size()){
        auto [p, now, dis] = q.front();q.pop();
        last = now;
        for (auto e : edges[now]) {
            if(e==p)continue;
            q.push({now,e,dis+1});
        }
    }
    start = last;
    q.push({-1,start,0});
    ll dia = 0;
    while(q.size()){
        auto [p, now, dis] = q.front();q.pop();
        last = now;
        dia = max(dia, dis);
        for (auto e : edges[now]) {
            if(e==p)continue;
            q.push({now,e,dis+1});
        }
    }

    if(dia%3==1){
        std::cout << "Second" << std::endl;
    }else{
        std::cout << "First" << std::endl;
    }
}


Measured memory_bytes: 20392
n=int(input())
a=list(map(int,input().split()))

f=0
b=sum(a)
m=abs(a[0]-sum(a[1:]))
for i in range(n-1):
    f+=a[i]
    b-=a[i]
    m=min(m,abs(f-b))
print(m)

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

#define ARC(i, a, b) for(int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T &anth(T &a, const T &b){ return a = ant(a, b); }
template<class T> T &onth(T &a, const T &b){ return a = ont(a, b); }

int ans;
int x, y, z;

int main(){
	int n;
	scanf("%d", &n);
	RC(i, n){
		char ch[20];
		scanf("%s", ch);
		int len = strlen(ch);
		if(ch[len - 1] == 'A' && ch[0] == 'B') ++y;
		else if(ch[len - 1] == 'A') ++x;
		else if(ch[0] == 'B') ++z;
		RC(j, len - 1) if(ch[j] == 'A' && ch[j + 1] == 'B') ++ans;
	}

	if(x == 0 && z == 0){
		if(y) ans += y - 1;
	}else ans += ont(x, z) + y;

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


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  sort(L.begin(),L.end());
  reverse(L.begin(),L.end());
  int sum = 0;
  for(int i=0;i<K;i++){
    sum += L.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())
 
dict = {}
strings = []
for i in range(N):
    x = input()
    if x in dict.keys():
        dict[x] += 1
    else:
        dict[x] = 1
 
maximum = 1
for i in dict:
    maximum = max(maximum,dict[i])
 
for word in dict:
    if dict[word] == maximum:
        strings.append(word)
strings.sort()
for word in strings:
    print(word)

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

typedef long long LL;
string s;

LL cnt[10], a[10];

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> s;
        if(s[0] == 'M') cnt[0]++;
        else if(s[0] == 'A') cnt[1]++;
        else if(s[0] == 'R') cnt[2]++;
        else if(s[0] == 'C') cnt[3]++;
        else if(s[0] == 'H') cnt[4]++;
    }
    int tot = 0;
    for(int i = 0; i < 5; i++)
        if(cnt[i]) a[tot++] = cnt[i];
    //cout << tot << endl;
    if(tot < 3) cout << 0 << '\n';
    else if(tot == 3) cout << a[0] * a[1] * a[2] << '\n';
    else if(tot == 4) cout << a[0] * (a[1] * a[2] + a[1] * a[3] + a[2] * a[3]) + a[1] * a[2] * a[3] << '\n';
    else {
        LL ans = a[0] * (a[1] * a[2] + a[1] * a[3] + a[1] * a[4] + a[2] * a[3] + a[2] * a[4] + a[3] * a[4]);
        ans += a[1] * (a[2] * a[3] + a[2] * a[4] + a[3] * a[4]);
        ans += a[2] * a[3] * a[4];
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int h;
void maxHeapify(int *A,int i){
  int l=i*2+1;
  int r=i*2+2;
  int largest;
  if(l<h&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<h&&A[r]>A[largest]) largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(A,largest);
  }
}
void buildMaxHeap(int *A){
  for(int i=h/2;i>=0;i--)
    maxHeapify(A,i);
}
signed main(){
  cin>>h;
  int A[h];
  for(int i=0;i<h;i++) cin>>A[i];
  buildMaxHeap(A);
  for(int i=0;i<h;i++) cout<<" "<<A[i];
  cout<<endl;
  return 0;
}

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

int main() {
map<char,int> a;
string s;
cin >> s;
rep(i,s.size()){
  a[s.at(i)]++;
}
bool ans  = true;
rep(i,s.size()){
  if(a.at(s.at(i))%2 != 0) ans = false;
}
cout << (ans?"Yes":"No") << endl;
}


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

int main(){
    long long int n,ans=0,a1=0,a2=0,a4=0;
    cin>>n;
    string s="Yes";
    vector<long long int>t(1000000);
    for(int i=0;i<n;i++){
        cin>>t[i];
        if(t[i]%4==0){
            a4++;
        }
        else if(t[i]%2==0){
            a2++;
        }
        else{
            a1++;
        }
    }
    if(a2>0){
        a1++;
    }
    if(a1>a4+1){
        s="No";
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    if (n > m) {
        cout << 0 << endl;
        return 0;
    }

    vector<ll> x(m), y(m - 1);
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    for (int i = 0; i < m - 1; ++i) {
        y[i] = x[i + 1] - x[i];
    }
    sort(y.begin(), y.end());
    reverse(y.begin(), y.end());

    ll d = 0;
    for (int i = 0; i < n - 1; ++i) {
        d += y[i];
    }

    cout << x[m - 1] - x[0] - d << endl;
    return 0;

}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

const long long MOD = 2;

vector<int> g[10];

int p[10];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int x;
            cin >> x;
            g[i].push_back(x - 1);
        }
    }

    for (int i = 0; i < M; i++) {
        cin >> p[i];
    }

    int ok = 0;
    for (int i = 0; i < (1 << N); i++) {
        int ans = 0;
        for (int j = 0; j < M; j++) {
            int sum = 0;
            for (auto k : g[j]) {
                sum ^= (i >> k & 1);
            }
            ans += sum % 2 == p[j];
        }
        if (ans == M) {
            ok++;
        }
    }
    cout << ok << endl;
    // Failed to predict input format
    return 0;
}


Measured memory_bytes: 256
//wawando's template

#include <iostream>
#include <string>
#include <fstream>
#include <functional>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <set>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>  //clock_t , clock() , CLOCKS_PER_SEC
#include <cstring>
#include <cctype>
#include <climits> // LLONG_MAX , LLONG_MIN , INT_MAX , INT_MIN

//MACROS
#define pb              push_back
#define mp              make_pair
#define INF             1000000000     //1 billion safer for floyd warshall, avoid overflow

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	//ios::sync_with_stdio(false);
  int N, Hi, ans = 0, max = -1;
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%d", &Hi);
    if(Hi >= max) {
      max = Hi;
      ans++;
    }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int, read().split())
idx = max(range(n),key=lambda i: abs(a[i]))

print(2*n-1)
for i in range(n):
    print(idx+1,i+1)
if a[idx] >= 0:
    for i in range(n-1):
        print(i+1,i+2)
else:
    for i in range(n-2,-1,-1):
        print(i+2,i+1)

Measured memory_bytes: 9064
N = int(input())
S = sorted([int(input()) for i in range(N)])
min_no_ten = float('inf')
for s in S:
    if s % 10 != 0:
        min_no_ten = s
        break
else:
    print(0)
    exit()

total = sum(S)
if total % 10 != 0:
    print(total)
else:
    print(total - min_no_ten)


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

long long n, a[209], sz[209], ret, mod = 1000000007;
long long dp[209][209][209], power[5] = { 1,10,100,1000,10000 };

long long solve(vector<long long>E, long long num, bool iszero) {
	for (int i = 0; i <= E.size(); i++) { for (int j = 0; j <= i; j++) { for (int k = 0; k <= i - j; k++) dp[i][j][k] = 0; } }
	dp[0][0][0] = 1;
	for (int k = 0; k < E.size(); k++) {
		for (int i = 0; i <= k; i++) {
			for (int j = 0; j <= k - i; j++) {
				if (dp[k][i][j] == 0) continue;
				long long X = i + 1, Y = j + 1;
				dp[k + 1][i + 1][j] += dp[k][i][j] * X;
				dp[k + 1][i][j + 1] += dp[k][i][j] * Y*power[sz[E[k]]];
				dp[k + 1][i][j] += dp[k][i][j];
			}
		}
		for (int i = 0; i <= k + 1; i++) {
			for (int j = 0; j <= k + 1 - i; j++) dp[k + 1][i][j] %= mod;
		}
	}
	long long Z = 0;
	for (int j = 0; j <= E.size(); j++) {
		for (int k = 0; k <= E.size() - j; k++) {
			if (j == 0 && num == 0) continue;
			Z += dp[E.size()][j][k]; Z %= mod;
			if (iszero == true) {
				Z += dp[E.size()][j][k] * j; Z %= mod;
				Z += dp[E.size()][j][k] * (k + 1) * 10LL; Z %= mod;
			}
		}
	}
	return Z;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) { cin >> a[i]; sz[i] = to_string(a[i]).size(); }
	for (int i = 1; i <= n; i++) {
		vector<long long>X; bool OK = false;
		for (int j = 1; j <= n; j++) { if (i != j) { if (a[j] != 0)X.push_back(j); else OK = true; } }
		long long G = solve(X, a[i], OK);
		ret += a[i] * G; ret %= mod;
	}
	cout << ret << endl;
	return 0;
}


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

bool isPa(int x){
      string s = to_string(x);
      int n = s.length();
      for(int i = 0;i < n / 2;i++){
            if(s[i] != s[n - i - 1])return false;
      }
      return true;
}

int main(){
      int a,b;cin >> a >> b;
      int ans = 0;
      for(int i = a;i <= b;i++){
            if(isPa(i))ans++;
      }
      cout << ans;
}

Measured memory_bytes: 256
num = int(input())
s = 'abcdefghijklmnopqrstuvwxyz'
ans = ''
while num > 26:
    num, rest = divmod(num, 26)
    ans += s[rest - 1]
    if rest == 0:
        num -= 1
    #num -= 1
    #print(ans, num, rest)
    
ans += s[num - 1]
print(ans[::-1])


Measured memory_bytes: 9152
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct Union_Find {
	vector<int> rank, par;
	int independent_tree;
	int N;

	Union_Find() = default;

	Union_Find(int n) {
		N = n;
		for (int i = 0; i < N; i++)rank.push_back(1), par.push_back(i);
		independent_tree = N;
	}

	void setsize(int n) {
		N = n;
		for (int i = 0; i < N; i++)rank.push_back(1), par.push_back(i);
		independent_tree = N;
	}

	int getroot(int X) {
		if (par[X] == X)return X;
		return par[X] = getroot(par[X]);
	}

	bool issame(int A, int B) {
		return getroot(A) == getroot(B);
	}

	void unite(int A, int B) {
		A = getroot(A), B = getroot(B);
		if (A == B)return;
		independent_tree--;
		if (rank[A] > rank[B]) {
			par[B] = A;
		}
		else if (rank[A] == rank[B]) {
			par[B] = A;
			rank[A]++;
		}
		else {
			par[A] = B;
		}
	}

};

//強連結成分分解 O(V+E)　Union Findを使って一部の機能を実装してる
struct StronglyConnectedComponents {
	vector<vector<int>> E, rE;
	vector<int> belong;//belong[i] := i番目の頂点が属してる強連結成分の集合番号
	vector<int> order, used;
	int N;
	int anscnt = 1;//集合番号は1-idxで実装した
	Union_Find uf;

	StronglyConnectedComponents(vector<vector<int>> e) {
		E = e;
		N = E.size();
		rE.resize(N);
		used.resize(N);
		belong.resize(N);
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < E[i].size(); j++) {
				rE[E[i][j]].push_back(i);
			}
		}

		uf.setsize(N);
	}

	void dfs(int pos, int bef) {
		used[pos] = 1;
		for (int i = 0; i < E[pos].size(); i++) {
			int nxt = E[pos][i];
			if (nxt == bef)continue;
			if(!used[nxt])dfs(nxt, pos);
		}
		order.push_back(pos);
	}

	void rdfs(int pos, int bef) {
		belong[pos] = anscnt;
		if (bef != -1)uf.unite(pos, bef);
		for (int i = 0; i < rE[pos].size(); i++) {
			int nxt = rE[pos][i];
			if (nxt == bef || belong[nxt] != 0) {
				continue;
			}
			rdfs(nxt, pos);
		}
	}

	void conduct() {
		for (int i = 0; i < N; i++)
			if (used[i] == 0)dfs(i, -1);

		reverse(order.begin(), order.end());

		for (int i = 0; i < N; i++) {
			if (belong[order[i]] == 0)rdfs(order[i], -1), anscnt++;
		}
	}

	int operator[](int k) {
		return belong[k];
	}

	vector<vector<int>> trans_adjacency_list(){
		//i番目の今日連結グループの中身を返す。 例によって1-idxで
		vector<vector<int>> ret(anscnt);
		for (int i = 0; i < N; i++) {
			ret[belong[i]].push_back(i);
		}
		return ret;
	}

	vector<vector<int>> get_SCC_DAG(){
		//強連結成分を頂点としたグラフを作る。
		//強連結成分の番号はbelong[i]にある通りで1-idxで実装されてる
		//UFを使うことでO(N)でできた

		vector<vector<int>> ret;
		ret.resize(anscnt);
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < E[i].size(); j++) {
				int nxt = E[i][j];
				if (!uf.issame(i, nxt)) {
					ret[belong[i]].push_back(belong[nxt]);
				}
			}
		}
		return ret;
	}
};

int v, e;

int main() {
	cin >> v >> e;
	vector<vector<int>> E(v);
	for (int i = 0; i < e; i++) {
		int u, v;
		cin >> u >> v;
		E[u].push_back(v);
	}

	StronglyConnectedComponents scc(E);
	scc.conduct();

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int u, v;
		cin >> u >> v;
		if (scc.uf.issame(u, v))cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 5944
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int>> data;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        data.push_back(make_tuple(a, b));
    }
    sort(data.begin(), data.end());
    int amax = get<0>(data.at(n - 1));

    int counter = 0;
    multiset<int> b;
    int output = 0;
    for (int a = 1; a <= m; a++)
    {
        //cout << "m" << a << endl;
        //cout << "counter" << counter << endl;
        for (int i = counter; i < n; i++)
        {
            if (get<0>(data.at(i)) == a)
            {
                //cout << "push";
                //cout << get<1>(data.at(i)) << endl;
                b.insert(get<1>(data.at(i)));
                counter++;
            }
            else
                break;
        }
        //cout << "next";
        if (!b.empty())
        {
            auto maxitr = --b.end();
            output += *maxitr;
            b.erase(maxitr);
        }
        //cout << "output" << output << endl;
    }
    cout << output;
}

Measured memory_bytes: 5620
n = int(input())
s1 = input()
s2 = input()
mod = 10**9 + 7

if s1[0] == s2[0]:
    ans = 3
    q = 1
else:
    ans = 6
    q = -1

for i in range(1, n):
    x = s1[i]
    y = s2[i]
    if x == y:
        if q == 0:
            q = 1
        elif q == 1:
            ans *= 2
    else:
        if q == -1:
            q = 0
        elif q == 0:
            ans *= 3
            q = -1
        else:
            ans *= 2
            q = -1
    ans %= mod
print(ans%mod)


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


int main(){


    int n, i, j;

    int x = 0;

    int y = 0;

    int z = 0;

    int k = 0;

    string t;

    vector<string> s;

 
    cin >> n;


    for( i = 0 ; i < n ; i = i + 1 ){

         cin >> t;

         s.push_back(t);

         if( t.at(0) == 'B' && t.at( t.size() - 1 ) == 'A' ) x += 1;

         else if( t.at(0) == 'B' ) y += 1;

         else if( t.at( t.size() - 1 ) == 'A' ) z += 1;

         for( j = 0 ; j < t.size() - 1 ; j = j + 1 ){

              if( t.substr(j, 2) == "AB" ) k += 1;

              }

         }


    if( y + z == 0 && x > 0 ) k += x - 1;

    else k += min( x + y, x + z );


    cout << k << endl;


    return 0;


    }

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    int[] as;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt() - 1;
        }
        solve();
    }

    void solve() {
        boolean[] used = new boolean[n];
        int current = 0;
        int count = 0;
        while (true) {
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (used[current]) {
                System.out.println(-1);
                return;
            }
            used[current] = true;
            count++;
            current = as[current];
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 35832
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n)-1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a)-1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using Vec = vector<T>;
template<class T> using VVec = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i-1)*10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}

struct IoSetup {
	IoSetup() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

vector<ll> dp(2010, -1);
const ll mod = 1000000007;

ll rec(int x) {
	if (dp[x] != -1) return dp[x];
	if (x <= 2) return 0;
	ll ret = 0;
	for (int i = x - 3; i >= 3; i--) {
		ret = (ret + 1 + rec(i)) % mod;
	}
	return dp[x] = ret;
}

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

	if (S <= 2) {
		cout << 0 << endl;
		return 0;
	}

	cout << (rec(S) + 1) % mod << endl;
	
	return 0;
}

Measured memory_bytes: 3656
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = []
    for _ in range(M):
        b, c = map(int, input().split())
        BC.append((b, c))

    BC = sorted(BC, key=lambda x: -x[1])
    n = 0
    for b, c in BC:
        n += b
        A += [c] * b
        
        if n >= N:
            break

    A = sorted(A, key=lambda x: -x)
    return sum(A[:N])


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 35436
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int count=0;
		while(sc.hasNext()){
			String s = sc.next();
			StringBuffer t = new StringBuffer(s);
			t.reverse();
			if(t.toString().compareTo(s)==0)count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 17136
n, m, l = map(int, input().split())
list_a = []
list_b = []
list_c = []

for i in range(n):
    list_a.append(list(map(int, input().split())))
for j in range(m):
    list_b.append(list(map(int, input().split())))

for i in range(n):
    li = []
    for j in range(l):
        su = 0
        for k in range(m):
            su += list_a[i][k] * list_b[k][j]
        li.append(su)
    print(" ".join(list(map(str, li))))



Measured memory_bytes: 6248
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define V vector
#define pb push_back
#define mp make_pair
#define endl "\n"
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define MOD 1000000007  //1e9+7

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void solve()
{
	int n; cin>>n;
	int ans=0;
	if(n>=500){
		ans+=(n/500)*1000;
		n%=500;
	}
	if(n>=5){
		ans+=(n/5)*5;
		n/=5;
	}
	cout<<ans<<endl;
}
	
int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //int t; cin>>t;
    //while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x)	make_pair(x);
    
#define debug(x) 		cerr << #x << '=' << x << endl;
#define debug2(x, y)	cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << _x << ' '; cerr << endl;
#define debugm(a) 		cerr << #a << ":\n"; \
						for (auto v: a) { for(const auto x: v) cout << x << ' '; cerr << "\n"; }
 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long
 
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;
 
const int INF  = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN;
const int mmod = 998244353;

int32_t main()
{
	FAST_IO;
	
	int n, k;
	cin >> n >> k;
	int a[n+1];
	for (int i = 1; i <= n; i++) cin >> a[i];
	
	if (k == 1) {
		cout << 0 << endl;
		return 0;
	}
	int preSum[n+1];
	preSum[0] = 0;
	
	for (int i = 1; i <= n; i++) preSum[i] = preSum[i-1] + a[i];
	
	int ans = 0;
	
	map<int, int> m;
	m[0]++;
	for (int j = 1; j <= n; j++) {
		ans += m[(preSum[j]-j)%k];
//		debug(ans);
		m[(preSum[j]-j)%k]++;
//		debug(m[(preSum[j]-j)%k]);
//		debug((preSum[j]-j)%k);
		if (j >= k-1) {
			m[(preSum[j-k+1]-(j-k+1))%k]--;
//			debug((preSum[j-k+1]-(j-k+1))%k);
//			debug(m[(preSum[j-k+1]-(j-k+1))%k]);
//			debug2(j, j-k+1);
		}
//		cout << ans << endl;
	}
	
//	for (auto it: m) cout << it.first << ' ' << it.second << endl;
	cout << ans << endl;
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined 


Measured memory_bytes: 15872
def main():
	s = input()
	max_len = 0
	this_len = 0
	is_start = False
	for c in s:
		if is_acgt(c):
			this_len += 1
			is_start = True
			if max_len < this_len:
				max_len = this_len
		else:
			this_len = 0
			is_start = False
	print(max_len)


def is_acgt(c: str) -> bool:
	if c in ["A", "C", "G", "T"]:
		return True
	return False

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる
  ll cost; // e.costでその辺の重みにアクセスできる
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}
//素数判定 
//一つ一つの判定ではこっちの方が速い(一つ当たりO(√N))
//一方100までに何個あるかなどはEratosthenesの篩の方が良い（O(NlogN))
bool PN(int x) {
  if (x <= 1) return false; // 1や0,-1は素数ではない
  if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) return false; // 割れたら素数じゃない
  }
  return true;
}
// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  long long ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}
  
//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N, D, X;
  cin >> N >> D >> X;
  int ans = X + N;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    ans += (D - 1) / A;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
bool a,b,c;

int main() 
{

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='a')a=true;
		if(s[i]=='b')b=true;
		if(s[i]=='c')c=true;
	}
	if(a==true&&b==true&&c==true)cout<<"Yes";
	else cout<<"No";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <math.h>
#include <string>

#define ll unsigned long long
#define vll vector<ll>
#define vvll vector<vll>
#define vb vector<bool>
#define vvb vector<vb>
#define vstr vector<string>
#define pll pair<ll, ll>
#define pb pair<bool, bool>
#define vpll vector<pll>
#define vpb vector<pb>

using namespace std;

int main()
{
	ll n;
	cin >> n;
	vll arr(n);
	for (ll i = 0; i < n; i++) cin >> arr[i];
	for (ll i = 0; i < n; i++)
	{
		if (arr[i] == 0)

		{
			//while (true);
			cout << "0" << endl;
			return 0;
		}
	}
	ll ans = 1;
	for (ll i = 0; i < n; i++)
	{
		if(log10(ans) + log10(arr[i]) > 18)
		{
			cout << "-1" << endl;
			return 0;
		}
		ans *= arr[i];
		if (ans > (ll)1000000000000000000)
		{
			cout << "-1" << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

/*
3
1000000000000000000 1000000000000000000
1000000001
*/

Measured memory_bytes: 3712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String line = br.readLine();
      final Pattern delim = Pattern.compile(" ");
      int[] arrayS = delim
        .splitAsStream(line)
        .parallel()
        .mapToInt(Integer::parseInt)
        .toArray();

      OptionalInt max =
        Arrays.stream(arrayS).max();

      dispIntArray( countingSort(arrayS, max.getAsInt()) );
    }
    catch ( IOException e ) {
      System.out.println("IOException!");
    }

  }

  public int[] countingSort(int[] a, int k) {

    int   aLength = a.length;
    int[] result  = new int[aLength];
    int[] counter = new int[k+1];

    for (int var : a) {
      counter[var]++;
    }

    for (int i=1, max=k+1; i < max; i++) {
      counter[i] += counter[i-1];
    }

    for (int i=aLength-1, val=0; i>=0; i--) {
      val = a[i];
      result[counter[val]-1] = val;
      counter[val]--;
    }

    return result;
  }

  public void dispIntArray(int[] target) {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 202848
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(int argc, const char* argv[]) {
	string line; cin >> line;

	int s0_unex = 0;// 010101...を想定した場合の想定外の数した場合の想定外の数
	int s1_unex = 0;// 101010...

	int s0_next_exp = 0;
	int s1_next_exp = 1;
	for (auto c : line) {
		int num = (c - '0');

		if (s0_next_exp != num) s0_unex++;
		if (s1_next_exp != num) s1_unex++;

		s0_next_exp = 1 - s0_next_exp;
		s1_next_exp = 1 - s1_next_exp;
	}

	cout << min(s0_unex, s1_unex) << endl;

	return 0;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if (A < C && C < B) {
    cout << "Yes" << endl;
  } else if (B < C && C < A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
map <string,int> cost;
multimap <string,string>  rule;
set <string> his;
void update(string a){
  multimap<string,string>::iterator it=rule.find(a);
  while(it != rule.end() && it->first == a) {
    if(cost[it->second]>cost[a])cost[it->second]=cost[a], update(it->second);
    it++;
  }
}
int mk_rule(string a){
  if(his.count(a) == 0){
    his.insert(a);    
    multimap<string,string>::iterator it=rule.find(a);
    while(it != rule.end() && it->first == a) cost[a]= min(cost[a],mk_rule(it->second)),it++;
    update(a);
  }
  return cost[a];
}
int main(){
  int n,m,b;
  cin >> n;
  string a,c,ls[5002];
  for(int i=0;i<n;i++) cin >> ls[i] >> b, cost[ls[i]] = b;

  cin >> m;
  for(int i=0;i<m;i++){
    cin >> a >> c;
    rule.insert(pair<string,string>(a,c));
    rule.insert(pair<string,string>(c,a));
  }
  int ans=0;
  for(int i=0;i<n;i++) ans += mk_rule(ls[i]);
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 2244
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,ans = 0;
    int dp[1100][1100];
    char field;
    while(scanf("%d",&n),n)
    {
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
            {
                scanf(" %c",&field);
                dp[j + 1][i + 1] = 0;
                if(field == '*')dp[j + 1][i + 1] = -1;
            }
        for(int i = 1; i < n + 1; i++)
        {
            for(int j = 1; j < n + 1; j++)
            {
                if(dp[j][i] == -1);
                else if(j == 1 || i == 1)dp[j][i] = 1;
                else dp[j][i] = max(1,min(dp[j - 1][i - 1],min(dp[j - 1][i],dp[j][i - 1])) + 1);
                ans = max(ans,dp[j][i]);
            }
        }
        /*for(int i = 1; i < n + 1; i++)
        {
            for(int j = 1; j < n + 1; j++)
            {
                printf("%2d",dp[j][i]);
            }
            printf("\n");
        }*/
        printf("%d\n",ans);
        ans = 0;
    }
    return 0;
}

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

void debtAfterWeeks(int &debt, int interest, int &n){
	float fdebt,quotient;
	if(n==0){
		return;
	}else{
		fdebt=static_cast<float>(debt)*(1.0+static_cast<float>(interest)/100.0);
		debt=static_cast<int>(ceil(fdebt));
		quotient = debt % 1000;
		if(quotient != 0){
			debt = debt + 1000.0 - quotient;
		}
		--n;
		debtAfterWeeks(debt, 5, n);
	}
}

int main(){
	int n;
	int debt=100000;
	cin>>n;
	debtAfterWeeks(debt, 5, n);
	cout<<debt<<endl;
	return 0;
}

Measured memory_bytes: 1164
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(int to, int cost){
        this->to = to;
        this->cost = cost;
    }
};

const long long INF = LLONG_MAX / 2;

int main()
{
    int n, m, limit;
    cin >> n >> m >> limit;
    vector<vector<Edge> > edges(n);
    for(int i=0; i<m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        -- a;
        -- b;
        if(c <= limit){
            edges[a].push_back(Edge(b, c));
            edges[b].push_back(Edge(a, c));
        }
    }

    vector<vector<long long> > dp(n, vector<long long>(n, INF));
    for(int i=0; i<n; ++i){
        priority_queue<
            pair<long long, int>,
            vector<pair<long long, int> >,
            greater<pair<long long, int> >
        > pq;

        dp[i][i] = 0;
        pq.push(make_pair(0, i));
        while(!pq.empty()){
            long long cost;
            int curr;
            tie(cost, curr) = pq.top();
            pq.pop();
            if(dp[i][curr] < cost)
                continue;

            int rest = limit - cost % limit;
            for(const Edge& e : edges[curr]){
                long long cost2 = cost + e.cost;
                int next = e.to;
                if(rest < e.cost)
                    cost2 += rest;
                if(cost2 < dp[i][next]){
                    dp[i][next] = cost2;
                    pq.push(make_pair(cost2, next));
                }
            }
        }
    }

    int q;
    cin >> q;
    while(--q >= 0){
        int s, t;
        cin >> s >> t;
        -- s;
        -- t;
        long long ans = -1;
        if(dp[s][t] < INF)
            ans = (dp[s][t] - 1) / limit;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3236
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = 0;
        int b = 0;
        int c = 0;
        int count = 0;
        
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        for(int i = a; i <= b; i++){
            if(c % i == 0){
                count++ ;
            }else{
                continue;
            }
        }
        
        System.out.println(count);
    }
}


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

using namespace std;

typedef long long ll;

const int max_n = 202020;
int INF = 2e9;
vector<int> g[max_n];
vector<int> dp(max_n, INF);

vector<int> a;
vector<int> ans;

void dfs(int x, int p){
	auto itr = lower_bound(dp.begin(), dp.end(), a[x]);
	int i = itr - dp.begin();
	int from = *itr;
	int to = min(*itr, a[x]);
	*itr = to;
	
	ans[x] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
	
	for(int y : g[x]){
		if(y == p) continue;
		dfs(y, x);
	}
	dp[i] = from;
}

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

	int n;
	cin >> n;

	a.resize(n);
	rep(i, n) cin >> a[i];

	rep(i, n - 1){
		int u, v;
		cin >> u >> v;
		u--; v--;

		g[u].push_back(v);
		g[v].push_back(u);
	}

	ans.resize(n);
	dfs(0, -1);
	rep(i, n){
		cout << ans[i] << "\n";
	}

}


Measured memory_bytes: 27928
#pragma GCC target ("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1]
#define ll long long
#define pi 2 * acos(0.0)
#define usll unordered_set<ll>
#define sll set<ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define umll unordered_map<ll,ll>
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define Y cout<< "YES"<< "\n"
#define N cout<< "NO"<< "\n"
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll a[n],x=0,p;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        x=x^a[i];
    }
    for(ll i=0;i<n;i++)
    {
        p=x^a[i];
        cout<<p<< " ";
    }
    return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  auto begin = chrono::system_clock::now();
  
  int d;
  cin >> d;
  
  vector<int> c(26);
  for (int i = 0; i < 26; i++) cin >> c.at(i);
  
  vector<vector<ll>> s(d, vector<ll>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  
  // sが最大のものを貪欲
  vector<int> t(d);
  for (int i = 0; i < d; i++) {
    int it = 0;
    for (int j = 0; j < 26; j++) {
      if (s.at(i).at(j) > s.at(i).at(it)) it = j;
    }
    t.at(i) = it;
  }
  
  vector<vector<int>> dim(d, vector<int>(26, 1));
  ll suff = 0;
  for (int i = 0; i < d; i++) {
    suff += s.at(i).at(t.at(i));
    if (i > 0) {
      for (int j = 0; j < 26; j++) dim.at(i).at(j) = dim.at(i - 1).at(j) + 1;
    }
    dim.at(i).at(t.at(i)) = 0;
    for (int j = 0; j < 26; j++) {
      suff -= c.at(j) * dim.at(i).at(j);
    }
  }
  
  auto end = chrono::system_clock::now();
  auto time = chrono::duration_cast<chrono::microseconds>(end - begin).count();
  int dd = -1;
  while (time < 1950000) {
    dd = (dd + 1) % d;
    ll keepdelta = -10000, next = -1;
    for (int q = 0; q < 26; q++) {
      if (q == t.at(dd)) continue;
      vector<vector<int>> dim2 = dim;
      ll delta = s.at(dd).at(q) - s.at(dd).at(t.at(dd));
      for (int j = dd; j < d; j++) {
        delta += c.at(q) * dim2.at(j).at(q);
        delta += c.at(t.at(dd)) * dim2.at(j).at(t.at(dd));
      }
      dim2.at(dd).at(t.at(dd)) = 1; // 仮
      dim2.at(dd).at(q) = 0;
      for (int j = dd; j < d; j++) {
      if (dim2.at(j).at(t.at(dd)) > 0 && j > 0) dim2.at(j).at(t.at(dd)) = dim2.at(j - 1).at(t.at(dd)) + 1;
        if (dim2.at(j).at(q) > 0 && j > 0) dim2.at(j).at(q) = dim2.at(j - 1).at(q) + 1;
        delta -= c.at(q) * dim2.at(j).at(q);
        delta -= c.at(t.at(dd)) * dim2.at(j).at(t.at(dd));
      }
      if (delta > keepdelta) {
        keepdelta = delta;
        next = q;
      }
    }
    if (next == -1) continue;
    
    int q = next;
    dim.at(dd).at(t.at(dd)) = 1; // 仮
    dim.at(dd).at(q) = 0;
    for (int j = dd; j < d; j++) {
      if (dim.at(j).at(t.at(dd)) > 0 && j > 0) dim.at(j).at(t.at(dd)) = dim.at(j - 1).at(t.at(dd)) + 1;
      if (dim.at(j).at(q) > 0 && j > 0) dim.at(j).at(q) = dim.at(j - 1).at(q) + 1;
    }
    t.at(dd) = q;
    suff += keepdelta;
    end = chrono::system_clock::now();
    time = chrono::duration_cast<chrono::microseconds>(end - begin).count();
  }
  //cout << suff << endl;
  for (int i = 0; i < d; i++) cout << t.at(i) + 1 << '\n';
}

Measured memory_bytes: 3876
N,M = map(int,input().split())

AC = [0]*N
WA = [0]*N
AC_cnt = 0
WA_cnt = 0

p = [0]*M
S = [0]*M

for i in range(M):
    p[i],S[i] = map(str, input().split())

for i in range(M):
    q_num = int(p[i])
    if AC[q_num-1] == 0:
        if S[i] == "AC":
            AC[q_num-1] = 1
        else:
            WA[q_num-1] += 1

for i in range(N):
    if AC[i] == 1:
        WA_cnt += WA[i]
        AC_cnt += 1

print(AC_cnt,WA_cnt)

Measured memory_bytes: 24516
#include <iostream>
#include <algorithm>

using namespace std;

int n, k, h[100001] = {}, dp[100010] = {};

int main() {

	for (int i = 0; i < 100010; i++) {
		dp[i] = 1e9;// = 10^9
	}
	cin >> n >> k;

	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}


	dp[1] = 0;

	for (int i = 2; i <= n; i++) {

		dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);

		for (int j = 1; i - j >= 1 && j <= k; j++) {

			dp[i] = min(dp[i],dp[i - j] + abs(h[i] - h[i - j]));

		}
	}

	cout << dp[n] << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
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);
}
/*-------------------------------------------*/

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

    int n, k;
    cin >> n >> k;

    vector<ll> a(n);

    rep(i, n) cin >> a[i];

    rep(i, n - k) cout << (a[i] < a[i + k] ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 4776
#include<bits/stdc++.h>
using namespace std;
const int N=4000005;
char s[N],t[N];
int fail[N],dp[N];
int main()
{
	scanf("%s%s",s+1,t+1);
	int k=strlen(s+1),n=k,m=strlen(t+1);
	while(n<m*2)
	{
		for(int i=1;i<=n;i++)
			s[n+i]=s[i];
		n*=2;
	}
	for(int i=1;i<=n;i++)
		s[n+i]=s[i];
	n*=2;
	fail[0]=-1;
	for(int i=1;i<=m;i++)
	{
		int j=i-1;
		while(j&&t[fail[j]+1]!=t[i]) 
			j=fail[j];
		fail[i]=fail[j]+1;
	}
	int ans=0,j=0;
	for(int i=1;i<=n;i++)
	{
		while(~j&&s[i]!=t[j+1]) 
			j=fail[j];
		j++;
		if(j==m) 
		{
			dp[i]=dp[i-m]+1;
			ans=max(ans,dp[i]);
		}	
	}
	if(ans>=n/m-1)
		ans=-1;
	printf("%d\n",ans); 
	return 0;
}


Measured memory_bytes: 23040
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110000;
vector<int> graph[MAXN];
int dp[MAXN];
int solve(int a) {
  if (dp[a] != -1) {
    return dp[a];
  }
  int ans = 0;
  for (int i = 0; i < graph[a].size(); i++) {
    ans = max(ans, solve(graph[a][i]) + 1);
  }
  return dp[a] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    graph[x].push_back(y);
  }
  for (int i = 0; i < n; i++) {
    dp[i] = -1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, solve(i));
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 8448
import kotlin.comparisons.*
data class job(var cost: Int, var dead: Int)
fun main(args: Array<String>){
    val n = readLine()!!.toInt()

    var jobs = mutableListOf<job>()


    repeat(n){
        val (a,b) = readLine()!!.split(" ").map(String::toInt)
        jobs.add(job(a,b))
    }

    val sortedList = jobs.sortedWith(compareBy(job::dead,job::cost))

    val co = mutableListOf<Int>()
    val de = mutableListOf<Int>()


    for(i in 0..n-1){
        val (x,y) = sortedList[i]
        co.add(x)
        de.add(y)
    }


    var sumtime = 0

    for(i in 0..n-1){
        sumtime += co[i]
        if(de[i] < sumtime){
            println("No")
            return
        }
    }
    println("Yes")







    //println(jobs)
    //println(sortedList)
}




Measured memory_bytes: 122176
from itertools import accumulate
im = [[0]*1001 for i in range(1001)]
for x_1, y_1, x_2, y_2 in (map(int, input().split()) for _ in range(int(input()))):
	im[x_1][y_1] += 1
	im[x_1][y_2] -= 1
	im[x_2][y_1] -= 1
	im[x_2][y_2] += 1
print(max(map(max, map(accumulate, zip(*map(accumulate, im))))))


Measured memory_bytes: 13648
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n; cin >> n;
    priority_queue<int> pq;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        pq.push(a[i]);
    }
    int temp1 = pq.top();pq.pop();
    auto temp2 = pq.top();
    rep(i,n){
        if(a[i] == temp1) cout << temp2 << endl;
        else cout << temp1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3316