akhauriyash/Code-Regression huggingface dataset:
while 1:
    try:
        year, month, day = map(int, input().split())
    except EOFError:
        break

    if year < 1868:
        gen = "pre-meiji"

    elif year == 1868:
        if month < 9:
            gen = "pre-meiji"
        elif month == 9:
            if day < 8:
                gen = "pre-meiji"
            else:
                gen = "meiji"
                y = 1
        else:
            gen = "meiji"
            y = 1

    elif 1868 < year < 1912:
        gen = "meiji"
        y = year - 1868 + 1

    elif year == 1912:
        if month < 7:
            gen = "meiji"
            y = 45
        elif month == 7:
            if day < 30:
                gen = "meiji"
                y = 45
            else:
                gen = "taisho"
                y = 1
        else:
            gen = "taisho"
            y = 1

    elif 1912 < year < 1926:
        gen = "taisho"
        y = year - 1912 + 1

    elif year == 1926:
        if month < 12:
            gen = "taisho"
            y = 15
        elif month == 12:
            if day < 25:
                gen = "taisho"
                y = 15
            else:
                gen = "showa"
                y = 1
        else:
            gen = "showa"
            y = 1

    elif 1926 < year < 1989:
        gen = "showa"
        y = year - 1926 + 1

    elif year == 1989:
        if month == 1:
            if day < 8:
                gen = "showa"
                y = 64
            else:
                gen = "heisei"
                y = 1
        else:
            gen = "heisei"
            y = 1

    elif 1989 < year:
        gen = "heisei"
        y = year - 1989 + 1

    if gen == "pre-meiji":
        print(gen)
    else:
        print(gen, str(y), str(month), str(day))



Measured memory_bytes: 5604
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
keta = [[0,0] for _ in range(60)]
for i in a:
    for j in range(60):
        if (i >> j) & 1:
            keta[j][1] += 1
        else:
            keta[j][0] += 1
ans = 0
for i in range(len(keta)):
    lis = keta[i]
    ans += lis[0] * lis[1] * pow(2, i, mod)
    ans %= mod
print(ans)

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main() {
  ll x;
  cin >> x;
  ll sum=0;
  int i=0;
  while(sum<x){
    i++;
    sum+=i;
  }
  cout<<i<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
int n;
cin>>n;
map<int ,int> d;
for(int i=0;i<n;i++){
int l;
cin>>l;
d[l]++;
}

int m;
cin>>m;
string ans="YES";
for(int i=0;i<m;i++){
int l;
cin>>l;
if(d.count(l) && d.at(l)!=0)d[l]--;
else ans="NO";
}
cout<<ans<<endl;
}

Measured memory_bytes: 9600
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

string s;

int main() {
	cin >> s;

	cout << (s.size()%2 ^ (s[0]==s[s.size()-1]) ? "First" : "Second");
	cout << endl;
}


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


int main()
{
    long long x,y,i,t,s;
    s=0;

    cin>>x;
    y=x;
    while(y)
    {
        s+=(y%10);
        y/=10;
    }
    if(x%s)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<iostream>
#include <stdlib.h>
#include<ctime>
#include <string>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
	string s;
	cin >> s;	
	int zero=0;
	int one=0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '0')
		{
			zero++;
		}
		else if (s[i] == '1')
		{
			one++;
		}		
	}

	if (one == 0 || zero == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	cout << min(one, zero) * 2 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};



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

	string s;
	cin >> s;
	if(s=="ABC")cout << "ARC" << endl;
	else cout << "ABC" << endl;

	return 0;
}


Measured memory_bytes: 3640
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    a = list(get_ints())
    ans = 0
    for i in range(N):
        if (i + 1) % 2 == 1 and a[i] % 2 == 1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9116
#include<stdio.h>
int main(void)
{
	int i,n,x,y,z,number;
	double d,w,bmi,best;
	scanf("%d",&n);
	while(n!=0) {
		bmi=100;
		best=100;
		x=1000001;
		for(i=1;i<=n;i++) {
			scanf("%d %d %d",&x,&y,&z);
			w=y/100.0;
			bmi=z/(w*w);
			if(bmi<=22.0) {
				bmi=22.0-bmi;
				if(bmi<best) {
					best=bmi;//---------------
					if(number!=x) {
						number=x;
					}
					else {
						if(x<number) {
							number=x;
						}
					}
				}
			}
			else {
				bmi=bmi-22.0;
				if(bmi<best) {
					best=bmi;
					if(number!=x) {
						number=x;
					}
					else {
						if(x<number) {
							number=x;
						}
					}
				}
			}
		}
		printf("%d\n",number);
	scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<int> x(n);
    rep(i,n) cin>>x[i];
    int res=1e+7;
    for(int p=-100;p<=200;p++){
        int buf=0;
        rep(i,n){
            buf+=(x[i]-p)*(x[i]-p);
        }
        res=min(buf,res);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
s = list(input())
s = [int(i) for i in s]
d = 10 ** 7
for i in range(len(s) - 2):
    n = s[i] * 100 + s[i + 1] * 10 + s[i + 2]
    if abs(n - 753) < d:
        d = abs(n - 753)
print(d)


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
  int N, K;
  cin >> N >> K;
  cout << (int)(K * pow(K - 1, N - 1)) << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.Deque;
import java.util.ArrayDeque;

class Main{
	public static void main(String[] args)throws Exception{
		Scanner scanner = new Scanner(System.in);
		int answer = 0;
		int n = Integer.parseInt(scanner.nextLine());
		int[] data1 = new int[10500];
		for(int i = 0; i < n; i++){
			data1[i] = scanner.nextInt();
		}
		String nothing = scanner.nextLine();

		int q = Integer.parseInt(scanner.nextLine());
		int[] data2 = new int[q];
		for(int i = 0; i < q; i++){
			data2[i] = scanner.nextInt();
		}
		
		for(int i = 0; i < q; i++){
			data1[n + i] = data2[i];
			int j = 0;
			while(data1[j] != data2[i]){
				j++;
			}
			if(j != n + i){
				answer++;
			}
		}
		System.out.println(answer);

	}
}

Measured memory_bytes: 40224
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      String X = sc.next();
      String Y = sc.next();
      String list = "ABCDEF";
      if(list.indexOf(X) < list.indexOf(Y)){
        System.out.println("<");
      }else if(list.indexOf(X) > list.indexOf(Y)){
        System.out.println(">");
      }else{
        System.out.println("=");
      }
	}
}


Measured memory_bytes: 21844
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

int powM(int x, int n){
    if(n == 0){
        return 1;
    }
    if(n % 2 == 0){
        return powM(x * x % MOD, n / 2);
    }
    return powM(x, n-1) * x % MOD;
}

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

    string l;
    cin >> l;
    int n = SZ(l);

    vector<int> a(n+1);
    a[0] = 1;
    rep(i, n){
        a[i+1] = a[i] * 3 % MOD;
    }

    int ans = 0;
    int cnt = 0;
    rep(i, n){
        if(l[i] == '1'){
            ans += a[n-1-i] * powM(2, cnt);
            ans %= MOD;
            cnt++;
        }
    }
    ans += powM(2, cnt);
    ans %= MOD;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1848
#include<iostream>
using namespace std;
int main(){
    int a[4],i,max1=0,maxi,s=0;
    cin>>a[1]>>a[2]>>a[3];
    for(i=1;i<=3;i++){
        if(a[i]>max1){
            max1=a[i];
            maxi=i;
        }
    }
    for(i=1;i<=3;i++)
        if(maxi!=i)
            s+=a[i];
    cout<<s;
    return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#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>
using namespace std;

const int MOD = 1000000007;

int main()
{
    int n, len;
    cin >> n >> len;
    vector<int> x(n), a(n);
    for(int i=0; i<n; ++i)
        cin >> x[i];
    for(int i=0; i<n; ++i)
        cin >> a[i];

    vector<int> dp(len+1, 0);
    dp[0] = 1;
    for(int i=0; i<n; ++i){
        vector<int> nextDp(len+1, 0);
        int sum = 0;
        for(int j=0; j<len; ++j){
            sum += dp[j];
            sum %= MOD;
            if(x[i] <= j && (a[i] == 0 || (j - x[i]) % a[i] == 0)){
                nextDp[j+1] = sum;
                nextDp[j+1] %= MOD;
                if(a[i] == 0)
                    break;
            }
        }
        dp.swap(nextDp);
    }

    int ans = 0;
    for(int i=0; i<=len; ++i){
        ans += dp[i];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1272
object Main extends App {
  val sc = new java.util.Scanner(Console.in)

  def next() = sc.next
  def nextInt() = Integer.parseInt(next)
  def nextDouble() = java.lang.Double.parseDouble(next)

  def solve(n: Int): Unit = {
    if (n > 0) {
      val xs = List.fill(n)(nextDouble)
      val m = xs.sum / n
      val aa = xs.fold(0.0) { (z, e) => z + (e - m) * (e - m) } / n
      println(math.sqrt(aa))
      solve(nextInt)
    }
  }

  solve(nextInt)
}



Measured memory_bytes: 49944
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int O = (m+1)/2;
    int E = m-O;
    for (int i = 1; i <= O; i++){
        printf("%d %d\n",i,2*O+1-i);
    }
    for (int j = 1; j <= E; j++){
        printf("%d %d\n",2*O+j,2*O+2*E+2-j);
    }
}


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

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

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

  int a, b, c;
  cin >> a >> b >> c;

  cout << min(a + b, min(b + c, c + a)) << endl;
  return 0;
}


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

#define M 255

int main() {
  int n, c, t, ans;
  char buf[M+2];
  char a[M][M];
  while (1) {
    scanf("%d\n", &n);
    if (!n) break;

    for (int i=0; i<n; i++) {
      fgets(buf, sizeof(buf), stdin);
      for (int j=0; j<n; j++) {
        a[i][j] = (buf[j]=='0') ? 0 : 1;
      }
    }

    ans = 0;
    for (int i=0; i<n; i++) {
      c = 0;
      for (int j=0; j<n; j++) {
        if (a[i][j]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    for (int i=0; i<n; i++) {
      c = 0;
      for (int j=0; j<n; j++) {
        if (a[j][i]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    for (int s=0; s<2*n-1; s++) {
      c = 0;
      for (int i=0; i<n; i++) {
        t = s-i;
        if (t>=0 && t<n && a[i][t]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    for (int d=-n+1; d<n; d++) {
      c = 0;
      for (int i=0; i<n; i++) {
        t = i+d;
        if (t>=0 && t<n && a[i][t]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1100
import Data.List
import Data.Maybe (catMaybes)

deleteAny :: String -> [Maybe String]
deleteAny [] = []
deleteAny xs = map (`stripPrefix` xs) ["maerd", "remaerd", "esare", "resare"]

solve :: String -> String
solve xs = if null s then xs else solve (head s)
    where s = catMaybes $ deleteAny xs

main :: IO ()
main = do
    s <- reverse <$> getLine
    putStrLn $ if null (solve s) then "YES" else "NO"


Measured memory_bytes: 7548
object Main {
  def SelectionSort(A: Array[Int]):(Int,Array[Int]) = {
    var count = 0
    def swap(i: Int, j: Int){
      if(i != j){
        count += 1
      }
      val tmp = A(i)
      A(i) = A(j)
      A(j) = tmp
    }

    for(i <- 0 to A.length - 1){
      var mini = i
      for(j <- i + 1 to A.length - 1){
        if (A(j) < A(mini)){
          mini = j
        }
      }
      swap(i,mini)
    }
    (count,A)
  }


  def main(args: Array[String]){
    val N = readLine().map(_.toInt)
    val input = readLine().split(" ").map(_.toInt).toArray
    val result = SelectionSort(input)
    println(result._2.mkString(" "))
    println(result._1)
  }
}

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

int l, n, m;
int main() {
	int i, k;
	cin>>l;
	for(n=1; 1<<n <= l; n++);
	for(i=n-1; i; i--) if(l&1<<i-1) m++;
	printf("%d %d\n", n, 2*n+m-2);
	for(i=1; i<n; i++) {
		printf("%d %d %d\n", i, i+1, 0);
		printf("%d %d %d\n", i, i+1, 1<<i-1);
	}
	for(i=n-1, k=1<<n-1; i; i--) {
		if(l&1<<i-1) printf("%d %d %d\n", i, n, k), k += 1<<i-1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    long long int a,b,n,lcm;
    while (scanf ("%lld %lld",&a,&b)!=EOF)
    {
        n=__gcd(a,b);
        lcm=(a*b)/n;
        cout<<n<<" "<<lcm<<endl;
    }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define r(i, n) for (int i=1;i<n;i=+2)
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b;
  c=a*b;
  if (a>=10 || b>=10) c=-1;
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    rep(i, 0, n) {
        ll h;
        cin >> h;
        if(h >= k) ans++;
    }    
    cout << ans << endl;
}

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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
using namespace std;
using ll = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll gcd(ll a, ll b)
{
  if (a < b)
  {
    return gcd(b, a);
  }
  while (b != 0)
  {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N, M;
    cin >> N >> M;

    priority_queue<int, vector<int>, less<int>> q;
    loop(0, N, i) {
      int tmp;
      cin >> tmp;
      q.push(tmp);
    }

    loop(0, M, i) {
      int top = q.top() / 2;
      q.pop();
      q.push(top);
    }

    ll sum = 0;
    loop(0, N, i) {
      int nx = q.top();
      q.pop();
      sum += nx;
    }
    print(sum);
}

Measured memory_bytes: 3884
from collections import deque
alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

S=input()
N=len(S)

dic={moji:deque([]) for moji in alphabetlist}
for i in range(N):
    dic[S[i]].append(i+1)

left=deque([])
right=deque([])
mid=[]

if N%2==1:
    check=0
    memo=0
    for moji in dic:
        if len(dic[moji])%2==1:
            k=len(dic[moji])
            check+=1
            memo=dic[moji][k//2]
    if check!=1:
        print(-1)
        exit()
    else:
        mid.append(memo)
else:
    check=0
    for moji in dic:
        if len(dic[moji])%2==1:
            print(-1)
            exit()

for i in range(N//2):
    for moji in alphabetlist:
        if len(dic[moji])>=2:
            L=dic[moji][0]
            R=dic[moji][-1]
            for moji2 in alphabetlist:
                if len(dic[moji2])>=2 and dic[moji2][0]<L<R<dic[moji2][-1]:
                    break
            else:
                left.append(L)
                right.appendleft(R)
                dic[moji].popleft()
                dic[moji].pop()
                break

ans=list(left)+mid+list(right)
n=N
#A1 ... AnのBIT(1-indexed)
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

res=0
for i in range(N):
    res+=i-BIT_query(ans[i])
    BIT_update(ans[i],1)

print(res)

Measured memory_bytes: 60748
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

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

int main(){
    double l;
    cin >> l;
    double ans = l*l*l/27;
    printf("%.12f\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll w,h;cin >> w >>h;
    if(w%3==0||h%3==0){
        cout << 0 <<endl;
        return 0;
    }
    if(w*h==4){
        cout << 1 <<endl;
        return 0;
    }
    ll ans=min(h,w);
    rep(i,w){
        ll a=i*h;
        ll b=(w-i)*(h/2);
        ll c=h*w-a-b;
        ll x=min(a,b);
        x=min(x,c);
        ll y=max(a,b);
        y=max(y,c);
        ans=min(ans,y-x);
    }
    swap(h,w);
        rep(i,w){
        ll a=i*h;
        ll b=(w-i)*(h/2);
        ll c=h*w-a-b;
        ll x=min(a,b);
        x=min(x,c);
        ll y=max(a,b);
        y=max(y,c);
        ans=min(ans,y-x);
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
import math
import bisect
import heapq
from collections import deque

n, m = map(int, input().split())

p = [[0] * n for _ in range(n)]

c, d = [0] * m, [0] * m
for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    c[i],d[i] = a,b

    p[a][b], p[b][a] = 1, 1


def dfs(p,n):
    seen = [False] * n
    s = 0
    deq = deque([0])
    while deq:
        s = deq.pop()
        seen[s] = True
        for i in range(n):
            if p[s][i] == 0 or seen[i]:
                continue
            deq.append(i)

    for i in range(n):
        if not seen[i]:
            return 1
    return 0


ans = 0

for i in range(m):
    a,b = c[i],d[i]
    p[a][b], p[b][a] = 0, 0

    ans += dfs(p,n)
    p[a][b], p[b][a] = 1, 1

print(ans)


Measured memory_bytes: 3316
N = [int(_) for _ in input()]
dp = [[0, 0] for _ in range(len(N))]
dp[0][0] = min(N[0], 11 - N[0])
dp[0][1] = min(N[0] + 1, 10 - N[0])
for i in range(1, len(N)):
    dp[i][0] = min(dp[i - 1][0] + N[i], dp[i - 1][1] + 10 - N[i])
    dp[i][1] = min(dp[i - 1][0] + N[i] + 1, dp[i - 1][1] + 9 - N[i])
print(dp[-1][0])


Measured memory_bytes: 169048
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define swap(a,b,t)(t=a,a=b,b=t)

ll a[200010];
ll num[200010];

int main(){
	int n,x;
	scanf("%d%d",&n,&x);
	
	if(x==1||x==2*n-1){
		puts("No");
		return 0;
	}
	if(n==2){
		puts("Yes\n1\n2\n3");
		return 0;
	}
	
	puts("Yes");
	if(x==2){
		a[n-2]=4;
		a[n-1]=1;
		a[n  ]=2;
		a[n+1]=3;
		num[4]=num[1]=num[2]=num[3]=1;
	}else{
		a[n-2]=x-2;
		a[n-1]=x+1;
		a[n  ]=x;
		a[n+1]=x-1;
		num[x-2]=num[x+1]=num[x]=num[x-1]=1;
	}
	ll t=1;
	rep(i,1,2*n)if(!a[i]){
		while(num[t])t++;
		a[i]=t;
		num[t]=1;
	}
	rep(i,1,2*n)printf("%lld\n",a[i]);
	return 0;
}

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

using namespace std;

int main() {
	long long L, R;
	cin >> L >> R;
	if (R - L >= 2019) {
		cout << "0" << endl;
		return 0;
	}
	long long modL;
	long long modR;
	modL = L % 2019;
	modR = R % 2019;
	long long ans = 2020;
	if (modL > modR) cout << "0" << endl;
	else {
		for (long long i = modL; i < modR; i++) {
			for (long long j = i + 1; j < modR + 1; j++) {
				if ((i * j) % 2019 < ans) ans = (i * j) % 2019;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    int x, y;
    while (true) {
        cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        }
        if (x>y) {
            swap(x,y);
        }
        cout << x << " " << y << endl;
    }
    return 0;
}




Measured memory_bytes: 2976
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int  c = N % 10;
    if(c == 2 || c == 4 || c == 5  || c == 7 || c == 9)
        cout << "hon";
    else if(c == 3)
        cout << "bon";
    else
        cout << "pon";
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;

int n, a, b, c;

int main()
{
	scanf ("%d", &n);
	a = n / 100;
	b = n % 10;
	if (a == b)	printf ("Yes\n");
	else printf ("No\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define SORT(x) sort(all(x))
#define RSORT(x) sort(all(x),greater<ll>())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  ll N;
  cin >> N;
  vll A(N);
  // set<ll> AS;
  ll max = 0;
  ll next_max = 0;
  rep(i,0,N){
    cin >> A[i];
    if(max < A[i]) max = A[i];
    else if(next_max < A[i]) next_max = A[i];
  }

  if(next_max == 0) next_max = max;

 
  rep(i,0,N){
    if(max != A[i]) print(max);
    else print(next_max);
  }

   
 return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
//One implementation to rule them all?
#define db              double
#define ll              long long int
#define ld                long long double
//#define int           long long int
#define ull             unsigned long long
#define fi              first
#define se              second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define repr(i,n,b)     for(int i=n;i>=b;i--)
#define endl            '\n'
#define mem(a,b)        memset(a, b, sizeof a)
#define mkp             make_pair
#define pb              push_back
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)          a.begin(), a.end()
#define sz(a)           int((a).size())
//Bitwise 
#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
//Can use tuples in C++17
using namespace std;
typedef vector < int > vii;
typedef vector < ll > vll;
typedef vector < vii > vvi;
typedef pair < int,int > pii;
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
const db PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
db eps       =          0.000001;
ll mod       =          (1e9+7);   //998244353
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=1e5+5;
bool judgePermutation(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}

int main(){ 
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//  cout.tie(NULL);
//  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
	
		
		int n;
		cin>>n;
		ll ans=0;
		rep(i,1,n+1) if(i%3 && i%5) ans+=i;
		cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, size) for (int i = start; i < size; i++)
#define FORR(i, start, size) for (int i = start; i > start-size; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
    int n,x0,y0,h0;
    cin >> n;
    vint x,y,h;

    FOR(i,0,n){
        int xi,yi,hi;
        
        cin >> xi >> yi >> hi;
        if (hi!=0){
            x0 = xi;
            y0 = yi;
            h0 = hi;
        }
        x.pb(xi);
        y.pb(yi);
        h.pb(hi);
    }
    
    bool finish = false;

    int pH,H;
    if (!(finish)){
        FOR(i,0,101){
            if(!(finish)){
                FOR(j,0,101){
                    bool flag = true;
                    FOR(k,0,n){
                        pH = abs(i-x0) + abs(j-y0) + h0;
                        H = abs(i-x[k]) + abs(j-y[k]) + h[k];
                        if (pH!=H){
                            if (h[k]==0 && pH - (abs(i-x[k]) + abs(j-y[k]) + h[k]) < 0){
                                continue;
                            }else{
                                flag = false;
                            }
                        }
                    }
                    if (flag){
                        cout << i << ' ' << j << ' ' << abs(i-x0) + abs(j-y0) + h0 << endl;
                        finish = true;
                    }
                }
            }
        }
    }

}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
    int n = s.Length;
		string answer = "";

    for(int i = 0; i < n; i++) answer += "x";

		Console.WriteLine(answer);
	}
}


Measured memory_bytes: 11092
#include<stdio.h>
int main(void)
{
	int x,ans;
	scanf("%d",&x);
	ans=x%7;
	if(ans==0){
		printf("thu\n");
	}
	else if(ans==1){
		printf("fri\n");
	}
	else if(ans==2){
		printf("sat\n");
	}
	else if(ans==3){
		printf("sun\n");
	}
	else if(ans==4){
		printf("mon\n");
	}
	else if(ans==5){
		printf("tue\n");
	}
	else if(ans==6){
		printf("wed\n");
	}
	return 0;
}


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

/*..DEFINITIONS .... */
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin>>tt; while(tt--)
#define mp make_pair
#define pb push_back
#define lchild (2*node+1)
#define rchild (2*node+2)
#define f first
#define s second
#define br cout<<endl
#define MOD (1000000007LL)
using namespace std;

/*...TYPEDEFS....*/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

/*...USEFUL FUNCTIONS....*/
ll gcd(ll a, ll b){
    if(b==0)return a;
    else gcd(b, a%b);
}
ll pwr(ll base, ll exp, ll mod=MOD){
    ll tmp = 1;
    while(exp > 0)
	{
        if(exp%2)
		{
			tmp=(tmp*base)%mod;
	    }
		base=(base*base)%mod;
		exp/=2;
    }
    return tmp;
}


int main(){
FIO
int n;
cin >> n;
int a[n];

for(int i=0; i<n; ++i){
    cin >> a[i];
}
deque<int> dq;
if(n&1){
    for(int i=0; i<n; ++i){
        if(!(i&1)){
            dq.push_front(a[i]);
        }
        else{
            dq.pb(a[i]);
        }
    }
}
else{
    for(int i=0; i<n; ++i){
        if(!(i&1)){
            dq.pb(a[i]);
        }
        else{
            dq.push_front(a[i]);
        }
    }
}
for(int i=0; i<dq.size(); ++i){
    cout << dq[i] << " ";
}
cout << "\n";







return 0;
}


Measured memory_bytes: 3840
from itertools import combinations

while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    else:
        cnt = 0
        c = combinations(range(1, n+1), 3)
        for i, j, k in c:
            if i + j + k == x:
                cnt += 1
        print(cnt)


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

using namespace std;

int n, m, q;
long long cost;
int l[100010], h[100010];

struct edge
{
    int u, v;
    long long w;
    bool operator < (const edge& other) const
    {
        return w < other.w;
    }
} e[400010];

int Find(int x)
{
    return x == l[x] ? x : l[x] = Find(l[x]);
}

int Union(int u, int v)
{
    if ((u = Find(u)) == (v = Find(v))) return 0;
    if (h[u] < h[v]) swap(u, v);
    l[v] = u;
    h[u] += h[v];
    return 1;
}

int in[100010], out[100010], par[100010][15], times;
long long rmq[100010][15], c[100010];
vector <pair <int, long long> > adj[100010];

void dfs(int u, int p)
{
    in[u] = ++times;
    par[u][0] = p;
    for (int i = 1; i < 15; ++i)
        par[u][i] = par[par[u][i - 1]][i - 1];
    rmq[u][0] = c[u];
    for (int i = 1; i < 15; ++i)
        rmq[u][i] = max(rmq[u][i - 1], rmq[par[u][i - 1]][i - 1]);
    for (int i = 0; i < adj[u].size(); ++i)
    {
        int v = adj[u][i].first;
        long long w = adj[u][i].second;
        if (v == p) continue;
        c[v] = w;
        dfs(v, u);
    }
    out[u] = times;
}

int check(int u, int v)
{
    return (in[u] <= in[v] && out[v] <= out[u]);
}

int LCA(int u, int v)
{
    if (check(u, v)) return u;
    for (int i = 14; i + 1; --i)
        if (par[u][i] && !check(par[u][i], v)) u = par[u][i];
    return par[u][0];
}

long long calc(int u, int w)
{
    long long res = 0;
    for (int i = 14; i + 1; --i)
        if (par[u][i] && check(w, par[u][i]))
        {
            res = max(res, rmq[u][i]);
            u = par[u][i];
        }
    return res;
}

void Kruskal()
{
    for (int i = 1; i <= n; ++i) l[i] = i, h[i] = 1;
    sort(e + 1, e + m + 1);
    for (int i = 1; i <= m; ++i)
        if (Union(e[i].u, e[i].v))
        {
            adj[e[i].u].push_back({e[i].v, e[i].w});
            adj[e[i].v].push_back({e[i].u, e[i].w});
            cost += e[i].w;
        }
}

int main()
{
//    freopen("ELECTRIC.inp", "r", stdin);
//    freopen("ELECTRIC.out", "w", stdout);

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

    cin >> n >> m;

    for (int i = 1; i <= m; ++i)
        cin >> e[i].u >> e[i].v >> e[i].w;
    Kruskal();
    dfs(1, 0);

    cin >> q;
    while (q--)
    {
        int u, v;
        cin >> u >> v;
        int w = LCA(u, v);
        cout << cost - max(calc(u, w), calc(v, w)) << "\n";
    }
}




Measured memory_bytes: 13248
n=int(input())
a=list(map(int, input().split()))
b=[0 for _ in range(n)]
if n%2!=0:
    for i in range(n):
        if i%2==0:
            b[n//2-i//2]=str(a[i])
        else:
            b[n//2+i//2+1]=str(a[i])
else:
    for i in range(n):
        if i%2==0:
            b[n//2+i//2]=str(a[i])
        else:
            b[n//2-i//2-1]=str(a[i])
print(' '.join(b))

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

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    rep(i,n){
        printf("%d", a[n-1-i]);
        if(i < n-1)cout << " ";
        else cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3224
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define REP(i,begin,end) for(int i=begin;i<=end;i++)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

#define MAXN 100002

int n;
int h[MAXN], sol[MAXN];

int main(){
fio

cin >> n;
REP(i,1,n) cin >> h[i];

sol[1] = 0;
sol[2] = abs(h[2]-h[1]);

REP(i,3,n) sol[i] = min(sol[i-1]+abs(h[i]-h[i-1]), sol[i-2]+abs(h[i]-h[i-2]));

cout << sol[n] << endl;
return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    H, W = MI()
    costs = []

    for i in range(10):
        cost_row = LI()
        costs.append(cost_row)

    for k in range(10):
        for i in range(10):
            for j in range(10):
                costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j])

    ans = 0
    for _ in range(H):
        row = LI()
        for item in row:
            if item == -1:
                continue
            ans += costs[item][1]

    print(ans)


main()


Measured memory_bytes: 73840
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<cstring>
typedef long long ll;
const ll MAXN=2*1e5+10;
const int INF=0x7fffffff; 

using namespace std;

struct VER{
	int x,step;
};
int n,m;
int vis[MAXN]={0};
vector<int> arry[MAXN];

void search(){
	queue<VER> q;
	VER v;
	v.x=1,v.step=0;
	q.push(v);
	int flag=1;
	while(!q.empty()&&flag){
		v=q.front();
		q.pop();
		int posx=v.x,postep=v.step;
		vis[posx]=postep;
		if(postep>2)
			continue;
		int size=arry[posx].size();
		for(int i=0;i<size;i++){
			int gox=arry[posx][i];
			if(gox==n&&postep+1<=2){
				cout<<"POSSIBLE"<<endl;
				flag=0;
				break;
			}
			if(vis[gox]==INF){
				vis[gox]=postep+1;
				v.x=gox;
				v.step=postep+1;
				q.push(v);
			}
			
		}
	}
	if(flag){
		cout<<"IMPOSSIBLE"<<endl;
	}
}

int main(){
	
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		vis[i]=INF;
	}
	for(int i=1;i<=m;i++){
		int a,b;
		cin>>a>>b;
		arry[b].push_back(a);
		arry[a].push_back(b);
	}
	search();
	return 0;
} 

Measured memory_bytes: 13552
#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include <algorithm>
//#include "../cxx-prettyprint/prettyprint.hpp"

std::vector<std::pair<int, int>> edges;
std::vector<std::set<int>> graph_original;
std::vector<std::set<int>> graph;
std::vector<bool> visited;

bool can_reach(int a, int b) {
    visited[a] = true;
    if (graph[a].empty()) {
        return false;
    } else if (std::find(graph[a].begin(), graph[a].end(), b) != graph[a].end()) {
        return true;
    } else {
        for (int next : graph[a]) {
            if (visited[next]) continue;
            if (can_reach(next, b)) return true;
        }
        return false;
    }
}

int main() {
    int N, M;
    std::cin >> N >> M;

    graph_original.resize(N + 1);

    for (int i = 0; i < M; i ++) {
        int a, b;
        std::cin >> a >> b;
        edges.push_back({a, b});
        graph_original[a].insert(b);
        graph_original[b].insert(a);
    }

    int n_bridges = 0;
    for (auto edge : edges) {
        graph = graph_original;
        graph[edge.first].erase(edge.second);
        graph[edge.second].erase(edge.first);
        visited.assign(N + 1, false);

        bool is_bridge = !can_reach(edge.first, edge.second);
        n_bridges += is_bridge;
    }
    std::cout << n_bridges << std::endl;
}


Measured memory_bytes: 256
N,T = map(int,input().split())
mat = [list(map(int,input().split())) for i in range(N)]
for i in range(N):
    if mat[i][1] > T:
        mat[i][0] = 1001
ans = min([x[0] for x in mat])
if ans == 1001:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3060
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		StringBuilder s = new StringBuilder(sc.next());
		String t = sc.next(); boolean found = false;
		int sLen = s.length(), tLen = t.length();
		for (int i=sLen-1; i>=0; i--) {
			if ((s.charAt(i)=='?' || s.charAt(i)==t.charAt(0)) && (i+tLen)<=sLen) {
				boolean ok = true;
				int j=0;
				while (j<tLen) {
					if (!(s.charAt(i+j)=='?' || t.charAt(j)==s.charAt(i+j))) {
						ok=false; break;
					}	
					j++;
				}
				if (ok) {
					s.replace(i, i+tLen, t);
					found = true; break;
				}
			}	
		}
		System.out.println(found ? s.toString().replaceAll("\\?","a") : "UNRESTORABLE");
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35748
n,k,s=map(int,input().split())
ans=[]
i=0
if(s!=10**9):
    for _ in range(n):
        if(i<k):
            ans.append(s)
            i+=1
        else:
            ans.append(10**9)
else:
    for _ in range(n):
        if(i<k):
            ans.append(s)
            i+=1
        else:
            ans.append(1)

print(*ans)


Measured memory_bytes: 6720
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> v(n);
	for (ll i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	ll ans = 0;
	for (ll i = 0; i < k; i++) {
		ans += v[i];
	}
	cout << ans << endl;
}


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

typedef pair<int,int> P;

int main(){
  int n,w,d;
  int p,s;

  while(cin >> n >> w >> d , n||w||d){
    vector<P> v;
    v.push_back(P(w,d));
    
    for(int i=0;i<n;i++){
      cin >> p >> s;
      
      P tmp = v[p-1]; v.erase(v.begin()+p-1);
      s %= tmp.first + tmp.second;
      P p1,p2;
      if(s<tmp.first){
	p1 = P(min(s,tmp.first-s),tmp.second);
	p2 = P(max(s,tmp.first-s),tmp.second);
      }else{
	s -= tmp.first;
	p1 = P(tmp.first,min(s,tmp.second-s));
	p2 = P(tmp.first,max(s,tmp.second-s));
      }
      v.push_back(p1); v.push_back(p2);
    }

    vector<int> ans;
    for(int i=0;i<=n;i++)ans.push_back(v[i].first * v[i].second);
    sort(ans.begin(),ans.end());

    for(int i=0;i<n;i++)cout << ans[i] << " ";
    cout << ans[n] << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin >>s>>t;
  lol ans=inf;
  for(int i=0;i<(int)s.size()-t.size()+1;i++){
    int sum=0;
    for(int j=0;j<t.size();j++){
      if(s[i+j]==t[j]) sum++;
    }
    chmin(ans,(int)t.size()-sum);
  }
  cout <<ans<<'\n';
  return(0);
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int k;
char s[125252];
char sar[5*125252][10];

int comp(const void *a, const void *b){
  return strcmp(a,b);
}

int main(){
  scanf("%s%d",s,&k);
  int n = strlen(s);
  int it = 0;
  int i,len;  // c90
  for(i=0;i<n;i++){
    for(len=1;len<=5;len++)if(i+len<=n){
      strncpy(sar[it], s+i, len);
      sar[it][len] = '\0';
      it++;
    }
  }
  qsort(sar, it, sizeof(*sar), comp);
  int cnt = 0;
  for(i=0;i<it;i++){
    if(i==0 || strcmp(sar[i], sar[i-1])!=0){
      cnt++;
    }
    if(cnt == k){
      puts(sar[i]);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 2684