akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

ll a[2000000];
bool appeard[2000000];

int main(void) {
  ll K, ans = -1;
  cin >> K;

  //if (7 % K == 0) {
  //  cout << 1 << endl;
  //  return 0;
  //}

  for (ll i = 1; ; i++) {
    a[i] += 7;
    if (i >= 2) {
      a[i] += a[i-1] * 10;
    }
    a[i] %= K;
    if (a[i] == 0) {
      ans = i;
      break;
    }
    if (appeard[a[i]]) {
      break;
    }
    appeard[a[i]] = true;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12376
n, k = map(int,input().split())
a = [int(i) for i in input().split()]
s = []
ord = [-1] * (n+1)
c, l = 1, 0
v = 1
while (ord[v] == -1):
    ord[v] = len(s)
    s.append(v)
    v = a[v-1]
    
c = len(s) - ord[v]
l = ord[v]
print(s[k] if (k < l) else s[l + (k - l) % c])

Measured memory_bytes: 32304
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long ll;
const int MAXN=1e5+5;

int N,M;

struct E{int next,to;} e[MAXN<<1];int ecnt,G[MAXN];
void addEdge(int u,int v){e[++ecnt]=(E){G[u],v};G[u]=ecnt;}
void addEdge2(int u,int v){addEdge(u,v);addEdge(v,u);}

int clr[MAXN];
bool dfs(int u)
{
	for(int i=G[u];i;i=e[i].next)
	{
		int v=e[i].to;
		if(~clr[v])
		{
			if(clr[v]==clr[u]) return false;
			else continue;
		}
		clr[v]=clr[u]^1;
		if(!dfs(v)) return false;
	}
	return true;
}

int main()
{
	int i;
	scanf("%d%d",&N,&M);
	for(i=1;i<=M;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		addEdge2(u,v);
	}
	memset(clr,-1,sizeof(clr));
	clr[1]=0;
	ll cnt=0;
	if(dfs(1))
	{
		for(i=1;i<=N;i++) if(clr[i]) cnt++;
		cnt=(ll)cnt*(N-cnt);
	}else cnt=(ll)N*(N-1)/2;
	std::cout<<cnt-M;
	return 0;
}

Measured memory_bytes: 2944
def sieve(n):
    primes = []
    candidates = list(range(2, n + 1))
    v = candidates[0]
    while v ** 2 <= n:
        primes.append(v)
        candidates.pop(0)
        candidates = list(filter(lambda x: x % v != 0, candidates))
        v = candidates[0]
    primes += candidates
    return primes

N = int(input())
L = sieve(55556)

n = 0
ans = []
for l in L:
    if (l + 1) % 5 == 0:
        ans.append(str(l))
        n += 1
    if n == N:
        break

print(' '.join(ans))


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

int main() {
    int N,K,l;

    cin >> N >> K;
    int ls[N];
    for(int i=0; i<N; ++i) {
        cin >> ls[i];
    }
    sort(ls, ls+N);

    int sum_num = 0;
    for(int i=N-1; i > N-K-1; --i) {
        //cout << ls[i] << " ";
        sum_num += ls[i];
    }
    cout << sum_num << endl;
    //cout << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    C_h, C_w = map(int, input().split())
    D_h, D_w = map(int, input().split())
    field = [list(input()) for _ in range(H)]
    direction = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    F = [[float('inf')] * W for _ in range(H)]
    queue = deque([(C_h - 1, C_w - 1)])
    nextqueue = deque([])
    t = 0
    alr = set()
    while queue:
        i, j = queue.popleft()
        if not (i, j) in alr:
            F[i][j] = min(t, F[i][j])
            if D_h == i + 1 and D_w == j + 1:
                break
            alr.add((i, j))
            for dx, dy in direction:
                nx, ny = i + dx, j + dy
                if 0 <= nx <= H - 1 and 0 <= ny <= W - 1:
                    if field[nx][ny] == '.':
                        queue.append((nx, ny))
            for p in range(i - 2, i + 3):
                for q in range(j - 2, j + 3):
                    if 0 <= p <= H - 1 and 0 <= q <= W - 1:
                        if field[p][q] == '.':
                            nextqueue.append((p, q))
                            F[p][q] = min(F[p][q], t + 1)
        if not queue:
            queue = nextqueue.copy()
            nextqueue.clear()
            t += 1

    if F[D_h-1][D_w-1] == float('inf'):
        print(-1)
    else:
        print(F[D_h - 1][D_w - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 228000
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
//#define max(a,b) ((a)<(b)?(b):(a))
//#define min(a,b) ((a)<(b)?(a):(b))
//#define swap(a,b) a^=b^=a^=b
#define lb(x) ((x)&(-(x)))
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 500010
using namespace std;
typedef long long ll;
int n,a,b,c,d;
int main(){
	cin>>n>>a>>b>>c>>d,b-=a,n--;
	for(int i=n;~i;i--){
//		cout<<1ll*i*c-1ll*(n-i)*d<<" "<<1ll*i*d-1ll*(n-i)*c<<endl;
		if(b>=1ll*i*c-1ll*(n-i)*d&&b<=1ll*i*d-1ll*(n-i)*c)return puts("YES"),0;
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
typedef pair<int,P> PP;
const int N=14;
int dp1[N][1001],c[N][N],dp2[1<<N][N],dp3[2][1<<(N/2+1)][1001],dp[1<<N][1001],ans;
vector<PP> a[N+1];
int main() {
  int A,B,n;
  cin >> n >> A >> B;
  for(int k=0; k<n; k++) {
    fill(dp1[k],dp1[k]+B+1,-(1<<30));
    dp1[k][0]=0;
    int m;
    cin >> m;
    for(int i=0; i<m; i++) {
      PP p;
      cin >> p.S.F >> p.F >> p.S.S;
      int t=1;
      while(p.S.S) {
        do {
          for(int j=B; j>=0; j--) {
            if(j+p.S.F*t<=B) dp1[k][j+p.S.F*t]=max(dp1[k][j+p.S.F*t],dp1[k][j]+p.F*t);
          }
          p.S.S-=t;
        } while(p.S.S%(t*2));
        t*=2;
      }
    }
    for(int i=0; i<B; i++) dp1[k][i+1]=max(dp1[k][i+1],dp1[k][i]);
  }
  for(int i=0; i<n; i++)for(int j=0; j<n; j++) cin >> c[i][j];
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
  for(int t=0;t<(1<<n);t++)for(int i=0;i<n;i++) dp2[t][i]=1<<30;
  for(int i=0; i<n; i++) dp2[1<<i][i]=c[0][i];
  for(int t=1; t<(1<<n); t++) {
    for(int i=0; i<n; i++) {
      if(!(t&(1<<i))) continue;
      for(int j=0; j<n; j++) {
        if(t&(1<<j)) continue;
        dp2[t|(1<<j)][j]=min(dp2[t|(1<<j)][j],dp2[t][i]+c[i][j]);
      }
    }
  }
  for(int t=0;t<(1<<(n/2+n%2));t++)for(int i=0;i<=B;i++)dp3[0][t][i]=dp3[1][t][i]=-(1<<30);
  for(int l=0; l<2; l++) {
    dp3[l][0][0]=0;
    for(int t=0; t<(1<<(n/2+n%2*l)); t++) {
      for(int i=0; i<n/2+n%2*l; i++) {
        if(t&(1<<i)) continue;
        for(int j=B; j>=0; j--) {
          for(int k=B-j; k>=0; k--) {
            dp3[l][t|(1<<i)][j+k]=max(dp3[l][t|(1<<i)][j+k],dp3[l][t][j]+dp1[i+n/2*l][k]);
          }
        }
      }
      for(int i=0; i<B; i++) dp3[l][t][i+1]=max(dp3[l][t][i+1],dp3[l][t][i]);
    }
  }
  for(int t=0;t<(1<<n);t++)for(int i=0;i<=B;i++)dp[t][i]=-(1<<30);
  for(int t=0;t<(1<<(n/2));t++) {
    if(n>1&&t%2==0) continue;
    for(int s=0; s<(1<<(n/2+n%2)); s++) {
      int C=max(0,A-dp2[t|(s<<(n/2))][0]),D=min(B,C);
      for(int i=0; i<=D; i++)ans=max(ans,dp3[0][t][i]+dp3[1][s][D-i]);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int D, N; cin >> D >> N;
    long int ans;
    if (N == 100) {
        N = 101;
    }
    if (D == 0) {
        ans = N;
    } else if (D == 1) {
        ans = 100 * N;
    } else if (D == 2) {
        ans = 10000 * N;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3580
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

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

template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
   o << "{";
   for (int i = 0; i < (int)v.size(); i++)
      o << (i > 0 ? ", " : "") << v[i];
   o << "}";
   return o;
}

vector<int> z_algorithm(const string &s)
{
   vector<int> prefix(s.size());
   for (int i = 1, j = 0; i < s.size(); i++)
   {
      if (i + prefix[i - j] < j + prefix[j])
      {
         prefix[i] = prefix[i - j];
      }
      else
      {
         int k = max(0, j + prefix[j] - i);
         while (i + k < s.size() && s[k] == s[i + k])
            ++k;
         prefix[i] = k;
         j = i;
      }
   }
   prefix[0] = (int)s.size();
   return prefix;
}

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   ll n;
   string s;
   cin >> n;
   cin >> s;

   int ans = 0;
   for (int i = 0; i < n; i++)
   {
      string news = s.substr(i);
      auto za = z_algorithm(news);
      //cout << za << endl;
      for (int j = 1; j < za.size(); j++)
      {
         if (j >= za[j])
         {
            ans = max(ans, za[j]);
         }
      }
   }

   cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll N, M;
    cin >> N >> M;
    vecll k(M);
    vector<vecll> s(M, vecll(N));
    vecll p(M);
    for(ll i = 0; i < M; i++){
        cin >> k.at(i);
        for(ll j = 0; j < k.at(i); j++){
            cin >> s.at(i).at(j);
        }
    }
    for(auto& i : p) cin >> i;

    ll ans = 0;
    for(ll i = 0; i < pow(2, N); i++){
        vecll onoff(N, 0);
        ll j = 0;
        ll ii = i;
        while(ii > 0){
            onoff.at(j) = ii % 2;
            ii /= 2;
            j++;
        }
        ll truecounter = 0;
        for(ll m = 0; m < M; m++){
            ll count = 0;
            for(ll n = 0; n < k.at(m); n++){
                count += onoff.at(s.at(m).at(n) - 1);
            }
            if(count % 2 != p.at(m)) break;
            truecounter++;
        }
        if(truecounter == M) ans++;
    }
    cout << ans << endl;
}

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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

// -------------------------------------------


void solve(long long N, std::vector<string> S){
  ll ans = -1;
  rep(i,N) {
    bool f = true;
    vector<ll> v(N,0);
    v[i] = 1;
    queue<ll> q;
    q.push(i);
    while(!q.empty() and f) {
      ll now = q.front();
      q.pop();
      rep(j,S[now].size()) {
	if(S[now][j]=='1') {
	  if(v[j] == 0) {
	    v[j] = v[now]+1;
	    q.push(j);
	  } else {
	    if(v[j]+1!=v[now] and v[j]-1!=v[now]) {
	      f = false;
	      break;
	    }
	  }
	}
      }
    }
    if(f) {
      rep(j,N) {
	ans = max(ans, v[j]);
      }
    }
  }
  std::cout << ans << std::endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<string> S(N);
    for(int i = 0 ; i < N ; i++){
      cin>>S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);
#define tie cin.tie(0);
#define x first
#define y second
#define ll long long
#define mod 666013

using namespace std;

int n;
string s, rs = "aoieu";


int main(){
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		for (int j = 0; j < rs.size(); j++)
			if (s[i] == rs[j]) return cout << "vowel", 0;
	cout << "consonant";
    return 0;
}


Measured memory_bytes: 764
from collections import deque


def bfs():
  d.append(0)
  trace[0] = 1
 
  while d:
    now = d.pop()
    for next in g[now]:
      if trace[next] == 0:
        trace[next] = 1
        score[next] += score[now]
        d.append(next)


n,q = map(int,input().split())
g = [[] for i in range(n)]

trace = [0]*n#頂点の個数
score = [0]*n

for i in range(n-1):#各々の頂点から行ける頂点のリスト
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  g[a].append(b)
  g[b].append(a)

for i in range(q):
  p,x = map(int,input().split())
  p -= 1
  score[p] += x

d = deque([])

bfs()
      
print(*score)

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

using namespace std;

typedef long long ll;

int main() {
		string S;
		ll K;
		cin >> S >> K;

		for (int i = 0; i < K; i++) {
				if (S[i] != '1') {
						cout << S[i] << endl;
						return 0;
				}
		}

		cout << 1 << endl;

		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();
   
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        string s="";
        while(n>0)
        {
            ll d= (n-1)%26;
            s+= (char)('a'+d);
            n=(n-1)/26;
        }
        for(int  i=s.size()-1;i>=0;i--)
            cout<<s[i];
        nl;
    }
    
}

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

int n, t;
int xs[112345];
int ys[112345];

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

  int max = 0;
  int maxdiff = -1;
  for(int i = n - 1; i >= 0; --i) {
    max = std::max(max, xs[i]);
    ys[i] = max - xs[i];
    maxdiff = std::max(maxdiff, ys[i]);
  }

  int pair = 0;
  for(int i = 0; i < n; ++i) {
    if( ys[i] == maxdiff ) pair += 1;
  }
  printf("%d\n", pair);
  // int t2 = t / 2;
  // printf("
  // printf("%d\n", std::max(pair - t2 + 1, pair));
  
  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;

const int INF = 1000000010;

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

    vector<int> dp(n, INF);
    for (int i = 0; i < n; ++i) {
        auto it = lower_bound(dp.begin(), dp.end(), a[i]);
        *it = a[i];
    }
    int ans = distance(dp.begin(), lower_bound(dp.begin(), dp.end(), INF));
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 3624
//#pragma GCC optimize("Ofast")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>


#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
//#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MAX = 100010;
int MOD = (ll)1000000000 + 7;
ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;


typedef pair<ll, int>P;//firstは距離、secondは頂点番号
struct Ver { ll dist; set<int>company; };//頂点に、始点からの距離と最後に使った会社を持たせる
struct edge { int to, cmp; };//辺には行き先の頂点と会社を持たせる
Ver d[100010];
int V;//頂点数
int M;//辺の本数

vector<edge>G[100010];//グラフ
					  //int d[MAX];//始点からの距離
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	set<int>st;//キューに入っている頂点番号
			   //全点への距離をINFで初期化
	for (int i = 0; i < V + 1; ++i) {
		d[i].dist = INF;
	}
	//始点への距離は0
	d[s].dist = 0;
	//始点をキューに入れる
	que.push(P(0, s)); st.insert(s);
	while (!que.empty()) {
		P p = que.top(); que.pop();
		auto c = st.erase(p.second);
		int v = p.second;//今見ている頂点
		if (d[v].dist < p.first)continue;

		//今見ている頂点につながるすべての辺について距離を更新する
		int n = G[v].size();
		for (int i = 0; i < n; ++i) {
			edge e = G[v][i];
			int cost = 1;
			//vに訪れるのに最後に使った会社(複数の場合もある)が今見ている辺の会社と同じならコストを0にする
			if (d[v].company.find(e.cmp) != d[v].company.end())cost = 0;
			//今見ている辺を使うことでe.toへの距離が小さくなるなら、距離を更新し、最後に使った会社をe.cmpとする
			if (d[e.to].dist > d[v].dist + cost) {
				d[e.to] = { d[v].dist + cost,{ e.cmp } };
				que.push(P(d[e.to].dist, e.to)); st.insert(e.to);
			}
			//今見ている辺を使っても距離が変わらない場合、最後に使った会社に(もしe.cmpがなかったら)e.cmpを追加する
			else if (d[e.to].dist == d[v].dist + cost) {
				if (d[e.to].company.find(e.cmp) == d[e.to].company.end()) {
					d[e.to].company.insert(e.cmp);
					if (st.find(e.to) == st.end()) {
						que.push(P(d[e.to].dist, e.to)); st.insert(e.to);
					}
				}

			}
		}
	}
}

int main() {
	cin >> V >> M;
	int p, q, c;
	for (int i = 0; i < M; i++) {
		scanf("%d %d %d", &p, &q, &c);
		G[p].push_back({ q,c });
		G[q].push_back({ p,c });
	}
	dijkstra(1);
	ll ans = d[V].dist;
	if (ans == INF) {
		cout << -1 << endl; return 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 30936
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
int main(){
    int n,r;
    cin>>n>>r;
    cout<<r+100*(10-min(10,n))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

int main()
{

  int n, k, x, y;
  cin >> n >> k >> x >> y;

  int ans;

  if (n < k)
    ans = n * x;
  else
    ans = k * x + (n - k) * y;

  cout << ans << endl;
}


Measured memory_bytes: 3568
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<set>
using namespace std;
double x[210000];
double y[210000];
pair<pair<double,int> ,double> ev[410000];
int main(){
	int a;scanf("%d",&a);
	double b;scanf("%lf",&b);
	for(int i=0;i<a;i++){
		double X,Y;
		scanf("%lf%lf",&X,&Y);
		x[i]=cos(1)*X-sin(1)*Y;
		y[i]=sin(1)*X+cos(1)*Y;
		ev[i*2]=make_pair(make_pair(y[i]-b,1),x[i]);
		ev[i*2+1]=make_pair(make_pair(y[i]+b,0),x[i]);
	}
	std::sort(ev,ev+a*2);
	int ret=0;
	set<double>S;
	S.insert(-1000000000);
	S.insert(1000000000);
	for(int i=0;i<a*2;i++){
		if(ev[i].first.second==1){
			double L=ev[i].second-b;
			double R=ev[i].second+b;
			double val=*(S.lower_bound(L));
			if(val>R)ret++;
			S.insert(L);
			S.insert(R);
		}else{
			double L=ev[i].second-b;
			double R=ev[i].second+b;
			S.erase(L);
			S.erase(R);
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 19552
#include <bits/stdc++.h>
 
int main(){
	int n,m;
	std::cin>>n>>m;
	double ans;
	double pow = 1.0;
	for(int i = 0; i < m; i++) pow *= 2.0;
	ans = (((double)m)*1800.0 + ((double) n)*100.0) *pow;
	std::cout<<(int)ans<<std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

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

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

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

int N;

int larger(const string& num) {
    ll i = stoll(num);
    if (i > N) return 1;
    return 0;
}

int ok(const string& num) {
    if (num.find('7') == string::npos) return 0;
    if (num.find('5') == string::npos) return 0;
    if (num.find('3') == string::npos) return 0;
    return 1;
}

int add(const string& base, int count) {
    string new7(base);
    string new5(base);
    string new3(base);
    new7 += '7';
    if (!larger(new7)) {
        if (ok(new7)) {
            count++;
        }
        count = add(new7, count);
    }
    new5 += '5';
    if (!larger(new5)) {
        if (ok(new5)) {
            count++;
        }
        count = add(new5, count);
    }
    new3 += '3';
    if (!larger(new3)) {
        if (ok(new3)) {
            count++;
        }
        count = add(new3, count);
    }
    return count;
}

int main(int argc, const char * argv[]) {
    N = inputValue();
    output(add("", 0));

    return 0;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

W, H, x, y = LI()

'''
どこの点が与えられても、縦、横、四隅の点とむすんで面積を確認する
対角で面積が同じ場合は、2分割を意味する
正方形の場合、絶対半分にでき、原点の場合は複数個線を作れる

長方形の場合、原点の場合は複数個可能で、それ以外の場合は無理
'''

if W == H:
    # 正方形の場合
    print(W*H/2, end=' ')
    if x == y == W/2:
        print(1)
    else:
        print(0)
else:
    # 正方形以外の場合
    if x == W/2 and y == H/2:
        print(W*H/2, 1)
    else:
        #  # 中途半端な位置の点のばあい
        #  # 4隅と縦横を調査
        #  S = W*H
        #  # 縦の場合
        #  s1 = x*H
        #  s2 = S - s1
        #  sm = min(s1, s2)

        #  # 横の場合
        #  s1 = W*y
        #  s2 = S - s1
        #  sm = max(sm, min(s1, s2))
        #  print(sm, 0)

        # どんなところからでも二等分可能
        print(W*H/2, 0)


Measured memory_bytes: 64876
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>

using namespace std;

int main(){
	int i, j;
	int x, y;

	cin >> x >> y;

	cout << x + y / 2 << endl;









	getchar();
	getchar();
	return 0;
}

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

typedef long long ll;

#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define MOD 1000000007
#define pb push_back
#define vll vector<ll>
#define FOR(i,n) for(int i{0}; i < n; ++i)

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<string, int> ans = { {"AC", 0}, {"TLE", 0}, {"WA", 0}, {"RE", 0}} ;
  while (n--) {
	  string s;
	  cin >> s;
	  ans[s]++;
  }
  cout << "AC x " << ans["AC"] << '\n';
  cout << "WA x " << ans["WA"] << '\n';
  cout << "TLE x " << ans["TLE"] << '\n';
  cout << "RE x " << ans["RE"] << '\n';
  return 0;
}


Measured memory_bytes: 3676
import sys

def check(i,sum,Mi_max,n,A,cA):

	if i == n:
		if sum-1 < Mi_max:
#			print(f"{i},{sum}")
			cA[sum-1] = 1
		return True

	if i != 0 and sum > 0 and sum-1 < Mi_max:
#		print(f"{i},{sum}")
		cA[sum-1] = 1

	res = check(i+1,sum+A[i],Mi_max,n,A,cA) or check(i+1,sum,Mi_max,n,A,cA)

def test():

#	with open("in.txt",mode='r') as f:
#		n = int(f.readline())
#		A = list(map(int,f.readline().split()))
#		q = int(f.readline())
#		M = list(map(int,f.readline().split()))

	n = int(sys.stdin.readline())
	A = list(map(int,sys.stdin.readline().split()))
	q = int(sys.stdin.readline())
	M = list(map(int,sys.stdin.readline().split()))

	Mi_max = 0

	for i in M:
		if Mi_max < i:
			Mi_max = i
#	print(Mi_max)

	check_array = [0] * Mi_max

	check(0,0,Mi_max,n,A,check_array)

#	for i in range(len(check_array)):
#		print(f"{i+1}:{check_array[i]}")

	for i in M:
		if check_array[i-1] == 1:
			print("yes")
		else:
			print("no")

if __name__ == "__main__":
	test()




Measured memory_bytes: 5640
#include<bits/stdc++.h>
using namespace std;
int main() {
  int x, y; cin >> x >> y;
  if(x * 2 <= y && y <= x * 4) {
    if(y % 2 == 0) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,M;
    cin >> N >> M;
    int s[10], c[10];
    int Num[3]={-1,-1,-1};
    for (int i=0; i<M; i++) {
        cin >> s[i] >> c[i];
        if (Num[s[i]-N+2] == -1) {
            Num[s[i]-N+2] = c[i];
        }
        else if(Num[s[i]-N+2]!=c[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    if (Num[1-N+2] == 0 && N != 1) {
        cout << -1 << endl;
        return 0;
    }
    for (int i=0; i<N; i++) {
        if (i==0&&N!=1&&Num[i-N+3]==-1) cout << 1;
        else {
        cout << (Num[i-N+3] == -1 ? 0 : Num[i-N+3]);
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int H, W, M; cin >> H >> W >> M;
  vector<int> R(H), C(W);
  map<pair<int, int>, int> m;
  int mr = 0, mc = 0;
  for (int i = 0; i < M; i++) {
    int r, c; cin >> r >> c; r--, c--;
    mr = max(mr, ++R[r]);
    mc = max(mc, ++C[c]);
    m[{r, c}] = 1;
  }
  vector<int> a, b;
  for (int i = 0; i < H; i++) {
    if (R[i] == mr) a.push_back(i);
  }
  for (int i = 0; i < W; i++) {
    if (C[i] == mc) b.push_back(i);
  }
  for (auto x : a) {
    for (auto y : b) {
      if (m[{x, y}] == 0) {
        cout << mr + mc << endl;
        return 0;
      }
    }
  }
  cout << mr + mc - 1 << endl;
}

Measured memory_bytes: 28476
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int h,w;
  cin>>h>>w;
  vector<vector<int>> field(h,vector<int>(w));
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      cin>>field[i][j];
    }
  }
  vector<pair<int,int>> vec;
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      if(field[i][j]%2==0) continue;
      if(i+1<h)
      {
        field[i][j]--;
        field[i+1][j]++;
        vec.push_back(make_pair(i,j));
      }
      else if(j+1<w)
      {
        field[i][j]--;
        field[i][j+1]++;
        vec.push_back(make_pair(i,j));
      }
    }
  }
  cout<<vec.size()<<endl;
  for (int i = 0; i < vec.size(); ++i)
  {
    cout<<1+vec[i].first<<" "<<1+vec[i].second<<" ";
    if(vec[i].first==h-1) 
    {
      cout<<1+vec[i].first<<" "<<1+vec[i].second+1<<endl;
    }
    else 
      cout<<1+vec[i].first+1<<" "<<1+vec[i].second<<endl;
  }

}

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

int main(){
  int N;
  cin>>N;
  vector<int> vec(N),vec1(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
    vec1.at(i)=vec.at(i);
  }
  sort(vec1.begin(),vec1.end());
  for(int i=0;i<N;i++){
  	if(vec.at(i)==vec1.at(N-1))
      cout<<vec1.at(N-2)<<endl;
    else
      cout<<vec1.at(N-1)<<endl;
  }
}

Measured memory_bytes: 3200
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();

    System.out.println(Math.max(C - (A - B), 0));

  }
}


Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

#define st first
#define nd second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REV(a) reverse(a.begin(),a.end())
#define SORT(a) sort(a.begin(),a.end())
#define inf (int)1e9
#define linf (ll)1e18

int n,f[1000][1000];
int p[1000][1000];
vi a;
ll ans=-linf;
void ha(){
		int c[1000]={};
		FOR(i,0,n){
				FOR(j,0,10){
						if(a[j]==1&&f[i][j]==1)c[i]=c[i]+1;
				}
		}
		ll cnt=0;
		FOR(i,0,n){
				cnt=cnt+p[i][c[i]];
		}
		ans=max(ans,cnt);
}

void dfs(bool ff){
		if(a.size()==10){
				if(ff)ha();
				return ;
		}
		a.push_back(0);
		dfs(ff);
		a.pop_back();
		a.push_back(1);
		dfs(1);
		a.pop_back();

}

int main() {
		ios::sync_with_stdio(false);
		cin>>n;
		FOR(i,0,n)FOR(j,0,10)cin>>f[i][j];
		FOR(i,0,n)FOR(j,0,11)cin>>p[i][j];
		a.clear();
		dfs(0);
		cout<<ans<<endl;



		return 0;
}




Measured memory_bytes: 4736
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    int K;
    string S;
    read(K, S);
    if(S.size() > K){
        S = S.substr(0, K);
        S += "...";
    }
    write(S);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

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

drink = []
for _ in range(n):
   a, b = map(int, input().split())
   drink.append([a, b])

drink.sort()

x = 0
ans = 0
for a, b in drink:
   if (x + b <= m):
      ans += a * b
      x += b
   else:
      y = m - x
      ans += a * y
      break

print(ans)


Measured memory_bytes: 20064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}


void cerrall(const vector<bool>& a){rep(i,a.size()) cerr << i << " " << (a[i]? "True" : "False") << "\n"; cerr << "\n";}
template<class T> void cerrall(const vector<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const set<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const multiset<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T, class U> void cerrall(const vector<pair<T,U>>& a){rep(i,a.size()) cerr << i << " : " << a[i].first << " " << a[i].second << "\n";}
template<class T, class U> void cerrall(const map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}
template<class T, class U> void cerrall(const unordered_map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}

template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}

template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int a,b,c,d,e;cin >> a >> b >> c >> d >> e;
    b += 60 * a;
    d += c * 60;
    int ans = d - b - e;
    chmax(ans, 0);
    cout << ans << endl;
}

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

public class Main {
 
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        Set<String> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.add(s[i]);
        }
        System.out.println(set.size());
    }
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    
    public boolean hasNext() { 
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();
    }
    
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

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

int main() {
  int K, S;
  cin >> K >> S;
  int res = 0;
  
  for(int x=0; x<=K; x++) {
    for(int y=0; y<=K; y++) {
      int z = S - x - y;
      if(0 <= z && z <= K) res++;
      }
    }
  cout << res << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define N 20005
int a[N],b[N];
int n,p[N];
int main(){
	scanf("%d",&n);
	for(int i=1,v;i<=n;i++) scanf("%d",&v),p[v]=i;
	int la=1,lb=0;
	for(int i=1;i<=n;i++){
		int x=max(la,p[i]-lb),y=min(lb,p[i]-la);
		a[i]=x,b[i]=y;
		la=a[i]+1,lb=b[i]-1;
	}
	int mn=1e9;
	for(int i=1;i<=n;i++) mn=min(mn,a[i]);
	for(int i=1;i<=n;i++) a[i]-=mn-1;
	mn=1e9;
	for(int i=1;i<=n;i++) mn=min(mn,b[i]);
	for(int i=1;i<=n;i++) b[i]-=mn-1;

	for(int i=1;i<=n;i++) printf("%d ",a[i]);puts("");
	for(int i=1;i<=n;i++) printf("%d ",b[i]);puts("");
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;

int main(void){
   int a, b, c;
   cin >> a >> b >> c;
   int ans[11];
   ans[0]=c;
   for(int i = 0; i < 10; i++){
    ans[i+1] = a*ans[i]-b;
    cout << ans[i+1] << endl;
   }
    return 0;
}

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

int main(){
    ll a,b,c;cin >> a >> b >> c;
    if(a+b>=c)cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

p = []
q = []

for i in range(m):
    l, r = map(int,input().split())
    p.append(l)
    q.append(r)

p1 = max(p)
q1 = min(q)


if q1 >= p1:
    print(q1 - p1 + 1)
else:
    print(0)

Measured memory_bytes: 10996
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

int bc(int x) {
  return __builtin_popcount(x);
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  VL l(n);
  REP(i, 0, n) cin >> l[i];
  VI p(n);
  REP(i, 0, n) p[i] = i;
  ll mi = 1e18;
  REP(s, 1, 1 << n) {
    REP(t, 1, 1 << n) {
      if (s & t) continue;
      REP(u, 1, 1 << n) {
        if (s & u) continue;
        if (t & u) continue;
        ll tmp = 0;
        ll k = 0;
        REP(i, 0, n) if (s & 1 << i) k += l[i];
        tmp += abs(k - a);
        k = 0;
        REP(i, 0, n) if (t & 1 << i) k += l[i];
        tmp += abs(k - b);
        k = 0;
        REP(i, 0, n) if (u & 1 << i) k += l[i];
        tmp += abs(k - c);
        tmp += 10 * (bc(s) + bc(t) + bc(u) - 3);
        mi = min(mi, tmp);
      }
    }
  }
  cout << mi << endl;
}


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

int main() {
  string n;
  cin >> n;
  for(int i =0 ; i<3 ; i++){
    if(n.at(i) == '1'){
      n.at(i) = '9';
    }
    else {
      n.at(i) = '1';
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    ll h, w;
    cin >> h >> w;

    ll odd_row = floor(1.0 * (w + 1) / 2);
    ll even_row = floor(1.0 * w / 2);

    ll ret = 0;
    ret += h / 2 * (odd_row + even_row);
    if((h%2) == 1)
    {
        ret += odd_row;
    }

    if(h == 1 || w == 1)
    {
        ret = 1;
    }
    cout << ret << endl;


}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int A = sc.nextInt();
   int B = sc.nextInt();
   
   if((A-1)%(B-1)==0) System.out.println((A-1)/(B-1));
   else System.out.println(((A-1)/(B-1))+1);
 }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x,m;

main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE    
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout); 
    #endif

    cin>>n>>x>>m;
    x%=m;
    vector<ll>a;
    map<ll,int>lookup;
    ll cycle=-1;
    for(int i=1;i<=min(n,m+5);i++){
        if(lookup[x]){
            cycle=x;
            break;
        }
        a.push_back(x);
        lookup[x]++;
        x*=x;x%=m;
    }

     ll sum=0;
    if(cycle==-1){
        for(int i=0;i<n;i++){
            sum+=a[i];
        }
        cout<<sum<<"\n";
        return 0;
    }

    int k=0,start;
    for(int i=0;i<n;i++){
        if(a[i]==cycle){
            start=i;
            break;
        }
        sum+=a[i];
        k++;
    }
    n-=k;
    
    ll cyclesum=0,len=0;
    for(int i=start;i<a.size();i++) cyclesum+=a[i],len++;
    sum+=(n/len)*cyclesum;
    n%=len;
    while(n--){
        sum+=a[start++];
    }
    cout<<sum<<"\n";
}       

Measured memory_bytes: 6680
import java.util.Scanner;
public class Main {
	
	public static int d;
	public static int g;
	public static int[] p;
	public static int[] c;
	public static int[] s;
	public static int ans;
	
	public static void dfs( int n, int sum, int num, int s1 ) {
		if( n == d ) {
			if( sum < g ) {
				int need = (int)Math.ceil((double)(g - sum)/(100 * (s1+1)));
				if( need < p[s1] )
					ans = Math.min(ans, num+need);
			}
			else
				ans = Math.min(ans, num);
		}
		else {
			sum += s[n];
			num += p[n];
			dfs(n+1, sum, num, s1);
			sum -= s[n];
			num -= p[n];
			s1 = n;
			dfs(n+1, sum, num, s1);
		}
	}
	
	public static void main(String args[] ) {
		Scanner sc = new Scanner(System.in);
		
		d = sc.nextInt();
		g = sc.nextInt();
		p = new int[d];
		c = new int[d];
		s = new int[d];
		
		for( int i = 0; i < d; i++ ) {
			p[i] = sc.nextInt();
			c[i] = sc.nextInt();
			s[i] = p[i] * 100 * (i+1) + c[i];
		}
		
		ans = 0;
		for( int i = 0; i < d; i++ )
			ans += p[i];
		
		dfs( 0, 0, 0, 0 );
		System.out.println( ans );
		
		sc.close();
	}
}

Measured memory_bytes: 35736
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
using namespace std;

int main(){
  string S;
  cin>>S;
  int sum=0;
  for(int i=0; i<S.size(); ++i){
    if(S.at(i)=='x') sum++;
  }
  if(sum>=8) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a,b;

	scanf("%d %d", &a, &b);

	if(a < b)
	{
		printf("a < b\n");
	}
	else if(a > b)
	{
		printf("a > b\n");
	}
	else
	{
		printf("a == b\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskGC solver = new TaskGC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskGC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();

            int[] inp = new int[n];
            for (int i = 0; i < n; i++) {
                inp[i] = in.nextInt();
            }

            int[] sorted = new int[n];
            for (int i = 0; i < n; i++) {
                sorted[i] = inp[i];
            }
            Arrays.sort(sorted);

            int numOps = 0;
            for (int i = 0; i < n; i++) {
                int a = inp[i];
                int idx = Arrays.binarySearch(sorted, a);

                int diff = Math.abs(idx - i);
                if (diff % 2 != 0) {
                    numOps++;
                }
            }
            out.println(numOps / 2);
        }
    }
}


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

int main() {
    int N; cin >> N;
    vector<int> a(N); for (int i = 0; i < N; ++i) cin >> a[i], --a[i];
    int res = 0;
    for (int i = 0; i < N; ++i) {
        if (a[a[i]] == i) ++res;
    }
    cout << res/2 << endl;
}

Measured memory_bytes: 640
from sys import exit
# import copy
# import numpy as np
# from collections import deque


n, = map(int, input().split())

cnt = [0, 0, 0, 0]
for _ in range(n):
    tmp = input()
    if tmp == "AC":
        cnt[0] += 1
    elif tmp == "WA":
        cnt[1] += 1
    elif tmp == "TLE":
        cnt[2] += 1
    elif tmp == "RE":
        cnt[3] += 1

print("AC x", cnt[0])
print("WA x", cnt[1])
print("TLE x", cnt[2])
print("RE x", cnt[3])


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

bool palin(string s)
{
    string bb = s;
    reverse(bb.begin(), bb.end());
    if (bb.compare(s) == 0)
        return true;
    return false;
}

int main()
{
    string s;
    cin >> s;
    if (palin(s) && palin(s.substr(0, s.size() / 2)) && palin(s.substr(s.size() / 2 + 1, s.size())))
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    return 0;
    
}

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

int main(){
    int n; cin >> n;
    int x[110];
    int mid=0,mid2=0;
    rep(i,n){
        cin >> x[i];
        mid+=x[i];
    }
    mid=(mid/n);
    mid2=mid+1;
    int res=0,res2=0;
    rep(i,n){
        res+=(x[i]-mid)*(x[i]-mid);
        res2+=(x[i]-mid2)*(x[i]-mid2);
    }
    cout << min(res,res2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 1000000007
using namespace std;
typedef long long ll;

int main(){
  int N, M;
  cin >> N >> M;
  vector<string> A(N), B(M);
  bool exist = false;
  rep(i, 0, N)  cin >> A[i];
  rep(i, 0, M)  cin >> B[i];

  for (int ly = 0; ly + M <= N; ly++) {
		for (int lx = 0; lx + M <= N; lx++) {
			bool match = true;
			for (int y = 0; y < M; y++) {
				for (int x = 0; x < M; x++) {
					if (A[ly+y][lx+x] != B[x][y]) {
						match = false;
					}
				}
			}
      if(match)  exist=true;
      
    }
  }

  if(exist) cout << "Yes" << endl;
  else  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256