akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n, k, c; cin >> n >> k >> c;
    string s; cin >> s;
    vector<int> l(n), r(n);
    for (int i = 0, j = 1; i < n && j <= k; i++) {
        if (s[i] == 'o') {
            l[i] = j++;
            i += c;
        }
    }
    for (int i = n - 1, j = k; i >= 0 && j > 0; i--) {
        if (s[i] == 'o') {
            r[i] = j--;
            i -= c;
        }
    }
    for (int i = 0; i < n; i++) {
        if (l[i] && l[i] == r[i]) {
            cout << i + 1 << endl;
        }
    }
    return 0;
}


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

#define PI 3.1415926535897

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    
    double a, b, h, m;
    cin>>a>>b>>h>>m;
    double ah = h*(360/12)+m/2;
    double am = m*(360/60);
    double ang = min(abs(ah-am), 360-abs(ah-am));
    // cout<<ang<<endl;
    double ans = sqrt(a*a+b*b-2*a*b*cos(ang*(PI/180.0)));
    cout<<setprecision(12)<<ans;
    return 0;
}

Measured memory_bytes: 4244
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (int i = n-1; i > -1; i-=2) {
    cout << a[i] << " ";
  }
  if (a.size()%2 == 0) {
    for (int i = 0; i < n-1; i +=2) {
      if (i!=n-2) {
        cout << a[i] << " ";
      }
      else {
        cout << a[i];
      }
    }
  }
  else {
    for (int i = 1; i < n-1; i+=2) {
      if (i!=n-2) {
        cout << a[i] << " ";
      }
      else {
        cout << a[i];
      }
    }
  }
}

Measured memory_bytes: 3968
#define _ 2<<17
A[_];long P[_],M=1e9+7,F[_],I[_]={1},X;i,j,k,t;c(a,b)int*a,*b;{t=*a-*b?:a[1]-b[1];}p(a,b){return b?p(a%M*a%M,b/2)*(b%2?a:1L)%M:1;}f(a,b){return F[a+b]*I[a]%M*I[b]%M;}main(s){for(;++X<_;)I[X]=p(s=F[X]=X*s%M,M-2);for(;~scanf("%d",A+i);)i++-1||gets(P);for(qsort(A,i/2,8,c);i/(j+=2);P[j]=X)for(X=f(s=A[k=j-2]-=1,t=A[j-1]-=1);(k-=2)>=0;)X=t<A[k+1]?X:(X-f(s-A[k],t-A[k+1])*P[k+2]%M+M)%M;printf("%d",X);}

Measured memory_bytes: 6396
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int N, K;
	cin >> N >> K;
	VVI xy(4*K,VI(4*K,0));
	REP(i, N) {
		ll xx, yy;
		string cc;
		cin >> xx >> yy >> cc;
		if (cc == "W") xx += (ll)K;
		xx %= (ll)(2 * K);
		yy %= (ll)(2 * K);
		xy[(int)xx][(int)yy]++;
		xy[(int)xx+ 2 * K][(int)yy]++;
		xy[(int)xx][(int)yy+2 * K]++;
		xy[(int)xx + 2 * K][(int)yy + 2 * K]++;
	}

	//cout << endl;
	//REP(i, 4 * K) {
	//	REP(j, 4 * K) {
	//		cout << xy[j][4 * K - 1 - i] << " ";
	//	}
	//	cout << endl;
	//}
	//cout << endl;
	REP(i, 4 * K) FOR(j, 1, 4 * K) xy[i][j] += xy[i][j - 1];
	FOR(i, 1, 4 * K) REP(j, 4 * K) xy[i][j] += xy[i - 1][j];
	//REP(i, 4 * K) {
	//	REP(j, 4 * K) {
	//		cout << xy[j][4 * K - 1 - i] << " ";
	//	}
	//	cout << endl;
	//}
		
	int maxs = xy[K - 1][K - 1] + xy[2 * K - 1][2 * K - 1] - xy[2 * K - 1][K - 1] - xy[K - 1][2 * K - 1] + xy[K - 1][K - 1];
	FOR(i, 1, 2 * K) maxs = max(maxs, (xy[i + K - 1][K - 1] - xy[i - 1][K - 1]) + (xy[i + 2 * K - 1][2 * K - 1] - xy[i + K - 1][2 * K - 1] - xy[i + 2 * K - 1][K - 1] + xy[i + K - 1][K - 1]));
	FOR(j, 1, 2 * K) maxs = max(maxs, (xy[K - 1][j + K - 1] - xy[K - 1][j - 1]) + (xy[2 * K - 1][j + 2 * K - 1] - xy[2 * K - 1][j + K - 1] - xy[K - 1][j + 2 * K - 1] + xy[K - 1][j + K - 1]));

	
	FOR(i, 1, 2 * K) {
		FOR(j, 1, 2 * K) {
			int s1 = xy[i + K - 1][j + K - 1] - xy[i - 1][j + K - 1] - xy[i + K - 1][j - 1] + xy[i - 1][j - 1];
			int s2 = xy[i + 2 * K - 1][j + 2 * K - 1] - xy[i + K - 1][j + 2 * K - 1] - xy[i + 2 * K - 1][j + K - 1] + xy[i + K - 1][j + K - 1];
			maxs = max(maxs,s1 + s2);
		}
	}
	cout << maxs << endl;	
	//cin >> N >> K;
}


Measured memory_bytes: 64896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define traceloop(x,a) {for(ll i=0;i<x;i++) cerr<<a[i]<<" "; cerr<<endl;}
ll ab(ll x) {return x>0LL?x:-x;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll a,b;
	cin>>a>>b;
	if(a==b)
	{
		for(int i=0; i<a; i++)
			cout<<a;
	}
	else
	{
		if(a<b)
		{
			for(int i=0; i<b; i++)
			cout<<a;
		}
		else
		{
			for(int i=0; i<a; i++)
			cout<<b;
		}
	}
	return 0;
}
	

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

int cmpnum(const void *n1,const void *n2){
	return *(int*)n1-*(int*)n2;
}

int main(void){
	int N,K,i;
	scanf("%d %d",&N,&K);
	int p[N];
	for(i=0;i<N;i++) scanf("%d",&p[i]);
	qsort(p,N,sizeof(int),cmpnum);
	int ans=0;
	for(i=0;i<K;i++) ans+=p[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define INF (1 << 20)
int N;
int L[8];
int B[3];

struct Banboo {
  int total;
  int count;
  Banboo() {
    total = 0;
    count = 0;
  }
};

int calc(int *V) {
  Banboo R[4];
  for (int i = 0; i < N; ++i) {
    R[V[i]].total += L[i];
    ++R[V[i]].count;
  }
  if (R[0].count == 0 || R[1].count == 0 || R[2].count == 0) {
    return INF;
  }
  int ret = 0;
  for (int i = 0; i < 3; ++i) {
    ret +=abs(R[i].total-B[i]) + (R[i].count-1) * 10;
  }
  return ret;
}

void bfs(int n, int *V, int &ans) {
  if (n == N) {
    int ret = calc(V);
    ans = min(ans,ret);
  } else {
    for (int i = 0; i < 4; ++i) {
      V[n] = i;
      bfs(n + 1,V,ans);
    }
  }
}

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

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

  int ans = INF;
  int V[8];
  bfs(0, V, ans);

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
a = list()
for i in range(n):
	a.append(list(map(int, input().split())))
b = list()
for i in range(m):
	b.append(int(input()))
for i in range(n):
	ans = 0
	for j in range(m):
		ans += a[i][j] * b[j]
	print(ans)



Measured memory_bytes: 6012
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int t = n;
    int x = 0;
    while(t>0){
        x+=t%10;
        t/=10;
    }
    if(n%x==0){
        puts("Yes");
    }else{
        puts("No");
    }

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  vector<int> c(3,0);
  int N = s.size();
  for (int i = 0; i < N; i++) {
    c[s[i]-97] += 1;
  }
  if (abs(c[0]-c[1]) < 2 && abs(c[0]-c[2]) < 2 && abs(c[1]-c[2]) < 2) {
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if (a <= b && c <= b)
    {
        printf("%d\n", a + c);
    }
    else if (b <= a && c <= a)
    {
        printf("%d\n", b + c);
    }
    else
    {
        printf("%d\n", a + b);
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

ll tree[1 << 19];
int n;

void update(int p, ll val) {
 for(tree[p += n] = val; p > 0; p >>= 1)
   tree[p >> 1] = max(tree[p], tree[p ^ 1]);
  
  return ;
}

ll query(int l, int r) {
  ll res = 0;
  for(l += n, r += n; l <= r; l >>= 1, r >>= 1) {
	if(l & 1) res = max(tree[l++], res);
    if(!(r & 1)) res = max(tree[r--], res);
  }
  
  return res;
}

int A[200000];
ll B[200000];

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i)
    cin >> A[i];
  for(int i = 0; i < n; ++i)
    cin >> B[i];
  
  for(int i = 0; i < n; ++i) {
  	ll add = query(1, A[i]);
    update(A[i], B[i] + add);
  }
  
  cout << tree[1];
  return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);++i)

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")

#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")

int main(void){
  int H,W,K,black=0,ans=0,bith,bitw;
  cin >> H >> W>>K;
  char c[H][W],tmp[H][W];
  vector<int>h(H),w(W);
  rep(i,H){
    rep(j,W){
      cin>>c[i][j];
    }
  }

  for (bith=0; bith < (1<<H); ++bith) {    
    for(bitw=0;bitw < (1<<W); ++bitw){//W
      for (int i = 0; i < W; ++i) {
	if (bitw & (1<<i)) 
	  w.at(i)=1;
	else
	  w.at(i)=0;
      }
      for (int i = 0; i < H; ++i) {//H
	if (bith & (1<<i)) 
	  h.at(i)=1;
	else
	  h.at(i)=0;
      }
    
      rep(i,H){//write	
	rep(j,W){
	  if(1==h.at(i))
	    tmp[i][j]='%'; //red
	  else if(1==w.at(j))
	    tmp[i][j]='%';
	  else
	    tmp[i][j]=c[i][j];
	}
      }
      rep(i,H){//distingish
	rep(j,W){
	  if(tmp[i][j]=='#')black++;
	  //cout<< tmp[i][j];	
	}
	//cout <<endl;
      }
      if(black==K)ans++;//count
      black=0;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3624
unittest
{
	assert( [ "2", "3 4" ].parse.expand.solve == "3.50000" );
	assert( [ "3", "500 300 200" ].parse.expand.solve == "375.00000" );
	assert( [ "5", "138 138 138 138 138" ].parse.expand.solve == "138.00000" );
}



import std.conv;
import std.container;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto vs = input.front.split.to!( double[] );
	return tuple( vs );
}

auto solve( double[] vs )
{
	auto queue = heapify!( ( a, b ) => b < a )( vs );
	while( 2 <= queue.length )
	{
		auto a = queue.front;
		queue.popFront;
		auto b = queue.front;
		queue.popFront;
		queue.insert( ( a + b ) / 2 );
	}
	return format( "%0.5f", queue.front );
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,i,r=0;
  string s;
  cin>>n;
  cin>>s;
  for(i=0;i<n;i++){
    if(s[i]=='R') r++;
  }
  if(r>(n-r)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

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

    int amax = *max_element(a.begin(), a.end());

    bool valid = true;
    if(amax % 2){
        int half = amax / 2 + 1;
        for(int i=half; i<=amax; i++){
            if(2 <= cnt[i]) cnt[i] -= 2;
            else valid = false;
        }

        for(int i=1; i<=half; i++){
            if(0 < cnt[i]) valid = false;
        }
    }
    else{
        int half = amax / 2;
        if(1 <= cnt[half]) cnt[half]--;
        else valid = false;

        for(int i=half+1; i<=amax; i++){
            if(2 <= cnt[i]) cnt[i] -= 2;
            else valid = false;
        }

        for(int i=1; i<=half; i++){
            if(0 < cnt[i]) valid = false;
        }
    }

    if(valid) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  #define int long
  #define pi pair<int,int>
  int n,m,inp;
  cin>>n>>m;
  auto func=[](int a,int b){return a>b;};
  priority_queue<int,vector<int>,decltype(func)> que(func);
  vector<pi> b(m);
  for(int i=0;i<n;++i){
    cin>>inp;
    que.push(inp);
  }
  for(int i=0;i<m;++i)cin>>b[i].first>>b[i].second;
  sort(b.begin(),b.end(),[](pi a,pi b){return a.second>b.second;});
  int cnt=0;
  for(int i=0;cnt<n&&que.top()<b[i].second&&i<m;++i){
    for(int j=0;j<b[i].first&&que.top()<b[i].second;++j){
      que.pop();
      que.push(b[i].second);
    }
  }
  int sum=0;
  while(!que.empty()){
    sum+=que.top();
    que.pop();
  }
  cout<<sum;
  return 0;
}

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

using namespace std;

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

  int a, odd = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a % 2) {
      odd++;
    }
  }

  if (odd % 2) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }

  return 0;
}

Measured memory_bytes: 384
/************************************************
*Author        :  lrj124
*Created Time  :  2019.08.04.19:51
*Mail          :  1584634848@qq.com
*Problem       :  a
************************************************/
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main() {
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%d%d%d",&a,&b,&c);
	printf("%d",max(0,b+c-a));
	//cerr << 1.0*clock()/CLOCKS_PER_SEC << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n; cin >> n;
    while (n) {
        if (n % 10 == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
package main

import (
	"fmt"
)

type Node struct {
	p, l, r int
}

const NIL = -1

var n, id, l, r int

func main() {
	fmt.Scan(&n)

	nodes := make([]Node, n)
	for i := 0; i < n; i++ {
		nodes[i].p = NIL
	}

	for i := 0; i < n; i++ {
		fmt.Scan(&id)
		fmt.Scan(&l)
		fmt.Scan(&r)

		nodes[id].l = l
		nodes[id].r = r

		if l != NIL {
			nodes[l].p = id
		}
		if r != NIL {
			nodes[r].p = id
		}
	}

	//nodesができたのでrootを探す
	root := -1
	for i := 0; i < n; i++ {
		if nodes[i].p == NIL {
			root = i
			break
		}
	}

	//Preorder
	fmt.Println("Preorder")
	preParse(nodes, root)
	fmt.Println("")
	//Inorder
	fmt.Println("Inorder")
	inParse(nodes, root)
	fmt.Println("")
	//Postorder
	fmt.Println("Postorder")
	postParse(nodes, root)
	fmt.Println("")

}

func preParse(nodes []Node, u int) {
	if u == NIL {
		return
	}

	fmt.Printf(" %d", u)
	preParse(nodes, nodes[u].l)
	preParse(nodes, nodes[u].r)
}

func inParse(nodes []Node, u int) {
	if u == NIL {
		return
	}

	inParse(nodes, nodes[u].l)
	fmt.Printf(" %d", u)
	inParse(nodes, nodes[u].r)
}

func postParse(nodes []Node, u int) {
	if u == NIL {
		return
	}

	postParse(nodes, nodes[u].l)
	postParse(nodes, nodes[u].r)
	fmt.Printf(" %d", u)
}



Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n % k;
  cout << min(a, k - a) << endl;
  return(0);
}


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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    int cnt = 0;
    for (int i = 1; i <= N; i++) {
        if (to_string(i).length() % 2 == 1) {
            cnt ++;
        }
    }
    cout << cnt << endl;
    
    return 0;
}

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

int main() {
    ll N,M;cin >> N >> M;
    ll A[M] = {};
    ll sum = 0;
    for (int i = 0;i < M;i++) {
        cin >> A[i];
        sum += A[i];
    }
    ll res = N - sum;
    if (res >= 0) cout << res << endl;
    else cout << -1 << endl;
}

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

using namespace std;

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

    int n, k, x, y;

    cin >> n >> k >> x >> y;
    if (n <= k)
        cout << x * n << endl;
    else
        cout << x * k + y * (n - k) << endl;

    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vi a(n);
  ll sum = 0;
  rep(i,n){
    cin >> a[i];
    sum += a[i];
  }
  ll x = sum, y = 0;
  ll ans = infll;
  rep(i,n-1){
    x -= a[i];
    y += a[i];
    ans = min(ans, abs(x-y));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


string S;


string subS(int begin, int end){
	string sub;
	rep(i, begin, end) sub.pb(S[i]);
	return sub;
}


bool judge(int& pos){
	string sub;
	if(pos+7 <= SIZE(S)){
		sub = subS(pos, pos+7);
		if(sub == "remaerd") return pos+=7, true;
		sub.erase();
	}
	if(pos+6 <= SIZE(S)){
		sub = subS(pos, pos+6);
		if(sub == "resare") return pos+=6, true;
		sub.erase();
	}
	if(pos+5 <= SIZE(S)){
		sub = subS(pos, pos+5);
		if(sub == "maerd" || sub == "esare") return pos+=5, true;
	}
	return false;
}


bool solve(){
	reverse(ALL(S));
	int pos = 0;
	while(pos != SIZE(S))
		if(!judge(pos)) return false;
	return true;
}


signed main(){
	cin >> S;

	if(solve()) YES;
	else NO;

	return 0;
}

Measured memory_bytes: 512
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
        
    elif m==-1 or f==-1:
        print('F')
    elif m+f>=80:
        print("A")
    elif m+f>=65:
        print("B")
    elif m+f>=50 or (r>=50 and m+f>=30):
        print('C')
    elif m+f>=30:
        print("D")
    elif m+f<30 :
        print("F")
    
    
        
        

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

int main(){
    int n, m;
    cin >> n >> m;
    int k[m], s[10][10];
    rep(i, m){
        cin >> k[i];
        rep(j, k[i]){
            cin >> s[i][j];
        }
    }
    int p[m];
    rep(i, m){
        cin >> p[i];
    }

    int ans = 0;
    bool ok;
    rep(iii, (int)pow(2, n)){
        ok = true;
        int ss[n];
        int ii = iii;
        rep(i, n){
            ss[i] = ii%2;
            ii/=2;
        }
        
        rep(i, m){
            int c = 0;
            rep(j, k[i]){
                if(ss[s[i][j]-1]==1){
                    c++;
                }
            }
            if((p[i]-c)%2!=0){
                ok = false;
                break;
            }
        }
        if(ok){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for(ll i = 0; i < (n); i++)
#define fori(i, b, e) for(ll i = (b); i < (e); i++)
#define forr(i, b, e) for(ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>
#define Matd vector<vector<ld>>
#define Arrd vector<ld>

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    Arr a(n);
    forn(i, n) cin >> a[i];
    ll mx = *max_element(allele(a));
    ll cnt = count_if(allele(a), [mx](ll x)->bool{
        return (x == mx);
    });
    Arr b(a);
    sort(allele(b), greater<ll>());
    ll scd = b[1];
    forn(i, n) cout << (cnt == 1 && a[i] == mx ? scd : mx) << endl;
    return 0;
}

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


int main(){
    int n, tmp = 0;
    string s;
    cin >> n >> s;

    vector<int> es(n,0);
    rep(i,n){
        if(s[i] == 'E') tmp++;
        es[i+1] = tmp;
    }

    int ans = n;
    rep(i,n){
        int e, w;
        w = i - es[i];
        e = es[n] - es[i+1];
        ans = min(ans, w+e);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1796
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>  
#include<cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include<map>
#include<algorithm>
#include<functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<climits>
#include<typeinfo>
#include<utility>
#define LEN 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}

//cout << fixed << setprecision(10)



int main() {
	
	int n, k;
	cin >> n >> k;
	vector<int>d(k);
	vector<int>sunuke(n);
	
	int tmp;
	for (int i = 0;i < k;i++) {
		cin >> d[i];
		for (int j = 0;j < d[i];j++) {
			cin >> tmp;
			sunuke[tmp-1] = sunuke[tmp-1] + 1;
		}
	}
	int ans = 0;
	for (int i = 0;i < n;i++) {
		if (sunuke[i] == 0)ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3632
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;

void SharingCookies(){
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}

}

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



Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int n;cin>>n;vector<int> v(n);rep(i,0,n)cin>>v[i];
    int m;cin>>m;vector<int> vv(m);rep(i,0,m)cin>>vv[i];

    rep(i,0,min(n,m)){
        if(v[i]<vv[i]){
            cout<<1<<endl;
            return 0;
        }else if(v[i]>vv[i]){
            cout<<0<<endl;
            return 0;
        }
    }
    cout<<((n>=m)?0:1)<<endl;
}



/*
1 2 3 4 5

6
*/



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define endl '\n'
#define F first
#define S second
typedef pair<int,int> pii;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int r,d,x; cin>>r>>d>>x;
	int cnt = 10;
	ll op = x*1ll;
	while(cnt--){
		op = r*op -d; 
		cout<<op<<endl;
	}
	return 0;
}


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

A, B, C, X, Y = [int(x) for x in input().strip().split()]
ans = 0

if A > 2*C and B > 2*C:
    print(max(X, Y) * 2 * C)
else:
    if (A + B) >= 2 * C:
        minXY = min(X, Y)
        ans += minXY * 2 * C
        X -= minXY
        Y -= minXY
    if X:
        if A < 2 * C:
            ans += X * A
        else:
            ans += X * 2 * C
    if Y:
        if B < 2 * C:
            ans += Y * B
        else:
            ans += Y * 2 * C
    print(ans)
        


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        int N=gi();
        long s=0;
        for (int i=1; i<=N;i++) {
        	if(i%3!=0 && i%5!=0) {
        		s+=i;
        	}
        }

        System.out.println(s);
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35736
#include <bits/stdc++.h>
using namespace std;
int main(){
	vector<char> vec(6);
	for (int i = 0; i < 6; i++) {
		cin >> vec.at(i);
	}
	if(vec.at(2) == vec.at(3) && vec.at(4) == vec.at(5)){
		cout << "Yes";
    } else {
		cout << "No";
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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




Measured memory_bytes: 3568
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int H, W, N;
int a[10010];
int board[110][110];
signed main() {
    cin >> H >> W >> N;
    rep(i,0,N) cin >> a[i];

    int x = 0, y = 0, mo = 0;
    rep(i,0,N) {
        while(a[i]--) {
            // printf("i = %lld, x = %lld, y = %lld, mo = %lld\n", i, x, y, mo);
            board[x][y] = i+1;
            if(y == W-1 && mo == 0) x++, mo ^= 1;
            else if(y == 0 && mo == 1) x++, mo ^= 1;
            else if(mo % 2) y--;
            else y++;
        }
    }

    rep(i,0,H) {
        rep(j,0,W) {
            cout << board[i][j] << (j != W-1 ? " " : "");
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
	
    int n, i, ans = 0, cnt = 0;
    char s[110];
    cin >> n;
    REP(i, n) cin >> s[i];

    map<char, int> mp;

    for(i = 1; i < n; i++){
        cnt = 0;
        mp.clear();
        for(int j = 0; j < i; j++){
            mp[s[j]]++;
        }
        for(int j = i; j < n; j++){
            if(mp[s[j]] > 0) cnt++, mp[s[j]] = 0;
        }
        ans = max(ans, cnt);
    }

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int dp[1001];
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,W;
	int i,j;
	int c=1;
	while(1){
	scanf("%d",&W);
	if(W==0)return 0;
	scanf("%d",&n);
	for(i=0;i<=W;i++)dp[i]=-1;
	dp[0]=0;
	for(i=0;i<n;i++){
		int w,v;
		scanf("%d,%d",&v,&w);
		for(j=W-w;j>=0;j--){
			dp[j+w]=max(dp[j+w],dp[j]+v);
		}
	}
	int m=0;
	for(i=1;i<=W;i++){
		if(dp[i]>dp[m])m=i;
	}
	printf("Case %d:\n",c);
	printf("%d\n%d\n",dp[m],m);
	c++;
	}
}

Measured memory_bytes: 1032
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#include <complex>
using namespace std;
using VI = vector<int>;

int main() {
    int n, k;
    cin >> n >> k;
    VI ls(n);
    for (int i = 0; i < n; i++) {
        cin >> ls[i];
    }
    sort(ls.begin(), ls.end(), greater<>());
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += ls[i];
    }
    cout << ans << endl;
}


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

int main() {
	int n,dmin;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int num,d = 0;
		cin >> num;
		while (!(num % 2)) {
			num /= 2;
			d++;
		}
		if (!i || (dmin > d)) { dmin = d; }
	}
	cout << dmin << endl;
}

Measured memory_bytes: 3552
N = input()

A = []
for i in N:
    A.append(i)

cnt = 0
j = 0
while len(A) >= 2 and len(A)-1 > j:
    if A[j] != A[j+1]:
        cnt = cnt + 2    
        del A[j]
        del A[j]
        if j != 0:
            j -= 1
    else:
        j += 1

print(cnt)

Measured memory_bytes: 3956
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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);
    B solver = new B();
    solver.solve(1, in, out);
    out.close();
  }

  static class B {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int N = in.nextInt();
      int R = in.nextInt();
      int r = 0;

      for (int i = 0; i < R; i++) {
        r += in.nextInt();
      }

      int res = N - r;
      if (res >= 0) {
        out.print(res);
      } else {
        out.print(-1);
      }
    }

  }
}



Measured memory_bytes: 46264
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 5000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(){
    int n; cin>>n;
    vector<int> p(n),q(n);
    rep(i,n){
        cin>>p.at(i);
        q.at(p.at(i)-1)=i;
    }
    q.push_back(-1);
    int ans=0,cnt=0;
    rep(i,n){
        cnt++;
        if(q.at(i)>q.at(i+1)){
            chmax(ans, cnt);
            cnt=0;
        }
    }
    cout<<n-ans<<endl;
}

Measured memory_bytes: 6400
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int INF = 1<<27;
const int MAX = 51;
 
int dis_d[MAX][MAX],in,s,d,G[MAX];
int min_d[MAX];
bool used[MAX];
 
int prim(){
    for(int i = 0 ; i < d ; i++){
	min_d[i] = INF;
	used[i] = false;
    }
 
    min_d[0] = 0;
    int res = 0;
 
    while(true){
	int v = -1;
 
	for(int u = 0 ; u < d ; u++){
	    if(!used[u] && (v == -1 || min_d[u] < min_d[v])) v = u;
	}
 
	if(v == -1) break;
	used[v] = true;
	res += min_d[v];
 
	for(int u = 0 ; u < d ; u++){
	    min_d[u] = min(min_d[u],dis_d[v][u]);
	}
    }
 
    return res;
}
 
int main(){
    while(cin >> s >> d , s + d){
	fill(G,G+MAX,INF);
 
	for(int i = 0 ; i < s ; i++){
	    for(int j = 0 ; j < d ; j++){
		cin >> in;
		if(!in) continue;
		G[j] = min(G[j],in);
	    }
	}
	fill(dis_d[0],dis_d[MAX],INF);
 
	for(int i = 0 ; i < d ; i++){
	    dis_d[i][d] = dis_d[d][i] = G[i];
	}    
 
	for(int i = 0 ; i < d-1 ; i++){
	    for(int j = i + 1 ; j < d ; j++){
		cin >> in;
		if(!in) continue;
		dis_d[i][j] = dis_d[j][i] = in;
	    }
	}       
	d++;
	cout << prim() << endl;
    }
    return 0;
}

Measured memory_bytes: 3048
def dfs(L,i,j):
    if L[i][j] > 0:
        L[i][j] = 0
    else:
        return

    for k in [-1, 1]:
        ni = i + k
        if ni not in range(12):
            continue
        if L[ni][j] > 0:
            dfs(L, ni, j)

    for k in [-1, 1]:
        nj = j + k
        if nj not in range(12):
            continue
        if L[i][nj] > 0:
            dfs(L, i, nj)
    return

while True:
    L = []
    try:
        for _ in range(12):
            L.append( [int(x) for x in input()] )
    except:
        break

    c = 0
    for i in range(12):
        for j in range(12):
            if L[i][j]  > 0:
                c += 1
                dfs(L, i, j)
    print(c)
    try:
        input()
    except:
        break



Measured memory_bytes: 5616
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int sum;
		
		n = sc.nextInt();
		while (n != 0) {
			sum = 0;
			for (int i = 0; i < n / 4; i++) {
				sum += sc.nextInt();
			}
			System.out.println(sum);
			n = sc.nextInt();
		}
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

    vector<int> a(4);
    int org_data[] = {1,4,7,9};      // 元データ
    std::vector<int> data(org_data, std::end(org_data));  

    for(int i=0; i<4;i++){
    cin >> a[i];
    }
    sort(a.begin(),a.end());
    if(a==data){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

#define ld long double
#define int long long
struct vec{
	int x , y;
	vec(int _x = 0 , int _y = 0) : x(_x) , y(_y){}
	ld ang(){return atan2(y , x);}
	friend vec operator +(vec x , vec y){return vec(x.x + y.x , x.y + y.y);}
	friend vec operator -(vec x , vec y){return vec(x.x - y.x , x.y - y.y);}
	friend int operator %(vec x , vec y){return x.x * y.y - x.y * y.x;}
}now[103]; int N , id[103]; long double ans[103];

int stk[103] , in[103] , top , cnt;
void hull(){
	for(int i = 1 ; i <= N ; ++i) id[i] = i;
	sort(id + 1 , id + N + 1 , [&](int x , int y){return now[x].x < now[y].x || now[x].x == now[y].x && now[x].y < now[y].y;});
	for(int i = 1 ; i <= N ; ++i){
		while(top >= 2 && (now[id[i]] - now[stk[top - 1]]) % (now[stk[top]] - now[stk[top - 1]]) <= 0) --top;
		stk[++top] = id[i];
	}
	for(int i = 1 ; i <= top ; ++i) in[++cnt] = stk[i];
	top = 0;
	for(int i = N ; i ; --i){
		while(top >= 2 && (now[id[i]] - now[stk[top - 1]]) % (now[stk[top]] - now[stk[top - 1]]) <= 0) --top;
		stk[++top] = id[i];
	}
	for(int i = 2 ; i < top ; ++i) in[++cnt] = stk[i];
}

const ld pi = acos(-1);

signed main(){
	cin >> N; for(int i = 1 ; i <= N ; ++i) cin >> now[i].x >> now[i].y;
	hull();
	if(cnt == 2) ans[in[1]] = ans[in[2]] = 0.5;
	else
		for(int i = 1 ; i <= cnt ; ++i){
			int l = in[i == 1 ? cnt : i - 1] , cur = in[i] , r = in[i == cnt ? 1 : i + 1];
			ld pos1 = (now[l] - now[cur]).ang() , pos2 = (now[r] - now[cur]).ang();
			ld delt = pos2 - pos1; while(delt < 1e-5) delt += pi;
			while(delt >= pi) delt -= pi;
			ans[cur] = (pi - delt) / pi / 2;
		}
	for(int i = 1 ; i <= N ; ++i) cout << fixed << setprecision(7) << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 512
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#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 reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<tuple<string, int, int>> book;
    rep(i, n) {
        string s;
        int p;
        cin >> s >> p;
        book.eb(s, -p, i+1);
    }
    sort(all(book));
    rep(i, n) {
        cout << get<2>(book[i]) << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static int n;
	public static int s;
	public static int c;
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		while(true){
			c=0;
			n=sc.nextInt();
			s=sc.nextInt();
			if(n==0&&s==0)break;
			else f(0,0,0);
			System.out.println(c);
		}
	}
	public static void f(int m,int a,int t){
		if(a==n){
			if(t==s)++c;
		}
		else {
			for(int i=m;i<10;++i){
				f(i+1,a+1,t+i);
			}
		}
	}
}

Measured memory_bytes: 11000
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    // 上下左右が全て"."である"#"が存在するかどうかを探す
    A = Number(input.split(" ")[0]);
    B = Number(input.split(" ")[1]);
    C = Number(input.split(" ")[2]);
    D = Number(input.split(" ")[3]);
    flagA=false;
    flagB=false;
    cnt = 0;
    for(i=0;i<=100;i++){
        if(i==A){
            flagA=true;
        }
        if(i==B){
            flagA=false;
        }
        if(i==C){
            flagB=true;
        }
        if(i==D){
            flagB=false;
        }
        if(flagA && flagB){
            cnt++;
        }
    }


    console.log(cnt);
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a < b && b < c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return (0);
}

Measured memory_bytes: 1008
import std.functional,
       std.algorithm,
       std.container,
       std.typetuple,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  string S = readln.chomp;
  short flag;
  long sum;

  foreach (i; 0..2^^(S.length-1)) {
    string fs = ("%." ~ (S.length - 1).to!string ~ "b").format(flag++);

    string formula;

    foreach (j, ch; S) {
      if (0 < j && j < S.length && fs[j - 1] == '1') {
        formula ~= '+';
      }

      formula ~= ch;
    }

    sum += formula.split("+").to!(long[]).sum;
  }

  writeln(sum);
}


Measured memory_bytes: 508
///=======================///
/// coder: Andy - Tohrumi ///
///=======================///

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)

using namespace std;

typedef pair<ll, ll> pll;	typedef pair<int, int> ii;
typedef vector<pll> vll;	typedef vector<string> vs;		typedef vector<ii> vii;
typedef vector<int> vi; 	typedef vector<ll> vl;

///======code start here======///

ll dp[100005][105];

signed main() {
	fastio;
	int n, W; cin >> n >> W;
	int w[n], v[n];
	rep(i, 0, n) {
		cin >> w[i] >> v[i];
	}
	rep(i, 1, 100005) {
		rep(j, 0, n + 1) {
			if(j == 0) {
				dp[i][j] = 1000000007;
			}
			else dp[i][j] = min(dp[i][j - 1], w[j - 1] + dp[max(i - v[j - 1], 0)][j - 1]);
		}
	}
	ll ans; 
	rep(i, 0, 100001) {
		if(dp[i][n] <= W) ans = i;
	}
	cout << ans << endl;
	return 0;
}



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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
    int n;
    cin >> n;
    map<string, int> mp;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        ++mp[s];
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        --mp[s];
    }
    int best = 0;
    for (auto& p : mp) {
        best = max(p.second, best);
    }
    cout << best << "\n";
}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 3632
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)                
                
    divisors.sort()
    return divisors

n = int(input())
num = 0

num += len(make_divisors(n-1))-1

k = make_divisors(n)
k.pop(0)

for item in k:
  tn = n
  while tn % item == 0:
      tn /= item
    
  if tn % item == 1:
    num += 1

print(num)


Measured memory_bytes: 3316