akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    int A[n];
    REP(i,n) cin >> A[i];
    int ans = 1;
    int B[3] = {};
    FOR(i,0,n){
        int cnt = 0;
        int id = 5;
        REP(j,3){
            if(B[j] == A[i]){
                chmin(id,j);
                cnt ++;
            }
        }
        if(id == 5){
            cout << 0 << endl;
            return 0;
        }
        ans *= cnt;
        B[id] ++;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
//57
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<utility>

using namespace std;

int main(){
  for(char w[11];cin>>w,w[0]!='0';){
    queue<pair<vector<int>,int> >que;
    vector<int> in;
    for(int i=0;w[i];i++){
      int n=(w[i]=='r')?1:(w[i]=='g')?2:4;
      in.push_back(n);
    }
    que.push(make_pair(in,0));
    set<vector<int> > s;
    while(!que.empty()){
      vector<int> v=que.front().first;
      if(s.find(v)!=s.end()){
	que.pop();
      }else{
	s.insert(v);
	int c=0;
	for(int i=0;i<v.size();i++){
	  c|=v[i];
	}
	if((c&(c-1))==0)break;
	for(int i=0;i<v.size()-1;i++){
	  if(v[i]!=v[i+1]){
	    vector<int> n=v;
	    int nc=7^v[i]^v[i+1];
	    n[i]=n[i+1]=nc;
	    que.push(make_pair(n,que.front().second+1));
	  }
	}
	que.pop();
      }
    }
    if(que.empty()){
      cout<<"NA"<<endl;
    }else{
      cout<<que.front().second<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2712
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int n,m; cin >> n >> m;
    if(n == 1 && m == 1) cout << 1 << endl;
    else if(n == 1) cout << m-2 << endl;
    else if(m == 1) cout << n-2 << endl;
    else cout << (ll)(n-2)*(m-2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int i, sum=0;
  char num;
  string N;
  cin >> N;
  for (i=0; N[i]!='\0'; i++) {
    num=N[i];
    sum+=atoi(&num);
  }
  if (atoi(N.c_str())%sum==0) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}

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

using namespace std;

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int m = 0;
	if (s[0] == 'E') m--;
	int k = m;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'W') m++;
		if (s[i + 1] == 'E') m--;
		k = min(k, m);
	}
	if (s[n - 1] == 'W') m++;
	cout << (n - m) / 2 + k << endl;
	return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007
 
const int mxN = 2e5 + 1;
//ll a[mxN];
ll n, x, t;
 
 
int main()
{
FIO

    string s;
    cin >> s;
    ll sum = 0;
    for(int i = 0; s[i]; i++)
        sum += s[i] - '0';

    cout << (sum % 9 ? "No" : "Yes");

    return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
#define reg register
using namespace std;
typedef long long ll;
int n,m,len[10],p[10],f[305][70];
int main(){
	scanf("%d%d",&n,&m);
	if(n==2){
		scanf("%d%d",len+1,len+2);
		reg double t=max(len[1]+len[2]-m,0);
		printf("%.16lf\n",min(t/m,1.0));
		return 0;
	}
	for(reg int i=1;i<=n;i++)scanf("%d",len+i);
	sort(len+1,len+1+n);
	reg int L=len[n];reg double Ans=0,fac=0;
	do{
		memset(f,0,sizeof(f));
		f[L*n][0]=1;
		for(reg int i=0;i<=n*m;i++)
			for(reg int j=i;j<=n*m;j++)
				for(reg int s=0;s<(1<<(n-1));s++)
					if(i%n&&!((s>>(i%n-1))&1))
						f[min(n*m,max(j,i+len[i%n]*n))][s|(1<<(i%n-1))]+=f[j][s];
		Ans+=f[n*m][(1<<(n-1))-1];
		fac++;
	}while(next_permutation(len+1,len+n));
	printf("%.16lf\n",Ans/((double)fac*pow(m,n-1)));
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <unordered_set>

using namespace std;

const int L=1005;
const int N=1000005;
const int M=8000005;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};

int n,m,S,T;
int sx,sy,tx,ty,cnt;
bool g[L][L];
int h[N],e[M],ne[M],idx;
int q[N],qx[N],qy[N],hh,tt;
int id[L][L],dist[N];

bool read()
{
    char ch=getchar();
    while(ch!='.'&&ch!='#')ch=getchar();
    return ch=='.';
}

void add(int a,int b)
{
    e[++idx]=b;
    ne[idx]=h[a];
    h[a]=idx;
}

void dfs(int x,int y)
{
    *qx=x,*qy=y,hh=tt=0;
    id[x][y]=cnt;
    unordered_set<int> s;
    while(hh<=tt)
    {
        int x=qx[hh],y=qy[hh++],nx,ny;
        if(x==sx&&y==sy)S=cnt;
        if(x==tx&&y==ty)T=cnt;
        for(int i=0;i<4;i++)
        {
            nx=x+dx[i],ny=y+dy[i];
            if(nx&&ny&&nx<=n&&ny<=m&&g[nx][ny]&&!id[nx][ny])
                qx[++tt]=nx,qy[tt]=ny,id[nx][ny]=cnt;
        }
        for(int i=x-2;i<x+3;i++)
            for(int j=y-2;j<y+3;j++)
                if(i>0&&j>0&&i<=n&&j<=m&&g[i][j]&&id[i][j]&&id[i][j]!=cnt&&!s.count(id[i][j]))
                    add(cnt,id[i][j]),add(id[i][j],cnt),s.insert(id[i][j]);
    }
}

int bfs()
{
    memset(dist,0x3f,sizeof dist);
    dist[S]=0,*q=S,hh=tt=0;
    while(hh<=tt)
    {
        int t=q[hh++];
        if(t==T)return dist[t];
        for(int i=h[t];i;i=ne[i])
            if(dist[e[i]]>dist[t]+1)
                dist[e[i]]=dist[t]+1,q[++tt]=e[i];
    }
    return -1;
}

int main()
{
    scanf("%d %d\n%d %d\n%d %d\n",&n,&m,&sx,&sy,&tx,&ty);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            g[i][j]=read();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(g[i][j]&&!id[i][j])
                ++cnt,dfs(i,j);
    printf("%d\n",bfs());
    return 0;
}

Measured memory_bytes: 16044
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}



int main() {

  int s;
  cin >> s;

  // int ans = 100000;


  if (s == 25) {
    cout << "Christmas"<<endl;
  }
  if (s == 24) {
    cout << "Christmas Eve"<<endl;
  }

  if (s == 23) {
    cout << "Christmas Eve Eve"<<endl;
  }

  if (s == 22) {
    cout << "Christmas Eve Eve Eve"<<endl;
  }


  // cout << ans;
  // cout << ((n == 3 || n==5 || n==7)? "YES" : "NO" );
  // cout <<"w:" <<w << "  h:" <<h<<endl;

}




















Measured memory_bytes: 256
N, K = map(int, input().split())
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, 100000 + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

for i in range(1, K+1):
    print((cmb(K-1, i-1, 1000000007)*cmb(N-K+1, i, 1000000007)) % 1000000007)


Measured memory_bytes: 58992
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
    string s;

    cin >> s;

    int cnt =0 ;
    for(int i=0; i<s.size()/2; i++)
    {
        if(s[i] != s[s.size()-1-i])
        {
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3636
# include<bits/stdc++.h>
using namespace std;
int main()
{
  int x;
  int n,m;
  int flag=0;
  cin>>x;
  cin>>n>>m;
  for(int i=n;i<=m;i++)
  {
    if(i%x==0)
    {
      flag=1;
      break;
    }
  }
  if(flag==1)
    cout<<"OK"<<endl;
  else
    cout<<"NG"<<endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int N = 3007;

vector <int> g[N];

int dp[N];

void dfs(int u) {
  for (auto v : g[u]) {
    dfs(v);
    dp[u] |= (dp[v] == 0);
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i + 1 < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    if (a[u] < a[v]) g[v].push_back(u);
    if (a[u] > a[v]) g[u].push_back(v);
  }
  for (int i = 0; i < n; ++i) dfs(i);
  for (int i = 0; i < n; ++i) {
    if (dp[i]) {
      cout << i + 1 << ' ';
    }
  }
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

void binary_convert(int x,vector<bool> &ob){
    for(int i=0;i<20;i++){
        ob[i]=bool(x%2);
        x/=2;
    }
}

bool matching(vector<bool>&x,vector<bool> &y,vector<bool> &ans){
    bool ju=false;
    for(int i=0;i<20;i++){
        if(x[i]&&y[i]){
            ans[i]=true;
            ju=true;
        }
        else{
            if(y[i]){
                x[i]=true;
            }
        }
    }
    return ju;
}

void shrinking(vector<bool> &ans,vector<vector<bool>> &da,int &l,vector<bool> &now){
    bool ju=false;
    for(int i=0;i<20;i++){
        if(ans[i]){
            if(da[l][i]){
                ans[i]=false;
            }
            else{
                ju=true;
            }
        }
        else{
            if(da[l][i]){
                now[i]=false;
            }
        }
    }
    l++;
    if(ju){
        shrinking(ans,da,l,now);
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> inp(n);
    for(int i=0;i<n;i++){
        cin >> inp[i];
    }
    vector<vector<bool>> da(n,vector<bool>(20));
    for(int i=0;i<n;i++){
        binary_convert(inp[i],da[i]);
    }
    int l=0,r=0;
    long long ans=0;
    vector<bool> now(20,false);
    while(r<n){
        vector<bool> memo(20,false);
        if(matching(now,da[r],memo)){
            shrinking(memo,da,l,now);
        }
        ans=(long long)ans+r-l+1;
        r++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
 int a,b;
 cin >> a>>b;
 int count = 0;
 while(a>0){
   a/=b;
   count ++;
 }
 cout << count << endl;
 return 0;
}

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;

  int x = 100 * r + 10 * g + b;
  if (x % 4 == 0)
    cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

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


int main(){
    int N, K,x=0, ans, A[220000];
    cin >> K >> N;
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 1; i < N; ++i){
        x = max(x, A[i] - A[i-1]);
    }
    x = max(x, A[0] + K - A[N-1]);
    ans = K - x;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;


bool Card[4][13];

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		char Picture;
		int Num;

		cin >> Picture >> Num;
		Num--;

		switch (Picture) {
		case'S':
			Card[0][Num] = true;
			break;
		case'H':
			Card[1][Num] = true;
			break;
		case'C':
			Card[2][Num] = true;
			break;
		case'D':
			Card[3][Num] = true;
			break;
		}
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (!Card[i][j]) {
				switch (i) {
				case 0:
					cout << "S";
					break;
				case 1:
					cout << "H";
					break;
				case 2:
					cout << "C";
					break;
				case 3:
					cout << "D";
					break;
				}
				cout << " " << j + 1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 100005;
typedef long long i64;

int N, K, mask = 0;
int A[MAX_N], B[MAX_N];

int main() {
  i64 result = 0;
  
  scanf("%d%d", &N, &K);

  for (int i = 1; i <= N; ++i)
    scanf("%d%d", &A[i], &B[i]);
  
  for (int i = 29; i >= 0; --i) 
    if ((K >> i) & 1) {
      i64 now = 0;

      mask |= (1 << i) - 1;
      for (int j = 1; j <= N; ++j)
	if ((mask | A[j]) == mask)
	  now += B[j];
      result = max(result, now);

      mask++;
    }
  
  i64 now = 0;

  for (int j = 1; j <= N; ++j)
    if ((mask | A[j]) == mask)
      now += B[j];
  result = max(result, now);
  
  printf("%lld\n", result);
  return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

struct Node {
    int key;
    Node* prev;
    Node* next;
};

Node* nil;

void init() {
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key) {
    Node* x = (Node*)malloc(sizeof(Node));
    x->key = key;
    x->prev = nil;
    x->next = x->prev->next;
    x->prev->next = x;
    x->next->prev = x;
}

Node* listSearch(int key) {
    Node* cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node* x) {
    if (x == nil) return;
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void printList() {
    Node* cur = nil->next;
    int isf = 1;
    while (cur != nil) {
        if (not isf) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
    return;
}

int main(void){
    // Your code here!
    int n, key;
    char s[20];
    
    init();
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s %d", s, &key);
        if (s[0] == 'i') {
            insert(key);
        }
        else if (s[6] == 'F') {
            deleteFirst();
        }
        else if (s[6] == 'L') {
            deleteLast();
        }
        else {
            deleteKey(key);
        }
    }
    
    
    printList();
    return 0;
}



Measured memory_bytes: 34008
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define min_pq priority_queue<pll, vector<pll>, greater<pll> >
#define vpii vector<pair<int,int> >
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define modulo %
#define moduloe %=

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
ll add(ll a, ll b) {a+=b; while(a >= mod) a-= mod; while(a<0) a+= mod;}
ll mul(ll a, ll b) {return (a * 1LL *b % mod);}
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 500006;
const lf EPS = 0.000000001;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll dp[102][100010];
ll w[110], v[110];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        ll W;
        cin>>n>>W;
        rep1(i, 1, n)
            cin>>w[i]>>v[i];

        for(i=1;i<=100000;i++)
            dp[0][i] = 1e18;

        for(i=1;i<=n;i++)
        {
            for(j=0;j<=100000;j++)
            {
                dp[i][j] = dp[i-1][j];
                if(j - v[i] >= 0)
                    dp[i][j] = min(dp[i][j], dp[i-1][j - v[i]] + w[i]);
            }
        }

        ll mx = 0;
        for(i=0;i<=100000;i++)
        {
            if(dp[n][i] <= W)
                mx = i;
        }
        cout<<mx<<endl;
    }
    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b;
  c = a + b;
  if( c % 2 == 0) {
    cout << c / 2 << endl;
  }else {
    cout << (c + 1) / 2 << endl;
  }
}


Measured memory_bytes: 256
def main():
    num = int(input())
    counter = [0] * (num + 1)
    # func(41, 41, 41) = 10086
    # func(99, 1, 1) = 10002
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 123 - x - y + 1):
                tmp = (x + y + z) ** 2 - x * y - y * z - z * x
                if tmp > num:
                    break
                counter[tmp] += 1
    for count in counter[1:]:
        print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9268
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::*;
use std::string::*;
use std::f64::consts::PI;

struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }

    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }

    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let s: String = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();

        return s.parse::<T>().ok().unwrap();
    }

    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

fn prime_factorization(n: i64) -> HashMap<i64, i64> {
    let mut n = n;
    let mut res = HashMap::new();
    let mut i = 2;
    while i * i <= n {
        while n % i == 0 {
            n /= i;
            let count = res.entry(i).or_insert(0);
            *count += 1;
        }
        i += 1;
    }

    if n > 1 {
        res.insert(n, 1);
    }

    return res;
}

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let k: usize = sc.read();
    if k == 1 {
        println!("{}", 0);
    } else {
        println!("{}", n - k);
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s,int v,vector<int>&d,whei(edge)&G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size();i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int n;
	cin >> n;
	hei(int) s(n), t(n);
	rep(i, 0, n) {
		cin >> s[i];
		t[i] = s[i];
	}
	sort(t.begin(), t.end());
	rep(i, 0, n) {
		if (s[i] >= t[n / 2])cout << t[(n / 2) - 1] << endl;
		else cout << t[n / 2] << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
#define N 8
int col[N],dp[N*2-1],dn[N*2-1];
int row[N],pan[N];
void Queen(int i)
{
  int j,T;
  if(i==N)
    {
      for(T=0;T<N;T++)
    {
      for(j=0;j<N;j++){
	if(j==row[T])
	  printf("Q");
	else printf(".");
      }
      printf("\n");
    }
      return ;
    }
  if(i==N)
    {
      for(T=0;T<N;T++)
    {
      for(j=0;j<N;j++){
	if(j==row[T])
	  printf("Q");
	else printf(".");
      }
      printf("\n");
    }
      return ;
    }
  
  if(pan[i]!=-1){
    Queen(i+1);
    return ;
  }
  for(j=0;j<N;j++)
    {
      if(col[j]==-2)continue;
      if(dp[i+j]==-2)continue;
      if(dn[i-j+N-1]==-2)continue;
      row[i]=j;
      col[j]=dp[i+j]=dn[i-j+N-1]=-2;
      Queen(i+1);
      col[j]=dp[i+j]=dn[i-j+N-1]=-1;
    }
}
int main ()
{
  int n,i,p,o,j;
  for(i=0;i<N;i++)
    {
      row[i]=-1;
    }
for(i=0;i<N;i++)
    {
      col[i]=-1;
    }
for(i=0;i<N;i++)
  {
      pan[i]=-1;
    }


  
  for(i=0;i<N*2-1;i++)
    {
      dp[i]=-1;
      dn[i]=-1;
    }


  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&p,&j);
    pan[p]=j;
    row[p]=j;
    col[j]=-2;
    dp[p+j]=-2;
    dn[p-j+N-1]=-2;
    }
  Queen(0);
  
  

      

  return 0;
}
 


Measured memory_bytes: 2148
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    Q,H,S,D = MI()
    N = I()
    if(Q*2<H):
        H=2*Q
    if(H*2<S):
        S=H*2
    if(S*2<D):
        D=S*2
    print(N//2*D + ((N&1)*S))
if __name__ == '__main__':
    main()

Measured memory_bytes: 6224
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		char[] pp=new char[s.length()/2];
		for(int i=0; i<s.length()/2; i++){
			pp[i]=s.charAt(i);
		}
		int count=0;
		for(int i=s.length()-1; i>(s.length()-1)/2; i--){
			if(pp[s.length()-1-i]!=s.charAt(i)){
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> v(m);
  rep(i,m) {
    cin >> v[i].second >> v[i].first;
    v[i].second--; v[i].first--;
  }
  sort(v.begin(),v.end());
  int now = -1;
  int ans = 0;
  rep(i,m) {
    if(v[i].second<=now) continue;
    now = v[i].first-1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define int long long
#define ll long long
#define moder 1000000007
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
signed main(){
	string s;
	cin>>s;
	int ans=999;
	for(int i=0;i<s.size()-2;i++){
		if(ans>abs(753-stoi(s.substr(i,3))))ans=abs(753-stoi(s.substr(i,3)));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
            for (int i = 1; i <= b; ++i) {
                if ((a * i) % b == c) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 22868
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    cin >> S;
    int ans = 0;
    int count = 0;
    for(int i=0;i<S.size();i++){
        if(S[i] == 'R'){
            count++;
        }
        else{
            count=0;
        }
        if(ans<count){
            ans=count;
        }
    }
    cout << ans << endl;
}


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

typedef pair<int,int> p;
int N,R,L;
int d[1111111]={0};
int t[1111111]={0};
int x[1111111]={0};
int team[11111111]={0};
p rmq[1111111];

void updata(int k,int x){
  int no=k;
  k += N-2;
  rmq[k].first += x;
  rmq[k].second = no;
  while(k > 0){
    k = (k - 1) / 2;
    if(rmq[k*2+1].first > rmq[k*2+2].first){
      rmq[k] = rmq[k*2+1];
    }
    else if(rmq[k*2+1].first < rmq[k*2+2].first){
      rmq[k] = rmq[k*2+2];
    }
    else if(rmq[k*2+1].second < rmq[k*2+2].second){
      rmq[k] = rmq[k*2+1];
    }
    else{
      rmq[k] = rmq[k*2+2];
    }
  }
  return;
}


int main(){
  for(int i=0;i<1111111;i++){
    rmq[i].first = 0;
    rmq[i].second = 0;
  }
  int smp=0;
  int now=0;
  int now1=0;
  cin >> N >> R >> L;
  for(int i=0;i<R;i++){
    smp = rmq[0].second;
    cin >> d[i] >> t[i] >> x[i];
    //if(smp != rmq[0].second){
      team[smp] += t[i] - now;
      now = t[i];
      //}
    updata(d[i],x[i]);
    smp = rmq[0].second;
  }
  team[smp] += L - now;
  int a=0;
  int ans=1;
  for(int i=1;i<=N;i++){
    //cout<<team[i]<<endl;
    if(a < team[i]){
      ans = i;
      a = team[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 23684
n=int(input())
l = []
for _ in range(n):
    l.append(input())
if len(l)>len(set(l)):
  print("No")
  exit()
i=0
while i<n-1:
  if l[i][-1]!=l[i+1][0]:
    print("No")
    exit()
  else:
    i=i+1
print("Yes")

Measured memory_bytes: 3064
import Foundation
//10000x + 5000y + 1000z = Y
let rdInt = readLine()!.split(separator: " ").map({Int($0)!})
let N = rdInt[0]
let Y = rdInt[1]

var ansX = -1
var ansY = -1
var ansZ = -1

testlabel: for x in 0 ... N {
    for y in 0 ... N {
        let z = N-x-y
        if z < 0 {
            break
        }
            if 10000*x + 5000*y + 1000*z == Y {
                ansX = x
                ansY = y
                ansZ = N - x - y
                break testlabel
            }
    }
}
print(ansX,ansY,ansZ)

Measured memory_bytes: 13600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
int main() {
    ll N,K;
    cin >> N >> K;
    vector<long double> fl(N);
    vector<ll> ctm(N);
    long double ans=0;
    ll mact=0;
    for(int i=0;i<N;i++){
        ll ct=0;
        ll tmp=i+1;
        while(tmp<K){
            tmp*=2;
            ct++;
        }
        //fl[i]=(float)1.0/N*(float)1.0/pow(2,ct);
        ctm[i]=ct;
        mact=max(mact,ct);
        //ans+=fl[i];
    }
    ll tp=0;
    for(int i=0;i<N;i++){
        ll tmp=1;
        while(mact>ctm[i]){
            ctm[i]++;
            tmp*=2;
        }
        tp+=tmp;
    }
    ll bun=1;
    for(int i=0;i<mact;i++){
        bun*=2;
    }
    //ans=(float)1.0/N*tp/pow(2,mact);
    ans=(long double)tp/(long double)(N*bun);

    cout << fixed << setprecision(10) << ans << endl;
}

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

int main() {
    int n;
    int cnt = 0;
    bool flg_dup = false;
    vector<int> mochies;
    cin >> n;
    mochies = vector<int>(n);
    for (int i = 0; i < n; i++) cin >> mochies.at(i);

    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (i != j) {
                if (mochies.at(i) == mochies.at(j)) {
                    flg_dup = true;
                    break;
                }
            }
        }
        if (!flg_dup) cnt += 1;
        flg_dup = false;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
DBG = true
n = gets.to_i
a = gets.split.map{|x| x.to_i}
b = gets.split.map{|x| x.to_i}

sa = a.inject(:+)
sb = b.inject(:+)
if sa < sb
  print -1
  exit
end

fusoku = 0
nfusoku = 0
amari = []
for i in 0...n
  dif = b[i] - a[i]
  if dif > 0
    fusoku += dif
    nfusoku += 1
  elsif dif < 0
    amari << -dif
  end
end

if nfusoku == 0
  print 0
  exit
end

amari.sort_by!{ |x| -x }
namari = 0
sum = 0
for i in 0...amari.size
  sum += amari[i]
  namari += 1
  if sum >= fusoku
    print namari + nfusoku
    exit
  end
end


Measured memory_bytes: 17424
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May 17 21:40:36 JST 2020
 **/

signed main() {
    double a, b, H, M;
    std::cin >> a >> b >> H >> M;
    std::complex<double> x = std::polar(a, 2 * M_PI * (H / 12 + M / 60 / 12));
    std::complex<double> y = std::polar(b, 2 * M_PI * M / 60);
    std::cout << std::abs(x - y) << std::endl;
}


Measured memory_bytes: 4144
/**
 _____      _ _              ______     
/  ___|    (_|_)             |  _  \    
\ `--. _ __ _ _  __ _ _ __   | | | |___ 
 `--. \ '__| | |/ _` | '_ \  | | | / _ \
/\__/ / |  | | | (_| | | | | | |/ /  __/
\____/|_|  |_| |\__,_|_| |_| |___/ \___|
            _/ |                         
           |__/                          
All Required Header Files ********/
#include <bits/stdc++.h>  
using 		namespace 		std;
using 		lli= 			long long  int;
using 		ulli= 			unsigned long long int;
using 		ld= 			long double;
int main() {
	
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
	
	lli n,k,op=0;
	cin>>n>>k;
	cout<<max(op,min((n%k),(k-(n%k))));
	
	
	
	return 0;
}


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

using namespace std;


int main() {
	int N;
	long long sum[211111];

	cin >> N;
	sum[0] = 0;
	for(int i = 1; i <= N; i++) {
		long long A;
		cin >> A;
		sum[i] += sum[i - 1] + A;
	}

	sort(sum, sum + N + 1);

	int l = 0;
	int r = 0;
	long long count = 0;
	while(l <= N) {
		while(r <= N && sum[l] == sum[r]) r++;
		long long n = r - l;
		count += n*(n-1)/2;
		l = r;
	}

	cout << count << endl;

	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define lli long long int
#define f first
#define s second
#define fw(i, start, end) for (lli i = start; i < end; ++i)
int vis[100005][3];
int dp[100005][3];
int a[100005][3];
lli n;
int solve(int pos, int last)
{
    if (pos > n)
        return 0;
    if (vis[pos][last])
        return dp[pos][last];
    else
    {
        vis[pos][last] = 1;
        int best = 0;
        fw(i, 0, 3)
        {
            if (i != last)
                best = max(best, a[pos][i] + solve(pos + 1, i));
        }
        dp[pos][last] = best;
    }
    return dp[pos][last];
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // lli n;
    cin >> n;

    fw(i, 1, n + 1)
    {
        fw(j, 0, 3)
                cin >>
            a[i][j];
    }

    lli ans = fmax(solve(1, 0), fmin(solve(1, 1), solve(1, 2)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a;
    string s;
    cin>>a>>s;
    if(a>=3200) cout<<s;
    else cout<<"red";
}

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

// qsort
int compare(const void *a, const void *b)
{
  return *(int*)a - *(int*)b;
}

int main( int argc, char *argv[] )
{
  char c;

  scanf( "%c", &c );
  printf( "%c\n", c+1 );
}



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

int main()
{
    int rect_side_01 = 0;
    int rect_side_02 = 0;

    cin >> rect_side_01 >> rect_side_02;

    int area = rect_side_01 * rect_side_02;
    int sum_side = 2*rect_side_01 + 2*rect_side_02;

    cout << area << " " << sum_side << endl;

    return 0;
}

Measured memory_bytes: 1164
class Union:
  def __init__(s, num):
    s.T = [-1 for i in range(num)]
 
  def root(s, x):
    if s.T[x] < 0: return x, -s.T[x]
    t, k = s.root(s.T[x])
    s.T[x] = t
    return t, k
 
  def merge(s, x, y):
    an, am = s.root(x)
    bn, bm = s.root(y)
    if an == bn: return False
    if am < bm: an, bn  = bn, an
    s.T[an] += s.T[bn]
    s.T[bn] = an
    return True
 
  def size(s, x):
    return s.root(x)[1]

  def same(s, x, y):
    return s.root(x)[0] == s.root(y)[0]

import sys
input = sys.stdin.readline

N, M, K = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
 
uni = Union(N)
ans = [-1] * N
for a, b in AB:
  a -= 1
  b -= 1
  uni.merge(a, b)
  ans[a] -= 1
  ans[b] -= 1
 
L = [[] for _ in range(N)]
for c, d in CD:
  c -= 1
  d -= 1
  L[c].append(d)
  L[d].append(c)
 
for i in range(N):
  ans[i] += uni.size(i)
  for j in L[i]:
    if uni.same(i, j):
      ans[i] -= 1
 
ans = map(str, ans)
print(" ".join(ans))

Measured memory_bytes: 128604
from collections import defaultdict as ddict
d = (-1,0,1)
cmap = ddict(int)
h,w,n = map(int, input().split())
for _ in range(n):
  a,b = map(int, input().split()) 
  for x in d:
    for y in d:
      ca = a+x
      cb = b+y
      if 1<ca<h and 1<cb<w:
        cmap[(ca,cb)] += 1
l = [0]*10
j = list(cmap.values())
for i in range(1,10):
  l[i] = j.count(i)
l[0] = (h-2)*(w-2) - sum(l)
for x in l:
  print(x)

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

using i64 = int64_t;

#define rep(i, a) for (int i = 0; i < (int)(a); ++i)

long long int solve(string s) {
    long long int dp[20][2][2][2][2][2] = {1};
    rep(i, s.size()) rep(j, 2) rep(k, 2) rep(l, 2) rep(m, 2) rep(n, 2) {
        int lim = j ? 7 : s[i] - '0';
        rep(d, lim + 1) {
            if(d != 0 && d != 3 && d != 5 && d != 7)continue;
            if(n && d == 0)continue;
            dp[i + 1][j || d < lim][k || d == 3][l || d == 5][m || d == 7][n || d != 0] += dp[i][j][k][l][m][n];
            //cerr << i << " " << j << " " << k << " " << l << " " << m << " " << dp[i + 1][j || d < lim][k || d == 3][l || d == 5][m || d == 7][n || d != 0] << endl;
        }
    }
    long long int ans = 0;
    rep(j, 2) ans += dp[s.size()][j][1][1][1][1];
    return ans;
}

int main(){
    string s;
    cin >> s;
    cout << solve(s) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    string s;cin >> s;
    int n = s.size();
    int K;cin >> K;
    vector<vector<vl>> dp(n+10,vector<vl>(2,vl(K+1,0)));
    dp[0][0][0] = 1;
    for(int i=0;i<n;++i){
        int D = s[i] - '0';
        for(int j=0;j<2;++j){
            for(int k=0;k<=K;++k){
                for(int d=0;d<=(j?9:D);++d){
                    if(d==0){
                        dp[i+1][j || (d<D)][k] += dp[i][j][k];
                    }
                    else if(k<K)dp[i+1][j || (d<D)][k+1] += dp[i][j][k];
                }
            }
        }
    }
    cout << dp[n][0][K] + dp[n][1][K] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll	long long
#define mp make_pair
#define pb	push_back
#define ALL(_a)	_a.begin(), _a.end()
#define PI acos(-1.0)
#define MAX 200005
#define MOD 1000000007
#define nl '\n'
#define pqmin(x) priority_queue<x, vector<x>, greater<x>>
#define pqmax(x) priority_queue<x>
#define testCase(x) int x; cin>>x; while(x--)
#define int ll
void c_p_c() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
//............................................................
//   A'udhu Billaahi min ash-shaitwanir rajeem
//       Bismillah-ir Rahman-ir Raheem
//           Rabbi zidnee 'ilmaa
//............................................................
void solve() {
	int n;
	cin >> n;
	int x, a[n + 1] = {0};
	for (int i = 1; i < n; i++) {
		cin >> x;
		a[x]++;
	}
	for (int i = 1; i <= n; i++)cout << a[i] << nl;
}
int32_t main() {
	c_p_c();
	//testCase(t)
	solve();
	return 0;
}

Measured memory_bytes: 5196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;

int main(){
    ll i,j;
    ll n;
    cin>>n;

    ll a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);

    ll b[n];
    b[0]=a[0];
    ll cnt=1;
    for(i=1;i<n;i++){
        if(a[i]>2*b[i-1]) cnt=0;
        b[i]=b[i-1]+a[i];
        cnt++;
    }
    cout<<cnt<<endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
map<char,int>m;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(m[s[i]]!=1)
m[s[i]]=1;
else
m[s[i]]++;
}
if(m.size()==2)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<algorithm>

const double INF = 1e9;
const double EPS = 1e-9;

struct Point {
    Point() :x(INF), y(INF) {}
    Point(double x, double y) :x(x), y(y) {}
    double x, y;
};
struct Compare {
    bool f;
    Compare(bool f = false) :f(f) {}
    bool operator()(const Point& lhs, const Point& rhs) const {return f ? lhs.y < rhs.y : lhs.x < rhs.x;}
};
double distance(const Point& lhs, const Point& rhs) {
    double dx = lhs.x - rhs.x;
    double dy = lhs.y - rhs.y;
    return dx * dx + dy * dy;
}

struct Result {
    double d;
    Point p1, p2;
    Result() :d(INF) {}
    Result(double d, const Point p1, const Point p2) :d(d), p1(p1), p2(p2) {}
};
bool operator<(const Result& lhs, const Result& rhs) {return lhs.d < rhs.d;}

Result closest_pair_recursion(const std::vector<Point>::const_iterator& begin, const std::vector<Point>::const_iterator& end) {
    int size = end - begin;
    if(size <= 1) return Result();

    auto mid = begin + size / 2;
    Result r = std::min(closest_pair_recursion(begin, mid), closest_pair_recursion(mid, end));

    auto left = std::lower_bound(begin, end, Point(mid->x - r.d - EPS, mid->y), Compare());
    auto right = std::upper_bound(left, end, Point(mid->x + r.d + EPS, mid->y), Compare());
    std::vector<Point> y_sorted(left, right);
    std::sort(y_sorted.begin(), y_sorted.end(), Compare(true));

    for(auto i = y_sorted.begin(); i != y_sorted.end(); ++i) {
        for(auto j = i + 1; j != y_sorted.end(); ++j) {
            if(j->y - i->y >= r.d) break;
            if(distance(*i, *j) >= r.d) continue;
            r = Result(distance(*i, *j), *i, *j);
        }
    }
    return r;
}
Result closest_pair(std::vector<Point> point) {
    std::sort(point.begin(), point.end(), Compare());
    return closest_pair_recursion(point.begin(), point.end());
}

#include<iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<Point> point(n);
    for(auto& p: point) cin >> p.x >> p.y;
    auto answer = closest_pair(point);
    cout << distance(answer.p1, answer.p2) << endl;
}

Measured memory_bytes: 17448
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using ll = long long;
using namespace std;

const long long MOD = 1000000007;
const ll LINF = 1LL << 50;


int main() {
  ll N;
  cin >> N;

  ll nend = 0;

  while(nend*nend < N){
    nend += 1;
  }

  ll ans = LINF;
  for (ll n = 1; n <= nend; n++){
    if (N%n == 0){
      ans = min({ans,n+N/n-2});
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
char a[10001];
int main()
{
	cin>>a;
	bool flag=false;
	for(int i=0;i<strlen(a);i++)
	{
		if(a[i]=='C')flag=true;
		if(flag&&a[i]=='F'){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y);
#define sz(x) (int)(x.size())
#define nax 201010
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pi pair<int ,int>
#define pii pair <int,pi>
using namespace std;
int arr[nax];
int brr[5*nax];
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int n;
  sd(n);
  for(int i =1 ;i<=n;i++)
    sd(arr[i]);
  int fptr = 200000;int nptr = 200001;
  memset(brr,-1,sizeof brr);
  for(int i = 1;i<=n;i++)
  {
    if(i%2 == 1)
    {
      brr[fptr] = arr[i];
      fptr--;
    }
    else
    {
      brr[nptr] = arr[i];
      nptr++;
    }
  }
  if(n%2 == 0)
  {
    for(int i = 5*nax-1;i>=0;i--)
    {
        if(brr[i]!=-1)
          printf("%d ",brr[i]);
    }
  }
  else
  {
    for(int i = 0;i< 5*nax;i++)
    {
        if(brr[i]!=-1)
          printf("%d ",brr[i]);
    }
  }
  return 0;
}
 

Measured memory_bytes: 6912
a, b, K = gets.split(' ').map(&:to_i)

(1..K).each do |i|
  if i.odd?
    a -= 1 if a.odd?

    a /= 2
    b += a
  else # i.odd?
    b -= 1 if b.odd?

    b /= 2
    a += b
  end
end

puts "#{a} #{b}"

Measured memory_bytes: 1788