akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
AC = 0
WA = 0

answer_list = {}
for i in range(N):
    answer_list[str(i+1)] = 0

for i in range(M):
    p, S = input().split()
    if answer_list[p] == "AC":
        pass
    else:
        if S == "AC":
            AC += 1
            WA += answer_list[p]
            answer_list[p] = "AC"
        else:
            answer_list[p] += 1

print(AC, WA)


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

using namespace std;
int main()
{
    int k, n;
    cin>> k>> n;
    int h[n], d[n];
    for(int i=0; i<n; i++)
        cin>> h[i];
    for(int i=0; i<n-1; i++)
    {
        d[i]=h[i]+k-h[i+1];
    }
    d[n-1]=h[n-1]-h[0];
    sort(d, d+n);
    cout<< d[0]<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 1000000007;
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int H, W; cin >> H >> W;
    vector<string> S(H); for (auto &s : S) cin >> s;
    vector<vector<int>> A(H, vector<int>(W, -1));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') continue;
            int k = j;
            while (k < W && S[i][k] == '.') k++;
            int cnt = k - j;
            for (; j < k; j++) A[i][j] += cnt;
        }
    }
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            if (S[i][j] == '#') continue;
            int k = i;
            while (k < H && S[k][j] == '.') k++;
            int cnt = k - i;
            for (; i < k; i++) A[i][j] += cnt;
        }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ans = max(ans, A[i][j]);
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 20224
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,s,f) for(int i=(int)s;i<(int)f;i++)
#define INF 1<<31-1
using ll=long long;
using namespace std;


int main()
{
	int N,K;
	cin>>N>>K;
	vector<ll> h(N);
	rep(i,N) cin>>h[i];
	sort(h.begin(),h.end(),greater<ll>());
	ll ans=INF;
	rep(i,N-K+1)
	{
		ans=min(ans,h[i]-h[i+K-1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#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++)

using namespace std;

int n;

int main() {
  int a, b;
  cin >> n;
  
  bool found = false;
  rep1(a, 10) {
    rep1(b, 10) {
      if (a*b == n) {
        found = true;
      }
    }
  }
  if (found) cout << "Yes";
  else cout << "No";
}

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

long long int N, M, X, A, B[200];

int main(){
    scanf("%lld%lld%lld", &N, &M, &X);
    for(int i = 0; i < M; ++B[A], ++i)scanf("%lld", &A);
    partial_sum(begin(B), end(B), begin(B));
    printf("%lld\n", min(B[X], B[N] - B[X]));
    return 0;
}


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

void bubbleSort(unsigned int A[], int N)
{
    int flag = 1;
    for(int i = 0; flag; i++)
    {
	flag = 0;
	for(int j = N - 1; j >= i+1; j--)
	{
	    if(A[j] < A[j-1])
	    {
		int temp = A[j];
		A[j] = A[j-1];
		A[j-1] = temp;
		flag = 1;
	    }
	}
    }
}

int main(void)
{
    int N;
    cin >> N;
    unsigned int L[N];
    for(int i = 0; i < N; i++)
	cin >> L[i];

    bubbleSort(L, N);

    int count = 0;
    for(int i = 0; i < N; i++)
    {
	for(int j = i+1; j < N; j++)
	{
	    for(int k = j+1; k < N; k++)
	    {
		if(L[k] < L[i] + L[j])
		{
		    count++;
		}
		else
		{
		    break;
		}
	    }
	}
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b,ans;
	cin >> a >> b;
	if (b==1) {
		ans = 0;
	}
	else if (b < a) {
		ans = 1;
	}
	else {
		if ((b - 1) % (a - 1) == 0) {
			ans = (b - 1) / (a - 1);
		}else ans =(b - 1) / (a - 1) + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e3;
const int maxn=1e6+5;
int main()
{
    int n;
    scanf("%d",&n);
    if(n%2==0)printf("%d",n/2-1);
    else printf("%d",n/2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2;
typedef pair<int, P2> P3; typedef long long ll; typedef long double ld;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<10> fact; constexpr Prime<10> prime;
constexpr int comb(int a, int b){long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b];return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr int sqrtN = 512, logN = 32;
constexpr ld PI = abs(acos(-1));
constexpr ll LINF=1e18;

int n, a[200010], b[200010];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	
	int s = 0;
	for(ll x = (1 << 28); x; x >>= 1){
		for(int i = 0; i < n; i++) a[i] &= 2 * x - 1; sort(a, a + n);
		for(int i = 0; i < n; i++) b[i] &= 2 * x - 1; sort(b, b + n);
		
		int c = 0;
		for(int i = 0; i < n; i++){
			int p = lower_bound(b, b + n, x - a[i]) - b;
			int q = lower_bound(b, b + n, 2 * x - a[i]) - b;
			int r = lower_bound(b, b + n, 3 * x - a[i]) - b;
			
			(c += q - p + n - r) %= 2;
		}
		
		s += x * (c % 2);
	}
	
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define dump3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n, x;
    cin >> n >> x;
    vll b(n), l(n), u(n);
    rep(i, n){
        cin >> b[i] >> l[i] >> u[i];
    }
    vector<tuple<ll, ll, ll, ll>> vt;
    ll val = 0;
    rep(i, n){
        vt.emplace_back(b[i]*l[i]+(x-b[i])*u[i], u[i], l[i], b[i]);
        val -= l[i]*b[i];
    }
    sort(vt.rbegin(), vt.rend());
    vll acc;
    acc.emplace_back(0);
    rep(i, n){
        acc.emplace_back(*acc.rbegin()+get<0>(vt[i]));
    }
    // ans : 0 ~ nx
    
    // binary search
    // https://qiita.com/drken/items/97e37dd6143e33a64c8c
    ll bsl = -1;
    ll bsr = n*x;
    while(bsr - bsl > 1){
        // dump2(bsl, bsr);
        ll mid = bsl + (bsr - bsl) / 2;
        ll q = mid / x;
        ll r = mid % x;
        ll m = 0;
        rep(i, q){
            ll mt;
            if(r > get<3>(vt[i])){
                mt = get<2>(vt[i])*get<3>(vt[i]) + get<1>(vt[i])*(r-get<3>(vt[i]));
            }else{
                mt = get<2>(vt[i])*r;
            }
            // dump(mt);
            m = max(m, acc[q+1] - get<0>(vt[i]) + mt);
        }
        rea(i, q, n){
            ll mt;
            if(r > get<3>(vt[i])){
                mt = get<2>(vt[i])*get<3>(vt[i]) + get<1>(vt[i])*(r-get<3>(vt[i]));
            }else{
                mt = get<2>(vt[i])*r;
            }
            // dump(mt);
            m = max(m, acc[q] + mt);
        }
        if(m + val >= 0){
            bsr = mid;
        }else{
            bsl = mid;
        }
    }
    cout << bsr << endl;
}

Measured memory_bytes: 8816
def search(s, n):
  if int(s) > n:
    return 0
  ans = 1 if (s.count('7') > 0 and s.count('5') > 0 and s.count('3') > 0) else 0
  for c in '753':
    ans += search(s+c,n)
  return ans

N = int(input())
print(search('0',N))
    

Measured memory_bytes: 2940
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> k;
  ans = n % k;
  ans = min(ans, abs(ans - k));
  Cout(ans);
  return 0;
}

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

int linear(int a[], int key, int n);
int main()
{
	int i, j, n, q, c = 0;
	int s[100000], t[100000];

	cin >> n;
	for (i = 0; i < n; i++) cin >> s[i];

	cin >> q;
	for (i = 0; i < q; i++) cin >> t[i];

	for (i = 0; i < q; i++) {
		c += linear(s, t[i], n);
	}
	cout << c << endl;

}
int linear(int a[], int key, int n)
{
	int left = 0;
	int right = n;
	int  mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (a[mid] == key) {
			return 1;
		}
		else if (key < a[mid]) {
			right = mid;
		}
		else {
			left = mid + 1;
		}
	}
	return 0;
}

Measured memory_bytes: 3576
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input, "index" : 0, "max" : input.length,
  "hasNext" : function(){return (this.index < this.max);},
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  }
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var fromOne = new Set();
  var toN = new Set();
  for(var i = 0; i < M; i++){
    var tmp = nextIntArray();
    if(tmp[0] == 1){
       fromOne.add(tmp[1]);
    }
    if(tmp[1] == N){
       toN.add(tmp[0]);
    }
  }
  myerr(fromOne);
  myerr(toN);
  var toNlist = Array.from(toN);
  for(var i = 0; i < toNlist.length; i++){
    if(fromOne.has(toNlist[i])){
       myout("POSSIBLE");
      return;
    }
  }
  myout("IMPOSSIBLE");
}

Measured memory_bytes: 70752
package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	n, m := readInt2()

	if n == m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}


int main(){
  ll ac = 0,wa = 0,n,m;
  cin >> n >> m;
  vector<ll> vec(n,0);
  vector<ll> ch(n,0);
  string s;
  rep(i,m){
    cin >> tmp1 >> s;
    if(vec[tmp1-1] == 0){
      if(s == "AC"){
        vec[tmp1-1] = 1;
        ac++;
        wa += ch[tmp1-1];
      }else{
        ch[tmp1-1]++;
      }
    }
  }
  cout << ac << " " << wa << endl;
}

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

int main()
{
	int n,a,d;
	int c = 1000000;
	int b = 0;
	cin >> n;
	for (int i=0; i<n ; i++)
	{
		cin >> a;
		while (a == (a/2)*2 )
		{
			b += 1;
			a /= 2;
		}
		if (b < c)
		{
			c = b;
			b= 0;
		}
		else
		{
			b = 0;
		}
		
	}
	cout << c << endl;
	
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
 
int main() {
  string c, s1, s2;
  cin >> c;
  bool b = false;
  for(int i=0; i<c.size(); i++) {
    s1.push_back(b ? '1' : '0');
    s2.push_back(b ? '0' : '1');
    b = !b;
  }

  int ans1 = 0, ans2 = 0;
  for(int i=0; i<c.size(); i++) {
    if(s1[i]!=c[i]) {
      ans1++;
    }
    if(s2[i]!=c[i]) {
      ans2++;
    }
  }

  cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#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; }

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> v = {
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
  };
  int k;
  cin >> k;
  cout << v[k-1] << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	while ( true )
	{
		int n, m, a;
		cin >> n >> m >> a;

		if ( !( n | m | a ) )
		{
			break;
		}

		vector< pair<int,PII> > horizontal( m );
		FOR( h, horizontal )
		{
			cin >> h.fst >> h.snd.fst >> h.snd.snd;
		}
		sort( ALL( horizontal ), greater< pair<int,PII> >() );

		VI ends( n );
		REP( i, 0, n )
		{
			ends[i] = i + 1;
		}
		FOR( h, horizontal )
		{
			swap( ends[ h.snd.fst - 1 ], ends[ h.snd.snd - 1] );
		}

		int res;
		REP( i, 0, n )
		{
			if ( ends[i] == a )
			{
				res = i + 1;
			}
		}
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
  ll n;
  cin >> n;
  cout << (((1000 - n) % 1000) + 1000) % 1000 << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main()
{
	char text[3];
	int a[3];
    for(int i=0;i<=2;i++)
    {
    	cin>>text[i];
		a[i]=int(text[i]);	
	}
    if(a[0]==a[1]&&a[0]==a[2]&&a[1]==a[2])
	cout<<"No"<<endl;
	else
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
 int a[4],b[4],h,bb,i;
 while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]){
  h=bb=0;
  for(i=0;i<4;i++)if(a[i]==b[i])h++;
  sort(a,a+4);sort(b,b+4);
  for(i=0;i<4;i++)if(find(b,b+4,a[i])!=b+4)bb++;
  bb -= h;
  cout<<h<<" "<<bb<< endl;
 }
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  map<string,int> list;
  rep(i,N) {
    string S;
    cin >> S;
    list[S]++;
  }
  int m = 0;
  for (auto i = list.begin(); i != list.end(); ++i) {
    m = max(m, i->second);
  }
  for (auto i = list.begin(); i != list.end(); ++i) {
    if (i->second == m) cout << i->first << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> got_ac(N);
  vector<int> count_wa(N);
  for (int i = 0; i < M; i++) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if (got_ac[p]) {
      continue;
    }
    if (s == "AC") {
      got_ac[p] = true;
    } else {
      count_wa[p]++;
    }
  }
  int ac = 0;
  int wa = 0;
  for (int i = 0; i < N; i++) {
    if (got_ac[i]) {
      ac++;
      wa += count_wa[i];
    }
  }
  cout << ac << " " << wa << endl;

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
  int a,b,i;
  scanf("%d %d",&a,&b);
  if(a<b){
        for(i=1;i<=b;i++)
        {
          printf("%d",a);
        }
    }
    else{
        for(i=1;i<=a;i++)
        {
          printf("%d",b);
        }
    }
}



Measured memory_bytes: 1676
n = int(input())
ls_s = [input() for _ in range(n)]
m = int(input())
ls_t = [input() for _ in range(m)]

ls_u =ls_s + ls_t
p = m + n 

ans = 0


for i in range(n):
    cnt = 0
    for j in range(p):
        if ls_u[i] == ls_u[j] and j <= n - 1:
            cnt += 1
        elif ls_u[i] == ls_u[j] and n - 1 < j:
            cnt += -1
    if cnt >= ans:
        ans = cnt

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> ii;
const int mod = (int) 1e9 + 7;
const ll inf = 1LL << 60;
const int maxn = (int) 1e3 + 5;
const ld eps = 1e-9;

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

int res, n, m, k, f[maxn][maxn];
string a[maxn];
queue<ii> Q;

int dist(int x, int y) {
    int d = min(x, n - 1 - x);
    d = min(d, min(y, m - 1 - y));
    return d;
}

int main() {
    //freopen("test.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    memset(f, -1, sizeof f);
    cin >> n >> m >> k;
    rep(i, 0, n) {
        cin >> a[i];
        rep(j, 0, m) {
            if(a[i][j] == 'S') {
                Q.push(ii(i, j));
                f[i][j] = 0;
                if(dist(i, j) == 0) return cout << "0\n", 0;
            }
        }
    }
    while (!Q.empty()) {
        int x = Q.front().fi;
        int y = Q.front().se;
        Q.pop();
        rep(i, 0, 4) {
            int u = x + dx[i], v = y + dy[i];
            if(u < 0 || v < 0 || u >= n || v >= m || f[u][v] != -1 || a[u][v] == '#') continue;
            f[u][v] = f[x][y] + 1;
            Q.push(ii(u, v));
        }
    }
    res = mod;
    rep(i, 0, n) {
        rep(j, 0, m) {
       //     cout << f[i][j] << ' ';
            if(f[i][j] == -1 || f[i][j] > k) continue;
            res = min(res, (dist(i, j) + k - 1) / k);
        }
     //   cout << endl;
    }
    //cout << dist(1, 1) << endl;
    cout << res + 1 << endl;
}







Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int a, b, c, d; cin >> a >> b >> c >> d;
  for(int i = 0; i < 1e6; i++){
    if(i%2 == 0){
      c -= b;
      if(c <= 0){
        cout << "Yes" << endl;
        return 0;
      }
    }else {
      a -= d;
      if(a <= 0){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")
#define ret return 0

int n, a, b, c;

vector<int> l;

int search(int used, int a_, int b_, int c_)
{
	if (used == n)
	{
		if (min({ a_,b_,c_ })>0)
			return abs(a - a_) + abs(b - b_) + abs(c - c_) - 30;
		else
			return INF;
	}
	int ans1 = search(used + 1, a_, b_, c_);
	int ans2 = search(used + 1, a_ + l[used], b_, c_)+10;
	int ans3 = search(used + 1, a_, b_ + l[used], c_)+10;
	int ans4 = search(used + 1, a_, b_, c_ + l[used])+10;

	return min({ ans1,ans2,ans3,ans4 });
}

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

	cin >> n >> a >> b >> c;
	int tmp;
	rep(i, n)
	{
		cin >> tmp;
		l.push_back(tmp);
	}

	int ans = search(0, 0, 0, 0);
	cout << ans << endl;

	ret;
}

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

typedef long long ll;

int main()
{
	ll a, b, c; cin >> a >> b >> c;
	int ans = 0;
	while (!((a|b|c)&1))
	{
		ll A = (b+c)>>1, B = (a+c)>>1, C = (a+b)>>1;
		if (A == a && B == b && C == c)
		{
			ans = -1;
			break;
		}
		a = A, b = B, c = C;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
const int MAX=1e5+5;
set<pair<int,int> > lef;
set<pair<int,int> > rgt;

int l[MAX];
int r[MAX];

int main()
{
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
    scanf("%d %d",&l[i],&r[i]);
  }
  for(int i=1;i<=n;i++)
  {
    lef.insert(make_pair(-l[i],i));
    rgt.insert(make_pair(r[i],i));
  }
  int cnt=0;
  int cur=0;
  long long ans=0;
  while(lef.size()&&rgt.size())
  {
    cnt++;
    if(cnt%2)
    { 
      pair<int,int> tmp=(*rgt.begin());
      rgt.erase(rgt.begin());
      lef.erase(make_pair(-l[tmp.second],tmp.second));
      if(cur<=r[tmp.second]&&cur>=l[tmp.second])
      {
        continue;
      }
      ans+=abs(cur-tmp.first);
      cur=tmp.first;
    }
    else
    {
      pair<int,int> tmp=(*lef.begin());
      lef.erase(lef.begin());
      rgt.erase(make_pair(r[tmp.second],tmp.second));
      if(cur<=r[tmp.second]&&cur>=l[tmp.second])
      {
        continue;
      }
      ans+=abs(cur+tmp.first);
      cur=-tmp.first;
    }
    
  }
  ans+=abs(cur);
  for(int i=1;i<=n;i++)
  {
    lef.insert(make_pair(-l[i],i));
    rgt.insert(make_pair(r[i],i));
  }
  cnt=0;
  cur=0;
  long long tmpo=0;
  while(lef.size()&&rgt.size())
  {
    cnt++;
    if((cnt%2)==0)
    { 
      pair<int,int> tmp=(*rgt.begin());
      rgt.erase(rgt.begin());
      lef.erase(make_pair(-l[tmp.second],tmp.second));
      if(cur<=r[tmp.second]&&cur>=l[tmp.second])
      {
        continue;
      }
      tmpo+=abs(cur-tmp.first);
      cur=tmp.first;
    }
    else
    {
      pair<int,int> tmp=(*lef.begin());
      lef.erase(lef.begin());
      rgt.erase(make_pair(r[tmp.second],tmp.second));
      if(cur<=r[tmp.second]&&cur>=l[tmp.second])
      {
        continue;
      }
      tmpo+=abs(cur+tmp.first);
      cur=-tmp.first;
    }
  }
  tmpo+=abs(cur);
   printf("%lld\n",max(ans,tmpo));
  

}

Measured memory_bytes: 10368
#include<iostream>
#define rep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;

int main() {
    int s, k; cin >> k >> s;

    int cnt = 0;

    rep(i, k){
        rep(j, k){
            int l = s - i - j;
            if (l < 0) continue;
            if (l <= k) {
                cnt++;
                // cout << i << j << l << endl;
            }
        }
    }cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    input!{
        s: chars,
    }
    let s: Vec<i32> = s.into_iter()
        .map(|c| c as u8 as i32 - 'a' as u8 as i32).collect();
    let n = s.len();
    let mut pre = vec![INF; 1 << 26];
    const INF: i32 = 1 << 28;
    let mut dp = vec![INF; n + 1];
    dp[0] = 0;
    pre[0] = 0;
    let mut acc = 0;
    for i in 0 .. n {
        let idx = s[i];
        acc ^= 1 << idx;
        if pre[acc] < INF {
            dp[i + 1] = min(dp[i + 1], dp[pre[acc] as usize] + 1);
        }
        if acc == 0 {
            dp[i + 1] = 1;
        }
        pre[acc] = i as i32 + 1;
        for j in 0 .. 26 {
            let nxt = acc ^ 1 << j;
            if pre[nxt] < INF {
                if dp[i + 1] > dp[pre[nxt] as usize] + 1 {
                }
                dp[i + 1] = min(dp[i + 1], dp[pre[nxt] as usize] + 1);
            }
            if nxt == 0 {
                dp[i + 1] = 1;
            }
        }
    }
    puts!("{}\n", dp[n]);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 272636
from collections import*
from heapq import*
n,m,*t=map(int,open(0).read().split())
d=defaultdict(list)
for a,b in zip(t[::2],t[1::2]):d[a].append(b)
q=[]
for i in sorted(d.keys())[::-1]:
    for b in sorted(d[i])[::-1][:m-i+1]:
        if len(q)<=m-i:heappush(q,b)
        elif q and q[0]<b:heappushpop(q,b)
print(sum(q))

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    int n, m; cin >> n >> m;
    vl h(n);
    vvl edges(n);
    rep(i,n) cin >> h[i];
    rep(i,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    int ans = 0;
    rep(i,n) {
        int flag = 1;
        for (auto to : edges[i]) {
            if (h[to] >= h[i]) flag = 0;
        }
        ans += flag;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;


public class Main {

	BufferedReader reader;
	
	class CharComparator implements Comparator<Character>{
		private boolean descend;
		@Override
		public int compare(Character o1, Character o2) {
			// TODO Auto-generated method stub
			if(descend) return o2-o1; else return o1-o2;

		}
		
		CharComparator(boolean descend){
			this.descend=descend;
		}
		
	}
	
	int charArray2int(final Character[] s){
		int n=0;
		for(int i=0;i<s.length;++i){
			n*=10;
			n+=s[i]-'0';
		}
		return n;
	}
	void int2charArray(Character[] s, int n){
		for(int i=s.length-1;i>=0;--i){
			s[i]=(char) (n%10+'0');
			n/=10;
		}
	}
	
	int solve(String n0){
		Character N[]=new Character[4];
		for(int i=0;i<4;++i){
			N[i]=n0.charAt(i);
		}
		
		if(charArray2int(N)%1111==0) return -1;
		
		int k;
		for(k=0;charArray2int(N)!=6174;++k){
			Arrays.sort(N, new CharComparator(true));
			int L=charArray2int(N);
			Arrays.sort(N, new CharComparator(false));
			int S=charArray2int(N);
			
			int2charArray(N, L-S);
		}
		return k;
	}
	
	String ns() throws Exception{
		return reader.readLine();
	}
	
	void io(){
		reader=new BufferedReader(new InputStreamReader(System.in));
		
		try{
			String s;
			while((s=ns()).compareTo("0000")!=0){
				int ans=solve(s);
				System.out.println(ans==-1?"NA":ans);
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().io();
	}

}

Measured memory_bytes: 32100
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

bool isOK(vector<int> v, int index, int key) {
    if(v[index] > key)
        return true;
    else
        return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(vector<int> v, int key) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right =
        (int)v.size(); // 「index =
                       // a.size()-1」が条件を満たさないこともあるので、初期値は
                       // a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while(right - left > 1) {
        int mid = left + (right - left) / 2;

        if(isOK(v, mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている
     */
    return right;
}
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) { cin >> A[i]; }
    vector<int> B(N);
    rep(i, 0, N) { cin >> B[i]; }
    vector<int> C(N);
    rep(i, 0, N) { cin >> C[i]; }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    long long res = 0;
    rep(i, 0, N) {
        long long bc =
            N - distance(C.begin(), lower_bound(C.begin(), C.end(), B[i] + 1));
        long long ab =
            distance(A.begin(), lower_bound(A.begin(), A.end(), B[i]));
        res += bc * ab;
    }
    cout << res << endl;
}


Measured memory_bytes: 1408
import sys
    
sys.setrecursionlimit(200000)
    
N = int(input())
A = list(map(int, input().split(' ')))
    

sumA = []
for i in range(N):
    if i == 0:
        sumA.append(A[i])
    else:
        sumA.append(sumA[-1] + A[i])
    
ans = 0
    
for i in range(N):
    if sumA[-1] // 2 > sumA[i]:
        continue
    else:
        if i == 0:
            ans = abs(sumA[i] * 2 - sumA[-1])
            break
        else:
            ans = min(abs(sumA[i] * 2 - sumA[-1]), abs(sumA[i-1] * 2 - sumA[-1]))
            break
    
print(ans)

Measured memory_bytes: 26220
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))

sort_a = sorted(a, reverse=True)
max_a = sort_a[0]
max_a_1 = sort_a[1]

for i in range(n):
  if a[i] == max_a:
    print(max_a_1)
  else:
    print(max_a)


Measured memory_bytes: 19052
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		Arrays.parallelSort(a);

		int mod = 1000000007;
		long[] p = new long[100001];
		long[] pi = new long[100001];
		p[0] = 1;
		pi[0] = 1;
		for (int i = 1; i < p.length; i++) {
			p[i] = p[i - 1] * i % mod;
			pi[i] = modinv(p[i], mod);
		}

		long sum1 = 0;
		long sum2 = 0;
		for (int i = 0; i < n; i++) {
			if (n - 1 - i >= k - 1) {
				long val = nCr(n - 1 - i, k - 1, mod, p, pi);
				sum1 += val * a[i];
				sum1 %= mod;
			}
			if (i >= k - 1) {
				long val = nCr(i, k - 1, mod, p, pi);
				sum2 += val * a[i];
				sum2 %= mod;
			}
		}
		long ans = sum2 - sum1;
		while (ans < 0) {
			ans += mod;
		}
		ans %= mod;
		System.out.println(ans);
	}

	static long nCr(int n, int r, int m, long[] p, long[] pi) {
		return p[n] * pi[r] % m * pi[n - r] % m;
	}

	static long modinv(long a, long m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}


Measured memory_bytes: 45780
import sys
X,N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
p = list(map(int,input().split()))

num1 = X-1
num2 = X+1
if X not in p:
  print(X)
  sys.exit()
while 1:
  if num1 == 0:
    print(num1)
    break
  if num1 in p and num2 not in p:
    print(num2)
    break
    
  elif num1 not in p and num2 in p:
    print(num1)
    break
  elif num1 not in p and num2 not in p:
    print(num1)
    break
  else:
    num1 -= 1
    num2 += 1
    



Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 1000000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

bool vis[MAX + 5];

int main() {

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

    int k, curr, ans = 1;
    cin >> k;
    curr = 7 % k;
    while (curr && !vis[curr]) {
        vis[curr] = true;
        curr *= 10;
        curr += 7;
        curr %= k;
        ++ans;
    }
    if (curr) {
        cout << -1;
    } else {
        cout << ans;
    }

    return 0;
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;	//N:ボタンの数
  int num = 1;	//num:押すボタン
  int num_f = 1; //num_f:一回前に押したボタン
  int times = 0;	//times:押した回数
  cin >> N;		//Nの入力
  vector<int> a(N);	//a():ボタンの対応番号
  
  for(int i=0; i<N ; i++)cin >> a.at(i);	//ボタンの入力
  while(a.at(num-1) != 0 && a.at(num-1) != 2){
    num_f = num;		// num_fの更新
    num = a.at(num-1);	//次押すボタンの設定
    a.at(num_f-1) = 0;	//一回押したボタンは0にする
    times++;			//押した回数の更新
  }
  
  times++;
  
  if(a.at(num-1) ==0){
    cout << -1 << endl;
  }else{
    cout << times << endl;
  }
  
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

int T;
double C[2*NUM+1],E;

//右側の合成プレートの比熱を求める
double calc_right(){

	double ret = C[2*T];
	int rest_time = 1;

	for(int base_loc = 2*T-1; base_loc >= T+1; base_loc--){

		ret = min(C[base_loc],(ret*rest_time+C[base_loc])/(double)(rest_time+1));
		rest_time++;
	}

	return ret;
}

//左側の合成プレートの比熱を求める
double calc_left(){

	double ret = C[0];
	int rest_time = 1;

	for(int base_loc = 1; base_loc <= T-1; base_loc++){

		ret = min(C[base_loc],(ret*rest_time+C[base_loc])/(double)(rest_time+1));
		rest_time++;
	}

	return ret;
}

int main(){

	scanf("%d %lf",&T,&E);

	for(int i = 0; i < 2*T+1; i++){
		scanf("%lf",&C[i]);
	}

	double LEFT,RIGHT;

	//左方向の合成プレートの比熱計算
	LEFT = calc_left();

	//右方向の合成プレートの比熱計算
	RIGHT = calc_right();

	double ans = E/C[T];
	double mid,another;

	mid = E/(C[T]+T*(LEFT+RIGHT));
	another = (E-mid*C[T])/(LEFT+RIGHT);

	ans = max(ans,min((T+1)*mid,mid+another));

	printf("%.10lf\n",ans);

	return 0;
}



Measured memory_bytes: 4744
a = []
a[0] = gets.split(" ").map(&:to_i)
a[1] = gets.split(" ").map(&:to_i)
a[2] = gets.split(" ").map(&:to_i)
a.flatten!

n = gets.to_i

n.times do |_|
  x = gets.to_i
  a = a.map{|j| j == x ? 0 : j}
end

lines = [
  [0, 1, 2],
  [3, 4, 5],
  [6, 7, 8],
  [0, 3, 6],
  [1, 4, 7],
  [2, 5, 8],
  [0, 4, 8],
  [2, 4, 6],
]

lines.each do |line|
  l, n, m = line;
  if (a[l] == 0 && a[n] == 0 && a[m] === 0)
    print "Yes\n"
    exit
  end
end
print "No\n"

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

int a, b;
int main(){
  cin >> a >> b;
  int ans = max (a - 2*b, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
from numba import jit
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
import time
 
def main():
    N,X,T = map(int,input().split())
    print(math.ceil(N/X) * T)

if __name__ == '__main__':
    main()

Measured memory_bytes: 91436
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        int x = int.Parse(ReadLine());
        var bekiList = new List<int>();

        for (int i = 1; i <= 31; i++)
        {
            if (i == 1)
            {
                bekiList.Add(1);
                continue;
            }

            for (int j = 2; true; j++)
            {
                int beki = (int)Math.Pow(i, j);
                if (beki > x)
                {
                    break;
                }

                bekiList.Add(beki);
            }
        }

        Console.WriteLine(bekiList.Max().ToString());
    }

}

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

int main() {
  int A,B,C,D,N;
  cin >> N;
  D = N % 10;
  C = (N % 100 - D)/10;
  B = (N % 1000 - N % 100)/100;
  A = (N - N % 1000)/1000;
    
  if ((A == B && B == C) || (B==C && C == D) ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,h[100005],dp[100205];

int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>h[i];
    for(int i=0;i<100200;i++)dp[i]=1e9;
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k && i+j<n;j++){
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
import sys

from scipy.sparse.csgraph import floyd_warshall
import numpy as np


def solve():
    infinity = 10 ** 10
    n, m, le = map(int, input().split())
    paths = np.full((n, n), infinity)
    for i in range(n):
        paths[i, i] = 0

    for _ in range(m):
        a, b, c = map(int, input().split())
        paths[a - 1, b - 1] = paths[b - 1, a - 1] = c

    paths = floyd_warshall(paths)
    paths = floyd_warshall(paths <= le)
    paths[np.isinf(paths)] = 0

    q = int(input())
    answer = []
    for _ in range(q):
        s, t = map(int, input().split())
        answer.append(int(paths[s - 1][t - 1] - 1))

    print(*answer, sep='\n')
    #print("\n".join(map(str, answer)))


if __name__ == "__main__":
    solve()


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

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pll;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fir first
#define sec second
#define gc getchar
#define pc putchar

#define fo0(i,a,b) for(int i=(a);i<(b);i++)
#define fo1(i,a,b) for(int i=(a);i<=(b);i++)
#define fd0(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define fd1(i,a,b) for(int i=(a);i>=(b);i--)
#define mset(a,b) memset(a,(b),sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))

template<typename T> inline T gcd(T a, T b){T t;if(a>b){while(b){
t=b;b=a%b;a=t;}return a;}else{while(a){t=a;a=b%a;b=t;}return b;}}
template<typename T> inline T lcm(T a, T b){return a/gcd(a,b)*b;}

template<typename T> inline void QR(T &x){x=0;int fl=1;char ch=gc();while(ch<'0'||ch>'9')
{if(ch=='-')fl=-1;ch=gc();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=gc();}x*=fl;}
void Read(int &x){QR(x);} void Read(LL &x){QR(x);}
void Read(double &x){scanf("%lf", &x);} void Read(char &x){x=gc();}
template<typename T> void QW(T x){if(x<0){pc('-');x=-x;}if(x/10)QW(x/10);pc(x%10+'0');}
void Write(int &x){QW(x);} void Write(LL &x){QW(x);}
void Write(double &x){printf("%f", &x);} void Write(char &x){pc(x);}
void in(){} template<class T1,class...T2> void in(T1 &head,T2 &...tail){Read(head);in(tail...);}
void out(){} template<class T1,class...T2> void out(T1 head,T2 ...tail){Write(head);out(tail...);}

int main(){
	int a, b;
	in(a, b);
	out(a + b / 2);
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby

def dfs(a,&block)
	return to_enum(:dfs,a) if !block_given?
	yield [a[0],a[0].to_s] if a.size<2
	(a.size-1).times{|i|
		dfs(a[0..i]){|l|
			dfs(a[i+1..-1]){|r|
				yield [l[0]+r[0],%Q((#{l[1]} + #{r[1]}))]
				yield [l[0]-r[0],%Q((#{l[1]} - #{r[1]}))]
				yield [l[0]*r[0],%Q((#{l[1]} * #{r[1]}))]
			}
		}
	}
end

while (a=gets.split.map(&:to_i))!=[0,0,0,0]
	if a.permutation.none?{|e|
		if r=dfs(e).find{|n,s|n==10}
			puts r[1]
			true
		end
	}
		p 0
	end
end

Measured memory_bytes: 6124
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

#define ll long long
#define FOR(x,y) for(ll x=0; x < (ll)y; x++)



int main() {
    int x;
    cin >> x;
    int c500 = x/500;
    x -= c500*500;
    int c5 = x/5;
    int ans = c500*1000 + c5*5;
    cout << ans;


    return 0;
}


Measured memory_bytes: 256
from itertools import zip_longest

def resolve():
    odd = input()
    even = input()

    for o, e in zip_longest(odd, even):
        if o is None:
            o = ""
        elif e is None:
            e = ""
        print(o+e, end="")
    else:
        print()

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3060
import numpy as np

N = input()
V = np.array(map(int, raw_input().split()))
C = np.array(map(int, raw_input().split()))

flag_arr = (V-C) > 0

res = 0

for i in range(N):
    if flag_arr[i]:
        res = res + V[i] - C[i]

print(res)

Measured memory_bytes: 16260
fun readInts() = readLine()!!.split(' ').map(String::toInt)

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xx = readInts()
    val xs = xx.sorted()
    val m = (n shr 1) - 1
    val xm = xs[m]
    xx.map { if (xm < it) xm else xs[m + 1] }.forEach(::println)
}


Measured memory_bytes: 98132