akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
#define int long long
using namespace std;
using point = pair< int,int >;

signed main() {
    int n;
    string str;

    int ba;
    while (~scanf("%lld", &n)) {
        if (n == 0) break;
        cin >> str;
        ba = 0;
        int menb[n] = {};

        REP (i, 100) {
            if (str[i] == 'M') {
                menb[i % n]++;
            } else if (str[i] == 'L') {
                menb[i % n]++;
                menb[i % n] += ba;
                ba = 0;
            } else {
                ba += menb[i % n] + 1;
                menb[i % n] = 0;
            }
        }

        sort(menb, menb + n);
        REP (i, n) {
            if (i) printf(" ");
            printf("%lld", menb[i]);
        }
        printf(" %lld\n", ba);
    }
    return 0;
}




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

int main()
{
	ll m,N;
	cin>>N>>m;
	ll arr[N+1];
	for(ll i=0;i<=N;i++)
		arr[i]=1;
	for(ll i =0;i<m;i++)
	{
		ll x;
		cin>>x;
		arr[x]=0;

	}
	ll steps[N+1];
	for(ll i=0;i<=N+1;i++)
	{
		steps[i]=0;
	}
	steps[N]=1;
	for(ll i=N-1;i>=0;i--)
	{
		if(arr[i+1])
			steps[i]=(steps[i]+steps[i+1])%(1000000007);
		if(arr[i+2])
			steps[i]=(steps[i]+steps[i+2])%(1000000007);
	}
	cout<<steps[0]<<"\n";

}

Measured memory_bytes: 5148
N = int(input())
W = list(map(int, input().split()))

min_d = float("inf")

for i in range(N-1):
    s1 = sum(W[:i+1])
    s2 = sum(W[i+1:])
    min_d = min(min_d, abs(s1-s2))

print(min_d)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>

/* #define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))
sort(a, a + SIZE_OF_ARRAY(a)); 配列内を昇順ソート(aという配列) */

using namespace std;

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    if((a.back() == b.front()) && (b.back() == c.front())){
        printf("YES");
    }
    else{
        printf("NO");
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int MOD=2019;
signed main(){
    fastio
    string s;cin>>s;
    int n=s.size();
    int a[n];
    a[n-1]=s[n-1]-'0';
    int curr=1;
    map<int,int>m;
    m[0]++;m[a[n-1]]++;
    for(int i=n-2;i>=0;i--){
      curr*=10;curr%=MOD;
      a[i]=(curr*(s[i]-'0')+a[i+1])%2019;
      m[a[i]]++;
    }
    ll ans=0;
    ans/=2;
    for(auto x:m){
      ans+=(ll)x.second*(x.second-1)/2;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4588
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    foreach (state; 0 .. 1 << 3)
    {
        long tmp = S[0] - '0';
        foreach (j; 0 .. 3)
            if (state & (1 << j))
            {
                tmp += S[j + 1] - '0';
            }
            else
            {
                tmp -= S[j + 1] - '0';
            }
        if (tmp == 7)
        {
            write(S[0]);
            foreach (j; 0 .. 3)
                if (state & (1 << j))
                {
                    write('+', S[j + 1]);
                }
                else
                {
                    write('-', S[j + 1]);
                }
            writeln("=7");
            return;
        }
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=505;
int mp1[MAXN][MAXN],mp2[MAXN][MAXN];
int n,m;
char ch[MAXN][MAXN];
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)scanf("%s",ch[i]+1);
	for(int i=1;i<=n;i++)mp1[i][1]=1,mp2[i][m]=1;
	for(int i=1;i<=n;i++)for(int j=2;j<m;j++)
	{
		if(i&1)mp1[i][j]=1;
		else mp2[i][j]=1;
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(ch[i][j]=='#')
		mp1[i][j]=mp2[i][j]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)putchar(mp1[i][j]==1?'#':'.');
		puts("");
	}
	puts("");
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)putchar(mp2[i][j]==1?'#':'.');
		puts("");
	}
	return 0;
}



Measured memory_bytes: 2944
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int k=scanner.nextInt();
        int n=scanner.nextInt();
        int arr[]=new int[n];
        for(int j=0;j<n;j++){
            arr[j]=scanner.nextInt();
        }
        int max=Integer.MIN_VALUE;
        for(int j=1;j<n;j++){
            if(arr[j]-arr[j-1]>max){
                max=arr[j]-arr[j-1];
            }
        }
        if(k-arr[n-1]+arr[0]>max){
            max=k-arr[n-1]+arr[0];
        }
        System.out.println(k-max);
    }
}


Measured memory_bytes: 85516
#include <iostream>
#include <iomanip>

typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for(ll i=init;i<(n);i++)


int n;
char target[] = {'7', '5', '3'};

bool count(int num) {
    int cnt = 0;
    for (char c : target) {
        int nn = num;
        while (nn > 0) {
            if (nn % 10 == c - '0') {
                cnt++;
                break;
            }
            nn /= 10;
        }
    }
    if (cnt >= 3) {
        return true;
    } else {
        return false;
    }
}

int dfs(ll num) {
    if (num > n)return 0;
    int ret = count(num) ? 1 :0;
    for(char c : target){
        ret += dfs(num * 10 + (c-'0'));
    }
    return ret;
}


int main() {
    cin >> n;
    cout << dfs(0) << endl;
    return 0;
}


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            long N = long.Parse(str[0]);
            long K = long.Parse(str[1]);
            long[] memo = new long[1000001];
            for (long i = 0; i < N; i++)
            {
                var str2 = Console.ReadLine().Split(' ');
               long a=long.Parse(str2[0]);
                long b= long.Parse(str2[1]);
                memo[a] += b;
            }
            long count = 0;
            for (long i = 0; i < memo.Length; i++)
            {
                count += memo[i];
                if (count >= K) { Console.WriteLine(i);return; }
            }
        }
    }
}


Measured memory_bytes: 15816
#include <iostream>
#include <set>
#include <vector>

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

  int n;
  std::cin >> n;
  std::vector<int> A(n), B(n);
  for (int i = 0; i < n; i++) {
    std::cin >> A[i];
  }
  for (int i = 0; i < n; i++) {
    std::cin >> B[i];
  }
  std::set<std::pair<int, int>, std::greater<std::pair<int, int>>> s;

  for (int i = 0; i < n; i++) {
    s.emplace(B[i], i);
  }

  long long ans = 0;
  while (!s.empty()) {
    int i = s.begin()->second;
    s.erase(s.begin());
    int d = B[i] - A[i], t = B[(i + 1) % n] + B[(i - 1 + n) % n];
    if (d != 0 && d < t) {
      ans = -1;
      break;
    }
    ans += d / t;
    B[i] -= d / t * t;
    if (B[i] != A[i])
      s.insert(std::make_pair(B[i], i));
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 11264
# ぜんぶ同じなら永遠に続く あとはわからんからシミュ
# ぜんぶ奇数の場合は-1じゃなくて0

a, b, c = map(int, input().split())
if a == b == c:
    if a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        print(-1)
    else:
        print(0)
    exit()

count = 0
while True:
    if len(set(list(map(lambda x: x % 2, [a, b, c])))) != 1:
        break
    count += 1
    a, b, c = b / 2 + c / 2, a / 2 + c / 2, a / 2 + b / 2

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
#define double long double
const int INF = 1e18, MOD = 1e9 + 7;

signed main() {
    int n, a, x, y;
    cin>>n;
    vector<pair<int, int>> shougen[22];
    for (int i = 0; i < n; i++) {
        cin>>a;
        for (int j = 0; j < a; j++) {
            cin>>x>>y;
            shougen[i].push_back(make_pair(--x, y));
        }
    }
    int ans = -INF;
    for (int i = 0; i < pow(2, n); i++) {
        bool flag = true;
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                for (pair<int, int> p: shougen[j]) {
                    if (
                        p.second == 1 && !((i >> p.first) & 1) ||
                        p.second == 0 && ((i >> p.first) & 1)
                    ) {
                        flag = false;
                    }
                }
            }
        }
        if (flag) {
            int cnt = 0;
            for (int j = 0; j < n; j++) {
                if ((i >> j) & 1) {
                    cnt++;
                }
            }
            ans = max(ans, cnt);
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

const int MAXN = 3010;

double dp[MAXN][MAXN];

int main() {
    #ifdef BLAT
        freopen("input", "r", stdin);
    #endif


    int n;
    cin >> n;
    dp[0][0] = 1.0;

    for(int i = 1; i <= n; ++i) {
    	double p;
    	cin >> p;
    	for(int j = i; j; --j) {
    		dp[i][j] = dp[i-1][j]*(1.0-p) + dp[i-1][j-1]*p;
    	}
    	dp[i][0] = dp[i-1][0]*(1.0-p);
     }

     double ans = 0;
     for(int i = n / 2 + 1; i <= n; ++i) {
     	ans += dp[n][i];
     }

     cout << setprecision(12) << fixed << ans << '\n';
}   	

Measured memory_bytes: 69120
#include <bits/stdc++.h>
using namespace std ;
const int MAXN = 2e5 + 5 ;
int n , m ;
struct Node {
    int next , to ;
} edge[ MAXN << 2 ] ;
int head[ MAXN ] , cnt ;
int vis[ MAXN ] ;
inline int read () {
    int tot = 0 , f = 1 ;
    char c = getchar () ;
    while ( c < '0' || c > '9' ) {
        if ( c == '-' ) f = -1 ;
        c = getchar () ;
    }
    while ( c >= '0' && c <= '9' ) {
        tot = ( tot << 1 ) + ( tot << 3 ) + ( c ^ 48 ) ;
        c = getchar () ;
    }
    return tot * f ;
}
inline void add ( int x , int y ) {
    edge[ ++ cnt ].next = head[ x ] ;
    edge[ cnt ].to = y ;
    head[ x ] = cnt ;
}
inline void bfs () {
    queue < int > q ;
    q.push ( 1 ) ;
    while ( q.size () ) {
        int u = q.front () ;
        q.pop () ;
        for ( int i = head[ u ] ; i ; i = edge[ i ].next ) {
            int v = edge[ i ].to ;
            if ( vis[ v ] ) continue ;
            vis[ v ] = u ;
            q.push ( v ) ;
        }
    }
}
signed main () {
    n = read () ; m = read () ;
    for ( int i = 1 ; i <= m ; i ++ ) {
        int a = read () , b = read () ;
        add ( a , b ) ; add ( b , a ) ;
    }
    bfs () ;
    for ( int i = 2 ; i <= n ; i ++ ) {
        if ( vis[ i ] == 0 ) {
            cout << "No\n" ; return 0 ;
        }
    }
    cout << "Yes\n" ;
    for ( int i = 2 ; i <= n ; i ++ ) {
        cout << vis[ i ] << endl ;
    }
    return 0 ;
}

Measured memory_bytes: 7576
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll h, w;
ll table[100][100];

ll d[100][100];
ll dx[4] = { 0,1,0,-1 };
ll dy[4] = { 1,0,-1,0 };

void solve() {
	queue<P> que;

	que.push({ 0,0 });
	rep(i, 100)rep(j, 100)d[i][j] = INF;
	d[0][0] = 1;

	while (!que.empty()) {
		P p = que.front();
		ll y = p.first;
		ll x = p.second;
		que.pop();
		if (y == 2 * h - 2 && x == 2 * w - 2)continue;
		rep(i, 4) {
			ll nx = x + dx[i];
			ll ny = y + dy[i];
			if (ny >= 0 && ny < 2 * h - 1 && nx >= 0 && nx < 2 * w - 1) {
				if (table[ny][nx] == 0) {
					if (d[ny + dy[i]][nx + dx[i]] > d[y][x] + 1) {
						d[ny + dy[i]][nx + dx[i]] = d[y][x] + 1;
						que.push({ ny + dy[i],nx + dx[i] });
					}
				}
			}
		}
	}
}

int main() {
	while (cin >> w >> h&&h + w) {
		rep(i, 2 * h - 1) {
			rep(j, 2 * w - 1) {
				if ((i + j) % 2)cin >> table[i][j];
			}
		}
		solve();
		//rep(i, 2 * h - 1) {
		//	rep(j, 2 * w - 1) {
		//		if(d[i][j]!=INF)cout << d[i][j] << " ";
		//		else cout << -1 << " ";
		//	}
		//	cout << endl;
		//}
		if (d[2 * h - 2][2 * w - 2] == INF)cout << 0 << endl;
		else cout << d[2 * h - 2][2 * w - 2] << endl;
	}
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

	int n;
	cin >> n;
	vector<double> a(n);
	double sum = 0;
	rep(i, n){
		cin >> a[i];
		sum += a[i];
	}

	double k = sum / n;
	double mi = 100000;
	int ans = 0;
	rep(i, n){
		if(mi > abs(a[i]-k)){
			mi = abs(a[i]-k);
			ans = i;
		}
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int dp[101];

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	dp[a]++;
	dp[b]--;
	dp[c]++;
	dp[d]--;
	for (int i = 1; i <= 100; ++i) {
		dp[i] += dp[i - 1];
	}

	cout << count(dp, dp + 101, 2) << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
t = [int(_) for _ in input().split()]
m = int(input())
px = []
for i in range(m):
    p, x = map(int, input().split())
    px.append((p, x))
total = sum(t)
for i in px:
    print(total-(t[i[0]-1]-i[1]))

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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 200005;

bool git(long long n, long long x) {
    while (n % x == 0) {
        n /= x;
    }
    return n % x == 1;
}

vector<long long> getDivs(long long n) {
    vector<long long> divs;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (i != 1) {
                divs.push_back(i);
            }
            if (n / i != 1 && n / i != i) {
                divs.push_back(n / i);
            }
        }
    }
    return divs;
}

int main() {
    long long n;
    scanf("%lld", &n);
    
    vector<long long> divs = getDivs(n);
    vector<long long> divs2 = getDivs(n - 1);
    
    set<long long> ans;
    for (auto x : divs2) {
        ans.insert(x);
    }
    
    for (auto x : divs) {
        if (git(n, x)) {
            ans.insert(x);
        }
    }
    
    printf("%d\n", ans.size());
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define itn int
#define all(c) c.begin(),c.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;

const ll MAX_N = 2e5 + 5, inf = 1e18, mod = 1000000007;
const double PI = 3.1415926536;
int days[13] = {0, 31, 28, 31, 30, 31,30, 31, 31, 30, 31, 30, 31};

template<typename T>
ostream& operator <<(ostream& out, const vector<T>& mas) {
    for (const auto& x : mas) {
        out << x << ' ';
    }
    return out;
}

void ok() {
    cout << "YES" << '\n';
}

void no() {
    cout << "NO" << '\n';
}

inline ll nxt() {
    ll x;
    cin >> x;
    return x;
}

void solve() {
    int n = nxt();
    vector<int> a(n);
    generate(all(a), nxt);
    unordered_map<int, int> cnt;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        sum += cnt[a[i]];
        cnt[a[i]]++;
    }

    ll ans = 0; 
    for (auto i : a) { 
        sum -= cnt[i] * (cnt[i] - 1) / 2;
        cout << (cnt[i] - 1) * (cnt[i] - 2) / 2 + sum << '\n';
        sum += cnt[i] * (cnt[i] - 1) / 2;
    } 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int t = 1;
    while (t--) {
    	solve();
    }
    return 0;
}


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

int n;
int d[200001];
vector<int> v;

int main() {
  scanf("%d", &n);
  v.push_back(1);
  for (int i = 6; i <= n; i*=6) {
    v.push_back(i);
  }
  for (int i = 9; i <= n; i*=9) {
    v.push_back(i);
  }
  
  memset(d,0x3f,sizeof(d));
  d[0] = 0;
  
  for (int it : v) {
    for (int i = it; i <= n; i++) {
      d[i] = min(d[i], d[i-it]+1);
    }
  }
  
  printf("%d", d[n]);
  
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int a, b;

int main(){
    cin >> a >> b;
    if((a*b)%2 == 1) cout << "Odd" << "\n";
    else cout << "Even" << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
	int n, m,c, count=0;
	cin>>n>>m>>c;
	int b[m];
	for(int i = 0 ; i< m;i++) cin>>b[i];
	int a[n][m];
	for(int i = 0 ; i< n;i++)
	{ int sum =0;
		for(int j = 0; j< m;j++)
		{
			cin>>a[i][j];
			sum+=b[j]*a[i][j];
		}
		if(sum+c>0)count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1145&lang=jp
typedef long long ll;
#define INF 1<<30
#define LINF 1LL<<60

int getnum(int&pos, const string& str) {
	int ret = 0;
	while (true) {
		if (str[pos] >= '0' && str[pos] <= '9') {
			ret = ret * 10 + (str[pos] - '0');
			pos++;
			continue;
		}
		break;
	}
	return ret;
}

string gennom(int&pos,const string& str, const int& n) {
	int roop = getnum(pos, str);
	if (str[pos] == '(') pos++;
	else {
		string ret;
		char c = str[pos++];
		for (int i = 0; i < roop;i++) {
			ret += c;
			if (ret.length() > n)break;
		}
		return ret;
	}
	string s;
	string ret;
	for (;pos < str.length();) {
		if (str[pos] >= '0' && str[pos] <= '9') {
			s += gennom(pos,str, n);
			continue;
		}
		if (str[pos] >= 'A' && str[pos] <= 'Z') {
			s += str[pos++];
			continue;
		}
		if (str[pos] == ')') {
			pos++; break;
		}
	}

	for (int i = 0; i < roop; i++) {
		ret += s;
		if (ret.length() > n)break;
	}
	return ret;
}

string solve(const string& str,int& n) {
	string ret;
	int pos = 0;
	for (;pos < str.length();) {
		if (str[pos] >= 'A' && str[pos] <= 'Z') {
			ret += str[pos++];
		}
		else {
			ret += gennom(pos,str, n);
		}
		if (ret.length() > n)return ret;
	}
	return ret;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	string str; int n;
	while (cin >> str >> n) {
		if (str == "0" && n == 0) break;
		string ans = solve(str, n);
		//cout << ans << endl;
		if (ans.length() > n) {
			cout << ans[n] << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7804
#include <bits/stdc++.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 ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;
}


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

int main(){

  uint64_t N,num=1,K=0;
  cin >> N;
  uint64_t A[N];
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++){
    if(A[i]==num){
      K++;
      num++;
    }
  }
  if(K==0) cout << "-1" << endl;
  else cout << N-K << endl;
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
p = list(map(int, input().split()))
q = [i for i in range(1, n+1)]
cnt = 0
for j in range(n):
    if p[j] == q[j]:
        if j != n-1:
            p[j], p[j+1] = p[j+1], p[j]
            cnt += 1
        else :
            p[j], p[j-1] = p[j-1], p[j]
            cnt += 1
print(cnt)


Measured memory_bytes: 14008
import java.util.Scanner;

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

    int x = sc.nextInt();
    int ans = 1;

    for (int i=0; i<3; i++) {
      ans = ans*x;
    }

    System.out.printf("%d\n", ans);
  }
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	
	ll n, x;
	cin >> n >> x;
	
	vector<ll> v(n+1);
	vector<ll> sum_v(n+1);
	REP(i,n){
		cin >> v[i+1];
		sum_v[i+1] = v[i+1];
	}
	
	REP(i,n)sum_v[i+1] += sum_v[i];
	
	ll ans = LLINF;
	for(int i = 1;i <= n;i++){
		ll now = 0;
		ll place = n;
		ll kosuu = 1;
		while(place > 0){
			now += (sum_v[place] - sum_v[max(place - i, 0LL)]) * max(5LL, 2*kosuu + 1);
			place -= i;
			kosuu++;
			if(ans < now)break;
		}
		now += (i + n) * x;
		ans = min(ans, now);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n,d,Count=0;
    cin>>n>>d;
    int x[n][d];
    for (int i=0;i<n;i++)
    {
        for(int j=0;j<d;j++)
        {
            cin>>x[i][j];
        }
    }
    for (int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
           int sum=0;
           for (int k=0;k<d;k++)
           {
               sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
           }
           if (sum==floor(sqrt(sum))*floor(sqrt(sum)))
            Count++;
        }
    }
    cout<<Count;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254

macro_rules! eprint {
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = write!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! eprintln {
    () => { eprintln!(""); };
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = writeln!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! dbg {
    ($v:expr) => {{
        let val = $v;
        eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
        val
    }}
}

macro_rules! mat {
    ($($e:expr),*) => { Vec::from(vec![$($e),*]) };
    ($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
    ($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
    ($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
    ($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
        $a$([$i])*.$f($($t),*)
    };
    ($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
        let t = $e;
        ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
    } };
}

pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
    line
}

macro_rules! read {
    ($($t:tt),*; $n:expr) => {{
        let stdin = ::std::io::stdin();
        let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
            let line = line.unwrap();
            let mut it = line.split_whitespace();
            _read!(it; $($t),*)
        }).collect::<Vec<_>>();
        ret
    }};
    ($($t:tt),*) => {{
        let line = readln();
        let mut it = line.split_whitespace();
        _read!(it; $($t),*)
    }};
}

macro_rules! _read {
    ($it:ident; [char]) => {
        _read!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        Vec::from(_read!($it; String).into_bytes())
    };
    ($it:ident; usize1) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_read!($it; $t)),*)
    };
}


pub fn main() {
    let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i32 = std::i32::MAX;

fn solve() {
    let (l,r,d) = read!(i64,i64,i64);
    let mut ans = 0;
    for i in l..r+1 {
        if i%d==0 {
            ans += 1;
        }
    }
    println!("{}",ans);
    
}

fn run() {
    solve();
}


Measured memory_bytes: 2268
k = int(input())
Lis = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(Lis[k - 1])

Measured memory_bytes: 38384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1, T2> P)
{
	return s << '<' << P.first << ", " << P.second << '>';
}
template<class T> ostream& operator << (ostream &s, vector<T> P)
{
	for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s;
}
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{
	for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl;
}
template<class T> ostream& operator << (ostream &s, set<T> P)
{
	EACH(it, P) { s << "<" << *it << "> "; } return s << endl;
}
template<class T1, class T2> ostream& operator << (ostream &s, map<T1, T2> P)
{
	EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl;
}

typedef pair<int, int> pint;
typedef pair<int, int> Edge;
const int MAX = 410000;
vector<Edge> G[MAX];

const int INF = 1 << 29;
int N, M;

int L[MAX], R[MAX], D[MAX];
int dp[MAX];
bool isnots[MAX];

string solve() {
	for (int i = 0; i < N; ++i) dp[i] = INF;
	for (int i = 0; i < N; ++i) {
		if (isnots[i]) continue;
		dp[i] = 0;
		priority_queue<pint, vector<pint>, greater<pint> > que;
		que.push(pint(0, i));
		while (!que.empty()) {
			pint p = que.top();
			que.pop();
			for (auto e : G[p.second]) {
				if (chmin(dp[e.first], dp[p.second] + e.second)) {
					que.push(pint(dp[e.second], e.first));
				}
			}
		}
	}

	//REP(i, N) cout << i << ": " << dp[i] << endl;

	for (int i = 0; i < M; ++i) {
		if (dp[R[i]] - dp[L[i]] != D[i]) return "No";
	}
	return "Yes";
}

int main() {
	while (cin >> N >> M) {
		for (int i = 0; i < MAX; ++i) G[i].clear();
		memset(isnots, 0, sizeof(isnots));
		for (int i = 0; i < M; ++i) {
			int a, b, c;
			cin >> a >> b >> c;
			--a, --b;
			L[i] = a, R[i] = b, D[i] = c;
			G[a].push_back(Edge(b, c));
			isnots[b] = true;
		}
		cout << solve() << endl;
	}
}






Measured memory_bytes: 19700
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto x = readln.chomp.split.to!(int[]);
  if (x[0] > 8 || x[1] > 8) {
    writeln(":(");
  } else {
    writeln("Yay!");
  }
}


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

# どちらも同じ結果となる：
negative_values = list(filter(lambda x:x<0 , a) )
# negative_values = [x for x in a if x<0]
num_negative = len(negative_values)

if num_negative % 2 == 0 :
	ans = sum(list(map(abs, a)))
	print(ans)
else:
	# 絶対値が最小のものを負にしたものが答え
	abs_array = list(map(abs, a))
	ans = sum(abs_array) - 2 * min(abs_array)
	print(ans)


Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=2e5+7;
const ll inf=(ll)1e17+7;
struct e{
	int from,to,dis,nxt;
}edge[MAXN<<2];
struct po{
	int x,y;
	ll l;
	bool operator <(const po &rhs)const
	{
		return l<rhs.l;
	}
}a[MAXN*20],g[MAXN<<2],pre;
int n,m,wson[MAXN],size[MAXN],vis[MAXN*2];
int f[MAXN],tp=0,num,head[MAXN<<1],root,sum,cnt;
ll ans,dep[MAXN],x[MAXN];
inline int read()
{
	int x=0,c=1;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
inline void add_edge(int from,int to,int dis)
{
	edge[++num].nxt=head[from];
	edge[num].to=to;
	edge[num].dis=dis;
	head[from]=num;
}
inline void get_root(int u,int fa)
{
	size[u]=1;wson[u]=0;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(vis[v]||v==fa) continue;
		get_root(v,u);
		size[u]+=size[v];
		wson[u]=max(wson[u],size[v]);
	}
	wson[u]=max(wson[u],sum-size[u]);
	root=(wson[u]<wson[root]?u:root);
}
inline void dfs(int u,int fa,ll d)
{
	g[++tp]=(po){u,0,d+x[u]};
	pre=min(pre,g[tp]);
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(vis[v]||v==fa) continue;
		dfs(v,u,d+edge[i].dis);
	}
}
inline void solve(int u)	
{
	pre=(po){0,0,inf};
	vis[u]=1;tp=0;
	dfs(u,0,0);
	for(int i=1;i<=tp;i++) a[++cnt]=(po){pre.x,g[i].x,pre.l+g[i].l};
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(vis[v]) continue;
		sum=size[v];root=0;
		get_root(v,u);solve(root);
	}
}
int find(int x) {return f[x]==x?f[x]:f[x]=find(f[x]);}
int main()
{
//	freopen("data.in","r",stdin);
//	freopen("my.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) x[i]=read();
	for(int i=1;i<=n-1;i++){
		int u,v,l;
		u=read();v=read();l=read();
		add_edge(u,v,l);add_edge(v,u,l);
	}
	wson[0]=10000007;
	sum=n;	
	get_root(1,0);
	solve(root);
	sort(a+1,a+cnt+1);
	for(int i=1;i<=n;i++) f[i]=i;	
	for(int i=1;i<=cnt;i++){
		int r1=find(a[i].x),r2=find(a[i].y);
		if(r1!=r2){
			ans+=a[i].l;
			f[r1]=r2;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 78336
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;




void main() {
    int k, x;
    scan(k, x);

    writefln("%(%s %)", iota(x - k + 1, x + k));
}


















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import itertools

N,M = map(int, input().split())
A = []
C = []
comp = sum(1<<int(x) for x in range(N))
for m in range(M):
  a, b = map(int, input().split())
  A.append(a)
  c = list(map(int, input().split()))
  C.append(sum(1<<(int(x)-1) for x in c))

INF = 10**18
dp = [INF] * (1<<N)
dp[0] = 0

for n,(a,c) in itertools.product(range(1<<N),zip(A,C)):
    m = n|c
    x = dp[n]+a
    if dp[m] > x:
      dp[m] = x

answer = dp[-1]
if answer == INF:
    answer = -1
print(answer)

Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, b, c;
	for (int h = 0; h < 1000; h++) {
		cin >> n;
		if (n == 0) {
			cin >> n; return 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			if (a == 100 || b == 100 || c == 100) {
				cout << 'A' << endl;
			}
			else if ((a + b) / 2 >= 90) {
				cout << 'A' << endl;
			}
			else if ((a + b + c) / 3 >= 80) {
				cout << 'A' << endl;
			}
			else if ((a + b + c) / 3 >= 70) {
				cout << 'B' << endl;
			}
			else if ((a + b + c) / 3 >= 50 && (a >= 80 || b >= 80)) {
				cout << 'B' << endl;
			}
			else {
				cout << 'C' << endl;
			}
		}
	}
	cin >> n;
}


Measured memory_bytes: 2996
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    int N;
    string S;
    cin >> N >> S;
    int cur = 0;
    for(int i=0; i<N; i++)
        if(S[i] == '.') cur++;

    int ans = cur;
    for(int i=0; i<N; i++){
        if(S[i] == '.') cur--;
        else cur++;
        ans = min(ans, cur);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	string S;
	cin >> S;
	string ans = S.size()%2==0 ? "Yes" : "No";
	for(int i=0; i<S.size(); i++){
		if(S[i]!=(i%2==0?'h':'i')) ans = "No";
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
 
int n,i,j,d;
long long p[105];
 
long long solve(int l, int r, long long now){
	if(l >= r){
		if(l == r){
			if(now == 0LL){
				if(l == 0) return 9LL;
				return 10LL;
			}
			return 0LL;
		}
		
		if(now == 0LL) return 1LL;
		return 0LL;
	}
	
	long long tot = 0;
	
	long long v1 = now % 10;
	long long v2;
	if(v1 < 0){
		v2 = v1 + 10;
	}
	else
	v2 = v1 - 10;
	
	int num1 = 10 - abs(v1);
	int num2 = 10 - abs(v2);
	
	if(l == 0) num2--;
	if(v1 == 0 && l == 0) num1--;
	
	tot += solve(l + 1, r - 1, (now - v1 + v1 * p[r - l]) / 10) * num1;
	if(v1 != 0)
	tot += solve(l + 1, r - 1, (now - v2 + v2 * p[r - l]) / 10) * num2;
	
	return tot;
}
 
int main(){
	
	scanf("%d", &d);
	
	p[0] = 1LL;
	
	for(i = 1; i <= 18; i++)
	p[i] = p[i - 1] * 10LL;
	
	long long res = 0LL;
	
	for(i = 1; i <= 18; i++)
	res += solve(0, i - 1, d);
	
	printf("%lld\n", res);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n,m; cin >> n >> m;
    vector<int> p(m);
    vector<string> s(m);
    rep(i,m) {
        cin >> p[i] >> s[i];
        p[i]--;
    }    
    int po = 0;
    int pe = 0;
    vector<int> wa(n);
    vector<bool> ac(n);
    rep(i,m){
        if(s[i] == "AC"){
            if(!ac[p[i]]) {
                po++;
                pe += wa[p[i]];
            }
            ac[p[i]] = true;
        }
        else{
            wa[p[i]]++;
        }
    }
    cout << po << " " << pe << endl;
}

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

struct info {
    int year;
    int idx;
};

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<int> v(m), y(m);

    for (int i = 0; i < m; i++) {
        cin >> v[i] >> y[i];
    }

    vector<vector<pair<int, int>>> vv(n, vector<pair<int, int>>(1, make_pair(-1, -1)));

    for (int i = 0; i < m; i++) {
        pair<int, int> t = make_pair(y[i], i);
        vv[v[i] - 1].push_back(t);
    }

    for (int i = 0; i < n; i++) {
        sort(vv[i].begin(), vv[i].end());
    }

    vector<string> s(m);
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < vv[i].size(); j++) {
            int idx = vv[i][j].second;
            int t = v[idx];

            ostringstream ss1, ss2;
            ss1 << setw(6) << setfill('0') << v[vv[i][j].second];
            ss2 << setw(6) << setfill('0') << j;

            string st = ss1.str() + ss2.str();

            s[idx] = st;
        }
    }

    for (int i = 0; i < m; i++) {
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 14336
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())


int n;
vector<ll>pos,neg;
ll zero,k;

int main(){
	cin >> n >> k;
	rep(i,n){
		ll x; cin >> x;
		if(x == 0) zero++;
		else if(x > 0) pos.pb(x);
		else neg.pb(-x);
	}
	SORT(pos); SORT(neg);
	
	ll lb = -2e18, ub = 2e18;
	while(ub-lb > 1){
		ll mid = (ub+lb)/2;
		ll cnt = 0;
		
		if(mid < 0){
			rep(i,pos.size()){
				ll val = (-mid + pos[i]-1) / pos[i];
				int f = POSL(neg,val);
				cnt += neg.size() - f;
			}
		}
		else{
			cnt += 1LL * pos.size() * neg.size();
		}
		if(mid >= 0){
			cnt += 1LL*zero*(n-zero) + 1LL*zero*(zero-1)/2;
		}
		if(mid > 0){
			rep(i,pos.size()){
				ll val = (mid) / pos[i];
				int f = POSU(pos,val);
				f = min(f,i);
				cnt += f;
			}
			rep(i,neg.size()){
				ll val = (mid) / neg[i];
				int f = POSU(neg,val);
				f = min(f,i);
				cnt += f;
			}
		}
		if(cnt >= k) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
}

Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> v(N);
    Rep (i, N) {
        cin >> v[i];
    }

    sort(v.begin(), v.end());

    double value = (v[0] + v[1]) / 2.0;
    for (ll i = 2; i < N; i++) {
        value = (value + v[i]) / 2.0;
    }

    cout << value << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

typedef unsigned long long ull;

typedef struct Item
{
    int value;
    int weight;
    string type;
    ull data;
    string name;
}item;

bool cmp(const Item &t1, const Item &t2)
{
    if (t1.value != t2.value)
    {
        return t1.value < t2.value;
    }
    else if (t1.weight != t2.weight)
    {
        return t1.weight < t2.weight;
    }
    else if (t1.type != t2.type)
    {
        return t1.type < t2.type;
    }
    else if (t1.data != t2.data)
    {
        return t1.data < t2.data;
    }
    else
    {
        return t1.name < t2.name;
    }

}

int main()
{
    int n;
    scanf("%d", &n);

    vector<item> vecItem;
    for (int i = 0; i < n; i++)
    {
        item tempItem;
        cin >> tempItem.value >> tempItem.weight >> tempItem.type
                >> tempItem.data >> tempItem.name;
        vecItem.push_back(tempItem);
    }

    sort(vecItem.begin(), vecItem.end(), cmp);
    for (int i = 0; i < n; i++)
    {
        cout << vecItem[i].value << " " << vecItem[i].weight << " "
             << vecItem[i].type << " " << vecItem[i].data << " "
             << vecItem[i].name << endl;
    }

    return 0;
}



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

int main()
{
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h+2, vector<char>(w+2));
  int i, j;
  for(i = 0; i < h+2; i++)
  {
    for(j = 0; j < w+2; j++)
    {
      if(i == 0 || j == 0 || i == h+1 || j == w+1)
      {
        a.at(i).at(j) = '.';
      }
      else
      {
        cin >> a.at(i).at(j);
      }
    }
  }
  int plax = 1;
  int play = 1;
  int sw = 0;
  while(sw == 0)
  {
    a.at(play).at(plax) = '.';
    bool allvisit = true;
    for(i = 1; i <= h; i++)
    {
      for(j = 1; j <= w; j++)
      {
        if(a.at(i).at(j) == '#')
        {
          allvisit = false;
        }
      }
    }
    if(allvisit) 
    {
      sw = 1;
      break;
    }
    else if(!allvisit && play == h && plax == w) 
    {
      sw = -1;
      break;
    }
    if(a.at(play+1).at(plax) == '#')
    {
      play++;
    }
    else if(a.at(play).at(plax+1) == '#')
    {
      plax++;
    }
    else
    {
      sw = -1;
      break;
    }
  }
  if(sw == 1) cout << "Possible" << endl;
  else if(sw == -1) cout << "Impossible" << endl;
}

Measured memory_bytes: 256
import math

def F(a,b):
  return max(len(str(a)),len(str(b)))

N = int(input())
minimum = len(str(N))

for i in range(1,int(math.sqrt(N))+1):
  if N % i == 0:
    j = int(N/i)
    minimum = min(F(i,j), minimum)
#print(i)
#print(j)
print(minimum)

Measured memory_bytes: 9196
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array.Unboxed

main :: IO ()
main = do
  [a,b] <- getl $ wrds toInt
  unless (a == 0 && b == 0) $ do
    n <- getl toInt
    solve a b <$> replicateM n (getl $ wrds toInt) >>= print
    main

solve :: Int -> Int -> [[Int]] -> Int
solve a b xs = (! (a,b)) $ foldl g ia [(i,j) | i <- [1..a],j <- [1..b]]
  where
    f i j = [i,j] `elem` xs
    ia = listArray ((1,1),(a,b)) (repeat 0) :: UArray (Int,Int) Int
    g ar (i,j)
      | f i j = ar // [((i,j),0)]
      | i == 1 && j == 1 = ar // [((i,j),1)]
      | i == 1 = ar // [((i,j), ar ! (i,j-1))]
      | j == 1 = ar // [((i,j), ar ! (i-1,j))]
      | otherwise = ar // [((i,j), ar ! (i-1,j) + ar ! (i,j-1))]
        
toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  
  cin >> str;
  if(str=="000"){
    cout << 0 << endl;
  }
  
  if(str=="001"){
    cout << 1 << endl;
  }
  
  if(str=="010"){
    cout << 1 << endl;
  }
  
  if(str=="011"){
    cout << 2 << endl;
  }
  
  if(str=="100"){
    cout << 1 << endl;
  }
  
  if(str=="101"){
    cout << 2 << endl;
  }
  
  if(str=="110"){
    cout << 2 << endl;
  }
  
  if(str=="111"){
    cout << 3 << endl;
  }
}

Measured memory_bytes: 256