akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int W = scanner.nextInt();

    int[] w = new int[N];
    int[] v = new int[N];

    for (int i = 0; i < N; i++) {
      w[i] = scanner.nextInt();
      v[i] = scanner.nextInt();
    }

    long[][] vw = new long[4][N + 1];
    for (int i = 0; i < N; i++) {
      vw[w[i] - w[0]][i] = v[i];
    }
    for (int i = 0; i < 4; i++) {
      Arrays.sort(vw[i]);
      reverse(vw[i], 1, N);
      for (int j = 1; j < N + 1; j++) vw[i][j] += vw[i][j - 1];
    }

    long max = 0;
    for (int a = 0; a <= N; a++) {
      for (int b = 0; b <= N - a; b++) {
        for (int c = 0; c <= N - a - b; c++) {
          for (int d = 0; d <= N - a - b - c; d++) {
            long tw = (long) w[0] * a + (w[0] + 1L) * b + (w[0] + 2L) * c + (w[0] + 3L) * d;
            long tv = vw[0][a] + vw[1][b] + vw[2][c] + vw[3][d];
            if (tw > W) continue;
            max = Math.max(max, tv);
          }
        }
      }
    }
    System.out.println(max);
  }

  private static void swap(long[] a, int i, int j) {
    long tmp = a[i];
    a[i] = a[j];
    a[j] = tmp;
  }

  private static void reverse(long[] a, int i, int j) {
    if (i > j) throw new IllegalArgumentException("i must be less than j");
    while (i < j) {
      swap(a, i, j);
      i++;
      j--;
    }
  }
}


Measured memory_bytes: 23508
#include<stdio.h>
int main(){
	unsigned short set;            	/* 使用できる最大値格納用変数 */
	unsigned long tag;            	/* 目標値格納用変数 */
	int mid;            	/* 計算用変数 */
	int agg[100];       	/* 計算結果格納用配列 */
	int i, j;           	/* ループ変数 */
	int input_count = 0;	/* 入力数カウンタ */
	int num_count = 0;  	/* 目標を満足する値のカウンタ */
	
	/* 配列の初期化 */
	for(i = 0;i < 100;i++){
		agg[i] = 0;
	}
	
	/* 数値の入力、演算を無限ループ */
	while(1){
		/* 使用できる最大値、目標値の入力 */
		scanf("%d %ld", &set, &tag);
		
		/* 終了処理 */
		if(set == 0 && tag == 0){
			break;
		}
		/* カウンタをリセット */
		num_count = 0;
		
		/* 目標を満足する値をカウント */
		for(i = 1;i < set;i++){
			for(j = i;j <= set;j++){
				/* i + j と目標値の差をmidに代入 */
				mid = tag - (i + j);
				/* midがiとjの間にある場合カウント*/
				if(mid > i && mid < j){
					num_count++;
				}
			}
		}
		
		/* カウントした結果を格納 */
		agg[input_count] = num_count;
		/* 入力数をカウント */
		input_count++;
	}
	
	/* 結果の出力 */
	for(i = 0;i < input_count;i++){
		printf("%d\n", agg[i]);
	}
	
	return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const
#define st static

cs ll mod=998244353;

inline
void outint(int a){
    st char ch[13];
    if(a==0)pc('0');
    while(a)ch[++ch[0]]=(a-a/10*10)^48,a/=10;
    while(ch[0])pc(ch[ch[0]--]);
}

ll fac[4002],inv[4002],ifac[4002];

ll ans[4002];

inline
ll C(int n,int m){
    if(n<m)return 0;
    return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

inline
void init(){
    fac[0]=fac[1]=inv[1]=ifac[1]=ifac[0]=1;
    for(int re i=2;i<=4000;++i){
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        fac[i]=fac[i-1]*i%mod;
        ifac[i]=ifac[i-1]*inv[i]%mod;
    }
}

inline
ll calc(ll a,ll k,ll n){
    ll ans=0;
    for(int re i=0;i<=min(a>>1,n>>1);++i){
        ll tmp=C(a>>1,i)*C(k+n-i*2-1,k-1)%mod;
        if(i&1)ans=(ans-tmp+mod)%mod;
        else ans=(ans+tmp)%mod;
    }
    return ans;
}

int n,k;

int main(){
    init();
    cin>>k>>n;
    for(int re i=1;i<=k;++i){
        if(i&1)ans[i]=(calc(i,k-1,n)+calc(i,k-1,n-1))%mod;
        else ans[i]=calc(i,k,n);
    }
    for(int re i=1;i<=k;++i)outint(ans[i]),pc('\n');
    for(int re i=k-1;i;--i)outint(ans[i]),pc('\n');
    return 0;
}

Measured memory_bytes: 384
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;

int d;
int tab[nax];

int main()
{
	scanf("%d", &n);
	tab[0]=1e9;
	tab[0]+=7;
	for (int i=1; i<=n; i++)
	{
		int x;
		scanf("%d", &x);
		int bsa=0;
		int bsb=d;
		while(bsa<bsb)
		{
			int bss=(bsa+bsb+2)>>1;
			if (tab[bss]>=x)
				bsa=bss;
			else
				bsb=bss-1;
		}
		int p=bsa+1;
		d=max(d, p);
		tab[p]=x;
	}
	printf("%d\n", d);
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var R = int.Parse(inputs[0]);
        var G = int.Parse(inputs[1]);
        var B = int.Parse(inputs[2]);
        var N = int.Parse(inputs[3]);

        int count = 0;
        for (int r = 0; r * R <= N; r++)
        {
            for (int g = 0; g * G <= N - r * R; g++)
            {
                var diff = N - r * R - g * G;
                var rem = diff % B;
                if (diff >= 0 && rem == 0)
                {
                    count++;
                }
            }
        }
        Console.WriteLine(count);
    }
}



Measured memory_bytes: 11092
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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 main() { 
    string s; cin >> s;
    map<char, int> mp;
    for(char c: s){
        mp[c]++;
    }
    bool fg = true;
    for(auto m: mp){
        if(m.second%2!=0)fg = false;
    }
    cout << (fg?"Yes":"No") << ln;
}

Measured memory_bytes: 256
n=int(input())
s=[input() for i in range(n)]
dic={}
l=list()
cnt=0
for i in range(n):
  k=sorted(s[i])
  t=''.join(k)
  l.append(t)
  if l[i] in dic:
    dic[l[i]]+=1
  else:
    dic[l[i]]=0
c=list(dic.values())
for i in range(len(c)):
   cnt+=c[i]*(c[i]+1)//2
print(cnt)


Measured memory_bytes: 25640
N = int(input())

d = {}
for i in range(1, 10):
    for j in range(1, 10):
        d[(i, j)] = 0

for i in range(1, N+1):
    s = str(i)
    head, tail = int(s[0]), int(s[-1])
    if head > 0 and tail > 0:
        d[(head, tail)] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += d[(i,j)] * d[(j,i)]
print(ans)


Measured memory_bytes: 40684
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using namespace std;/*{{{*/

#include <iostream>
#include <map>
#include <vector>

typedef vector<char> VC;
typedef vector<VC> VVC;

#define FOR(i, b, e) for (typeof(e) i = (b); i != (e); i < (e)? ++i : --i)
#define REP(i, n) FOR(i, 0, n)

#define EACH(c,it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define EXIST(s,e) ((s).find(e)!=(s).end())
/*}}}*/

struct article {
	char material;
	bool is_removed;
	int topmost;
	int bottommost;
	int leftmost;
	int rightmost;
};

typedef map<char, article> MCA;

VVC image;
MCA articles;

bool remove_all()
{
	bool all_removed = true;
	EACH (articles, itr) {
		article &art = itr->second;
		if (!art.is_removed) {
			all_removed = false;
			// Remove it and recurse
			VVC save = image;
			bool rect = true;
			FOR (i, art.topmost, art.bottommost + 1) {
				FOR (j, art.leftmost, art.rightmost + 1) {
					if (image[i][j] != '*' && image[i][j] != art.material) {
						rect = false;
					} else {
						image[i][j] = '*';
					}
				}
			}
			if (rect) {
				// Recurse
				art.is_removed = true;
				if (remove_all()) {
					return true;
				}
			}
			// Restore and continue trying
			art.is_removed = false;
			image = save;
		}
	}
	return all_removed;
}

int main()
{
	int t; cin >> t;
	REP (_, t) {
		// Initialize
		articles.clear();

		int h, w; cin >> h >> w;
		image = VVC(h, VC(w, '.'));
		REP (i, h) {
			REP (j, w) {
				cin >> image[i][j];
			}
		}

		// Scan Image
		REP (i, h) {
			REP (j, w) {
				if (image[i][j] != '.') {
					char c = image[i][j];
					if (!EXIST(articles, c)) {
						article a = {c, false, 50, 0, 50, 0};
						articles[c] = a;
					}
					articles[c].topmost = min(articles[c].topmost, i);
					articles[c].bottommost = max(articles[c].bottommost, i);
					articles[c].leftmost = min(articles[c].leftmost, j);
					articles[c].rightmost = max(articles[c].rightmost, j);
				}
			}
		}

		if (remove_all()) {
			cout << "SAFE" << endl;
		} else {
			cout << "SUSPICIOUS" << endl;
		}
	}
}

// vim: foldmethod=marker

Measured memory_bytes: 1264
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    S = [""] * N
    for i in range(N):
        S[i] = input().rstrip()

    xABx = 0
    xxxA = 0
    Bxxx = 0
    BxxA = 0
    for s in S:
        xABx += s.count("AB")
        if s[0] == "B" and s[-1] == "A":
            BxxA += 1
        elif s[0] == "B":
            Bxxx += 1
        elif s[-1] == "A":
            xxxA += 1

    if BxxA == 0:
        ans = xABx + min(xxxA, Bxxx)
    else:
        if xxxA == Bxxx == 0:
            ans = xABx + (BxxA - 1)
        else:
            ans = xABx + BxxA + min(xxxA, Bxxx)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3700
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0565

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    pastas = [int(input()) for _ in range(3)]
    drinks = [int(input()) for _ in range(2)]
    total = min(pastas) + min(drinks) - 50
    print(total)


if __name__ == '__main__':
    main(sys.argv[1:])

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

#[allow(unused)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

macro_rules! out {
    ($x:expr) => {
        println!("{}", $x)
    };
}

macro_rules! debug {
    ($x:expr) => {
        println!("{:?}", $x)
    };
}

use std::io::Read;

fn one_digit(x: u32) -> bool {
    return 1 <= x && x <= 9
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s);
    let mut iter = s.split_whitespace();
    let n: u32 = iter.next().unwrap().parse().unwrap();
    let m: u32 = iter.next().unwrap().parse().unwrap();

    if one_digit(n) && one_digit(m) {
        out!(n * m)
    } else {
        out!(-1)
    }
}



Measured memory_bytes: 4352
sx, sy, tx, ty = map(int, input().split())
ans1 = "R"*(tx-sx) + "U"*(ty-sy)
ans2 = "L"*(tx-sx) + "D"*(ty-sy)
ans3 = "D" + "R"*(tx-sx+1) + "U"*(ty-sy+1) + "L"
ans4 = "U" + "L"*(tx-sx+1) + "D"*(ty-sy+1) + "R"

print(ans1+ans2+ans3+ans4)

Measured memory_bytes: 3060
alphabet_list = ['A','B','C','D','E',
                 'F','G','H','I','J',
                 'K','L','M','N','O',
                 'P','Q','R','S','T',
                 'U','V','W','X','Y','Z']

N = int(input())
S = list(input())

for i in range(len(S)):
  S[i] = alphabet_list[(ord(S[i]) - 64 + N) % 26 - 1]

print(''.join(S))

Measured memory_bytes: 3064
n, k = map(int, input().split())
A = list(map(int, input().split()))

f = 1
first = []
for _ in range(n):
    num = A[f-1]
    first.append(num)
    f = num

for i in range(n):
    if num == first[i]:
        roopcount = n-i-1 #3
        break

if k <= n:
    print(first[k-1])
else:
    s = (k-(n-roopcount))%roopcount
    print(first[i+s])

Measured memory_bytes: 32300
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

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

	//初期値は大きい値
	int ans = s.size();

	//iは最初に使う色（０か１）
	for(int i = 0; i < 2; i++){
		int cnt = 0;
		for(int j = 0; j < s.size(); j++){
			if((j%2 == 0) ^ (s[j] != (char)(i+'0')))cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  long long int minimum = -99999;
  for (int i = 1; i <= 40; i++){
    for (int j = 2; j <= 12; j++){
      if (std::pow(i,j) <= x){
        if (std::pow(i,j) > minimum){
          minimum = std::pow(i,j);
        }
      }
    }
  }
  cout << minimum << endl;
}

Measured memory_bytes: 4124
#include<stdio.h>
int main(void){
  int n,k;
  scanf("%d%d",&k,&n);
  int a[n];
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
}
  int max=k-a[n-1]+a[0];
for(int i=0;i<n-1;i++){
  int l=a[i+1]-a[i];
  if(l>max)
    max=l;
 
}
  	 		
  printf("%d",k-max);
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    while (s.length()) {
        if (s.length() >= 5 && s.substr(s.length() - 5, 5) == "dream") s = s.substr(0, s.length() - 5);
        else if (s.length() >= 7 && s.substr(s.length() - 7, 7) == "dreamer") s = s.substr(0, s.length() - 7);
        else if (s.length() >= 5 && s.substr(s.length() - 5, 5) == "erase") s = s.substr(0, s.length() - 5);
        else if (s.length() >= 6 && s.substr(s.length() - 6, 6) == "eraser") s = s.substr(0, s.length() - 6);
        else {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}


Measured memory_bytes: 512
# ABC158d


def main():
    import sys
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    s = input()
    q = int(input())
    query = [input().split() for _ in range(q)]

    mode = 0
    from collections import deque
    que = deque(list(s))
    for i in query:
        if len(i) == 1:
            mode = 1-mode
            continue
        f = int(i[1])
        if mode == 0:
            if f == 1:
                que.appendleft(i[2])
            else:
                que.append(i[2])
        else:
            if f == 1:
                que.append(i[2])
            else:
                que.appendleft(i[2])
    mode = 1 if mode == 0 else - 1
    # print(mode)
    qq = list(que)
    # print(qq[::-1])
    print(*(qq[::mode]), sep='')


if __name__ == '__main__':
    main()


Measured memory_bytes: 50748
N = input().split()
NN = []
for i in range(3):
    NN.append(int(N[i]))
NN.sort()
A = NN[0]
B = NN[1]
C = NN[2]

count = 0

if A == B:
    count = 0
elif A%2 != B%2:
    A = A+1
    C = C+1
    count = count +1
while(A != B):
    A = A+2
    count = count+1
count = count + (C-A)
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 100005;

int main() {
    string s;
    cin >> s;
    if (s.back() == 's')
        s += "es";
    else
        s += "s";
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb;

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

ll KetaSum(string num){
    ll sum=0;
    rep(i,num.size()){
        sum += num[i] - '0';
    }
    return sum;
}

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

    ll resultSum=0;
    rep(i,N+1){
        ll ketaSum = KetaSum(to_string(i));
        if(A <= ketaSum && ketaSum <= B){
            resultSum += i;
        }
    }

    cout << resultSum << endl;
}



Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int n;
  string s;
  cin>>n>>s;
  int a=n/2;
  string str=s.substr(0,a);
  if(str==s.substr(a))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
a, b, c, d, e, f = map(int,input().split())

water = 0
sugar = 0
rate = 0

for x in range(31):
    for y in range(31):
        if x + y == 0:
            continue
        for z in range(101):
            for w in range(101):
                now_water = 100*a*x + 100*b*y + c*z + d*w
                if now_water > f:
                    break
                now_sugar = c*z + d*w
                if now_water*e >= now_sugar*(100 + e):
                    now_rate = now_sugar/now_water
                    if rate <= now_rate:
                        rate = now_rate
                        water = now_water
                        sugar = now_sugar


print(water,sugar)

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

using namespace std;

#define ll long long int
#define ld long double
#define pii pair<int,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define bit(a,b) ((a>>b)&1)
#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

const ll mx = 1e6+1, Mod = 1e9+7;

int n;

int main()
{
    IOS;
    int r;
    cin >> r;
    if(r<1200)
        cout << "ABC";
    else if(r<2800)
        cout << "ARC";
    else
        cout << "AGC";
    return 0;
}












Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;
	cout << 6 - A - B << '\n';

	return 0;
}


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

using namespace std;
typedef long long int ll;

int main(void) {
  string s, t;
  cin >> s >> t;
  ll ans = 0;
  rep(i, s.size())
    if (s[i] != t[i])
      ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3904
n, q = map(int, input().split())
s = input()

t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i : i + 2] == "AC" else 0)
# print(t)
for j in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])

Measured memory_bytes: 9540
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int nal[100010][26];

int
main(int argc, const char *argv[])
{
  char s[100001], t[100001];
  scanf("%s", s);
  scanf("%s", t);

  int al[30] = {};
  int n = strlen(s), m = strlen(t);
  for (int i = 0; i < n; i++) al[s[i] - 'a']++;
  for (int i = 0; i < m; i++) {
    if (al[t[i] - 'a'] == 0) {
      printf("-1\n");
      return 0;
    }
  }

  for (int i = 0; i < 26; i++) nal[n][i] = -1;
  nal[n][s[n - 1] - 'a'] = n;
  for (int i = n - 1; i >= 1; i--) {
    for (int j = 0; j < 26; j++) {
      nal[i][j] = nal[i + 1][j];
    }
    nal[i][s[i - 1] - 'a'] = i;
  }

  ll k = 0; int e = 0;
  while (e < m) {
    if (nal[(int)(k % (ll)n) + 1][t[e] - 'a'] != -1) {
      k += nal[(int)(k % (ll)n) + 1][t[e] - 'a'] - k % (ll)n;
      e++;
    } else {
      k += (ll)n - k % (ll)n;
    }
  }

  printf("%lld\n", k);

  return 0;
}
  

  

  


Measured memory_bytes: 10496
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}

	int ans = 1;

	int tmp = H[0];
	for (int i = 1; i < N; ++i) {
		if (tmp < H[i - 1]) {
			tmp = H[i - 1];
		}

		if (tmp <= H[i]) {
			ans++;
		}
	}

	cout << ans << endl;
}


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

int ze(int a){
if(a<0)return -a;
return a;
}
int main(){
int a,b;
cin>>a>>b;
vector<int>c(a);
for(int d=0;d<a;d++)cin>>c[d];
vector<vector<int>>e(b,vector<int>(3));
for(int f=0;f<b;f++)cin>>e[f][0]>>e[f][1]>>e[f][2];
vector<vector<int>>dp(a+1,vector<int>(b));
for(int h=1;h<a;h++){
	for(int i=0;i<b;i++){
		if(c[h]>=e[i][0]&&c[h]<=e[i][1]){
			int s=0;
		for(int j=0;j<b;j++){
			if(c[h-1]>=e[j][0]&&c[h-1]<=e[j][1])
			s=max(s,dp[h][j]+ze(e[i][2]-e[j][2]));
		}
		dp[h+1][i]=s;
		}
	}
}
int x=0;
for(int y:dp[a]){
	if(x<y)x=y;
}
cout<<x<<endl;
}

Measured memory_bytes: 3236
import java.util.Scanner

object Main extends App {

  def readALine(c:Int, ac:List[Int]=Nil):List[Int] =
    if (c > 0) readALine(c-1, sc.nextInt::ac) else ac.reverse
  // def readLines(r:Int, c:Int, ac:List[List[Int]]):List[List[Int]] =
  //   if (r > 0) readLines(r-1, c, readALine(c, Nil)::ac) else ac.reverse
  val sc = new Scanner(System.in)
  val N = sc.nextLong

  val divisor = 26

  def solver(n:Long, al:List[Int]):List[Int] = {
    // println(s"debug n:$n al:$al")
    if (n / divisor ==0)
      (n % divisor).toInt::al
    else
      solver((n-divisor)/divisor, ((n-divisor) % divisor).toInt::al)
  }

  println(solver(N-1, Nil).map((x)=>(x+97).toChar).mkString(""))

}

Measured memory_bytes: 55344
n = int(raw_input())
p = map(int, raw_input().split())
a = [0] * n
b = [0] * n
for i, x in enumerate(p):
    x -= 1
    a[x] = x * 30000 + i + 1
    b[x] = n * 30000 - x * 30000
for x in a:
    print x,
print
for x in b:
    print x,
print


Measured memory_bytes: 4908
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
//vector.assign (n,value)... for global vectors
class abc
{
    public:
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,r;
    cin>>n>>r;
    ll ans;
    if (n>=10)
    {
        ans=r;
    }
    else
    {
        ans=r+=100*(10-n);
    }
    cout<<ans<<'\n';
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int r,c;
  cin>>r>>c;
  int matrix[200][200]={0};
  int col[200]={0};
  int row[200]={0};
  int matrixsum=0;
  for(int i=1;i<=r;i++)
  {
    for(int k=1;k<=c;k++)
    {
      cin>>matrix[i][k];
    }
  }
  for(int i=1;i<=r;i++){
    for(int k=1;k<=c;k++)
    {
      col[i]=col[i]+matrix[i][k];
    }
    //cout<<col[i]<<endl;
  }
  for(int i=1;i<=c;i++)
  {
    for(int j=1;j<=r;j++)
    {
      row[i]=row[i]+matrix[j][i];
    }
    //cout<<row[i]<<endl;
    matrixsum=matrixsum+row[i];
  }
  row[c+1]=matrixsum;
  for(int i=1;i<=r+1;i++)
  {
    if(i<=r)
    {
    for(int k=1;k<=c+1;k++)
    {
      if(k<=c)
      {
        cout<<matrix[i][k]<<" ";
      }else{
        cout<<col[i];
      }
    }
    cout<<endl;
  }else{
      for(int j=1;j<=c+1;j++)
      {
        if(j<=c){
        cout<<row[j]<<" ";
      }else{
        cout<<row[j];
      }
      }
      cout<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3252
{-# LANGUAGE RankNTypes #-}
    
import Control.Monad.State
import Control.Monad.ST
import Data.Array.ST
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V

main :: IO ()
main = readContents 2 >>= print . solve

solve :: [[Int]] -> Int
solve [[n, k], vs] = runST (initialize >>= stAction)
    where
        ws = V.fromList vs

        initialize :: ST s (Table s (Int, Int, Int) Int)
        initialize = newArray ((0, 0, 0), (n, n, k + 1)) Nothing
        
        stAction t 
            | n == 1 = return (max 0 $ head vs)
            | otherwise = evalMemo calc (0, n - 1, k) t 

        calc f (a, b, c)
            | c == 0 = return 0
            | a == b = return $ max 0 av 
            | av >= 0 && bv >= 0 = maximum <$> sequence [(+ av) <$> f (a + 1, b, c - 1), (+ bv) <$> f (a, b - 1, c - 1)]
            | av >= 0 && c > 1 = maximum <$> sequence [(+ av) <$> f (a + 1, b, c - 1), f (a, b - 1, c - 2), (+ bv) <$> f (a, b - 1, c - 1)]
            | av >= 0 = maximum <$> sequence [(+ av) <$> f (a + 1, b, c - 1), (+ bv) <$> f (a, b - 1, c - 1)]
            | bv >= 0 && c > 1 = maximum <$> sequence [(+ bv) <$> f (a, b - 1, c - 1), f (a + 1, b, c - 2), (+ av) <$> f (a + 1, b, c - 1)]
            | bv >= 0 = maximum <$> sequence [(+ av) <$> f (a + 1, b, c - 1), (+ bv) <$> f (a, b - 1, c - 1)]
            | c > 1 = maximum <$> sequence [(+ av) <$> f (a + 1, b, c - 1), (+ bv) <$> f (a, b - 1, c - 1),f (a + 1, b, c - 2), f (a, b - 1, c - 2)]
            | otherwise = return 0
            where
                av = ws V.! a
                bv = ws V.! b

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

type Table s a b = STArray s a (Maybe b)
type Memo s a b = a -> StateT (Table s a b) (ST s) b

evalMemo :: (Ix a) => (forall s. Memo s a b -> Memo s a b) -> a -> Table s a b -> ST s b
evalMemo f k = evalStateT (memoizeFix f k)

runMemo :: (Ix a) => (forall s. Memo s a b -> Memo s a b) -> a -> Table s a b -> ST s (b, Table s a b)
runMemo f k = runStateT (memoizeFix f k)

memoizeFix :: (Ix a) => (forall s. Memo s a b -> Memo s a b) -> forall s. Memo s a b
memoizeFix f k = get >>= (\arr -> lift (readArray arr k) >>= maybe (f (memoizeFix f) k >>= ((<$) <*> (lift . writeArray arr k . Just))) return)

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

int main() {
    int n;
    cin >> n;
    if(n%2 == 0)
    {
        cout << n/2 << "\n";
    }
    else
    {
        cout << (n/2 + 1) << "\n";
    }
	// your code goes here
	return 0;
}


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

int main(void) {
  string S;
  cin >> S;
  int N = S.size();
  int64_t K;
  cin >> K;

  int64_t left_num = 1;
  for (int i = 1; i < N; ++i) {
    if (S[0] != S[i]) break;
    ++left_num;
  }
  if (left_num == N) {  // All number is the same
    cout << N * K / 2 << endl;
    return 0;
  }

  int64_t right_num = 1;
  for (int i = N - 2; i >= 0; --i) {
    if (S[N - 1] != S[i]) break;
    ++right_num;
  }

  int64_t answer = 0;
  int64_t seq_num = 1;
  for (int i = 1; i < N; ++i) {
    if (S[i - 1] == S[i]) {
      ++seq_num;
    } else {
      answer += (seq_num / 2);
      seq_num = 1;
    }
  }
  answer += (seq_num / 2);
  answer *= K;

  if (S[0] == S[N - 1]) {
    answer += (left_num + right_num) / 2 * (K - 1);
    answer -= left_num / 2 * (K - 1);
    answer -= right_num / 2 * (K - 1);
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  char a,b,c ;
  cin>>a>>b>>c ;
  if (a=='a' && b=='b' && c=='c')
  cout <<("Yes")<<endl ;
  else if (a=='a' && b=='c' && c=='b')
  cout <<("Yes")<<endl ;
  else if (a=='b' && b=='a' && c=='c')
  cout <<("Yes")<<endl ;
  else if (a=='b' && b=='c' && c=='a')
  cout <<("Yes")<<endl ;
  else if (a=='c' && b=='a' && c=='b')
  cout <<("Yes")<<endl ;
  else if (a=='c' && b=='b' && c=='a')
  cout <<("Yes")<<endl ;
  else
  cout <<("No")<<endl ;
  return 0 ;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int A[] = new int[N];
        for (int i = 0; i < N ; i++) {
            A[i] = scan.nextInt();
        }
        int B[] = new int[N];
        for (int i = 0; i < N ; i++) {
            B[A[i]-1] = i+1;
        }

        for (int i = 0; i < N - 1 ; i++) {
            os.print(B[i] + " ");
        }
        os.println(B[N-1]);

    }
}

Measured memory_bytes: 60696
N, K = map(int, input().split())
boundary_value = int((N-1) * (N-2) / 2)

if boundary_value < K:
    print(-1)
else:
    graph = []
    num_side = boundary_value - K

    for i in range(N):
        for j in range(i + 1, N):
            graph.append([i + 1, j + 1])
    
    print(N + num_side - 1)
    for i in range(N + num_side - 1):
        print("%d %d" %(graph[i][0], graph[i][1]))

Measured memory_bytes: 3844
#include<iostream>
#include<cstdio>
#include<stdlib.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a<0&&b>0){cout<<"Zero"<<endl;return 0;}
if(a==0||b==0){cout<<"Zero"<<endl;return 0;}
if(a>0){cout<<"Positive"<<endl; return 0;}
if((b-a)%2==1){cout<<"Positive"<<endl; return 0;}
if((b-a)%2==0){cout<<"Negative"<<endl; return 0;}
return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int l[200];
int b[200];
int main(void){
    int n,x,i;
    for(i=0;i<200;i++){
        l[i]=-1;
        b[i]=-1;
    }
    scanf("%d %d",&n,&x);
    for(i=1;i<=n;i++){
        scanf("%d",&l[i]);
    }
    b[0]=0;
    for(i=1;i<=n;i++){
        b[i]=b[i-1]+l[i];
    }
    int cnt=0;
    for(i=0;i<=n;i++){
        if(b[i]<=x){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
n, yen = map(int, input().split())

x = y = z = -1

for a in range(0, n+1):
    for b in range(0, n + 1 - a):
        num = n - a - b
        if (10000*a + 5000*b + 1000*num) == yen:
            x = a
            y = b
            z = num
            break

print(x, y, z)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	
	scanf("%d", &n);
	for (int i = 1; i <= 3500; i++) {
		for (int j = 1; j <= 3500; j++) {
			long long x = 1ll * n * i * j;
			long long y = 1ll * 4 * i * j - 1ll * n * j - 1ll * n * i;
			if (y > 0 && x % y == 0) {
				printf("%d %d %lld\n", i, j, x / y);
				return 0;
			}
		}
	}
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

double R1,R2;

double f(double m)
{
	return 1.0 / m;
}

int main()
{
	scanf("%lf%lf",&R1,&R2);

	double lo = 0.1,hi = 100.0,mid;
	FOR(i,0,100){
		mid = (lo + hi) / 2.0;
		if(f(mid) >= 1.0 / R1 + 1.0 / R2){
			lo = mid;
		}
		else{
			hi = mid;
		}
	}

	printf("%.10f\n",(lo + hi) / 2.0);

	return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = [input() for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            count = 0
            for i_ in range(i-1, i+2):
                for j_ in range(j-1, j+2):
                    if 0<= i_ <h and 0<= j_ <w:
                        if s[i_][j_] == '#':
                            count += 1
            s[i]=s[i][:j]+str(count)+s[i][j+1:]

for i in range(h):
    print(s[i])



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll a,b,c; cin>>a>>b>>c;
	(a+b+c>=22)?cout<<"bust\n":cout<<"win\n";
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll nj[2000003]={0};
ll c1,c2,r1,r2;
ll qpow(ll a,ll b)
{
	if(b==0)	return 1;
	ll c=qpow(a,b/2);
	if(b%2==0)	return c*c%mod;
	else		return c*c%mod*a%mod;
}
ll cnm(ll n,ll m)
{
	return nj[m+n]*qpow(nj[n]*nj[m]%mod,mod-2)%mod;
}
ll f()
{
	return cnm(r1,c1)+cnm(r2+1,c2+1)-cnm(r1,c2+1)-cnm(r2+1,c1);
}
int main(void)
{
	scanf("%lld%lld%lld%lld",&r1,&c1,&r2,&c2);
	nj[0]=1;
	for(ll i=1;i<=2000002;i++)
	{
		nj[i]=nj[i-1]*i;
		nj[i]%=mod;
	}
	printf("%lld",(f()+mod*100)%mod);
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp make_pair

const int N = 200200;
int n;
pll a[N];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);


    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%lld%lld", &a[i].first, &a[i].second);
        if (a[i].first > a[i].second) swap(a[i].first, a[i].second);
    }
    ll l1 = a[0].first, r1 = a[0].first, l2 = a[0].second, r2 = a[0].second;
    for (int i = 0; i < n; i++)
    {
        l1 = min(l1, a[i].first);
        r1 = max(r1, a[i].first);
        l2 = min(l2, a[i].second);
        r2 = max(r2, a[i].second);
    }
    ll ans = (r1 - l1) * (r2 - l2);
    ll len = max(r1, r2) - min(l1, l2);
    sort(a, a + n);
    ll l3 = max(r1, r2), r3 = a[n - 1].first;
    for (int i = 0; i <= n; i++)
    {
        ans = min(ans, len * (r3 - min(l3, (i == n ? l3 : a[i].first))));
        if (i == n) break;
        l3 = min(l3, a[i].second);
        r3 = max(r3, a[i].second);
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 3328
// Problem : G - Longest Path
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_g
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int n,m;
vector<int> adj[maxn];
int vis[maxn],dp[maxn];
vector<int> v;
void dfs(int curr)
{
	//cout << curr <<" ";
	vis[curr]=1;
	for(auto x:adj[curr])
	{
		if(vis[x]==0)
		dfs(x);
		dp[curr]=max(dp[curr],1+dp[x]);
	}
}
void solve()
{
	cin >> n >> m;
	rep(i,0,m)
	{
		int x,y;
		cin >> x >> y;
		adj[x].pb(y);
	}
	repe(i,1,n)
	{
		if(vis[i]==0)
			dfs(i);
		//cout <<"\n";
	}
	int ans=0;
	repe(i,1,n)
		ans=max(ans,dp[i]);
	cout << ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 15624
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    int H,W,K; cin>>H>>W>>K;
    vector<string> S(H);
    vector<vector<int>> ruiseki(H+1,vector<int>(W+1,0));
    for (int i = 0; i < H; ++i) {
        cin>>S[i];
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            ruiseki[i+1][j+1]=S[i][j]-'0'+ruiseki[i+1][j]+ruiseki[i][j+1]-ruiseki[i][j];
        }
    }

    int ans=(int)1e9;
    for (int i = 0; i < (1 << (H - 1)); ++i) {
        int cnt=0;
        vector<int> div; div.push_back(0);
        for (int j = 0; j < H - 1; ++j) {
            if((i>>j)&1) {
                cnt++;
                div.push_back(j+1);
            }
        }
        div.push_back(H);
        int N=div.size()-1;
        int prev=0;
        bool use=true;
        for (int j = 1; j <= W; ++j) {
            bool back= false;
            for (int k = 0; k < N; ++k) {
                int tmp=ruiseki[div[k+1]][j]-ruiseki[div[k]][j]-ruiseki[div[k+1]][prev]+ruiseki[div[k]][prev];
                if(tmp>K) {
                    back= true;
                    break;
                }
            }
            if(back){
                if(j-1==prev) {
                    use= false;
                    break;
                }
                prev=j-1;
                cnt++;
                j--;
            }
        }
        if(use) ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int w,a,b;
    scanf("%d %d %d",&w,&a,&b);
    if( a + w < b)
        printf("%d\n",(b - (a+w)));
    else if(b + w < a)
        printf("%d\n",(a - (b+w)));
    else
        printf("0\n");
    return 0;
}


Measured memory_bytes: 128
import heapq
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    for i,aa in enumerate(a):
        a[i] = -1 * aa
    heapq.heapify(a)
    for i in range(m):
        tmp = heapq.heappop(a) * (-1) // 2
        heapq.heappush(a,tmp * (-1))
    print(sum(a) * (-1))
if __name__=='__main__':
    main()


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

int main() {
	int N, ans = 0;
	cin >> N;

	for (int i = N; i >= 1; i--) {
		string S = to_string(i);
		if (S.size() % 2 != 0) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int c,n,s,t,b,i,j,k,x[9][4]={
		{1,3,0,0},
		{0,2,4,1},
		{1,5,2,2},
		{0,4,6,3},
		{1,3,5,7},
		{2,4,8,5},
		{3,7,6,6},
		{4,6,8,7},
		{5,7,8,8}
	};
	char u,v,w;
	while(scanf("%d",&n),n)
	{
		int a[16][9]={0};
		scanf(" %c %c %c",&u,&v,&w);
		s=u-'A',t=v-'A',b=w-'A';
		c=a[0][s]=1;
		for(i=0;i<n;++i,c*=4)for(j=0;j<9;++j)for(k=0;k<4;++k)
			if(x[j][k]!=b)a[i+1][x[j][k]]+=a[i][j];
			else a[i+1][j]+=a[i][j];
		printf("%.8f\n",a[n][t]/(double)c);
	}
	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    cout << fixed << setprecision(10);
    if(x > a * b / 2){
        cout << atan(2 * (a * b - x) / a / a) * 180 / M_PI << endl;;
    }else{
        cout << atan(b * b / 2 / x) * 180 / M_PI << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int A,B;cin >> A >> B;
    if(A%3==0 || B%3==0 || (A+B)%3==0) cout << "Possible";
    else cout << "Impossible";
    cout << endl;
    return 0;
}

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

int a[100010],n;
vector <int> v[2];
int maxn=0;

void solve(int x,int id){
	for(int i=1;i*i<=x;i++){
		if(x%i==0){
			v[id].push_back(i);
			v[id].push_back(x/i);
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<2;i++) solve(a[i],i);
	sort(v[0].begin(),v[0].end());
	reverse(v[0].begin(),v[0].end());
	sort(v[1].begin(),v[1].end());
	reverse(v[1].begin(),v[1].end());
	for(int i=0;i<2;i++){
		for(int j=0;j<v[i].size();j++){
			int cnt=0;
			for(int k=0;k<n;k++) if(a[k]%v[i][j]==0) cnt++;
			if(cnt>=n-1) maxn=max(maxn,v[i][j]);
		}
	}
	printf("%d\n",maxn);
	return 0;
}

Measured memory_bytes: 640
from itertools import combinations
import sys
#input = sys.stdin.buffer.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
Com = []
for i in range(N):
    Com.append(i)


ans = float('inf')
for com in combinations(Com, K):
    anscom = 0
    thread = 0
    for i, a in enumerate(A):
        if i not in com:
            thread = max(thread, a)
        else:
            if thread < a:
                thread = a
            else:
                anscom += thread + 1 - a
                thread += 1
    ans = min(ans, anscom)
print(ans)




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  string year = s.substr(0,4);
  int years = stoi(year);
  string month = s.substr(5,2);
  int months = stoi(month);
  if(years<2019){
    cout << "Heisei" << endl;
  } else if (years==2019 && months<05){
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}


Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
//#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

int main(void){

	int m;
	cin >> m;
	while (m--){
		int money, year, n;
		int max_money = 0;
		scanf("%d%d%d", &money, &year, &n);
		for (int j = 0; j < n; j++){
			int way, commission;
			double r;
			scanf("%d%lf%d", &way, &r, &commission);
			int buff = money;
			if (way == 1){
				for (int k = 0; k < year; k++){
					buff = buff + r * buff - commission;
				}
			}
			else{
				int buff2 = 0;
				for (int k = 0; k < year; k++){
					buff2 += r * buff;
					buff -= commission;
				}
				buff = buff + buff2;
			}
			max_money = max(buff, max_money);
		}
		cout << max_money << endl;
	}

	return 0;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)


int main()
{
	int n;
	cin>>n;
	float ans=0;
	while(n--)
	{
		float x;
		string s;
		cin>>x>>s;
		if(s[0]=='J') ans+=x;
		else ans+=380000*x;
	}
	cout<<ans;
	return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n, x; cin >> n >> x;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    ASC(a);
    int ans = 0;
    ll count = 0;
    REP(i, n) {
        count += a[i];
        if (count == x) {
            ans++;
            break;
        }
        else if (count > x) break;
        ans++;
    }
    if (count < x) ans--;
    cout << ans << endl;
}


Measured memory_bytes: 256