akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	
	int n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	
	string s;
	cin >> s;
	
	vector<int> stone(n,0);
	//stoneの定義
	//0:石なし、前後も安全
	//1:石なし、前後に石あり(要注意)
	//2:石あり、前後に石なし
	//3:石あり、前後にも石あり(死亡)
	
	for (int i = 1; i < n-1; i++) {
		if(s.at(i) == '.'){
			//石なし
			if(s.at(i-1) == '#' || s.at(i+1) == '#'){
				//前後石あり＝要注意
				stone.at(i) = 1;
			}
		} else {
			//石あり
			if(s.at(i-1) == '#' || s.at(i+1) == '#'){
				//前後石あり=ダメ
				stone.at(i) = 3;
			} else {
				//ふつうの石
				stone.at(i) = 2;
			}
		}
	}
	
	//debug zone
	
	/*
	for (int i=1; i < n-1; i++) {
		cout << i << ":" << stone.at(i) << ", ";
		
	}
	cout << endl;
	*/
	
	int count=0;
	
	if (c < d) {
		//ふぬけがどっかいく=間に1があっても問題なし
		//つまりA～Dの間に絶対ダメゾーンがなければOK
		for (int i = a; i < d; i++) {
			if (stone.at(i) == 3){
				//絶対ダメあり
				count = -1;
				break;
			}
		}
		if ( count == -1) {
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl;
		}
		//ふぬけどっかいく 終わり
	} else {
		//ふぬけがどっかいかない
		//つまりB～Dに1が1個しかないと死ぬ
		
		//とりあえず上と同じ処理
		for ( int i = a; i < c; i++) {
			if (stone.at(i) == 3){
				//絶対ダメあり
				count = -1;
				break;
			}
		}
		if (count == -1) {
			cout << "No" << endl;
			return 0;
		} else {
			//ここから特別処理
			count = 1;
			for (int i = b-1; i < d; i++){
				//ふぬけのいる間に0が現れないとアウト
				if (stone.at(i) > 0) {
					count*2;
				} else {
					count = 0;
				}
			}
			if (count > 0) {
				cout << "No" << endl;
			} else {
				cout << "Yes" << endl;
			}
		}
	}
	
	return 0;
}


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

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

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

    int a, b;
    cin >> a >> b;
    if (a <= b + b) {
        cout << "0" << "\n";
    } else {
        cout << a - (b + b) << "\n";


    }
}















Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,A,B;cin >> N >> A >> B;
  cout << min(N*A,B) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int N, c[10][10][10], ans; char S[30001];
int main() {
  scanf("%d\n%s", &N, &S);
  int l[10] = {0};
  for(int i = 0; i < N-2; ++i) {
    if(l[S[i]-'0']++) continue;
    int m[10] = {0};
    for(int j = i+1; j < N-1; ++j) {
      if(m[S[j]-'0']++) continue;
      for(int k = j+1; k < N; ++k) {
        ++c[S[i]-'0'][S[j]-'0'][S[k]-'0'];
      }
    }
  }
  for(int i = 0; i < 10; ++i) {
    for(int j = 0; j < 10; ++j) {
      for(int k = 0; k < 10; ++k) {
        if(c[i][j][k]) ++ans;
      }
    }
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 256
N=int(input())
S=list(input().split())
A=[int(n) for n in S]

ans=0

for i in range(N-1):
    if A[i]>A[i+1]:
        s=A[i]-A[i+1]
        A[i+1]+=s
        ans+=s
    else:
        pass
print(ans)

Measured memory_bytes: 32524
s = input()
fro = int(s[:2])
bac = int(s[2:])

if 1 <= fro <= 12:
    if 1<= bac <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif 1 <= bac <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, K, ans = 1; cin >> N >> K;
    for (int i = 0; i < N; i++) {
        if (ans + K >= 2 * ans) ans *= 2;
        else ans += K;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3720
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    ll Xlen = N * (M / __gcd(N, M));
    map<ll, char> check;
    ll Sb = Xlen / N;
    ll Tb = Xlen / M;
    for(ll i = 0; i < N; i++) {
        check[Sb * i] = S[i];
    }
    int ok = 1;
    for(ll i = 0; i < M; i++) {
        if(!check.count(Tb * i))
            continue;
        if(check[Tb * i] != '.' && check[Tb * i] != T[i])
            ok = 0;
    }
    if(ok) {
        cout << Xlen << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 9388
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int c = scanner.nextInt();
    int[] b = new int[m];
    for (int i = 0; i < m; i++) {
      b[i] = scanner.nextInt();
    }
    int[] sum = new int[n];
    for (int i = 0; i < n; i++) {
      sum[i] = 0;
      for (int j = 0; j < m; j++) {
        sum[i] += scanner.nextInt() * b[j];
      }
    }

    int ans = 0;

    for (int i = 0; i < n; i++) {
      if (sum[i] + c > 0)
        ans++;
    }

    System.out.println(ans);

  }

}


Measured memory_bytes: 23892
i,j,k,s;main(x){char a[99],b[99];for(scanf("%s%d",a,&x);x--;){scanf("%s",b);for(i=0;i<10;i++){k=0;for(j=i;a[k]==b[j];){j++;k++;j=j>9?0:j;if(a[k]=='\0'){s++;i=11;break;}}}}printf("%d\n",s);exit(0);}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

/**
 * グラフの表現
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A&lang=ja">ALDS1_11_A</a>
 */
public class Main {

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

		for (int x[] : g) {
			Arrays.fill(x, 0);
		}

		for (int i = 0; i < n; i++) {
			int u = sc.nextInt();
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				int v = sc.nextInt();
				g[u - 1][v - 1] = 1;
			}
		}

		for (int x[] : g) {
			System.out.println(Arrays.toString(x).replace("[", "").replace("]", "").replace(",", ""));
		}

		sc.close();

	}

}



Measured memory_bytes: 34348
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


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
























int main(){
    ll l, r, d;
    cin >> l >> r >> d;
    ll ans = 0;
    for(ll i = l; i <= r; i++){
        if(i % d == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define ll long long

typedef pair<int,int> P;
const int INF = 500000000;

int main(){
    int k;
    string s,res;
    cin >> k >> s;
    if (s.size() <= k) res = s;
    else res = s.substr(0,k) + "...";
    cout << res << "\n";
}

Measured memory_bytes: 3632
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main(){
    ll n,k;
    cin>>n>>k;
    mint ans=mint(k);
    ans=ans.pow(n);
    cout<<ans<<endl;
}



Measured memory_bytes: 50060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll a,b,c,n;
    string s, t;
    ll ans;
    string answer = "No";

    cin  >> a >>b;



    cout << max((ll)0, a-2*b) << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int h, w;
char a[105];
int main() {
	int i;
	scanf("%d%d", &h, &w);
	for(i=0; i<w+2; i++) putchar('#'); puts("");
	while(h--) {
		scanf("%s", a);
		putchar('#'); printf("%s", a); putchar('#'); puts("");
	}
	for(i=0; i<w+2; i++) putchar('#'); puts("");
	return 0;
}

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

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second

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

using namespace std;


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

   int n; cin >> n;
   
   int ans = 0;
   while(n--){
      int l, r; cin >> l >> r;
      int diff = (r-l) + 1;
      ans += diff;
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 256
n  = int(input())
s = [int(input()) for i in range(n)]

s.sort()
ans = sum(s)
if (ans % 10 != 0):
    print(ans)
else:
    for i in s:
        if (i % 10 != 0):
            print(ans - i)
            break
    else:
        print(0)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a) )
#define M 4000010
#define md 1000000007

ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}
/*inline ll add(ll a,ll b){return (a+b)%md;}
inline ll mul(ll a,ll b){return (a*b)%md;}
ll f[M],iv[M];
ll C(ll n,ll r){return mul(f[n],mul(iv[r],iv[n-r]));}
void prep_fac(){
    f[0]=1;
    rep(i,1,M)f[i]=mul(i,f[i-1]);
    iv[M-1]=power(f[M-1],md-2,md);
    for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
}*/



int main()
{
	IOS;
	ld n,d;
	cin>>n>>d;
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		ld x,y;
		cin>>x>>y;
		ld p=x*x+y*y;
		p=sqrtl(p);
		if(p<=d)
		ans++;
	}
	cout<<ans;
}



Measured memory_bytes: 3768
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  int count = 0;
  rep(i,n){
    if(s[i] != t[0]) continue;
    for(int j=0;i+j < n;j++){
      if(s[i+j] == t[j]){
        count++;
      }else{
        count = 0;
      }
    }
    if(count != 0) break;
  }
  cout << 2*n-count << endl;
	return 0;
}


Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n); cin >> as;
    int cnt = 0;
    for(auto& a : as){
        cnt += a < 0;
    }
    for(auto& a : as){
        a = abs(a);
    }
    ll acc = accumulate(as.begin(), as.end(), 0ll);
    if(cnt & 1){
        int mini = M;
        for(auto& a : as){
            mini = min(mini, a);
        }
        cout << acc - mini * 2 << '\n';
    }else{
        cout << acc << '\n';
    }
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
int fun(int a,int b)
{
int r;
do
{
r=a%b;
a=b;
b=r;
}while(r!=0);
return a;
}
int gcd(int a,int b,int c)
{
	return fun(fun(a,b),c);
}

int main()
{
	int n,i,j,k;
	long long int s=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		for(k=1;k<=n;k++)
		{
			s+=gcd(i,j,k);
		}
		
	}
	printf("%lld",s);
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    if (x == 0)
        cout << 1;
    else cout << 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<long long int>vec_a,vec_b;

	for (int i = 0; i < n; i++)
	{
		long long int num;
		cin >> num;
		vec_a.push_back(num);
	}

	if (n % 2 == 0)
	{
		int num = n / 2;
		for (int i = 0; i < num; i++)
		{
			vec_b.push_back(vec_a[n - 2 * i - 1]);
		}
		for (int i = 0; i < num; i++)
		{
			vec_b.push_back(vec_a[2 * i]);
		}
	}
	else
	{
		int num = n / 2;
		for (int i = 0; i < num + 1; i++)
		{
			vec_b.push_back(vec_a[n - 2 * i - 1]);
		}
		for (int i = 0; i < num ; i++)
		{
			vec_b.push_back(vec_a[1 + 2 * i]);
		}
	}

	for (int i = 0; i < n ; i++)
	{
		cout << vec_b[i]<< " ";
	}
}

Measured memory_bytes: 5488
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    int n,ans=0;
    cin>>n;
    vector<int> v(n+1,0);
    for(int i=1;i<=n;i+=2){
        for(int j=1;j<=i;++j){
            if(i%j==0)++v[i];
        }
    }
    for(int i=1;i<=n;i+=2){
        if(v[i]==8)++ans;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def func1(N):
    if N%2==0:
        return N//2
    else:
        return 3*N+1
s = int(input())
a_n = {}
for i in range(1, 1000001):
    if s in a_n:
        break
    else:
        a_n[s] = 1
    s = func1(s)
print(i)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  ll ans=0;
  repo(i, n){
    int m=i;
    while(m<=n){
      ans+=m;
      m+=i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
    int n,n1,x;
    while(cin>>n1)
    {
        x=0;n=n1;
      while(n>0)
      {
          x+=(n%10);
          n/=10;
      }
      cout<<(n1%x==0?"Yes":"No")<<endl;
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

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

sm = sum(a)
best_dif = 100*100
for i in range(N):
    dif = abs(a[i]*N - sm)
    if dif < best_dif:
        best_dif = dif
        ans = i
print(ans)


Measured memory_bytes: 2940
n, m = map(int, input().split())

points    = [0] * n
penalty   = [0] * n
penalties = 0

for i in range(m):
  q, ans = input().split()
  q = int(q) - 1
  # まだ正解が出ていない場合
  if(points[q] == 0):
    # 正解の場合
    if(ans == 'AC'):
      points[q] = 1
      penalties += penalty[q]
    # 不正解の場合
    else:
      penalty[q] += 1

print('{} {}'.format(sum(points), penalties))

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

int main(){
	int n,y;
	int man,gosen,sen;
	man = gosen = sen = -1;
	cin >> n >> y;
	bool flag = false;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			int t = n - i - j;
			if((i * 10000) + (j * 5000) + (t * 1000) == y){
				man = i;
				gosen = j;
				sen = t;
			}
		}
	}
	
	cout << man << " " <<  gosen << " " <<  sen << endl;
	return 0;
}

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

int main(){
  int h,w;
  cin >> h >> w;
  int dp[h][w];
  vector<vector<char>> v(h,vector<char>(w,0));
  r(i,h){
    r(j,w){
      cin >> v[i][j];
      dp[i][j]=1000;
    }
  }
  if(v[0][0]=='#')dp[0][0]=1;
  else dp[0][0]=0;
  r(i,h){
    r(j,w){
      if(i==h-1&&j==w-1)continue;
      else if(i==h-1){
        if(v[i][j]=='.'&&v[i][j+1]=='#')dp[i][j+1]=min(dp[i][j]+1,dp[i][j+1]);
        else dp[i][j+1]=min(dp[i][j],dp[i][j+1]);
      }
      else if(j==w-1){
        if(v[i][j]=='.'&&v[i+1][j]=='#')dp[i+1][j]=min(dp[i][j]+1,dp[i+1][j]);
        else dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
      }
      else{
        if(v[i][j]=='.'&&v[i][j+1]=='#')dp[i][j+1]=min(dp[i][j]+1,dp[i][j+1]);
        else dp[i][j+1]=min(dp[i][j],dp[i][j+1]);
        if(v[i][j]=='.'&&v[i+1][j]=='#')dp[i+1][j]=min(dp[i][j]+1,dp[i+1][j]);
        else dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
      }
    }
  }
  
  cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

s=list(input())
n=len(s)

#print(s[0],s[1])

cnt0=0
cnt1=0
for i in range(n):
    if s[i]=="0":
        cnt0+=1
    elif s[i]=="1":
        cnt1+=1

print(2*min(cnt0,cnt1))


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  ll M = (N + 1) * N / 2;
  vector<ll> S(M);

  ll index = 0;
  for (ll i = 0; i < N; i++) {
    ll s = 0;
    for (ll j = i; j < N; j++) {
      s += A[j];
      S[index] = s;
      index++;
    }
  }

  ll ans = 0;
  for (ll i = 40; i >= 0; i--) {
    ll d = (1ll<<i);
    ll cnt = 0;
    for (ll j = 0; j < M; j++) {
      if (((ans + d) & S[j]) == ans + d) cnt++;
    }
    if (cnt >= K) ans += d;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4224
import java.util.Scanner;

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

	void solve(Scanner sc) {
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if (A == B && B == C && A == C) {
			System.out.println("Yes");

		} else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 21332
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner (System.in);
		
		int n = sc.nextInt();
		int [][] game = new int [n][3];
		int [][] result = new int [n][3];
		
		int i, j, k;
		
		for (i = 0; i < n; i++) {
			for (j = 0; j < 3; j++) {
				game[i][j] = sc.nextInt();
				result[i][j] = game[i][j];
			}
		}
		
		for (j = 0; j < 3; j++) {
			for (i = 0; i < n; i++) {
				for (k = 0; k < n; k++) {
					if (k != i) {
						if (game[i][j] == game[k][j]) {
							result[i][j] = 0;
						}
					}
				}
			}
		}
		
		for (i = 0; i < n; i++) {
			int sum = 0;
			for (j = 0; j < 3; j++) {
				sum += result[i][j];
			}
			System.out.println(sum);
		}
		
	}

}

Measured memory_bytes: 20832
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = deque(input())

ans = 0
while S:
	if len(S) == 1:
		S.pop()
	elif S[0] == S[-1]:
		S.popleft()
		S.pop()
	else:
		if S[0] == "x":
			S.append("x")
			ans += 1
		elif S[-1] == "x":
			S.appendleft("x")
			ans += 1
		else:
			print(-1)
			break
else:
	print(ans)


Measured memory_bytes: 5976
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int a[maxn],b[maxn],c[maxn],ca,cb,n;

inline int jud1()
{
	for(int i=1;i<=n;i++) if(a[i]!=c[i]) return 0;
	return 1;
}

inline int jud2()
{
	for(int i=1;i<=n;i++) if(b[i]!=c[i]) return 0;
	return 1;
}

int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read(),c[i]=i;
	if(jud1()) ca=1; if(jud2()) cb=1;
	int cnt=1;
	while(next_permutation(c+1,c+n+1))
	{
		cnt++;
		if(jud1()) ca=cnt;
		if(jud2()) cb=cnt;
	}
	cout<<abs(ca-cb)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n;
    cin>>n;
    vector<string> w(n);
    map<string,long long> m;
    f(i,0,n){
        cin>>w[i];
        m[w[i]]++;
    }
    bool f=true;
    f(i,0,n-1){
        if(w[i][w[i].size()-1]!=w[i+1][0]){
            f=false;
        }
        else if(m[w[i]]>1){
            f=false;
        }
    }
    if(f){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef pair<int,int> pii;

int main(){
  int H, W;
  cin >> H >> W;
  string F[H];
  for(int i = 0; i < H; ++i){
    cin >> F[i];
  }
  int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
  pair<pii,pii> e[4];
  e[0] = make_pair(pii(1,0),pii(1,1));
  e[1] = make_pair(pii(0,1),pii(1,1));
  e[2] = make_pair(pii(0,0),pii(0,1));
  e[3] = make_pair(pii(0,0),pii(1,0));
  vector< pair<double,int> > A;//"#"テ」ツ?ョテヲツ閉ーテ」ツつ誰テ」ツ?ィテ」ツ?凖」ツつ凝」ツ?ィ2*N+2テ」ツ?静」ツつ嘉」ツ??」ツ?ョティツヲツ?ァツエツ?ヲツ閉ー
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(F[i][j] == '#'){
	for(int k = 0; k < 4; ++k){
	  if(i+dx[k] < 0 || j+dy[k] < 0 || i+dx[k] > H-1 || j+dy[k] > W-1 || F[i+dx[k]][j+dy[k]] != '#'){
	    pii s = pii(H-i-e[k].first.first, j+e[k].first.second);
	    pii t = pii(H-i-e[k].second.first, j+e[k].second.second);
	    //printf("(%d, %d), (%d, %d)\n",s.first,s.second,t.first,t.second);
	    if(s.second && s.first)
	      A.push_back(make_pair((double)s.first/s.second, -1));
	    if(t.second && s.first)
	      A.push_back(make_pair((double)t.first/t.second, +1));
	  }
	}
      }
    }
  }
  sort(A.begin(),A.end());
  int ans = 0, t = 0;

  for(int i = 0; i < (int)A.size(); ++i){

    t += A[i].second;
    t = max(t,0);
    ans = max(t,ans);
  }

  cout << (ans+1)/2 + 1 << endl;
  return 0;
}

Measured memory_bytes: 19948
#include <iostream>
#include <vector>
#include <algorithm>

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

    std::vector<int> A(N), B(N), C(N);
    for (int &a : A) {
        std::cin >> a;
    }
    for (int &b : B) {
        std::cin >> b;
    }
    for (int &c : C) {
        std::cin >> c;
    }

    std::sort(A.begin(), A.end());
    std::sort(C.begin(), C.end());

    long count = 0;
    for (int &b : B) {
        long a_count = std::upper_bound(A.begin(), A.end(), b - 1) - A.begin();
        long c_count = C.end() - std::lower_bound(C.begin(), C.end(), b + 1);
        count += a_count * c_count;
    }
    std::cout << count << std::endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n,k;  cin >> n >> k;
    vector<bool> a(n, true);
    rep(i, k) {
        int d; cin >> d;
        rep(i, d) {
            int x; cin >> x; x--;
            a[x] = false;
        }
    }
    cout << accumulate(all(a), 0) << endl;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n, x;
    cin >> n >> x;
    int l[n];
    rep(i, n) { cin >> l[i]; }
    int count = 1;
    int now = 0;
    rep(i, n) {
        now += l[i];
        if (now <= x) {
            count++;
        } else {
            break;
        }
    }

    cout << count << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, T;
ll A[100010];
ll mina[100010], diff[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  mina[0] = A[0];
  diff[0] = 0;
  for (int i = 1; i < N; i++) {
    mina[i] = min(mina[i - 1], A[i]);
    diff[i] = A[i] - mina[i];
  }
  ll tmp = *max_element(diff, diff + N);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += diff[i] == tmp;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2560
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // Initialize
        	var iN = cin.ReadInt;
          	var sS = cin.ReadLine;
          	var sTarget = "ABC";
          	var iAns = 0 ;
            // Process
        	for(var i = 0 ; i <= iN - sTarget.Length ; i ++)
            	if(sS.Substring(i,sTarget.Length) == sTarget) iAns ++ ;
          	// Output
          	WriteLine(iAns);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 27928
#include <iostream>

void swap(int *x,int *y){
  int temp;
  temp = *x;
  *x = *y;
  *y = temp;
}

int main(int argc, char const *argv[]) {
  int i=1;
  while(1){
    int a,b;
    std::cin >> a >> b;
    if(a==0 && b==0)break;
    if(a > b) swap(&a,&b);
    std::cout << a << " "<< b << std::endl;
    i++;
  }
  return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s1,s2,s3;
	int a,b;
	cin>>s1>>s2;
	cin>>a>>b;
	cin>>s3;
	if(s3==s1)a--;
	else b--;
	cout<<a<<' '<<b<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int x[100010];
        int cnt=0;
        for(int i=1;i<=n;i++)
        {

            scanf("%d",&x[i]);
        }
         if(x[1]==1)
            {
                cnt++;
                 swap(x[1],x[2]);
            }
         for(int i=2;i<n;i++)
         {
             if(x[i]==i)
             {
                 if(x[i+1]==i+1)
                    swap(x[i],x[i+1]);
                 else
                    swap(x[i],x[i-1]);
                 cnt++;
             }
         }
         if(x[n]==n)
            cnt++;
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
 
int main(){
    long long int n, m;
    cin >> n >> m;
    if(n == 1 && m != 1) cout << m - 2 << endl;
    else if(n != 1 && m == 1) cout << n - 2 << endl;
    else if(n == 1 && m == 1) cout << 1 << endl;
    else if(n != 1 && m != 1) cout << (n - 2) * (m - 2) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string s;
    cin>>s;
    if(s[0]!=s[1]||s[0]!=s[2]||s[1]!=s[2]){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N,i,j;
	cin>>N;
	int A[2][N],B[2][N];
	for(i=0;i<N;i++) cin>>A[0][i],B[0][i]=0;
	for(i=0;i<N;i++) cin>>A[1][i],B[1][i]=0;
	B[0][0]=A[0][0];B[1][0]=A[0][0]+A[1][0];
	for(i=1;i<N;i++) B[0][i]=B[0][i-1]+A[0][i];
	for(i=1;i<N;i++) B[1][i]=A[1][i]+max(B[0][i],B[1][i-1]);
	cout<<B[1][N-1]<<endl;
	return (0);
}

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

int main(){
    string S;
    cin >> S;
    int min = 1000, k;
    for(int i = 0; i < S.size() - 2; i++){
        k = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + S[i+2] - '0';
        if(min > abs(k - 753)) min = abs(k - 753);
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//以下雛形を記す
long long INF =  -10000000000000000;
struct edge{
    int from;
    int to;
    long long cost;
};

int main(){
    int N, M;//Vは頂点、Kは辺の数
    cin >> N >> M;
    vector<edge> es(M);
    for(int i = 0; i < M; i++){
        cin >> es[i].from >> es[i].to >> es[i].cost;
        es[i].from--;
        es[i].to--;
       // es[i].cost *= -1;
    }
    vector<long long> d(N);//各頂点までの距離
    for(int i = 0; i < N; i++) d[i] = INF;
    d[0] = 0;
    int n = 0;
    for(int i = 0; i < N - 1; i++){
        for(int j = 0; j < M; j++){
            edge e = es[j];
            if(d[e.from] != INF && d[e.to] < d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    long long ans = d[N - 1];
    bool neg[N];
    for(int i = 0; i < N; i++) neg[i] = false;
    for(int i = 0; i < N; i++){//もう1セット更新し直して、最後が更新されていたらinfを出力
        for(int j = 0; j < M; j++){
            edge e = es[j];
            if(d[e.from] != INF){
                if(d[e.to] < d[e.from] + e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    neg[e.to] = true;
                }
                if(neg[e.from]) neg[e.to] = true;//d[e.from]が更新されていたら、その次の更新でd[e,to]は当然更新される
            }
        }
    }
    if(neg[N-1]) cout << "inf" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,c;
  int k;
  int sum=0;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  if(a>=k){
    sum = k;
    printf("%d\n", sum);
  } else {
    sum += a;
    if(b>=k-a){
      printf("%d\n", sum);
    } else {
      sum += -1*(k-a-b);
      printf("%d\n", sum);
    }
  }
  return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define pi 3.1415926
#define sec setprecision　
const long long mod = 998244353;
const int  MAX = 510000;

using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll p = sqrt(b);
	ll k = b % p, h = b / p, s = 1;
	rip(i, p)s = (s * a) % mod; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);
}
ll fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return (fac[n] * (finv[k] * finv[n - k] % mod) % mod);
}
ll fanc(ll h) {
	if (h == 1)return(1);
	else return (2 * (fanc((h / 2))) + 1);
}
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rip(i, n)cin >> a[i];
	vector<int>b(n);
	int mini = 1000000;
	rip(i, n) {
		mini = min(mini, a[i]);
		b[i] = mini;
	}
	int count = 0;
	rip(i, n) {
		if (a[i] == b[i])count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())     
#define rep(i,n) for(ll i=0;i<n;i++)
#define mp make_pair
//s.replace(s.find("10"), sizeof("10") - 1, "");
#define N 1001
using namespace std;
ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
bool compare(const pair<int, int>&i, const pair<int, int>&j)
    {
        return i.second < j.second;
    }
bool isPrime(ll n){
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}  
ll fact(ll n){
    if(n==0||n==1 ) return 1;
    return n*fact(n-1);
}
    
int main()
{
        // added the two lines below 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    string s;
    cin>>s;
    int flag=0;
    for(int i=0;i<3;i++){
        if(s[i]==s[i+1]){
            flag=1;
            break;
        }
    }
    if(flag) cout<<"Bad";
    else cout<<"Good";
    }
    
    
    


Measured memory_bytes: 256
n, t = [int(i) for i in input().split()]
r = [[int(i) for i in input().split()] for j in range(n)]
min_cost = 10000
for i in r:
    if i[1] <= t:
        if i[0] < min_cost:
            min_cost = i[0]
if min_cost == 10000:
    print('TLE')
else:
    print(min_cost)


Measured memory_bytes: 2940
n=int(input())
s=[*input()]
q=int(input())
from collections import *
d=defaultdict(list)
from bisect import *
for i,c in enumerate(s):
  d[c]+=[i]
for _ in range(q):
  x,y,z=input().split()
  y=int(y)-1
  if x=='1':
    if s[y]==z: continue
    d[s[y]].pop(bisect(d[s[y]],y)-1)
    s[y]=z
    insort(d[z],y)
  else:
    a=0
    for l in d.values():
      if bisect(l,int(z)-1)-bisect_left(l,y): a+=1
    print(a)

Measured memory_bytes: 34880
#include<stdio.h>

int max(int a,int b,int c)
{
	if (a > b&&a > c)
		return a;
	else if (b > a&&b > c)
		return b;
	else
		return c;
}
int min(int a, int b, int c)
{
	if (a < b&&a < c)
		return a;
	if (b < a&&b < c)
		return b;
	else
		return c;
}

int main()
{
	int task[3];
	scanf("%d%d%d", &task[0], &task[1], &task[2]);
	printf("%d", max(task[0], task[1], task[2]) - min(task[0], task[1], task[2]));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
ll add(ll a, ll b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
  return a;
}
ll sub(ll a, ll b) {
  a -= b;
  if (a < 0) {
    a += MOD;
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector < ll > dp(k + 5, 0);
  dp[0] = 1;
  for (int child = 1; child <= n; child++) {
    int x; cin >> x;
    vector < ll > mars(k + 5, 0);
    for (int given = k; given >= 0; given--) {
      int tmp = dp[given];
      int L = given + 1;
      int R = given + min(k - given, x);
      if (L > R) continue;
      mars[L] = add(mars[L], tmp);
      if (R + 1 <= k) mars[R + 1] = sub(mars[R + 1], tmp);
      }
      ll prefix = 0;
      for (int i = 0; i <= k; i++) {
        prefix = add(prefix, mars[i]);
        dp[i] = add(dp[i], prefix);
      }
  }
  cout << dp[k] << "\n";
  return 0;
}

Measured memory_bytes: 1792
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<long long,long long> P;
//typedef pair<long long,P> P1;
//typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define se second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())


#define ALL(v)  (v).begin(),(v).end()
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))




template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define pr printf
#define re return
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)



ll N;
ll sum;
ll flg;
int main(){
	
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	
	cin >> N;
	
	vector<pair<long long, long long> > p(N);
	for(long long i=0; i<N; i++){
		long long a, b;
		cin >> a >> b;
		p[i] = make_pair(b, a);
	}
    
	
	sort(p.begin(), p.end());
	//sort(p.begin(), p.end(),greater<pair<long long,long long> >());
	
	
	//●●●	通常（ペア用）
	flg=0;
	sum=0;
	for(long long i=0; i<N; i++){
		
		sum+=p[i].se;
		if(sum>p[i].fi){
			flg=1;
			break;
		}
	}
	
	
	if(flg==0){
		puts("Yes");
	}
	else{
		puts("No");
	}
	re 0;
}


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

int main()
{
  int X, Y;
  cin >> X >> Y;

  for (int i = 0; i <= X; i++)
  {
    if (i * 2 + 4 * (X - i) == Y)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 110000

ll dp1[MAXN];
ll dp2[MAXN];
ll ans[MAXN];
ll n, m;
vector<vector<int>>edges(MAXN);

void dfs1(int now=1, int p=-1){
  dp1[now]=1;
  for(auto c: edges[now]){
    if(c==p)continue;
    dfs1(c, now);
    dp1[now]*=dp1[c];
    dp1[now]%=m;
  }
  dp1[now]++;
}

void dfs2(int now=1, int p=-1){
  if(p==-1)dp2[now]=1;

  int ec = edges[now].size();

  vector<ll>lprod(ec, 1);
  rep(i, ec){
    int c = edges[now][i];
    if(i)lprod[i] *= lprod[i-1];
    if(c==p)continue;
    lprod[i]*=dp1[c];
    lprod[i]%=m;
  }

  vector<ll>rprod(ec, 1);
  rrep(i, ec){
    int c = edges[now][i];
    if(i<ec-1)rprod[i] *= rprod[i+1];
    if(c==p)continue;
    rprod[i] *= dp1[c];
    rprod[i] %= m;
  }

  rep(i, ec){
    int c = edges[now][i];
    if(c==p)continue;
    dp2[c] = dp2[now];
    if(i)dp2[c] = dp2[c] * lprod[i-1] % m;
    if(i<ec-1)dp2[c] = dp2[c] * rprod[i+1] % m;
    dp2[c]++;
    dp2[c] %= m;
    dfs2(c, now);
  }
}

void dfs3(int now=1, int p=-1){
  ans[now] = dp2[now];
  for(auto c: edges[now]){
    if(c==p)continue;
    ans[now] *= dp1[c];
    ans[now] %= m;
    dfs3(c, now);
  }
}

int main(){
  cin>>n>>m;
  rep(i, n-1){
    int x,y;cin>>x>>y;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }

  dfs1();
  dfs2();
  dfs3();

  rep1(i, n)cout<<ans[i]<<endl;

  return 0;

  rep1(i, n)cout<<dp1[i]<<' ';cout<<endl;
  rep1(i, n)cout<<dp2[i]<<' ';cout<<endl;

  return 0;
}

Measured memory_bytes: 22424
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int a;
    cin>>a;
    int ans=a+a*a+a*a*a;
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
main=do
 [n,m]<-map read.words<$>getLine
 i<-map((\[s,c]->(\a->a!!((read s)-1)==(c!!0))).words).lines<$>getContents
 let j=filter(\a->all(id)$map(\f->f a)i)[b|b<-map show[0..1000],length b==n]
 putStrLn$if null j then"-1"else j!!0

Measured memory_bytes: 636