akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}

class DStaticSushi {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N, C;
    cin >> N >> C;
    vector<int> x(N);
    vector<int> v(N);
    int ans = 0;
    rep(i, N) cin >> x[i] >> v[i];
    vector<int> cum_sum(N + 1);
    vector<int> cum_sum_inv(N + 1);
    rep(i, N) {
      cum_sum[i + 1] = v[i];
      cum_sum[i + 1] += cum_sum[i];
      cum_sum_inv[i + 1] = v[v.size() - 1 - i];
      cum_sum_inv[i + 1] += cum_sum_inv[i];
    }
    rep(i, N) {
      ans = max(ans, cum_sum[i + 1] - x[i]);
      ans = max(ans, cum_sum_inv[i + 1] - (C - x[N - 1 - i]));
      cum_sum[i + 1] -= x[i];
      cum_sum_inv[i + 1] -= (C - x[N - 1 - i]);
    }
    map<int, vector<int>> to;
    map<int, vector<int>> to2;
    map<int, vector<int>> inv;
    map<int, vector<int>> inv2;
    rep(i, N) to[cum_sum[i + 1]].emplace_back(i);
    rep(i, N) to2[cum_sum[i + 1] - x[i]].emplace_back(i);
    rep(i, N - 1) {
      if (to.count(cum_sum[N - i])) {
        if (to[cum_sum[N - i]].size() > 1) {
          to[cum_sum[N - i]].pop_back();
        } else {
          to.erase(cum_sum[N - i]);
        }
      }
      if (to2.count(cum_sum[N - i] - x[N - i - 1])) {
        if (to2[cum_sum[N - i] - x[N - i - 1]].size() > 1) {
          to2[cum_sum[N - i] - x[N - i - 1]].pop_back();
        } else {
          to2.erase(cum_sum[N - i] - x[N - i - 1]);
        }
      }
      inv[cum_sum_inv[i + 1]].emplace_back(i);
      inv2[cum_sum_inv[i + 1] - (C - x[N - 1 - i])].emplace_back(i);
      ans = max(ans, to.rbegin()->first + inv2.rbegin()->first);
      ans = max(ans, to2.rbegin()->first + inv.rbegin()->first);
    }
    cout << ans << endl;
  }
};


signed main() {
  DStaticSushi solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int a,b,c;

int main(void){
	cin >> a >> b >> c;
	bool res = false;
	if(a == b and a != c) res = true;
	if(a == c and a != b) res = true;
	if(b == c and a != b) res = true;

	cout << (res ? "Yes" : "No") << '\n';

	return 0;
}

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

   typedef long long ll;
   typedef pair<ll, ll> P;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

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

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

int main(){
   string S, T; cin >> S >> T;
   bool flag = false;
   REP(i, S.size()){
      string U = S.substr(i, S.size() - i) + S.substr(0, i);
      if (U == T) flag = true;
   }
   if (flag) cout << "Yes\n";
   else cout << "No\n";
}

Measured memory_bytes: 256
'use strict'

function main(input) {
  input = input
    .trim()
    .split(' ')
    .map(Number)
  // .split('\n')
  // .map(v => v.split(' ').map(Number))

  const [a, b] = input
  const ans = Math.max(...[a + b, a - b, a * b])

  console.log('%d', ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    char digit[1000];
    int i;
    scanf("%s",digit);
    int len=strlen(digit);
    int flag=0;
    for(i=0;i+1<len;i++)
    {
        if(digit[i]==digit[i+1])
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        printf("Bad\n");
    }
    else
    {
        printf("Good\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)



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

	string S;
	cin >> S;
	if (S == "Sunny")puts("Cloudy");
	else if (S == "Rainy")puts("Sunny");
	else puts("Rainy");
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  def searchPartialUnbalanced(l: List[Char]): (Int, Int) = {
    def go(list: List[(Char, Int)]): (Int, Int) = {
      list match {
        case Nil                                 ⇒ (-1, -1)
        case (a, ai) :: (b, bi) :: t if (a == b) ⇒ (ai + 1, bi + 1)
        case (a, ai) :: _ :: (b, bi) :: t if (a == b) ⇒
          (ai + 1, bi + 1)
        case _ :: t ⇒ go(t)

      }
    }
    go(l.zipWithIndex)
  }
  val (from, to) = searchPartialUnbalanced(scala.io.StdIn.readLine.toList)
  println(from + " " + to)
}

Measured memory_bytes: 36368
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const int MAX_N=10001;

int calc(int n){
  int res=0;
  if(n%2){
    return 0;
  }else{
    return calc(n/2)+1;
  }
}

int main(){
  int A[3],a[3];
  cin >> A[0] >> A[1] >> A[2] ;
  if(A[0]%2 && A[1]%2 && A[2]%2){
    cout << "0" << endl;
    return 0;
  }
  int ans=-1;
  rep(i,30){
    //cout << A[0]<<" "<<A[1]<<" "<<A[2] << endl;
    int a[3];
    rep(j,3) a[j]=A[j]>>i;
    if((a[0]&1 && a[1]&1 && a[2]&1)||((~a[0]&1)&&(~a[1]&1)&&(~a[2]&1))){
      continue;
    }else{
      ans=i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second

const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}

int main() { _
  string s; cin >> s;
  if (s.size() & 1) cout << "No" << endl;
  else {
    bool fail = false;
    for (int i = 0; i < s.size(); i += 2) {
      if (s[i] != 'h' || s[i+1] != 'i') {
        fail = true;
        break;
      }
    }
    if (fail) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

const int N = 1e5 + 1000;
vector<vector<int>> g(N);
vector<bool> visited(N, false);
vector<int> order;
void dfs(int v) {
	visited[v] = true;
	for (auto &u : g[v]) {
		if (!visited[u]) {
			dfs(u);
		}
	}
	order.push_back(v);
}
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
	}
	for (int i = 1; i <= n; i++) {
		if (!visited[i]) {
			dfs(i);
		}
	}
	reverse(order.begin(), order.end());
	vector<int> ans(n + 1, 0);
	for (auto &v : order) {
		for (auto &u : g[v]) {
			ans[u] = max(ans[u], ans[v] + 1);
		}
	}
	cout << *max_element(ans.begin(), ans.end()) << "\n";
}



Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n][3];
    for(int i=0;i<n;i++)
     for(int j=0;j<3;j++)
      cin>>a[i][j];
    for(int i=1;i<n;i++)
    {
        a[i][0]+=max(a[i-1][1],a[i-1][2]);
        a[i][1]+=max(a[i-1][0],a[i-1][2]);
        a[i][2]+=max(a[i-1][0],a[i-1][1]);
    }
    cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]))<<endl;
}

Measured memory_bytes: 4712
n = int(input())
a = [int(input()) for i in range(n)]
a2 = sorted(a)
ma = a2[-1]
se = a2[-2]
result = []
for i in range(n):
    if a[i] == ma:
        result.append(se)
    else:
        result.append(ma)
for j in range(n):
    print(result[j])

Measured memory_bytes: 16160
//47行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b);
template<class T> bool chmax(T& a,T b);
template<class T> void debugger(vector<T>& a);
template<class T> void debugger(vector<vector<T>>& a);
///////////////////////////////////////////////////////////

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    string s;cin >> s;
    if(s[1] != s[0] or s[1] != s[2])cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

///////////////////////////////////////////////////////////
template<class T> bool chmin(T& a,T b){
    if(a > b){a = b;return true;}else return false;
}
template<class T> bool chmax(T& a,T b){
    if(a < b){a = b;return true;}else return false;
}
template<class T> void debugger(vector<T>& a){
    cerr << "{";
    for(int i = 0;i < a.size();i++){
        if(i == 0)cerr << a[i];
        else cerr << "," << a[i];
    }
    cerr << "}" << '\n';
    return;
}
template<class T> void debugger(vector<vector<T>>& a){
    int n = a.size();
    int m = a[0].size();
    cerr << "__|";
    for(int i = 0;i < m;i++){
        cerr << setw(5) << i;
    }
    cerr << '\n';
    for(int i = 0;i < n;i++){
        cerr << setw(3) << i;
        for(int j = 0;j < m;j++){
            if(a[i][j] >= 100000)cout << setw(5) << "INF";
            else cerr << setw(5) << a[i][j];
        }
        cerr << '\n';
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
int N,K;


int main() {
   cin>>N>>K;
  double ans=0;
  if(N>K){
    ans+=(double)(N-K)/N;
  }
  for(int i=1; i<=N;i++){
    double a=1/(double)N;
    int c=i;
    if(i<=K){
    while(c<K){
      a/=2;
      c*=2;
    }
    ans+=a;
    }
  }
  cout<<fixed<<setprecision(10);
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#!/usr/local/bin/python3

import fractions

def solve(a,b,c,d):
	a = a - 1
	l = c * d // fractions.gcd(c, d)
	r1 = a - (a // c + a // d - a // l)
	r2 = b - (b // c + b // d - b // l)
	return (r2 - r1)


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


Measured memory_bytes: 5344
#include<stdio.h>
#include<string.h>
int main(){
  int i,j;
  scanf("%d",&j);
  char x[100],y[100],z[200];
  scanf("%s %s",x,y);
  for(i=0;i<j;i++){
    printf("%c%c",x[i],y[i]);
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = taskB

  def taskA(): Unit = {
    val r = sc.nextInt
    println(if (r < 1200) "ABC" else if (r < 2800) "ARC" else "AGC")
  }

  def taskB(): Unit = {
    val s = sc.next
    if (s.filter(_.isUpper) == "AC" && s(0) == 'A' && s(1) != 'C' && s(s.length - 1).isLower) {
      println("AC")
    } else {
      println("WA")
    }
  }
}


Measured memory_bytes: 25904
N = int(input())
table = [[0] * 10 for _ in range(10)]

for i in range(N):
  N_ = str(i+1)
  s = int(N_[0])
  e = int(N_[-1])
  table[s][e] += 1

sum = 0
for i in range(1,10):
  for j in range(1,10):
    sum += table[i][j] * table[j][i]

print(sum)

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

#define ll long long
#define ld double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define setpr(pp) fixed<<setprecision(pp)
#define FOR(I,N) for(I=0;I<N;++I)
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod	%1000000007
#define pi 3.141592653
#define NL -5000000

int main()
{	IOS;
	char ch;
	cin>>ch;
	if(ch>='a')
		cout<<'a';
	else
		cout<<'A';
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  ll X, K, D; cin >> X >> K >> D;
  ll ksub = X / D;
  ll dt = X - ksub * D;
  if (X>=0){
    if( K < ksub) {cout << X-K*D << endl; return 0;} 
    if((K-ksub)%2 == 0){cout << dt << endl; return 0;}
    else {cout << abs(dt-D) << endl; return 0;}
  }   
  else{
    if( K < abs(ksub)) {cout << abs(X+K*D) << endl; return 0;} 
    if((K-ksub)%2 == 0){cout << abs(dt) << endl; return 0;}
    else {cout << abs(dt+D) << endl; return 0;}
  }
  return 0;
}


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

int main() {
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    int xs[n];
    int ys[m];
    for(int i=0;i<n;i++){
        cin >> xs[i];
    }
    for(int i=0;i<m;i++){
        cin >> ys[i];
    }
    bool ans = false;
    for(int z=x+1;z<=y;z++){
        bool xloop_flag = true;
        for(int i=0;i<n;i++) {
            if(xs[i] >= z) {
                xloop_flag = false;
            }
        }
        bool yloop_flag = true;
        for(int j=0;j<m;j++){
            if(ys[j] < z) {
                yloop_flag = false;
            }
        }
        if(xloop_flag && yloop_flag){
            ans = true;
            break;
        }
    }

    if(ans){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }

    return 0;
}

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> T(N);
    for(ll i = 0; i < N; i++)
    {
        cin >> T[i];
    }
    sort(T.begin(),T.end());

    for(ll i = 0; i < N-1; i++)
    {
        ll a,b;
        if(T[i] < T[i+1])
        {
            a = T[i+1];
            b = T[i];
        }
        else
        {
            a = T[i];
            b = T[i+1];
        }
        ll r = a % b;
        while(r != 0)
        {
            a = b;
            b = r;
            r = a % b;
        }
        T[i+1] = T[i] / b * T[i+1];
        //cout << T[i+1] << endl;
    }
    cout << T[N-1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int H = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		String c[][] = new String[H][W];
		for(int i = 0; i < H; i++) {
			String temp = sc.next();
			for(int j = 0; j < W; j++) {
				c[i][j] = temp.substring(j, j + 1);
			}
		}
		int ans = 0;
		for (int i = 0; i < (Math.pow(2, H)); i++) {
			String c1[][] = new String[H][W];
			for(int a = 0; a < H; a++) {
				c1[a] = c[a].clone();
			}
			for (int j = 0; j < H; j++) {
				if ((1&i>>j) == 1) {
					for(int a = 0; a < W; a++) {
						c1[j][a] = "$";
					}
				}
			}
			for (int k = 0; k < (Math.pow(2, W)); k++) {
				String c2[][] = new String[H][W];
				for(int a = 0; a < H; a++) {
					c2[a] = c1[a].clone();
				}
				for (int l = 0; l < W; l++) {
					if ((1&k>>l) == 1) {
						for(int a = 0; a < H; a++) {
							c2[a][l] = "$";
						}
					}
				}
				int cnt = 0;
				for(int y = 0; y < H; y++) {
					for(int x = 0; x < W; x++) {
						if(c2[y][x].equals("#")) {
							cnt++;
						}
					}
				}
				if(cnt == K) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 39872
N, *H = map(int, open(0).read().split())
cnt = 0
for i in range(N - 1):
    if H[i + 1] - H[i] < -1:
        print('No')
        break
    elif H[i + 1] - H[i] == -1:
        cnt += 1
    elif H[i + 1] - H[i] == 0:
        pass
    else:
        cnt = 0
        
    if cnt > 1:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 71228
n = input()
As = list(map(int,input().split()))

prev_A = As[0]
total_step_hight = 0
for i in range(1,len(As)):
    if  As[i-1] > As[i]:
        total_step_hight += As[i-1] - As[i]
        As[i] = As[i] + (As[i-1] - As[i])

print(total_step_hight)


Measured memory_bytes: 32300
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <unordered_map>

#define NUM 3200

using namespace std;
#define ASCII 48
int main() {
	int in;
	std::string s;
	cin >> in;
	cin >> s;

	if (in >= NUM) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}
}



Measured memory_bytes: 256
from bisect import bisect_left

D = int(input())
C = [0]+list(map(int, input().split()))

S = [0]+[[0] + list(map(int, input().split())) for _ in range(D)]

contest = [[0] for _ in range(27)]

#SL:満足度、sch：スケジュール
SL, sch = 0, [0]

#tの日程でコンテストを行った時の満足度を計算
for d in range(1, D+1):
    t = int(input())
    sch.append(t)
    #コンテストの開催日時を記録
    contest[t].append(d)
    SL += S[d][t]

    for i in range(1, 27):
        SL -= C[i]*(d-contest[i][-1])

for i in range(1, 27):
    contest[i].append(D+1)

# print("contest", contest)
# print("sch", sch)
# print(S)
M = int(input())
for i in range(M):
    d, q = map(int, input().split())
    SL += S[d][q]-S[d][sch[d]]

    # print("1", contest[sch[d]])
    ind = bisect_left(contest[sch[d]], d)
    # print("2", ind)
    k = d-contest[sch[d]][ind-1]
    l = contest[sch[d]][ind+1]-d
    SL -= C[sch[d]]*k*l
    del contest[sch[d]][ind]

    ind = bisect_left(contest[q], d)
    contest[q].insert(ind, d)
    k = d-contest[q][ind-1]
    l = contest[q][ind+1]-d
    SL += C[q]*k*l
    sch[d] = q
    print(SL)

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  fio();
  vi a(2), b(2);
  int n;
  cin >> n;
  cin >> a[0] >> a[1] >> b[0] >> b[1];
  a[0]--; a[1]--; b[0]--; b[1]--;
  string s;
  cin >> s;
  
  rep (p, 2) {
    int u = a[p], v = b[p];
    int mi = min(u, v), ma = max(u, v);
    int cnt = 0;
    for (int i = mi; i <= ma; i++) {
      if (s[i] == '.') cnt = 0;
      else cnt++;
      if (cnt >= 2) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  bool gya = false;
  if (b[1] < b[0]) gya = true;

  if (!gya) {
    cout << "Yes" << endl;
    return 0;
  }
  
  int now = a[1];
  while (now < b[1]) {
    if (now != 0 && s[now - 1] == '.' && s[now + 1] == '.') {
      gya = false;
    }
    if (s[now + 1] == '.') {
      now += 1;
    }
    else {
      now += 2;
    }
  }

  if (gya) {
    if (now != 0 && s[now - 1] == '.' && s[now + 1] == '.') {
      gya = false;
    }
  }

  if (!gya) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 592
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)
	b := make([]int, N)
	for i := 0; i < N; i++ {
		b[i] = -1
	}
	for _, ai := range A {
		l, r := -1, N
		for r-l > 1 {
			c := (l + r) / 2
			if ai > b[c] {
				r = c
			} else {
				l = c
			}
		}
		b[r] = ai
	}
	fmt.Println(sort.Search(N, func(i int) bool { return b[i] == -1 }))
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 5108
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define mp make_pair
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define forn(i,n) for(ll i=0 ; i<n ; i++)
#define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ub upper_bound
#define pb push_back
#define mod 1000000007
using namespace std;

ll ipow(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    } 
    return result; 
} 

int main(){
	fio
	unordered_map<int,int>m;
	int n;
	cin>>n;
	int a[n];
	int flag=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	m[a[i]]++;
	}
	for(auto x : m){
		if(x.second>1){
			
			flag=1;
			break;
		}
	}
	if(flag==1){
		cout<<"NO"<<endl;
	}
	else
	cout<<"YES"<<endl;
	
return 0;
}

Measured memory_bytes: 9288
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define scan(n) scanf("%lld",&n)
#define scan2(a,b) scanf("%lld %lld",&a,&b)
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define print(n) printf("%lld\n",n)
#define scanS(s) scanf("%s",&s)
#define printS(s) printf("%s",s)

#define ff first
#define ss second
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define repr(i,a) for(i = a ; i >= 0 ; i--)
#define REP(i,a,b) for(i = a ; i <= b ; i++)
#define REPR(i,a,b) for(i = a ; i >= b ; i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define pb push_back
#define popb pop_back

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

void solve() {
    lli i, n, k, ans = 0;
    cin >> n >> k;
    if (k % 2) {
        ans = sqr(n / k) * (n / k);
    } else {
        lli cnt1 = 0, cnt2 = 0;
        for (i = k / 2; i <= n; i += k / 2) {
            if(i % k == k / 2)
                cnt1++;
            if(i % k == 0)
                cnt2++;
            ans = sqr(cnt1) * cnt1 + sqr(cnt2) * cnt2;
        }
    }
    cout << ans << endl;
}

int main()
{
    opt;
    lli t = 1;
    //cin >> t;

    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll M,K;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>M>>K;
    if(K>=(1<<M)) cout <<-1<<"\n";
    else if(M==1){
        if(K==0) cout <<0<<" "<<0<<" "<<1<<" "<<1<<"\n";
        else cout <<-1<<"\n";
    }
    else{
        rep(i,0,K) cout <<i<<" ";
        rep(i,K+1,1<<M) cout <<i<<" ";
        cout <<K<<" ";
        rer(i,1<<M,K+1) cout <<i<<" ";
        rer(i,K,0) cout <<i<<" ";
        cout <<K<<" ";
        cout <<"\n";
    }
}

Measured memory_bytes: 1792
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<bitset>
#include <cstdio>
#include <cmath>

using namespace std;

typedef long long ll;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

int main(){
    int N,M;
    cin>>N>>M;
    cout<<(N+M)/2<<endl;
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

class unionfind {
	vector<int> par, rank;

public:
	void init(int n) {
		par.resize(n);
		rank.resize(n);

		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return ;

		if (rank[x] < rank[y]) par[x] = y;
		else {
			par[y] = x;
			if (rank[x] == rank[y]) ++rank[x];
		}
	}

	bool same(int x, int y) { return (find(x) == find(y)); }
} uf;

const ll MOD = 998244353;
const int maxn = 1600;
const int MX = TEN(6) * 5;

int st[maxn][maxn];
V<int> g[maxn];
ll p2[MX];

int main() {
	p2[0] = 1;
	for (int i = 1; i < MX; ++i) {
		p2[i] = p2[i-1] * 2 % MOD;
	}

	memset(st, -1, sizeof(st));
	int N; cin >> N;
	bool ng = 0;

	for (int i = 1; i < N; ++i) {
		string s; cin >> s;

		for (int j = 1; j < N; ++j) {
			int c = -1;
			if (s[j-1] == 'o') {
				c = 1;
			} else if (s[j-1] == 'x') {
				c = 0;
			}
			int ni = i, nj = j;
			if (ni + nj >= N) {
				ni = N - ni, nj = N - nj;
			}
			if (ni < nj) swap(ni, nj);
			if (st[ni][nj] != -1 && c != -1 && st[ni][nj] != c) {
				ng = 1;
			}
			if (c != -1) {
				st[ni][nj] = c;
			}
		}
	}
	if (ng) {
		puts("0");
		return 0;
	}

	uf.init(N + 1);
	V<int> deg(N + 1);

	for (int i = 1; i < N; ++i) {
		for (int j = 1; j < N; ++j) {
			int p = i - j, q = i + j;
			if (p >= 0 && p <= N && q >= 0 && q <= N) {
				if (st[i][j] == -1) {
					uf.unite(p, q);
					g[p].pb(q);
					g[q].pb(p);
				} else if (st[i][j] == 1) {
					deg[p] ^= 1;
					deg[q] ^= 1;
				}
			}
		}
	}

	V<int> nume(maxn), pr(maxn), cmp(maxn);

	for (int i = 0; i <= N; ++i) {
		int v = uf.find(i);
		++cmp[v];
		pr[v] ^= deg[i];
		for (auto to : g[i]) {
			++nume[v];
		}
	}

	set<int> us;
	ll ans = 1;

	for (int i = 0; i <= N; ++i) {
		int v = uf.find(i);
		if (us.count(v)) continue;
		us.insert(v);

		int num = (i & 1) ? (N + 1) / 2 : N / 2 + 1;
		int r = nume[v] / 2;
		if (num % 2 == 1) {
			if (pr[v]) {
				puts("0");
				return 0;
			}
			r -= cmp[v] - 1;
		}
		ans = ans * p2[r] % MOD;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 55808
local mmi, mma = math.min, math.max
local n, m, k = io.read("*n", "*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local asum = {a[1]}
for i = 2, n do
  asum[i] = asum[i - 1] + a[i]
end
local b = {}
for i = 1, m do
  b[i] = io.read("*n")
end
local bsum = {b[1]}
for i = 2, m do
  bsum[i] = bsum[i - 1] + b[i]
end
local blim = m
local ret = 0
for i = 0, n do
  local az = i == 0 and 0 or asum[i]
  if k < az then break end
  while 0 < blim and k < az + bsum[blim] do
    blim = blim - 1
  end
  ret = mma(ret, i + blim)
end
print(ret)


Measured memory_bytes: 18672
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int n, m;
int a[100], x[100];


int main() {
  cin >> n;
  rep(i, n) cin >> x[i];
  cin >> m;
  rep(i, m) cin >> a[i];

  rep(i, m) {
    int s = a[i] - 1;
    bool f = 1;
    REP(j, s + 1, n) {
      if(x[s] == x[j] - 1) {
        f = 0;
      }
    }
    if(f && x[s] != 2019) x[s]++;
  }

  rep(i, n) {
    cout << x[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] list = new long[5];
		for(int i = 0; i < 5; i++) {
			list[i] = 0;
		}
		for(int i = 0; i < n; i++) {
			String s = sc.next();
			if(s.charAt(0) == 'M')
				list[0]++;
			else if(s.charAt(0) == 'A')
				list[1]++;
			else if(s.charAt(0) == 'R')
				list[2]++;
			else if(s.charAt(0) == 'C')
				list[3]++;
			else if(s.charAt(0) == 'H')
				list[4]++;
		}
		long ans = 0;
		for(int i = 0; i < 5; i++) {
			for(int j = i + 1; j < 5; j++) {
				for(int k = j + 1; k < 5; k++) {
					ans += list[i] * list[j] * list[k];
				}
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 43700
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	a, b := int64(scanInt()), int64(scanInt())

	e := euclidean(a,b)
	f := factorization(e)
	
	fmt.Println(len(f)+1)
}

func euclidean(a,b int64) int64 {
	r, x := a%b, b
	for r != 0 {
		x, r = r, x%r
	}
	return x
}

func factorization(n int64) map[int64]int {
	res := make(map[int64]int, 0)
	for i := int64(2); i*i <= n; i++ {
		for n%i == 0 {
			res[i]++
			n /= i
		}
	}
	if n!=1 {
		res[n] = 1
	}
	return res
}


Measured memory_bytes: 640
down = []
puddles = []
ans = 0

for i, s in enumerate(input()):
    if s == '\\':
        down.append(i)
    elif s == '/' and down:
        l = down.pop()
        # 累積和
        a = i - l
        # 高さが上から見ていった時下向きの斜面が今のペアの斜面より右にきている
        # -> 次の池
        while puddles and puddles[-1][0] > l:
            a += puddles.pop()[1]
        puddles.append((l, a))


print(sum(a for l, a in puddles))
print(len(puddles), *(a for l, a in puddles))


Measured memory_bytes: 6516
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,m,a[1010][3],dp[1010][1010][2][2][2],to[2],ans=0;

int main()
{
	to[0]=1;
	to[1]=-1;
	rep(i,1005) rep(j,1005) rep(k,2) rep(p,2) rep(r,2) dp[i][j][k][p][r]=-1e16;
	rep(i,2) rep(j,2) rep(k,2) dp[0][0][i][j][k]=0;
	cin>>n>>m;
	rep(i,n) rep(j,3) scanf("%lld",&a[i][j]);
	repn(i,n)
	{
		rep(j,m+1)
		{
			rep(k,2) rep(p,2) rep(r,2)
			{
				dp[i][j][k][p][r]=max(dp[i][j][k][p][r],dp[i-1][j][k][p][r]);
				if(j-1>=0)
				dp[i][j][k][p][r]=max(dp[i][j][k][p][r],
				dp[i-1][j-1][k][p][r]+to[k]*a[i-1][0]+to[p]*a[i-1][1]+to[r]*a[i-1][2]);
			}
		}
	}
	rep(i,2) rep(j,2) rep(k,2) ans=max(ans,dp[n][m][i][j][k]);
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 63744
#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 <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

void shortestPath(const vector<vector<int> >& edges, int start, vector<int>& dist)
{
    int n = edges.size();
    dist.assign(n, INT_MAX);
    dist[start] = 0;
    queue<int> q;
    q.push(start);

    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(unsigned i=0; i<edges[v].size(); ++i){
            int u = edges[v][i];
            if(dist[u] == INT_MAX){
                dist[u] = dist[v] + 1;
                q.push(u);
            }
        }
    }
}

bool findPath(int n, const vector<vector<int> >& edges, vector<int>& cnt)
{
    vector<int> dist;
    shortestPath(edges, 0, dist);
    int x = max_element(dist.begin(), dist.end()) - dist.begin();
    shortestPath(edges, x, dist);
    int y = max_element(dist.begin(), dist.end()) - dist.begin();

    cnt.assign(dist[y]+1, 0);
    y = edges[y][0];
    while(x != y){
        cnt[dist[y]] = edges[y].size() - 2;
        for(int a : edges[y]){
            if(dist[a] + 1 == dist[y]){
                y = a;
                break;
            }
        }
    }

    return accumulate(cnt.begin(), cnt.end(), cnt.size()) == n;
}

void makePermutation(const vector<int>& cnt, vector<int>& p)
{
    int n = cnt.size();

    p.clear();
    int index = 1;
    for(int i=0; i<n; ++i){
        for(int j=0; j<cnt[i]; ++j)
            p.push_back(index + 1 + j);
        p.push_back(index);
        index += cnt[i] + 1;
    }
}

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

    vector<int> cnt;
    if(!findPath(n, edges, cnt)){
        cout << -1 << endl;
        return 0;
    }
    
    vector<int> p, q;
    makePermutation(cnt, p);
    reverse(cnt.begin(), cnt.end());
    makePermutation(cnt, q);
    p = min(p, q);

    cout << p[0];
    for(int i=1; i<n; ++i)
        cout << ' ' << p[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 7936
N,K = map(int,input().split())
S = input()
if N == 1:
    print(0)
    exit()

ans = 0
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i + 1]:
        ans += 1
    else:
        cnt += 1

ans += min(K,cnt//2) * 2

if K > cnt//2 and S[0] != S[-1]:
    ans += 1

print(ans)

Measured memory_bytes: 9256
import sys
from heapq import heappop, heappush
from itertools import accumulate
 
def dijkstra(n, edges, start, *, adj_matrix=False, default_value=float("inf")):
    inf = float("inf")
    vertices = [inf] * n
    vertices[start] = 0
    q, rem = [(0, start)], n - 1
 
    while q and rem:
        cost, v = heappop(q)
        if vertices[v] < cost:
            continue
        rem -= 1
 
        dests = ((i, n) for i, n in enumerate(edges[v]) if n != default_value)\
            if adj_matrix else edges[v]
 
        for dest, _cost in dests:
            newcost = cost + _cost
            if vertices[dest] > newcost:
                vertices[dest] = newcost
                heappush(q, (newcost, dest))
 
    return vertices
 
n, m, s, t = map(int, input().split())
s, t = s-1, t-1
yen = [[] for _ in [0]*n]
sno = [[] for _ in [0]*n]
for l in sys.stdin.readlines():
    u, v, a, b = map(int, l.strip().split())
    yen[u-1].append((v-1, a))
    yen[v-1].append((u-1, a))
    sno[u-1].append((v-1, b))
    sno[v-1].append((u-1, b))
 
yen = dijkstra(n, yen, s)
sno = dijkstra(n, sno, t)
result = list(accumulate([y+s for y, s in zip(yen, sno)][::-1], min))
money = 10**15
for n in result[::-1]:
    print(money-n)


Measured memory_bytes: 80548
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define sd second
#define ll long long
#define pli pair<ll,int>

using namespace std;

const int maxn = 500010;
const int maxk = 5010;
const ll oo = 1e9+7;

int m,n,a[maxn],s[maxn],num[maxn],id[maxn];

int cmp (int x,int y) {
    return a[x] < a[y];
}

int main() {
    //freopen("in.txt","r",stdin);
    cin>>n;
    for (int i=1;i<=n;i++) {
        cin>>a[i];
        id[i] = i;
    }
    sort(id+1,id+n+1,cmp);
    for (int i=1;i<=n/2;i++) s[id[i]] = a[id[n/2+1]];
    for (int i=n/2+1;i<=n;i++) s[id[i]] = a[id[n/2]];
    for (int i=1;i<=n;i++) cout<<s[i]<<endl;

}


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

int main() {
  string N;
  cin>>N;
  bool ans=false;
  for(int i=0;i<3;i++){
    if (N.at(i)=='7'){
      ans=true;
      break;
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll              long long int
#define vi              vector< int >
#define vll             vector< ll >
#define vc              vector< char >
#define vs              vector< string >
#define pb              push_back
#define all(v)          v.begin(), v.end()
#define PI              acos(-1.0)  // 3.1415926535897932
#define yes             cout << "yes" << endl
#define no              cout << "no" << endl
#define YES             cout << "YES" << endl
#define NO              cout << "NO" << endl

int main()
{
    ll k, a, b, c=0;
    cin >> k;
    cin >> a >> b;
    for(int i=a; i<=b; i++)
    {
        if(i%k==0)
        {
            c=1;
            break;
        }
    }
    if(c==1)
        cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> job(m);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        if (a > m) continue;
        job[m - a].push_back(b);
    }
    ll ans = 0;
    priority_queue<ll> pq;
    rrep(i, m) {
        rep(j, sz(job[i])) pq.push(job[i][j]);
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using vi = vector<int>;

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
const int INF = 1000000000;

int match[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vi dp;
vi A;
int N, M;
int main() {
  cin >> N >> M;

  A.resize(M);
  REP(i, M) {
    cin >> A[i]; --A[i];
  }
  sort(ALL(A));
  reverse(ALL(A));

  dp.resize(N+1, -INF);
  dp[0] = 0;

  for (int i = 1; i <= N; ++i) {
    REP(j, M) {
      if (i - match[A[j]] >= 0 && dp[i - match[A[j]]] != -INF)
        dp[i] = max(dp[i], dp[i - match[A[j]]] + 1);
    }
  }
  int d = N;
  REP(i, dp[N]) {
    REP(j, M) {
      if (d - match[A[j]] >= 0 && dp[d-match[A[j]]] == dp[d] - 1) {
        cout << (A[j]+1);
        d -= match[A[j]];
        break;
      }
    }
  }
  cout << "\n";
  return 0;
}


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

int main(){
int h, w, k;
cin >> h >> w >>k;
int a[h][w]={0};
int c[h][w]={0};
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
char c; cin >>c;
if(c=='.')a[i][j]=0;
else a[i][j] = 1;
}
}
int ans=0;
for (int bit=0; bit<(1<<h); bit++){
for (int bit2=0; bit2<(1<<w); bit2++){
  for(int i = 0; i < h; i++){
  for(int j = 0; j < w; j++){
        c[i][j] = a[i][j];
      }
  }
        for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            if (bit&(1<<i) || bit2&(1<<j))c[i][j] =0;
        }
        }
int cnt=0;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
     cnt += c[i][j];
     }
   }
if(cnt == k) ans++;
  }
}     
cout << ans <<endl;
return 0;
 }    

Measured memory_bytes: 3628
#include<iostream>

int main() {
    std::string s, t;
    std::string u;
    int a, b;

    std::cin >> s >> t;
    std::cin >> a >> b;
    std::cin >> u;
    
    if (u == s) a--;
    else b--;

    std::cout << a << ' ' << b << std::endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'
#define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/
// ll power(ll x, ll y) {
//     ll res = 1;x %= mod;
//     while (y > 0) {
//         if (y & 1)res = (res*x) % mod;
//         y = y>>1;
//         x = (x*x) % mod;
//     }
//     return res%mod;
// }
// bool cmp(pair<int, int> a, pair<int, int> b){
//     return (a.fi+a.si) > (b.fi+b.si);
// }
// void solve(){
//     int n, s = 0;
//     cin >> n;
//     vector<pair<int, int> > v(n) ;
//     rep(i, 0, n)cin >> v[i].fi >> v[i].si, s += v[i].fi;
//     sort(all(v), cmp);
//     rep(i, 0, n){
//         if(v[i].fi+v[i].si <= s){
//             cout << "INDEFINITELY\n";
//             return;
//         }
//         else s -= v[i].fi;
//     }
//     int mi, ans = s;
//     rep(i,0,n){
//         if()
//     }
// }

void solve() {
    string s, t;
    cin >> s >> t;
    int ans = INT_MAX;
    for(int i = 0; i + t.size() <= s.size(); i++){
        int tans = 0;
        for(int j = 0; j < t.size(); j++){
            if(s[i+j] != t[j])tans++;
        }
        ans = min(ans, tans);
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    // fact((2e6+10));
    // //declare  and  global
    int t = 1;
    // cin >> t;
    rep(i, 0, t){
        solve();
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

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

    ll l[N + 1] = {}; l[0] = 0;
    for (int i = 1; i <= N; i++) l[i] = l[i - 1] + i;

    ll r[N + 1] = {}; r[0] = N;
    for (int i = 1; i <= N; i++) r[i] = r[i - 1] + (N - i);

    ll ans = 0;
    for (int i = K; i <= N + 1; i++) {
        // cout << "# i : " << i << " l : " << l[i - 1] << " r : " << r[i - 1] << endl;
        ans = (ans + r[i - 1] - l[i - 1] + 1) % MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6760