akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    n, x, y = map(int, input().split())
    x -= 1
    y -= 1
    inf = 10 ** 7
    ans = [0 for _ in range(n)]

    # See:
    # https://www.youtube.com/watch?v=zG1L4vYuGrg&feature=youtu.be
    # KeyInsight:
    # △: 全探索 + 深さ優先探索
    # ×: どのように実装すればいいか、見当がつかなかった
    for i in range(n):
        # グラフを陽に持たない場合
        # 始点からの距離を管理
        dist = [inf for _ in range(n)]  # 距離無限大で初期化
        dist[i] = 0

        # キューを用意して、頂点を管理
        d = deque()
        d.append(i)

        # BFS
        while d:
            v = d.popleft()  # 最も左側の内容(=最初に突っ込んだ値)を取り出す
            dj = dist[v]

            # 場合分け
            # 範囲外参照を回避しながら、次の頂点に移動したときの距離を計算
            if v - 1 >= 0 and dist[v - 1] == inf:
                dist[v - 1] = dj + 1
                # 次の頂点をキューに突っ込む
                d.append(v - 1)
            if v + 1 < n and dist[v + 1] == inf:
                dist[v + 1] = dj + 1
                d.append(v + 1)
            if v == x and dist[y] == inf:
                dist[y] = dj + 1
                d.append(y)
            if v == y and dist[x] == inf:
                dist[x] = dj + 1
                d.append(x)

        # 距離ごとの個数を計算
        for j in range(n):
            ans[dist[j]] += 1

    # 始点と終点を区別
    for k in range(n):
        ans[k] //= 2

    # 答えを出力
    for ii in range(1, n):
        print(ans[ii])


if __name__ == '__main__':
    main()


Measured memory_bytes: 71604
#include <stdio.h>
#include <math.h>
#define N 10000
int isprime(int);
int main()
{
  int n,i,count=0,x;
  int array[N];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&array[i]);
      x=isprime(array[i]);
      if(x==1) count=count+1;
    }
  printf("%d\n",count);
  return 0;
}

int isprime(int x)
  {
    int i,count=0;
    if(x==2) return 1;
    if(x<2 || x%2==0) return 0;
      for(i=3;i<=sqrt(x);i++)
      {
       	if(x%i==0)
	  {
      return 0;
	  }
      }
      return 1;
  }

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

// A^2 - 2AK + K^2 = B^2 - 2BK + K^2
// (A^2 - B^2) = 2(A - B)K
// K = (A^2 + B^2) / 2(A - B)

int main() {
  i64 A, B;
  cin >> A >> B;
  
  i64 y = 2 * (A - B);
  i64 x = A * A - B * B;
  if (x % y == 0) {
    cout << x / y << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m] <- getIntList
    as <- getIntList
    let ss = scanl (\a b -> (a+b) `mod` m) 0 as
    let ans = sum . map (comb . length) . group $ sort ss
            where comb x = x * (x-1) `div` 2
    print ans

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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))

int main(){
  INT(n);
  vector<tuple<int, int, int>> xys;
  int hmax = 0;
  REP(n){
    INT(x); INT(y); INT(h); xys.EB(x, y, h);
    hmax = max(hmax, h);
  }
  REP(cx, 101){
    REP(cy, 101){
        REP(ch, hmax, hmax + 201){
          bool ok = true;
          for(auto tpl: xys){
          int x, y, h; tie(x, y, h) = tpl;
          if (max(ch - abs(x - cx) - abs(y - cy), 0) != h){
            ok = false; break;
          }
        }
        if (ok){
          printf("%d %d %d\n", cx, cy, ch);
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
Option Strict On

Module Module1
    Dim N As String
    Dim i, j, k As Int32

    Sub Main()
        N = Console.ReadLine()

        While i <= 9
            k = 0
            For j = 0 To 3
                If CInt(N(j) & "") = i Then
                    k += 1
                Else
                    k = 0
                End If

                If k >= 3 Then Exit While
            Next
            i += 1
        End While

        Console.WriteLine(
            New String() {"No", "Yes"}(k \ 3)
        )

    End Sub
End Module

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, m, x;
  cin >> n >> m >> x;

  vector<ll> c(n);
  vector<vector<ll>> a(n, vector<ll>(m));
  for (ll i = 0; i < n; ++i) {
    cin >> c[i];
    for (ll j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }

  function<void(ll&, ll, vector<ll>, ll)> solve;
  solve = [&](ll &ans, ll pos, vector<ll> seen, ll money) {
    if (pos == n){
      ll cnt = 0;
      bool ok = true;
      for (ll i = 0; i < m; ++i) {
        if (seen[i] < x) ok = false;
      }
      if (ok) ans = min(ans, money);
      return;
    }

    auto next_seen = seen;
    for (ll i = 0; i < m; ++i) {
      next_seen[i] += a[pos][i];
    }
    solve(ans, pos+1, next_seen, money+c[pos]);
    solve(ans, pos+1, seen, money);
  };

  ll ans = 1e18;
  vector<ll> seen(m); 
  solve(ans, 0, seen, 0);

  if (ans == 1e18) ans = -1;
  cout << ans << endl;

  return 0;
}


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

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

    int red = 0;
    int blue = 0;
    rep(i, s.size()){
        if(s[i] == '0') red++;
        else blue++;
    }

    cout << 2*min(red, blue) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
const int MAXN = 2e5 + 10;
using namespace std;
int n;
int A[MAXN], B[MAXN], ta[MAXN], tb[MAXN], sa, sb, tot = 0, Do[MAXN], fa[MAXN];
int find(int x) {
    return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);
}
int unionn(int x, int y) {
    fa[x] = y;
}
int main() {
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)scanf("%d",&A[i]),sa ^= A[i]; A[n + 1] = sa;
    for(int i = 1; i <= n; i++)scanf("%d",&B[i]),sb ^= B[i]; B[n + 1] = sb;
    n++;
    memcpy(ta, A, sizeof(A)); memcpy(tb, B, sizeof(B));
    sort(ta + 1, ta + n + 1); sort(tb + 1, tb + n + 1);
    for(int i = 1; i <n; i++) if(ta[i] != tb[i]) return puts("-1"), 0;
 
    int ans = 0, sum = 0;
    for(int i = 1; i <= n; i++) 
        if(A[i] != B[i] || (i == n)) {
            Do[++sum] = A[i]; Do[++sum] = B[i];
            if(i < n)ans++;
        }
    if(ans == 0) return puts("0"), 0;
 
    sort(Do + 1, Do + sum + 1);
    sum = unique(Do + 1, Do + sum + 1) - Do - 1;
    for(int i = 1; i <= sum; i++) fa[i] = i;
    for(int i = 1; i <= n; i++)
        if(A[i] != B[i]) {
            A[i] = lower_bound(Do + 1, Do + sum + 1, A[i]) - Do;
            B[i] = lower_bound(Do + 1, Do + sum + 1, B[i]) - Do;
            unionn(find(A[i]), find(B[i]));
        }
 
    for(int i = 1; i <= sum; i++)
        if(fa[i] == i) ans++;
    printf("%d", ans - 1);
 
    return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b) cout << "a > b" << endl;
    else if (a < b) cout << "a < b" << endl;
    else cout << "a == b" << endl;
}


Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	/**
	 * @param args 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
//		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
//			String ss = br.readLine();
//			String tt = br.readLine();
			String ss = sc.nextLine();
			String tt = sc.nextLine();
			int[]s = new int[ss.length()];
			int[]t = new int[tt.length()];
			for(int i=0;i<s.length;i++){
				s[i] = ss.charAt(i);
			}
			for(int i=0;i<t.length;i++){
				t[i] = tt.charAt(i);
			}
			SuffixArray sa = new SuffixArray(s);
			int left=-1,right=t.length+1;
			while(left<right-1){
				int len= (left+right)/2;
				boolean f = false;
				int[] sub = new int[len];
				for(int i=0;i<t.length;i++){
					if(i+len>t.length)break;
					for(int k=i;k<i+len;k++){
						sub[k-i]=t[k];
					}
					if(sa.contain(sub)){
						f=true;
						break;
					}
				}
				if(f){
					left=len;
				}
				else{
					right=len;
				}

			}
			System.out.println(left);
		}
	}

	static class SuffixArray {

		int n,k=1;
		Integer[] sa,rank,tmp;
		int[] s;

		SuffixArray(int[] _s) {
			s=_s;
			n = s.length;
			rank=new Integer[n+1];
			sa=new Integer[n+1];
			tmp=new Integer[n+1];
			for(int i=0;i<n;i++){
				sa[i]=i;
				rank[i]=s[i];
			}
			sa[n]=n;
			rank[n]=-1;

			for(k=1;k<=n;k<<=1){
				Arrays.sort(sa,new Comparator<Integer>(){
					@Override
					public int compare(Integer o1, Integer o2) {
						int r1=rank[o1];
						int r2=rank[o2];
						if(r1!=r2)return r1-r2;
						int r11=o1+k <= n ? rank[o1+k] : -1;
						int r22=o2+k <= n ? rank[o2+k] : -1;

						return r11-r22;
					}
				});
				tmp[sa[0]]=0;
				for(int i=1;i<=n;i++){
					tmp[sa[i]]=tmp[sa[i-1]]+ (compare(sa[i-1],sa[i])!=0?1:0);
				}
				for(int i=0;i<=n;i++){
					rank[i]=tmp[i];
				}
			}
		}

		/*
		 * s.contains(t)的な
		 */
		boolean contain(int[] t){
			return contain(s,sa,t);
		}

		private boolean contain(int[]s,Integer[] sa,int[] t){
			int a=0,b=s.length;
			while(b-a>1){
				int c = (a+b)/2;
				//			String sub = s.substring(sa[c], Math.min(sa[c]+t.length, s.length));
				if(compare(s,sa[c],Math.min(sa[c]+t.length, s.length),t)<0){
					a=c;
				}
				else{
					b=c;
				}
			}
			return compare(s,sa[b], Math.min(sa[b]+t.length, s.length),t)==0;
		}

		/*
		 * s.substring(i1,i2).compareTo(t) 的な
		 */
		private int compare(int[]s,int i1,int i2,int[] t){
			for(int i=i1;i<i2;i++){
				if(i-i1>=t.length){
					return 1;
				}
				if(s[i]!=t[i-i1]){
					return s[i]-t[i-i1];
				}
			}
			return (i2-i1)-t.length;
		}

		private int compare(Integer o1, Integer o2) {
			int r1=rank[o1];
			int r2=rank[o2];
			if(r1!=r2)return (r1-r2);
			int r11=o1+k <= n ? rank[o1+k] : -1;
			int r22=o2+k <= n ? rank[o2+k] : -1;

			return (r11-r22);
		}
	}
}

Measured memory_bytes: 68548
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
using namespace std;

//C

const int MAX_N = 1000000;
int prime[MAX_N];
bool is_prime[MAX_N + 1];

int sieve(int n){
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++)
	{
		if (is_prime[i]){
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = false;
		}
	}
	return p;
}

int main(){
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int ans = sieve(n);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 2468
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
    int n,m,sum=0;
    cin>>n;

    int t[n];
    for(int i=0; i<n; i++){
        cin>>t[i];
        sum += t[i];
    }

    cin>>m;
    int p[m],x[m];
    for(int i=0; i<m; i++){
        cin>>p[i]>>x[i];
        cout<<(sum-(t[p[i]-1]-x[i]))<<endl;
    }
    return 0;
}

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

int dx[] = {0,1};
int dy[] = {1,0};
int mp[1024][1024];
int dp[1024][1024];

int main()
{
	int H,W,N;
	while(cin>>H>>W>>N, H||W||N)
	{
		for(int y=0; y<H; y++)
		for(int x=0; x<W; x++)
		{
			cin >> mp[y][x];
		}

		memset(dp, 0, sizeof(dp));

		dp[0][0] = N-1;
		for(int y=0; y<H; y++)
		for(int x=0; x<W; x++)
		for(int i=0; i<2; i++)
		{
			int ny = y+dy[i];
			int nx = x+dx[i];
			if(ny<H && nx<W)
			{
				int s = (mp[y][x]==i?1:0);
				dp[ny][nx] += (dp[y][x]+s)/2;
			}
		}

		int y=0,x=0;
		while(y<H && x<W)
		{
			int s = (mp[y][x]+dp[y][x])%2;
			y = y+dy[s];
			x = x+dx[s];
		}

		cout << y+1 << " " << x+1 << endl;
	}
}

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

int main(){
  int a, b;

  cin >> a >> b;
  
  if (a == b) {
    cout << "a == b" << endl;
  }else if(a < b){
     cout <<  "a < b" << endl;
  }else{
    cout << "a > b" << endl;
  }
}

Measured memory_bytes: 1160
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)

"""
A = [10,4,8,7,3]
is_left_end = [1,0,1,0,0]
left_idx = [0,0,2,2,2]
というものを作る
"""
is_left_end = np.empty(N, dtype=np.bool)
is_left_end[0] = 1
is_left_end[1:] = (A[1:] > A[:-1])


left_idx = np.where(is_left_end, np.arange(N), 0) # [0,0,2,0,0]
np.maximum.accumulate(left_idx, out=left_idx) # [0,0,2,2,2]

answer = (np.arange(N) - left_idx).max()
print(answer)

Measured memory_bytes: 24300
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,p[30],m=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
	}
	for(int i=1;i<n-1;i++)
	{
		if(((p[i]>p[i-1])&&(p[i]<p[i+1]))||((p[i]>p[i+1])&&(p[i]<p[i-1])))
		{
			m++;
		}
	}
	cout<<m<<endl;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

const val YES = "Yes"
const val NO = "No"
fun solve(N: Int, H: IntArray){
    var ret = H[0] - 1
    for (i in 1 until N){
        if (H[i] > ret){
            H[i] -= 1
        }else if (H[i] < ret){
            println(NO)
            return
        }
        ret = H[i]
    }
    println(YES)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val H = IntArray(N)
    for (i in 0 until N) {
        H[i] = sc.next().toInt()
    }
    solve(N, H)
}



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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	if(n%10 ==9 || n/10 == 9) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}



Measured memory_bytes: 892
while True:
	try:
		a,b,c,d,e,f = map(float, input().split())
		z = a*e - b*d
		if z != 0:
			y = (a*f - c*d) / z
			x = (c*e - b*f) / z
			print("{:.3f} {:.3f}".format(x+0,y+0))
	except:
		break

Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int bannum = sc.nextInt();
		String keyword = sc.next();
		String kanban;
		int cnt = 2;
		int knum = 0;
		for(int s = 0;s < bannum;s++){
			kanban = sc.next();
			loop:for(int i = 0; kanban.length()-i > keyword.length()-1;i++){
				if(keyword.charAt(0) == kanban.charAt(i)){
					for(int j = kanban.length()-1;j-i>=keyword.length()-1;j--){
						if(keyword.charAt(keyword.length()-1) == kanban.charAt(j)){
							cnt = 2;
							for(int k = 1;k <= keyword.length()-1;k++){
								//System.out.println(keyword.charAt(k));
								//System.out.println(kanban.charAt((j-i)/(keyword.length()-1)*k+i));
								if(keyword.charAt(k) == kanban.charAt((j-i)/(keyword.length()-1)*k+i)){
									cnt++;
									if(cnt-1 == keyword.length()){
										knum++;
										break loop;
									}								
								}
							}
						}
					}
				}
			}			
		}
		System.out.println(knum);
/*		if(cnt-1 == keyword.length()){
			System.out.print("?????£??????");
		}
	*/	
		
	}

}

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

using namespace std;

int main(int argc, const char * argv[]) {
    int N = 0;
    int D = 0;
    cin >> N >> D;

    int interval = 2*D+1;

    cout << (N+interval-1)/interval << endl;

    return 0;
}

/**
 cheat sheet

 vector<int> v{ 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
 sort(v.begin(), v.end());
 => 0 1 2 3 4 5 6 7 8 9

 vector<int> v{ 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
 sort(v.begin(), v.end(), greater<int>());
 => 9 8 7 6 5 4 3 2 1 0

 struct A { int x, y; };
 bool comp(A i1, A i2) { return (i1.y < i2.y); }
 vector<A> v { { 6, 8 }, { 1, 9 }, { 2, 4 }, { 4, 7 } };
 sort(v.begin(), v.end(), comp);
 => [1, 9] [2, 4] [4, 7] [6, 8]

 */


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int[] sary = new int[6];
		String rollpattern;

		Scanner stdIn = new Scanner(System.in);

		for (int i = 0; i < sary.length; i++) {
			sary[i] = stdIn.nextInt();
		}
		stdIn.nextLine();
		rollpattern = stdIn.nextLine();

		Dice dice = new Dice(sary[0], sary[1], sary[2], sary[3], sary[4], sary[5]);
		dice.rollPattern(rollpattern);
		System.out.println(dice.getTop());

		stdIn.close();
	}
}

class Dice {
	private int top;
	private int front;
	private int right;
	private int left;
	private int back;
	private int bottom;

	int temp;

	public Dice(int top, int front, int right, int left, int back, int bottom) {
		super();
		this.top = top;
		this.front = front;
		this.right = right;
		this.left = left;
		this.back = back;
		this.bottom = bottom;
	}

	public void rollPattern(String rollpattern) {
		for (int i = 0; i < rollpattern.length(); i++) {
			roll(rollpattern.charAt(i));
					}
	}

	public void roll(char x) {
		switch (x) {
		case 'N':
			rollNorth();
			break;
		case 'S':
			rollSorth();
			break;
		case 'W':
			rollWest();
			break;
		case 'E':
			rollEast();
			break;
		default:
			System.exit(1);
			break;
		}
	}

	private void rollNorth() {
		temp = top;
		top = front;
		front = bottom;
		bottom = back;
		back = temp;
	}

	private void rollSorth() {
		temp = top;
		top = back;
		back = bottom;
		bottom = front;
		front = temp;
	}

	private void rollWest() {
		temp = top;
		top = right;
		right = bottom;
		bottom = left;
		left = temp;
	}

	private void rollEast() {
		temp = top;
		top = left;
		left = bottom;
		bottom = right;
		right = temp;
	}

	public int getTop() {
		return top;
	}
}

Measured memory_bytes: 26316
num = list(map(int, input().split()))

def getEuclideanAlgorithm(i, j):
    r = i % j
    while (r != 0):
        i = j
        j = r
        r = i % j
    return j

if (num[0] < num[1]):
    gcd = getEuclideanAlgorithm(num[1], num[0])
else:
    gcd = getEuclideanAlgorithm(num[0], num[1])

print(int((num[0] * num[1]) / gcd))

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

using namespace std;

int noNumbers;
int div1 , div2 , div4 ;
int main(){


    scanf("%d",&noNumbers);


    for ( int i = 0 ; i < noNumbers ; i++ ){
        int x ;
        scanf("%d",&x);

        if ( x % 4 == 0 ){
            div4++;
        }else if ( x % 2 == 0 ){
            div2++;
        }else{
            div1++;
        }

    }

    if ( div2 == 0 ){
        div2 = 1;
    }else{
        div2 = 0;
    }

    if ( div4 + div2 >= div1 ){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
    int n;cin>>n;
    ll a;
    map<int,int> map;
    int count=0;
    rep(i,n){
      int a;
      cin>>a;
      map[a]++;
    }
    for(auto p:map){
        if(p.second%2!=0)count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 4864
N, M = map(int,input().split())
H = list(map(int, input().split()))

C = [1 for _ in range(N)]

for i in range(M):
  A, B = map(int, input().split())
  A -= 1
  B -= 1
  if H[A] >= H[B]:
    C[B] = 0
  if H[A] <= H[B]:
    C[A] = 0
  #print(C)
    
print(sum(C))

Measured memory_bytes: 20100
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>

using namespace std;


int main() {
	int x;
	cin >> x;
	if (x >= 400 && x <= 599)cout << '8';
	if (x >= 600 && x <= 799)cout << '7';
	if (x >= 800 && x <= 999)cout << '6';
	if (x >= 1000 && x <= 1199)cout << '5';
	if (x >= 1200 && x <= 1399)cout << '4';
	if (x >= 1400 && x <= 1599)cout << '3';
	if (x >= 1600 && x <= 1799)cout << '2';
	if (x >= 1800 && x <= 1999)cout << '1';

}

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

int main()
{
  int n, w;
  while (cin >> n >> w && n != 0) {
    vector<int> hist(100*n);
    for (int i = 0; i < n; i++) {
      int v;
      cin >> v;
      hist[v/w]++;
    }
    int leftist = 0;
    for (int i = 0; i < 100*n; i++) {
      if (hist[i] != 0) {
        leftist = i;
      }
    }
    const double m = *max_element(hist.begin(), hist.end());
    double ans = 0.01;
    for (int i = 0; i <= leftist; i++) {
      double color = double(leftist-i)/leftist;
      double prop = hist[i] / m;
      ans += color*prop;
    }
    printf("%.6f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();
    println!("{}", b + std::cmp::min(c, a + b + 1));
}

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


Measured memory_bytes: 4352
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        long ans = 0;
        for(int i=0;i<N;i++){
            A[i] = sc.nextLong();
            if(i != 0 && A[i-1] > A[i]){
                ans += A[i-1] - A[i];
                A[i] = A[i-1];
            }

        }

        System.out.println(ans);


    }

}




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

using namespace std;
typedef long long ll;

const int N = int(1e8) + 7;

void init(){

}

void solve(){
    ll a, b;
    scanf("%lld %lld", &a, &b);
    if((a+b)%2 == 0)
        printf("%lld\n", (ll)((a+b)/2));
    else
        printf("IMPOSSIBLE\n");
}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}



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

int main() {

  while( true ) {

    long long int h, w;
    cin >> w >> h;
    if ( h == 0 ) break;

    vector< vector< long long int > > v;

    for ( long long int i = 0; i < h; i++ ) {

      vector< long long int > vv;

      for ( long long int j = 0; j < w; j++ ) {

	long long int in;
	cin >> in;
	vv.push_back( in );

      }

      v.push_back( vv );

    }

    long long int c[4];
    for ( long long int i = 0; i < 4; i++ ) {
      cin >> c[i];
    }

    priority_queue< pair< long long int, pair< pair< long long int, long long int >, long long int > > > q;

    long long int dp[31][31][4] = {};
    for ( long long int i = 0; i < w; i++ ) {
      for ( long long int j = 0; j < h; j++ ) {
	for ( long long int k = 0; k < 4; k++ ) {
	  dp[j][i][k] = 1000000000000000;
	}
      }
    }

    q.push( make_pair( 0, make_pair( make_pair( 0, 0 ), 1 ) ) );

    while( true ) {

      long long int p = q.top().first;
      long long int y = q.top().second.first.first;
      long long int x = q.top().second.first.second;
      long long int d = q.top().second.second;

      q.pop();

      if ( dp[y][x][d] <= p ) continue;
      dp[y][x][d] = p;

      if ( y == h - 1 && x == w - 1 ) {
	cout << -p << endl;
	break;
      }

      long long int dx[4] = {  0,  1,  0, -1 };
      long long int dy[4] = { -1,  0,  1,  0 };
      long long int k = v[y][x];
      long long int dd = ( d + k ) % 4;
      long long int mx = x + dx[dd];
      long long int my = y + dy[dd];
      if ( 0 <= mx && mx < w && 0 <= my && my < h && k != 4 ) {
	q.push( make_pair( p, make_pair( make_pair( my, mx ), dd ) ) );
      }
      for ( long long int i = 0; i < 4; i++ ) {
	dd = ( d + i ) % 4;
	mx = x + dx[dd];
	my = y + dy[dd];
	if ( 0 <= mx && mx < w && 0 <= my && my < h ) {
	  q.push( make_pair( p - c[i], make_pair( make_pair( my, mx ), dd ) ) );
	}
      }

    }

  }

  return 0;

}

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int n,m;
    cin>>n>>m;
    vector<int> g(n);
    for(int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a]++;
        g[b]++;
    }
    for(int i=0;i<n;i++) {
        cout<<g[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define vecin(n, a) rep(i, n)scanf("%d", &a[i])

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int a, b, k;
	scanf("%d%d%d", &a, &b, &k);
	int count = 0;
	repr(i, max(a, b)) {
		if (a % i == 0 && b % i == 0) {
			++count;
		}
		if (count == k) {
			printf("%d\n", i);
			return 0;
		}
	}

	Please AC;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n1,n2,n3;
	scanf ("%d %d %d",&n1,&n2,&n3);
	if (n1==n2&&n2==n3&&n1==n3) {
		printf ("No\n");
	}
	else if (n1!=n2&&n2!=n3&&n1!=n3){
		printf ("No\n");
	}
	else {
		printf ("Yes\n");
	}
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

int main(){
    long A,V;
    std::cin >> A >> V;
    long B,W;
    std::cin >> B >> W;
    long T;
    std::cin >> T;
    long dis = abs(A-B);
    if((V-W)*T>=dis){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

  string arr[] = {"KIH", "B", "R"};

  bool ok=false;
  REP(bit, 1<<4){
    string tmp;
    REP(j,3){
      if(bit & 1<<j)tmp += "A";
      tmp += arr[j];
    }
    if(bit & 1<<3)tmp += "A";
    if(tmp == s)ok=true;
  }
  cout << (ok ? "YES" : " NO") << endl;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;

int main(){
    int a[5];
    rep(i,5){
        cin >> a[i];
        if(a[i]==0){
            cout << i+1;
        }
    }
	return 0;
}



Measured memory_bytes: 3604
#include<stdio.h>
int main(){
int a,c[7],i,j;
double b;
for(i=0;i<6;i++){
c[i]=0;
}
scanf("%d\n",&a);
for(i=0;i<a;i++){
scanf("%lf\n",&b);
if(b<165){
c[0]++;
}
else if(b<170){
c[1]++;
}
else if(b<175){
c[2]++;
}
else if(b<180){
c[3]++;
}
else if(b<185){
c[4]++;
}
else{
c[5]++;
}
}
for(i=0;i<6;i++){
printf("%d:",i+1);
for(j=0;j<c[i];j++){
printf("*");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 1904
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>

typedef long long int64;

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> ds;
  for (int i = 0; i < n; i++) {
    int d;
    std::cin >> d;
    ds.push_back(d);
  }

  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (i != j) {
        sum += ds.at(i) * ds.at(j);
      }
    }
  }

  std::cout << sum << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,m,g[15][15],a[1<<15],dp[15][1<<15];
int main(){
	n=read(),m=read();
	for(int i=0;i<m;i++){
		int x=read()-1,y=read()-1,z=read();
		g[x][y]=g[y][x]=z;
	}
	for(int i=0;i<1<<n;i++){
		a[i]=0;
		for(int j=0;j<n;j++)
			for(int k=j+1;k<n;k++)
				if(i&(1<<j) and i&(1<<k))
					a[i]+=g[j][k];
	}
	memset(dp,-0x3f,sizeof(dp));
	for(int i=1;i<1<<n;i+=2)
		dp[0][i]=a[i];
	for(int i=0;i<1<<n;i++)
		for(int j=0;j<n;j++){
			if(dp[j][i]<0)continue;
			ll ab=(1<<n)-1-i;
			for(int p=ab;p>0;p=(p-1)&ab)
				for(int k=0;k<n;k++)
					if(g[j][k] and(p&(1<<k)))
						dp[k][i+p]=max(dp[k][i+p],dp[j][i]+a[p]+g[j][k]);
		}
	ll ans=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			ans+=g[i][j];
	printf("%lld",ans-dp[n-1][(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 4480
#83 連立方程式

while True:
    try:
        a, b, c, d, e, f = map(float,input().split())
    except:
        break
    
    x = (e*c - b*f) / (a*e - b*d)
    y = (c*d - a*f) / (b*d - a*e)
    
    if x == -0.0 :
        x = 0.0
    if y == -0.0 :
        y == 0.0
    print(f'{x:.3f}', f'{y:.3f}')


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

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}

const int INF=1e9;
const double eps=0.0000000001;

int main(){
  ll ans=1,n,v=0;
  cin >> n;
  ll a[1000000];
  FOR(i,n){
    cin >> a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);
  FOR(i,n-1){
    if(a[i]==a[i+1]){
      ans*=a[i];
      v++;
      i++;
      if(v==2){break;}
    }
  }
  if(v!=2){
    cout << 0 << endl;
  }else{
    cout << ans << endl;
  }
}


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

#define N ((ll)1e18)

int main(int argc, char const *argv[])
{
	long long a;
	string b;
	cin >> a >> b;
	b.erase(b.find('.'), 1);
	ll c = stoll(b);
	cout << (a*c)/100;
	return 0;
}


Measured memory_bytes: 3612
import java.util.*;

public class Main {
	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		int n = in.nextInt();
		double[] a = in.nextDoubleArray(n);
		double sum = 0;
		
		for (int i = 0; i < a.length; i++) {
			sum += 1/a[i];
		}
		
		System.out.println(1/sum);
		
	}
	
	private static class MyScanner {
		static Scanner sc = new Scanner(System.in);
		
		String next() {
			return sc.next();
		}
		
		String nextLine() {
			return sc.nextLine();
		}
		
		int nextInt() {
			return Integer.parseInt(sc.next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextInt();
			}
			return array;
		}
		
		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextDouble();
			}
			return array;
		}
		
		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}
			return array;
		}
		
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define chkmax(a,b) ((a)>(b)?(a):(b))
#define f(i,a,b) for(register int i=(a); i<=(b);++i)
void read(int &x)
{
	char c=getchar();x=0;
	while(!isdigit(c))c=getchar();
	while(isdigit(c))x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
}
int tag[100010][32],res[50],n,m,ans,now;
int main()
{
	read(n),read(m);
	int s,t,ch;
	f(i,1,n)
	{
		read(s),read(t),read(ch);
		++tag[s][ch],--tag[t+1][ch];
	}
	f(i,1,1e5+1)
	{
		now=0;
		f(j,1,m)
		{
			res[j]+=tag[i][j];
			if(res[j])++now;
		}
		ans=chkmax(ans,now);
	}printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 12800
use proconio::input;

fn main() {
    input! {
        x: i32,
        n: i32,
        p: [i32; n],
    }
    for a in 0..=x {
        let num1 = x - a;
        if !p.iter().any(|s| s == &num1) {
            println!("{}", num1);
            return;
        }
        let num2 = x + a;
        if !p.iter().any(|s| s == &num2) {
            println!("{}", num2);
            return;
        }
    }
    // 2x以降
    for a in (2 * x)..=100 {
        if !p.iter().any(|s| s == &a) {
            println!("{}", a);
            return;
        }
    }
}

Measured memory_bytes: 2172
import java.util.Scanner;

public class Main{
	public static boolean judge(int[] x){
		for(int i = 0; i < x.length; i++){
			if( x[i] == 0 ){
				continue;
			} else if( x[i] >= 3 ){
				x[i] -= 3;
				i--;
			} else if( i+2 < x.length && x[i] > 0 && x[i+1] > 0 && x[i+2] > 0 ){
				x[i]--; x[i+1]--; x[i+2]--;
				i--;
			} else {
				return false;
			}
		}
		return true;
	}
				
	public static int solve(int[] num, String[] color){
		int[] R = new int[9];
		int[] G = new int[9];
		int[] B = new int[9];
				
		for(int i = 0; i < 9; i++){
			if( color[i].equals("R") ){
				R[num[i]-1]++;
			} else if( color[i].equals("G") ){
				G[num[i]-1]++;
			} else {
				B[num[i]-1]++;
			}
		}
		
		if( judge(R) && judge(G) && judge(B) ){
			return 1;
		} else {
			return 0;
		}
	}
		
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] result = new int[n];
		for(int i = 0; i < n; i++){
			int[] num = new int[9];
			String[] color = new String[9];
			for(int j = 0; j < 9; j++){
				num[j] = stdIn.nextInt();
			}
			for(int j = 0; j < 9; j++){
				color[j] = stdIn.next();
			}
			result[i] = solve(num, color);
		}
		for(int i = 0; i < n; i++){
			System.out.println(result[i]);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstring>

using namespace std;

bool done(int m[], int a, int b) {
    bool z = true, res;
    for (int i = 1; i <= 9; i++) {
        if (m[i] > 0) z = false; else continue;
        if (m[i] >= 3) {
            m[i] -= 3;
            res = done(m, a, b - 1);
            m[i] += 3;
            if (res) return true;
        }
        if (m[i] >= 2) {
            m[i] -= 2;
            res = done(m, a - 1, b);
            m[i] += 2;
            if (res) return true;
        }
        if (i <= 7 && m[i] > 0 && m[i + 1] > 0 && m[i + 2] > 0) {
            m[i]--;
            m[i + 1]--;
            m[i + 2]--;
            res = done(m, a, b - 1);
            m[i]++;
            m[i + 1]++;
            m[i + 2]++;
            if (res) return true;
        }
    }
    if (z && a == 0 && b == 0) return true;
    return false;
}

int main(void) {
    int m[11];
    char c;
    while (true) {
        memset(m, 0, sizeof(m));
        for (int i = 0; i < 13; i++) {
            cin >> c;
            m[(int)(c - '0')]++;
        }
        if (cin.eof()) break;
        bool f = true;
        for (int i = 1; i <= 9; i++) {
            if (m[i] >= 4) continue;
            m[i]++;
            if (done(m, 1, 4)) {
                if (f) f = false;
                else cout << " ";
                cout << i;
            }
            m[i]--;
        }
        if (f) cout << 0;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    string s; cin >> s;
    int cnt = 0;
    REP(i,N){
        if(s[i] == 'R') cnt++;
    }
    int ans = 0;
    REP(i,cnt){
        if(s[i] == 'W') ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3748
#include<algorithm>
#include<functional>
#include<iterator>
#include<iostream>
#include<vector>
using namespace std;
struct C{
    char c;
    int n;
    bool operator<(const C&a)const{
        return n<a.n;
    }
    bool operator<=(const C&a)const{
        return n<=a.n;
    }
    bool operator==(const C&a)const{
        return c==a.c&&n==a.n;
    }
};
std::vector<C>P(100000);
void quickSort(int p,int r){
    if(r-p<2) return;
    int i=p-1;
    for(int j=p;j<r;++j){
        if(P[j]<=P[r-1]){
            i++;
            swap(P[i],P[j]);
        }
    }
    quickSort(p,i);
    quickSort(i+1,r);
}
template<class T, class C = std::less<>>
void mergeSort(T first, T last, C cmp = C()) {
    const auto N = std::distance(first, last);
    if (N <= 1) return;
    const auto mid = std::next(first, N / 2);
    mergeSort(first, mid, cmp);
    mergeSort(mid, last, cmp);
    std::inplace_merge(first, mid, last, cmp);
}
int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;++i) cin>>P[i].c>>P[i].n;
    vector<C>Q(100000);
    copy(P.begin(),P.end(),Q.begin());
    quickSort(0,N);
    mergeSort(Q.begin(),Q.begin()+N);
    puts(mismatch(P.begin(),P.end(),Q.begin()).first==P.end()?"Stable":"Not stable");
    for(int i=0;i<N;++i) cout<<P[i].c<<' '<<P[i].n<<endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	ll x, k, d; cin >> x >> k >> d;
	x = abs(x);
	if (k <= x / d) {
		cout << abs(x) - k * d << "\n";
	} else {
		// cout << min(x % d, d - x % d) << "\n";
		ll need = x / d;
		k -= need;
		ll ans = x % d;
		cout << (k & 1 ? (d - ans) : ans) << "\n";
	}
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, A, BC):
    A.sort()
    BC.sort(key=lambda x: x[1], reverse=True)
    i = 0
    for b, c in BC:
        for j in range(i, i+b):
            if j < N and c > A[j]:
                A[j] = c
                i = j + 1
            else:
                break

        if i != j + 1:
            break
    return sum(A)


def main():
    N, M = read_int_n()
    A = read_int_n()
    BC = [read_int_n() for _ in range(M)]
    print(slv(N, M, A, BC))


if __name__ == '__main__':
    main()


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	int N, T, ans = 0x7fffffff;
	for (cin >> N >> T; N; N--) {
		int c, t;
		cin >> c >> t;
		if (t <= T) ans = min(ans, c);
	}
	if (ans == 0x7fffffff) {
		cout << "TLE\n";
	}
	else {
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 256