akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    int m;cin>>m;
    vl d(m),c(m);
    ll D=0,S=0;
    rep(i,m)cin>>d[i]>>c[i];
    rep(i,m){
        D+=c[i];
        S+=d[i]*c[i];
    }
    cout<<(D-1)+(S-1)/9<<endl;
}

Measured memory_bytes: 3328
N = int(input())
B = list(map(int, input().split()))

ans = list()
for k in reversed(range(N)):
    hit = False
    for l in reversed(range(1, k + 2)):
        if B[l - 1] == l:
            B = B[:l - 1] + B[l:]
            hit = True
            ans.append(l)
            break
    if not hit:
        print(-1)
        exit(0)

for e in reversed(ans):
    print(e)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[1001];
int  main()
{
	scanf("%s",s);
	if(s[0]==s[1]&&s[0]==s[2])
	{
		printf("Yes\n");
		return 0;
	}
	if(s[1]==s[2]&&s[1]==s[3])
	{
		printf("Yes\n");
		return 0;
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  string S;
  int W;
  
  cin>>S>>W;
  
  
  for(int i=0;i<S.size();i+=W){
    cout<<S[i];
  }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define int long long
using namespace std;
int INF = 1e16;

struct edge{
	int to,cost;
};
typedef pair<int,int> P; //firstは最短距離、secondは頂点の番号

int V; //頂点数
vector<edge> G[100010];
int d[100010]; //頂点sからの最短距離

void dijkstra(int s) {
	//greater<P>を指定することでfirstが小さい順に取り出せる
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d + V,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) {
			continue;
		}
		for(int i = 0;i < G[v].size();i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

signed main() {
    cin >> V;
    for(int i = 0;i < V - 1;i++) {
        int A,B,C;
        cin >> A >> B >> C;
        G[A - 1].push_back(edge{B - 1,C});
        G[B - 1].push_back(edge{A - 1,C});
    }
    int Q,K;
    cin >> Q >> K;
    dijkstra(K - 1);
    for(int i = 0;i < Q;i++) {
        int A,B;
        cin >> A >> B;
        cout << d[A - 1] + d[B - 1] << endl;
    }
}


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

int main(){
    int N;  cin >> N;
    for(int i=1; i<=9; i++){
        if(N%i==0 && N/i < 10){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<array>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(int i=0; i<(n); i++)

vector<array<int,27>> KMP;
array<int,27> Z;

int N;
vector<string> Sbuf;
LL ans=0;

int main() {

 cin>>N;
 Sbuf.resize(N);
 rep(i,N){ cin>>Sbuf[i]; reverse(Sbuf[i].begin(),Sbuf[i].end()); }

 rep(i,26) Z[i]=-1;
 Z[26]=0;
 KMP.push_back(Z);

 for(auto& S : Sbuf){
  int p=0;
  rep(i,S.size()){
   int d=S[i]-'a';
   if(KMP[p][d]==-1){
    KMP[p][d] = KMP.size();
    KMP.push_back(Z);
   }
   p=KMP[p][d];
  }
  KMP[p][26]++;
 }

 for(auto& S : Sbuf){
  vector<int> M(S.size()+1);

  for(int i=S.size()-1; i>=0; i--){
   M[i] = M[i+1] | (1<<(S[i]-'a'));
  }

  int p=0;
  rep(i,S.size()){
   int d=S[i]-'a';
   rep(nx,26){
    if((1<<nx) & M[i]) if(KMP[p][nx]!=-1)
     ans += KMP[KMP[p][nx]][26]; 
   }
   p=KMP[p][d];
  }
 }

 ans -= N;

 cout<<ans<<endl;
 
 return 0;
}

Measured memory_bytes: 117348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   int a, b;
   char op;
   cin >> a >> op >> b;
   if (op == '+')
   {
      cout << a + b << endl;
   }
   else if (op == '-')
   {
      cout << a - b << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int64_t Gcd(int64_t a,int64_t b){
    if(a%b==0) return b;
    Gcd(b,a%b);
}

map<int64_t,int64_t> Factorical(int64_t n){
    map<int64_t,int64_t> mp;
    for(int64_t i=2; i*i<=n; i++){
        if(n%i==0){
            while(n%i==0){
                n/=i;
                mp[i]++;
            }
        }
    }
    if(n!=1) mp[n]++;

    return mp;
}

int main(){
    int64_t A,B; cin>>A>>B;

    int64_t gcd=Gcd(A,B);
    map<int64_t,int64_t> Prm=Factorical(gcd);

    int64_t ans=Prm.size()+1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
ll dfs(ll S, ll i, ll sum);
int main(void){
    ll S;
    scanf("%lld", &S);
    printf("%lld\n", dfs(S, 10, 0));
    return 0;
}
ll dfs(ll S, ll i, ll sum){
    if(S/i == 0) return S+sum;
    return dfs(S/i, 10, sum+S%i) + dfs(S, i*10, sum);
}

Measured memory_bytes: 128
# abc152_a.py
# https://atcoder.jp/contests/abc152/tasks/abc152_a

# A - AC or WA /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 高橋君は、プログラミングコンテスト AXC001 に参加しており、問題 A にコードを提出しました。
# この問題には N個のテストケースがあり、すべてのテストケースに正解した場合のみ提出は AC となります。
# 高橋君の提出は、N 個のテストケースのうち M個のテストケースに正解しました。
# 高橋君の提出が AC となるか判定してください。

# 制約
#     1≤N≤100
#     0≤M≤N
#     入力はすべて整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N M

# 出力
# 高橋君の提出が AC となる場合は Yes, そうでない場合は No と出力せよ。

# 入力例 1
# 3 3

# 出力例 1
# Yes

# 3つのテストケースすべてに正解したので、AC となります。

# 入力例 2
# 3 2

# 出力例 2
# No

# 3つのテストケース中 2つしか正解できなかったので、AC となりません。

# 入力例 3
# 1 1

# 出力例 3
# Yes


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    if N == M:
        result = 'Yes'
    else:
        result = 'No'

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 3']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['3 2']
        lines_export = ['No']
    if pattern == 3:
        lines_input = ['1 1']
        lines_export = ['Yes']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9084
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
int main()
{
	checkpoint1();
	ll n,m;
	cin>>n>>m;
	ll dp[n][m];
	char a[n][m];
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	if(a[0][0]=='#'||a[n-1][m-1]=='#')
		cout<<0;
	else
	{
		dp[0][0]=1;
		for(ll i=0;i<n;i++)
		{
			for(ll j=0;j<m;j++)
			{
				if(i==0&&j==0)
					continue;
				else
				{
					if(a[i][j]=='#')
						dp[i][j]=0;
					else
					{
						dp[i][j]=((i-1<0)? 0:dp[i-1][j])+((j-1<0)?0 :dp[i][j-1]);
						dp[i][j]%=mod;
					}
				}
			}
		}
		cout<<dp[n-1][m-1];
	}
	return 0;
}

Measured memory_bytes: 12448
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,a[200001],b[200001];
    cin>>N;
    memset(b,0,sizeof(b));
    for(int i=2;i<=N;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=N;i++)
    {
        cout<<b[i]<<endl;;
    }



}


Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  int A;
  int B;
  cin >> K >> A >> B;
  int N;
  N = B / K;
  
  if (N * K >= A){
	cout << "OK" << endl;
  }

  else {
	cout << "NG" << endl;
  }
}

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

int main(){
    std::string s1,s2;
    std::cin>>s1>>s2;
    std::vector<std::vector<int>> ld(s1.size()+1,std::vector<int>(s2.size()+1,INT_MAX));
    for (int i = 0; i <= s1.size(); ++i) ld[i][0]=i;
    for (int i = 0; i <= s2.size(); ++i) ld[0][i]=i;
    for (int i = 1; i <= s1.size(); ++i) {
        for (int j = 1; j <= s2.size(); ++j) {
            ld[i][j]=std::min(ld[i-1][j]+1,std::min(ld[i][j-1]+1,ld[i-1][j-1]+(s1[i-1]==s2[j-1]?0:1)));
        }
    }
    std::cout<<ld[s1.size()][s2.size()]<< std::endl;
    return 0;
}



Measured memory_bytes: 6908
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N,A,answer=0;
  map<int,int> B;
  for (cin >> N; N; B[A]++, N--) {
    cin >> A;
  }
  vector<int> lengths;
  for (auto p : B) {
    if (p.second >= 4) {
      answer = max(answer,1ll*p.first*p.first);
    }
    if (p.second >= 2) {
      lengths.push_back(p.first);
    }
  }
  if (lengths.size() >= 2) {
    answer = max(answer,1ll*lengths.back()*lengths[lengths.size()-2]);
  }
  cout << answer;
}

Measured memory_bytes: 8236
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    cnt_2 = 0
    cnt_4 = 0
    for i in range(n):
        if A[i] % 4 == 0:
            cnt_4 += 1
        elif A[i] % 2 == 0:
            cnt_2 += 1

    if (n - max(0, cnt_2 - 1)) // 2 <= cnt_4:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 63344
#include<stdio.h>
#include<string.h>

long long int p_array[5001];
long long int c_array[5001];


int main()
{
	long long int score = -1000000001, n, k;
	long long int current_score;

	scanf("%lld %lld", &n, &k);

	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &p_array[i]);
	}

	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &c_array[i]);
	}

	for (int i = 1; i <= n; i++)
	{
		int first_step = i;
		int next_step = p_array[first_step];
		long long int step_num = 0;
		current_score = 0;

		while ((first_step != next_step) && (step_num < k))
		{
			current_score += c_array[next_step];
			step_num++;

			next_step = p_array[next_step];

			if (score < current_score)
			{
				score = current_score;
			}

			if ((first_step == next_step) && (step_num < k))
			{
				current_score += c_array[next_step];
				step_num++;
			}


			if (score < current_score)
			{
				score = current_score;
			}
		}


		if ((current_score > 0) && (step_num < k))
		{
			long long int round_scoure = 0;
			round_scoure = ((k - step_num) / step_num)*current_score;

			first_step = i;
			next_step = p_array[first_step];;

			for (long long int j = 0; j<((k%step_num) + step_num); j++)
			{
				round_scoure += c_array[next_step];
				next_step = p_array[next_step];

				if (round_scoure > score)
				{
					score = round_scoure;
				}
			}

		}

	}


	printf("%lld", score);

	return 0;
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX = 1000;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L

int main() {
	string S; cin >> S;
	int cnt = 0; int s_flg = 0;
	for (int ii = 0; ii < 3; ii++) {
		if (S[ii] == 'R') {
			if (s_flg == 1) {
				cnt = 1;
				s_flg = 0;
			} else {
				cnt++;
			}
		}
		else s_flg = 1;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <iostream>

#include <sstream>
#include <fstream>
#include <cmath>
#include <vector>


using namespace std;


int main( int argc , char ** argv ){
	
	long long a = 0 , b = 0 , x = 0;
	cin >> a >> b >> x;

	int p = 0;
	if(b%x == 0 ) p=1;

	// cout << ceil( ( (double)b/(double)x ) ) << " , ";
	// cout << ceil( ( (double)a/(double)x ) ) << endl;
	long long ans = ceil((long double)b/(long double)x ) - ceil( (long double)a/(long double)x ) + p;

	cout << ans << endl;
}



Measured memory_bytes: 384
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: usize = sc.read();
    let v: Vec<i32> = sc.vec(n);
    let mut result = 0;
    for left in 0..n + 1 {
        for right in (0..n + 1).rev() {
            let cnt = left + right;
            if cnt > k {
                continue;
            }
            if left >= 1 {
                if n - right <= left - 1 {
                    continue;
                }
            }
            let mut tmp = vec![];
            for i in 0..left {
                tmp.push(v[i]);
            }
            for i in (n - right..n).rev() {
                tmp.push(v[i]);
            }
            tmp.sort();
            let mut rest = k - cnt;
            for i in 0..tmp.len() {
                if rest <= 0 {
                    break;
                }
                if tmp[i] >= 0 {
                    break;
                }
                if tmp[i] < 0 {
                    tmp[i] = 0;
                    rest -= 1;
                }
            }
            result = std::cmp::max(result, tmp.iter().fold(0, |sum, x| sum + x));
        }
    }
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

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


Measured memory_bytes: 8572
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  uint16_t P, Q, R;
  cin >> P >> Q >> R;
  uint16_t res = P + Q + R;
  if (P > Q) {
    if (P > R) {
      res -= P;
    } else {
      res -= R;
    }
  } else {
    if (Q > R) {
      res -= Q;
    } else {
      res -= R;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}

int main(){
    int n;cin>>n;
    rep(i,n){
        REP(j,i+1,n){
            int k=i^j;
          ll ans;
            rep(l,n){
                if(k&1==1){
                    ans=l;
                    break;
                }
                k>>=1;
            }
            cout<<ans+1<<' ';
        }
        cout<<endl;
    }
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String b = sc.next();
        int answer = 0;
        for (int i = 3; i <= a; i++) {
            if (b.substring(i - 3, i).equals("ABC")) {
                answer++;
            } else if (b.equals("ABC")) {
                answer = 1;
            }
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], cnt[maxn], sum[maxn];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	} 
	long long ans = 0;
	for (int i = 1; i <= 1000; i++) sum[i] = sum[i - 1] + cnt[i];
	for (int i = 1; i <= 1000; i++) {
		for (int j = i + 1; j <= 1000; j++) {
			int l = j, r = min(1000, i + j - 1);
			ans += 1LL * cnt[i] * cnt[j] * (sum[r] - sum[l]);
		}
		for (int j = 1; j <= 1000; j++) {
			if (j == i || i * 2 <= j) continue;
			ans += 1LL * (cnt[i] * (cnt[i] - 1) / 2) * cnt[j];
		}
		ans += 1LL * cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) / 6;
	}
	cout << ans << endl;
	return 0;
}
/*
x + y > z
x + z > y
z + y > x

=>
z < x + y
z > max(x - y, y - x);
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=1e5+1;
const ll INF=4e15;
void solve()
{
	ll N,K;
	cin>>N>>K;
	ll h[maxn],dp[maxn];
	// dp[i]: denotes the minimum cost to reach ith position from
	// 		  1st position
	for(ll i=1;i<=N;i++)
	{
		cin>>h[i];
	}
	
	//Base Case
	dp[1]=0;	// minimum cost to stay in 1st position is 0
	dp[2]=abs(h[2]-h[1]);	// minimum cost to reach pos 2 from pos 1
	
	// Calculating dp[i]
	for(ll i=3;i<=N;i++)
	{
		dp[i]=INF;
		for(ll j=i-1;j>=1&&j>=i-K;j--)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
		// Frog can reach ith position from i-1 th pos or from
		// i-2 th pos or i-3 th pos ..... i-K th pos
		// Just take the best way of reaching ith pos.
	}
	cout<<dp[N]<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



Measured memory_bytes: 1792
from collections import defaultdict
from itertools import cycle
N = int(input())
S = []
P = []
for i in range(N):
    s,p = input().split()
    S.append(s)
    P.append(int(p))

dic = defaultdict(list)
for s,p in zip(S,P):
    dic[s].append(p)

for k in dic:
    dic[k].sort(reverse = True)

city = sorted(set(S))

SP = dict()
for i,s,p in zip(range(1,N+1),S,P):
    SP[(s,p)] = i
ans = []
for c in city:
    for po in dic[c]:
        ans.append((c,po))
for a in ans:
    print(SP[a])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    string a,b,c;
    cin >> a >> b >> c;
    bool ans = false;
    if (a.back() == b.front() && b.back() == c.front()) ans = true;
    CFYN(ans)

    return 0;
}

Measured memory_bytes: 256
li, ri = [0, 0, 0, 0], [0, 0, 0, 0]
while True:
    try:
        l, r = map(float, input().split())
    except:
        break
    
    if l < 0.2:
        li[3] += 1
    elif l < 0.6:
        li[2] += 1
    elif l < 1.1:
        li[1] += 1
    else:
        li[0] += 1
 
    if r < 0.2:
        ri[3] += 1
    elif r < 0.6:
        ri[2] += 1
    elif r < 1.1:
        ri[1] += 1
    else:
        ri[0] += 1

for l, r in zip(li, ri):
    print(l, r)


Measured memory_bytes: 5576
// D - Bouquet
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// a^n mod m を計算する(二分累乗法:O(logn))
ll modpow(ll a, ll n, ll m) {
	ll res = 1;
	while(n > 0){
		if(n & 1) res = res * a % m;
		a = a * a % m;
		n >>= 1;
	}
	return res;
}

// nCr mod m
ll nCr(ll n, ll r, ll m){
	ll a = 1, b = 1;
	for(ll i=0; i<r; ++i){
		a = a * (n-i) % m;
		b = b * (r-i) % m;
	}
	return a * modpow(b, m-2, m) % m;
}

int main(){
	ll MOD = 1000000007, N,A,B;
	cin>>N>>A>>B;
	ll ans = (nCr(N, A, MOD) + nCr(N, B, MOD)) % MOD;
	ans = (modpow(2, N, MOD) - 1 - ans) % MOD;
	if(ans < 0L) ans += MOD;
	cout<< ans <<endl;
}

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

int main(){
  int n,m,d;
  cin >> n >> m >> d;
  double ans=d>0?((2.0*(n-d))/n/n*(m-1.0)):(double)((m-1.0)/n);
  cout << setprecision(12) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}

int main() {
	ll a,b;
	cin >> a >> b;
	ll g = __gcd(a,b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int tyle[1401][1401];
ll dp[1401][1401];

int main() {
    

    ll h,w;
    cin >> h >> w;
    for (ll i=1;i<=h;i++){
        for (ll j=1;j<=w;j++){
            cin >> tyle[i][j];
        }
    }
    ll maxs = 0;
    for (ll i=1;i<=h;i++){
        for(ll j=1;j<=w;j++){
            if(tyle[i][j] == 1){
                dp[i][j] = 0;
            }else{
                dp[i][j] = min(dp[i-1][j], min(dp[i-1][j-1], dp[i][j-1])) + 1;
            }
            if(dp[i][j] > maxs){
                maxs = dp[i][j];
            }
        }
    }
    cout << maxs*maxs << endl;


}





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

using namespace std;
#define taskname "TEST"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 1e4 + 5;
const int mod = 1e9 + 7;
int n , a[17][17];
ll dp[1 << 17];
vector<int> bit[1 << 17];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    int cnt = 0;
    cin >> n;
    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j < n ; ++j)cin >> a[i][j];
    for(int i = 0  ; i < (1 << n) ; ++i)
    {
        for(int j = 0 ; j < n ; ++j)if((i >> j) & 1)bit[i].pb(j);
    }
    for(int i = 1 ; i < (1 << n) ; ++i)
    {
        for(int j = i ; j > 0 ; j = (j - 1) & i)
        {
            int sz = bit[j].size();
            ll add = 0;
            for(int t = 0 ; t < sz ; ++t)
                for(int k = 0 ; k < t ; ++k)
                    add += a[bit[j][t]][bit[j][k]];
//            if(i == 6)cout << dp[i ^ j] << " " << (i ^ j) << " " << j << " " << add << endl;
            dp[i] = max(dp[i],dp[i ^ j] + add);
        }
    }
    cout << dp[(1 << n) - 1];
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    double A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;
    int water = 0;
    int suger = 0;
    double ret = 0;
    for(int i = 0;i <= F / 100 / A;i++) {
        for(int j = 0;j <= (F - 100 * A * i) / 100 / B;j++) {
            int cnt = F - (i * 100 * A + j * 100 * B);
            for(int k = 0;k <= (cnt / C);k++) {
                for(int l = 0;l <= (cnt - k * C) / D;l++) {
                    if((i * 100 * A + j * 100 * B) / 100 * E >= k * C + l * D) {
                        if(i == 0 && j == 0 && k == 0 && l == 0) {
                            continue;
                        }
                        if((k * C + l * D) * 100 / (i * A + j * B + k * C + l * D) >= ret) {
                            water = i * 100 * A + j * 100 * B;
                            suger = k * C + l * D;
                            ret = (k * C + l * D) * 100  / (i * A + j * B + k * C + l * D);
                        }
                    }
                }
            }
        }
    }
    cout << water + suger << " " << suger << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) putchar(*(C + i));
	putchar(' ');
}

typedef tuple<int, int, int, int, int, int> TP;
const int K = 18;
const int KM = 1 << (K - 1);
pair<int, int> dat1[1 << K], dat2[1 << K];

pair<int, int> check1(int L, int R, int A, int l, int r) {
	if (L <= l && r <= R) return dat1[A];
	if (r <= L || R <= l) return mp(1e9, 0);
	return min(check1(L, R, A * 2, l, (l + r) / 2), check1(L, R, A * 2 + 1, (l + r) / 2, r));
}

inline pair<int, int> query1(int L, int R) {
	return check1(L, R, 1, 0, KM);
}

pair<int, int> check2(int L, int R, int A, int l, int r) {
	if (L <= l && r <= R) return dat2[A];
	if (r <= L || R <= l) return mp(1e9, 0);
	return min(check2(L, R, A * 2, l, (l + r) / 2), check2(L, R, A * 2 + 1, (l + r) / 2, r));
}

inline pair<int, int> query2(int L, int R) {
	return check2(L, R, 1, 0, KM);
}

int a[200001], b[200001], c[200001], d[200001], e[200001];
inline int keisan(int A, int B) {
	pair<int, int> p1, p2;
	if (A & 1) {
		p1 = query2(A / 2, B / 2);
		p2 = query1(p1.second / 2 + 1, B / 2 + 1);
	}
	else {
		p1 = query1(A / 2, B / 2 + 1);
		p2 = query2(p1.second / 2, B / 2 + 1);
	}
	*(a + p1.first) = p2.first;
	*(b + p1.first) = A;
	*(c + p1.first) = p1.second;
	*(d + p1.first) = p2.second;
	*(e + p1.first) = B;
	return p1.first;
}

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


	int N = getint();
	rep(i, N / 2) {
		int P = getint();
		dat1[i + KM] = mp(P, 2 * i);
		P = getint();
		dat2[i + KM] = mp(P, 2 * i + 1);
	}
	for (int i = KM - 1; i >= 1; i--) {
		dat1[i] = min(dat1[2 * i], dat1[2 * i + 1]);
		dat2[i] = min(dat2[2 * i], dat2[2 * i + 1]);
	}

	priority_queue<int, vector<int>, greater<int>> que;
	que.push(keisan(0, N - 1));

	while (que.size()) {
		int Q = que.top();
		que.pop();
		putint(Q);
		putint(*(a + Q));
		if (*(b + Q) != *(c + Q)) {
			que.push(keisan(*(b + Q), *(c + Q) - 1));
		}
		if (*(c + Q) + 1 != *(d + Q)) {
			que.push(keisan(*(c + Q) + 1, *(d + Q) - 1));
		}
		if (*(d + Q) != *(e + Q)) {
			que.push(keisan(*(d + Q) + 1, *(e + Q)));
		}
	}

	Would you please return 0;
}

Measured memory_bytes: 9724
#include <bits/stdc++.h>
#define MOD 1000000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
inline ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll char_to_ll(char c) { return (int)(c - '0'); }
inline ll string_to_ll(string s) { return atoi(s.c_str()); }
inline bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    ll A, B, C, K, ans = 0;
    cin >> A >> B >> C >> K;

    if(A >= K){
        ans += K;
        cout << ans << endl;
        return 0;
    }else{
        ans += A;
        K -= A;
    }

    if(B >= K){
        cout << ans << endl;
        return 0;
    }else{
        K -= B;
    }

    if(C >= K){
        ans -= K;
        cout << ans << endl;
        return 0;
    }else{
        K -= C;
    }


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
 
int main(){
  long long n,ans=1;
  scanf("%lld",&n);
  long long arr[n+5],maks=1000000000000000000;
  for(long long i=1;i<=n;i++){
      scanf("%lld",&arr[i]);}
  
  for(int i=1;i<=n;i++){
    if(arr[i]==0){
        printf("0");
        return 0;
    }
  }
  
  for(long long i=1;i<=n;i++){
    if(maks/ans<arr[i]){
        printf("-1");
        return 0;
    }
    
    ans*=arr[i];
  }
  
  printf("%lld",ans);
}

Measured memory_bytes: 2488
#include<iostream>
using namespace std;
int a,b,k,i;
int main()
{ 
  cin >> a >> b >> k;
  if(b-a<2*k-1){
    for(i=a;i<=b;i++){printf("%d\n",i);
                 }
  }else{
    for(i=a;i<a+k;i++){printf("%d\n",i);
                      }
    for(i=b-k+1;i<=b;i++){printf("%d\n",i);
                         }
  }
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    int K,X;
    cin >>K>>X;

    //-----------------------------------
    int  ansm = max(-100000,X-K+1),ansmax=min(100000,X+K-1);

    cout << ansm;
    for(int i=ansm+1; i<=ansmax;i++){
        cout <<" "<< i ;
    }
    cout<<endl;
    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <utility>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstring>
using namespace std;
using ll = long long;
using P = pair<int, int>;

constexpr int lim = 500;

int h, w;
int grid[lim+1][lim+1];
bool vis[lim+1][lim+1];

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

bool inGrid(int ny, int nx){
  return 0 < ny && ny <= h && 0 < nx && nx <= w;
}

int main(){
  cin >> h >> w;
  for(int y=1; y<=h; y++){
    for(int x=1; x<=w; x++) cin >> grid[y][x];
  }

  vector<P> xx, yy;
  for(int y=1; y<=h; y++){
    if(y % 2){
      for(int x=1; x<=w; x++){
        if(grid[y][x] % 2){
          if(inGrid(y, x+1)){
            grid[y][x]--;
            grid[y][x+1]++;
            xx.emplace_back(x, x+1);
            yy.emplace_back(y, y);
          } 
          else if(inGrid(y+1, x)){
            grid[y][x]--;
            grid[y+1][x]++;
            xx.emplace_back(x, x);
            yy.emplace_back(y, y+1);
          }
        }
      }
    }
    else{
      for(int x=w; x>0; x--){
        if(grid[y][x] % 2){
          if(inGrid(y, x-1)){
            grid[y][x]--;
            grid[y][x-1]++;
            xx.emplace_back(x, x-1);
            yy.emplace_back(y, y);
          }
          else if(inGrid(y+1, x)){
            grid[y][x]--;
            grid[y+1][x]++;
            xx.emplace_back(x, x);
            yy.emplace_back(y, y+1);
          }
        }
      }
    }
  }
  
  cout << xx.size() << endl;
  for(int i=0; i<xx.size(); i++){
    cout << yy[i].first << " " << xx[i].first << " " << yy[i].second << " " << xx[i].second << endl;
  }
  return 0;
}


Measured memory_bytes: 5228
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, l, mi = inf, cnt,ans;
signed main() {
	cin >> n >> l;
	for (int i = l; i <= l + n - 1; i++) {
		if (mi > abs(i)) {
			mi = abs(i); cnt = i;
		}
	}
	for (int i = l; i <= l + n - 1; i++) {
		if (i != cnt) {
			ans += i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def checkA(s):
  if s[:2] == ">'" and s[-1] == "~":
    body = s[2:-1]
    if len(body) >= 3 and body.count("#") == 1 and body.index("#") == len(body) // 2 and body.count("=") == len(body) - 1:
      return True
    else:
      return False
  else:
    return False

def checkB(s):
  if s[:2] == ">^" and s[-2:] == "~~":
    body = s[2:-2]
    if len(body) > 0 and len(body) % 2 == 0:
      for i in range(0, len(body), 2):
        if body[i:i + 2] != "Q=":
          return False
      else:
        return True
    else:
      return False
  else:
    return False

n = int(input())
for _ in range(n):
  s = input()
  if len(s) <= 5:
    print("NA")
  else:
    if checkA(s):
      print("A")
    elif checkB(s):
      print("B")
    else:
      print("NA")


Measured memory_bytes: 5624
N,Q=map(int,input().split())
tree={}
for i in range(N-1):
  a,b=map(int,input().split())
  if (a-1) in tree:
    tree[a-1].append(b-1)
  else:
    tree[a-1]=[b-1]
  if (b-1) in tree:
    tree[b-1].append(a-1)
  else:
    tree[b-1]=[a-1]

point=[0]*N

for i in range(Q):
  p,x=map(int,input().split())
  point[p-1]+=x

ans=[0]*N
stack=[]
stack.append([0,0,-1])
while len(stack)>0:
  nodes=stack.pop()
  node=nodes[0]
  sump=nodes[1]
  parent=nodes[2]
  sump=sump+point[node]
  ans[node]=sump
  if node in tree:
      childs=tree[node]
      for child in childs:
        if child!=parent:
          stack.append([child,sump,node])

print(*ans)

Measured memory_bytes: 81204
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long D;
vector<long> c(26);
vector<vector<long>> s(365,vector<long>(26));
vector<long> t(365);

void INPUT(){
  cin >> D;
  rep(i,26) cin >> c.at(i);
  rep(i,D){
    rep(j,26) cin >> s.at(i).at(j);
  }
}

long greedy(){
  vector<long> lastday(26,-1);

  long ans = 0;
  rep(i,D){
    vector<long> tmpscore(26,ans);
    rep(j,26){
      tmpscore.at(j) += s.at(i).at(j);
      rep(k,26){
        if(j != k){
          tmpscore.at(j) -= (i - lastday.at(k))*c.at(k);
        }
      }
    }
    long day = 0;
    long maxi = tmpscore.at(0);
    rep(j,26){
      if(tmpscore.at(j) > maxi){
        maxi = tmpscore.at(j);
        day = j;
      }
    }
    ans = maxi;
    //cout << day+1 << endl;
    t.at(i) = day;
    lastday.at(day) = i;
  }
  return ans;
}

long calc(){
  vector<long> lastday(26,-1);
  long ans = 0;
  rep(i,D){
    long tt = t.at(i);
    ans += s.at(i).at(tt);
    lastday.at(tt) = i;
    rep(j,26){
      ans -= (i - lastday.at(j)) * c.at(j);
    }
    //cout << ans << endl;
  }
  return ans;
}

void OUTPUT(){
  rep(i,D){
    cout << t.at(i)+1 << endl;
  }
}

int main(){
  INPUT();
  long now = greedy();
  srand(time(NULL));
  rep(i,500){
    long d = rand() % D;
    long q = rand() % 26;
    long prev_q = t.at(d);
    t.at(d) = q;
    long res = calc();
    if(res > now){
      now = res;
    }else{
      t.at(d) = prev_q;
    }
  }
  OUTPUT();
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

// https://betrue12.hateblo.jp/entry/2020/02/17/020628

ll dp[1001001][2]; // i桁まで見て、これまでピッタリ払っている多くorはらっている、場合に発生する支払い・お釣りの最小合計枚数
// j=0 ピッタリ払っている状態からはお釣りは発生しない。自身が払う枚数だけ遷移先に加算される
// j=1 上位桁で1枚多く払っている状態からは何枚お釣りを受け取るかのみを考慮する
// (少し考えればわかるが、上位桁で1枚多く払っているのならその桁で自身が1枚払う必要はない)

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  string s; cin>>s;
  s='0'+s;
  ll n=s.size();
  
  rep(i,n+1) rep(j,2) dp[i][j]=LINF;
  dp[0][0]=0;
  rep(i,n){
    ll now=s[i]-'0';
    chmin(dp[i+1][0],dp[i][0]+now);      // ピッタリ払う
    chmin(dp[i+1][1],dp[i][0]+now+1);    // 1枚多く支払うので+1
    chmin(dp[i+1][0],dp[i][1]+10-now);   // 上位桁が1枚多い状態から払わない => お釣りとして10-nowもらう
    // NOTE: この一行がない場合
    // 例として95を考える
    // 100円払って、5円お釣りをもらう、1+5=6が最小
    // この一行がないと、100の位で1枚払い、10の桁ではお釣りを貰わず余りを1の位に補填する、という場合を考慮できない
    // 上記の場合が抜けると、105円払って10円貰う場合、6+1=7がが最小となり辻褄が合わない
    chmin(dp[i+1][1],dp[i][1]+10-now-1); // 上位桁が1枚多い状態から払わないが、以降の桁のために1枚受け取らず残しておく => お釣りとして10-now-1もらう
  }
  
  cout<<dp[n][0]<<endl;
  
}

Measured memory_bytes: 16968
import heapq
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([c, b - 1])
    G[b - 1].append([c, a - 1])
Q, K = map(int, input().split())

def dijkstra(s, N, G):
    d = [float('inf')] * N
    d[s] = 0
    hq = [[0, s]]
    heapq.heapify(hq)
    while len(hq) > 0:
        v, i = heapq.heappop(hq)
        if d[i] < v:
            continue
        for c, j in G[i]:
            if d[j] > d[i] + c:
                d[j] = d[i] + c
                heapq.heappush(hq, [d[j], j])
    return d

D = dijkstra(K - 1, N, G)

dist = [0] * Q
for i in range(Q):
    x, y = map(int, input().split())
    dist[i] = D[x - 1] + D[y - 1]

for d in dist:
    print(d)

Measured memory_bytes: 55848
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))




n = in_int()

a = in_list()

m = {}
max_1 = 0
val_1 = -1
max_2 = 0
val_2 = -1
for xx in a:
    if xx in m:
        m[xx]+=1
    else:
        m[xx] = 1


ans = 0

for xx in m:
    tt = m[xx]
    ans += tt*(tt-1)//2



for xx in a:
    tt = m[xx]

    print(ans - (tt)*(tt-1)//2 + (tt-1)*(tt-2)//2)

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	if(s == "ABC") {
		cout << "ARC\n";
	} else {
		cout << "ABC\n";
	}

	return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  std::vector<long long> B(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    B[i] = A[i];
  }

  sort(all(B));
  rep(i, 0, N) {
    if (B[N - 1] != A[i]) {
      cout << B[N - 1] << endl;
      continue;
    }

    cout << B[N - 2] << endl;
  }
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 4736
n,k=map(int,input().split())
mod=10**9+7
edge=[[] for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)
fra=[1]*(k+2)
inv=[1]*(k+2)
t=1
for i in range(1,k+2):
    t*=i
    t%=mod
    fra[i]=t
t=pow(fra[k+1],mod-2,mod)
for i in range(k+1,0,-1):
    inv[i]=t
    t*=i
    t%=mod
if max([len(i) for i in edge])+1>k:
    print(0)
    quit()
ans=fra[k]*inv[k-len(edge[1])-1]%mod
q=[1]
c=[0 for i in range(n+1)]
c[1]=1
while len(q)>0:
    t=q.pop()
    for i in edge[t]:
        if c[i]==0:
            ans*=fra[k-2]*inv[k-2-(len(edge[i])-1)]%mod
            ans%=mod
            q.append(i)
            c[i]=1
print(ans)

Measured memory_bytes: 73248