akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int n,ans=0;
vector<bool> ver;
void dfs(const graph &g,int v,int p){
  ver[v]=true;
  vector<bool> w=ver;
  if(p==n)ans++;
  for(auto i:g[v]){
    if(ver[i])continue;
    dfs(g,i,p+1);
    ver=w;
  }
}

int main(){
  int i,j,k,cnt=0;
  int m;
  cin>>n>>m;
  graph g(n);
  for(i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ver.assign(n,false);
  dfs(g,0,1);
  cout<<ans<<endl;
  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------
		int n = Integer.parseInt(sc.next());
		String s = sc.next();

		if (s.length() % 2 == 0 && s.substring(0, n / 2).equals(s.substring(n / 2, n))) {
			out.println("Yes");
		} else {
			out.println("No");
		}

		// ------------------------------------------------
		sc.close();
		out.flush();
	}
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

const ll MAXN = 200*1000+5;
ll a[MAXN];
map<pair<ll,ll>,ll> memo; 

ll dp(ll idx, ll need){
    if (need==0) return 0;
    if (idx<0) return -inf;
    if (need > (idx+1)/2+1) return -inf;
    pair<ll,ll> state{idx,need};
    
    if (memo.count(state)) return memo[state]; 
    return memo[state] = max(dp(idx-1,need), dp(idx-2,need-1)+a[idx]);
}


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

    ll n;cin>>n;
    REP(i,n) cin>>a[i];
    cout<< dp(n-1,n/2) <<endl;
    return 0;
}

Measured memory_bytes: 39588
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  int L[N];
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  sort(L,L + N, greater< int >());
  int ans = 0;
  for (int i =0; i <K; i++) {
    ans += L[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		String s = fs.next();
		
		int r = 0;
		int b = 0;
		
		for(int i = 0; i < n; i++) {
			char charAt = s.charAt(i);
			
			if(charAt == 'R') {
				r++;
			}else {
				b++;
			}
		}
		
		if(r > b) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 22484
n=int(input())
a=map(int, input().split())
a=list(a)
a.sort(reverse=True)
sum_alice=0
sum_bob=0
for i in range(0, n, 2):
    sum_alice=sum_alice+a[i]
for i in range(1, n, 2):
    sum_bob=sum_bob+a[i]
print(sum_alice-sum_bob)


Measured memory_bytes: 38384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;

template<class T> bool ckmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template <typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template <typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template <class X, class Y>
std::ostream & operator << (std::ostream & os, std::pair <X, Y> const& p) {
    return os << p.first << " " << p.second;
}

template <class Ch, class Tr, class Container>
std::basic_ostream <Ch, Tr> & operator << (std::basic_ostream <Ch, Tr>& os, Container const& x) {
    bool first = true;
    for(auto& y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BPictureFrame {
public:
	void solve(std::istream& in, std::ostream& out) {
        int h, w;
        in >> h >> w;
        vector<string> grid(h);
        in >> grid;
        vector<string> res(h + 2, string(w + 2, '#'));
        FOR(i, 0, h) {
            FOR(j, 0, w) {
                res[i + 1][j + 1] = grid[i][j];
            }
        }
        trav(row, res) {
            out << row << '\n';
        }
	}

	void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
	BPictureFrame solver;
    solver.setup();
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end() 

int const N = 200001;
int n, v[N], nxt[N]; 

int main(){
    scanf("%d", &n);
    for(int i = 0; i<n; ++i){
      scanf("%d", v+i);
    }
    // nxt[i] = index of first number greater than zero that is positoned after i 
    ll an = 0;
    nxt[n] = n;
    for(int i = n-1; i >= 0; --i){
       nxt[i] = nxt[i+1]; 
       if(v[i+1])nxt[i] = i+1;
    }
    for(int i = 0; i<n; ++i){
       ll ad = 0, ope = 0, sm = 0, XOR = 0, lst = i, f = 0; 
       for(int j = i; j < n && ope <= 20; j = nxt[j], ++ope){
           int z = j - lst;
           if(f)ad += z; 
           XOR ^= v[j];
           sm += v[j];
           if(XOR == sm)f = 1, ++ad;
           else f = 0; 
           lst = j+1;
       }
       if(f)ad += (n-lst);
       an += ad;
    }
    printf("%lld\n", an);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll arr[5],n;
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        if(s[0]=='M')
            arr[0]++;
        else if(s[0]=='A')
            arr[1]++;
        else if(s[0]=='R')
            arr[2]++;
        else if(s[0]=='C')
            arr[3]++;
        else if(s[0]=='H')
            arr[4]++;
    }
    ll ans=0;
    for(int i=0; i<5; i++)
    {
        for(int j=i+1; j<5; j++)
        {
            for(int k=j+1; k<5; k++)
            {
            ans+=arr[i]*arr[j]*arr[k];
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {

   int n;
   cin>>n;
   vector <int> vec;
    for (int i = 0; i <n ; ++i) {
    int x;
    cin>>x;
    vec.push_back(x);
    }
    vector <int> v=vec;
    sort(v.begin(),v.end(),greater<int>());
    int mx1=v[0],mx2=v[1];
    for(auto v: vec )
    {
        if(v!=mx1)
            cout<<mx1<<" ";
            else
                cout<<mx2<<" ";

    }
}


Measured memory_bytes: 3316
n, k = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

Y = []
Z = []

for x in X:
    if x == 0:
        Y.append(0)
        Z.append(0)
    elif x < 0:
        Y.append(abs(x))
    else:
        Z.append(x)

ans = sum(Y) + sum(Z)
Y.reverse()

for i, y in zip(range(1, len(Y)+1), Y):
    if i <= k and k - i <= len(Z):
        ans = min(ans, y + (0 if i == k else 2 * Z[k-(i+1)]))

for i, z in zip(range(1, len(Z)+1), Z):
    if i <= k and k - i <= len(Y):
        ans = min(ans, (0 if i == k else 2 * Y[k-(i+1)]) + z)

print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H, vector<char>(W));
  for (ll i = 0; i < H; ++i) {
    for (ll j = 0; j < W; ++j) {
      cin >> maze.at(i).at(j);
    }
  }
  vector<bool> h_del(H, false);
  vector<bool> w_del(W, false);
  for (ll i = 0; i < W; ++i) {
    bool all = true;
    for (ll j = 0; j < H; ++j) {
      if (maze.at(j).at(i) != '.') {
        all = false;
        break;
      }
    }
    if (all) {
      w_del.at(i) = true;
    }
  }
  for (ll i = 0; i < H; ++i) {
    bool all = true;
    for (ll j = 0; j < W; ++j) {
      if ('.' != maze.at(i).at(j)) {
        all = false;
        break;
      }
    }
    if (all) {
      h_del.at(i) = true;
    }
  }
  for (ll i = 0; i < H; ++i) {
    bool no = true;
    for (ll j = 0; j < W; ++j) {
      if (h_del.at(i) || w_del.at(j)) {
        continue;
      }
      cout << maze.at(i).at(j);
      no = false;
    }
    if (!no) {
      cout << endl;
    }
  }
}


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

alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def solve(n):
    if n == 1:
        return ['a']
    elif n == 2:
        return ['aa', 'ab']
    else:
        chars = alphabets[0:n]
        result = []
        for retsu in solve(n - 1):
            done = False
            for char in chars:
                if char in retsu:
                    result.append(retsu + char)
                else:
                    if not done:
                        result.append(retsu + char)
                        done = True
                    else:
                        break
        return result

print("\n".join(solve(N)))


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

int main()
{
  int i, n;
  scanf("%d", &n);
  double b[n + 5] = {0.0}, a[n + 5] = {0.0}, p;
    b[0] = 1.0, a[0] = 1.0;
  for (i = 1; i <= n; i++)
    {
      scanf("%lf", &p);
      for (int j = 0; j <= i; j++)
        b[j] = a[j] * (1.0 - p) + a[j - 1] * p;

    b[0] = a[0] * (1.0 - p);

      for (int j = 0; j <= i; j++)
        {a[j] = b[j];} //printf("%lf. ",a[j]);}
      //printf("\n");
    }

  double sum = 0.0;
  for (i=(n+1)/2; i<=n; i++)
  {
    sum += a[i];
    //printf("%lf ", a[i]);
  }

  //printf("\n");
  printf("%.11lf\n", sum);

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int[] line = new int[4];
		line[0] = sc.nextInt();
		line[1] = sc.nextInt();
		line[2] = sc.nextInt();
		line[3] = sc.nextInt();

		String ans;
		if(!isIn(line, 1)){
			ans = "NO";
		}else if(!isIn(line, 9)){
			ans = "NO";
		}else if(!isIn(line, 7)){
			ans = "NO";
		}else if(!isIn(line, 4)){
			ans = "NO";
		}else{
			ans ="YES";
		}
		
		System.out.println(ans);
	}
	
	public static boolean isIn(int[] line,int x){
		for(int n=0; n<4; n++){
			if(line[n]==x){
				line[n]=0;
				return true;
			}
		}
		return false;
	}

}


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

keta = 1
for i in range(1, 18):
    t = 26*(26**i-1)//25
    if n <= t:
        break
    else:
        keta += 1

n -= 26*(26**(keta-1)-1)//25
n -= 1

ans = ""
for i in range(keta):
    t = 26**i
    ans = chr(ord('a')+(n//t)%26)+ans
print(ans)

Measured memory_bytes: 61788
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=200005;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,k,a[maxn],N;
ll sum[maxn],tot[maxn],ans=0;
vector<ll> vec;
void add(int x){
	while (x<=N){
		++tot[x];
		x+=x&(-x);
	}
}
ll query(int x){
	ll res=0;
	while (x){
		res+=tot[x];
		x-=x&(-x);
	}
	return res;
}
int main(){
	n=read(),k=read();
	for (int i=1;i<=n;++i) a[i]=read()-k;
	for (int i=1;i<=n;++i) sum[i]=sum[i-1]+a[i];
	for (int i=0;i<=n;++i) vec.push_back(sum[i]);
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());N=vec.size();
	for (int i=0;i<=n;++i) sum[i]=lower_bound(vec.begin(),vec.end(),sum[i])-vec.begin()+1;
	for (int i=0;i<=n;++i){
		ans+=query(sum[i]);
		add(sum[i]);
	}
	printf ("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5872
n,m = map(int,input().split())
ans = ["num"]*n
for i in range(m):
    s,c = map(int,input().split())
    if ans[s-1] == "num" or ans[s-1] == c:
        ans[s-1] = c
    else:
        print("-1")
        exit()

if ans[0] == 0 and n >= 2:
    print("-1")
    exit()
elif ans[0] == 0 and n == 1:
    print("0")
    exit()
elif ans[0] == "num" and n == 1:
    print("0")
    exit()
elif ans[0] == "num":
    ans[0] = 1

for j in range(n):
    if ans[j] == "num":
        ans[j] = 0

[print(ans[k],end ="") for k in range(n)]

Measured memory_bytes: 9236
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)


#define INF (1e9)
typedef long long unsigned int ll;


int main()
{

    int n,m;
    cin >> n>>m;
    int x[m];
    REP(i,m){
        cin >> x[i];

    }
    int l[m - 1];
    

    sort(x, x + m);
    REP(i,m-1){
        l[i] = x[i + 1] - x[i];
    }

    sort(l, l + m-1);

    int sum = 0;



    if(n>=m){
        cout << 0 << endl;

    }
    else
    {
        REP(i,m-n){
            sum += l[i];
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;


struct node {
    long id;
    long parent_id;
    long num_children;
    long *children;
    long d;
};


node nodes[100000];
int main()
{
    long n;
    scanf("%ld", &n);

    for (long i = 0; i < n; i++) {
        nodes[i].d = 0;
        nodes[i].parent_id = -1;
    }

    for (long i = 0; i < n; i++) {
        long id;
        scanf("%ld", &id);
        nodes[id].id = id;
        scanf("%ld", &nodes[id].num_children);

        nodes[id].children = (long *)malloc(sizeof(node) * nodes[id].num_children);

        for (long j = 0; j < nodes[id].num_children; j++) {
            long cid;
            scanf("%ld", &cid);
            nodes[id].children[j] = cid;
            nodes[cid].parent_id = id;
        }
    }


    for (long i = 0; i < n; i++) {
        node tmp = nodes[i];
        long id = tmp.id;
        while(tmp.parent_id != -1) {
            nodes[id].d++;
            tmp = nodes[tmp.parent_id];
        }
    }

    for (long i = 0; i < n; i++) {
        node tmp = nodes[i];
        printf("node %ld: parent = %ld, depth = %ld, ", tmp.id, tmp.parent_id, tmp.d);
        if (tmp.parent_id == -1)
            printf("root, ");
        else if(tmp.num_children == 0)
            printf("leaf, ");
        else
            printf("internal node, ");
        printf("[");
        for (long j = 0; j < tmp.num_children; j++) {
            printf("%ld", tmp.children[j]);
            if (j != tmp.num_children - 1)
                printf(", ");
        }
        printf("]\n");
    }

    return 0;
}


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

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int s;
  cin >> s;
  if (s >= 0 && s <= 2) {
    cout << 0 << endl;
    return 0;
  }
  if (s >= 3 && s <= 5) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> dp(s + 1, 0);
  rep(i, 3) {
    dp[i] = 0;
    dp[i + 3] = 1;
  }
  rep(i, s + 1) {
    if (0 <= i && i <= 5) continue;
    dp[i] = (dp[i - 1] + dp[i - 3]) % inf;
  }
  cout << dp[s] << endl;
  return 0;
}

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

int main() {
	// your code goes here
	string A,B;
	cin >> A >>B;
	int ans=1;
	for(int i=0;i<3;i++){
		if(A[i]!=B[2-i]){ans=0;}
	}
	if(ans==1){cout << "YES"<<endl;}
	else{cout <<"NO"<<endl;}
	return 0;
}

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

using namespace std;

typedef long long ll;

ll bikkuri(ll n)
{
    if (n <= 0)
    {
        return 0;
    }
    return (n+1) * n / 2;
}

int main()
{
    ll N, K;
    cin >> N >> K;
    ll sum = 0;
    for (int k = K; k <= N + 1; k++)
    {
        sum += (bikkuri(N) - bikkuri(N - k) - bikkuri(k - 1) + 1);
        //cout << k << " : " << bikkuri(N) - bikkuri(N - k) - bikkuri(k - 1) + 1 << endl;
        sum = sum % (1000000000 + 7);
    }
    cout << sum << endl;
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename T>
struct fenwick_tree {
    int n;
    T ZERO;
    std::vector<T> data;
    fenwick_tree(int n, T ZERO = T()) : n(n), ZERO(ZERO), data(n + 1, ZERO) {}
    void add(int i, T x) { for (i++; i <= n; i += i & -i) { data[i] += x; }}
    T get_sum(int i) const {
        if (i > n) { i = n; }
        T ret = ZERO;
        for (; i > 0; i -= i & -i) { ret += data[i]; }
        return ret;
    }
    T get_sum(int l, int r) const {
        if (l < r) { return get_sum(r) - get_sum(l); }
        else { return ZERO; }
    }
};

int N, M;
int L[110000], R[1100000];
signed main() {
    cin >> N >> M;
    fenwick_tree<int> ft(N + 2);
    rep(i, M) {
        cin >> L[i] >> R[i];
        ft.add(L[i], 1), ft.add(R[i] + 1, -1);
    }
    int ans = 0;
    for (int i = 2; i <= N + 1; i++) { if (ft.get_sum(i) == M) { ans++; }}
    cout << ans << endl;
}

Measured memory_bytes: 2560
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'
#define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/


void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    int x = c >= b ? b-1 : c;
    cout << ((a*(x%b)) - (((a%b) * (x%b))%b))/b;

}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3652
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = input()[:-1]
print(min(max(map(len, s.split(a))) for a in s))






Measured memory_bytes: 3316
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=next[i])
#define repvc(i,vc) for(int i=0,_sz=vc.size();i<_sz;++i)
using namespace std;

const int INF=1<<30;
typedef long long ll;

inline int read()
{
	int ret=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

const int maxn=200000+10;

struct Node{
	int a,b;
	inline void input(){
		scanf("%d%d",&a,&b);
	}
	inline bool operator < (const Node &rhs)const{
		return b<rhs.b;
	}
}p[maxn];

int main()
{
	int n;cin>>n;
	rep(i,1,n) p[i].input();
	sort(p+1,p+n+1);
	int cur=0;
	rep(i,1,n)
	{
		if(cur+p[i].a > p[i].b) {
			cout<<"No"<<endl;
			return 0;
		}
		cur+=p[i].a;
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	char in[21],out[21];
	cin >>in;
	int len = strlen(in);
	for(int i=0; i<len; i++){
		out[len-i-1] = in[i];
	}
	out[len] = 0;
	cout <<out<<endl;
	return 0;
}

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

int main(){
  string str;
  while(cin >> str,str[0]-'0'){
    int a=0,b=0;
    for(int i=1; i<str.size(); ++i){
      if(str[i]=='A')++a;
      if(str[i]=='B')++b;
    }
    if(a>b){++a;}else{++b;}
    cout << a << " " << b << endl;
  }
  return 0;
}



Measured memory_bytes: 3144
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime


def prime_factorize(n):
    res = []
    for i in range(2, int(n**0.5)+1):
        if n % i != 0: continue
        ex = 0

        while (n % i == 0):
            ex += 1
            n //= i
        res.append((i, ex))
    if n != 1: res.append((n, 1))
    return res

A,B = imn()

pf = prime_factorize(gcd(A,B))

print(len(pf)+1)


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

using namespace std;

typedef long long int ll;

const ll MOD = 1e9+7;

int main() {
	int n;

	cin >> n;

	vector <ll> a(n, 0);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	vector <ll> b(n+1, 0);

	for (int i = n-1; i >= 0; i--) {
		b[i] = b[i+1] + a[i];
		b[i] = b[i] % MOD;
	}

	ll ans = 0;

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

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 6420
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var ai = Sarray();
            var ans = 0L;
            for (var i = 0; i < N; ++i)
            {
                var aite = ai[i] - 1;
                if (aite < i) continue;
                if (ai[aite] - 1 == i)
                    ++ans;
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 21344
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;
ll dp[1000005][2][2];
ll go(ll n,ll k,bool ok1,bool ok2){
    if(k == n && ok1 && ok2)
        return 1;
    if(k == n)
        return 0;
    if(dp[k][ok1][ok2] != -1)
        return dp[k][ok1][ok2];
    ll ans=0;
    for(ll i = 0; i <= 9; i++){
        if(i == 0)
            ans = (ans%mod + go(n,k+1,true,ok2)%mod)%mod;
        else if(i == 9)
            ans = (ans%mod + go(n,k+1,ok1,true)%mod)%mod;
        else
            ans = (ans%mod + go(n,k+1,ok1,ok2)%mod)%mod;
    }
    return dp[k][ok1][ok2] = ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    cout << go(n,0,false,false) << endl;
    return 0;
}



Measured memory_bytes: 128460
def have_eight_divisor_odd(n):
    have_eight_divisor_odd_count = 0
    for i in range(1, n+1):
        count = 0
        if i % 2 == 1:
            for j in range(1, i+1):
                if i % j == 0:
                    count += 1
        if count == 8:
            have_eight_divisor_odd_count += 1
    return have_eight_divisor_odd_count

N = int(input())
result = have_eight_divisor_odd(N)
print(result)    

Measured memory_bytes: 9168
n = gets.to_i
a= gets.chomp.split.map(&:to_i)
max = 0

(0...n).each do |i|
  (0...n).each do |j|
    if i != j
      if max < (a[i]-a[j]).abs
          max = (a[i]-a[j]).abs
      end
    end
  end
end

puts max

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> pt;
const int INF = 1 << 29;
const double EPS = 1e-10;

vector<int> plane[10000];

int main(){
  int AN, BN, R, x, y, res;
  while(cin >> AN >> BN >> R && (AN || BN || R)){ 
    res = 0;
    rep(i, 10000) plane[i].clear();
    rep(i, AN) {
      cin >> x >> y;
      plane[x].push_back(y);
    }
    rep(i, 10000) sort(plane[i].begin(), plane[i].end());
    
    rep(j, BN){
      cin >> x >> y;
      for(int i = max(0, x - 4 * R); i < min(x + 4 * R + 1, 10000); i++){
	int dx = abs(x - i);
	int dy = (int)sqrt((4*R * 4*R)-dx*dx);
	res += upper_bound(plane[i].begin(),plane[i].end(),y+dy)
	  - lower_bound(plane[i].begin(), plane[i].end(), y-dy);
      }
    }
    cout << res << endl;
  }
  return 0;
}
 

Measured memory_bytes: 2384
use std::cmp::min;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    let mut ans = n;

    for i in 0..n + 1 {
        let mut cc = 0;
        let mut t = i;
        while t > 0 {
            cc += t % 6;
            t /= 6;
        }
        t = n - i;
        while t > 0 {
            cc += t % 9;
            t /= 9;
        }
        ans = min(ans, cc);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string O,E;
  cin>>O>>E;
  REP(i,O.size()+E.size()){
    cout<<((i%2==0)?O[i/2]:E[i/2]);
  }
  cout<<endl;
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int res = 0;
	rep (i, n) {
	  int a;
	  cin >> a;
	  if (i % 2 == 0 && a % 2) res++;
	}
	cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3644
#include<stdio.h>
int A[2000010];
void CouSort(int n){
  int k=10000,i,j,B[2000010],C[10010];
  for(i=0;i<k;i++)
    C[i]=0;
  for(j=0;j<n;j++){
    C[A[j]]++;
  }
  /* C[i]にはiの出現数が記録されている*/
  for(i=1;i<k;i++)
    C[i] = C[i] + C[i-1];
  /* C[i]にはi以下の数の出現数が記録されている*/
  for(j=n-1;j>=0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i=1;i<n;i++)
    printf("%d ",B[i]);
  printf("%d\n",B[n]);
}

main(){
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  CouSort(n);
  return 0;
}

Measured memory_bytes: 16264
def main():
    a = []
    for _ in range(28):
        a.append(int(input()))
    a.sort()

    ans = []
    num = [i for i in range(1, 31)]
    for x in range(30):
        if num[x] not in a:
            ans.append(num[x])

    for x in range(2):
        print(ans[x])

if __name__ == "__main__":
    main()

Measured memory_bytes: 7788
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INS(x) string (s); cin >> s
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()


ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main () {
  ll a, b, c, d;
  cin>>a;
  cin>>b;
  cin>>c;
  cin>>d;
  ll lcm;
  lcm=c*d/euclidean_gcd(c, d);
  a--;
  cout<< b-a-(b/c-a/c)-(b/d-a/d)+(b/lcm-a/lcm);
}


Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
h=list(map(int,input().split()))
AA=[]
for i in range(N):
  a=T-h[i]*0.006-A
  if a<0:
    a*=-1
  AA.append(a)
print(AA.index(min(AA))+1)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

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

  if(n%2){
    cout << n/2 << endl;
  }else{
    cout << (n-1)/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.split("\n");

const n = lines[0].split(" ").map(Number)

let nmax = Math.max.apply(null,n);
let nmin = Math.min.apply(null,n);

while(nmax%nmin !== 0){
    let t = nmax%nmin
    nmax = nmin
    nmin = t
}
console.log(nmin)


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

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			int a = int.Parse(Console.ReadLine());

			
			Console.WriteLine(a==3||a==5||a==7 ? "YES" : "NO");
		}
	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int h,w,k;
int pre[11][1001],ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>h>>w>>k;
    for (int i=1;i<=h;i++){
        for (int j=1;j<=w;j++){
            pre[i][j]=pre[i-1][j];
            char x;
            cin>>x;
            if (x=='1'){
                pre[i][j]++;
            }
        }
    }
    ans=1e9;
    for (int bit=0;bit<(1<<h);bit++){
        if (!(bit&(1<<0))) continue;
        int cur=0;
        vector<int> cut;
        cut.pb(0);
        for (int i=1;i<h;i++){
            if (bit&(1<<i)){
                cur++;
                cut.pb(i);
            }
        }
        cut.pb(h);
        bool works=true;
        for (int j=1;j<=w;j++){
            for (int i=1;i<cut.size();i++){
                if (pre[cut[i]][j]-pre[cut[i-1]][j]>k){
                    works=false;
                    break;
                }
            }
        }
        if (!works) continue;
        int num[12];
        memset(num,0,sizeof(num));
        for (int j=1;j<=w;j++){
            bool reset=false;
            for (int i=1;i<cut.size();i++){
                num[i]+=pre[cut[i]][j]-pre[cut[i-1]][j];
                if (num[i]>k) reset=true;
            }
            if (reset){
                cur++;
                for (int i=1;i<cut.size();i++){
                    num[i]=pre[cut[i]][j]-pre[cut[i-1]][j];
                }
            }
        }
        ans=min(ans,cur);
    }
    cout<<ans;
}

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

using namespace std;

int main()
{
    // オリジナルの回答
    int num, m ,c;
    cin >> num >> m >> c;

    vector<int> b;
    int input;
    for (int i = 0; i < m; i++) {
        cin >> input;
        b.push_back(input);
    }

    vector<vector<int>> a;
    int input2;
    for (int i = 0; i < num; i++) {
        vector<int> temp;
        for (int j = 0; j < m; j++) {
            cin >> input2;
            temp.push_back(input2);
        }

        a.push_back(std::move(temp));
    }

    int correctNum = 0;
    for (const auto v : a) {
        int sum = 0;
        for (int i = 0; i < m; i++) {
            sum += v[i] * b[i];
        }

        if (sum + c > 0) {
            correctNum++;
        }
    }

    cout << correctNum << endl;

    return 0;
}


Measured memory_bytes: 256
while 1:
	n,k = map(int,raw_input().split())
	s = [0]*(n+1)
	if n == 0: break
	c = sorted([int(raw_input()) for i in range(k)])
	have0 = 1 if c[0] == 0 else 0
	jump = 0
	for i in c[have0:]:
		s[i] = s[i-1] + 1
		if have0 and s[i-1] == 0 and s[i-2] > 0:
			s[i] += s[i-2] + 1 - jump
			jump = s[i-2] + 1
		if s[i-1] == 0 and s[i-2] == 0:
			jump = 0
	print max(s)

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N, C;
    cin >> N >> C;
    vector<VI> grid(N, VI(N));
    vector<VI> D(C, VI(C));
    REP(i, C) {
        REP(j, C) cin >> D[i][j];
    }
    REP(i, N) {
        REP(j, N) {
            cin >> grid[i][j];
            grid[i][j]--;
        }
    }
    vector<unordered_map<int, int>> V(3); 
    REP(i, N) {
        REP(j, N) {
            int k = (i + j) % 3;
            V[k][grid[i][j]]++;
        }
    }
    int ans = INT_MAX;
    FOR(i, 0, C - 1) {
        FOR(j, i + 1, C - 1) {
            FOR(k, j + 1, C - 1) {
                VI A{i, j, k};
                do {
                    int sum = 0;
                    for (int l = 0; l < 3; l++) {
                        for (auto p : V[l]) {
                            sum += D[p.first][A[l]] * p.second;
                        }
                    }
                    ans = min(ans, sum);
                } while (next_permutation(all(A)));
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 4223352036854775007
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=10005;
const int NN=2005;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    str s;
    cin >> s;
    if (s[s.size()-1]=='s'){
        s+='e';
    }
    s+='s';
    cout << s << E;
    r0;
}
/*








*/


Measured memory_bytes: 3660
def main():
    n,m,x = map(int,input().split())
    c = []
    a = []
    for _ in range(n):
        ca = [int(v) for v in input().split()]
        c.append(ca[0])
        a.append(ca[1:])
    
    INTHIGH = 1<<32
    pricemin = INTHIGH
    for i in range(1<<n):
        sm = [0]*m
        sc = 0
        for j in range(n):
            if i & 1<<j:
                sc += c[j]
                for k in range(m):
                    sm[k] += a[j][k]
                if min(sm)>=x:
                    pricemin = min(pricemin, sc)
                    break

    print(pricemin if pricemin<INTHIGH else -1) 

main()

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

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

int main(){
  int n;
  cin >>n;
  
  map<string,int> M;

  int syurui=0;
  for(int i=0; i<n; i++){
    string str;
    cin >> str;

    if(! M.count(str)){
      M.insert(make_pair(str,1));
    } else{
      M.at(str)++;
    }
  }

  cout << M.size() << endl;
  return 0;
}

Measured memory_bytes: 19228
I=input;n=int(I());s='%d\n';i,j=0,n-1;a,b=I(s%i),I(s%j)
while 1:
 k=(j+i+1)//2;c=I(s%k)
 if(k-i)%2==(a==c):j=k
 else:a=c;i=k

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

# define ll long long 
# define VI vector<int>
# define VLL vector<ll>
# define PII pair<int,int> 
#define mp make_pair
#define pb push_back
# define PI acos(-1)
# define double long double
const int MxN = 10005 ; 
# define FOR(i,a,b) for(int i = a ; i < b ; ++i)
 
/* VARIABLES */

int n , h ;
vector<PII> s(MxN) ; 

/* END OF VARIABLES */



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	
	cin >> n >> h ; 
	int a ; 
	int mx = 0 ; 
	VI array(n) ; 
	FOR(i,0,n) {
		cin >>a >> array[i]; 
		mx = max(a,mx) ; 
	}
	VI tmp ; 
	FOR(i,0,n) {
		if(array[i] > mx)
			tmp.pb(array[i]) ; 
	}

	sort(tmp.begin(), tmp.end() , greater<int> ()) ;
	int cnt = 0 ; 
	for(int x : tmp) {
		h -= x ; 
		cnt++;
		if(h <= 0 ) {
			cout << cnt ;
			return 0 ; 
		}
	} 

	cout << cnt + (h + mx -1 )/mx ; 

	return 0 ; 
}



Measured memory_bytes: 4324