akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

//using namespace __gnu_pbds;
using namespace std ;

typedef pair<int, int> pi ;
//typedef tree< pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const i64 mod = 1000000007LL ;
#define INF 2000000000001LL
#define maxn 200005

/*
     *os.find_by_order(k) -> returns the k'th smallest element (indexing starts from 0)
      os.order_of_key(v)  -> returns how many elements are strictly smaller than v
*/

i64 dp[305][305][305] ;
int n , m ;

int f(int Left , int New , int rem)
{
    if( rem==0 )
    {
        if( New == 0 && Left == 0 ) return 1 ;
        return 0 ;
    }
    if(Left<0 || New<0 || rem<0) return 0 ;
    if( dp[Left][New][rem] != -1 ) return dp[Left][New][rem] ;

    int ans = (1LL*(n-Left-New)*f(0,New,rem-1))%mod ;
    ans =  (ans + 1LL*Left*f(Left,New,rem-1))%mod ;
    ans =  (ans + 1LL*New*f(Left+1,New-1,rem-1))%mod ;

    return dp[Left][New][rem] = ans ;
}

int main()
{
//    int n , m ;

    scanf("%d %d",&n,&m) ;

    memset(dp,-1,sizeof(dp)) ;

    printf("%d\n" , f(0,n-1,m) ) ;

    return 0 ;
}


Measured memory_bytes: 221952
def exe():
    print('Yes')
    exit()

A = []
for _ in range(3):
    A.append(list(map(int, input().split())))

N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0

for i in range(3):
    if sum(A[i]) == 0:
        exe()
    elif A[0][i]+A[1][i]+A[2][i]==0:
        exe()
if A[0][0]+A[1][1]+A[2][2] == 0:
    exe()
elif A[0][2]+A[1][1]+A[2][0] == 0:
    exe()

print('No')

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

void insertion_sort(int &cnt, vector<int> &arr, int n, int g)
{
  for (int i = g; i < n; i++) {
    int v = arr[i];
    int j = i - g;
    while (j >= 0 && arr[j] > v) {
      arr[j+g] = arr[j];
      j -= g;
      cnt++;
    }
    arr[j+g] = v;
  }
}

void shell_sort(vector<int> &arr, int n)
{
  int cnt;
  int m;  
  vector<int> G;
  
  cnt = 0;
  for (int g = 1; g <= n; g = 3*g+1) {
    G.push_back(g);
  }
  reverse(G.begin(), G.end());
  m = G.size();

  for (int i = 0; i < m; i++)
    insertion_sort(cnt, arr, n, G[i]);

  cout << m << endl;
  for (int i = 0; i < m; i++)
    cout << G[i] << (i==m-1?'\n':' ');
  cout << cnt << endl;
  for (int i = 0; i < n; i++)
    cout << arr[i] << endl;
}

int main()
{
  int n;
  vector<int> arr;

  cin >> n;
  arr = vector<int>(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];

  shell_sort(arr, n);
  return EXIT_SUCCESS;
}




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

int num, K;
long long ans;
deque<int> d;

void add(int tmp, int a, int b) {
  if (a == b) {
    long long ansa = 0;
    ++num;
    long long c = 1;
    if (num == K) {
      for (int i = 0; i < b; ++i) {
        ansa += d[b-i-1] * c;
        c *= 10;
      }
      ans = ansa;
    }
    // printf("%d\n", ansa);
    return;
  } else {
    if (tmp != 0) {
      d.push_back(tmp-1);
      add(tmp-1, a+1, b);
      d.pop_back();
    }
    d.push_back(tmp);
    add(tmp, a+1, b);
    d.pop_back();
    if (tmp != 9) {
      d.push_back(tmp+1);
      add(tmp+1, a+1, b);
      d.pop_back();
    }
  }
  return;
}
 
int main () {
  // long long ans;
  num = 9;
  cin >> K;
  if (K < 10) ans = K;
  for (int i = 1; i < 10; ++i) {
    int a = 0;
    for (int j = 1; j < 10; ++j) {
      d.push_back(j);
      add(j, 1, i+1);
      d.pop_back();
      if (num >= K) {
        a = 1;
        break;
      }
    }
    if (a == 1) {
      break;
    }
  }
  cout << ans << endl;
  // printf("%lld\n", ans[K]);
  // cout << d << endl;
  // cout << d[1] << endl;
  return 0;
}

Measured memory_bytes: 256
n, d[51], i,sum,j;

main(){
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&d[i]);
	for(i=0;i<n-1;i++)
		for(j=i+1;j<n;j++)
			sum+=d[i]*d[j];
	printf("%d\n",sum);
}

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


long kei(int n,vector<int> &moji){
  int m= moji.size();
  if(n == m-1)
    return moji.at(n);
  int x=0;
  for(int i=0;i<m-n-1;i++){
    x *=2;
    x += moji.at(n) * pow(10,i);
  }
  return moji.at(n)*pow(10,m-n-1)+x+kei(n+1,moji)*2;
}

int main(){
  string str;
  cin >> str;
  vector<int>moji(str.size());
  for(int i=0;i< str.size();i++){
    moji.at(i)= str.at(i)-48;
  }
  cout << kei(0,moji) << endl;
}
  

Measured memory_bytes: 4072
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 11000000000000000LL
#define MOD 1000000007

int main() {
	long long a, b, c, d, e, n, minn = INF;

	cin >> n;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;


	minn = min(a, minn);
	minn = min(b, minn);
	minn = min(c, minn);
	minn = min(d, minn);
	minn = min(e, minn);


	if (minn >= n) {
		cout << 5;
	}
	else {

		if ((n - minn) % minn == 0) {
			cout << 5 + (n - minn) / minn;
		}
		else {
			cout << 5 + (n - minn) / minn + 1;	
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
using ll = long long;
using P = pair<ll, ll>;

const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void fail() {
  cout << -1 << endl;
  exit(0);
}

int main(){
    string s;
    cin >> s;
    ll n = s.size();
    bool f = false;
    for(ll i=0; i < n; i++){
      for(ll j=i; j < n; j++){
        f = f || s.substr(0, i) + s.substr(j, n) == "keyence";
      }
    }
    if(f){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import math

N,D = map(int,input().split())

L = []
for i in range(N):
    x,y = map(int,input().split())
    s = math.sqrt(x**2 + y**2)
    L.append(s)

count = 0
for j in range(len(L)):
    if L[j] <= D:
        count += 1

print(count)

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 90000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

ll Z = 0;
ll d(ll a,ll i){
  a++;
  /*if(a < i){
    return 0;
  }
  if(a <= 2*i){
    return 2 * i - a + 1;
  }*/
  ll res = 0;
  res += a / (2*i) * i;
  if(a % (2*i) < i){
    return res;
  }else{
    return res + a % (2*i) - i;
  }
}
int main(){
  ll A,B;cin >> A >> B;
  vector<ll> C(40,0);
  for(int i = 0;i < 40;i++){
    C[i] = abs(d(A-1,pow(2,i)) - d(B,pow(2,i))) % 2;
  }
  ll ans = 0;
  for(int i = 0;i < 40;i++){
    ans += pow(2,i) * C[i];
    //cout << C[i];
  }
  //cout << endl;
  cout << ans << endl;
 // cout << d(A-1,1) << ' ' << d(A-1,2) << ' ' << d(A-1,4) << ' ' << d(A-1,8) << endl;
  //cout << d(B,1) << ' ' << d(B,2) << ' ' << d(B,4) << ' ' << d(B,8) << endl;
}



Measured memory_bytes: 256
import java.lang.Math.*
fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val coinCount = Array(2){IntArray(n){0}}
    var currentCost = 0L
    repeat(2 * n){
        val (x, y) = readLine()!!.trim().split(' ').map(String::toInt)
        if (x in 1 .. n) {
            if (y <= 1) {
                currentCost += 1 - y
                coinCount[0][x - 1]++
            }else {
                currentCost += y - 2
                coinCount[1][x - 1]++
            }
        }else {
            if (x <= 1){
                currentCost += 1 - x
                if (y <= 1){
                    currentCost += 1 - y
                    coinCount[0][0]++
                }else {
                    currentCost += y - 2
                    coinCount[1][0]++
                }
            }else {
                currentCost += x - n
                if (y <= 1){
                    currentCost += 1 - y
                    coinCount[0][n - 1]++
                }else {
                    currentCost += y - 2
                    coinCount[1][n - 1]++
                }
            }
        }
    }
    for (i in 0 until n - 1){
        if (coinCount[0][i] <= 0) {
            if (coinCount[1][i] > 1) {
                val move = min(1 - coinCount[0][i], coinCount[1][i] - 1)
                currentCost += move
                coinCount[0][i] += move
                coinCount[1][i] -= move
            }
            currentCost += 1 - coinCount[0][i]
            coinCount[0][i + 1] -= 1 - coinCount[0][i]
            coinCount[0][i] = 1
        }
        if (coinCount[1][i] <= 0){
            if (coinCount[0][i] > 1){
                val move = min(1 - coinCount[1][i], coinCount[0][i] - 1)
                currentCost += move
                coinCount[1][i] += move
                coinCount[0][i] -= move
            }
            currentCost += 1 - coinCount[1][i]
            coinCount[1][i + 1] -= 1 - coinCount[1][i]
            coinCount[1][i] = 1
        }
        if (coinCount[0][i] > 1){
            currentCost += coinCount[0][i] - 1
            coinCount[0][i + 1] += coinCount[0][i] - 1
            coinCount[0][i] = 1
        }
        if (coinCount[1][i] > 1) {
            currentCost += coinCount[1][i] - 1
            coinCount[1][i + 1] += coinCount[1][i] - 1
            coinCount[1][i] = 1
        }
    }
    currentCost += abs(coinCount[0].last() - 1)
    println(currentCost)
}


Measured memory_bytes: 105404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 1e5 + 10;
const ll LINF = LLONG_MAX;
int main() {
    fast();
 
    ll a,b;
    cin >> a >> b;
    cout<<((a-2*b>=0)?a-2*b:0); 
    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 256
using ll=long long;using ull=unsigned long long;
#include<limits>
namespace pcl{template<typename T>constexpr T TNF=std::numeric_limits<T>::max()/2;constexpr int INF=TNF<int>;constexpr ll LNF=TNF<ll>;constexpr double DNF=TNF<double>;constexpr double EPS=1e-8;constexpr int P7=1'000'000'007;constexpr int DX[]={1,0,-1,0,1,1,-1,-1};constexpr int DY[]={0,1,0,-1,-1,1,1,-1};}
#include<algorithm>
#include<cmath>
#include<iostream>
namespace pcl{template<typename T>void updmax(T&a,T const&b){a=std::max(a,b);}template<typename T>void updmin(T&a,T const&b){a=std::min(a,b);}template<typename T,typename U,typename V>bool in_range(T const&begin,U const&mid,V const&end){return begin<=mid&&mid<end;}template<typename T,typename U,typename V>bool in_range(T const&begin,std::initializer_list<U>list,V const&end){auto p=std::minmax_element(list.begin(),list.end());return begin<=*p.first&&*p.second<end;}template<typename T,typename U,typename V>bool in_range_strict(T const&begin,std::initializer_list<U>list,V const&end){if(!std::is_sorted(list.begin(),list.end()))return false;return in_range(begin,list,end);}template<typename T>inline T cget(){T x;std::cin>>x;return x;}}
#include<iostream>
#include<vector>
namespace pcl{template<typename T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){os<<'[';for(size_t i=0;i<v.size();i++){if(i!=0)os<<",";os<<v[i];}os<<']';return os;}template<typename T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(size_t i=0;i<v.size();i++)is>>v[i];return is;}}
#include<bits/stdc++.h>
using namespace std;using namespace pcl;int main(){int H,W;cin>>H>>W;vector<string>field(H);for(int i=0;i<H;i++)cin>>field[i];vector<vector<int>>hcnt(H,vector<int>(W));for(int i=0;i<H;i++){int s=-1;for(int e=0;e<=W;e++){if(e==W||field[i][e]=='#'){if(s!=-1){for(int j=s;j<e;j++)hcnt[i][j]=e-s;s=-1;}}else{if(s==-1)s=e;}}}vector<vector<int>>vcnt(H,vector<int>(W));for(int j=0;j<W;j++){int s=-1;for(int e=0;e<=H;e++){if(e==H||field[e][j]=='#'){if(s!=-1){for(int i=s;i<e;i++)vcnt[i][j]=e-s;s=-1;}}else{if(s==-1)s=e;}}}int res=0;for(int i=0;i<H;i++){for(int j=0;j<W;j++){if(field[i][j]=='#')continue;updmax(res,hcnt[i][j]+vcnt[i][j]-1);}}cout<<res<<endl;}


Measured memory_bytes: 35712
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> L(M); rep(i, M) cin >> L[i].first >> L[i].second;

    map<int, vector<int>> m;
    rep(i, M) {
        m[L[i].first].push_back(L[i].second);
    }

    for (auto& v: m) {
        sort(all(v.second));
    }

    rep(i, M) {
        auto p = lower_bound(all(m[L[i].first]), L[i].second);
        cout << std::setw(6) << std::setfill('0') << L[i].first << std::setw(6) << std::setfill('0') << (p - m[L[i].first].begin())+1 << endl;
    }
}


Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

void yes(){
    cout<<"Yes"<<endl;
}
void no(){
    cout<<"No"<<endl;
}

int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    if(a[n-1]==0){
        yes();
        return 0;
    }
    if(n%3==0){
        
        if(a[0]==a[n/3-1]&&a[n/3]==a[2*n/3-1]&&a[2*n/3]==a[n-1]){
            ll x=a[0],y=a[n/3],z=a[2*n/3];
            if(((x^y)==z)||((x^z)==y)||((y^z)==x)){
                yes();
                return 0;
            }
        }
    }
    no();
    
    return 0;
}


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

using namespace std;

int a[100005],b[100005];
int main()
{
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int p=0,t=1,q;
    for(q=1;q<n;q++){
        if(s[q]==s[q-1]){
            t++;
        }
        else{
            if(s[q-1]=='1')
            a[p++]=t;
            else
            a[p++]=-t;
            t=1;
        }
    }
    if(s[q-1]=='1')
    a[p++]=t;
    else
    a[p++]=-t;
    //for(int m=0;m<p;m++) cout<<a[m]<<endl;
    memcpy(b,a,sizeof(a));
    int i=0,j=0;
    int sum=0,ans=0;
    while(i<=j&&j<p){
        while(k>0&&j<p){
            if(a[j]<0){
                a[j]=-a[j];
                k--;
                j++;
            }
            else
            j++;
        }
        j--;
        sum=0;
        while(a[j]>0&&j<p) j++;
        j--;
        for(int m=i;m<=j;m++) sum+=a[m];
        ans=max(ans,sum);
        k++;
        for(int m=i;m<j;m++){
            if(b[m]<0){
                i=m;
                break;
            }
        }
        i++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1280
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
import itertools
lst = [i+1 for i in range(n)]
l = [0]*len(lst)
for i in itertools.permutations(lst):
    l.append(list(i))
for i in range(len(l)):
    if p == l[i]:
        a = i
    if q == l[i]:
        b = i
print(abs(b-a))

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

int main(void) {
	int N, X, L[100], D = 0, count = 1, i;
	cin >> N >> X;
	for (i = 0; i < N; i++) {
		cin >> L[i];
	}

	for (i = 0; i < N; i++) {
		D += L[i];
		if (D <= X)
			count++;
		else
			break;
	}

	cout << count;
}

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


int main(){
    int x , n ;
    cin >> x >> n ;
    vector<int> p(n) ;
    if(n != 0 ) rep(i,n) cin >> p[i] ;
    sort(p.begin(),p.end()) ;
    int ans = 100000 ;
    int tem = 0 ;
    int count = 0 ;
    rep(i,102){
        count = 0 ;
        rep(j,n) if( i == p[j] ) count++  ;
        if(count == 0 ){
            if( ans >= abs(x-i) ){
                if( ans != abs(x-i) ){
                    ans = abs(x-i) ;
                    tem = i - x ;
                }
            }
        } 
    }
    cout << x + tem << endl;
}

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

map<string,int> normal;
map<string,vector<string> > rec;

int f(string x){
	int ans = normal[x] , sum = 0;
	if( rec[x].size() == 0 ) return ans;
	for(int i = 0 ; i < rec[x].size() ; i++){
		sum += f(rec[x][i]);
	}
	return min(ans,sum);
}

int main(){
	int n;
	while(cin >> n && n){
		normal.clear();
		rec.clear();
		for(int i = 0 ; i < n ; i++){
			string a;
			int b;
			cin >> a >> b;
			normal[a] = b;
		}
		int m;
		cin >> m;
		for(int i = 0 ; i < m ; i++){
			string x,y;
			cin >> x;
			int t;
			cin >> t;
			for(int j = 0 ; j < t ; j++){
				cin >> y;
				rec[x].push_back(y);
			}
		}
		string want;
		cin >> want;
		cout << f(want) << endl;
	}
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define ll long long int
using namespace std;
int main()
{
    ll a,b,c,n,x,y,z,cnt=0,sum=0;
    string str;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;


}




Measured memory_bytes: 3620
import sys
from collections import deque

input = sys.stdin.readline
n, k = map(int, input().split())
s_list = list(map(int, list(input()[:-1])))
new_list = []
tmp = 0
for s in s_list:
    if s == 1:
        if tmp < 0:
            new_list.append(tmp)
            tmp = 1
        else:
            tmp += 1
    else:
        if tmp > 0:
            new_list.append(tmp)
            tmp = -1
        else:
            tmp -= 1
new_list.append(tmp)
q = deque([]) 
new_len = len(new_list)
if new_list[0] < 0:
    flag = 0
else:
    flag = 1
check = 0
cnt = 0
tmp = 0
for p in new_list:
    if p > 0:
        q.append(p)
        tmp += p
    else:
        if check < k:
            q.append(p)
            check += 1
            tmp += abs(p)
        else:
            pop_p = q.popleft()
            if pop_p > 0: 
                tmp -= pop_p
                tmp -= abs(q.popleft())
            else:
                tmp -= abs(pop_p)
            q.append(p)
            tmp += abs(p)
    cnt = max(cnt, tmp)
print(cnt)


Measured memory_bytes: 5276
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    struct P
    {
        public int index;
        public List<int> ad;
        public Dictionary<int, int> weights;
        public P(int index)
        {
            this.index = index;
            ad = new List<int>();
            weights = new Dictionary<int, int>();
        }
    }
    class E
    {
        public int index1;
        public int index2;
        public int weight;
        public E(int index1,int index2,int weight)
        {
            this.index1 = index1;
            this.index2 = index2;
            this.weight = weight;
        }
    }
    static void Main(string[] args)
    {
        var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var ps = new P[nm[0]];
        var eg = new E[nm[1]];
        for (var i = 0; i < nm[0]; i++)
            ps[i] = new P(i);
        for (var i = 0; i < nm[1]; i++)
        {
            var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            ps[input[0] - 1].ad.Add(input[1] - 1);
            ps[input[1] - 1].ad.Add(input[0] - 1);
            ps[input[0] - 1].weights[input[1] - 1] = input[2];
            ps[input[1] - 1].weights[input[0] - 1] = input[2];
            eg[i] = new E(input[0] - 1, input[1] - 1,input[2]);
        }
        var wei = new int[nm[0], nm[0]];
        for(var i = 0; i < nm[0]; i++)
        {
            for (var j = 0; j < nm[0]; j++)
                wei[i, j] = int.MaxValue;
            wei[i, i] = 0;
            var set = new HashSet<int>();
            while (true)
            {
                var min = int.MaxValue;
                var minj = -1;
                for (var j = 0; j < nm[0]; j++)
                    if (!set.Contains(j) && min > wei[i, j])
                    {
                        min = wei[i, j];
                        minj = j;
                    }
                if (minj == -1) break;
                set.Add(minj);
                foreach (var a in ps[minj].ad)
                {
                    if (!set.Contains(a) && wei[i, a] > wei[i, minj] + ps[minj].weights[a])
                        wei[i, a] = wei[i, minj] + ps[minj].weights[a];
                }
            }
        }
        var res = 0;
        foreach (var ege in eg)
        {
            var isTh = false;
            for(var i=0;i<nm[0];i++)
                for(var j = 0; j < nm[0]; j++)
                    if (wei[i, ege.index1] + ege.weight + wei[ege.index2, j] == wei[i, j])
                    {
                        isTh = true;
                        break;
                    }
            if (!isTh) res++;
        }
        WriteLine(res);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13408
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    if(b==0){
        return a;
    }else{
        return gcd(a%b,b);
    }
}

int main(){
    int N;
    cin >> N;
    ll A[100000];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    ll dp[100000][2]={};
    
    dp[0][0]=A[0];
    dp[0][1]=-A[0];
    
    for(int i=1; i<N-1; i++){
        dp[i][0]=max(dp[i-1][0]+A[i],dp[i-1][1]-A[i]);
        dp[i][1]=max(dp[i-1][1]+A[i],dp[i-1][0]-A[i]);
    }
    
    ll ans = max( dp[N-2][0]+A[N-1], dp[N-2][1]-A[N-1] );
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
/**
*    created: 27.06.2020 20:49:54
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int ans = 0;
    rep(i,n){
        if(s[i]!=t[i]){
            ans++;
        }
    }
cout << ans << endl;
}

Measured memory_bytes: 3788
import java.util.*;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int K = sc.nextInt();
    char[][] a = new char[H][W];
    boolean[][] b = new boolean[H][W];
    // Arrays.fill(b, true);
    for (int i=0; i < H; i++) {
      String tmp = sc.next();
      for (int j=0; j < W; j++) {
        a[i][j] = tmp.charAt(j);
        b[i][j] = true;
      }
    }
    int ans = 0;
    for(int i=0; i <Math.pow(2,(H+W));i++){
      int count = 0;
      for(int j=0; j<H; j++){
        if((1&i>>j)==1){
          for(int k=0; k<W; k++){
            b[j][k] = false;
          }
        }
      }
      for(int j=H; j<H+W; j++){
        if((1&i>>j)==1){
          for(int k=0; k<H; k++){
            b[k][j-H] = false;
          }
        }
      }
      for (int i1=0; i1 < H; i1++) {
        for (int j1=0; j1 < W; j1++) {
          if(a[i1][j1] == '#' && b[i1][j1]==true){
              count++;
          }
          b[i1][j1] = true;
        }
      }
      if(count==K){
        ans++;
      }
      // Arrays.fill(b, true);
      // System.out.println("b");

    }
    System.out.println(ans);
  }
}



Measured memory_bytes: 37248
#include<stdio.h>
int main(void)
{
	int K,A,B,i,flg;
	scanf("%d %d %d",&K,&A,&B);
	flg=0;
	for(i=A;i<=B;i++){
		if(i%K==0){
			flg=1;
		}
	}
	if(flg==1){
		printf("OK\n");
	}
	else{
		printf("NG\n");
	}
	return 0;
}

Measured memory_bytes: 1632
'use strict'

function main(input) {
  input = input.split('\n').map(v => v.split(' ').map(v => ~~v))
  const n = input[0][0]
  const m = input[0][1]

  const roads = input.slice(1, input.length)

  const counts = Array.apply(null, { length: n }).map(v => 0)
  for (let i = 0; i < m; i++) {
    counts[roads[i][0] - 1] += 1
    counts[roads[i][1] - 1] += 1
  }
  for (let i in counts) {
    console.log(counts[i])
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
from itertools import product
N,M,X = map(int,input().split())
cc = [list(map(int,input().split())) for i in range(N)]
saisyou = float('inf')
for i in product([0,1],repeat=N):
  dd = [0]*(M+1)
  check = 0
  for j in range(N):
    if i[j] == 1:
      for h in range(M+1):
        dd[h] += cc[j][h]
  for k in dd[1:]:
    if k < X:
      check = 1
  if check == 0:
    saisyou = min(dd[0],saisyou)
if saisyou == float('inf'):
  saisyou = -1
print(saisyou)

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

int main()
{
	int Dice1[6];
	int Dice2[6];
	int tmp;
	int count=0;
	int i, j;
	
	for(i=0;i<6;i++){
		cin >> Dice1[i];
	}
	
	for(i=0;i<6;i++){
		cin >> Dice2[i];
	}
	
	for(i=0;i<5;i++){
		if(Dice1[i]==Dice2[i])
			count++;
	}
	
	for(i=0;i<4;i++){
		tmp=Dice2[0];
		Dice2[0]=Dice2[1];
		Dice2[1]=Dice2[5];
		Dice2[5]=Dice2[4];
		Dice2[4]=tmp;
		if(Dice2[1]==Dice1[1])
				break;

		else{
			for(j=0;j<4;j++){
				tmp=Dice2[0];
				Dice2[0]=Dice2[3];
				Dice2[3]=Dice2[5];
				Dice2[5]=Dice2[2];
				Dice2[2]=tmp;
				if(Dice2[0]==Dice1[1]){
					tmp=Dice2[0];
					Dice2[0]=Dice2[4];
					Dice2[4]=Dice2[5];
					Dice2[5]=Dice2[1];
					Dice2[1]=tmp;
					break;
				}
			}
		}
	}
	for(i=0;i<4;i++){
		tmp=Dice2[0];
		Dice2[0]=Dice2[3];
		Dice2[3]=Dice2[5];
		Dice2[5]=Dice2[2];
		Dice2[2]=tmp;
		if(Dice2[0]==Dice1[0]){
			if(Dice1[0]==Dice2[0]&&Dice1[1]==Dice2[1]&&Dice1[2]==Dice2[2]&&Dice1[3]==Dice2[3]&&Dice1[4]==Dice2[4]&&Dice1[5]==Dice2[5]){
				cout << "Yes" << endl;
				return 0;
			}
			
			else if(count!=4){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define INT long long int
#define oo 9999987654321ll
using namespace std;
INT n, m, p[2010];
bool chk[2010];
vector<INT> G[2010];
void dfs(int x, int z)
{
    chk[x] = true;
    p[z] = x;
    //for(int i = 0 ; i <= z ; i++ ) cout<<p[i]<<" "; cout<<endl;
    for(int i = 0 ; i<G[x].size() ; i++ )
    {
        int y = G[x][i];
        if( !chk[y] )
            dfs(y, z+1);
        else
        {
            set<INT> t;
            t.insert(y);
            for(int j = z ; p[j] != y ; j-- ) t.insert(p[j]);
            INT cnt = 0;
            for(INT q : t)
                for(INT r : G[q] )
                    if( t.find(r) != t.end() ) cnt++;
            if( t.size() == cnt )
            {
                cout<<cnt<<endl;
                for(INT q : t )  cout<<q<<endl;
                exit(EXIT_SUCCESS);
            }
        }
    }
    chk[x] = false;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y;
        cin>>x>>y;
        G[x].push_back(y);
    }
    for(int i = 1 ; i <= n ; i++ ) dfs(i, 0);
    cout<<-1<<endl;
}


Measured memory_bytes: 512
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
 
parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

res = 1000000000 + 7

main = do
  [n, m] <- readIntegerList
  print $ (min n (m `div` 2)) + (max (m - 2 * n) 0) `div` 4


Measured memory_bytes: 380
#include <stdio.h>
#include <string.h>
int main(){
	char S[101];
	int count,i,N;
	count = 0;
	scanf("%s",S);
	N=strlen(S);
	for(i=0;i<N;i++){
		if(S[i]!=S[N-i-1]){ 
			count++;
			}
		}
		printf("%d",count/2);
		return 0;
}

Measured memory_bytes: 128
using System;

namespace AizuOnline
{
    class Program
    {
        static void Main(string[] args)
        {
            int sec = int.Parse(Console.ReadLine());
            int hour = sec / 3600;
            sec -= hour * 3600;
            int minute = sec / 60;
            sec -= minute * 60;
            Console.WriteLine("{0}:{1}:{2}", hour, minute, sec);
        }
    }
}



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

int main(){
  string s;
  cin >> s;
  deque<char> q;
  for(char c : s) q.push_back(c);
  bool flip = 0;
  int Q;
  cin >> Q;
  
  rep(qi,Q){
    
    int ty;
    cin >> ty;
    if(ty == 1){
      flip = !flip;
    }else{
      int f; char c;
      cin >> f >> c;
      if(flip) f = 3-f;
      if(f == 1) {
        q.push_front(c);
      }else{
        q.push_back(c);
      }
    }
  }
    
  if(flip) reverse(q.begin(),q.end());
  string ans;
  for(char c : q) ans += c;
  cout << ans << endl;
  return 0;
  }

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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define present(i, c) ((c).find(i) != (c).end())

#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define fora(i, a, b) for(int i = (a); i < (b); i++)
#define ford(i, n) for(int i = (n)-1; i >= 0; i--)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x" = " << x << endl)
#define watch_all(x) TRACE(cerr << #x" = "; for(auto __i : x) cerr << __i << " "; cerr << endl)
	
#define INF 0x3F3F3F3F

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

/*
// ===============
// Codigo Original
// ===============

string S, T;
int n, m;
string dp[3001][3001];

void run_test() {
	cin >> S >> T;
    n = sz(S); m = sz(T);
    for0(i, n+1) dp[i][0] = "";
    for0(i, m+1) dp[0][i] = "";
    for1(i, n) for1(j, m) {
        if(sz(dp[i-1][j]) > sz(dp[i][j])) dp[i][j] = dp[i-1][j];
        if(sz(dp[i][j-1]) > sz(dp[i][j])) dp[i][j] = dp[i][j-1];
        if(S[i-1] == T[j-1]) if(sz(dp[i-1][j-1]) + 1 > sz(dp[i][j])) dp[i][j] = dp[i-1][j-1] + S[i-1];
    }
    string ans = "";
    for0(i, n+1) for0(j, m+1) if(sz(dp[i][j]) > sz(ans)) ans = dp[i][j];
    cout << ans << endl;
}
*/

// ============================
// Otimizando Memoria
// Removendo uma dimensao da DP
// ============================
string S, T;
int n, m;
string dp[2][3001];

void run_test() {
	cin >> S >> T;
    n = sz(S); m = sz(T);
    for0(i, m+1) dp[0][i] = dp[1][i] = "";
    int curr = 1, prev = 0;
    for1(i, n) {
        for1(j, m) {
            if(sz(dp[prev][j]) > sz(dp[curr][j])) dp[curr][j] = dp[prev][j];
            if(sz(dp[curr][j-1]) > sz(dp[curr][j])) dp[curr][j] = dp[curr][j-1];
            if(S[i-1] == T[j-1]) if(sz(dp[prev][j-1]) + 1 > sz(dp[curr][j])) dp[curr][j] = dp[prev][j-1] + S[i-1];
        }
        prev = curr;
        curr = 1-curr;
    }
    string ans = "";
    for0(j, m+1) if(sz(dp[prev][j]) > sz(ans)) ans = dp[prev][j];
    cout << ans << endl;
}

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

ifstream infile;
clock_t start__;
void open_func();
void close_func();

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	open_func();
	//int t; cin >> t; while(t--) run_test();
	run_test();
	close_func();
	return 0;	
}

void open_func() {
	//infile = ifstream("input.in"); if(infile.good()) cin.rdbuf(infile.rdbuf());
	start__ = clock();
	cerr << "---" << endl;
}

void close_func() {
	clock_t elapsed = clock()-start__;
	cerr << "---" << endl << "(time " << fixed << setprecision(2) << elapsed * (1.0/CLOCKS_PER_SEC) << "s)" << endl;	
	//if(infile.good()) infile.close();
}


Measured memory_bytes: 22276
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF      100000000
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
char x[12];

int main(){
    rep(i,12) cin >>x[i];
    rep(i,12){
        if(i == 4) cout << " ";
        cout << x[i];
    }
    cout << endl;
}



Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(n: i64, mut mat: Vec<(i64, i64, i64)>) -> &'static str {
    mat.insert(0, (0, 0, 0));
    let yes = mat[..].windows(2).all(|v| {
        let (t, x, y) = v[0];
        let (nt, nx, ny) = v[1];
        let time = nt - t;
        let dist = (nx - x).abs() + (ny - y).abs();
        dist <= time && time % 2 == dist % 2
    });
    if yes {
        "Yes"
    } else {
        "No"
    }
}

fn main() {
    input!{
        n: i64,
        mat: [(i64, i64, i64) ;n]
    }

    println!("{:}", solve(n, mat));
}


Measured memory_bytes: 14588
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,C;
  cin>>N>>C;
  int D[C][C];
  REP(i,C)REP(j,C)cin>>D[i][j];
  lint S[C][3];
  REP(i,C)REP(j,3)S[i][j]=0;
  REP(i,N)REP(j,N){
    int c;
    cin>>c;
    c--;
    REP(k,C)S[k][(i+j)%3]+=D[c][k];
  }
  lint ans=1e18;
  REP(i,C)REP(j,C)REP(k,C){
    if(i==j or j==k or k==i)continue;
    ans=min(ans,S[i][0]+S[j][1]+S[k][2]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)

int main() {
	int n, m, a;
	while (cin >> n >> m >> a, n || m || a) {
		int maxh = 0;
		bool amida[1001][102];
		REP(i, 0, 1001) REP(j, 0, 102) amida[i][j] = false;
		REP(i, 0, m) {
			int h, p, q;
			cin >> h >> p >> q;
			maxh = max(maxh, h);
			h--;
			amida[h][p] = true;
		}

		int now = a;
		RREP(i, 0, maxh) {
			if (amida[i][now]) {
				now++;
			}
			else if (amida[i][now - 1]) {
				now--;
			}
		}

		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int N = 2e5 + 7;
const int MOD = 998244353;
const int rv2 = (MOD + 1) / 2;

void add(int &x, int y) {
	x += y;
	if (x >= MOD) {
		x -= MOD;
	}
	if (x < 0) {
		x += MOD;
	}
}

int st[N];

string pat;
int n;

void init() {
	st[0] = 1;
	for (int i = 1; i < N; i++) {
		st[i] = st[i - 1] * 2LL % MOD;
	}
	for (int i = 0; i < n; i++) {
		pat += '#';
	}
}

void print(int x) {
	for (int i = 0; i < n; i++) {
		cout << x % 2;
		x /= 2;
	}
	cout << "\n";
} 

int main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	init();
	string s;
	cin >> n;
	cin >> s;
	vector <int> res(n, 0);
	vector <int> was;
	for (int sh = 1; sh < n; sh++) {
		if ((2 * n) % sh) continue;
		int d = n % sh;
		int len = sh / __gcd(sh, d);
		if (len % 2) continue;

		//cout << sh << " " << len << " " << d << "\n";

		int add_d = st[sh / len - 1], now = 0;
		string sa = "", ta = "";

		for (int i = 0; i < sh; i++) {
			sa += s[i];
			ta += '#';
		}

		int pos = 0;

		for (int i = 0; i < sh; i++) {
			if (i < pos) continue;
			int start = i;
			int value = sa[i] - '0';
			if (value == 1) {
				add(now, add_d);
				//cout << add_d << "\n";
			}
			
			int iter = start;

			do {
				ta[iter] = (char) ('0' + value);
				iter = (iter + d) % sh;
				value = 1 - value;
			} while (iter != start);

			//cout << ta << " " << add_d * 2 << " " << value << "\n";


			while (pos < sh && ta[pos] != '#') {
				if (ta[pos] != sa[pos]) break;
				pos++;
			}

			if (pos < sh && ta[pos] != '#') {
				if (ta[pos] < sa[pos]) {
					add(now, add_d);
				}
				break;
			}

			add_d = add_d * (ll) rv2 % MOD;
		}

		if (pos == sh) {
			string sa = "";
			for (int i = 0; i < sh; i++) {
				sa += '#';
			}
			for (int i = 0; i < sh; i++) {
				if (i < d) {
					sa[d - i - 1] = ta[i];
				} else {
					sa[sh + d - 1 - i] = ta[i];
				}
			}
			//cout << sa << "\n";
			for (int i = sh; i < n; i++) {
				sa += sa[i % sh];
			} 
			reverse(sa.begin(), sa.end());
			//cout << sa << "\n";
			if (sa <= s) {
				add(now, 1);
			}
		}

		res[sh] = now;

		for (int x : was) {
			if (sh % x == 0) {
				add(res[sh], -res[x]);
			}
		}	
		was.push_back(sh);
	}
	int ans = 0;
	int cnt = 0;
	for (char c : s) {
		cnt = (2LL * cnt + c - '0') % MOD;
	}
	add(cnt, 1);
	for (int i = 0; i < n; i++) {
		if (!res[i]) continue;
		//cout << i << " " << res[i] << "\n";
		add(ans, res[i] * (ll) i % MOD);
		add(cnt, -res[i]);
	}
	//cout << cnt << " " << 2 * n << "\n";
	add(ans, cnt * (ll) (2 * n) % MOD);
	cout << ans << "\n";
}


Measured memory_bytes: 2652
#include <stdio.h>
#define ll long long
const int mod = 1e9 + 7;

int n;

int mx[21][21];

ll dp[ (1<<21) ];


int main(){

	scanf("%d",&n);
	for(int i=0;i<n;i++) 
	for(int j=0;j<n;j++)
		scanf("%d",&mx[i][j]);
	dp[0] = 1;

	for(int mask = 0;mask<(1<<n);mask++){
		int a = __builtin_popcount(mask);
		for(int i = 0;i<n;i++){

			if(mask>>i&1 || mx[a][i] == 0 ) continue;
			int next = ( mask | (1<<i) ); 
			dp[ next ] += dp[mask];
			if(dp[ next ] > mod) dp[next]-=mod;

		}
	}
	printf("%lld",dp[ (1<<n)-1 ]);
}

Measured memory_bytes: 18112
import sys
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

sys.setrecursionlimit(10**6)
# def solve():
# 	n, m = read()
# 	graph = [[] for i in range(n+1)]
# 	for _ in range(m):
# 		u, v = read()
# 		graph[u].append(v)
# 	visited = [0 for i in range(n+1)]
# 	def dfs(node):
# 		if visited[node]:
# 			return(visited[node])
# 		if not graph[node]:
# 			visited[node] = 0
# 			return(0)
# 		m = 0
# 		for i in graph[node]:
# 			m = max(m, dfs(i))
# 		visited[node] = 1 + m#ax(dfs(i) for i in graph[node])
# 		# print(node, visited[node])
# 		return(visited[node])

# 	ans = 0
# 	for i in range(1, n+1):
# 		ans = max(ans, dfs(i))
# 	# print(visited)
# 	print(ans)


def grid():
	n, m = read()
	arr = []
	for i in range(n):
		arr.append(inp().strip())
	# dic = {}
	dp = [-1]*m*n
	# print(dp, len(dp))
	def count_paths(i, j):
		# key = str(i)+"-"+str(j)
		# if key in dic:
		# 	return(dic[key])
		key = (i*m + j)
		# print(key)
		if i == n-1 and j == m-1:
			dp[key] = 1
			return(1)
		if i == n or j == m:
			return(0)
		if arr[i][j] == "#":
			dp[key] = 0
			return(0)
		if dp[key] > -1:
			return(dp[key])
		paths = (count_paths(i+1, j) + count_paths(i, j+1)) % (10**9 + 7)
		# dic[key] = paths
		dp[key] = paths
		return(paths)
	print(count_paths(0, 0))

def grid2():
	n, m = read()
	arr = []
	for i in range(n):
		arr.append(inp().strip())
	dp = {}
	# print(dp, len(dp))
	def count_paths(i, j):
		key = str(i)+"-"+str(j)
		if key in dp:
			return(dp[key])
		# key = (i*m + j)
		# print(key)
		if key in dp:
			return(dp[key])
		if i == n-1 and j == m-1:
			dp[key] = 1
			return(1)
		if i == n or j == m:
			return(0)
		if arr[i][j] == "#":
			dp[key] = 0
			return(0)
		
		paths = (count_paths(i+1, j) + count_paths(i, j+1)) % (10**9 + 7)
		# dic[key] = paths
		dp[key] = paths
		return(paths)
	print(count_paths(0, 0))



if __name__ == "__main__":
	# solve()
	grid()

Measured memory_bytes: 45052
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n)
	pl := map[string]int{}
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		pl[s]++
	}
	fmt.Scan(&m)
	mi := map[string]int{}
	for i := 0; i < m; i++ {
		var s string
		fmt.Scan(&s)
		mi[s]++
	}
	ans := 0
	for k, v := range pl {
		sum := v
		if m, ok := mi[k]; ok {
			sum -= m
		}
		if ans < sum {
			ans = sum
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
program B
    integer :: N, L, m = 1000000, mi = 0, s = 0, num
    read*,N, L
    do i = 0, N - 1, 1
        num = L + i
        s = s + num
        if (abs(num) < m) then
            m = abs(num)
            mi = num
        endif
    enddo
    print*, s - mi
end program B

Measured memory_bytes: 512
a, b = map(int, input().split())
num = range(b+1)[a:]
ans = list()

for i in num:
    count = 0
    for j in range(len(str((i)))//2):
        if str(i)[j] == str(i)[-(j+1)]:
            count += 1
    if count == len(str(i))//2:
        ans.append(i)

print(len(ans))

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

pf = [0]*n
mn = 1e9
for i in range(0,n):
    mn = min(mn,a[i])
    pf[i] = mn
    
cn = 0
for i in range(n):
    if(a[i]<=pf[i]):
        cn += 1
        
print(cn)

Measured memory_bytes: 76496
a = gets.to_i
# b = gets.to_i
# s = gets.chomp
# s,t = gets.split.map(&:to_s)
# n= gets.split.map(&:to_i)

# s = gets.chomp.chars.uniq
# puts gets.chomp.chars.uniq.size != 1 ? "Yes" : "No"

p a.even? ? 0.5 : (a/2+1)*1.0/a

Measured memory_bytes: 1788
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
sum = 0
for i in range(n):
	sum += pow(-1,i)*a[i]
b[0] = sum//2
for i in range(1,n):
	b[i] = -b[i-1] + a[i-1]
c = [n*2 for n in b]
L=[str(a) for a in c]
L=" ".join(L)
print(L)

Measured memory_bytes: 23060
function main(){
	print(scan('string').split('').reverse().join(''))
}
 
function rep(a, b, c){
	if(c == null){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		c(i);
	}
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var input = '';
var input_index = 0;
 
function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}
 
function print(val){
	console.log(val);
}
 
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.split(/\s+/);
	main();
});

Measured memory_bytes: 15576
#include <iostream>

int main()
{
    std::string s; std::cin >> s;
    for (int i = 0; i < 12; i++)
    {
        if (i == 4)
        {
            std::cout << " ";
        }
        std::cout << s[i];
    }
    std::cout << std::endl;
    return 0;
}


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

using namespace std;
#define taskname ""
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 1e5 + 5;
int n , a[maxn] , b[maxn];
int sum[maxn * 2];
ll need;
void update(int x){
    for( ; x <= n * 2 ; x += x & -x)
        sum[x]++;
}
inline int ss(int x){
    int res = 0;
    for( ; x > 0 ; x &= x - 1){
        res += sum[x];
    }
    return res;
}
bool chk(int val)
{
    fill_n(sum , maxn * 2 , 0);
    int s = n;
    update(s);
    ll res = 0;
    for(int i = 1 ; i <= n ; ++i)
    {
        if(a[i] >= val)s++;
        else s--;
        res += ss(s);
        update(s);
    }
    return res >= need / 2 + need % 2;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen(taskname".INP", "r",stdin);
	//freopen(taskname".OUT", "w",stdout);
    cin >> n;
    need = 1ll * n * (n + 1) / 2;
    for(int i = 1 ; i <= n ; ++i)
    {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1 , b + n + 1);
    int l = 1;
    int h = n;
    while(l <= h)
    {
        int mid = (l + h) / 2;
        if(!chk(b[mid]))h = mid - 1;
        else l = mid + 1;
    }
    cout << b[h];
}


Measured memory_bytes: 1792