akhauriyash/Code-Regression huggingface dataset:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (declare (inline sort))
  (let* ((n (read))
         (xs (make-array n :element-type 'uint32))
         (sorted-xs (make-array n :element-type 'uint32)))
    (dotimes (i n)
      (let ((x (read-fixnum)))
        (setf (aref xs i) x
              (aref sorted-xs i) x)))
    (setf sorted-xs (sort sorted-xs #'<))
    (let ((mid (- (floor n 2) 1))
          (mid+1 (floor n 2)))
      (loop for x across xs
            do (if (<= x (aref sorted-xs mid))
                   (println (aref sorted-xs mid+1))
                   (println (aref sorted-xs mid)))))))

#-swank(main)


Measured memory_bytes: 33632
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    H, W = map(int, input().split())
    A = []
    cnt = 0
    for _ in range(H):
        a = list(map(int, input().split()))
        cnt += sum(a)
        A.append(a)

    ans = []
    for h in range(H):
        if h % 2 == 0:
            for w in range(W):
                if h == H - 1 and w == W - 1:
                    continue
                if A[h][w] % 2 == 1:
                    if w == W - 1:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w + 1] += 1
                        ans.append((h, w, h, w + 1))
                else:
                    continue
        else:
            for w in range(W)[::-1]:
                if h == H - 1 and w == 0:
                    continue
                if A[h][w] % 2 == 1:
                    if w == 0:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w - 1] += 1
                        ans.append((h, w, h, w - 1))
                else:
                    continue

    print(len(ans))
    for a, b, c, d in ans:
        print(a + 1, b + 1, c + 1, d + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22796
#import math
#import fractions
from functools import reduce

'''
def gcdList(ls):
    return reduce(math.gcd, ls)
#    return reduce(fractions.gcd, ls)
'''

def gcd(a,b):
    while b:
        a, b = b, a % b
    return a
def gcdList(ls):
    return reduce(gcd,ls)

n,y = map(int,input().split())
x = sorted([int(i) for i in input().split()])
x_ = [0 for _ in range(n)]
for i in range(n):
    x_[i] = abs(y-x[i])
print(gcdList(x_))

Measured memory_bytes: 14600
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    S = {s: list(input()) for s in 'abc'}
    x = 'a'
    while S[x]:
        # S[x]のindex0を削除し、削除した要素を取得してxに代入している！
        x = S[x].pop(0)

    print(x.upper())  # 大文字にして出力


resolve()

Measured memory_bytes: 2940
#include<iostream>
#include <string>

using namespace std;
int main(){
    string S;
    cin >> S;
    long long sum =0;
    int n = S.size();
    for(int i=0; i<(1 << (n-1));++i){
        long long psum=0;
        for (int j=0;j<n;++j){
            psum *=10;
            psum += S[j]-'0'; //数値変換
            if((i & (1<<j)) == 0){
                sum +=psum;
                psum=0;
            }
        }
        sum+=psum;
    }
    cout << sum <<endl;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    input! {
        n :usize,
        m :usize,
        k :usize,
        a: [usize; n],
        b: [usize; m],
    }

    let mut asum :Vec<usize> = Vec::new();
    asum.push(a[0]);
    for i in 1..n {
        asum.push(a[i]+asum[i-1]);
    }
    let asum = asum;

    let mut bsum :Vec<usize> = Vec::new();
    bsum.push(b[0]);
    for i in 1..m {
        bsum.push(b[i]+bsum[i-1]);
    }
    let bsum = bsum;

    let j = bsum.binary_search(&k);
    let mut max = match j {
        Ok(x) => x+1,
        Err(x) => x,
    };
    for i in 0..n {// number of books from a minus 1
        if asum[i] > k {continue;}
        let j = bsum.binary_search(&(k-asum[i]));
        let bnum = match j {
            Ok(x) => x+1,
            Err(x) => x,
        };
        if bnum + i + 1 > max {
            max = bnum + i + 1;
        }
    }

    println!("{}", max);
}


Measured memory_bytes: 12628
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if A < B:
    aa = A + V*T
    bb = B + W*T
    if aa >= bb:
        print("YES")
    else:
        print("NO")
else:
    aa = A - (V*T)
    bb = B - (W*T)
    if aa <= bb:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9220
#include<iostream>
//#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int N = 200005;
 
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int k;
	cin>>k;
	string s;
	cin>>s;
	if((int)s.size() > k){
		for(int i=0;i<k;i++){
			cout<<s[i];
		}
		cout<<"...";
	}else{
		cout<<s;
	}
	
	return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long k = sc.nextLong();
		long d = sc.nextLong();
		sc.close();

		long count;
		if(x>=0) {
			count = x/d;
		}else {
			count = -1*x/d;
		}

		boolean flag = false;
		long zanCount;
		if(count<=k) {
			zanCount = k - count;
		}else {
			zanCount = k;
			count=0L;
			flag = true;
		}

		long zanX;
		if(count==0) {
			zanX = x;
		}else {
			if(x>=0) {
				zanX = x - count*d;
			}else {
				zanX = x + count*d;
			}
		}

		//答え
		if(flag) {
			if(x>=0) {
				zanX = x - k*d;
			}else {
				zanX = x + k*d;
			}
			if(zanX<0) {
				zanX = -1L*zanX;
			}
			System.out.println(zanX);
			return;
		}


		if(zanCount%2==0) {
			if(zanX<0) {
				zanX = -1L*zanX;
			}
			System.out.println(zanX);
		}else {
			long aa = zanX-d;
			long bb = zanX+d;

			if(aa<0) {
				aa = -1L*aa;
			}
			if(bb<0) {
				bb = -1L*bb;
			}

			if(aa<=bb) {
				zanX = aa;
			}else {
				zanX = bb;
			}
			System.out.println(zanX);
		}




	}
}

Measured memory_bytes: 35700
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
#include <iomanip>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(1000001); //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 1000000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
	}
	ifac[1000000] = mpow(fac[1000000], M - 2);
	for (ll i = 1000000; i > 0; i--) {
		ifac[i - 1] = ifac[i] * i%M;
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	return fac[a] * ifac[a - b] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int a, b;
	cin >> a >> b;
	if (a < 10 && b < 10)
		cout << a * b << endl;
	else
		cout << "-1" << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;

#define MAXN 100001
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007

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

    ll a,b,c;
    cin>>a>>b>>c;

    ll resp=0;
    if(b <= c){
        c-=b;
        resp += (2*b);
        if(a + 1 >= c){
            resp+=c;
        }else{
            resp+=(a + 1);
        }
    }else{
        resp = b + c;
    }
    cout<<resp<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n, a, b;
    cin >> n >> a >> b;
    string s; cin >> s;
    int ab = a + b;
    int qab = 0, qb = 0;
    bool q = false;
    REP(i,n) {
        q = false;
        if (s[i] == 'a') {
            if (qab < ab) {
                q = true;
                qab++;
            }
        } else if (s[i] == 'b') {
            if (qab < ab && qb < b) {
                q = true;
                qab++;
                qb++;
            }
        }
        ATYN(q)
    }

    return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    string s;
    ll q;
    cin >> s >> q;
    ll rev_cnt = 0;
    string pre = "", suf = "";
    rep(i, q){
        ll t, f;
        char c;
        cin >> t;
        if(t == 1) rev_cnt++;
        else{
            cin >> f >> c;
            if(rev_cnt%2){
                if(f == 1) suf += c;
                else pre += c;
            }else{
                if(f == 1) pre += c;
                else suf += c;
            }
        }
    }
    if(rev_cnt%2 == 0){
        reverse(pre.begin(), pre.end());
        cout << pre << s << suf << endl;
    }else{
        reverse(suf.begin(), suf.end());
        reverse(s.begin(), s.end());
        cout << suf << s << pre << endl;
    }
    return 0;
}

Measured memory_bytes: 1088
table = [True for i in range(1, 100000)]

def generate():
	global table
	for i in range(2, len(table)):
		if table[i] == True:
			for j in range(i * i, len(table), i):
				table[j] = False

	table[1] = False
	
def prime(x):
	if table[1] == True:
		generate()

	return table[x]

v = []
for i in range(11, 55556, 10):
	if prime(i):
		v.append(i)

n = int(raw_input())

for i in range(n):
	print v[i],


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

int main()
{
  string s;
  cin >> s;
  int ans = 0, cnt = 0;
  int a = 0, z = 0;
  rep(i, s.size()){
    if(s[i] == 'A'){
      a = i;
      break;
    }
  }
  for(int i = s.size() - 1; i >= 0; i--) {
    if(s[i] == 'Z'){
      z = i;
      break;
    }
  }
  
  ans =  z - a + 1;
  if(ans < 0) ans = 0;
    
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace  std;
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define filla(a,k,n) memset(a,k,sizeof(a[0])*n)
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll dp[100005];
ll a[305];
ll n,k;
void solve(ll k)
{
	if(dp[k]!=-1)
	{
		return;
	}
	dp[k]=0;
	for(ll i=0;i<n;i++)
	{
		if(k>=a[i])
		{
			solve(k-a[i]);
			dp[k]=dp[k]||!dp[k-a[i]];
		}
	}
	return;
}
int main()
{
	cin>>n>>k;
	ll i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	memset(dp,-1,sizeof(dp));
	solve(k);
	if(dp[k]==1)
	{
		cout<<"First";
	}
	else
	{
		cout<<"Second";
	}




}


Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();
		int d = s.nextInt();
		int e = s.nextInt();
		int k = s.nextInt();

		int[] f ={a,b,c,d,e,k};
		for(int i=0;i<f.length;i++){
			int n1=0;
			int n2=0;
			int ans=0;
			for(int j=0;j<f.length;j++){
				if(i==j){
					continue;
				}
				n1=f[i];
				n2=f[j];
				if(n1>n2){
					ans=n1-n2;
				}else{
					ans=n2-n1;
				};
				if(ans>k){
					System.out.println(":(");
					return;
				}
			};
		};
		System.out.println("Yay!");
	}

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

using edge = tuple<ll, ll, ll>;
vector<int> V[2510];
vector<int> W[2510];
bool visit_zero[2510];
bool visit_N[2510];

void dfs(int k, bool *visit, vector<int> *v) {
    if (!visit[k]) {
        visit[k] = true;
        for (auto x: v[k]) {
            if (!visit[x]) {
                dfs(x, visit, v);
            }
        }
    }
}


int main(){
    int N, M;
    ll P;
    cin >> N >> M >> P;
    vector<edge> E;
    for (auto i = 0; i < M; i++) {
        int A, B;
        ll C;
        cin >> A >> B >> C;
        --A;
        --B;
        C = -(C-P);
        E.emplace_back(A, B, C);
        V[A].push_back(B);
        W[B].push_back(A);
    }
    dfs(0, visit_zero, V);
    dfs(N - 1, visit_N, W);
    vector<bool> ok(N);
    for (auto i = 0; i < N; i++) {
        ok[i] = visit_zero[i] && visit_N[i];
    }
    constexpr ll infty = 1000000000000000LL;
    vector<ll> d(N, infty);
    d[0] = 0;
    bool updated = true;
    int step = 0;
    while(updated)
    {
        updated = false;
        for (auto i = 0; i < M; i++) {
            int A, B;
            ll C;
            tie(A, B, C) = E[i];
            if (!ok[A] || !ok[B]) {
                continue;
            }
            ll t = d[A] + C;
            if (t < d[B]) {
                updated = true;
                d[B] = t;
            }
        }
        ++step;
        if (step > N) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << max (0LL, -d[N-1]) << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e3+10;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,m,k,sx,sy,dis[N][N],dn[4]={1,0,0,-1},dm[4]={0,1,-1,0};
char s[N][N];
bool vis[N][N];
void bfs() {
    queue<pii> q;
    q.push(mp(sx,sy));vis[sx][sy]=1;
    while(!q.empty()) {
        pii u=q.front();q.pop();
        for(int d=0;d<4;d++) {
            int x=u.fi+dn[d],y=u.se+dm[d];
            if(!vis[x][y]&&s[x][y]!='#') {
                dis[x][y]=dis[u.fi][u.se]+1;vis[x][y]=1;
                if(dis[x][y]!=k) q.push(mp(x,y));
            }
        }
    }
}
int main() {
    cin>>n>>m>>k;
    memset(s,'#',sizeof(s));
    for(int i=1;i<=n;i++) {
        scanf("%s",s[i]+1);
        for(int j=1;j<=m;j++) if(s[i][j]=='S') sx=i,sy=j;
    }
    bfs();
    int ans=inf;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(vis[i][j]) {
                if(i==1||i==n||j==1||j==m) ans=min(ans,1);
                else ans=min(ans,(min(i-1,min(j-1,min(n-i,m-j)))-1)/k+1+1);
            }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 5248
N = int(input())
AB = []
for i in range(N):
    l = input().split()
    AB.append((int(l[0]), int(l[1])))

AB.sort(key=lambda x: x[1])
# print(N, AB)

c = 0
p = True
for ab in AB:
    c += ab[0]
    if c > ab[1]:
        p = False
        break

if p:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 72920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  int x;
  cin >> x;
  int t = 0;
  while( t*(t+1)/2 < x){
    t ++;
  }
  cout << t << endl;
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  vector<int> A(N);
  for (auto& a : A) { cin >> a; }
  vector<int> B(N);
  for (auto& b : B) { cin >> b; }
  vector<int> C(N);
  for (auto& c : C) { cin >> c; }
  boost::sort(A);
  boost::sort(B);
  boost::sort(C);

  vector<int> mid(N);
  for (int i = 0; i < N; ++i) {
    auto b = B[i];
    auto itr = boost::upper_bound(C, b);
    auto num = std::distance(itr, C.end());
    mid[i] = num;
  }
  vector<ll> D(N);
  D[N-1] = mid[N-1];
  for (int i = N-2; i >= 0; --i) {
    D[i] = D[i+1] + mid[i];
  }
  vector<ll> E(N);
  for (int i = 0; i < N; ++i) {
    auto a = A[i];
    auto itr = boost::upper_bound(B, a);
    auto j = std::distance(B.begin(), itr);
    E[i] = D[j];
  }
  auto ans = boost::accumulate(E, (ll)0);
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 3456
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll x, y, a, b, c, i, p[100001], q[100001], r[100001], ans=0;
    vector<ll> vec;

    cin >> x >> y >> a >> b >> c;
    for(i=1; i<=a; i++){
        cin >> p[i];
    }
    for(i=1; i<=b; i++){
        cin >> q[i];
    }
    for(i=1; i<=c; i++){
        cin >> r[i];
    }

    sort(p+1, p+a+1);
    reverse(p+1, p+a+1);
    sort(q+1, q+b+1);
    reverse(q+1, q+b+1);
    sort(r+1, r+c+1);
    reverse(r+1, r+c+1);

    for(i=1; i<=x; i++){
        vec.push_back(p[i]);
    }
    for(i=1; i<=y; i++){
        vec.push_back(q[i]);
    }
    for(i=1; i<=c; i++){
        vec.push_back(r[i]);
    }

    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    for(i=0; i<x+y; i++){
        ans += vec[i];
    }

    cout << ans << endl;

    return 0;
}

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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int n;
    cin >> n;
    vector<string> v(n + 1);
    vector<string> vv(n + 1);
    REP (i, 0, n) {
        string s;
        cin >> s;
        v[i] = s;
        vv[i] = s;
        REP (j, 0, s.size()) if (v[i][j] == '?') {
            v[i][j] = 'a';
            vv[i][j] = 'z';
        }
    }
    string T;
    cin >> T;
    v[n] = vv[n] = T;
    sort(v.begin(), v.end());
    sort(vv.begin(), vv.end());
    auto f = upper_bound(v.begin(), v.end(), T);
    auto e = lower_bound(vv.begin(), vv.end(), T);
    int fi = f - v.begin();
    int ei = e - vv.begin();
    REP (i, ei, fi - 1) cout << i + 1 << ' ';
    cout << fi << endl;
    return 0;
}

Measured memory_bytes: 1408
mod = 10**6 + 3

fac = [0]*mod
fac[0] = 1
for i in range(1, mod):
    fac[i] = fac[i - 1] * i
    fac[i] %= mod

def gcd(a, b):
    def calc(a, b, first, second):
        if a < b:
            a, b = b, a
        r = a % b
        q = -(a - r)//b
        if r == 0:
            return b, second
        # first += q * second
        first = [x + q * y for (x, y) in zip(first, second)]
        return calc(r, b, second, first)
    first = [1, 0]
    second = [0, 1]
    return calc(a, b, first, second)

def mod_inv(n, mod):
    table = gcd(n, mod)
    inv = table[1][1]
    if inv < 0:
        inv += mod
    return inv

def mod_pow(x, n, mod):
    ret = 1
    while n > 0:
        if n & 1 != 0:
            ret *= x
            ret %= mod
        x *= x
        x %= mod
        n >>= 1
    return ret

l = input().split()
Q = int(l[0])
X = []
D = []
N = []
for i in range(Q):
    l = input().split()
    X.append(int(l[0]))
    D.append(int(l[1]))
    N.append(int(l[2]))


for i in range(Q):
    x = X[i]
    d = D[i]
    n = N[i]
    if d == 0:
        print(mod_pow(x, n, mod))
        continue
    inv_d = mod_inv(d, mod)
    x_d = (x * inv_d) % mod
    # print(i, x, d, n, inv_d, x_d, x_d + n - 1)
    if x_d + n - 1 >= mod:
        print(0)
        continue
    ans1 = fac[x_d + n - 1]
    ans2 = fac[x_d - 1]
    # print(ans1, ans2)
    ans = ans1 * mod_inv(ans2, mod)
    ans %= mod
    d_n = mod_pow(d, n, mod)
    ans = ans * d_n
    ans %= mod
    print(ans)

Measured memory_bytes: 122972
main(){
  long long int a[50],b;
  int n,p,d,x;
  int m[31][50];
  for(;scanf("%d",&n),n;){
    memset(m,0,sizeof(m));
    for(p=0;p<n;a[p]=(long long int)1<<p,p++)
      for(scanf("%d",&x);x;x--)scanf("%d",&d),m[d][p]=1;
    for(d=1;d<31;d++){
      for(b=p=0;p<n;p++)if(m[d][p])b|=a[p];
      for(p=0;p<n;p++)
        if(m[d][p]){
          a[p]=b;
          if(a[p]==((long long int)1<<n)-1){printf("%d\n",d);goto s;}
        }
    }
    puts("-1");s:;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define PI 3.14159265359

int main()
{
    int a, b, x;
    double ans;
    scanf("%d %d %d", &a, &b, &x);
    
        if (x <= (a * a * b) / 2)
        {
            ans = atan(((double)(a * b * b) / (2 * x))) / PI * 180.0;
        }
        else
        {
            ans = atan(2.0*(double)b/(double)a-2.0*(double)x/(double)(a*a*a)) / PI * 180.0;
        }
    
    
    
    printf("%lf", ans);
    return 0;
}

Measured memory_bytes: 128
const [nStr, aStr] = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/)
const as = aStr.split(/\s/).reduce((acc, curr) => {
  const num = Number(curr)
  acc[num] = (acc[num] || 0) + 1
  return acc
}, [])
if (as[1] === 1) {
  console.log(1)
} else if (as[1]) {
  console.log(0)
} else {
  for (let i = 2; i < as.length; i++) {
    if (!as[i]) {
      continue
    }
    const until = Math.floor(Math.pow(i, 0.5))
    for (let j = 2; j <= until; j++) {
      if (i % j === 0 && (as[j] || as[i / j])) {
        as[i] = 0
        break
      }
    }
  }
  console.log(as.reduce((a, b) => a + (b === 1 ? b : 0), 0))
}

Measured memory_bytes: 78512
package main

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

type Tuple struct {
	value int
	index int
}

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()

	Q := make([]SortInterFace, N+1)
	for i := 0; i < N+1; i++ {
		Q[i] = make(SortInterFace, 0)
	}

	for i := 0; i < M; i++ {
		p, y := sc.NextInt(), sc.NextInt()
		Q[p] = append(Q[p], Tuple{y, i})
	}

	ans := make([]string, M)

	for i := 1; i <= N; i++ {
		sort.Sort(Q[i])
		for j := 0; j < len(Q[i]); j++ {
			ans[Q[i][j].index] = fmt.Sprintf("%06d%06d", i, j+1)
		}
	}
	for i := 0; i < M; i++ {
		fmt.Println(ans[i])
	}

}

type SortInterFace []Tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].value < s[j].value
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 14244
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int n = sc.nextInt();
		int sum = 0;

		Integer array[] = new Integer[n];
		ArrayList<Integer> result = new ArrayList<Integer>();

		for (int i = 0; i < n; i++) {
			array[i] = (sc.nextInt());

			//総数をとっておく
			sum = sum + array[i];
		}

		//左側の和
		int tmp = 0;

		for (int j = 0; j < n - 1; j++) {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		}

		Collections.sort(result);

		System.out.println(result.get(0));

		sc.close();
	}
}


Measured memory_bytes: 22612
#include <iostream>

using namespace std;
long long int sum;
int main()
{
    int n, m;
    cin >> n >> m;


    for(int i = 1; i <= m; i++) {
        int x;
        cin >> x;
        sum += x;
    }

    if(sum <= n)
        cout << n - sum << "\n";
    else cout << -1 << "\n";
    return 0;
}


Measured memory_bytes: 3652
def main():
    n, m = map(int,input().split())
    x = []
    y = []
    for _ in range(m):
        xx, yy = map(int,input().split())
        x.append(xx-1)
        y.append(yy-1)
    ans = [0] * n
    ans[0] = 1
    red = [0] * n
    red[0] = 1
    num = [1] * n
    for i in range(m):
        if num[x[i]] > 0:
            num[x[i]] -= 1
            num[y[i]] += 1
            if ans[y[i]] == 0 and red[x[i]] == 1:
                ans[y[i]] = 1
                red[y[i]] = 1
            if num[x[i]] == 0 and ans[x[i]] == 1:
                red[x[i]] = 0
                ans[x[i]] = 0
    
    print(sum(ans))

if __name__ == '__main__':
    main()


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


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

  vector<string> v = {"Sunny", "Cloudy", "Rainy"};

  ll idx = 0;
  rep(i, 3){
    if(v[i] == s){
      idx = i;
      break;
    }
  }

  idx++;
  idx %= 3;
  cout << v[idx] << endl;



  return 0;
}


Measured memory_bytes: 256
#include <iostream>
    #include <math.h>
    using namespace std;
     
    int main() {
    int a,b,c;
    while(cin>> a>>b){
    c=a+b;
    int d;
    for(int i=0;i<8;i++){
    if(pow(10,i)<=c && c<pow(10,i+1)){
    d=i+1;
    }
    }
    cout<< d <<endl;	
    }
    return 0;
    }

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;cin >> k;
  vector<ll> a(k);
  REP(i,k){
    cin >> a[k-1-i];
  }
  ll mi=2,ma=2;
  REP(i,k){
    ll tmp = a[i];
    if(mi%tmp==0 || ma % tmp==0 || ma/tmp - mi/tmp>0){
      mi = (mi+tmp-1) / tmp * tmp;
      ma = ma/tmp * tmp + tmp-1;
    }else{
      mi = -1;
      break;
    }
  }
  if(mi==-1){
    cout << -1 << endl;
  }else{
    cout << mi << " " << ma << endl;
  }

}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, m, n) for(long long i = m; i < n; ++i)
#define CO(n) cout << n << endl
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int A[4];
    REP(i,0,4){
        A[i] = (int)(S[i]-'0');
    }
    //REP(i,0,4) cout << A[i] << endl;
    int total = 0;
    REP(i,0,8){
        bitset<3> bs(i);
        string simb = bs.to_string();
        total = A[0];
        REP(j,1,4){
            if (simb[j-1]=='0') total += A[j];
            else total -= A[j];
        }
        //cout << total << endl;
        if (total == 7){
            string calc = "";
            REP(j,0,3){
                if (simb[j] == '0') calc += "+";
                else calc += "-";
            }
            //cout << calc << endl; 
            string equation = "";
            REP(i,0,3){
                //CO(equation);
                equation = equation + S[i]+calc[i];
            }
            cout << equation + S[3]+"=7" << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}


int dp[50][3010];
signed main() {
    int n, m, s;
    while(cin >> n >> m >> s, n || m || s) {
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        repq(num,1,m) {
            repr(i,n*n,1) {
                repq(j,num,s) {
                    dp[i][j] = (dp[i][j] + dp[i-1][j-num]) % MOD;
                }
            }
        }
        cout << dp[n*n][s] << endl;
    }
    return 0;
}

Measured memory_bytes: 4144
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
    
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  for(int i = 0; i < n - 2; i++) {
    if(s[i] == 'A' and s[i + 1] == 'B' and s[i + 2] == 'C') ans++;
  }

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


Measured memory_bytes: 256
#include <stdio.h>
#define Num 1000
#define INF 200000000
#define White 0
#define Gray  1
#define Black 2

int M[Num][Num];


int Prim(int n) {
    int u , v;
    int i;
    int min;
    /*D 最小木Tに属する頂点とV-Tに属する頂点をつなぐ辺の中で、最小のものを記録*/
    /*P 最小木におけるvの親を記録*/
    /*訪問状態:White 未訪問　Gray 隣接した頂点を選んだ時　Black (Grayから最小の辺でつながれた頂点を選択し)訪問済みとする*/
    int D[Num] , P[Num] , Color[Num];
    
    for(i = 0 ; i < n ; i ++) {
        D[i] = INF;
        P[i] = -1;
        Color[i] = White;
    }
    
    D[0] = 0;
    
    while(1) {
        min = INF;
        u = -1;
        
        for(i = 0 ; i < n ; i++) {
            if(min > D[i] && Color[i] != Black) {
                u = i;
                min = D[i];
            }
        }
        if(u == -1)
            break;
        Color[u] = Black;
        for(v = 0 ; v < n ; v++) {
            if(Color[v] != Black && M[u][v] != INF) {
                if(D[v] > M[u][v]) {
                    D[v] = M[u][v];
                    P[v] = u;
                    Color[v] = Gray;
                }
            }
        }
    }
    int Sum = 0;
    for(i = 0 ; i < n ; i++)
        if(P[i] != -1)
            Sum += M[i][P[i]];
    
    return Sum;
}

int main(void)
{
    int n;
    int i , j;
    
    scanf("%d" , &n);
    
    for(i = 0 ; i < n ; i++) {
        for(j = 0 ; j < n ; j++) {
            scanf("%d" , &M[i][j]);
            
            if(M[i][j] == -1)
                M[i][j] = INF;
        }
    }
    
    printf("%d\n" , Prim(n));

    return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
ll a[maxn], v[maxn];
void solve(){
    ll n, k; cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];

    ll len = 0;
    v[1] = 1;
    queue<int> q;
    q.push(1);
    int tp = 0;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        int t = a[u];
        if(!v[t]){
            q.push(t);
            v[t] = v[u] + 1;
        }
        else{
            tp = v[t] - 1;
            len = v[u] - v[t] + 1;
            break;
        }
    }

    //cout << tp << len << endl;
    int tr = 1;
    if(k > tp + len) k = (k - tp) % len + tp; 

    for (int i = 0; i < k; i++) tr = a[tr];
    cout << tr << endl;
}
int main(){
    IOS; int t = 1;
    while(t--){
        solve();
    }
    return 0;
}

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

int maximum_sum_seq(vector<int> &seq,int n) {
  int max_sum = seq[0];
  for(int i=0;i<n;i++) {
    int cur = 0;
    for(int j=i;j<n;j++) {
      cur += seq[j];
      max_sum = max(max_sum,cur);
    }
  }
  return max_sum;
}

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

  int n;
  while(cin >> n) {
    if(n == 0) break;
    vector<int> seq(n);
    for(int i=0;i<n;i++) {
      cin >> seq[i];
    }
    cout << maximum_sum_seq(seq,n) << endl;
  }
}

Measured memory_bytes: 1208
<?php
  	fscanf(STDIN, "%s", $S);
	$chars = str_split($S);
	$countValues = array_count_values($chars);
	
	$containTwoChars = TRUE;
	if (count($countValues) != 2) {
      	$containTwoChars = FALSE;
      	echo "No";
      	exit(0);
    }

	$isFifty = TRUE;
	foreach ($countValues as $char => $count) {
      	if ($count != 2) {
          $isFifty = FALSE;
          	echo "No";
          	exit(0);
        } 
    }

	echo "Yes";

Measured memory_bytes: 3700
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include<stdbool.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) {ll tp=a;a=b;b=tp;}
const ll MOD = 1000000007;

int main(){
    char s[502020]; scanf("%s", s);
    int n = strlen(s);
    ll ans=0,tmpg=0,tmpl=0;
    int lt=(s[0]=='<'?1:0);
    rep(i,n){
        if(lt){
            if(s[i] == '<') tmpl++;
            else{
                lt=0;tmpg=1;
            }
        }else{
            if(s[i] == '>') tmpg++;
            else{
                ll tmp=max(tmpl,tmpg);
                ans+=tmp*(tmp+1)/2;
                tmp=min(tmpl,tmpg);
                ans+=tmp*(tmp-1)/2;
                lt=1;tmpl=1;
            }
        }
    }
    if(lt){
        ans+=tmpl*(tmpl+1)/2;
    }else{
        ll tmp=max(tmpl,tmpg);
        ans+=tmp*(tmp+1)/2;
        tmp=min(tmpl,tmpg);
        ans+=tmp*(tmp-1)/2;
    }
    printf("%lld\n", ans);
}


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

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

    if(a=="A"){
        cout<<"T"<<endl;
    }
    else if(a=="T"){
        cout<<"A"<<endl;

    }

    else if(a=="G"){
        cout<<"C"<<endl;
    }
    else if(a=="C"){
        cout<<"G"<<endl;
    }
}


Measured memory_bytes: 256