akhauriyash/Code-Regression huggingface dataset:
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=100111;
int n,a[maxn],b[maxn],pos[maxn*2];
LL pre[maxn*2];
pii vs[maxn*2];

int main()
{
	get1(n);
	for(int i=1;i<=n;i++)get2(a[i],b[i]);
	
	LL ans,s1=0,s2=0;
	for(int i=1;i<=n;i++)
	{
		s1+=a[i];
		s2+=b[i];
	}
	ans=min(s1,s2);
	
	for(int i=1;i<=n;i++)
	{
		vs[i]=mp(a[i],i);
		vs[i+n]=mp(b[i],i+n);
	}
	sort(vs+1,vs+n+n+1);
	for(int i=1;i<=n+n;i++)
	{
		pos[vs[i].ss]=i;
		pre[i]=pre[i-1]+vs[i].ff;
	}
	
	for(int i=1;i<=n;i++)
	{
		int cur=n-2;
		while(cur+(pos[i]>cur)+(pos[i+n]>cur)<n)cur++;
//		printf("pre= %lld %d %d\n",pre[cur],pos[i],pos[i+n]);
		ans=min(ans,pre[cur]+(pos[i]>cur?a[i]:0ll)+(pos[i+n]>cur?b[i]:0ll));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4992
def main():
    n = int(input())
    h = list(map(int,input().split()))
    dp = [0] * n
    dp[1] = abs(h[1]-h[0])
    for i in range(2,n):
        one_behind = dp[i-1] + abs(h[i-1] - h[i])
        two_behind = dp[i-2] + abs(h[i-2] - h[i])
        dp[i] = min(one_behind,two_behind)
    print(dp[n-1])



if __name__ == '__main__':
    main()


Measured memory_bytes: 20572
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
	    Scanner std = new Scanner(System.in);
	    int a = Integer.parseInt(std.next());
	    int b = Integer.parseInt(std.next());
	    int d = a/b;
	    int r = a%b;
	    double f = (double)a/(double)b;
	    String after = String.format("%.6f", f);
	    System.out.println(d+" "+r+" "+after);
	}
}

Measured memory_bytes: 26252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });
 
int main(){
    ll N;
    cin >> N;
    vector<ll> p(N);
    REP(i, N) cin >> p[i];

    DESC(p);
    ll sum = p[0]/2;
    FOR(i, 1, N) sum += p[i];
    cout << sum << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const int MAX_N=2e5+3;


const unsigned long long B=1e12+7;


int main(){
    LL X;cin>>X;
    for(LL A=-200;A<=200;A++){
        for(LL B=-200;B<=200;B++){
            if(A*A*A*A*A-B*B*B*B*B==X){
                cout<<A<<" "<<B<<endl;
                return 0;
            }
        }
    }
    while(1);
    return 0;
}

Measured memory_bytes: 3632
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll n,k,l,r;
    cin>>n>>k>>l>>r;
    ll m=n/2;
    vector<ll> a,b;
    for(int i=0;i<m;i++){
        ll b;
        cin>>b;
        a.push_back(b);
    }
    for(ll i=m;i<n;i++){
        ll a;
        cin>>a;
        b.push_back(a);
    }
    vector<vector<ll>> A,B;
    ll key=1; key<<=m; key--;
    A.resize(m+1);
    for(;key>=0;key--){
        ll sum=0;
        ll count=0;
        for(int i=0;i<m;i++){
            if(key>>i&1){sum+=a[i]; count++;}
        }
        A[count].push_back(sum);
    }
    ll R=n-m;
    key=1; key<<=R; key--;
    B.resize(R+1);
    for(;key>=0;key--){
        ll sum=0;
        ll count=0;
        for(int i=0;i<R;i++){
            if(key>>i&1){sum+=b[i]; count++;}
        }
        B[count].push_back(sum);
    }
    ll ans=0;
    for(int i=0;i<=m;i++){
        sort(A[i].begin(),A[i].end());
        for(int t=0;t<=R;t++){
            if(i+t!=k){continue;}
            sort(B[t].begin(),B[t].end());
            for(int k=0;k<A[i].size();k++){
                ll n=A[i][k];
                auto L=lower_bound(B[t].begin(),B[t].end(),l-n);
                auto R=upper_bound(B[t].begin(),B[t].end(),r-n);
                ans+=R-L;
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
const int64_t mod = 1000000009;

struct Mod {
  int64_t num;
  Mod () : num(0) {;}
  Mod (int64_t n) : num(n) {;}
  operator int64_t() { return num; }
};

Mod operator+(Mod a, Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator-(Mod a, Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator*(Mod a, Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator+=(Mod &a, Mod b) { return a = a + b; }
Mod operator-=(Mod &a, Mod b) { return a = a - b; }
typedef Mod Data;
typedef vector<Data> Array;
typedef vector<Array> Matrix;

Matrix operator*(const Matrix &lhs, const Matrix &rhs) {
  Matrix res(lhs.size(), Array(rhs[0].size(), 0));
  REP(i,lhs.size()) REP(j,rhs[0].size()) REP(k,rhs.size())
    res[i][j] = res[i][j] + lhs[i][k] * rhs[k][j];
  return res;
}
Matrix scalar(int size, Data k) {
  Matrix mat(size, Array(size, 0));
  REP(i,size) mat[i][i] = k;
  return mat;
}

Matrix operator^(const Matrix &lhs, const int64_t n) {
  if (n == 0) return scalar(lhs.size(), 1);
  Matrix res = (lhs * lhs) ^ (n / 2);
  if (n % 2) res = res * lhs;
  return res;
}

int main() {
  int dts = 0;
  while(1){
    int64_t w,h,n;
    cin>>w>>h>>n;
    if(!w)break;
    Matrix mat(w,Array(w));
    REP(i,w){
      if(i) mat[i][i-1] = 1;
      mat[i][i] = 1;
      if(i<w-1) mat[i][i+1] = 1;
    }
    map<int64_t,set<int64_t>> mm;
    vector<int64_t> ys;
    ys.push_back(0);
    ys.push_back(h-1);
    REP(i,n) {
      int64_t x,y;
      cin>>x>>y;
      --x;--y;
      mm[y].insert(x);
      ys.push_back(y);
    }
    sort(begin(ys),end(ys));
    ys.erase(unique(begin(ys),end(ys)),end(ys));
    int m=ys.size();
    Matrix ary(w,Array(1));
    ary[0][0]=1;
    REP(i,m-1){
      int64_t y=ys[i+1];
      int64_t d = ys[i+1]-ys[i]-1;
      auto pm = mat ^ d;
      ary = pm * ary;
      vector<Data> dp2(w+2);
      REP(j,w) {
        REP(k,3) {
          if (mm.count(y) == 0 || mm[y].count(j+k-1) == 0)
            dp2[j+k] += ary[j][0];
        }
      }
      REP(j,w) {
        ary[j][0] = dp2[j+1];
      }
    }
    ++dts;
    cout << "Case " << dts << ": " << ary[w-1][0] << endl;
  }
  return 0;
}

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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    vector<int> B(N);
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    vector<int> C(N - 1);
    for (int i = 0; i < N - 1; ++i) {
        cin >> C[i];
    }
    int res = 0;
    for (int i = 0; i < N; ++i) {
        res += B[A[i] - 1];
        if (i > 0 && A[i] == A[i - 1] + 1) {
            res += C[A[i - 1] - 1];
        }
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

a,b=map(int,input().split())
if a<=8 and b<=8:
    print("Yay!")
else:
    print(":(")


Measured memory_bytes: 38256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <queue> //C++
using namespace std; //C++



int main(void) {
	
	int a[10];
	cin >> a[1] >> a[2] >> a[3] >> a[4]>> a[5];

	int i;
	for (i = 1; i <= 5; i++) {
		if (a[i] == 0) {
			cout << i;
			return 0;
		}
	}


}


Measured memory_bytes: 3580
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static final void main(String[] args) {
        Main m = new Main();
        m.init();
        m.solve();
        out.flush();
    }

    // ========================================================================= //

    public void init() {

    }

    public void solve() {
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        int sn = s.length;
        int tn = t.length;

        boolean check0 = false;
        for (int i = sn - tn; i >= 0; i--) {
            boolean check1 = true;
            for (int j = 0; j < tn; j++) {
                if (s[j + i] == '?') continue;
                if (s[j + i] == t[j]) continue;
                check1 = false;
                break;
            }
            if (check1) {
                for (int j = 0; j < tn; j++) {
                    s[j + i] = t[j];
                }
                check0 = true;
                break;
            }
        }

        if (!check0) {
            out.println("UNRESTORABLE");
            return;
        }

        for (int i = 0; i < sn; i++) {
            if (s[i] == '?') s[i] = 'a';
        }

        out.println(s);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
 {
int n,k;
cin>>n>>k;
int a[n];
int ans=0;
for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
      if(a[i]>=k)
      ans++;
      
  }
  cout<<ans;
 }


Measured memory_bytes: 640
import java.util.Scanner;

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

        final double A = Integer.parseInt(sc.next());
        final double B = Integer.parseInt(sc.next());
        final double H = Integer.parseInt(sc.next());
        final double M = Integer.parseInt(sc.next());

        double parseH = H * 30d + (30d * (M / 60d));
        double parseM = M * 6d;

        double ang = Math.abs(parseH - parseM);
        double ans = Math.sqrt(Math.pow(A, 2) + Math.pow(B, 2) -2d * A * B * Math.cos(Math.toRadians(ang)));
        System.out.print(ans);
    }
}

Measured memory_bytes: 35960
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
  FAST/**/
   
   ll n,m,k;
   cin>>n>>m>>k;
   
   ll ***arr = new ll**[n];
   rep(n)
        arr[i] = new ll*[m];
   rep(n)
        repi(j,m)
            arr[i][j] = new ll[4];
   //memset(arr,0,sizeof(arr));
   rep(k)
   {
       ll r,c,v;
       cin>>r>>c>>v;
       r--,c--;
       arr[r][c][0] = v;
   }

   for(ll i=n-1;i>-1;i--)
   {
       for(ll j=m-1;j>-1;j--)
       {
           ll val = arr[i][j][0];
           arr[i][j][0] = 0;
           if(i+j == (n+m-2))
           {
               arr[i][j][1] = val;
               continue;
           }
           if(i+1<n)
           {
               ll maxi = max({arr[i+1][j][0],arr[i+1][j][1],arr[i+1][j][2],arr[i+1][j][3]});
               arr[i][j][0] = maxi;
               arr[i][j][1] = maxi + val;
           }
           
           for(ll st=0;st<4;st++)
           {
               if(j+1<m)
               {
                   arr[i][j][st] = max(arr[i][j][st],arr[i][j+1][st]);
                   if(st>0)
                        arr[i][j][st] = max(arr[i][j][st], arr[i][j+1][st-1] + val);
               }
           }
       }
   }
   
   ll ans = max({arr[0][0][0],arr[0][0][1],arr[0][0][2],arr[0][0][3]});
   cout<<ans;
   return 0;        
}  
  
          
   

Measured memory_bytes: 495548
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
map<int,int> arr;
void update(int key,int val)
{
  arr[key]=val;
}
int ref(int key)
{
  if(arr.count(key)) return arr[key];
  else return key;
}
int main(void)
{
  int n,a,d,m;
  cin >> n >> a >> d >> m;
  for(int i=0;i<m;++i){
    int x,y,z;
    cin >> x >> y >> z;
    if(x==0){
      int py,pz;
      py=ref(y);
      pz=ref(z);
      update(y,pz);
      update(z,py);
    }else{
      update(y,ref(z));
    }
  }
  int k;
  cin >> k;
  cout << a+d*(ref(k)-1) << endl;
  return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
char mg[120][120]={0};
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	for(int i=0;i<=100;i++)
		for(int k=0;k<=100;k++)
		{
			if(k<50)
				mg[i][k]=0;
			else
				mg[i][k]=1;
		}
	a--;
	b--;
	int h,l;
	h=1;
	l=0;
	while(b>0)
	{
		b--;
		mg[h][l]=1;
		if(h<99)
			h+=2;
		else
		{
			l+=2;
			h=1;
		}
	}
	h=1;
	l=99;
	while(a>0)
	{
		a--;
		mg[h][l]=0;
		if(h<99)
			h+=2;
		else
		{
			l-=2;
			h=1;
		}	
	}
	printf("100 100\n");
	for(int i=0;i<100;i++)
	{
		for(int k=0;k<100;k++)
		{
			if(mg[i][k]==0)
				printf(".");
			else
				printf("#");
		}
		printf("\n");
	}
	return 0;
 } 

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL dp[10005][105];
LL n,k,ans = 0;
string s;

int main(){
	cin >> s; n = s.length();
	cin >> k; s = ' ' + s;
	dp[0][0] = 1;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 0;j <= 9;j ++){
			for(LL l = 0;l <= k;l ++){
				dp[i][(j + l) % k] += dp[i - 1][l];
				dp[i][(j + l) % k] %= N;
			}
		}
	}
	LL sdg = 0;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 0;j < s[i] - '0';j ++){
			ans += dp[n - i][(k - (sdg + j) % k) % k];
			ans %= N;
		}
		sdg += (s[i] - '0');
		sdg %= k;
	}
	if(sdg == 0) ans ++;
	ans --; ans = (ans + N) % N;
	printf("%lld\n",ans);
	return 0;
}

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

typedef long long LL;
const int N = 4010;
const int Mod = 1e9 + 7;
int a, b, ans, f[N][N], C[N][N];

inline int dec(int x) {return x < 0 ? x + Mod : x;}
inline int inc(int x) {return x >= Mod ? x - Mod : x;}

template <class T> inline void in(T &x) {
	x = 0; int f = 0; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x = f ? -x : x;
}

inline void init() {
	int n = max(a, b);
	for (int i = 0; i <= n; ++i) C[i][0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= i; ++j) C[i][j] = inc(C[i - 1][j - 1] + C[i - 1][j]);
	for (int i = 0; i <= n; ++i) {
		f[i][0] = 1;
		for (int j = 1; j <= n; ++j) f[i][j] = inc(f[i][j - 1] + C[i][j]);
	}
	for (int i = 0; i <= n; ++i)
		for (int j = 1; j <= n; ++j) f[i][j] = inc(f[i][j - 1] + f[i][j]);
}

int main() {
	in(a), in(b), init();
	for (int p = 0; p <= a; ++p)
		for (int q = 0; q < b; ++q) {
			if (p + q > a) continue;
			if (!q) ans = inc(ans + 1);
			else ans = (1LL * C[b - 1][q] * f[q - 1][p] + (LL)ans) % Mod;
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 64256
s = input()
l = ["AKIHABARA","KIHABARA","AKIHBARA","AKIHABRA","AKIHABAR"]
l1 = ["KIHBR"]
l2 = ["AKIHBR","KIHABR","KIHBAR","KIHBRA"]
l3 = ["AKIHABR","AKIHBAR","AKIHBRA","KIHABRA","KIHABAR","KIHBARA"]
if s in l or s in l1 or s in l2 or s in l3:
  print("YES")
else:
  print("NO")

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


using namespace std;


map< pair<int,char>, string>mymap;
map< pair<int,char>, string> :: iterator it;

int main()
{


    int h;
    int W;

    cin>>h;
    cin>>W;

    int k;
    char j;

    for(int i=1; i<=h ;i++)
        for( k=1, j='A'; k<=W ; j++,k++ )
    {
        string str;

        cin>>str;

        mymap[make_pair(i,j)]=str;

    }

    for(it=mymap.begin() ;it!=mymap.end() ;it++)
    {
        if(it->second=="snuke")
        {
            cout<<it->first.second<<it->first.first<<endl;
            break;
        }

    }

    mymap.clear();



    return 0;

}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import collections
import itertools
import operator

class UnionFind:
  def __init__(self, elems=None):
    class KeyDict(dict):
      def __missing__(self, key):
        self[key] = key
        return key

    self.parent = KeyDict()
    self.rank = collections.defaultdict(int)
    self.size_ = collections.defaultdict(lambda: 1)

    if elems is not None:
      for elem in elems:
        _, _, _ = self.parent[elem], self.rank[elem], self.size_[elem]

  def find(self, x):
    if self.parent[x] == x:
      return x
    else:
      self.parent[x] = self.find(self.parent[x])
      return self.parent[x]

  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.rank[x] < self.rank[y]:
      self.parent[x] = y
      self.size_[y] += self.size_[x]
    else:
      self.parent[y] = x
      self.size_[x] += self.size_[y]
    if self.rank[x] == self.rank[y]:
      self.rank[x] += 1

  def are_same(self, x, y):
    return self.find(x) == self.find(y)

  def grouper(self):
    roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
    root = operator.itemgetter(1)
    for _, group in itertools.groupby(sorted(roots, key=root), root):
      yield [x for x, _ in group]

  def size(self,x):
    return self.size_[self.find(x)]


n,m = na()
g = UnionFind()
gg = [0]*n

for i in range(m):
    a,b = na()
    g.unite(a-1,b-1)
    gg[a-1] += 1
    gg[b-1] += 1

ans = -1

for j in gg:
    if j == 0:
        ans += 1

ans += len(list(g.grouper()))

print(ans)

Measured memory_bytes: 123508
n=int(input())
e=[[[],[]] for i in range(n)]
for i in range(n-1):
  u,v,w=map(int,input().split())
  u-=1
  v-=1
  w%=2
  e[u][w].append(v)
  e[v][w].append(u)

ans=[None for i in range(n)]
ans[0]=0
s=[0]
while s:
  ns=[]
  for i in s:
    for j in e[i][0]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=ans[i]
    for j in e[i][1]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=1-ans[i]
  s=ns
print("\n".join(map(str,ans)))

Measured memory_bytes: 112632
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int N,M,X,r=0,l=0;

int main(){
    cin>>N>>M>>X;
    int A[M];
    rep(i,M){
        cin>>A[i];
        if(X>A[i])l++;
        else r++;
    }
    out(min(r,l));
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define drep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

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

void _main() {
    int N;
    cin >> N;
    vector<pair<int, int>> robot(N);
    rep(i, 0, N) {
        int x, y;
        cin >> x >> y;
        robot[i] = make_pair(x+y, x-y);
    }
    sort(robot.begin(), robot.end());
    int cur = -inf;
    int ans = 0;
    fore(i, robot) {
        if ( cur <= i.second) {
           ans++;
           cur = i.first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int N;
    int H[20];
    scanf("%d", &N);
    for(int i = 0; i < N; i++){
        scanf("%d", &H[i]);
    }
    int ans = 1, high = H[0];
    for(int i = 1; i < N; i++){
        if(high <= H[i]){
            ans ++;
            high = H[i];
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <cmath>
using namespace std;

int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a+b)*h/2 << endl;	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,i,j,s[5];
  scanf("%d %d %d %d %d",&s[0],&s[1],&s[2],&s[3],&s[4]);
  for(i=0;i<5;i++){
    for(j=0;j<4;j++){
      if(s[j]<s[j+1]){
	a=s[j];
	s[j]=s[j+1];
	s[j+1]=a;
      }
    }
  }
  printf("%d %d %d %d %d\n",s[0],s[1],s[2],s[3],s[4]);
  return 0;
}
	

Measured memory_bytes: 596
<?php
//$queueからarray_shift()でひとつ頭を取り出す。
//$ary[]に体節の並びを保持。体節の長さ分だけfor(foreach)でまわして $ary[$i] と $ary[$i+1] とを比較
//もし、色が違えば$queueに次階層の状態を追加($array_push)
//体節の色がすべて同じなら終了する。
 
$file_handle = fopen('php://stdin', "r");   //fopen()は同位フォルダにファイルがあればその名前のみでOK
 
 
//wfs
function wfs() {
    global $cnt;
    global $sec;
    global $ary_start;
    global $goal_flag;
 
    $queue[0] = $ary_start;         //スタートを$queueに入れて開始
    $queue_size = count($queue[0]); //キューの長さを取得
    $queue[0]['sec'] = 0;           //スタート時の秒数(階層の深さ)を入れる
    while (!empty($queue)) {        //$queueが1つ以上あればループ
       $cur = array_shift($queue);  //配列$queueの頭から１つ取り出す。
        
       //終了条件。全ての配列が同じ色なら終了
       $cnt = 0;    //カウントの初期化
       for($i=0; $i<$queue_size; $i++){
           if ($cur[$i] !== $cur[0]){ break; }
           $cnt++;
       }
       if ($cnt === $queue_size) {
           $goal_flag = 1;
           $sec = $cur['sec'];  //ゴールした時の秒数
           break;   //色がすべて同じならwhileを抜ける
       }
        
       //探索
        for($i=0; $i<$queue_size-1; $i++){
            if ($cur[$i] !== $cur[$i+1]){
                $new = $cur;
                $new['sec'] = $cur['sec'] + 1;
                if ($cur[$i] !== 'r' && $cur[$i+1] !== 'r'){    
                    $new[$i] = 'r';  $new[$i+1] = 'r';
                } else if ($cur[$i] !== 'g' && $cur[$i+1] !== 'g'){
                    $new[$i] = 'g';  $new[$i+1] = 'g';
                } else {
                    $new[$i] = 'b';  $new[$i+1] = 'b';
                }
                $str = toString($new);
                if (empty($visited[$str])){
                    array_push($queue, $new);
                    $visited[$str] = 1;
                }
            }
        }
    }
}
 
//再訪防止用。配列のキーに文字列を設定するために使用
function toString($ary){
    $str = '';
    foreach ($ary as $key => $val){
        if (is_numeric($key)) { 
            $str = $str.$val;
        }
    }
    return $str;
}
 
 
while (1){
    //変数の初期化
    $cnt = 0;   //終了条件に使用
    $sec = 0;
    $goal_flag = 0;
 
    //ファイル読み込み
    $stdin = trim(fgets($file_handle));
    //終了条件
    if ($stdin == '0'){
        break;
    }
    $ary_start = str_split($stdin);
     
 
    //探索
    wfs();
 
    //出力
    if ($goal_flag === 1){
        echo $sec;
    } else {
        echo 'NA';
    }
    echo PHP_EOL;
}
 
fclose($file_handle);

Measured memory_bytes: 12928
#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;
 
const int INF = 1<<30;
const int MAX = 1000000;
typedef long long ll;
 
int main() {
    bool dp[MAX+1];
    bool prime[MAX+1];
    int n, m;
    memset(prime, true, sizeof(prime));

    for(int i = 2; i < sqrt(MAX); i++) {
        if(prime[i] == false)
            continue;
        for(int j = i*2; j < MAX; j += i)
            prime[j] = false;
    }

    while(cin >> n >> m, n) {
        for(int i = 0; i <= MAX; i++)
            dp[i] = false;
        dp[0] = true;

        for(int i = 0; i < n; i++) {
            int x;
            cin >> x;
            for(int t = 0; t <= m-x; t++) {
                if(dp[t])
                    dp[t+x] = true;
            }
        }

        int res = -1;
        for(int i = m; i >= 2; --i) {
            if(dp[i] && prime[i]) {
                res = i;
                break;
            }
        }
        if(res ==  -1)
            cout << "NA" << endl;
        else
            cout << res << endl;
    }
}

Measured memory_bytes: 3120
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint x[200100];
lint sum[200100];
int n;lint l;
lint cal(){
	x[n]=l+x[0];
	sum[0]=0;
	rep(i,n) sum[i+1]=sum[i]+i*(x[i+1]-x[i]);
	lint out=0;
	rep(i,n){
		int step=n-i-1;int t=i+step/2;
		lint ret=(x[i]+l-x[n-1])*step+x[i];
		ret+=(step-1)*(x[i+step/2]-x[i])-(2*(sum[i+step/2]-sum[i]-i*(x[i+step/2]-x[i])));
		ret+=2*(sum[n-1]-sum[t+1]-(t+1)*(x[n-1]-x[t+1]));
		if(step%2==0) ret+=2*(x[n-1]-x[t+1]);else ret+=x[n-1]-x[t+1];
		out=max(out,ret);
	}
	return out;
}
int main()
{
	cin>>l>>n;
	//x[0]=0;
	rep(i,n) cin>>x[i];
	lint out=cal();
	rep(i,n) x[i]=l-x[i];
	rep(i,n/2) swap(x[i],x[n-1-i]);
	out=max(out,cal());
	cout<<out<<endl;
	/*lint s0=0,s1=1;
	int a=0,b=n;
	while(a<=b){
		s0+=x[a+1]-x[a];a++;
		if(a<=b){
			s1+=x[b+1]-x[b];b--;
		}
	}
	a=0;b=n;
	while(a<=b){
		s1+=x[b+1]-x[b];b--;
		if(a<=b){
			s0+=x[a+1]-x[a];a++;
		}
	}
	cout<<max(s0,s1)<<endl;*/
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k, n, i, m=0;
    cin>>k>>n;
    int a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);

    for(i=1; i<n;i++)
    {
        m = max(m, a[i] - a[i-1]);
    }

    m = max(m, k - a[n-1] + a[0]);

    cout<<k-m<<endl;

    return 0;
}


Measured memory_bytes: 1024
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
ts=time.time()
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
show_flg=False
show_flg=True

an=0
k=0
s=list(input())
n=len(s)
d=[['R','U','D'],['L','U','D']]
for i in range(n):
    if s[i] in d[k]:
        0
    else:
        an=1
    k=1-k
    
print(YN[an])


Measured memory_bytes: 39404
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

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

int main(){
	int a[100],N;
	cin>>N;
	REP(i,N){
		cin>>a[i];
	}
	SORT(a,N);
	REVERSE(a,N);
	int alice=0,bob=0;
	for(int j=0;j<N;j=j+2){
		alice+=a[j];
	}
	for(int k=1;k<N;k=k+2)
		bob+=a[k];
	cout<<alice-bob;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<vector>
#include<utility> 
#include<queue> 
#include<algorithm>
using namespace std;
long long a[1005],b[1005],c[1005],d[1005],e[1005],f[1005],dir[5]={-1,0,1,0,-1};
bool used[3005][3005]={0},up[3005][3005]={0},down[3005][3005]={0},left[3005][3005]={0},right[3005][3005]={0}; 
vector<long long> x,y;
queue<pair<long long,long long>> que;
long long id_x(long long v){
	return lower_bound(x.begin(),x.end(),v)-x.begin();
}
long long id_y(long long v){
	return lower_bound(y.begin(),y.end(),v)-y.begin();
}
int main(){
	x.emplace_back(100000000000000000);
	x.emplace_back(-100000000000000000);
	y.emplace_back(100000000000000000);
	y.emplace_back(-100000000000000000);
	long long i,j,n,m;
	scanf("%lld%lld",&n,&m);
	for(i=0;i<n;i++){
		scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
		x.emplace_back(a[i]);
		x.emplace_back(b[i]);
		y.emplace_back(c[i]);
	}
	for(i=0;i<m;i++){
		scanf("%lld%lld%lld",&d[i],&e[i],&f[i]);	
		x.emplace_back(d[i]);
		y.emplace_back(e[i]);
		y.emplace_back(f[i]);
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	x.erase(unique(x.begin(),x.end()),x.end());
	y.erase(unique(y.begin(),y.end()),y.end());
	for(i=0;i<n;i++){
		a[i]=id_x(a[i]);
		b[i]=id_x(b[i]);
		c[i]=id_y(c[i]);
		for(j=a[i];j<b[i];j++){
			up[j][c[i]-1]=1;
			down[j][c[i]]=1;
		}
	}
	for(i=0;i<m;i++){
		d[i]=id_x(d[i]);
		e[i]=id_y(e[i]);
		f[i]=id_y(f[i]);
		for(j=e[i];j<f[i];j++){
			right[d[i]-1][j]=1;
			left[d[i]][j]=1;
		}
	}
	que.push({id_x(0)-1,id_y(0)-1});
	used[id_x(0)-1][id_y(0)-1]=1;
	while(que.size()){
		auto z=que.front();
		que.pop();
		for(i=0;i<4;i++){
			if((!i&&left[z.first][z.second])||(i==1&&up[z.first][z.second])||(i==2&&right[z.first][z.second])||(i==3&&down[z.first][z.second]))
				continue;
			long long r=z.first+dir[i],c=z.second+dir[i+1];
			if(r<0||c<0||r>=(int)x.size()||c>=(int)y.size()||used[r][c])
				continue;
			used[r][c]=1;
			que.push({r,c});
		} 
	}
	for(i=0;i<(int)x.size();i++){
		if(used[i][0]||used[i][y.size()-1]){
			puts("INF");
			return 0;
		}
	}
	for(i=0;i<(int)y.size();i++){
		if(used[0][i]||used[x.size()-1][i]){
			puts("INF");
			return 0;
		}
	}
	long long ans=0;
	for(i=0;i<(int)x.size()-1;i++)
		for(j=0;j<(int)y.size()-1;j++)
			if(used[i][j])
				ans+=(x[i+1]-x[i])*(y[j+1]-y[j]);
	printf("%lld\n",ans);
}


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

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

	vector<int> ln;

	for (int i = 0; i < n; i++) {
		int li;
		cin >> li;
		ln.push_back(li);
	}

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

	int count = 0;
	for (int i = n - 1; i >= 2; i--) {
		int l = 0;
		int r = i - 1;
		while (l < r) {
			if (ln[l] + ln[r] > ln[i]) {
				count += r - l;
				r--;
			}
			else {
				l++;
			}
		}
	}

	cout << count;
}


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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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; }

// UnionFind
struct UnionFind 
{
    vector <int> d;
    UnionFind(int n): d(n, -1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    } 
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -d[root(x)]; }
};

int main()
{
    int n, m;
    cin >> n >> m;

    vector <int> a(m), b(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    vector <ll> ans(m);
    ans[m-1] = (ll)n * (n-1) / 2;

    UnionFind x(n);

    for (int i = m-1; i >= 1; i--) {
        ans[i-1] = ans[i];

        if (!x.same(a[i], b[i])) {
            ans[i-1] -= (ll) x.size(a[i]) * x.size(b[i]);
            x.unite(a[i], b[i]);
        } 
    }

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



Measured memory_bytes: 3328
#include <bits/stdc++.h>
					using namespace std;
					#define pll pair<ll,ll>
					typedef long long ll;
					#define mod 51123987
					#define fi first
					#define se second
					#define mp make_pair
					#define pb push_back
					#define INF 1e15
			
					
					int main()
					{
						ll a,b;
						cin>>a>>b;
						for(ll i=1;i<=3000;i++)
						{
							if(floor(i*0.08)==a && floor(i*0.1)==b)
								{
									cout<<i;
									exit(0);
								}
						}
						cout<<-1;
					}


Measured memory_bytes: 256
while gets
  n = $_.to_i
  break if n == 0
  m = Array.new(n){ Array.new(n) }
  n.times { |i| m[i] = gets.split.map(&:to_i) }
  a = Array.new
  n.times { |i| a << m[i].min }
  mt = m.transpose
  b = Array.new
  n.times { |i| b << mt[i].max }
  puts (a & b).empty? ? 0 : a & b
end

Measured memory_bytes: 8620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main()
{
    string s;
    cin >> s;
    ll K;
    cin >> K;
    int cnt = 0;
    char x;
    rep(i, s.size())
    {
        if (s[i] == '1')
            cnt++;
        else
        {
            x = s[i];
            break;
        }
    }
    if (K <= cnt)
        cout << "1" << endl;
    else
        cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 05.10.2019 15:50:49       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> g(n);
  for (int i = 0; i < n; i++) {
    cin >> g[i];
  }
  int ans = 0;
  for (int st = 0; st < n; st++) {
    vector<int> dist(n, -1);
    vector<int> que(1, st);
    dist[st] = 0;
    for (int b = 0; b < (int) que.size(); b++) {
      for (int i = 0; i < n; i++) {
        if (g[que[b]][i] == '1' && dist[i] == -1) {
          que.push_back(i);
          dist[i] = dist[que[b]] + 1;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (g[i][j] == '1' && dist[i] == dist[j]) {
          cout << -1 << '\n';
          return 0;
        }
      }
    }
    int mx = *max_element(dist.begin(), dist.end());
    ans = max(ans, mx);
  }
  cout << ans + 1 << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 10005
using namespace std;
typedef long long ll;
ll n, k, dp[2][N][105];
char s[N];

ll f(ll ind, ll md, ll d){
	ll &r = dp[d][ind][md];
	if(r != -1)
		return r;
	if(ind > n){
		if(!md)
			return r = 1;
		return r = 0;
	}
	// cout << ind << " " << md << " " << d << endl;
	r = 0;
	if(!d){
		r = f(ind + 1, (md + s[ind] - '0')%k, 0);
		for(ll i = 0; i < s[ind] - '0'; i++)
			r = (r + f(ind + 1, (md + i)%k, 1) )%mod;
		return r;
	}
	for(ll i = 0; i < 10; i++)
		r = (r + f(ind + 1, (md + i)%k, 1) )%mod;
	return r;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	memset(dp, -1, sizeof dp);
	scanf("%s %lld",s + 1, &k);
	n = strlen(s + 1);
	printf("%lld\n", (f(1, 0, 0) + mod - 1)%mod );
	return 0;
}

Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n, d;
   cin >> n >> d;
   vector<vector<int>> x(n, vector<int>(d));
   rep(i, n) rep(j, d) cin >> x[i][j];
   int ans = 0;
   rep(i, n) {
      for (int j = i + 1; j < n; j++) {
         int sum = 0;
         rep(k, d) sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
         int norm = sqrt(sum);
         if (norm * norm == sum)
            ans++;
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
fact = math.factorial
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

N = i()
X = s()[::-1]
num1 = 1
num2 = 1
num3 = 0
num4 = 0
cnt = 0
for i in range(N):
    if X[i] == '1':
        cnt += 1
cnt1 = cnt+1#0用
cnt2 = cnt-1#1用
nums = []
ans = []
tans = [1]*N
for i in range(N):
    if X[i] == '0':
        nums.append(num1)
    else:
        num3 += num1
        num4 += num2
        nums.append(num2)
    if cnt1 != 0:
        num1 = (num1*2)%cnt1
    if cnt2 != 0:
        num2 = (num2*2)%cnt2
if cnt1 != 0:
    num3 %= cnt1
if cnt2 != 0:
    num4 %= cnt2
for i in range(N):
    if X[i] == '0':
        if cnt1 != 0: 
            ans.append((num3+nums[i])%cnt1)
        else:
            ans.append(0)
            tans[i] = 0
    else:
        if cnt2 != 0:    
            ans.append((num4-nums[i])%cnt2)
        else:
            ans.append(0)
            tans[i] = 0
ans.reverse()
tans.reverse()
def f(n):
    if n == 0:
        return
    tans[i] += 1
    c = n%(list(bin(n)[2:]).count('1'))
    f(c)
for i in range(N):
    f(ans[i])
for i in range(N):
    print(tans[i])

Measured memory_bytes: 102356
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[1000005];
bool edge[20][20];
bool flag,dame;
char s[1000005];
ll kai[1005];
ll dp[2000][2000];
ll ncr[2000][2000];

int main(){	
	cin >> n >> a >> b >> c >> d;
	dp[0][0] = 1;
	kai[0] = 1;
	kai[1] = 1;
	for(i=2;i<=2000;i++){
		kai[i] = rui(i,mod-2);
		kai[i] %= mod;
		//pe(i);p(kai[i]);
	}
	ncr[0][0] = 1;
	for(i=1;i<=1000;i++){
		for(j=0;j<=i;j++){
			if(j == 0 || i == j){
				ncr[i][j] = 1;
			}else{
				ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
				ncr[i][j] %= mod;
			}
			//pe(ncr[i][j]);
		}
		//el;
	}
	for(i=0;i<=b-a;i++){
		num = i + a;
		for(j=0;j<=n;j++){
			dp[i+1][j] += dp[i][j];
			dp[i+1][j] %= mod;
			if(n-j < num * c)continue;
			ll nokori = n-j;
			e = 1;
			for(k=1;k<=d;k++){
				if(nokori < num)break;
				e *= ncr[nokori][num];
				e %= mod;
				e *= kai[k];
				e %= mod;
				//p(e);
				nokori -= num;
				if(j + num * k > n)break;
				if(k >= c && j + num * k <= n){
					dp[i+1][j+num*k] += (dp[i][j]*e)%mod;
					dp[i+1][j+num*k] %= mod;
				}

			}
		}
	}
	//p(dp[0][0]);
	for(i=0;i<=b-a+1;i++){
		for(j=0;j<=n;j++){
		//	pe(dp[i][j]);
		}
		//el;
	}
	p(dp[b-a+1][n]);

	return 0;

}

Measured memory_bytes: 58368
#include <bits/stdc++.h>
using namespace std;
vector<int> A;
bool search(int N, int key) {
    A[N] = key;
    bool flag = false;
    for(int i = 0; i < N; i++) {
        if(A[i] == key) {
            flag = true;
            break;
        }
    }
    return flag;
}
int main() {
    int N;
    cin >> N;
    A.resize(N+1);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int Q;
    cin >> Q;
    int sum = 0;
    for(int i = 0; i < Q; i++) {
        int key;
        cin >> key;
        if(search(N, key)) {
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n;
    cin>>n;
    long long int sum=0,c=1;
    for(int i=1;i<n;i++)
    {
         if(n%i==0)
         {
              c=n/i;
              c--;
              sum=sum+c;    
          }
          else
          {
               c=n/i;
                sum=sum+c;    
          }
    }
    cout<<sum<<endl;
    
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
    char a;
    cin >> a;
    
    if(a=='A'){
        cout << 'T' << endl;
    }
    else if(a=='T'){
        cout << 'A' << endl;
    }
    else if(a=='C'){
        cout << 'G' << endl;
    }
    else{
        cout << 'C' << endl;
    }
    
}


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

long long int nsm(long long int n){
    return (n*n+n)/2;
}
int main(){
    string s;
  	cin>>s;
    char lastoccur = 65;
    long long int ans = 0;
    long long int lastcnt=0;
    for(int i=0;i<s.size();i++){
        long long int cnt = 1;
        while(i<s.size() && s[i]==s[i+1]){
            cnt++;
            i++;
        }
        if(lastoccur <= s.at(i)){
            if(lastcnt>=cnt)
                --cnt;
            else
                ans-=lastcnt;
        }
        lastoccur = s.at(i);
        lastcnt = cnt;
        ans+=nsm(cnt);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 900
// Problem : C - Ubiquity
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Delete the dynamically allocated memory

#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define pr              pair<long long,long long>
#define mp(a,b)         make_pair(a,b)
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fill(a,b)       memset(a, b, sizeof(a))
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)

ll modExp(ll a,ll b,ll p)
{
    if(a==0){
    	return 0;
    }
    if(b==0){
    	return 1;
    } 
    ll ans;
    if(b%2==0)
    {
        ll smallAns=modExp(a,b/2,p);
        ans=(smallAns*smallAns)%p;
    }
    else
    {
        ll smallAns=modExp(a,b-1,p);
        ans=a%p;
        ans=(ans*smallAns)%p;
    }
    return (ans+p)%p;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	if(n==1){
		cout<<0<<"\n";
	}else{
		ll v=modExp(10,n,mod1);
		ll v1=(2*modExp(9,n,mod1))%mod1;
		ll v3=modExp(8,n,mod1);
		cout<<((v-v1+mod1)%mod1+v3)%mod1<<"\n";
	}
	return 0;
	}
	
	
	
	
	
	



Measured memory_bytes: 3652