akhauriyash/Code-Regression huggingface dataset:
// Problem : E - Count Median
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define plii pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void solve(){
	int n;
	rd(n);
	vlli a,b;
	// error(n);
	FOR(i,n){
		int X,Y;
		rd(X,Y);
		a.pb(X);
		b.pb(Y);
	}	
	sort(all(a));
	sort(all(b));
	int mid1,mid2;
	if(n&1){
		mid1=a[n/2];
		mid2=b[n/2];
	}
	else{
		mid1=a[n/2]+a[(n/2)-1];
		mid2=b[n/2]+b[(n/2)-1];
	}
	// pp(mid1,mid2);
	
	pp(mid2-mid1+1);
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 6696
import java.util.*

fun main(args: Array<String>) = abc157e()

fun abc157e() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val q = readLine()!!.toInt()
    val queries = (1..q).map {
        readLine()!!.split(' ').map { it }
            .let { Query(if (it[0].toInt() == 1) QueryType.UPDATE else QueryType.GET, it[1].toInt(), it[2]) }
    }

    val arr = LongArray(n)
    s.forEachIndexed { index, c -> arr[index] = charToBit(c) }

    val st = SegmentTree(arr, Long::or)
    val answer = StringBuilder()

    for ((type, x, y) in queries) {
        when (type) {
            QueryType.UPDATE -> st[x - 1] = charToBit(y[0])
            else -> answer.appendln(st[x - 1..y.toInt() - 1])
        }
    }

    print(answer)
}

private fun charToBit(char: Char) = Math.pow(2.0, (char - 'a').toDouble()).toLong()

private data class Query(val type: QueryType, val x: Int, val y: String)
private enum class QueryType { UPDATE, GET }

private class SegmentTree(init: LongArray, val monad: (Long, Long) -> Long) {
    val indices: Int
    val nodes: LongArray

    init {
        var indices = 1
        while (indices < init.size) indices = indices shl 1
        val nodes = LongArray(2 * indices - 1)
        for (i in init.indices) nodes[i + indices - 1] = init[i]
        for (i in indices - 2 downTo 0) nodes[i] = monad(nodes[2 * i + 1], nodes[2 * i + 2])
        this.indices = indices
        this.nodes = nodes
    }

    operator fun set(x: Int, value: Long) {
        var index = x + indices - 1
        nodes[index] = value
        while (index > 0) {
            index = (index - 1) / 2
            nodes[index] = monad(nodes[2 * index + 1], nodes[2 * index + 2])
        }
    }

    operator fun get(range: IntRange): Int =
        BitSet.valueOf(longArrayOf(get(range.first, range.last + 1))).cardinality()

    fun get(a: Int, b: Int, k: Int = 0, l: Int = 0, r: Int = indices): Long {
        if (r <= a || b <= l) return 0
        if (a <= l && r <= b) return nodes[k]
        return monad(
            get(a, b, 2 * k + 1, l, (l + r) / 2),
            get(a, b, 2 * k + 2, (l + r) / 2, r)
        )
    }
}


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

int main() {
  
  int N,A,B;
  cin >> N >> A >> B;
  
  int t=0;
  for (int i=0; i<N; i++) {
    bool c=true;
    int s=0;
    int j=i+1;
    while (c) {
      if (j/10==0) c=false;
      s += j%10;
      j/=10;
    }
    if (A<=s && s<=B) t+=i+1;
  }
  
  cout << t << endl;
}

Measured memory_bytes: 256
def main():
    _ = int(input())
    s = input()
    print(solve(s))

def solve(s):
    n = len(s)

    blacks = [None for _ in range(n + 2)]
    whites = [None for _ in range(n + 2)]
    b = 0
    w = 0

    for i in range(n):
        if s[i] == '#':
            b += 1
        blacks[i + 1] = b

    for i in reversed(range(n)):
        if s[i] == '.':
            w += 1
        whites[i + 1] = w

    blacks[0] = 0
    blacks[n + 1] = blacks[n]
    whites[0] = whites[1]
    whites[n + 1] = 0

    m = float('inf')
    for i in range(n + 1):
        m = min(m, blacks[i] + whites[i + 1])

    return m

main()

Measured memory_bytes: 14980
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] fd = new int[m];
        for(int i = 0; i < n; i++){
            int k = sc.nextInt();
            for(int j = 0; j < k; j++){
                int a = sc.nextInt()-1;
                fd[a]++;
            }
        }
        int ans = 0;
        for(int f : fd){
            if(f == n) ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
# include <bits/stdc++.h>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// Did you miss me ?

# define gc          getchar
# define LL          long long
# define pb          push_back
# define mp          make_pair
# define vi          vector<int>
# define vll         vector<LL>
# define pii         pair<int,int>
# define all(v)      v.begin(),v.end()

const int MOD = 1000000007;
const int MAXN = 1e5 + 5;
const int INF = 1e9;
const int LN = 18;
const double PI = 3.14159265359;

template<class T> void in(T &x) { register T c=gc();x=0;T neg=0;for(;((c<48||c>57)&&c!='-');c=gc());if(c=='-'){neg=1;c=gc();}for(;c>47&&c<58;c=gc()){x=(x<<1)+(x<<3)+c-48;}if(neg)x=-x;}
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
LL power(LL a,LL b,LL m){ if(b==0) return 1; if(b==1) return a%m; LL t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}
LL lcm(LL a, LL b) { LL ret = a*b; ret /= __gcd(a,b); return ret;}
LL nC2(LL n) {LL ret = n*(n-1)/2; return ret;}

vector<int> primes;
void sieve(int n)
{
	bool isPrime[n + 1];
	memset(isPrime, true, sizeof(isPrime));
	isPrime[0] = isPrime[1] = false;
	for(int i = 2; i * i <= n; i++) {
		if (isPrime[i]) {
			for (int j = 2 * i; j <= n; j += i)
			 	isPrime[j] = false;
		}
	}
	for (int i = 2; i <= n; i++)
		if (isPrime[i])
			primes.push_back(i);
}

queue<int> choice[301];
int v[301], tot[301];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
    {
		for(int j=0;j<m;j++)
        {
			int x;
			cin>>x;
			choice[i].push(x-1);
		}
	}
	int ans=n;
	for(int i=0;i<m;i++)
    {
		int tans=0,idx=0;
		for(int j=0;j<m;j++)
            tot[j]=0;
		for(int j=0;j<n;j++)
        {
			while(v[choice[j].front()]==1)
				choice[j].pop();
			tot[choice[j].front()]++;
		}
		for(int j=0;j<m;j++)
        {
			tans=max(tans,tot[j]);
			if(tans==tot[j])
                idx=j;
		}
        v[idx]=1;
		ans=min(ans,tans);
	}
	cout<<ans;
}


Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    long double a,b,h,m;
    cin >> a >> b >> h >> m;

    long double aco = cos((0.5 * (h*60+m)) * M_PI / 180);
    long double asi = sin((0.5 * (h*60+m)) * M_PI / 180);

    long double bco = cos((6.0 * m) * M_PI / 180);
    long double bsi = sin((6.0 * m) * M_PI / 180);

    long double x1 = a * aco;
    long double y1 = a * asi;
    long double x2 = b * bco;
    long double y2 = b * bsi;

    cerr << "("<<x1<<","<<y1<<")"<<endl;
    cerr << "("<<x2<<","<<y2<<")"<<endl;


    cout << hypot(x1 - x2, y1 - y2) << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // メインプログラムここから
    string A, B, C; cin >> A >> B >> C;
    cout << "A" << B[0] << "C" << endl;
    // cout << "A" << B.front() << "C" << endl;
    // ここまで
}


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

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

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

using namespace std;

int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<char>> a(h,vector<char>(w));
  rep(i,h)rep(j,w)cin>>a[i][j];
  vector<bool> t(h),y(w);
  rep(i,h){
    rep(j,w){
      if(a[i][j]=='#')t[i]=y[j]=true;
    }
  }
  rep(i,h){
    if(t[i]){
      rep(j,w){
        if(y[j])cout<<a[i][j];
        if(j==w-1)cout<<endl;
      }
    }
  }
}


Measured memory_bytes: 256
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a,b = cin()
    if b>=2*a and b<=4*a and not b&1:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int n;
vector<int>arr,minArray;
int main()
{
    scanf("%d",&n);
    arr.resize(n);
    minArray.resize(n);
    for(int &i:arr)scanf("%d",&i);
    int mi=1e9;
    for(int i=0;i<n;i++)
    {
        mi=min(mi,arr[i]);
        minArray[i]=mi;
    }
    int ans=0;
    for(int i=0;i<n;i++)
        if(arr[i]<=minArray[i])ans++;
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int m=max({a,b,c});
    int ans=(a*b*c)/m/2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 1
c = [0, 0, 0]
for i in range(N):
    n = c.count(A[i])
    ans *= n
    ans %= MOD
    if n > 0:
        c[c.index(A[i])] += 1
print(ans)


Measured memory_bytes: 14396
n = int(input())

for i in range(n):
    first = False
    second = False
    third = False
    out = 0
    points = 0
    
    while (out != 3):
        event = raw_input()
        if event == "HIT":
            if first == True:
                if second == True:
                    if third == True:
                        points += 1

                    else:
                        third = True
                else:
                    second = True
            else:
                first = True

        elif event == "HOMERUN":
            if third == True:
                points += 4
            elif second == True:
                points += 3
            elif first == True:
                points += 2
            else:
                points += 1

            first = second = third = False

        else:
            out += 1

    print points

Measured memory_bytes: 6480
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, x, p[MAXN];
ll goal, b[MAXN], l[MAXN], r[MAXN], s[MAXN];
bool cmp(int x, int y) {
	return s[x] > s[y];
}
ll calc(int pos, ll t) {
	if (t <= b[pos]) return t * l[pos];
	else return b[pos] * l[pos] + (t - b[pos]) * r[pos];
}
ll check(ll t) {
	ll ans = 0, sum = 0;
	int lft = t % x;
	if (lft == 0) lft = x;
	int cnt = (t - lft) / x;
	assert(cnt < n);
	for (int i = 1; i <= cnt; i++)
		sum += s[p[i]];
	for (int i = cnt + 1; i <= n; i++)
		chkmax(ans, sum + calc(p[i], lft));
	sum += s[p[cnt + 1]];
	for (int i = 1; i <= cnt; i++)
		chkmax(ans, sum - s[p[i]] + calc(p[i], lft));
	return ans;
}
int main() {
	read(n), read(x);
	for (int i = 1; i <= n; i++) {
		read(b[i]), read(l[i]), read(r[i]);
		s[i] = b[i] * l[i] + (x - b[i]) * r[i];
		p[i] = i, goal += b[i] * l[i];
	}
	sort(p + 1, p + n + 1, cmp);
	if (goal == 0) {
		writeln(0);
		return 0;
	}
	ll l = 1, r = 1ll * n * x;
	while (l < r) {
		ll mid = (l + r) / 2;
		if (check(mid) >= goal) r = mid;
		else l = mid + 1;
	}
	writeln(l);
	return 0;
}

Measured memory_bytes: 6016
t,T = map(int,input().split())
a,A = map(int,input().split())
b, B = map(int,input().split())
p = a*t+A*T
q = b*t+B*T
if p == q:
    print('infinity')
elif p > q:
    if a > b:
        print(0)
    else:
        ans = 1
        r = p - q
        s = b*t - a*t
        m = s//r
        ans += 2*m
        if s%r == 0:
            ans -= 1
        print(ans)
else:
    if b > a:
        print(0)
    else:
        ans = 1
        r = q - p
        s = a*t - b*t
        m = s//r
        ans += 2*m
        if s%r == 0:
            ans -= 1
        print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vll a(n), sum(n+1);
    rep(i, 0, n) cin >> a[i];
    sum[0] = 0;
    rep(i, 0, n) sum[i+1] = sum[i] + a[i];
    ll ans = INF;
    rep(i, 1, n) {
        ans = min(ans, abs(sum[i] - (sum[n] - sum[i])));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3456
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll n;
    ll tmp;
    cin >> n;
    vector<pair<int,int>> a(n);
    REP(i,n){
        cin >> tmp;
        a[i] = make_pair(tmp, i+1);
    }
    sort(a.begin(), a.end());
    REP(i,n){
        cout << a[i].second << endl;
    }
    
}

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

int S[10000000];int N;

int  Binary_Search(int T[],int key){
  int left = 0;
  int right = N;
  while(left < right){
    int mid = (left + right) / 2;
    if(T[mid] == key)
	return 1;
      else if(key < T[mid])
	right = mid;
      else if(key >T[mid])
	left = mid + 1;
  }
  return 0;
}
  
  

int main(){
  int q;
  int a;
  int sum=0;
  

  cin>>N;
  for(int i=0;i<N;i++)cin>>S[i];
  cin>>q;

  for(int i=0;i<q;i++){
    cin>>a;
    sum += Binary_Search(S,a);
  }

  cout<<sum<<endl;

  return 0;

}
  
  

Measured memory_bytes: 3392
use std::io;


fn main() {
    let (a, b, c) = {
        let i = read::<isize>();
        (i[0], i[1], i[2])
    };
    if a == b { println!("{}", c); }
    else if b == c { println!("{}", a); }
    else { println!("{}", b); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include<stdio.h>

int main(){
  int x[10000],y[10000],i,j,h,w;
  for(i=0;i<10000;i++){
    scanf("%d %d",&x[i],&y[i]);
    if(x[i]==0&&y[i]==0){
      break;
    }
  }
  for(j=0;j<i;j++){
    for(h=0;h<x[j];h++){
      for(w=0;w<y[j];w++){
        if(h==0||h==x[j]-1){
          printf("#");
        }
        else{
          if(w==0||w==y[j]-1){
            printf("#");
          }
          else{
            printf(".");
          }
        }
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    ll n, t, ans = 0; cin >> n >> t;
    ll array[n]; REPI(i, n) cin >> array[i];

    REPI(i, n){
        if((array[i + 1] - array[i]) >= t) ans += t;
        else ans += array[i + 1] - array[i];
    }cout << ans;
}


Measured memory_bytes: 1792
v,e = map(int,input().split())
cost = []
for i in range(v):
    T = [float('inf')]*v
    T[i] = 0
    cost.append(T)
for i in range(e):
    a,b,c = map(int,input().split())
    cost[a][b] = c
for k in range(v):
    for i in range(v):
        for j in range(v):
            cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j])
flag = True
for i in range(v):
    for j in range(v):
        if cost[i][j] == float('inf'):
            cost[i][j] = 'INF'
        elif i == j and cost[i][j] < 0:
            flag = False
            break
if flag:
    for i in range(v):
        print(' '.join(map(str,cost[i])))
else:
    print('NEGATIVE CYCLE')


Measured memory_bytes: 6036
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, M; cin >> N >> M;
	vector<int> A(M, 0);
	for (int i = 0; i < N; i++)
	{
		int k;
		cin >> k;
		for (int j = 0; j < k; j++)
		{
			int a; cin >> a; a--;
			A[a]++;
		}
	}

	int res = 0;
	for (int i = 0; i < M; i++)
	{
		if(A[i] == N) res++;
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define MIN(A,B) ((A)<=(B)?(A):(B))
#define MAX(A,B) ((A)>=(B)?(A):(B))
int X,Y,Z,V[4],E[51],A[51];
double dp[51][5001];
int main() {
	while(scanf("%d %d %d",&X,&Y,&Z),X) {
		for(int i=0;i<X;i++) {
			scanf("%d",&V[i]);
		}
		memset(E,0,sizeof(E));
		memset(A,0,sizeof(A));
		for(int i=0;i<Z;i++) {
			int n;
			scanf("%d",&n);
			scanf("%d %d",&E[n],&A[n]);
		}
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for(int i=0;i<Y;i++) {
			for(int j=0;j<=5000;j++) {
				if(dp[i][j]==0) continue;
				for(int k=0;k<X;k++) {
					int next=MIN(Y,i+V[k]),money=j;
					if(E[next]==2) money+=A[next];
					if(E[next]==3) money=MAX(0,money-A[next]);
					if(E[next]==1) next=MIN(Y,next+A[next]);
					dp[next][money]+=dp[i][j]/X;
				}
			}
		}
		double sum=0;
		for(int i=0;i<=5000;i++) {
			sum+=i*dp[Y][i];
		}
		printf("%d\n",(int)sum);
	}
}

Measured memory_bytes: 3028
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef pair<int,int> P;
#define F first
#define S second
int fie[1111][1111];
int N,M;
int sosu[1000001];
P mie[1000001];
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};

P dp[1111][1111];
int ndx[]={1,0,-1};
P solve(int x,int y,int ss,int count){
  if(dp[x][y].F!=-1 && dp[x][y].S!=-1) return dp[x][y];
  if(fie[x][y]>N ||  fie[x][y] == -1 ){
    return P(0,-1);
  }
  if(!sosu[fie[x][y]]){count++; ss = fie[x][y]; }
  // printf("%d %d   count = %d  ss = %d fie=%d\n",x,y,count,ss,fie[x][y]);
  P ret = P(0,-1);
  for(int i=0;i<3;i++){
    int nx = x+ndx[i];
    int ny = y+1;
    P state = solve(nx,ny,ss,count);
    ret = max(ret,state);
  }
  if(!sosu[fie[x][y]]){
    ret.F++;
    if(ret.S==-1) ret.S=fie[x][y];
  }
  // printf("%d dp[%d][%d] =  %d, %d fie=%d\n",ss,x,y,ret.F,ret.S,fie[x][y]);
   return dp[x][y] = ret;
}

int main(){
  sosu[1]=1;
  sosu[0]=1;
  for(int i=2;i<=1000000;i++){
    if(!sosu[i]){
      for(int j=i+i;j<=1000000;j+=i){
	sosu[j]=1;
      }
    }
  }
  for(int i=0;i<1111;i++)
    for(int j=0;j<1111;j++)
      dp[i][j]=P(-1,-1);
  memset(fie,-1,sizeof(fie));


  int x = 1111/2,y = 1111/2;
  int id = 1, ic = 0;
  //printf("%d %d\n",x,y);
  fie[x][y]=1;
  x += dx[ic]; y += dy[ic];
  mie[1]=P(x,y);
 
  while( id < 1000000 ){
    id++;
    fie[x][y]=id;
    mie[id] = P(x,y);
    //if(id==1000000) printf("%d %d %d\n",id,x,y);
    //    if(!sosu[fie[x][y]]) if(id<1000) printf("sosu::%d %d %d\n",id,x,y);
    int nc = (ic+1)%4;
    int nx = x+dx[nc], ny = y+dy[nc];
    if( fie[nx][ny] == -1 ){
      x = nx; y=ny;
      ic=nc;
    } else {
      x = x + dx[ic]; y = y + dy[ic];
    }
  }


  /*    for(int i=110;i<1111;i++){
    for(int j=1100;j<1111;j++){
      printf("%3d ",fie[j][i]);
    }
    puts("");
  }
  */

  while(1){
    for(int i=0;i<1111;i++)
      for(int j=0;j<1111;j++)
	dp[i][j]=P(-1,-1);
    
    cin >> N >> M;
    if(!N && !M) break;
    //    printf("%d %d\n",mie[N].F,mie[N].S);
    P res = solve(mie[M].F,mie[M].S,-1,0);
    /*    if(sosu[fie[mie[M]][Mie[M]]]){
      res.F ++;
      }*/
    if(res.S == -1)
      printf("%d %d\n",0,0);
    else
      printf("%d %d\n",res.F,res.S);
    
  }
  
  
}

Measured memory_bytes: 27444
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,K;
  cin >> A>>B>>C>>K;
  if(A+B>K){
  cout << K << endl;
  }
  else{
    cout << 2*A+B-K << endl;
  }
    return 0; 
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int tmp;

        if(a > b){
            tmp = a;
            a = b;
            b = tmp;
        }
        if(c < a){
            tmp = c;
            c = b;
            b = a;
            a = tmp;
        }else if(c < b){
            tmp = c;
            c = b;
            b = tmp;
        }

        System.out.println(a + " " + b + " " + c);
    }
}



Measured memory_bytes: 26128
import numpy as np

def divisors(N):
    return sorted(sum((list({n, N // n}) for n in range(1, int(N ** 0.5) + 1) if not N % n), []))

def prime_factorize_dict(n):
    d = dict()
    while not n & 1:
        d[2] = d.get(2, 0) + 1
        n >>= 1
    f = 3
    while f * f <= n:
        if not n % f:
            d[f] = d.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = d.get(n, 0) + 1
    return d

N = int(input())
count = 0
for n in divisors(N)[1:]:
    M = N
    while not M % n:
        M //= n
    count += M % n == 1
fact_Nm1 = np.array(list(prime_factorize_dict(N - 1).values()), dtype=np.int32)
print(count + np.prod(fact_Nm1 + 1) - 1)

Measured memory_bytes: 12444
#include <cassert>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

void forwardChar(string &s, int &c) {
  if (c != s.size()) c++;
}
void forwardWord(string &s, int &c) {
  for (;c<s.size()&&s[c]==' ';++c);
  for (;c<s.size()&&s[c]!=' ';++c);
}
void backwardChar(string &s, int &c) {
  if (c) c--;
}
void backwardWord(string &s, int &c) {
  for (;c>0&&s[c-1]==' ';--c);
  for (;c>0&&s[c-1]!=' ';--c);
}
void insertText(string &s, int &c, const string &t) {
  s = s.substr(0,c) + t + s.substr(c);
  c += t.size();
}
void deleteChar(string &s, int &c) {
  if (c != s.size()) {
    s = s.substr(0,c) + s.substr(c+1);
  }
}
void deleteWord(string &s, int &c) {
  int p = c;
  for (; p<s.size()&&s[p]==' '; ++p);
  if (p==s.size()) return;
  for (; p<s.size()&&s[p]!=' '; ++p);
  s = s.substr(0,c) + s.substr(p);
}

int main() {
  int n;
  cin >> n;
  cin.ignore();
  while(n--) {
    string text;
    getline(cin, text);
    int m; cin >> m;
    // cout << m << endl;
    // cout << text << endl;
    int cursor = 0;
    while(m--) {
      string op1, op2;
      cin >> op1;
      cin.ignore();
      getline(cin,op2);
      // cout << op1 << " : " << op2 << endl;
      
      if (op1[0] == 'f') {
        if (op2[0] == 'c') forwardChar(text, cursor);
        else forwardWord(text, cursor);
      } else if (op1[0] == 'b') {
        if (op2[0] == 'c') backwardChar(text, cursor);
        else backwardWord(text, cursor);
      } else if (op1[0] == 'i') {
        assert(op2[0]=='"' && op2[op2.size()-1]=='"');
        op2 = op2.substr(1, op2.size()-2);
        insertText(text, cursor, op2);
      } else if (op1[0] == 'd') {
        if (op2[0] == 'c') deleteChar(text, cursor);
        else deleteWord(text, cursor);
      } else {
        assert(0);
      }
      assert(cursor>=0 && cursor<=text.size());
      // cout << text << " " << cursor << endl;
    }

    text = text.substr(0,cursor) + "^" + text.substr(cursor);
    cout << text << endl;
  }
}

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

int main(){
  int x1,y1,x2,y2;
  cin >>x1 >>y1 >>x2 >>y2;
  int X = x1-x2;
  int Y = y1-y2;
  cout << x2+Y << " " << y2-X << " " << x2+Y+X << " " << y2-X+Y << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower

using namespace std;

int main()
{
    //system("chcp 65001");

    int A,B;
    cin >> A >> B;

    if(A <= 9 && B <= 9)
    {
        cout << A * B;
    }
    else
    {
        cout << "-1";
    }
    

    return 0;
}

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

typedef long long ll;
#define rep(n, i) for(size_t i = 0; i < n; ++i)

void solve(void) {
  string s; cin >> s;
  string res = "";
  rep(s.size(), i) res += "x";

  cout << res << endl;
}
int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define ll long long
#define INF 10000
using namespace std;

int main(){
	int N,T;
	cin >>N>>T;
	vector<int> c(N);
	vector<int> t(N);
	int ans=INF;
	for(int i=0;i<N;i++){
		cin >>c[i]>>t[i];
		if(t[i]<=T){
			ans=min(ans,c[i]);
		}
	}
	if(ans>=INF){
		cout <<"TLE"<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int n,k;
ll MOD,f[305][305],c[305][305],sum[305][305];
int main()
{
	scanf("%d%d%lld",&n,&k,&MOD);
	c[0][0]=1;
	for(int i=0;i<=300;i++)
	for(int j=0;j<=300;j++)
	{
		if(c[i][j]>=MOD)c[i][j]-=MOD;
		c[i+1][j+1]+=c[i][j];
		c[i+1][j]+=c[i][j];
	}
	for(int i=k;i>=0;i--)
	{
		f[1][i]=1;
		sum[1][i]=sum[1][i+1]+1;
	}
	for(int i=2;i<=n+1;i++)
	{
		for(int j=k-1;j>=0;j--)
		{
			for(int s=1;s<i;s++)
			  f[i][j]=(f[i][j]+f[i-s][j]*sum[s][j+1]%MOD*c[i-2][s-1])%MOD;
			sum[i][j]=(sum[i][j+1]+f[i][j])%MOD;
		}
	}
	printf("%lld\n",f[n+1][0]);
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;
//using namespace boost::multiprecision;


int main(){

    string s;
    cin >> s;

    vector<int> count(26);

    rep(i,4){
        count[(int)(s[i] - 'A')]++;
    }

    sort(ALL(count));

    if(count[24] == 2 && count[25] == 2){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

int main(){
    long long N,ans,i,k;
    cin >> N;
    vector<long long> A(N+1,0),B(N+1,0),C(N+1,0);

    for(i = 1;i <= N;i++){
        cin >> A[i];
    }

    for(i = 1;i <= N;i++){
        cin >> B[i];
    }

    for(i = 1;i <= N-1;i++){
        cin >> C[i];
    }

    for(k = 1;k <= N;k++){

        ans += B[A[k]];

        if(A[k] == A[k-1] + 1 && k != 1){
            ans += C[A[k - 1]];
        }
    }

    cout << ans << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;



int main(){
    int N;cin >> N;
    int f=0;
    LL ans=0;
    for (int i = 0; i < N; i++) {
        int h;
        cin >> h;
        f=max(f,h);
        ans+=h;
    }
    cout << ans-f/2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	ff 				first
#define 	ss				second
#define 	pb				push_back
#define 	mp				make_pair
#define 	bb 				begin()
#define     rb              rbegin()
#define 	ee 				end()
#define     ub              upper_bound
#define     lb              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define     sorta(v)         sort(all(a))
#define     sortd(v)        sort(all(a), greater<ll >())
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vvll            vector<vll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

bool compare_float(double x, double y){
    return fabs(x - y) < DBL_EPSILON;
}

double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
// vll pwx(11);
// void cal(ll x){ pwx[0] = 1; rep(i, 1, 11)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve() {
  ll n;cin >> n;

  vll a(n), b(n);

  for(auto &i : a) cin >> i;

  b = a;

  for(ll i =  n - 2 ; i >= 0 ; i--) {
    a[i] += a[i+1];
    a[i] %= mod;
  }

  ll ans = 0;

  for(ll i = 0 ; i < n-1 ; i++) {
    ans += (b[i] * a[i+1]) % mod;
    ans %= mod;
  }

  cout << ans << nl;


}

 
int main(){
  // boost;
  // cal(1);

  // // For getting input from input.txt file 
  // freopen("timber_input.txt", "r", stdin); 

  // // Printing the Output to output.txt file 
  // freopen("output.txt", "w", stdout);


  int t = 1, k = 1;
  // cin>>t;
  while(t--){
      // cout<<"Case #"<<k<<": ";
      solve();
      k++;
  }
}

Measured memory_bytes: 6408
import itertools
def main():
    num = list(map(int, input().split()))
    num.sort()

    if num[0] == 1 and num[1] == 4 and num[2] == 7 and num[3] == 9:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n , c ;
    cin >> n >> c ;
    vector<tuple<double,double,int>> tup(n) ;
    vector<pair<double,int>> fin ;
    REP(i,n){
        double a, b ;
        int k ;
        cin >> a >> b >>  k ;
        tup[i] = MT(a,b,k) ;
    }
    sort(ALL(tup)) ;

    fin.PB(MP(get<1>(tup[0]),get<2>(tup[0]))) ;

    bool f = true ;

    FOR(i,1,n){
        f = true ;
        sort(ALL(fin)) ;
        REP(j,SZ(fin)){
            if(fin[j].SE==get<2>(tup[i]) && fin[j].FI<=get<0>(tup[i])){
                fin[j] = MP(get<1>(tup[i]),get<2>(tup[i])) ;
                f = false ;
                break ;
            }
            else if(fin[j].SE!=get<2>(tup[i]) && fin[j].FI+0.5<=get<0>(tup[i])){
                fin[j] = MP(get<1>(tup[i]),get<2>(tup[i])) ;
                f = false ;
                break ;
            }
        }
        if(f){
            fin.PB(MP(get<1>(tup[i]),get<2>(tup[i]))) ;
        }

    }
    cout << SZ(fin) <<endl ;



    

    return 0;
}


Measured memory_bytes: 2560
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [n]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const a: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    return `${a.map((i, index) => [i, index]).sort(([i1, _1], [i2, _2]) => i1 - i2).map(([_, i]) => i + 1).join(" ")}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


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

typedef long long ll;

int main() {
    string N;
    cin >> N;
    rep(i, 3) {
        if (N[i] == '7') {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

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

typedef long long ll;

const int maxn = 1e5 + 5;

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

  int H, W, h, w; cin >> H >> W >> h >> w;
  int ans = H * W - h * W - H * w + h * w;
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>

long fact(int n);

int main(void)
{
	int n;

	scanf("%d", &n);

	printf("%ld\n", fact(n));

	return (0);
}

long fact(int n)
{
	if (n == 0){
		return (1);
	}

	return (n * fact(n - 1));
}

Measured memory_bytes: 592
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream& operator<<(ostream& out, vector<T> &v){
  for (int i = 0; i < (int)v.size(); i++) {
    out<<v[i]<<' ';
  }
  return out;
}

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

  string s;
  cin >> s;
  if(s[1] == 'B') cout << "ARC";
  else cout << "ABC";


  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n ; cin >> n;
	string str; getline(cin,str); //ignore
	while(n--)
	{
		getline(cin,str);
		int alpha[26];
		int a=0,b=0; bool flag=false;
		for( ;a<26;a++)
		{
			if(a%2==0 || a%13==0) continue;
			for(b=0;b<26;b++)
			{
				for(int r=0;r<26;r++) alpha[r]=(a*r+b)%26;
				bool table[26]={0}; int k=0;
				for( ;k<26;k++)
					if(table[alpha[k]]) break;
				if(k<26) break;
				string THIS="", THAT="";
				THAT+=('a'+alpha['t'-'a']); THAT+=('a'+alpha['h'-'a']); THAT+=('a'+alpha[0]); THAT+=('a'+alpha['t'-'a']);
				THIS+=('a'+alpha['t'-'a']); THIS+=('a'+alpha['h'-'a']); THIS+=('a'+alpha['i'-'a']); THIS+=('a'+alpha['s'-'a']);
				for(int i=0;i<str.size();i++)
				{
					string ss=str.substr(i,4);
					if(ss==THAT || ss==THIS) {flag=true; break;}
				}
				if(flag) break;
			}
			if(flag) break;
		}
		string ans="";
		for(int i=0;i<str.size();i++)
		{
			char ch; ch=str[i];
			if(!islower(ch)) ans+=ch;
			else
			{
				for(int j=0;j<26;j++)
					if(alpha[j]==ch-'a') {ans+=('a'+j); break;}
			}
		}
		cout << ans << endl;
		//for(int i=0;i<26;i++) cout << alpha[i] << ' ' ; cout << endl;
	}
}

Measured memory_bytes: 1224
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 22:01:38 2019

@author: aozora
"""
N,S = open(0).read().split()
N = int(N)
T = []
MOD = 10**9+7
for i,c in enumerate(S):
  if i%2==0:
    if c=='B':
      T.append('W')
    else:
      T.append('B')
  else:
    T.append(c)

pre = 0
ans = 1
for c in T:
  if c=='B':
    ans *= pre
    ans %= MOD
    pre -= 1
    flag = False
  else:
    pre += 1
if T.count('B')!=T.count('W'):
  ans = 0
coef = 1
for i in range(1,N+1):
  coef *= i
  coef %= MOD
print(ans*coef%MOD)

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

int main() {
  int N, A, B;
  string S;
  cin >> N >> A >> B >> S;

  int A_n = 0, B_n = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'a' && A_n + B_n < A + B) {
      cout << "Yes" << endl;
      A_n++;
    } else if (S[i] == 'a') cout << "No" << endl;
    else if (S[i] == 'b' && A_n + B_n < A + B && B_n < B) {
      cout << "Yes" << endl;
      B_n++;
    } else if (S[i] == 'b')cout << "No" << endl;
    else cout << "No" << endl;
  }

  return 0;
}

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

int main() {
    int n, l;
    int x[20], dx[20];
    while(true) {
        scanf("%d%d", &n, &l);
        if(n == 0 && l == 0) break;
        for(int i = 0; i < n; ++i){
            char c;
            scanf(" %c %d", &c, x + i);
            dx[i] = (c == 'L') ? -1 : 1;
        }
        int v, t = 0, e;
        char alive[20], updated = true, drop;
        fill(alive, alive + n, 1);
        while(updated){
            ++t;
            updated = false;
            drop = false;
            for(int i = 0; i < n; ++i){
                if(!alive[i]) continue;
                x[i] += dx[i];
                if(x[i] == 0 || x[i] == l){
                    if(!drop || (drop && x[i] == 0)){
                        v = i;
                    }
                    drop = true;
                    alive[i] = false;
                }else{
                    updated = true;
                }
            }
            for(int i = 0; i < n; ++i){
                if(!alive[i]) continue;
                for(int j = i + 1; j < n; ++j){
                    if(!alive[j]) continue;
                    if(x[i] == x[j]){
                        dx[i] *= -1;
                        dx[j] *= -1;
                    }
                }
            }
        }
        printf("%d %d\n", t, v + 1);
    }
    return 0;
}

Measured memory_bytes: 1188
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: i64,
    }
    println!(
        "{}",
        match n % 10 {
            2 | 4 | 5 | 7 | 9 => "hon",
            0 | 1 | 6 | 8 => "pon",
            3 => "bon",
            _ => unreachable!(),
        }
    );
}


Measured memory_bytes: 2164
def prime_factors(N):
    from collections import defaultdict
    factors = defaultdict(int)
    for i in range(2,int(N**.5)+1):
        while N % i == 0:
            N //= i
            factors[i] += 1
    if N > 1:
        factors[N] += 1
    return dict(factors)

N,P=map(int, input().split())
factors=prime_factors(P)
ans=1
for k,v in factors.items():
    ans*=k**(v//N)
print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N, M, Q; 
vector<int> A, B, C, D;

int dfs(int n, vector<int> &v){ 
  int ret = 0;
  if(n == N){
    REP(i, N-1){
      if(v[i+1] < v[i]) return 0;
    }
    REP(i, Q){
      if(v[B[i]]-v[A[i]] == C[i]) ret += D[i];
    }

    return ret;
  }

  FOR(i, 1, M+1){
    if(n != 0){
      if(v[n-1] <= i){
        v[n] = i;
        chmax(ret, dfs(n+1, v));
      }
    }else{
      v[n] = i;
      chmax(ret, dfs(n+1, v));
    }
  }
  return ret;
}

signed main() {
  cin >> N >> M >> Q;

  A.resize(Q);
  B.resize(Q);
  C.resize(Q);
  D.resize(Q);
  REP(i, Q){
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    A[i]--; B[i]--;
  }

  vector<int> vec(N);
  cout << dfs(0, vec) << "\n";

  return 0;
}

Measured memory_bytes: 3664
/* ***********************************************
Author        :yang12138
Created Time  :2017/12/2 3:17:26
File Name     :A.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;

void solve(){
	int a,b,c,d;
	int n;
	cin>>a>>b>>c>>d>>n;
	d=min(d,a*8),d=min(d,b*4),d=min(d,c*2);
	c=min(c,a*4),c=min(c,b*2);
	b=min(b,a*2);

	ll ans=1LL*d*(n/2);
	n%=2;
	ans+=1LL*c*n;
	cout<<ans<<endl;
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
     
    using namespace std;
     
    #define all(x) x.begin(), x.end()
    typedef vector<int> vi;
    typedef pair<int,int> ii;
    typedef long long ll;
     
    const ll inf = 3e18 + 5;
     
    const int MAXN = 1 << 19;
    int N = 400000;
    int seg[2 * MAXN], A[MAXN];
    typedef vector<vi> vvi;
    
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
    
        string s;
        cin >> s;
        for(int i=0; i<19; i++){
            if(s[i]==',')
                cout << ' ';
            else
                cout << s[i];
        }
    }

Measured memory_bytes: 256
import math
A,B = list(map(int,input().split()))
A_ans_mini = math.ceil(A/0.08)
A_ans_max = math.floor((A+0.9999)/0.08)
B_ans_mini = math.ceil(B/0.1)
B_ans_max = math.floor((B+0.9999)/0.1)
if A_ans_max <B_ans_mini or B_ans_max < A_ans_mini:
    print("-1")
else:
    if B_ans_mini<A_ans_mini:
        ans = A_ans_mini
    else: ans = B_ans_mini
    print(int(ans))

Measured memory_bytes: 3064