akhauriyash/Code-Regression huggingface dataset:
#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;
const ll mod = 1000000007;

int nth_bit(ll num, int n){
    return (num >> n) & 1;
}

ll dp[101][8],cnt[8][8];
int main(){
    int h,w,k; cin >> h >> w >> k;
    k--;
    
    rep(bit,(1<<(w-1))){
        bool ok = true;
        rep(i,w-2){
            if(nth_bit(bit,i) && nth_bit(bit,i+1)){
                ok = false;
                break;
            } 
        }
        if(!ok) continue;

        vector<int> next(w); // i -> next[i]
        rep(i,w) next[i] = i;
        rep(i,w-1){
            if(nth_bit(bit,i)) swap(next[i], next[i+1]);
        }
        rep(i,w) cnt[i][next[i]]++;
    }

    dp[0][0] = 1;
    rep(i,h){
        rep(j,w){
            rep(l,w){
                dp[i+1][l] += dp[i][j] * cnt[j][l];
                dp[i+1][l] %= mod;
            }
        }
    }

    cout << dp[h][k] << endl;
}


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

const int INF = (1 << 30);
const int MAX_H = 50, MAX_W = 50;
typedef pair<int, int> P;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool isWhite[MAX_H][MAX_W];
int dist[MAX_H][MAX_W];


int main() {
    int h, w;
    cin >> h >> w;
    int num_white = 0;
    char ch;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> ch;
            if (ch == '.') {
                num_white++;
                isWhite[i][j] = true;
            } else {
                isWhite[i][j] = false;
            }
            dist[i][j] = INF;
        }
    }

    queue<P> que;
    que.push(P(0, 0));
    dist[0][0] = 0;
    while (que.size()) {
        P p = que.front(); que.pop();
        if (p.first == w-1 && p.second == h-1) break;
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && isWhite[ny][nx] && dist[ny][nx] == INF) {
                que.push(P(nx, ny));
                dist[ny][nx] = dist[p.second][p.first] + 1;
            }
        }
    }

    int ans = num_white - dist[h-1][w-1] - 1;
    if (ans < 0) ans = -1;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int p[200005];

int root(int x) {return p[x] < 0 ? x : p[x] = root(p[x]);}

void mer(int x, int y) {
    if ((x = root(x)) == (y = root(y))) return;
    if (p[x] > p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
}

int main() {
    ios::sync_with_stdio(false);
    int n, q, t, u, v;
    cin >> n >> q;
    for (int i = 0; i < n; i++) p[i] = -1;
    while (q--) {
        cin >> t >> u >> v;
        if (t == 0) mer(u, v);
        else cout << (root(u) == root(v)) << '\n';
    }
}


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

using namespace std;

int main()
{
  int s;
  cin >> s;
  int temp = s, c = 0;
  while(temp >= 10)
  {
      temp /= 10;
      c++;
  }
  int ans = temp;
  for(int i=0;i<c;i++)
   ans = ans*10 + temp;
  if(ans >= s)
    printf("%d\n", ans);
  else
  {
    for(int i=0;i<c+1;i++)
    printf("%d", temp+1);
    printf("\n");
  }
  return 0;
}


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

using namespace std;

int getset(int i, int set[])
{
    if (set[i] == i) return i;
    return getset(set[i], set);
}

int main()
{
    int n,m;
    long long ans[1<<17];
    int a[1<<17];
    int b[1<<17];
    int set[1<<17];
    int elem[1<<17];
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
	scanf("%d %d", a+i, b+i);
    }
    for (int i = 1; i <= n; i++) {
	set[i] = i;
	elem[i] = 1;
    }
    ans[m] = (long long)n * (n-1) / 2;
    for (int i = m-1; i >= 0; i--) {
	int aset = getset(a[i], set);
	int bset = getset(b[i], set);
	set[a[i]] = aset;
	set[b[i]] = bset;
	if (aset == bset) {
	    ans[i] = ans[i+1];
	    continue;
	}
	ans[i] = ans[i+1] - elem[aset] * elem[bset];
	int minset = min(aset, bset);
	int maxset = max(aset, bset);
	elem[minset] = elem[aset] + elem[bset];
	set[maxset] = minset;
    }
    for (int i = 1; i <= m; i++) {
	printf("%lld\n", ans[i]);
    }
    return 0;
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

int func(int a, int b, int c, int d){
    return abs(a-c) + abs(b-d);
}

signed main() {

    int N;
    cin>>N;
    vector<int> T(N);
    int ans = 0;
    rep(i,N){
        cin >> T[i];
        ans+=T[i];
    }
    int M;
    cin >> M;
    rep(i,M){
        int p, x;
        cin >> p >> x;
        
        cout << ans - (T[p-1]-x)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll a[100005],dp[100005];
int main(){
  ll i,j,k,n,m,t;
  cin>>n;
  for(i=1;i<=n;i++) cin>>a[i];
  dp[n]=1;
  for(i=n-1;i;i--) {
   dp[i]=1;
    if(a[i]>=a[i+1]) dp[i]+=dp[i+1];
  }
  ll ma=0;
  for(i=1;i<=n;i++) ma=max(ma,dp[i]);
  cout<<ma-1<<"\n";
  
}

Measured memory_bytes: 1792
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int g[1005][1005];

inline void solve(){
    int  r, c, a, b; 
    cin >> r >> c >> a >> b ; 
    for (int i=0;i<r;i++){
        for (int j=0;j<c;j++){
            if ((i<b and j<a) or (i>=b and j>=a)) g[i][j] = 1;
        }
    }
    for (int i=0;i<r;i++){
        for (int j=0;j<c;j++) cout << g[i][j] ; 
        cout << endl;
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}
/* 

7 6 2 3 
1 1 0 0 0 0 
1 1 0 0 0 0 
1 1 0 0 0 0 
0 0 1 1 1 1 
0 0 1 1 1 1 
0 0 1 1 1 1 
0 0 1 1 1 1 


*/ 


Measured memory_bytes: 11436
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          var s = Input.ScanStr().ToCharArray();
          Array.Sort(s);
          if(s[0]==s[1] && s[1]!=s[2] && s[2] == s[3])
            Out("Yes");
          else 
            Out("No");
        }
        static public void Out(object s) { Console.WriteLine(s); }
    }
    
    static class Input {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(); }
    }

    static class MyMath {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<map>

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;


int main(){
    string s;
    cin >> s;
    bool flag=true;
	if(s[0]==s[1])flag=false;
    if(s[1]==s[2])flag=false;
    if(s[2]==s[3])flag=false;

	cout << (flag ? "Good" : "Bad") << endl;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

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

  ll val = 1000;
  ll min_val = a[0];
  ll max_val = a[0];
  a.erase(unique(a.begin(), a.end()), a.end());
  for(int i = 1; i < a.size(); ++i)
  {
    if (a[i - 1] > a[i])
    {
      val += (val / min_val) * (max_val - min_val);
      max_val = min_val = a[i];
    }
    max_val = max(max_val, a[i]);
    min_val = min(min_val, a[i]);
  }

  val += (val / min_val) * (max_val - min_val);

  cout << val;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3644
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
        int A = stdIn.nextInt();
	int B = stdIn.nextInt();
	int C = stdIn.nextInt();
	int o = A-B;
	if(o!=0){
	    C-=o;
	}
	if(C>0){
	    System.out.println(C);
	}else{
	    System.out.println(0);
	}
    }
}


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

const int N_MAX = 100;
const int a_MAX = 1000;

int a[N_MAX + 10];

int main(){
  int n;
  
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  int max = 0;
  int min = a_MAX + 10;

  for(int i = 0; i < n; i++){
    if(a[i] > max){
      max = a[i];
    }
    if(min > a[i]){
      min = a[i];
    }
  }
  
  cout << max - min << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin >> s;
  int n=s.size();
  int ans=1e7;
  for(int i=0;i<n-1;i++){
    if(s[i]!=s[i+1]){
      ans=min(ans,max(i+1,n-i-1));
    }
  }
  if(ans==1e7){
    ans=n;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<cstdio>
const int N=2e5+3,INF=1e9;
int n,a[N],b[N],f[N];
inline bool Check(int g){
	int tmp=0,l=n+n,r=0;
	for(int i=1;i<n+n;i++)b[i]=a[i]>g;
	for(int i=2;i<n+n;i++)tmp+=b[i]^b[i-1];
	if(tmp==n+n-2)return!b[1];
	if(b[n]==b[n+1]||b[n]==b[n-1])return!b[n];
	for(int i=n;i>1;i--)
	  if(b[i]==b[i-1]){l=i;break;}
	for(int i=n;i+1<n+n;i++)
	  if(b[i]==b[i+1]){r=i;break;}
	if(l==n+n)return!b[r];
	if(!r)return!b[l];
	return!b[n-l>r-n?r:l];
}
int main(){
	int l,r,m;
	scanf("%d",&n);
	for(int i=1;i<n+n;i++)scanf("%d",a+i);
	for(l=-INF,r=INF;l<r;)m=l+r>>1,Check(m)?r=m:l=m+1;
	printf("%d",l);
	return 0;
}

Measured memory_bytes: 3296
n = gets.to_i
s=0
a = gets.split.map.with_index{|c, j| i = c.to_i; s += i; [i*n, j]}
a.sort
ans = p
d = Float::INFINITY
a.each do |b, i|
  dd = (s-b).abs
  if d > dd
    d = dd
    ans = i
  end
end
p ans

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;

using value_type = i64;


signed main(){
    i64 n, k;
    cin >> n >> k;

    i64 x = n - k, y = k;
    i64 sum = 0;
    while(y){
        sum += 3 * y * (x / y);
        i64 z = y;
        y = x % y;
        x = z;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
#define Maxn 100000
int k;
int dis[Maxn+5];
bool in[Maxn+5];
void spfa(){
	memset(dis,0x3f,sizeof dis);
	dis[1]=1;
	queue<int> q;
	q.push(1);
	in[1]=1;
	int u,v;
	while(!q.empty()){
		u=q.front();
		in[u]=0;
		q.pop();
		v=(u+1)%k;
		if(dis[u]+1<dis[v]){
			dis[v]=dis[u]+1;
//			printf("%d-->%d 1 %d %d\n\n",u,v,dis[u],dis[v]);
			if(!in[v]){
				q.push(v);
				in[v]=1;
			}
		}
		v=(u*10)%k;
		if(dis[u]<dis[v]){
			dis[v]=dis[u];
//			printf("%d-->%d 0 %d %d\n",u,v,dis[u],dis[v]);
			if(!in[v]){
				q.push(v);
				in[v]=1;
			}
		}
	}
}
int main(){
	scanf("%d",&k);
	spfa();
	printf("%d\n",dis[0]);
	return 0;
}


Measured memory_bytes: 896
def gcd(a,b):
	while b!=0:
		a,b=b,a%b
	return a
	print(gcd(a,b))

def lcm(a,b):
	return a*b//gcd(a,b)
  
a,b=list(map(int, input().split()))
print(lcm(a,b))

Measured memory_bytes: 38384
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	ll s;
	cin >> s;
	ll x = s / 100;
	ll y = s % 100;
	if (x > 12 && y > 12) cout << "NA";
	else if (x == 0 && y > 12) cout << "NA";
	else if (y == 0 && x > 12) cout << "NA";
	else if (x == 0 && y == 0) cout << "NA";
	else if (x > 12 || x == 0) cout << "YYMM";
	else if (y > 12 || y == 0) cout << "MMYY";
	else cout << "AMBIGUOUS";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> vec(N);
  int ma=0,mi=110;
  
  for(int i=0;i<N;i++) {
    cin>>vec.at(i);
    ma=max(ma,vec.at(i));
    mi=min(mi,vec.at(i));
  }
  long long mii=100000000;
  
  for(int i=mi;i<=ma;i++){
    long long sum=0;
    for(int j=0;j<N;j++){
      sum+=pow(vec.at(j)-i,2);
    }
    mii=min(mii,sum);
  }
  cout<<mii<<endl;
  return 0;
}
      


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#define N 200002
using namespace std;
int a[N],b[N],c[N],d[N],e[N],f[N],i,j,k,m,n,o[N],p[N],q,w;long long x;bool g[N];
inline bool cmp(int u,int v){return c[u]<c[v];}
inline void solve(int u,int v)
{
    for(;c[a[u]]==c[u];g[u=a[u]]=true);
    for(;c[b[v]]==c[v];g[v=b[v]]=true);
    for(j=v,q=0;u<=j;j=a[j])o[++q]=e[j];
    for(j=u,q=0;j<=v;j=b[j])p[++q]=f[j];
    for(j=q,o[q+1]=p[q+1]=0;j;j--)o[j]+=o[j+1],p[j]+=p[j+1];
    for(j=0;j<=q-m;j++)x+=(long long)(o[q-j]-o[q-j+1])*p[m+j];
    for(w=c[u];w!=c[a[u]]&&w!=c[b[v]]&&m<=q;q=j,w++)for(j=k=0;(k+=m)<=q;)o[++j]=o[k],p[j]=p[k];
    if(w!=c[a[u]]&&w!=c[b[v]])b[a[u]]=n+1,a[b[v]]=0;
    else
    {
        for(j=o[q+1]=p[q+1]=0;j<=q-m;j++)x-=(long long)(o[q-j]-o[q-j+1])*p[m+j];
        for(j=1,o[q+1]=p[q+1]=0;j<=q;j++)o[j]-=o[j+1],p[j]-=p[j+1];
        for(j=u,k=0;k<q;j=b[j])c[j]=w,e[j]=o[q-k],f[j]=p[++k];
        a[b[v]]=a[j],b[a[j]]=b[v];
    }
}
int main()
{
    scanf("%d%d",&n,&m),x=n;
    for(i=1;i<=n;i++)scanf("%d",c+i),d[i]=i,e[i]=f[i]=1,a[i]=i-1,b[i]=i+1;
    for(sort(d+1,d+n+1,cmp),i=1;i<=n;i++)if(!g[d[i]])solve(d[i],d[i]);
    return 0&printf("%lld\n",x);
}

Measured memory_bytes: 6016
s = input()
if s == 'SUN':
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
else:
    print(1)

Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(1000000000)
INF=10**9
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
def dfs(i,x,y,z,m):
    if i==n:
        if x>0 and y>0 and z>0:
            return abs(x-a)+abs(y-b)+abs(z-c)+m
        else:
            return INF
    ans=INF
    if x==0:
        ans=min(dfs(i+1,l[i],y,z,m),ans)
    else:
        ans=min(dfs(i+1,x+l[i],y,z,m+10),ans)
    if y==0:
        ans=min(dfs(i+1,x,l[i],z,m),ans)
    else:
        ans=min(dfs(i+1,x,y+l[i],z,m+10),ans)
    if z==0:
        ans=min(dfs(i+1,x,y,l[i],m),ans)
    else:
        ans=min(dfs(i+1,x,y,z+l[i],m+10),ans)
    return min(ans,dfs(i+1,x,y,z,m))
print(dfs(0,0,0,0,0))

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

using namespace std;

long long n;
string s;
long long a[26]={};
long long ans=1;
long long mod(long long a){
	return a%1000000007;
}
int main(){
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		a[s[i]-'a']++;
	}
	for(int i=0;i<26;i++)
	{
		if(a[i]){
			ans=mod(ans*(a[i]+1));
		}
	}
	cout<<ans-1<<endl;

}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;

  vll isprime(n+1,1);
  vll p;
  for(ll i=2; i<=n; i++){
    if(!isprime[i])
      continue;

    for(ll j=2; i*j<=n; j++)
      isprime[i*j]=0;

    p.push_back(i);
  }

  vll table(n+1,1);
  for(auto i:p){
    for(ll j=1; i*j<=n; j++){
      ll tmp=j;

      ll cnt=1;
      while(tmp%i==0){
        tmp/=i;
        cnt++;
      }
      table[i*j]*=cnt+1;
    }
  }

  ll ans=1;
  for(ll i=2; i<=n; i++)ans+=i*table[i];
  cout<<ans<<endl;


}



Measured memory_bytes: 164892
/**
*    created: 10.07.2020 17:24:58
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#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 all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+') cout << a + b << endl;
    else cout << a - b << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  string s;
  int Q;
  cin>>s>>Q;
  int y,F;
  char c;
  deque<char>k;
  for(char r:s){k.push_back(r);}
  bool rev=false;
  for(int i=0;i<Q;i++){
    cin>>y;
    if(y==1){
      rev=!rev;
    }
    if(y==2){
      cin>>F>>c;
      if(rev){F=3-F;}
      if(F==1){k.push_front(c);}
      if(F==2){k.push_back(c);}         
    }
  }
  if(rev){
  reverse(k.begin(),k.end());}
  string ans;
  for(char d: k){ans+=d;}
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4304
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	char num[10];
	cin >> num;
	if (num[0] == num[1] && num[1] == num[2]) {
		cout << "Yes\n";
	}
	else if (num[1] == num[2] && num[2] == num[3]) {
		cout << "Yes\n";
	}
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a;
	int ii = 1;

	for (;;) {
		scanf("%d", &a);
		if (a == 0) {
			break;
		}

		printf("Case %d: %d\n", ii, a);
		ii++;
	}

	return 0;
}

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

int main() {
  int n; cin >> n;
  map <char, int> m;

  for(int i = 0; i < n; i++) {
    string x; cin >> x;
    m[x[0]]++;
  }

  cout << "AC x " << m['A'] << endl;
  cout << "WA x " << m['W'] << endl;
  cout << "TLE x " << m['T'] << endl;
  cout << "RE x " << m['R'] << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000


int main() {
  int N, M; cin >> N >> M;

  Graph G(N);

  for (int i = 0; i < M; i++) {
    int k; cin >> k;
    for (int j = 0; j < k; j++) {
      int s; cin >> s; s--;
      G[s].push_back(i);
    }
  }


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

  // cout << "yes" << endl;

  int light[M];


  int ans = 0;
  
  for (int i = 0; i < pow(2, N); i++) {
    
    memset(light, 0, sizeof(light));

    for (int j = 0; j < N ; j++) {

      // if it uses switch j
      if ((1 << j) & (i)) {

        // all lights connected to j
        if (!G[j].empty()) {
          for (int y: G[j]) {
            // cout <<"switch j is:" << j << " connected to y: " << y << endl;
            light[y]++;
            light[y] %= 2;
          }
        }
        
      }
    }

    
    
    int flag = 1;
    for (int k = 0; k < M; k++) {
      if (Input[k] != light[k]) {
        flag = 0;
        break;
      }
    }
    
    if (flag) {
      // cout << i << endl;
      ans++;
    }
    
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


ll n;
ll m;
ll q;
vector <vector<ll>> qs;

ll calc(vector<ll> num){
    ll last;
    if (!num.empty()){
        last = num[num.size() - 1];
    } else {
        last = 1;
    }
    if (num.size() < n){
        ll ret = 0;
        for(ll last2=last; last2 <= m; last2++){
            vector <ll> num2 = num;
            num2.push_back(last2);
            ret = max(ret, calc(num2));
        }
        return ret;
    }
    ll ret = 0;
    REP(i, q){
        vector<ll> arr = qs[i];
        ll a = arr[0];
        ll b = arr[1];
        ll c = arr[2];
        ll d = arr[3];
        if (num[b-1] - num[a-1] == c){
            ret+=d;
        }
    }
    return ret;
}


int main(void){
    cin >> n;
    cin >> m;
    cin >> q;
    REP(i, q){
        ll a; ll b; ll c; ll d;
        cin >> a >> b >> c >> d;
        qs.push_back({a, b, c, d});
    }
    cout << calc({}) << endl;
    return 0;
}

Measured memory_bytes: 3640
import heapq
from collections import deque
must_red, must_green, a,b,c = map(int,input().split())
delicious_red_ls = list(map(int, input().split()))
delicious_green_ls = list(map(int, input().split()))
delicious_free_ls = list(map(int, input().split()))
delicious_red_ls.sort(reverse=True)
delicious_green_ls.sort(reverse=True)
first_red = delicious_red_ls[:must_red]
first_green = delicious_green_ls[:must_green]
first_set = first_green + first_red
first_set.sort()
delicious_free_ls.sort()

while delicious_free_ls:
    to_be_erased = heapq.heappop(first_set)
    erase = delicious_free_ls[-1]
    if to_be_erased < erase:
        new = delicious_free_ls.pop()
        heapq.heappush(first_set, new)
    else:
        heapq.heappush(first_set, to_be_erased)
        break
print(sum(first_set))




Measured memory_bytes: 29460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int N = s.nextInt();
        int M = s.nextInt();
        System.out.println((N*(N-1)+(M*(M-1)))/2);

    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 21076
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define lli long long int
#define test                lli t;cin>>t;while(t-->0)
#define ainput  int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define vec vector<lli>v;
vec
#define avinput  int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];v.push_back(a[i]);}
#define vp  for(lli i=0;i<v.size();i++) {cout<<v[i]<<" ";}cout<<endl;
#define vp1  for(lli i=0;i<v1.size();i++) {cout<<v1[i]<<" ";}cout<<endl;
#define vp2  for(lli i=0;i<v2.size();i++) {cout<<v2[i]<<" ";}cout<<endl;
#define vp3  for(lli i=0;i<v3.size();i++) {cout<<v3[i]<<" ";}cout<<endl;
#define vp6  for(lli i=0;i<v6.size();i++) {cout<<v6[i].first<<" "<<v6[i].second<<endl;}
#define ln cout<<endl;
  //cout << fixed << setprecision(10) <<((double)((sum*1.0)/((n*1.0-k*1.0)+1.0))) << endl;
set<lli>s1;
set<lli>s2;
set<string>st2;
vector<lli>v1;
vector<lli>v2;
vector<lli>v3;
vector<lli>v4;
vector<lli>v5;
vector<pair<lli,lli> >v6;
vector<pair<char,int> >v16;
vector<string>v7;
vector<string>v8;
vector<char>v9;
vector<double>v11;
list<lli>l;
//****coding start****
int main()
{
lli n;cin>>n;
string s;cin>>s;
v9.push_back(s[0]);
for(lli i=1;i<s.length();i++){
    if(s[i]==s[i-1])continue;
    else v9.push_back(s[i]);
}
cout<<v9.size()<<endl;
    return 0;
}

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

int main() {
  int N, l, r, i, count = 0;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++) cin >> h.at(i);
  vector<int> ch(N, 0);
  l = 0;
  while (l != N) {
    for (i = 0; i < N; i++)
      if (h.at(i) != ch.at(i)) break;
    if (i == N) break;
    for (; l < N; l++)
      if (h.at(l) != ch.at(l)) break;
    for (r = l; r < N - 1; r++)
      if (h.at(r + 1) == ch.at(r + 1)) break;

    for (i = l; i <= r; i++) ch.at(i) += 1;
    count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3532
import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        int p=sc.nextInt();
        for(int i=0;i<p;i++){
            String order=sc.next();
            int a=sc.nextInt();
            int b=sc.nextInt();
            
            if(order.equals("replace")){
                String rep=sc.next();
                str=str.substring(0,a)+rep+str.substring(b+1,str.length());
            }else if(order.equals("reverse")){
                StringBuffer sb=new StringBuffer(str.substring(a,b+1));
                String rvs=sb.reverse().toString();
                str=str.substring(0,a)+rvs+str.substring(b+1,str.length());
            }else{
                System.out.println(str.substring(a,b+1));
            }
        }
    }
}


Measured memory_bytes: 29488
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        String s = scanner.next();
        if (s.length() <= k) {
            System.out.println(s);
        }else {
            System.out.println(s.substring(0, k) + "...");
        }
    }
}


Measured memory_bytes: 38604
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    W, H, x, y = map(int, readline().split())

    ans = [W * H / 2]

    if W == 2 * x and H == 2 * y:
        ans.append(1)
    else:
        ans.append(0)

    print(*ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	if (a == b && b == c)cnt = 1;
	else if (a == b || b == c || c == a) cnt = 2;
	else cnt = 3;

	cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N;
	std::cin >> N;
	double p;
	p = 1.0*((N+1)/2)/N;
	printf("%.12f\n", p);
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

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

    int n, m;
    cin >> n >> m;
    vvi edges(n);
    int s;
    int t;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
        if (i == 0) {
            s = a;
            t = b;
        }
    }
    deque<int> ret = {s, t};
    set<int> used;
    used.insert(s);
    used.insert(t);
    while (true) {
        bool ok = true;
        for (auto &n : edges[s]) {
            if (used.count(n) == 0) {
                used.insert(n);
                ret.push_front(n);
                s = n;
                ok = false;
                break;
            }
        }
        if (ok)
            break;
    }
    while (true) {
        bool ok = true;
        for (auto &n : edges[t]) {
            if (used.count(n) == 0) {
                used.insert(n);
                ret.push_back(n);
                t = n;
                ok = false;
                break;
            }
        }
        if (ok)
            break;
    }
    cout << ret.size() << "\n";
    for (int i = 0; i < ret.size(); ++i) {
        cout << ret[i] + 1 << " ";
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 11392
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)
#define RFOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)
#define exist(c, v) (find((c).begin(), (c).end(), (v)) != (c).end())

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

template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
	return os;
}

const int MAX_LENGTH = 201;
string s;
set<int> dp[MAX_LENGTH][MAX_LENGTH];

int stoi(string str) {
	istringstream is(str);
	int res;
	is >> res;
	return res;	
}

set<int> expr(int l, int r) {
	if(dp[l][r].size())
		return dp[l][r];

	int depth = 0;
	bool found = false;
	for(int i = l; i < r; ++i) {
		switch(s[i]) {
		case '(': ++depth; break;
		case ')': --depth; break;
		case '+':
		case '-':
		case '*':
		case '/':
			if(depth == 0) {
				found = true;
				set<int> left = expr(l, i);
				set<int> right = expr(i + 1, r);
				FOR(it, left) {
					FOR(it2, right) {
						switch(s[i]) {
						case '+': dp[l][r].insert(*it + *it2); break;
						case '-': dp[l][r].insert(*it - *it2); break;
						case '*': dp[l][r].insert(*it * *it2); break;
						case '/': if(*it2) dp[l][r].insert(*it / *it2);
						}
					}
				}
			}
		}
	}

	if(!found) {
		if(s[l] == '(')
			dp[l][r] = expr(l + 1, r - 1);

		else
			dp[l][r].insert(stoi(s.substr(l, r - l)));
	}

	return dp[l][r];
}

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

	while(cin >> s, s != "#") {
		for(int i = 0; i < MAX_LENGTH; ++i)
			for(int j = i + 1; j < MAX_LENGTH; ++j)
				dp[i][j].clear();

		cout << expr(0, s.size()).size() << endl;
	}

	return EXIT_SUCCESS;
}

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

string s;
long long k;

void init(){
	cin>>s;
	cin>>k;
}

int main(){
	init();
	k--;
	if(s[0]=='1'){
		
		for(long long i=1;i<s.size()&&i<k;i++)
		if(s[i]!='1'){
			cout<<s[i]<<endl;
			return 0;
		}
		cout<<s[k]<<endl;
		return 0;
	}
	cout<<s[0]<<endl;
	return 0;
}

Measured memory_bytes: 256
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <random>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef long long LL;
typedef  vector<int> VI;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(c) REP(i,SZ(c))cerr<<#c<<i<<"="<<(c[i])<<endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int MOD = 1000000007;
int main()
{
	int a,b,c;
	cin >> a>>b>>c;
	if (b >= c)
	{
		cout << "delicious" << endl;
	}
	else if (a >=(c - b))
	{
		cout << "safe" << endl;
	}
	else
	{
		cout << "dangerous" << endl;
	}
#ifdef _DEBUG
	while(1);
#endif // _DEBUG

	return 0;
}

Measured memory_bytes: 256
in_data=input()

in_list=[]

in_list=in_data.split(" ")

in_list[0]=int(in_list[0])
in_list[1]=int(in_list[1])


if in_list[0]<in_list[1]:
    print("a"+" "+"< "+"b")

elif in_list[0]>in_list[1]:
    print("a"+" "+"> "+"b")

else :
    print("a"+" "+"== "+"b")






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

int main(){
    string S; cin >> S;
    list<char> Slist, Slist_rev;
    for( int i = 0; i < S.size(); i++ ){
        Slist.emplace_front(S[i]);
        Slist_rev.emplace_back(S[i]);
    }
    auto itr = Slist.begin();
    auto itr_r = Slist_rev.begin();
    int ans = 0;
    while( itr != Slist.end() || itr_r != Slist_rev.end() ){
        if( *itr == *itr_r ){
            itr++;
            itr_r++;
        } else if ( *itr == 'x' ){
            Slist_rev.insert(itr_r,'x');
            itr_r--;
            ans++;
        } else if ( *itr_r == 'x' ){
            Slist.insert(itr,'x');
            itr--;
            ans++;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 12800
n, l = [int(i) for i in input().split()]
if l <= 0 and l + n - 1 >= 0:
    print((l-1)*n + n*(n+1)//2)
elif l > 0:
    print((l-1)*n + n*(n+1)//2 - l)
else:
    print((l-1)*n + n*(n+1)//2 - (l+n-1))


Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
#define fs  first  
#define sc  second
#define ARR array
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
 
#include <bits/stdc++.h>
using namespace  __gnu_pbds; 
using namespace std;
 
 
// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif
 
typedef long long ll;  
inline void WRITE_CHAR(char c)  {putchar_unlocked(c);} 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  while (!isdigit(ch) && ch!=EOF) minus = (ch == '-'? -1 : minus),ch= (char) getchar_unlocked();
 
  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char *x) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();
 
  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
const ll OOl = 1e18 ;
const int N = 1e6+1,OO = 1e9,OOm = 0x3f3f3f3f, MOD = 1e9 + 7;

int main()
{
  int n;
  READn(n);
  int tot = (n>>1) + (n&1);
  WRITEn(tot);  
  return 0;
}
 
 

Measured memory_bytes: 3596
from collections import defaultdict

Dic = defaultdict(int)
H, W, N = map(int, input().split())
ans = [0]*10

for i in range(N):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    for dx in range(-1, 2):
        for dy in range(-1, 2):
            if 1 <= a + dy <= H-2 and 1 <= b + dx <= W-2:
                Dic[(a+dy, b+dx)] += 1

for i in Dic:
    ans[Dic[i]] += 1
ans[0] = (H-2)*(W-2) - sum(ans)

for i in ans:
    print(i)


Measured memory_bytes: 166892