akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        String s = scanner.nextLine();
        if (s.equals("A")) {
            System.out.println("T");
        } else if (s.equals("C")) {
            System.out.println("G");
        } else if (s.equals("G")) {
            System.out.println("C");
        } else {
            System.out.println("A");
        }
    }

}

Measured memory_bytes: 25300
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <sstream>

using namespace std;

int main(){
  int h, w, n;
  vector<int> o;
  cin >> h >> w;
  cin >> n;
  int flag=0;
  for (int i=1;i<=n;i++) {
    int a;
    char c;
    cin >> a;
    for (int j=0;j<a;j++) {
      if (o.size()==w) {
	if (flag % 2 == 1) {
	  reverse(o.begin(), o.end());
	}
	for (int k = 0;k<o.size();k++) {
	  cout << o.at(k);
	  if (k<o.size()-1) {
	    cout << " ";
	  } else {
	    cout << endl;
	  }
	}
	o.erase(o.begin(), o.end());
	flag++;
      }
      //      c = to_string(i)[0];
      //      cout << i << "\t" << j << "\t" << c << "\t" << a << endl;
      o.push_back(i);
    }
    if (o.size()==w) {
      if (flag % 2 == 1) {
	reverse(o.begin(), o.end());
      }

      for (int k = 0;k<o.size();k++) {
	cout << o.at(k);
	if (k<o.size()-1) {
	  cout << " ";
	} else {
	  cout << endl;
	}
      }
      o.erase(o.begin(), o.end());
      flag++;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, t, sum = 0; cin >> n >> t;
    ll pt; cin >> pt;
    rep(i, n-1){
        ll np; cin >> np;
        if(np-pt >= t) sum += t;
        else sum += np-pt;
        pt = np;
    }
    sum += t;
    cout << sum << endl;
}

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

int main(void){
	 double r;
	do{
		scanf("%lf",&r);
	}while(r<0 || r>10000);

	printf("%f ",r*r*M_PI);
	printf("%f\n",2*r*M_PI);
	return 0;
}

Measured memory_bytes: 648
# -*- coding:utf-8 -*-
while True:
    H,W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i +j)%2==0 or (i+j)==0:
                print("#",end = '')
            else:
                print(".",end='')
        print()
    print()

Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 2000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 100000;

int n;
int a[MAX_N];

int dp[MAX_N + 1];

int main() {
    cin >> n;
    REP(i, n) cin >> a[i];

    REP(i, n+1) dp[i] = INF;
    dp[0] = -1;
    int i_max = 0;
    REP(j, n) {
        if (a[j] > dp[i_max]) {
            dp[i_max + 1] = a[j];
            i_max++;
        }
        else {
            int k = lower_bound(dp, dp + i_max + 1, a[j]) - dp;
            dp[k] = a[j];
        }
    }
    PRINT(i_max);
    return 0;
}


Measured memory_bytes: 3880
h,w=map(int,input().split())


def sdif(h1,w1,h2,w2,h3,w3):
    s1=h1*w1
    s2=h2*w2
    s3=h3*w3
    return max(abs(s1-s2),abs(s2-s3),abs(s3-s1))

if h % 3==0 or w% 3== 0:
    print(0)
else:
    h1=h//3
    w1=w
    h2=h-h1
    w2=w//2
    h3=h2
    w3=w-w2
    r1=sdif(h1,w1,h2,w2,h3,w3)
    h1=h//3+1
    w1=w
    h2=h-h1
    w2=w//2
    h3=h2
    w3=w-w2
    r2=sdif(h1,w1,h2,w2,h3,w3)
    w1=w//3
    h1=h
    w2=w-w1
    h2=h//2
    w3=w2
    h3=h-h2
    r3=sdif(h1,w1,h2,w2,h3,w3)
    w1=w//3+1
    h1=h
    w2=w-w1
    h2=h//2
    w3=w2
    h3=h-h2
    r4=sdif(h1,w1,h2,w2,h3,w3)
    print(min(h,w,r1,r2,r3,r4))

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

int main() {
  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int count = 0;
    set<char> s1, s2;
    for (int j = 0; j < i + 1; j++) {
      s1.insert(s[j]);
    }
    for (int j = i + 1; j < n; j++) {
      s2.insert(s[j]);
    }
    for (auto value : s2) {
      if (s1.count(value)) {
        count++;
      }
    }
    ans = max (ans, count);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <queue>
#include <cstring>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
int dp[1405][1405];
int board[1405][1405];
int H,W;
int maxwidth=0;
const int inf=1e9+5;

int main(int argc,char const* argv[])
{
  memset(dp,-1,sizeof(dp));
  cin >> H >> W;
  for(int i=0;i<H;i++)
    {
      for(int j=0;j<W;j++)
	{
	  cin >> board[i][j];
	}
    }
  for(int i=0;i<H;i++)
    {
      for(int j=0;j<W;j++)
	{
	  dp[i][j]=(board[i][j]+1)%2;
	  maxwidth|=dp[i][j];
	}
    }
  for(int i=1;i<H;i++)
    {
      for(int j=1;j<W;j++)
	{
	  if(board[i][j])
	    {
	      dp[i][j]=0;
	    }
	  else
	    {
	      dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1;
	      maxwidth=max(maxwidth,dp[i][j]);
	    }
	}
    }
  cout << maxwidth*maxwidth<< endl;
  return 0;
}



Measured memory_bytes: 18476
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y,z;
}a[200001];
priority_queue<ll>q;
ll X,Y,Z,n,sum,ans,le[200001],C;
bool cmp(aaa a,aaa b){
	return a.y-a.x>b.y-b.x;
}
int main(){
	ll i,j;
	scanf("%lld%lld%lld",&X,&Y,&Z);
	n=X+Y+Z;
	for(i=1;i<=n;i++)scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].z);
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=n;i++)C+=a[i].z;
	for(i=1;i<=Y;i++){
		sum+=a[i].y-a[i].z;
		q.push(a[i].z-a[i].y);
	}
	for(i=Y+1;i<=n-X+1;i++){
		le[i-1]=sum;
		sum+=a[i].y-a[i].z;
		q.push(a[i].z-a[i].y);
		sum+=q.top();
		q.pop();
	}
//	puts("-1");
	while(!q.empty())q.pop();
	sum=0;
	for(i=n;i>=n-X+1;i--){
		sum+=a[i].x-a[i].z;
		q.push(a[i].z-a[i].x);
	}
	//puts("-1");
	for(;i>=Y;i--){
		ans=max(ans,sum+le[i]+C);
		sum+=a[i].x-a[i].z;
		q.push(a[i].z-a[i].x);
		sum+=q.top();
		q.pop();
	}
	printf("%lld",ans);
}
/*
我们重定义Ai=Ai-Ci，Bi=Bi-Ci，按照新的Ai降序排序。我们可以确定选择金币的一定是在选择铜币的前面。
不理解的话可以考虑只有A和C两种币的时候的情况.
然后我们用priority_queue维护一下最后加上sigma C 行了
*/

Measured memory_bytes: 2680
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, A[(int)2e5];
    intmax_t S[(int)2e5] = {}, nC2[(int)2e5], n_1C2[(int)2e5], sum = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &A[i]);
        S[A[i] - 1]++;
    }

    for (size_t i = 0; i < (size_t)2e5; i++) {
        if (S[i] >= 2) {
            nC2[i] = S[i] * (S[i] - 1) / 2;
            n_1C2[i] = (S[i] - 1) * (S[i] - 2) / 2;
        } else {
            nC2[i] = n_1C2[i] = 0;
        }
        sum += nC2[i];
    }

    for (size_t i = 0; i < N; i++) {
        printf("%jd\n", sum - nC2[A[i] - 1] + n_1C2[A[i] - 1]);
    }

    return 0;
}


Measured memory_bytes: 8704
#include <iostream>
#include <cmath>

int main(){
    int n, a;
    double t;
    double min = 999999999;
    int min_num;
    std::cin >> n >> t >> a;
    for(int i = 0; i < n; i++){
        int h;
        std::cin >> h;
        if(min > std::abs(a-(t-h*0.006))){
            min = std::abs(a-(t-h*0.006));
            min_num = i;
        }
    }
    std::cout << min_num + 1 << std::endl;
}


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

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

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

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

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

    int n;
    cin >> n;

    vector< LLP > v(n + 1);
    reps(i, n){
        cin >> v[i].first >> v[i].second;
    }
    SORT(v);

    vector<lint> sum(n + 1);
    reps(i, n){
        sum[i] = sum[i - 1] + v[i].second;
    }

    lint ans = 0, m = 0;
    reps(i, n){
        chmax(m, v[i].first - sum[i - 1]);
        chmax(ans, sum[i] - v[i].first + m);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14756
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1e9 + 10;//10^9
ll MOD  = 1000000007;
int dy[] = {0,0,1,-1};
int dx[] = {1,-1,0,0};

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a < b)swap(a, b);
    if(a < c)swap(a, c);
    
    if((3 * a - (a + b + c)) % 2 == 1){
        cout << (3 * (a + 1) - (a + b + c)) / 2 << endl;
    }else{
        cout << (3 * a - (a + b + c)) / 2 << endl;
    }
    
    
}

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

int main(){
  string s;
  cin >> s;
  int cnt = 0;
  if( s[0] == 'o' ) cnt++;
  if( s[1] == 'o' ) cnt++;
  if( s[2] == 'o' ) cnt++;
  int ans = 700 + cnt * 100 ;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).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 INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, k; cin >> n >> k;
    
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    ll amax = *max_element(ALL_OF(a));
    ll agcd = accumulate(ALL_OF(a), a[0], [](ll x, ll y) -> ll { return gcd(x, y); });

    if (k % agcd == 0 && k <= amax) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    
}

Measured memory_bytes: 1024
# include<iostream>
using namespace std;
# define N 1000
int main(){
    int n; cin >> n;
    int x[N]; for(int i=0; i<n; i++) cin >> x[i];
    int M; cin >> M;
    int y[N]; for(int i=0; i<M; i++) {cin >> y[i]; y[i]--;}

        for(int i=0; i<M; i++){
            if(x[y[i]] != 2019){
                if(x[y[i]+1] != x[y[i]]+1) x[y[i]] = x[y[i]]+1;
                //else x[y[i]] = x[y[i]];
            }
        }
    for(int i=0; i<n; i++) cout << x[i] << "\n";
    return 0;
}


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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#define co(n) cout << (n) << endl;
#define cn(n) cin >> n;
#define all(x) (x).begin(), (x).end()

int main(){
  ll n;cn(n)
  if (n%2){
    puts("0");
  }else{
    ll t = 0;
    ll m = n/2;
    while(m){
      t += m /= 5;
    }
    cout << t << endl;
  }
}

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

const int N=1e5+10;
int len,Cnt;
char a[N];

int main ()
{
	scanf ("%s", a+1);
	len=strlen (a+1);
	for (int i=1;i<=len>>1;++i)
		if (a[i]!=a[len-i+1]) Cnt++;
	if (Cnt==0) {
		puts ("Second");
		return 0;
	}	
	a[1]==a[len]? (len & 1?puts ("Second") : puts ("First") ) : (len & 1?puts ("First") : puts ("Second") );
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
using namespace std; 
#define rep(i, c) for(int i = 0; i < (int)c; i++)

int main() {
    ll n, p[200001], max_num = INF, cnt = 0;
    cin >> n;
    rep(i, n) cin >> p[i];
    rep(i, n) {
        if (p[i] <= max_num) {
            cnt++;
            max_num = p[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        if (n.charAt(0) == n.charAt(2)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23252
#include <iostream>
//using namespace std;
 //Compiler version g++ 6.3.0

using namespace std;

 int main()
 {
 	int frm,end,v;
 	int c=0;
 	cin >> frm >> end >> v;
 
    for(int n=frm;n<=end;n++){
       if(v%n==0){
          c++;
        }
    }

 	cout << c << endl;
 	
 	return 0;
 }



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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int K = cin.nextInt();

        int max = (N - 1) * (N - 2) / 2;
        if (K > max)
        {
            Console.WriteLine(-1);
            return;
        }

        Console.WriteLine(N - 1 + max - K);
        for (int i = 2; i <= N; i++)
        {
            Console.WriteLine("{0} {1}", 1, i);
        }

        int cur = 2;
        int tmp = 1;
        for (int i = 0; i < max - K; i++)
        {
            if (cur + tmp > N)
            {
                cur++;
                tmp = 1;
            }
            Console.WriteLine("{0} {1}", cur, cur + tmp);
            tmp++;
        }
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int h, w, k;
  cin >> h >> w >> k;
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  --x1, --y1, --x2, --y2;
  char c;
  vector<vector<int>> g(h, vector<int>(w));
  rep(i, h) rep(j, w) {
    cin >> c;
    if (c == '@') g[i][j] = -1;
  }
  g[x1][y1] = 1;
  queue<P> q;
  q.emplace(x1, y1);
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    rep(i, 4) {
      for (int j = 1; j <= k; ++j) {
        int nx = x + dx[i]*j;
        int ny = y + dy[i]*j;
        if (nx < 0 || ny < 0 || nx >= h || ny >= w || g[nx][ny] == -1) break;
        if (g[nx][ny] != 0 && g[nx][ny] <= g[x][y]) break;
        if (g[nx][ny] == 0) {
          g[nx][ny] = g[x][y] + 1;
          q.emplace(nx, ny);
        }
      }
    }
  }
  cout << g[x2][y2]-1 << endl;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<=num; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    seq_inv[0] = 1;
    seq_inv[1] = 1;
    for(int i=2; i<=num; i++){
        seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fact_inv[0] = 1;
    fact_inv[1] = 1;
    for(int i=2; i<=num; i++){
        fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
    }
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            add(s, dat[i]);
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return (MOD + sum(j) - sum(i-1)) % MOD;
    }

    void plus(int i, T x){
        while(i < n){
            add(dat[i], x);
            i |= i+1;
        }
    }
};

int main(){
    int N, H, D;
    cin >> N >> H >> D;

    create_mod_tables((int)1e6);

    int64_t C = 0;
    for(int i=1; i<=N; i++) add(C, fact[i]);

    BIT<int64_t> bit(H+1);
    bit.plus(0, fact[N]);
    for(int i=1; i<=H; i++) bit.plus(i, (i==H ? 1 : C) * bit.sum_between(i-D, i-1) % MOD);

    int64_t ans = bit.sum_between(H, H);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31616
package main
     
import (
	"bufio"
	"fmt"
	"os"
)
 
const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)
 
var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}
 
func main() {
	S, T := nextLine(), nextLine()
	var ans int
	for i := 0; i < len(S); i++ {
		if S[i] != T[i] {
			ans++
		}
	}
	fmt.Println(ans)
}
 
func nextLine() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2604
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#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 lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  ll n; cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  ll now=a[0];
  ll ans=0;
  REP(i,1,n){
    if(a[i]<=now) ans+=now-a[i];
    else now=a[i];
  }
  out(ans);
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


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

int n, a[50];

bool solve(int i, int m) {
	if (m == 0) return true;
	if (i >= n) return false;
	bool res = solve(i + 1, m) || solve(i + 1, m - a[i]);
	return res; 
} 

int main() {
	cin >> n;
	rep(i, n) cin >> a[i];
	int q, m;
	cin >> q;
	rep(i, q) {
		cin >> m;
		if (solve(0, m)) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  int a, b;
  cin >> a >> b;
  cout << max(0, a - b - b) << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}




Measured memory_bytes: 256
use std::io::{Read, stdin};
use std::str::FromStr;

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let x: i64 = read();
    let ans = hoge(b, x)-hoge(a-1 ,x);
    println!("{}", ans);
}

fn hoge(u: i64, x: i64) -> i64 {
    if u == -1 {
        0
    } else {
        u / x + 1
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
<?php

while (true) {
    $n = trim(fgets(STDIN));
    if ($n == 0) break;

    $ab = [];
    for ($i = 0; $i < $n; $i++)
        $ab[] = explode(' ', trim(fgets(STDIN)));

    $c = trim(fgets(STDIN));
    $d = trim(fgets(STDIN));

    echo bfs()."\n";
}

function bfs() {
    global $n, $ab, $c, $d;
    $q = new SplQueue();
    $q->enqueue([$c, 0]);

    $occured = [];
    while (!$q->isEmpty()) {
        $nc = $q->dequeue();
        for ($i = 0; $i < $n; $i++) {
            $ns = str_replace($ab[$i][0], $ab[$i][1], $nc[0]);
            $nn = $nc[1] + 1;
            if ($ns == $d) {
                return $nn;
            } else if (strlen($ns) <= 10) {
                if (!in_array($ns, $occured)) {
                    $q->enqueue([$ns, $nn]);
                    $occured[] = $ns;
                }
            }
        }
    }

    return -1;
}

Measured memory_bytes: 16116
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

bool is_less_X(vector<ll> A, vector<ll> F, ll K, ll X){
    ll n = A.size();

    ll s = 0;
    REP(i, n){
        s += max(A[i] - floor((double) X / (double) F[i]), 0);
    }
    //cout << X << ": "<< s << endl;
    if (s <= K) return true;
    return false;
}

int main() {

    ll N , K;
    cin >> N >> K;

    vector<ll> A(N), F(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> F[i];

    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<ll>());

    ll Xb = 1e12;
    ll Xs = -1;
    ll tmp;
    while(Xb - Xs > 1){
        tmp = (Xb + Xs) / 2;
        if (is_less_X(A, F, K, tmp)) Xb = tmp;
        else Xs = tmp;
        //cout << tmp << endl;
    }
    cout << Xb << endl;

    return 0;
}

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

using namespace std;

const double PI = 3.141592;
const int MAX_N = 1e5+5;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

const bool dbgEnabled = false;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef pair<string, ll> psi;
typedef pair<ll, string> pis;
typedef vector<pii> vpii;
typedef vector<psi> vpsi;
typedef vector<pis> vpis;
typedef vector<vi> vvi;

// Debug macros
#define dbg(x) do { \
	if (dbgEnabled) { cerr << #x << ": " << x << "\n"; } \
} while (0)

#define dbgv(x) do { \
	if (dbgEnabled) { cerr << #x << ": [ "; for (auto& _ : x) cerr << _ << " "; cerr << "]\n"; } \
} while (0)

#define dbgvv(x) do { \
	if (dbgEnabled) { cerr << #x << ":\n[\n"; for (auto& __ : x) dbgv(__); cerr << "]\n";} \
} while (0)

void solve() {
	double d, t, s;
	cin >> d >> t >> s;
	if (t >= d/s) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

int main() {
	if (!dbgEnabled) {
		ios_base::sync_with_stdio(false);
		cin.tie(nullptr); cout.tie(nullptr);
	}
	
	ll t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}    
    return 0;
}



Measured memory_bytes: 3712
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int n; cin>>n;
  int ans=(n+1)/2;
  cout<<ans<<endl;
  
  return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
string s;
/**********************************************/

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

    cin >> s;

    string akiba[] = {"AKIHABARA", "AKIHABAR", "AKIHABR", "AKIHBAR", "AKIHBRA", "AKIHBR", "AKIHABRA", "AKIHBARA",
                      "KIHABARA", "KIHABAR", "KIHABR", "KIHBAR", "KIHBRA", "KIHBR", "KIHABRA", "KIHBARA"};
    
    REP(i, 16){
        if(s == akiba[i]){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
n = int(input())
dp = [[0,0,0] for i in range(n)]
a,b,c = map(int,input().split())
dp[0][0],dp[0][1],dp[0][2] = a,b,c
for i in range(1,n):
    abc = list(map(int,input().split()))
    for j in range(0,3):
        for k in range(0,3):
            if k != j:
                dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[j])
print(max(dp[n-1]))


Measured memory_bytes: 86312
n=io.read("*n")
b={}

for i=1, n-1 do
  table.insert(b, i, io.read("*n"))
end

ans=0

a1=0
a2=0

for i=1, n-1 do
  a1=a2
  if i == 1 then
    a1=b[i]
    a2=b[i]
  end
  a2=b[i]
  if b[i+1] == nil then
    a2=b[i]
  elseif b[i] > b[i+1] then
    a2=b[i+1]
  end

  ans = ans + a1
end

ans = ans + a2

print(ans)

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;

int main(){
  long long int a;
  long long int b;

  while(cin >> a >> b){
    int ans;
    bool p[2000000];
    vector<vector<int> > part;
    
    ans = 2*b+1;
    part.resize(b*2+1);
    int N = (int)sqrt(a+b)+1;
    for(int i=0;i<=N;i++)p[i] = true;
    p[0] = false;
    p[1] = false;
    p[2] = true;
    
    int o = 0;
    if((a-b)%2)o++;
    for(int i=o;i<=2*b;i+=2)part[i].push_back(2);
    
    int c = 3;
    while(c*c<=N){
      for(int i=3*c;i<=N;i+=2*c)p[i] = false;
      do{c+=2;}while(!p[c]);
    }
    
    
    c = 3;
    while(c<=N){
      int t = (a-b)%c;
      for(int i=(c-t)%c;i<=2*b;i+=c)part[i].push_back(c);
      do{c+=2;}while(!p[c]);
    }
    
    
    for(int i=0;i<=2*b;i++){
      long long int tmp = a-b+i;
      int prv = 1<<30;
      if(tmp<=1)ans--;
      else{
	
	if(!part[i].empty()){
	  bool f = false;
	  for(int j=0;j<(int)part[i].size();j++){
	    int cnt = 0;
	    while(!(tmp%part[i][j])){
	      tmp /= part[i][j];
	      cnt++;
	    }
	    if(prv < cnt){
	      f=true;
	      break;
	    }else{
	      prv = cnt;
	    }
	    if(tmp==1)break;
	  }
	  if(f)ans--;
	}
	
      }
    }
    
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 38000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
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; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
    int n; cin >> n;
    vector<int> p(n); rep(i,n) cin >> p[i];
    sort(all(p));
    int ans = 0;
    rep(i,n) ans += p[i];
    ans -= p[n-1]/2;
    
    cout << ans;
    
return 0;
}

Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

dig_hun = 6
dig_ji = 0.5

ji = H * 30 + M * 0.5
hun = 6 * M
dig = abs(ji - hun)
rad = math.radians(dig)
ans = ( A**2 + B**2 - 2 * A * B * math.cos(rad)) ** (1/2)

print(ans)


Measured memory_bytes: 9496
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int dp[1005][1005];

int main()
{
//	cut here before submit 
//	freopen ("testcase.A_Thief", "r", stdin );
	int cnt = 0;
	while (1 ){
		int W;
		scanf ("%d", &W );
		if (W == 0 ) break;
		int N;
		scanf ("%d", &N );
		vector<int> v (N, 0 ), w (N, 0 );
		rep (i, N ){
			string str;
			cin >> str;
			while (str.find(',') != string::npos ){
				str = str.replace(str.find(','), 1, " ");
			} // end while
			stringstream ss (str );
			ss >> v[i] >> w[i]; 
		} // end rep
/*
		rep (i, N ){
			cerr << "v: " << v[i] << " w: " << w[i] << endl;
		} // end rep
*/
		memset (dp, 0, sizeof (dp ) );
		dp[0][w[0]] = v[0];
		for (int i = 1; i < N; i++ ){
			dp[i][w[i]] = v[i];
			for (int j = 0; j <= W; j++ ){
				if (dp[i-1][j] != 0 ){
					dp[i][j] = max (dp[i][j], dp[i-1][j] );
					if (j + w[i] <= W ){
						dp[i][j + w[i]] = max (dp[i][j + w[i]], dp[i-1][j] + v[i] );
					} // end if
				} // end if
			} // end for
		} // end for
/*
		rep (i, N ){
			rep (j, W ){
				cerr << setw(3) << dp[i][j];
			} // end rep
			cerr << endl;
		} // end rep
*/
		int res_v = 0, res_w = 0;
		for (int j = 0; j <= W; j++ ){
			if (dp[N-1][j] > res_v ){
				res_v = dp[N-1][j];
				res_w = j;
			} // end if
		} // end for
		printf ("Case %d:\n", ++cnt );
		printf ("%d\n", res_v );
		printf ("%d\n", res_w );
	} // end loop

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

Measured memory_bytes: 5224
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
#from fractions import gcd
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input():
    return sys.stdin.readline()[:-1]
def pri(x):
    if type(x) is list:
        print('\n'.join(map(str, x)))
    else:
        print(x)

N = int(input())
A = list(map(int, input().split()))

#sA = list(sorted(A))
c = Counter(A)
cnt = 0
for ci in c.values():
    cnt += ci*(ci-1)//2

for a in A:
    chk = c[a]
    res = cnt - chk*(chk-1)//2 + (chk-1)*(chk-2)//2
    print(res)



Measured memory_bytes: 26780
#include <iostream>
#include <vector>
#include <deque>
using namespace std;

#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)
#define pb push_back
#define pf pop_front
typedef long long ll;
typedef pair<int, int> pii;

const ll MAX_N = 10 * 1000 + 24;

int n, m;
int d[MAX_N];
vector<int> G[MAX_N], vec;
deque<int> dq;

int main() {
  FAST;
  cin>>n>>m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin>>u>>v;
    G[u].pb(v);
    d[v]++;
  }
  for (int i = 0; i < n; i++) {
    if (d[i] == 0) {
      dq.pb(i);
      vec.pb(i);
    }
  }
  while (dq.size()) {
    for (int j = 0; j < G[dq[0]].size(); j++) {
      u = G[dq[0]][j];
      d[u]--;
      if (d[u] == 0) {
        dq.pb(u);
        vec.pb(u);
      }
    }
    dq.pf();
  }
  for (int i = 0; i < n; i++) {
    cout<<vec[i]<<"\n";
  }
}



Measured memory_bytes: 3896
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=1

s=StoI()
n=len(s)
dp=[[0]*n for i in range(2)]

for i in range(n):
    if i==0:
        dp[0][i]=1
    elif i==1:
        if s[1]==s[0]:
            dp[0][i]=0
            dp[1][i]=1
        else:
            dp[0][i]=2
            dp[1][i]=1
    else:
        if s[i]==s[i-1]:
            dp[0][i]=dp[1][i-1]+1
            dp[1][i]=max(dp[0][i-2],dp[1][i-2])+1
        else:
            dp[0][i]=max(dp[0][i-1],dp[1][i-1])+1
            dp[1][i]=max(dp[0][i-2],dp[1][i-2])+1

ans=max(dp[0][n-1],dp[1][n-1])
print(ans)


Measured memory_bytes: 59356
#include<bits/stdc++.h>
using namespace std;
const int maxn =1e5+1;
int f[maxn][2];
typedef long long ll;
int main(){
	int D;
	cin>>D;
	if(D==25){
		cout<<"Christmas";
	}
	else if(D==24){
		cout<<"Christmas Eve";
	}
	else if(D==23){
		cout<<"Christmas Eve Eve";
	}
	else if(D==22){
		cout<<"Christmas Eve Eve Eve";
	}
	return 0;
}


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

int main(){
  map<int, bool> memo;

  int n;
  cin >> n;

  int cnt=0;

  for(int i=0; i<n; i++){
    int p[3];
    cin >> p[0] >> p[1] >> p[2];

    sort(p, p+3);

    int k=((p[0]-1)*1000+(p[1]-1))*1000+(p[2]-1);

    if(memo.find(k)!=memo.end()){
      cnt++;
    }else{
      memo[k]=true;
    }
  }

  cout << cnt <<endl;

  return 0;
}



Measured memory_bytes: 3216
_=input()
W=list(map(int,input().split()))
S=sum(W)
S1,tmp=0,0
for w in W:
    tmp=S1
    S1+=w
    if S1>S//2:
        break
if 2*S1-S<S-2*tmp:
    print(2*S1-S)
else:
    print(S-2*tmp)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

int main()
{
    int n(0);
    std::cin >> n;
    
    std::vector<long long> mons(n+1, 0);
    for(auto& v : mons){
        std::cin >> v;
    }
    
    std::vector<long long> savers(n, 0);
    for(auto& v : savers){
        std::cin >> v;
    }
    
    long long c(0);
    for(int i=0; i < n; ++i){
        const auto& n_hit = savers[i];
        const auto& n_mons = mons[i];
        
        c += std::min(n_hit, n_mons);
        if(n_hit > n_mons){
            const auto diff = n_hit - n_mons;
            auto& next_m = mons[i+1];
            c += std::min(diff, next_m);
            next_m = std::max(next_m-diff, 0LL);
        }
    }
    
    std::cout << c << std::endl;
    
    return 0;
}

Measured memory_bytes: 1792
from collections import deque

N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = pow(10,9)+7

A.sort(reverse=True)

deque = deque()
for a in A:
    deque.append(a)

ans = 1
cnt = 0
if K%2 == 1:
    ans *= deque.popleft()
    cnt += 1
    
if ans <= 0:
    for i in range(K-1):
        ans *= deque.popleft()
        ans %= mod
else:
    while cnt < K:
        x1 = deque.popleft()
        x2 = deque.popleft()
        deque.appendleft(x2)
        deque.appendleft(x1)
        y1 = deque.pop()
        y2 = deque.pop()
        if x1*x2 < y1*y2:
            ans *= y1*y2
            ans %= mod
            cnt += 2
        else:
            ans *= x1*x2
            ans %= mod
            if deque:
                x1 = deque.popleft()
            if deque:
                x2 = deque.popleft()
            deque.append(y2)
            deque.append(y1)
            cnt += 2
            
print(ans)

Measured memory_bytes: 95944
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n+1);
	rep(i,n)cin>>in[i];
	ll out=0;
	rep(i,n){
		out+=in[i]/2;
		in[i]%=2;
		if(in[i]&&in[i+1]){
			out++;
			in[i+1]--;
		}
	}
	cout<<out<<endl;
}








Measured memory_bytes: 640
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,x,m = inm()
k = -1
a = x
h = {}
f = [-1]*100001
f[0] = a
h[a] = 0
for i in range(1,n):
    a = (a*a)%m
    f[i] = a
    if a in h:
        k = i
        j = h[a]
        break
    else:
        h[a] = i
#ddprint(f"{f[:15]}")
if k<0:
    print(sum(f[:n]))
else:
    p = k-j
    q = (n-j)//p
    r = (n-j)%p
    #ddprint(f" /{k=} {j=} {f[j]} {f[k]} {p=} {q=} {r=}")
    print(sum(f[:j+r])+q*sum(f[j:k]))


Measured memory_bytes: 76200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	ll ans = 0, n = sz(s);
	ans += 1;
	ans += n*(n-1)/2;
	rep(i,'a','z'+1){
		ll cnt = count(all(s), i);
		ans -= cnt*(cnt-1)/2;
	}
	cout << ans << endl;
}

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

typedef long long LL;

const int Mod=1e9+7;

int N,M,Ans,Cnt;
LL F[90];

vector<pair<LL,LL>> V[105];

int main(){
	int i;
	LL x,y,p,q;
	pair<int,int> t;
	F[0]=F[1]=1;
	for(i=2;;i++){
		F[i]=F[i-1]+F[i-2];
		if(F[i]>1e18)
			break;
	}
	N=i;
	for(i=2;i<5;i++)
		V[1].push_back(make_pair(1,i));
	for(i=1;i+3<=N;i++)
		for(auto t:V[i]){
			x=t.second,y=t.first+x;
			for(;y<=F[i+3]+F[i];y+=x)
				V[i+1].push_back(make_pair(x,y));
		}
	scanf("%d",&M);
	while(M--){
		scanf("%lld%lld",&p,&q);
		if(p>q)
			swap(p,q);
		for(Ans=1;F[Ans+1]<=p&&F[Ans+2]<=q;Ans++);
		printf("%d ",Ans);
		if(Ans==1){
			printf("%d\n",1llu*(p%Mod)*(q%Mod)%Mod);
			continue;
		}
		Cnt=0;
		for(auto t:V[Ans-1]){
			x=t.first,y=t.second;
			if(y<=p)
				Cnt=(Cnt+(q-x)/y)%Mod;
			if(y<=q)
				Cnt=(Cnt+(p-x)/y)%Mod;
		}
		printf("%d\n",Cnt);
	}
	return 0;
}

Measured memory_bytes: 4096
N,K,S=map(int,input().split())
answers=[str(S)]*K
answers_=[str(S+1)]*(N-K)
a=' '.join(answers)
b=' '.join(answers_)
if K==0:
    if S==pow(10,9):
        answers_ = ['1'] * (N - K)
        b = ' '.join(answers_)
        c=b
    else:
        c=b
elif S==pow(10,9):
    answers_=['1']*(N-K)
    b = ' '.join(answers_)
    c=a+' '+b
else:
    c = a + ' ' + b
print(c)


Measured memory_bytes: 56304
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < 1000000001; i++){
        if(i * i > n){
            cout << (i - 1) * (i - 1);
            break;
        }
    }
    cout << "" << endl;
    return 0;
}

Measured memory_bytes: 256