akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll H, W;
    cin >> H >> W;
    vector<vector<bool>> S;
    vector<bool> wall;
    REP(i, H+2) wall.push_back(false);
    S.push_back(wall);
    REP(h, H) {
        string s;
        cin >> s;
        vector<bool> t;
        t.push_back(false);
        REP(w, W) {
            if (s[w] == '#') t.push_back(true);
            else t.push_back(false);
        }
        t.push_back(false);
        S.push_back(t);
    }
    S.push_back(wall);

    FOR(h, 1, H+1) {
        FOR(w, 1, W+1) {
            if (S[h][w] == true) cout << "#";
            else {
                ll bomb = 0;
                FOR(i, -1, 2) {
                    FOR(j, -1, 2) {
                        if (S[h+i][w+j] == true) bomb++;
                    }
                }
                cout << bomb;
            }
        }
        cout << "\n";
    }
}


Measured memory_bytes: 256
#include <cstdio>

int main (){
    int p,q,r;
    scanf("%d %d %d",&p,&q,&r);
    if(p>=q&&p>=r) printf("%d",q+r);
    else if(q>=p&&q>=r) printf("%d",p+r);
    else printf("%d",p+q);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
 int A, B, K;
 cin >> A >> B >> K;
  
 vector<int> C;
  
 for (int i =1; i<=min(A,B) ; i++){
  if (A%i==0 && B%i==0){
   C.push_back(i);
  }
 } 
  
  reverse(C.begin(), C.end());
  cout << C.at(K-1) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,n,a,sum=0;
    cin>>h>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        sum+=a;
    }
    if (sum>=h) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string str,str2;

  while(  cin >> str >> str2,(str[0] - '0')+(str2[0] - '0') ){
    int hit = 0,brow = 0;
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == str2[i])hit++;
    }
    for(int i = 0 ; i < 4 ; i++ ){
      for(int j = 0 ; j < 4 ; j++ ){
	if(str[i] == str2[j])brow++;
      }
    }
    cout << hit << " " << brow - hit << endl;
}
  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;

  ll max1 = 0;
  ll curr = 0;
  for (ll i = 0; i < s.length(); i++) {
    if (s[i] == 'R')
      curr++;
    else
      curr = 0;
    max1 = max(max1, curr);
  }

  cout << max1 << en;

  return 0;
}

Measured memory_bytes: 3644
N = int(input())
S = input()

num = 0
ans = N
for i in range(1, N):
    if S[i] == "E":
        num += 1
ans = num
for j in range(1, N):
    if S[j - 1] == "W":
        num += 1
    if S[j] == "E":
        num -= 1
    if num < ans:
        ans = num
print(ans)
    

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#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 {
#ifndef ONLINE_JUDGE
~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__) << "] "
typedef long long ll;
int main() {
	int x;
	cin >> x;
	cout<<!x;
}


Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <math.h>

int main(void);
unsigned int gcd(unsigned int x, unsigned int y);
unsigned int lcm(unsigned int x, unsigned int y);

int main(){
	int dataset_count = 0;
	unsigned int first_num = 0;
	unsigned int second_num = 0;

	std::vector<unsigned int> first_num_vector;
	std::vector<unsigned int> second_num_vector;

	//while (dataset_count < 2){
		//std::cin >> first_num >> second_num;
	while ((std::cin >> first_num >> second_num)/* || (dataset_count < 50)*/){
		dataset_count++;
		first_num_vector.push_back(first_num);
		second_num_vector.push_back(second_num);
	}
	for (unsigned int i = 0; i < first_num_vector.size(); i++){
		std::cout << gcd(first_num_vector[i], second_num_vector[i]) << " " << lcm(first_num_vector[i], second_num_vector[i]) << std::endl;
	}
	return 0;
}


// 最大公約数を求める関数
unsigned int gcd(unsigned int x, unsigned int y)
{
	unsigned int r;

	if (x == 0 || y == 0)  // 引数チェック
	{
		return 0;
	}

	// ユーグリッドの互除法
	while ((r = x % y) != 0) // yで割り切れるまでループ
	{
		x = y;
		y = r;
	}
	return y;
}

//	最小公倍数を求める関数
unsigned int lcm(unsigned int x, unsigned int y)
{
	unsigned int rtn;

	if (x == 0 || y == 0)  // 引数チェック
	{
		return 0;
	}

	rtn = (x / gcd(x, y)) * (y / gcd(x, y));

	return rtn * gcd(x, y);
}


Measured memory_bytes: 3068
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
int dp1[6005][6005];
int dp2[6005][6005];
int w[6005],v[6005];
int n,t;
int max(int x,int y)
{
    if(x>=y)
        return x;
    else return y;
}
int main()
{
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&w[i],&v[i]);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=t-1;j++)
        {
            dp1[i][j]=dp1[i-1][j];
            if(j>=w[i])
                dp1[i][j] = max(dp1[i][j],dp1[i-1][j - w[i]] + v[i]);
        }
    }
    for(int i=n;i>=1;i--)
    {
        for(int j=1;j<=t-1;j++)
        {
            dp2[i][j]=dp2[i+1][j];
            if(j>=w[i])
                dp2[i][j]=max(dp2[i][j], dp2[i+1][j - w[i]] + v[i]);

        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=t-1;j++)
        {
            ans=max(ans, dp1[i-1][j] + dp2[i+1][t-1-j] + v[i]);
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 145024
#include<bits/stdc++.h>
using namespace std;
const int p=1000000007,N=100005;
int n,i,a[N];
long long frac[N],inv[N],invf[N],invs[N],fst[N],ans[N],Ans;
int main(){
  scanf("%d",&n);
  for(i=1;i<=n;++i)scanf("%d",&a[i]);
  frac[0]=1;
  for(i=1;i<=n;++i)frac[i]=frac[i-1]*i%p;
  inv[1]=invf[1]=1;
  for(i=2;i<=n;++i){
    inv[i]=(-(p/i)*inv[p%i]%p+p)%p;
    invs[i]=(invs[i-1]+inv[i])%p;
    invf[i]=invf[i-1]*inv[i]%p;
  }
  fst[1]=1;
  for(i=2;i<=n;++i)fst[i]=(fst[i-1]*i+frac[i-1])%p;
  //for(i=1;i<=n;++i)printf("fst[%d] = %lld\n",i,fst[i]);
  for(i=1;i<=n;++i)ans[i]=(fst[i]*invf[i]+invs[n-i+1])%p*frac[n]%p;
  for(i=1;i<=n;++i)Ans=(Ans+ans[i]*a[i])%p;
  //for(i=1;i<=n;++i)printf("ans[%d] = %lld\n",i,ans[i]);
  printf("%lld",Ans);
}


Measured memory_bytes: 5376
import java.util.Scanner;

class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System.in);
      int a = stdIn.nextInt();
      int b = stdIn.nextInt();
      int c = a*b;
      int d = a+a+b+b;
      System.out.println( c + " " + d );
   }
}

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

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i <= (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 

const double PI =  3.141592653589793;

int main(){
	IO;
	string s,t;
	cin>>s>>t;
	s+=t[t.length()-1];
	(s==t)?cout<<"Yes\n":cout<<"No\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define d1(x) cout<<#x<<" "<<x<<endl;
#define d2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define d2i(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
#define all(v) v.begin(),v.end()
#define pm(v,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<v[i][j]<<" ";cout<<endl;}
///////////////////////////////////////////
/// choose such no such that every 5 sum of nu mber is divisible by 5

void solve(){
  ll n,m;
  cin>>n>>m;
  vll a(n),b(m);
  mat v(n+1,vll(m+1));
  mat sm(n+1,vll(m+1));
  for(ll &x:a)
  cin>>x;
  for(ll &x:b)
  cin>>x;
  v[0][0]=1;
  fr(i,0,m+1)
  sm[0][i]=1;
  fr(i,0,n+1)
  sm[i][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){

      if(a[i]==b[j]){
        v[i+1][j+1]=sm[i][j];
      }
      else v[i+1][j+1]=0;
      sm[i+1][j+1]=(sm[i+1][j]+sm[i][j+1]-sm[i][j]+mod)%mod;
      sm[i+1][j+1]=(sm[i+1][j+1]+v[i+1][j+1])%mod;
    }
  }
  //pm(v,n+1,m+1);
  //pm(sm,n+1,m+1);
  
 //if(a[n-1]==b[m-1])
 //cout<<v[n][m];
  cout<<sm[n][m]%mod;
}




int main(){
    ll t=1;
  //cin>>t;
    while(t--){
        solve();
        cout<<endl;
    
    }
    return 0;
}

Measured memory_bytes: 63232
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0
C = []
D = []
for i in range(n):
    if B[i] > A[i]:
        C.append(B[i] - A[i])
        ans += 1
    elif A[i] > B[i]:
        D.append(A[i] - B[i])

s = sum(C)
# print(s, C, D)

D.sort(reverse=True)
i = 0
while i < len(D) and s > 0:
    s -= D[i]
    ans += 1
    i += 1
# print(s)
if s > 0:
    ans = -1
print(ans)

Measured memory_bytes: 76080
#include <bits/stdc++.h>
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;

#define M 2005
int n;
char s[M];
int a[M][M],f[M][M],l[M][M],r[M][M];

int main () {
//freopen("a.in","r",stdin);
//freopen("zj.out","w",stdout);
	scanf("%d",&n);
	for1(1,n,i) {
		scanf("%s",s+1);
		for1(1,n,j) a[i][j]= s[j]=='#'?0:s[j]-'0';
	}
	
	ll ans=0;
	FOR2(n,1,i) FOR2(n,1,j) { 
		if(a[i][j]) {
			bool t[2]={a[i+1][j],a[i][j+1]};
			if(!(t[0]|t[1])) {
				l[i][j]=r[i][j]=j;
				for1(i+1,n,k) l[k][j]=n+1,r[k][j]=0;
			}
			else if(t[0]&&!t[1]) {
				l[i][j]=r[i][j]=j;
				f[i][j]=f[i+1][j];
			}
			else if(!t[0]&&t[1]) {
				f[i][j]=f[i][j+1];
				l[i][j]=j,r[i][j]=r[i][j+1];
				for1(i+1,n,k) l[k][j]=l[k][j+1],r[k][j]=r[k][j+1];
			}
			else {
				int tot=f[i+1][j]+f[i][j+1];
				l[i][j]=j,r[i][j]=r[i][j+1];
				
				int las_r=0;		
				for1(i+1,n,k) {
					if(l[k][j+1]>r[k][j+1]) break;
			//	if(i==2&&j==1) cout<<"-_-"<<las_r<<" "<<k<<" "<<l[k][j+1]<<endl;
					if(l[k][j+1]<=r[k][j]&&l[k][j+1]>las_r) tot-=f[k][l[k][j+1]];
					las_r=r[k][j];
					//if(l[k][j]>r[k][j]) l[k][j]=l[k][j+1],r[k][j]=r[k][j+1];
					l[k][j]=min(l[k][j],l[k][j+1]);
					r[k][j]=max(r[k][j],r[k][j+1]);
				}
				f[i][j]=tot;
			}
		}
		else l[i][j]=n+1,r[i][j]=0;
		ans+=a[i][j]*f[i][j];
		f[i][j]+=a[i][j];
	}
	/*
	for1(1,n,i) {
		for1(1,n,j) cout<<f[i][j]<<" ";
		cout<<endl;
	}
	*/
	cout<<ans<<endl;
}

Measured memory_bytes: 20224
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

int dfs(int cur, vector<vector<int>>& g) {
	vector<int> a;
	for (auto to : g[cur]) { a.emplace_back(dfs(to, g)); }
	if(a.empty()) return 1;
	sort(all(a), greater<int>());

	int res = 0;
	rep(i, a.size()) { res = max(res, a[i] + i); }

	//show(cur)
	//show(res + 1)
	//cout << a << endl;
	return res + 1;
}

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

	vector<vector<int>> g(n);
	rep(i, n - 1) {
		int a;
		cin >> a;
		a--;
		g[a].emplace_back(i+1);
	}

	cout << dfs(0, g) - 1 << endl;
}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1,
    x=-x;
  }
  while(x){
    f[s++]=x%10,
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
const int SZ=100001;
bool prime[SZ];
int sum[SZ];
void init(){
  int i;
  for(i=2;i<SZ;i++){
    prime[i] = true;
  }
  for(i=2;i<SZ;i++){
    if (!prime[i]){
      continue;
    }
    for (int j = i+i; j < SZ; j += i){
      prime[j] = false;
    }
  }
  for(i=0;i<SZ;i++){
    if (i%2 == 0){
      continue;
    }
    if (!prime[i]){
      continue;
    }
    if (!prime[i/2+1]){
      continue;
    }
    sum[i] = 1;
  }
  {
    int lhxun_Zi;
    for(lhxun_Zi=1;lhxun_Zi<(SZ-1) + 1;lhxun_Zi++){
      sum[lhxun_Zi] += sum[lhxun_Zi - (1) + (0)];
    }
  }
}
int main(){
  int i, l, q, r;
  init();
  rd(q);
  for(i=0;i<q;i++){
    rd(l);
    rd(r);
    wt_L(sum[r]-sum[l-1]);
    putchar_unlocked('\n');
  }
  return 0;
}
// cLay varsion 20170910-1

// --- original code ---
// const int SZ = 100001;
// inplace_L bool prime[SZ];
// inplace_L int sum[SZ];
// void init() {
//   rep(i,2,SZ) prime[i] = true;
//   rep(i,2,SZ) {
//     if (!prime[i]) continue;
//     for (int j = i+i; j < SZ; j += i) prime[j] = false;
//   }
//   rep(i,SZ) {
//     if (i%2 == 0) continue;
//     if (!prime[i]) continue;
//     if (!prime[i/2+1]) continue;
//     sum[i] = 1;
//   }
//   sum[1..SZ-1] += sum[0..];
// }
// 
// {
//   init();
//   int q, l, r;
//   rd(q);
//   rep(i,q) {
//     rd(l,r);
//     wt(sum[r]-sum[l-1]);
//   }
// }

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,k;
 cin>>n>>k;
 int a[n];
 int i;
 for(i=0;i<n;i++)
 cin>>a[i];
 int dp[k+1];
 memset(dp,0,sizeof(dp));
 for(i=0;i<=k;i++)
 {
 	for(int j=0;j<n;j++)
 	{
 	  if(i>=a[j] && dp[i-a[j]]==0)
 	  dp[i]=1;
 	}
 }
 cout<<(dp[k]==1?"First":"Second")<<endl;
 return 0;
}


Measured memory_bytes: 640
n,m,c=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
  tmp=0
  a=list(map(int,input().split()))
  for j in range(m):
    tmp+=b[j]*a[j]
  if tmp>-c:
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    vector<pair<ll,ll>> X(N);
    REP(i,N){
        cin >> X[i].first;
        cin >> X[i].second;
    }
    sort(all(X));
    int count = 0;
    int where = -1e9;
    REP(i,N){
        if(where <= X[i].first-X[i].second){
            where = X[i].first+X[i].second;
            count++;
        }else if(where >= X[i].first+X[i].second){
            where = X[i].first+X[i].second;
        }
    }
    cout <<count<< "\n";
}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

stack<pp> st;
vector<int> dp,a,d,ans;
vector<vector<int>> path;
int n,cd,idx,y;

int bs(int num){
    int l=0,r=n,ce;
    while(l!=r){
        ce=(l+r)/2;
        if(dp[ce]>=num) r=ce;
        else l=ce+1;
    }
    return l;
}

void dfs(int x,int per){
    for(auto to:path[x])
    if(to!=per) d[to]=d[x]+1;
    while(cd>=d[x]){
        cd--;
        tie(idx,y)=st.top();
        st.pop();
        dp[idx]=y;
    }
    idx=bs(a[x]);
    st.push(mk(idx,dp[idx]));
    dp[idx]=a[x]; cd++;
    ans[x]=bs(inf);
    for(auto to:path[x]){
        if(to!=per) dfs(to,x);
    }
}

int main(){
    cin>>n; 
    dp.assign(n+1,inf);
    a.assign(n,0);
    d.assign(n,0);
    ans.assign(n,0);
    path.assign(n,vector<int>(0));
    rep(i,n) cin>>a[i];
    rep(i,n-1){
        int u,v; cin>>u>>v;
        u--; v--;
        path[u].push_back(v);
        path[v].push_back(u);
    }
    cd=0; d[0]=1;
    dfs(0,-1);
    rep(i,n) printf("%d\n",ans[i]);
}

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

int main() {
  int A, B, C, X; cin >> A >> B >> C >> X;
  int ans = 0;
  rep(i, A+1) {
    rep(j, B+1) {
      rep(k, C+1) {
        if (i * 500 + j * 100 + k * 50 == X) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

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

// constant
// -----------------------------------------------------------------------------
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    ll N; cin >> N;
    vector<ll> A(N);

    ll d = 0;
    REP(i, N) {
        cin >> A[i];
        if(i) d += A[i];
        else d -= A[i];
    }

    ll ans = abs(d);
    FOR(i, 1, N - 1) {
        d -= A[i] * 2;
        ans = min(ans, abs(d));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4760
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

bool isprime(int x) {
	if (x == 2) {
		return true;
	}
	if (x < 2 || x % 2 == 0) {
		return false;
	}
	int i = 3;
	for (i; i <= sqrt(x); i+=2) {
		if (x%i == 0) {
			return false;
		}
	}
	return true;
}


int main(void) {
	int n;
	int a[10001];
	int count = 0;

	cin >> n;
	FOR(i, 1, n) {
		cin >> a[i];
		if (isprime(a[i])) {
			count++;
		}
	}
	
	cout << count << endl;


	return 0;
}


Measured memory_bytes: 3120
n,m = map(int,input().split())
xyz = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(8):
    s = [0 for j in range(n)]
    for j in range(n):
        a = 0
        for k in range(3):
            if i>>k&1:
                a += xyz[j][k]
            else:
                a -= xyz[j][k]
        s[j] = a
    s.sort()
    ans = max(ans,sum(s[n-m:]))
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main()
{
	double w;
	double h;
	double x;
	double y;

	cin >> w >> h >> x >> y;
	if(x==w/2&&(int)w%2==0&&y==h/2&&(int)h%2==0)
		cout << w * h / 2 << " " << 1 << endl;
	else
	{
		cout << w * h / 2 << " " << 0 << endl;
	}
	
}

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

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

int main() {
    int N,X,Y;
	cin >> N >> X >> Y;
	X = X-1;
	Y = Y-1;
	vector<int> cnt(N-1);
	for(int k=0;k<N-1;k++)cnt[k]=0;
	for(int i=0;i<N-1;i++){
		for(int j=i+1;j<N;j++){
			int dist = min(abs(j-i),abs(X-i)+1+abs(j-Y));
			cnt[dist-1]++;
		}
	}

	for(int k=0;k<N-1;k++){
		cout<<cnt[k]<<endl;
	}

    return 0;
}



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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

ll F(ll k, ll l, ll m) {
  ll max = std::max(k, l);
  ll min = k > l ? m : std::min(k, m);
  return max - min;
}

int main() {

  ll H, W; cin >> H >> W;
  ll ans = 1e18;
  REP(i, 1, H) {
    auto k = i * W;
    auto l = (H - i) * (W - W / 2);
    auto m = (H - i) * (W / 2);
    ans = std::min(ans, F(k, l, m));
  }

  REP(i, 1, W) {
    auto k = i * H;
    auto l = (W - i) * (H - H / 2);
    auto m = (W - i) * (H / 2);
    ans = std::min(ans, F(k, l, m));
  }

  REP(i, 1, H) {
    auto k = i * W;
    auto l = ((H - i) - ((H - i) / 2)) * W;
    auto m = (H - i) / 2 * W;
    ans = std::min(ans, F(k, l, m));
  }

  REP(i, 1, W) {
    auto k = i * H;
    auto l = ((W - i) - ((W - i) / 2)) * H;
    auto m = (W - i) / 2 * H;
    ans = std::min(ans, F(k, l, m));
  }

  std::cout << ans << "\n";
  
  return 0;
}

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

using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H,vector<char>(W,'x'));
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> A[i][j];
    }
  }
  
  for(int i = 0; i < H+2; i++){
    for(int j = 0; j < W+2; j++){
      if(i == 0 || j == 0 || i == H+1 || j == W+1) cout << '#';
      else cout << A[i-1][j-1];
    }
    cout << endl;
  }
}

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

#define INF 1E18


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

    ll ans = k*pow(k-1,n-1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll n, a[N], ans, ma, mx[N];
int main()
{
    std::ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		mx[i] = max(mx[i - 1], a[i - 1]);
	}
	for(int i = 1; i <= n; i++) ans += max(0LL, mx[i] - a[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6776
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
    int A[3];

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

    sort(A, A + 3);

    int ans = A[0] + A[1];

    cout << ans << endl;

    return 0;
}

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

int main(){
  ll n,k;cin>>n>>k;
  int bfr[200001],aft[200001];
  
  for(int i=1;i<=n;i++) cin>>bfr[i];

  int now=1;
  while(k>0){
    if(k%2) now=bfr[now];
    for(int i=1;i<=n;i++) aft[i]=bfr[bfr[i]];
    for(int i=1;i<=n;i++) bfr[i]=aft[i];
    k/=2;
  }
  cout<<now;
}

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

public class Main {

	private static void solve(){
		//Implement solution here.
		int n = ni();
		String[] s = new String[n];
		int[] t = new int[n];
		for(int i = 0; i < n; i++) {
			s[i] = next();
			t[i] = ni();
		}
		String x = next();
		int result = 0;
		boolean sleep = false;
		for(int i = 0; i < n; i++) {
			if(sleep)result += t[i];
			if(x.equals(s[i])) sleep = true;
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 22740
I=lambda:list(map(int,input().split()))
n,k=I()
l=I()
low=1
high=max(l)
while low<high:
	mid=(low+high)//2
	temp=0
	for i in l:
		temp+=(i//mid)-(i%mid==0)
	if temp>k:
		low=mid+1
	else:
		high=mid
print(low)



Measured memory_bytes: 93828
# frozen_string_literal: true

def z_algorithm(s)
  n = s.size
  return [] if n == 0

  z = [0]*n
  z[0] = n
  i, j = 1, 0
  while i < n
    j += 1 while i+j<n && s[j]==s[i+j]
    z[i] = j
    if j == 0 then
      i += 1
      next
    end
    k = 1
    while i+k<n && k+z[k]<j
      z[i+k] = z[k]
      k += 1
    end
    i += k
    j -= k
  end
  return z
end

s, t = $<.map &:chomp

ss = s+s
ss << s while ss.size < t.size*2
z = z_algorithm(t+ss)[t.size,s.size].map{ |z| z >= t.size }

vis = [false]*s.size

ans = (0 ... s.size).map{ |u|
  next if vis[u]
  vis[u] = true
  now = u
  cnt = 0
  while z[now]
    now = (now+t.size) % s.size
    vis[now] = true
    cnt += 1
    break if now == u
  end
  now==u && cnt.nonzero? ? 10**9 : cnt
}.compact.max

ans = -1 if ans >= 10**9
puts ans


Measured memory_bytes: 50756
#include<iostream>
#include<vector>
#include <memory>
using namespace std;

class MinMaxSumSolver {
    vector<int>A;
    int N;
public:
       long int Max(){
        long int m=-1000000;
        for(int i=0;i<A.size();i++)
        {
        if(A[i]>m)
            m=A[i];
        }
        return m;
    }


        long int Min(){
            int m=1000000;
            for(int i=0;i<A.size();i++)
                {
                    if(A[i]<m)
                    m=A[i];
                    }
            return m;
        }

       long long sum()
        {
            long long m=0;
            for(int i=0;i<A.size();i++)
                m+=A[i];
            return m;
        }

        void solve()
        {
            cin>>N;
            for(int i=0;i<N;i++)
                {
                    int x;
                    cin>>x;
                    A.push_back(x);
                }
            cout<<Min()<<' '<<Max()<<' '<<sum()<<endl;
        }
};

int main()
{
    auto_ptr<MinMaxSumSolver>solver(new MinMaxSumSolver());
    solver->solve();
}




Measured memory_bytes: 3212
//ABC144_B問題
#include <stdio.h>
int main(int argc, char const *argv[]) {
    int x;
    int flag = 0;
    scanf("%d",&x);

    for(int i=1;i<10;i++){
        for (int j = 1; j < 10; j++) {
            if(x== i*j) flag = 1;
        }
    }

    if(flag==1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  ll a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  if((abs(a-b) <= (v-w)*t) && (v > w)) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int d,t,s;
    cin>>d>>t>>s;
    if((s*t)>=d)
       cout<<"Yes\n";
    else
       cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

int gcd(int a, int b){
    if (b == 0) {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

void solve(){
    string str;
    cin >> str;

    int ans, S;
    ans = S = 0;

    for (int i = 0; i < (int)str.size(); i++) {
        if (str[i] == 'T') {
            if (S > 0) {
                S--;
            }else{
                ans++;
            }
        }else{
            S++;
        }
    }

    cout << ans + S << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll D,c[30],s[400][30],t[400],ans,last[30];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>D;
    rep1(i,26) cin>>c[i];
    rep1(i,D)rep1(j,26) cin>>s[i][j];
    rep1(i,D) cin>>t[i];
    rep1(i,D){
        ans+=s[i][t[i]];
        last[t[i]]=i;
        rep1(j,26) ans-=c[j]*(i-last[j]);
        cout<<ans<<"\n";
    }
}

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

int main() {
  string S;
  int c = 700;
  cin >> S;
  
  if (S.at(0) == 'o') c += 100;
  if (S.at(1) == 'o') c += 100;
  if (S.at(2) == 'o') c += 100;
  
  cout << c << endl;
}

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

int main() {
	long long s;
	cin >> s;
	int i = 0;
	if(s==1||s==2){
		cout << 4 << endl;
		return 0;
	}
	while(true){
		s = s%2==0?s/2:s*3+1;
		if(s==1){
			cout << i+3 << endl;
			return 0;
		}
		i++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m; 
  cin >>n>>m;
  vector <int> tabemono(m+1);
  for(int i=0;i<=m;i++){
    tabemono[i]=0;
  }
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int a;
      cin>>a;
      tabemono[a]++;
    }
  }
  int kotae=0;
  for(int i=1;i<=m;i++){
    if(tabemono[i]==n)kotae++;
  }
  cout<<kotae<<endl; 
  return 0;
}

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

int main(){
	string b;
	cin>>b;
	
	if(b=="A")
		cout<<"T"<<endl;
	
	if(b=="C")
		cout<<"G"<<endl;
	
	if(b=="G")
		cout<<"C"<<endl;
	
	if(b=="T")
		cout<<"A"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int32 i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int32 i = (b) - 1; i >= (a); --i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define C(x) cout << #x << ":" << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;
inline uint32 MIN(uint32 a, uint32 b){
	return a > b ? b : a;
}

int main() {
	uint32 n;
	uint32 s;
	cin >> n >> s;
	vector<uint32> a(n + 1);
	a[n] = 0;
	rep(i, 0, n)
		cin >> a[i];
	uint32 ans = n + 1;
	uint32 now = 0;
	uint32 l = 0, r = 0;
	while (r <= n){
		if (now < s){
			now += a[r++];
		}
		else{
			ans = MIN(ans, r-l);
			now -= a[l++];
		}
	}
	if (ans == n + 1) ans = 0;
	printf("%u\n", ans);
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main{ 
        public static void main(String[] args){
            int a[];
            int i=0,count=1;
            a = new int[100000];
            a[0]=1;
                Scanner n = new Scanner(System.in);
                while(a[i] != 0){
                    i++;
                     a[i] = n.nextInt();
                     if(a[i]!=0){
                         count+=1;
                    }
                }
                i=1;
                while(count>i){
                    System.out.println("Case " + i + ": " + a[i]);
                    i++;
                }
        }
    }


Measured memory_bytes: 42796
#include <bits/stdc++.h>
using namespace std;
 
int d[1123];
int c[1123];
 
int memo[11234];
 
int max_ans = 1e8 + 55;
int h, n;
 
int solve(int h){
	if(h <= 0) return 0;
    int & ret = memo[h];
  	if(ret != -1) return ret;
    ret =  c[0] + solve(h - d[0] );
    for(int i = 1; i < n; i++){
    	ret = min(ret, c[i] + solve(h - d[i]) );
    }
  	return ret;
}
 
int main(){
  scanf("%d %d", &h, &n);
  for(int i = 0; i < n; i++){
  	scanf("%d %d", d + i, c + i);
  }
  memset(memo, -1, sizeof memo);
  printf("%d\n", solve(h));
}

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

void solver() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<vector<int> > s(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    string ss;
    cin >> ss;
    for(int j = 0; j < w; j++) {
      if (ss[j] == '1') s[i][j] = 1;
      else s[i][j] = 0;
    }
  }

  int ans_min = h * w;
  for(int bit = 0; bit < (1 << h-1); bit++) {
    int ans = 0;
    vector<vector<int> > sblock_sums;
    int prev_i = -1;
    bool is_impossible = false;
    for(int i = 0; i < h - 1; i++) {
      if (bit & (1 << i)) {
        vector<int> sblock_sum(w);
        for(int j = prev_i + 1; j < i + 1; j++) {
          for(int l = 0; l < w; l++) {
            sblock_sum[l] += s[j][l];
          }
        }
        prev_i = i;
        sblock_sums.push_back(sblock_sum);
        ans++;
      }
    }

    vector<int> sblock_sum(w);
    for (int i = prev_i + 1; i < h; i++) {
      for (int j = 0; j < w; j++) {
        sblock_sum[j] += s[i][j];
      }
    }
    sblock_sums.push_back(sblock_sum);

    vector<int> sblock_wsums(sblock_sums.size());
    for (int i = 0; i < w; i++) {
      for(int j = 0; j < sblock_sums.size(); j++) {
        sblock_wsums[j] += sblock_sums[j][i];
      }

      bool need_split = false;
      for(int j = 0; j < sblock_wsums.size(); j++) {
        if (sblock_wsums[j] > k*2) {
          is_impossible = true;
          break;
        }
        if (sblock_wsums[j] > k) {
          need_split = true;
        }
      }

      if (is_impossible) break;

      if (need_split) {
        ans++;
        for (int j = 0; j < sblock_wsums.size(); j++) {
          sblock_wsums[j] = sblock_sums[j][i];;
        }
      }
    }
    if (is_impossible) continue;
    ans_min = min(ans, ans_min);
  }
  cout << ans_min << "\n";
}

int main() {
  solver();
  return 0;
}


Measured memory_bytes: 384
d, n = map(int, input().split())
if d == 0:
    if n != 100:
        print(n)
    else:
        print(101)
elif d == 1:
    if n != 100:
        print(100 * n)
    else:
        print(100*101)
else:
    if n != 100:
        print(10000 * n)
    else:
        print(10000 * 101)


Measured memory_bytes: 2940
#!/usr/bin/env python3
n,m = map(int,input().split())
cnt = [1]*n
visit = [0]*n
visit[0] = 1
for i in range(m):
    x,y = map(int,input().split())
    if visit[x-1] > 0:
        if cnt[x-1] == 1:
            visit[x-1] = 0
        visit[y-1] =1
    cnt[x-1] -=1
    cnt[y-1] += 1
print(sum(1 for i in visit if i > 0))

Measured memory_bytes: 51416
#include <stdio.h>

int main(void)
{
   char s[4];
   int i,a,b,ca=0,cb=0,cc=0;

   scanf("%s",s);

   if((s[0]==s[1])||(s[0]==s[2])||(s[1]==s[2]))
      printf("No");

   else printf("Yes");

   return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        int [,,]building = new int[4, 3, 10];
        
        for(int i = 0; i < n; i++){
            var arr = Console.ReadLine().Split(' ').ToArray();
            var b = int.Parse(arr[0]) - 1;
            var f = int.Parse(arr[1]) - 1;
            var r = int.Parse(arr[2]) - 1;
            var v = int.Parse(arr[3]);
            
            building[b, f, r] += v;
        }
        
        for(int bi = 0; bi < 4; bi++){
            for(int fi = 0; fi < 3; fi++){
                for(int ri = 0; ri < 10; ri++){
                    Console.Write(" ");
                    Console.Write(building[bi, fi, ri]);
                    
                }
                
                Console.WriteLine();
            }
            
            if(bi != 3)
                Console.WriteLine("####################");
            
        }
        
    }
}


Measured memory_bytes: 18332
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int n,k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int idx = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] == 1) {
            idx = i;
            break;
        }
    }

    int left_start = idx;
    int right_start = idx;

    int ans = 0;
    for(int i = 0; i < n; i += k - 1) {
        if(i == n - 1) break;
        ans++;
    }
    if(k >= n) ans = 1;

    cout << ans << endl;



}

Measured memory_bytes: 640
from collections import Counter

N = int(input())
V = list(map(int, input().split()))

evenCnt = Counter(V[::2]).items()
oddCnt = Counter(V[1::2]).items()

evenCnt = list(evenCnt)
oddCnt = list(oddCnt)

evenCnt.sort(key=lambda A: A[1], reverse=True)
oddCnt.sort(key=lambda A: A[1], reverse=True)

if evenCnt[0][0] != oddCnt[0][0]:
    ans = (-(-N // 2) - evenCnt[0][1]) + (N // 2 - oddCnt[0][1])
    print(ans)
else:
    ans = min(
        (-(-N // 2) - evenCnt[0][1]) + N // 2,
        -(-N // 2) + (N // 2 - oddCnt[0][1])
    )
    if len(evenCnt) > 1:
        ans = min(ans, (-(-N // 2) - evenCnt[1][1]) + (N // 2 - oddCnt[0][1]))
    if len(oddCnt) > 1:
        ans = min(ans, (-(-N // 2) - evenCnt[0][1]) + (N // 2 - oddCnt[1][1]))

    print(ans)

Measured memory_bytes: 18656
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=x && x<w && 0<=y && y<h)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;

/** Problem2330 Earth Invasion Diary of Miyavi-sensei **/
int main()
{
	long  n;
	cin >> n;
	long t=0, nn=1;
	while (nn<n) {
		nn*=3; t++;
	}
	cout << t << endl;
}

Measured memory_bytes: 1160
#include<stdio.h>
#define NUM 1000
int func(int);
int main()
{
  int score[NUM];
  int i,j,n;
  int gap;
  while(1)
    {
      scanf("%d",&n);
      if(n==0) break;
      for(i=0;i<n;i++) scanf("%d",&score[i]);
      gap=func(score[1]-score[0]);
      if(gap<0) gap*=(-1);
      for(i=0;i<n-1;i++)
	{
	  for(j=i+1;j<n;j++)
	    {
	      if(func(score[i]-score[j])<gap) gap=func(score[i]-score[j]);
	    }
	}
      printf("%d\n",gap);
    }
  return 0;
}
int func(int x)
{
  if(x>=0) return x;
  else return x*(-1);
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define mset(a,x) memset(a,x,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define OUT(x) cout<<(x)<<"\n"
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)
#define pb push_back
#define mp make_pair

ll n, m;

int main() {
    cin>>n>>m;
    ll r = m - 2 * n;

    if(r >= 0){
        OUT(n + r / 4);
    }
    else{
        OUT(m / 2);
    }



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<typename Monoid> struct Starry_Sky_Tree{
    //最小値(最大値)クエリ
    Monoid ope(Monoid a, Monoid b){
        return max(a, b);
    }
    //単位元
    Monoid unit;
    int n;
    vector<Monoid> seg, lazy;
    //要素数N(0-indexed)のxを単位元とするStarry-Sky木を構築
    Starry_Sky_Tree(int N, Monoid x){
        unit = x;
        n = 1;
        while(n < N) n <<= 1;
        seg.assign(2*n, 0);
        lazy.assign(2*n, 0);
    }
    //add(a, b, x)で[a,b)にxを加算する
    void add(int a, int b, Monoid x, int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(a >= r || b <= l) return;
        if(a <= l && r <= b){
            lazy[i] += x;
            return;
        }
        add(a, b, x, 2*i, l, (l+r)/2);
        add(a, b, x, 2*i+1, (l+r)/2, r);
        seg[i] = ope(seg[2*i]+lazy[2*i], seg[2*i+1]+lazy[2*i+1]);
    }
    //query(a, b)で[a, b)における最小値(最大値)を取得
    Monoid query(int a, int b, int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(a >= r || b <= l) return unit;
        if(a <= l && r <= b) return seg[i]+lazy[i];
        Monoid vl = query(a, b, 2*i, l, (l+r)/2);
        Monoid vr = query(a, b, 2*i+1, (l+r)/2, r);
        return ope(vl, vr)+lazy[i];
    }
    //O(N)で全ての遅延配列を本配列に組み込む
    void update(int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        seg[i] = seg[i]+lazy[i];
        if(r-l > 1){
            lazy[2*i] += lazy[i];
            lazy[2*i+1] += lazy[i];
            update(2*i, l, (l+r)/2);
            update(2*i+1, (l+r)/2, r);
        }
        lazy[i] = 0;
    }
    //本配列のi番目の要素を取得
    Monoid at(int i){
        return seg[n+i];
    }
    //初期化する
    void clear(){
        fill(seg.begin(), seg.end(), 0);
        fill(lazy.begin(), lazy.end(), 0);
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    pii p[N];
    rep(i, N){
        int L, R; cin >> L >> R;
        p[i] = pii(L, R);
    }
    sort(p, p+N);
    Starry_Sky_Tree<int> seg(M+1, -inf);
    rep(i, M) seg.add(i, i+1, i-M);
    int ans = max(0, N-M);
    rep(i, N){
        seg.add(0, p[i].second, 1);
        chmax(ans, seg.query(p[i].first, M+1)-p[i].first);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<float,int> P;

float abs(float a){
  if(a>0) return a;
  else return -a;
}

int main(){
  int n;
  int t,a;
  cin >>n>>t>>a;
  vector<P> H(n);
  rep(i,n){
    int x;
    cin >>x;
    float z = abs(a-t+x*0.006);
    P y = make_pair(z,i+1);
    H[i] = y;
  }
  sort(H);
  cout << H[0].second << endl;
}

Measured memory_bytes: 256