akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline

    n,k,q = map(int,input().split())
    a = list(map(int,input().split()))

    res = 10**9
    for e in a:
        tank = []
        new = []
        for je in a:
            if e <= je:
                tank.append(je)
            else:
                if len(tank) >= k:
                    tank.sort()
                    for i in range(len(tank)-k+1):
                        new.append(tank[i])
                tank = []
        if len(tank) >= k:
            tank.sort()
            for i in range(len(tank)-k+1):
                new.append(tank[i])
        new.sort()
        if len(new) > q-1:
            res = min(res,new[q-1]-e)
    print(res)

if __name__ =='__main__':
    main()

Measured memory_bytes: 45532
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int const N = 3e5 + 5;
int cnt[N];
int pr[N];
vector<int> f;
int n;

bool check(int k, int t) {
    if (t * k * 1ll > pr[n])
        return false;
    int i = lower_bound(f.begin(), f.end(), t) - f.begin();
    if (pr[i] >= 1ll * (i - (n - k)) * t)
        return true;
    else
        return false;
}

int bin_search(int k) {
    int l = 0; int r = N;
    while(l < r) {
        int med = (l + r) / 2;
        if (check(k, med))
            l = med + 1;
        else
            r = med;
    }
    return l - 1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int cpn;
    cin >> cpn;
    for (int i = 0; i < cpn; ++i) {
        int x;
        cin >> x;
        ++cnt[x];
    }
    for (auto x : cnt) {
        if (x)
            f.push_back(x);
    }
    sort(f.begin(), f.end());
    n = f.size();
    for (int i = 0; i < f.size(); ++i)
        pr[i + 1] = pr[i] + f[i];
    for (int i = 1; i <= cpn; ++i) {
        cout << bin_search(i) << '\n';
    }
    return false;
}


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

int main()
{
  char op;
  int kazu = 0;
  int sum = 0;
  
  cin >> sum;
  
  while(1)
    {
      cin >> op;
      if ( op == '=' )break;
      
      cin >> kazu;

      if(op == '+')
	{
	  sum = sum + kazu;
	}
      if(op == '-')
	{
	  sum -= kazu;
	}
      if(op == '*')
	{
	  sum *= kazu;
	}
      if(op == '/')
	{
	  sum /= kazu;
	}
    }
  cout << sum << endl;
}



Measured memory_bytes: 3080
//
// Created on 2020/08/14.
//


#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
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int a,b;
    cin>>a>>b;
    int k;
    cin>>k;
    vector<int>list = {INF};
    for (int i = 100; i >= 1 ; --i) {
        if(a % i == 0 && b % i == 0){
            list.push_back(i);
        }
    }
    cout<<list[k]<<endl;
    return 0;
}


Measured memory_bytes: 3600
#!/usr/bin/env python3
import sys


def solve(N: int):
    ans = []
    
    while(N != 0):
        r = N % 2
        if(r < 0):
            r += 2
        ans.append(r)
        N = int((N-r)/(-2))
    if(not ans):
        print(0)
    else:
        print(''.join(map(str, reversed(ans))))
        
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;

    int cntrl = 0;
    int cntlr = 0;
    int ml = 0;
    int mr = 0;
    int sum = 0;

    if(s[0] == 'L'){
        ml++;
    }
    if(s[n-1] == 'R'){
        mr++;
    }

    REP(i,n-1){
        if(s[i] == 'R' && s[i+1] == 'R'){
            sum++;
        }
    }

    for(int i = n - 1; i > 0; i--){
        if(s[i] == 'L' && s[i-1] == 'L'){
            sum++;
        }
    }

    REP(i,n-1){
        string tmp = s.substr(i,2);
        if(tmp == "LR"){
            cntlr++;
        }
        else if(tmp == "RL"){
            cntrl++;
        }
    }

    int p2 = min(cntrl,cntlr);
    int p1 = 0;

    if(k <= p2){
        p2 = k;
    }
    else if(cntlr > cntrl && ml+mr > 0){
        p1++;
    }
    else if(cntlr < cntrl && ml + mr < 2){
        p1++;
    }
    cout << sum + p2*2+p1 << endl;
    return 0;
}

Measured memory_bytes: 512
#![allow(unused)]

use std::cmp::Reverse;

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Self {
        Self { reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get_str(&mut self) -> &str {
        if let Some(t) = self.iter.next() {
            return t;
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get_str()
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        self.get_str().parse().ok().expect("Parse error")
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}

fn count_paren(s: &Vec<char>) -> (i64, i64) {
    s.iter().fold((0, 0), |(c, o), &p| {
        match p {
            '('        => (c, o + 1),
            _ if o > 0 => (c, o - 1),
            _          => (c + 1, o),
        }
    })
}

#[test]
fn test_count_paren() {
    assert_eq!(count_paren(&"(((((".chars().collect()), (0, 5));
    assert_eq!(count_paren(&")))))".chars().collect()), (5, 0));
    assert_eq!(count_paren(&")))((".chars().collect()), (3, 2));
    assert_eq!(count_paren(&"(()))".chars().collect()), (1, 0));
}

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let n: usize = sc.get();
    let ss: Vec<Vec<char>> =
        (0..n).map(|_| sc.get_str().chars().collect()).collect();

    let mut inc = vec![];  // 開き括弧のほうが多い
    let mut dec = vec![];  // 閉じ括弧のほうが多い
    let mut last = vec![]; // 閉じ括弧のみ
    for s in &ss {
        let (c, o) = count_paren(s);
        if o - c >= 0 {
            inc.push((c, o));
        } else if o > 0 {
            dec.push((c, o));
        } else {
            last.push((c, o));
        }
    }

    // 最初は '((..(' になる必要があるので，閉じ括弧の少ないものから順
    inc.sort_unstable_by_key(|&(c, _)| c);

    // 開き括弧の数に余裕があるうちに閉じ括弧の多いものから処理
    // 例えば '((((' '))))((' '))(' ')' は OK だが，それを並べ替えた
    //        '((((' '))(' '))))((' ')' は NG.
    // 閉じ括弧が同数なら開き括弧の多いものを先に持ってきて開き括弧の数を確保
    // 例えば '((' '))((' '))(' ')' は OK だが，それを並べ替えた
    //        '((' '))(' ))((' ')' は NG.
    dec.sort_unstable_by_key(|&(c, o)| (Reverse(c), Reverse(o)));

    // 最後は '))..)' になる必要がある．last は順不同．

    if Some(0) == inc.iter()
        .chain(dec.iter())
        .chain(last.iter())
        .fold(Some(0), |a, &(c, o)| {
            a.and_then(|x| if x - c < 0 { None } else { Some(x - c + o) })
        })
    {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)
#define INF 1e9
#define MP(a, b) make_pair(a, b)

int W, H;
bool m[52][52];
int cost[52][52];
queue<pair<int, pair<int, int>>> q;

void mypush(int co, int r, int c)
{
	int dr[] = {-1,  0,  0,  1};
	int dc[] = { 0,  -1,  1,  0};
	rep(i, 4) {
		if (cost[r+dr[i]][c+dc[i]] == INF && m[r+dr[i]][c+dc[i]]) {
			cost[r+dr[i]][c+dc[i]] = co+1;
			q.push(MP(co+1, MP(r+dr[i], c+dc[i])));
		}
	}
}
int culc()
{
	rep(i, 52) rep(j, 52) cost[i][j] = INF;
	cost[1][1] = 1;
	q.push(MP(1, MP(1, 1)));
	while(!q.empty()) {
		auto t = q.front();
		auto tt = t.second;
		q.pop();
		mypush(t.first, tt.first, tt.second);
	}
	return cost[H][W];
}
int main(void){
	int res = 0;
	cin >> H >> W;
	rep(i, H) rep(j, W) {
		char c;
		cin >> c;
		m[i+1][j+1] = c == '.';
		res += m[i+1][j+1];
	}
	int co = culc();
	if (co == INF) cout << -1 << endl;
	else cout << res - co << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstdio>
#include<vector>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;
int INF=900000000;
int n,k;
int c[5001],r[5001];
vector<int> vec[5001]; 
int nowcost[5001][5001];
int res[5001];

void bfs(int f){
	queue<PP> que;
	que.push(PP(r[f],P(f,c[f])));
	while(que.size()){
		PP p=que.front();
		que.pop();
		int co=p.second.second,t=p.second.first,gas=p.first;
		if(nowcost[f][t]<co && f!=t)continue;
		gas--;
		if(gas>=0){
			for(int i=0;i<vec[t].size();i++){
				int tt=vec[t][i];
				if(nowcost[f][tt]>co){
					nowcost[f][tt]=co;
					que.push(PP(gas,P(tt,co)));
				}
			}
		}
	}
}

int dijk(){
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,1));
	while(que.size()){
		P p=que.top();
		que.pop();
		int co=p.first,t=p.second;
		if(res[t]<co)continue;
		res[t]=co;
		for(int i=1;i<=5000;i++){
			if(res[i]>co+nowcost[t][i]){
				res[i]=co+nowcost[t][i];
				que.push(P(res[i],i));
			}
		}
	}
	return res[n];
}

int main(void){
	for(int i=0;i<=5000;i++){
		res[i]=INF;
		for(int j=0;j<=5000;j++)nowcost[i][j]=INF;
		nowcost[i][i]=0;
	}
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d%d",&c[i],&r[i]);
	for(int i=0;i<k;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	for(int i=1;i<=n;i++)bfs(i);
	printf("%d\n",dijk());
	return 0;
}

Measured memory_bytes: 99488
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string S;
  long w;
  cin >> S >> w;
  char result[1010] = { 0 };

  for (long i = 0; i < S.size(); i += w) result[i/w] = S[i];

  puts(result);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
#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() {
	double r, l, s;
	cin >> r;
	l = 2 * (double)r * (double)pi;
	s = (double)r * (double)r * (double)pi;
	printf("%.5lf ", s);
	printf("%.5lf\n", l);
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    string S;
    cin >> S;
    int ans = LLINF;
    for(int i = 0; i < S.length() - 2; ++i) {
        int val = atoi(S.substr(i, 3).c_str());
        ans = min(ans, abs(val - 753));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define DEBUG 0
#define REP(i, n) for (int i = 0; i < (n); i++) 
typedef long long ll;
typedef pair<int,int> pint;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

template<typename T>
vector<T> Divisors(T n)
{
    vector<T> result;

    T boundary = sqrt(n);

    for (T i = 1; i <= boundary; i++) {
        if (n % i == 0) {
            result.push_back(i);
            if(i != (n / i) && i * i != n)
                result.push_back(n/i);
        }
    }
    sort(result.begin(),result.end());
    return result;
}

// return true:素数
bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
//正の公約数を求める (vec.push)
//選ぶ値は互いに素でないといけないので、
//素数に対してのみ行えばよさそう
// aとbの公約数で素数のものはいくつか
int main() { 
    ll a,b;
    cin >> a >> b;

    vector <ll> vec;
    vec = Divisors(min(a,b));

    ll res = 1;

    for(ll i = 1; i < vec.size(); ++i)
    {
        if(IsPrime(vec[i]) == true)
        {
            if(a % vec[i] == 0 && b % vec[i] == 0)
            {
                ++res;
            }
        }
    }

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

Measured memory_bytes: 384
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    s = ns()

    if s == 'ABC':
        print('ARC')
    else:
        print('ABC')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9604
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 100000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll h,w,k ;
	cin >> h >> w >> k ;
	if(w==1){
		cout << 1 << endl ;
		return 0 ;
	}
	vvll dp(h+2,vll(w,0)) ;
	dp.at(0).at(0) = 1 ;
	for(int i=1;i<=h+1;i++){
		for(int j=0;j<(1<<(w-1));j++){
			bitset<10> bit(j) ;
			bool ok = true ;
			for(int l=1;l<10;l++){
				if(bit[l]&&bit[l-1]) ok = false ;
			}
			if(!ok) continue ;
			for(int l=0;l<w;l++){
				if(l!=0&&bit[l-1]) (dp.at(i).at(l) += dp.at(i-1).at(l-1)) %= mod ;
				if(l!=w-1&&bit[l]) (dp.at(i).at(l) += dp.at(i-1).at(l+1)) %= mod ;
				if(l==0&&!bit[l]) (dp.at(i).at(l) += dp.at(i-1).at(l)) %= mod ;
				if(l==w-1&&!bit[l-1]) (dp.at(i).at(l) += dp.at(i-1).at(l)) %= mod ;
				if(l!=0&&l!=w-1&&!bit[l]&&!bit[l-1]) (dp.at(i).at(l) += dp.at(i-1).at(l)) %= mod ;

			}
		}
	}
//	for(int i=0;i<h+1;i++) for(int j=0;j<w;j++) cout << dp.at(i).at(j) << (j==w-1?'\n':' ') ;
	cout << dp.at(h).at(k-1) << endl ;
}


Measured memory_bytes: 256
/**
 * 
 */
import java.util.*;
/**
 * @author akira
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		pair[][] cos = new pair[2][1000]; /* first は顧客番号 second　は取引回数 */
		int[] cosCnt = new int[2];
		int month = 0;
		while(scan.hasNextLine()){
			String str = scan.nextLine();
			if(str.indexOf(",") == -1){
				month++;
				if(month == 2){
					break;
				}
				continue;
			}
			int cosNum = Integer.parseInt(str.substring(0,str.indexOf(",")));
			int i;
			for(i = 0;i < cosCnt[month];i++){
				if(cos[month][i].first == cosNum){
					cos[month][i].second++;
					break;
				}
			}
			if(cosCnt[month] == i){
				cos[month][i] = new pair(cosNum,1);
				cosCnt[month]++;
			}			
		}
		ArrayList<pair> lst = new ArrayList<pair>();
		for(int i = 0;i < cosCnt[0];i++){
			for(int j = 0;j < cosCnt[1];j++){
				if(cos[0][i].first == cos[1][j].first){
					lst.add(new pair(cos[0][i].first,cos[0][i].second + cos[1][j].second));
				}
			}
		}
		Collections.sort(lst,new Compare());
		for(int i = 0;i < lst.size();i++){
			System.out.println("" + lst.get(i).first + " " + lst.get(i).second);
		}
	}

}
class pair{
	int first;
	int second;
	pair(int f,int s){
		first = f;
		second = s;
	}
}
class Compare implements Comparator<pair>{
	public int compare(pair a,pair b){
		return a.first - b.first;
	}
}

Measured memory_bytes: 17172
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
vector<int>arr;
vector<vector<int>>Q[2];
int dp(int l,int r,bool a){
      if(l>r)return Q[a][l][r]=0;
      int A,B;
      if(Q[a^1][l+1][r]==INF)Q[a^1][l+1][r]=dp(l+1,r,a^1);
      if(Q[a^1][l][r-1]==INF)Q[a^1][l][r-1]=dp(l,r-1,a^1);
      A=Q[a^1][l+1][r];
      B=Q[a^1][l][r-1];
      if(a)return max(A+arr[l],B+arr[r]);
      else return min(A-arr[l],B-arr[r]);
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n;
      cin>>n;
      arr.pb(-INF);
      for(int i=1;i<=n;i++){
            int x;
            cin>>x;
            arr.pb(x);
      }
      Q[0].resize(4000,vector<int>(4000,INF));
      Q[1].resize(4000,vector<int>(4000,INF));
      cout<<dp(1,n,1);
}


Measured memory_bytes: 250880
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int x;cin >> x;
    if(x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3588
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;






int main(void) {
	int N,K;

	cin >> N >> K;
	LL T = 1;
	for(int i=0; i< N; i++) {
		T = min(T * 2, T+K);
	}
	cout << T << endl;

	return 0;
}

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

int main(){
    int a,b;
    cin >>a>>b;
    bool ans = false;
    if(a%3==0) ans = true;
    else if(b%3==0) ans = true;
    else if((a+b)%3==0) ans = true;
    cout << (ans ? "Possible":"Impossible") << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    for(size_t i = 0; i < s.size(); i++){
        printf("%c", (s[i]-'A'+n)%26 + 'A');
    }
    cout << endl;
    return 0;
}

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

public class Main {

    void solve() {
        String s = in.nextToken();
        StringBuilder result = new StringBuilder();
        for (int i = 0 ; i < s.length() ; i+=2) {
            result.append(s.charAt(i));
        }
        out.println(result.toString());
    }


    FastScanner in;
    PrintWriter out;

    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }

}

Measured memory_bytes: 20948
/*
...........__________                                                                           ___  __
.............|       |                                                                           |   /
.............|       |                                                                           |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
...........__|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
void read_And_write(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void raushan_kumar(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int k,a,b;cin>>k>>a>>b;
    for(int i=1;i<=1000;i++){
    	d=i*k;
    	if(d<=b and d>=a){
    		flag=1;
    	}
    }
    if(flag)
    	cout<<"OK";
    else
    	cout<<"NG";
}

int32_t main()
{
    read_And_write();fast;int t=1;
    // cin>>t;
    while(t--){raushan_kumar();}
}

Measured memory_bytes: 3652
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
const int maxn=20;
int vis[maxn],n,x[maxn][maxn],y[maxn][maxn],ans,mark[maxn],a[maxn];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		char a='-',b='1';
		putchar(a);
		putchar(b);
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}
void dfs(int step,int now)
{
	if(step==n+1)
	{
		memset(mark,0,sizeof(mark));
		for(int i=1;i<=n;++i)
			if(vis[i])
			{
				if(mark[i]!=2)
				{
					for(int j=1;j<=a[i];++j)
						if(y[i][j])
						{
							if(mark[x[i][j]]==2||!vis[x[i][j]])
								return;
							mark[x[i][j]]=1;	
						}
						else
						{
							if(vis[x[i][j]])
							{
//								cout<<"NMSL";
								return;
							}
							mark[x[i][j]]=2;
						}
				}
				else
				{
//					cout<<"NMSL";
					return;
				}
			}
			else if(mark[i]==1)
				return;
		ans=max(ans,now);
//		for(int i=1;i<=n;++i)
//			cout<<vis[i]<<' ';
//		cout<<endl;
		return;
	}
	dfs(step+1,now);
	vis[step]=1;
	dfs(step+1,now+1);
	vis[step]=0;
}
int main()
{
    n=read();
	for(int i=1;i<=n;++i)
	{
		a[i]=read();
		for(int j=1;j<=a[i];++j)
			x[i][j]=read(),y[i][j]=read();
	}
	dfs(1,0);
	write(ans);
    return 0;
}


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

int main() {
  int N;
  cin >> N;

  string s[N];
  int t[N];

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

  string X;
  cin >> X;

  int loopStart;
  for (int i = 0; i < N; i++) {
    if (s[i] == X) {
      loopStart = i;
      break;
    }
  }

  int ans = 0;
  for (int i = (loopStart + 1); i < N; i++) {
    ans = ans + t[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

#define MAX 10000
#define NIL -1

struct Node { int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if(T[u].left != NIL)
		h1 = setHeight(T[u].left)  + 1;
	if(T[u].right != NIL)
		h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
	if( T[u].parent == NIL ) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
		return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
		return T[T[u].parent].right;
	return NIL;
}

void print(int u) {
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	int deg = 0;
	if(T[u].left  != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);
	
	if(T[u].parent == NIL) {
		printf("root\n");
	} else if(T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	} else {
		printf("internal node\n");
	}
}

int main(void) {
	int v, l, r, root = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++) T[i].parent = NIL;
	for(int i=0;i<n;i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left  = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	}
	
	for(int i=0; i<n; i++)
	if(T[i].parent == NIL) root = i;
	
	setDepth(root,0);
	setHeight(root);
	
	for(int i=0;i<n;i++) print(i);
	
	return 0;
}


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

using namespace std;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	vector<string> valid;
	int n = s.size(), m = t.size();
	rep(i, n - m + 1) {
		string ret = s;
		bool ok = true;
		rep(j, m) {
			if(ret[i+j] == '?') {
				ret[i+j] = t[j];
			}
			else if(ret[i+j] != t[j]) {
				ok = false;
			}
		}
		rep(j, n)if(ret[j] == '?')ret[j] = 'a';
		if(ok)valid.push_back(ret);
	}
	if(valid.size() == 0) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	sort(valid.begin(), valid.end());
	cout << valid[0] << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cmath>

typedef long long ll;
using namespace std;
int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n), c(m), d(m);
    for(int i=0;i<n;i++) {
        cin >> a[i] >> b[i];
    }
    for(int i=0;i<m;i++) {
        cin >> c[i] >> d[i];
    }
    vector<int> ans;
    for(int i=0;i<n;i++) {
        int idx = m + 1;
        ll num = 1e10;
        for(int j=0;j<m;j++) {
            ll dis = abs(c[j]-a[i]) + abs(d[j]-b[i]);
            if(num > dis) {
                num = dis;
                idx = j;
            }
        }
        ans.push_back(idx+1);
    }
    for(int i=0;i<n;i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, K;
priority_queue<ll> P;

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

  cin >> N >> K;
  ll h;
  rep(i, N) {
    cin >> h;
    P.push(h);
  }
  rep(i, min(K, N)) P.pop();
  ll sm = 0;
  while(!P.empty()) {
    sm+=P.top();
    P.pop();
  }
  cout << sm << "\n";
  return 0;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int PLAN1 = N * A;
  int PLAN2 = B;
  
  if(PLAN1 <= PLAN2){
    cout << PLAN1 << endl;
  }
  else{
    cout << PLAN2 << endl;
  }
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 5000100, MAXK = 30;
const ll MOD = 998244353;
const int INF = 1e8;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}



int main() {
	setIO();

    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a == b){
            System.out.print(c);
        }else if(a == c){
            System.out.print(b);
        }else{
            System.out.print(a);
        }
	}
}

Measured memory_bytes: 22996
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    ans = 0
    for n in range(N):
        S1 = set(S[:n])
        S2 = set(S[n:])
        I = S1 & S2
        ans = max(ans, len(I))
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 62556
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

const int N = 2e5+1;
int arr[N];

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,max=-1,max2=-1; cin>>n;
    FOR(i, 0, n) {
    	cin>>arr[i];
    	if(arr[i] >= max) {
    		max2 = max;
    		max = arr[i];
    	} else if(arr[i] >= max2) {
    		max2 = arr[i];
    	}
	}
	FOR(i, 0, n) {
		if(arr[i] == max) {
			cout<<max2<<endl;
		} else {
			cout<<max<<endl;
		}
	}
    return 0;
}

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

using namespace std;

typedef long long LL;

LL n,a,b,ans,p[10000],f[5200][5200];

void upd(LL &x,LL y){x=min(x,y);}

int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	for (LL i=1;i<=n;++i) scanf("%lld",p+i);
	memset(f,0x3f,sizeof f); f[0][0]=0;
	for (LL i=1;i<=n;++i)
		for (LL j=0;j<=n;++j)
			if (j<=p[i]){
				upd(f[i][p[i]],f[i-1][j]);
				upd(f[i][j],f[i-1][j]+a);
			}
			else{
				upd(f[i][j],f[i-1][j]+b);
			}
	ans=0x3f3f3f3f3f3f3f3fLL;
	for (LL i=0;i<=n;++i) upd(ans,f[n][i]);
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 211584
#include<bits/stdc++.h>
using namespace std;
int l[1200000],r[1200000];
int a[1200],tot,n,ans[1200];
int solve(){
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i+j!=n+1){
				tot++;
				l[tot]=i;
				r[tot]=j;
			}
		}
	}
	printf("%d\n",tot);
	for(int i=1;i<=tot;i++)printf("%d %d\n",l[i],r[i]);
}
int solve1(){
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i+j!=n){
				tot++;
				l[tot]=i;
				r[tot]=j;
			}
		}
	}
	printf("%d\n",tot);
	for(int i=1;i<=tot;i++)printf("%d %d\n",l[i],r[i]);
}
int main(){
//	freopen("1.in","r",stdin);
	scanf("%d",&n);
	if(n&1)solve1();
	else solve();
}

Measured memory_bytes: 2304
def insertion_sort(A):
    n = len(A)
    for i in range(1, n):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(' '.join(map(str, A)))
    return A

n = int(input())
A = list(map(int, input().split()))
print(' '.join(map(str, A)))
insertion_sort(A)


Measured memory_bytes: 5604
n=int(input())
l=[]
for i in range(n):
    a,b,c=map(int,input().split())
    l.append((a,b,c))
    if c>0:
        x,y,h=a,b,c
ma=len(l)
for s in range(101):
    for t in range(101):
        x2,y2,h2=s,t,h+abs(x-s)+abs(y-t)  #候補点
        c=0
        if all(h3==max(h2-abs(x3-x2)-abs(y3-y2),0)for(x3,y3,h3)in l):
            print(x2,y2,h2)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3064
s=input()
n=len(s)
x=0
y=0
for i in range(n):
  if i%2==0:
    if s[i]=='0':
      x+=1
    else:
      y+=1
  else:
    if s[i]=='1':
      x+=1
    else:
      y+=1
print(min(x,y))

Measured memory_bytes: 3188
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 410
typedef long long ll;
#define P std::pair<ll, int>
inline P hash(R int _a, R int _b, R int _c, R int _d)
{
	R int num[4] = {_a, _b, _c, _d};
	R int ans[4], c[4];
	for (R int i = 0; i < 4; ++i) ans[i] = 1001;
	for (R int i = 0; i < 4; ++i)
	{
		for (R int j = 0; j < 4; ++j)
			c[j] = num[(i + j) % 4];
		for (R int j = 0; j < 4; ++j)
			if (c[j] != ans[j])
			{
				if(c[j] < ans[j]) break;
				else goto failed;
			}
		memcpy(ans, c, 16);
		failed: continue;
	}
	R ll key = 0;
	R int cir;
	for (R int i = 0; i < 4; ++i)
		key = key * 10 + ans[i];
	if (ans[0] == ans[1] && ans[1] == ans[2] && ans[2] == ans[3]) cir = 4;
	else if (ans[0] == ans[2] && ans[1] == ans[3]) cir = 2;
	else cir = 1;
	return P(key, cir);
}
P A[maxn];
int c[maxn][4];
std::map<ll, int> mp;
int main()
{
//	setfile();
	R int n = F();
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < 4; ++j)
			c[i][j] = F();
		A[i] = hash(c[i][0], c[i][1], c[i][2], c[i][3]);
		mp[A[i].first] += A[i].second;
	}
	ll ans = 0;
	for (R int i = 1; i <= n; ++i)
	{
		mp[A[i].first] -= A[i].second;
		for (R int j = i + 1; j <= n; ++j)
		{
			mp[A[j].first] -= A[j].second;
			for (R int k = 0; k < 4; ++k)
			{
				R ll ret = 1;
				for (R int kk = 0; kk < 4; ++kk)
				{
					R P temp = hash(c[i][(kk + 1) % 4], c[i][kk],
								c[j][(k + (kk ^ 1)) % 4], c[j][(k + ((kk + 1) ^ 1)) % 4]);
					ret *= mp[temp.first];
					mp[temp.first] -= temp.second;
				}
				if (ret > 0) ans += ret;
				for (R int kk = 0; kk < 4; ++kk)
				{
					R P temp = hash(c[i][(kk + 1) % 4], c[i][kk],
								c[j][(k + (kk ^ 1)) % 4], c[j][(k + ((kk + 1) ^ 1)) % 4]);
					mp[temp.first] += temp.second;
				}
			}
			mp[A[j].first] += A[j].second;
		}
	}
	printf("%lld\n", ans );
	return 0;
}


Measured memory_bytes: 33024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int a = s.length();
        long wc = 0;
        long ans = 0;
        for (int i = 0; i < a; i++) {
            char target = s.charAt(a - 1 - i);
            if (target == 'W') {
                wc++;
            } else if (target == 'B') {
                ans += wc;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 26964
#include<stdio.h>
 
char S[100001];
 
int main(void){
    char c;
    long i, ans = 0;
    
    scanf("%s", S);
    
    c = S[0];
    
    for(i = 1; S[i] != '\0'; i++){
        if(c != S[i]) ans++;
        c = S[i];
    }
    
    printf("%ld\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
last = [0 for _ in range(26)]
S = 0
for i in range(D):
  t = int(input()) - 1
  last[t] = i + 1
  S += s[i][t]
  for j in range(26):
    S -= c[j] * (i + 1 - last[j])
  print(S)

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	int n,m;
	cin>>n>>m;
	map<int,int>used;
	vector<int>num(n,0);
	num[0]=1;
	if(n==1)num[0]=0;
	bool ok=true;
	vector<pair<int,int>>check(n);
	rep(i,m){
		int s,c;
		cin>>s>>c;
		s--;
		check[i]=make_pair(s,c);
		if(!used[s]){
			used[s]=1;
			num[s]=c;
		}else if(num[s]==c){
			
		}else{
			ok=false;
		}
	}
	if(num[0]==0&&n!=1)ok=false;

	rep(i,m){
		if(num[check[i].x]!=check[i].y)ok=false;
	}
	
	if(ok){
		rep(i,n)cout<<num[i];
		cout<<endl;
	}
	else{
		cout<<-1<<endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
const int mod = 1e9+7;
const int maxn = 2e5+5;
const double EPS = 1e-6;
using namespace std;
struct node{
	int v,s;
}num[maxn];
int sum[maxn]={0};
bool cmp(node a,node b){
	return a.s<b.s;
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int a;
	int t = 0;
	rep(i,0,n) {
		scanf("%d",&a);
		if(sum[a]==0) t++;
		sum[a]++;
	}
	if(t<=k) return printf("0\n"),0;
	int cnt = 0;
	rep(i,1,n+1) {
		if(sum[i]==0) continue;
		num[cnt].v = i;
		num[cnt++].s = sum[i];
	}
	sort(num,num+cnt,cmp);
	int ans = 0;
	rep(i,0,cnt){
		ans+=num[i].s;
		t--;
		if(t<=k) break;
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 2560
/*
* Problem link
* 
*/

#include<bits/stdc++.h>
using namespace std;

struct INIT{INIT(){cin.tie(0);ios_base::sync_with_stdio(false);} }init;
#define rep(i,n) for(auto i=(n)*0;i<n;i++)
typedef long long LL;
const LL INF = (LL)1e9;
typedef vector<LL> V;
typedef vector<V> VV;
inline LL calc(LL d, V& dist, V& cost) {
	LL sum = 0;
	int p = dist.size() - 1;
	rep(i, p) {
		if (dist[i] <= d&&d <= dist[i + 1]) {
			return sum + (d - dist[i])*cost[i];
		}
		sum += (dist[i + 1] - dist[i])*cost[i];
	}
	return INF;
}
int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	int N, M, C, S, G;
	while (cin >> N >> M >> C >> S >> G, N + M + C + S + G>0) {
	
		VV cost(N, V(N, INF));
		vector<VV> dist(C, VV(N, V(N, INF)));
		
		rep(i, N) {
			cost[i][i] = 0;
			rep(j, C)dist[j][i][i] = 0;
		}
		rep(i, M) {
			int x, y, c; LL d;
			cin >> x >> y >> d >> c;
			x--; y--; c--;
			dist[c][x][y] = dist[c][y][x] = min(dist[c][y][x], d);
		}
		vector<int> p(C);
		rep(i, C)cin >> p[i];
		VV q(C), r(C);
		rep(i, C) {
			q[i].resize(p[i]);
			r[i].resize(p[i]);
			q[i][0] = 0;
			rep(j, p[i] - 1)cin >> q[i][j + 1];
			rep(j, p[i])cin >> r[i][j];
			q[i].push_back(INF);
				
		}
		rep(c, C)rep(k, N)rep(i, N)rep(j, N)dist[c][i][j] = min(dist[c][i][j], dist[c][i][k] + dist[c][k][j]);
		rep(c, C)rep(i, N)rep(j, N)cost[i][j] = min(cost[i][j], calc(dist[c][i][j], q[c], r[c]));
		rep(k, N)rep(i, N)rep(j, N)cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
		if (cost[S - 1][G - 1] == INF)cout << -1 << endl;
		else cout << cost[S - 1][G - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 4712
def main():
    H,N = [int(x) for x in input().split()]
    A,B = [],[]
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)

    dp = [float('inf')]*(H+1)
    dp[0] = 0
    for i in range(N):
        for j in range(H+1):
            # print(i,j,dp[j],A[i],B[i])
            dp[min(j+A[i],H)] = min(dp[min(j+A[i],H)], dp[j]+B[i])
            # print(dp)
    print(int(dp[H]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 46940
(* O(max {n, m}) (n = |xs|) *)
let unique_count m xs = (* m >= xsの最大値, xsは0以上の整数のリスト *)
  let flags = Array.make (m + 1) 0 in
  List.iter (fun x -> flags.(x) <- 1) xs;
  Array.fold_left (+) 0 flags

let kDMax = 100

(* O(n) *)
let solve n ds = unique_count kDMax ds

let fold_int f a n =
  let rec fold f a i n =
    if i >= n then
      a
    else
      fold f (f a i) (i + 1) n
  in
    fold f a 0 n

let read_ints n =
  fold_int
    (fun sofar _ -> read_int () :: sofar)
    []
    n |> List.rev

let _ =
  let n = read_int () in
  let ds = read_ints n in
  solve n ds |> string_of_int |> print_endline

Measured memory_bytes: 384