akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	debug('R'%3,'G'%3,'B'%3);
	int n;
	std::cin >> n;
	std::string s;
	std::cin >> s;
	std::vector<std::vector<int> > dp(n+1,std::vector<int>(3,0));
	rep(i,n) {
		rep(j,3) {
			dp[i+1][j]=dp[i][j]+(int)(j==s[i]%3);
		}
	}
	int count=0;
	for(int j=1;j<n-1;j++) {
		for(int k=j+1;k<n;k++) {
			if(s[j]==s[k]) continue;
			count+=j-dp[j][s[j]%3]-dp[j][s[k]%3];
			int i=2*j-k;
			if(i>=0 && s[i]!=s[j] && s[i]!=s[k]) count--;
		}
	}
	print(count);
	return 0;
}


Measured memory_bytes: 3820
#include <stdio.h>
#define MAX 300

int main(void){
    int H[MAX],W[MAX];
    int i=0,j,w,h;
    for (i=0; i<MAX; i++) {
        scanf("%d %d",&H[i],&W[i]);
        if(H[i]==0&&W[i]==0){
            break;
        }
        else{
            if(H[i]<1||W[i]<1||300<H[i]||300<W[i]){
                return 0;
            }
        }
    }
    
    for(j=0;j<i;j++){
        for(h=0;h<H[j];h++){
            for(w=0;w<W[j];w++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2104
s=input()
n=len(s)
s+="X"
acnt=0
bccnt=0
res=0
i=0
while(i<n):
    if s[i:i+2]=="BC":
        bccnt+=1
        i+=1
    elif s[i]=="A":
        acnt+=1
        res-=bccnt
    else:
        res+=bccnt*acnt
        bccnt=0
        acnt=0
    i+=1
res+=bccnt*acnt
print(res)

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

int main(void){
    int n;scanf("%d",&n);
    int cnt=0;
    for (size_t i = 0; i < n; i++) {
        int t;
        scanf("%d",&t);
        if (t%2==0)cnt++;
    }
    printf("%d",(int)(pow(3,n)-pow(2,cnt)));
    return 0;
}

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

int Comp(const int *c1, const int *c2)
{
	return *((int *)c2) - *((int *)c1);
}

int main()
{
	int i, n, line[100] = { 0 };
	int other_total  = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &line[i]);

	qsort(line, n, sizeof(int), Comp);

	for (i = 1; i < n; i++)
		other_total += line[i];

	if (line[0] < other_total)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 128
/**
 * Created By: Anonyman637
 * Created On: 3/6/2020 6:27:28 AM
 */

/* =============================================================================
   ================================== HEADERS ==================================
   ========================================================================== */

#include <cstdio>
#include <string>
#include <cmath>

/* =============================================================================
   ================================= TYPEDEFS ==================================
   ========================================================================== */

typedef char i8;
typedef short i16;
typedef int i32;
typedef long long i64;

typedef unsigned char ui8;
typedef unsigned short ui16;
typedef unsigned int ui32;
typedef unsigned long long ui64;

using namespace std;

/* =============================================================================
   ================================== MACROS ===================================
   ========================================================================== */

#ifdef DEBUG
#define debug(format, ...) printf(format, __VA_ARGS__)
#else
#define debug(format, ...) 
#endif

#ifdef FILEIO
#define INFILE "fileio\\"__FILE__"In.txt"
#define OUTFILE "fileio\\"__FILE__"Out.txt"
#endif

/* =============================================================================
   ================================== GLOBALS ==================================
   ========================================================================== */


/* =============================================================================
   =================================== SETUP ===================================
   ========================================================================== */

i32 setup() {

#ifdef FILEIO
        if(freopen(INFILE, "r", stdin) == NULL) return 401;
        if(freopen(OUTFILE, "w", stdout) == NULL) return 402;
#endif

        return 0;
}


/* =============================================================================
   ================================= FUNCTIONS =================================
   ========================================================================== */

i32 main() {

        i32 errorInSetup = setup();
        if (errorInSetup) exit(errorInSetup);

        i64 i, t;
        i64 n, sqrtN, steps;
        scanf("%lld", &n);
        sqrtN = ceil(sqrt((double) n));
        for (i = sqrtN; i > 0; i--) {
                if (n % i == 0) {
                        steps = (n / i) + i - 2;
                        break;
                }
        }

        printf("%lld", steps);
        
        return 0;
}


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

int main(){
    string s;
    cin >> s;
    int a[4];
    int sum=0;
    rep(i, 4){
        a[i] = (int)(s[i]-'0');
        sum += a[i];
        // cout << a[i] << endl;
    }
    
    int sum_;
    rep(i, 2){
        rep(j, 2){
            rep(k, 2){
                sum_ = sum;
                sum_ -= (i*2*a[1] + j*2*a[2] + k*2*a[3]);
                // cout << sum_;
                if(sum_==7){
                    cout << a[0];
                    if(i==0) cout << '+';
                    else cout << '-';
                    cout << a[1];
                    if(j==0) cout << '+';
                    else cout << '-';
                    cout << a[2];
                    if(k==0) cout << '+';
                    else cout << '-';
                    cout << a[3];
                    cout << "=7" << endl;
                    return 0;
                }
            }
        }
    }
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[2005][2005]; // 0~i-1, j+1~n-1の文字を使ってできる回文の個数

// res[i][c]:=i文字目以降で最初に文字cが登場するindex
vvll calcNext(string &s){
  ll n=s.size();
  vvll res(n+1, vll(26,n));
  // sを後ろから見ていく
  for(ll i=n-1; i>=0; i--){
    // まずi+1文字目以降で最初に文字cが登場するindexをiにも格納する
    for(ll j=0; j<26; j++) res[i][j]=res[i+1][j];
    // その後、i番目の文字cに対応する値だけiとして更新する
    res[i][s[i]-'a']=i;
  }
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll n=s.size();
  string t=s;
  reverse(all(t));
  
  auto ns=calcNext(s);
  auto nt=calcNext(t);
  
  dp[0][0]=1;
  
  // sのi文字目
  for(ll i=0; i<n; i++){
    // tのj文字目
    for(ll j=0; j<n; j++){
      // 文字k
      for(ll k=0; k<26; k++){
        // s,tにおいて、i文字目以降でkが登場する最初のindex
        ll ni=ns[i][k];
        ll nj=nt[j][k];
        // +2はi-1とj-1の文字は必ず採用することを意味する
        if(ni+nj+2>n) continue;
        (dp[ni+1][nj+1]+=dp[i][j])%=MOD;
      }
    }
  }
  
  ll res=0;
  for(ll i=0;i<=n;i++){
    // i+j<=nを満たすi,jに対して、元の文字列sの左側i文字分と右側j文字分から作れる回文を調べている
    for(ll j=0; i+j<=n; j++){
      ll num=1;
      // 左側i文字と右側j文字を削ぎ取って残る文字列中に含まれる文字の種類数を調べている
      for(ll k=0; k<26; k++) if(ns[i][k]+1+j<=n) ++num;
      res=(res+dp[i][j]*num%MOD)%MOD;
    }
  }
  cout<<res-1<<endl;
}


Measured memory_bytes: 26524
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	int n, m;
	cin >> n >> m;
	int a[100020] = {};
	for (int i = 0; i < m; i++) {
		int b, c;
		cin >> b >> c;
		a[b]++;
		a[c + 1]--;
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		a[i] = a[i] + a[i - 1];
		if (a[i] == m) {
			cnt++;
		}
	}
	cout << cnt;
}

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

int main() {
    int k;cin>>k;
    int a=0;
    for (int i=0;i<10000000;i++) {
        a=(a*10+7)%k;
        if (a==0) {
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 3616
n, x, y = map(int, input().split())

ans = [0] * (n-1)

for i in range(1, n):
    for j in range(i+1, n+1):
        dist = min(abs(j-i), abs(x-i) + 1 + abs(j-y), abs(y-i) + 1 + abs(j-x))
        ans[dist-1] += 1

for i in range(len(ans)):
    print(ans[i])


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    i64 N,A,B;
    cin >> N >> A >> B;
    if(A>B) cout << 0 << endl;
    else if(N==1) cout << (A!=B?0:1) << endl;
    else cout << (B*(N-1)+A)-(A*(N-1)+B)+1 << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
while True:
    h, w = [int(i) for i in input().split()]
    if h == 0 and w == 0:
        break
    for i in range(h):
        if i == 0 or i == h - 1:
            print('#' * w)
        else:
            print('#' + '.' * (w - 2) + '#')
    print()



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  string s,t;
  cin >> s >> t;

  int n = s.size();
  int m = t.size();

  vector<int> sl(n);
  vector<int> tl(m);

  rep(i,n) sl.at(i) = s.at(i);
  rep(i,m) tl.at(i) = t.at(i);

  sort(sl.begin(), sl.end());
  sort(tl.rbegin(), tl.rend());

  //bool ans=true;
  if(n<m){
    rep(i,n){
      if(sl.at(i)<tl.at(i)) {cout << "Yes"; return 0;}
      else if(sl.at(i)>tl.at(i)){cout << "No"; return 0;}
    }
    cout << "Yes";
    return 0;
  }else if(n>=m){
    rep(i,m){
      if(sl.at(i)<tl.at(i)) {cout << "Yes"; return 0;}
      else if(sl.at(i)>tl.at(i)){cout << "No"; return 0;}
    }
    cout << "No";
    return 0;
  }
}

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

int main() {
   int a,b,k;
   cin>>a>>b>>k;
   int val = __gcd(a,b);
   for(int i = val; i>= 0;i--) {
   		if (k && a % i == 0 && b % i == 0) {
   			val = i;
   			k--;
   			
   		}
   }
   cout<<val<<endl;
}   

Measured memory_bytes: 256
array = gets.split.map(&:to_i)                                                                                                         
ans = "No"                                                                                                                             
if (0..array[0]).include? array[2]+array[4] then                                                                                       
  if (0..array[0]).include? array[2]-array[4] then                                                                                     
    if (0..array[1]).include? array[3]+array[4] then                                                                                   
      if (0..array[1]).include? array[3]-array[4] then                                                                                 
        ans = "Yes"                                                                                                                    
      end                                                                                                                              
    end                                                                                                                                
  end                                                                                                                                  
end                                                                                                                                    
puts ans

Measured memory_bytes: 6108
// Code for B - Count ABC
#include <iostream>
#include <string>
using namespace std;

int main() {
	string s;
	unsigned int n;
	const string tgt="ABC";
	const uint tgtl = tgt.length() - 1;
	cin >> n;
	cin >> s;
	uint ret = 0;
	for(uint i=0; i < n - tgtl; i++){
		if(s[i] == tgt[0]){
			if(s[i+tgtl] == tgt[tgtl]){
				bool correct = false;
				for(uint k = 1; k < tgtl ; k++){
					if(s[i+k] != tgt[k]){
						break;
					}else if(k == tgtl-1){
						correct = true;
						break;
					}
				}
				if(correct){
					ret++;
					i+=tgtl;
					if(i >= n -tgtl) break;
					else continue;
				}
			}
		}
	}
	cout << ret;
	return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    vector<string> A;
    for(int i = s.size() - 1; i >= 0; i--){
        int s_i = i, cnt = 0;
        for(int j = t.size() - 1; j >= 0; j--){
            if(s[s_i] == '?' or s[s_i] == t[j]) cnt++;
            s_i--;
        }
        if(cnt == t.size()){
            int start_idx = i - t.size() + 1;
            int end_idx = i;
            string tmp = "";
            for(int j = 0; j < s.size(); j++){
                if(j == start_idx){
                    int t_idx = 0;
                    for(int k = start_idx; k <= end_idx; k++){
                        tmp += t[t_idx];
                        t_idx++;
                    }
                    j += t.size() - 1;
                }else{
                    if(s[j] == '?') tmp += 'a';
                    else tmp += s[j]; 
                }
            }
            A.push_back(tmp);
        }
        if(i == t.size() - 1) break;
    }
    if(A.size()){
        sort(A.begin(), A.end());
        cout << A[0] << endl;
    }else cout << "UNRESTORABLE" << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ls = [-1]*N
ans = 0
for i in range(M):
  a, b = map(int, input().split())
  ls[b-1] = max(ls[b-1], a-1)

ps = -1
for i in range(N):
  if ls[i]==-1:
    continue
  if ls[i]>=ps:
    ans += 1
    ps = i
print(ans)

Measured memory_bytes: 5864
#include<bits/stdc++.h>
		#include <bitset>
		using namespace std;
		#define ll long long 
		#define ld long double
		#define MOD 1000000007
		#define mod9 1000000009
		#define mod 1000003
		#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
		#define mp make_pair
		#define pb push_back
		#define ct ll t;cin>>t;while(t--)
		#define bi begin()
		#define ei end()
		#define fi first 
		#define se second   	
		bool isPrime(ll n) 
		{ 
			// Corner case 
			if (n <= 1) 
				return false; 
			
			// Check from 2 to n-1 
			for (ll i = 2; i*i <= n; i++) 
				if (n % i == 0) 
					return false; 
			
			return true; 
		}
		long long binpow(long long a, long long b) {
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = (res%mod) * (a%mod);
				a = (a%mod) * (a%mod);
				b >>= 1;
			}
			return res%mod;
		}

		bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
		{
			return (a.se<b.se);
		}
		ll lcm(ll a,ll b)
		{
			return(a*b)/__gcd(a,b);
		}
		vector<ll>s[2005];
		void SieveOfEratosthenes() 
		{  
			ll n=2005;
			bool prime[1000005]; 
			memset(prime, true, sizeof(prime)); 
			// s[0]=1;
			// s[1]=1;
			for (int p=2; p*p<=n; p++) 
			{ 
				s[p].pb(1);
				if (prime[p] == true) 
				{   
					for (int i=p+p; i<=n; i += p) {
						prime[i] = false; 
						s[i].pb(p);
						}
				} 
			} 
			// for(ll i=2;i<10005;i++)
			// {
			// 	if(prime[i])
			// 	{
			// 		// s.pb(i);
			// 	}
			// }
		} 
		void eea(ll a, ll b, ll & x, ll & y) {
		if (a == 0) {
			x = 0;
			y = 1;
			return ;
		}
		ll x1, y1;
		eea(b % a, a, x1, y1);
		x = y1 - (b / a) * x1;
		y = x1;
		return ;
	}
	ll modinverse(ll a,ll m)
	{
		ll x, y;
		eea(a, m, x, y);
		if (__gcd(a,m) != 1) {
		return -1;
		}
	else {
		x = (x % m + m) % m;
		cout << x << endl;
		return x;
	}
	}
		ll fact[1000007]={0};
		ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
		y=y>>1;x=(1ll*x*x)%MOD;} return res;}
		void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
		ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
		ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
			ll C(ll n, ll k) {
    ll res = 1;
    for (ll i = 1; i <= k; ++i)
        res = ((res) * (n - k + i) / i)%MOD;
    return (ll)(res + 0.01)%MOD;
}
				
		int main()
		{
			fast
			ll n,m;
			cin>>n>>m;
			vector<ll>v(n);
			ll s=0;
			for(ll i=0;i<n;i++)
			{
				cin>>v[i];
				s+=v[i];
			}	
			float t=(1.0*s/(4*m));
			sort(v.bi,v.ei,greater<ll>());
			if(v[m-1]>=t)
			{
				cout<<"Yes\n";
			}
			else
			{
				cout<<"No\n";
			}
			}

 

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

#define LLINF (1LL<<60)
typedef long long ll;

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

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

//C++14 (GCC 5.4.1)
int main() {
    int a,b;
    cin >>a>>b;
    
    //-----------------------------------

    cout << (b-a)*(b-a+1)/2-b <<endl;
    return (0);
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

#include <bits/stdc++.h>
#define rep(i,a,n) for(ll i = a;i < n;i++)
typedef long long ll;
using namespace std;

int main(){
    ll n;
    cin >> n;
    ll cnt[n+1] = {};

    rep(j,1,101){
        rep(k,1,101){
            rep(l,1,101){
                if(j*j+k*k+l*l+j*k+k*l+l*j > n) continue;
                cnt[j*j+k*k+l*l+j*k+k*l+l*j]++;
            }
        }
    }

    rep(i,1,n+1){
        cout << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<ll>> dp(110, vector<ll>(10,0));
  dp[0][0]=1;
  
  rep(i,h){ rep(j,w){ for(int b=0; b<(1<<(w-1)); b++){
    bool flag=true;
    rep(l,w-2){ if(((b>>l)&1)&&((b>>(l+1))&1)){flag=false;} }
    if(!flag){ continue; }
    if(j>=1 && ((b>>(j-1))&1)){    //go left case
      dp[i+1][j-1] += dp[i][j];
      dp[i+1][j-1] %= mod;
      continue;
    }
    if(j<=w-2 && ((b>>j)&1)){    //go right case
      dp[i+1][j+1] += dp[i][j];
      dp[i+1][j+1] %= mod;
      continue;
    }
                                    //go straight case
      dp[i+1][j] += dp[i][j];
      dp[i+1][j] %= mod;
  }}}
  cout << dp[h][k-1] << endl;
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n, y;
  cin >> n >> y;
  y /= 1000;
  if (n > y)
  {
    cout << "-1 -1 -1";
    return;
  }
  set<ll> hash;

  queue<tuple<ll, ll, ll>> que;
  if (n <= y / 10) que.emplace(y / 10, 0, y - (y / 10) * 10);
  else if (n <= y / 5) que.emplace(0, y / 5, y - ((y / 5) * 5));
  else que.emplace(0, 0, y);

  while(!que.empty())
  {
    ll x, y, z;
    tie(x, y, z) = que.front();
    que.pop();

    ll hv = (x << 40LL) + (y << 20LL) + z;
    if (hash.find(hv) != hash.end()) continue;
    hash.insert(hv);

    if (x + y + z < n) continue;
    if (x + y + z == n)
    {
      cout << x << " " << y << " " << z;
      return;
    }
    if (z >= 5)
    {
      que.emplace(x, y + 1, z - 5);
    }
    if (z >= 10)
    {
      que.emplace(x + 1, y, z - 10);
    }
    if (y >= 2)
    {
      que.emplace(x + 1, y - 2, z);
    }
  }
  cout << "-1 -1 -1";

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 13644
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll N, K;
vector<ll> h, memo;

ll solve(ll n)
{
    if (memo.at(n) != -1)
    {
        return memo.at(n);
    }

    ll res = 1000000000000000000;

    rep(1, i, K + 1)
    {
        if (n - i < 0)
        {
            break;
        }
        res = min(res, solve(n - i) + abs(h.at(n) - h.at(n - i)));
    }
    return memo.at(n) = res;
}

int main()
{
    cin >> N >> K;
    h.resize(N);
    memo.resize(100010, -1);

    rep(0, i, N)
    {
        cin >> h.at(i);
    }
    memo.at(0) = 0;

    cout << solve(N - 1) << endl;
}

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

using namespace std;
typedef long long ll;


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

#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく

#define PB push_back //vectorヘの挿入
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

ll n;vector<pair<ll,ll>> vw;vector<vector<ll>> dp;
ll c1,c2;

void dfs(ll i){
    if(i==1){
        dp[i-1][vw[i-1].S]=vw[i-1].F;
    }else{
        ll j=i/2;
        FORD(k,c2,0){
            if(dp[j-1][k]!=0 or k==0){
                ll ne=k+vw[i-1].S;
                if(ne<=c2)dp[i-1][ne]=max(dp[j-1][k]+vw[i-1].F,dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=c1 and i*2<=n)dfs(i*2);
    if(i*2+1<=c1 and i*2+1<=n)dfs(i*2+1);
}

signed main(){
    cin>>n;
    vw.resize(n);
    REP(i,n)cin>>vw[i].F>>vw[i].S;
    c1=1<<10;c2=100000;
    dp.resize(c1);REP(i,c1)dp[i].resize(c2+1);
    dfs(1);
    REP(i,c1)REP(j,c2)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    ll q;cin>>q;
    #if 1
    REP(i,q){
        ll v,l;cin>>v>>l;
        vector<ll> cand;
        while(v>c1){
            cand.PB(v);
            v=v/2;
        }
        ll r=SIZE(cand);
        ll ans=0;
        REP(j,1<<r){
            ll v_sub=0;ll w_sub=0;
            REP(k,r){
                if((j>>k)&1){
                    v_sub+=vw[cand[k]-1].first;
                    w_sub+=vw[cand[k]-1].second;
                }
            }
            if(w_sub<=l)ans=max(ans,dp[v-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
    #endif
}


Measured memory_bytes: 810300
n,m = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    on = [0]*n
    for j in range(n):
        if ((i>>j)&1):
            on[j] += 1
    flag = 1
    for j in range(m):
        onnum = 0
        for l in range(1,len(k[j])):
            if (on[k[j][l]-1]==1):
                onnum += 1
        if ((onnum%2)!=p[j]):
            flag = 0
    if (flag == 1):
        ans += 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
t = sum(a)
x = [0]*n
x[0] = t - 2*sum(a[1::2])

for i in range(1,n):
    x[i] = (a[i-1]-x[(i-1)]//2)*2
   
print(' '.join(map(str,x)))

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

int Max,x;
string s;
bool ck;
vector<string> ans;

void dfs(int k, int sum, string p, vector<string> a) {
  if(sum>x) return;
  if(k==s.size()) {
    int z;
    stringstream ss;
    ss << p;
    ss >> z;
    sum+=z;
    a.push_back(p);
    if(sum>x) return;
    if(sum==Max) ck=false;
    else if(sum>Max) {
      Max=sum;
      ans=a;
      ck=true;
    }
    return;
  }
  dfs(k+1,sum,p+s[k],a);
  a.push_back(p);
  int z;
  stringstream ss;
  ss << p;
  ss >> z;
  string t="";
  t+=s[k];
  dfs(k+1,sum+z,t,a);
}

int main() {
  int d;
  while(cin >> x >> d) {
    if(x==0 && d==0) break;
    ck=false;
    Max=-1;
    ans.clear();
    stringstream ss;
    ss << d;
    ss >> s;
    dfs(0,0,"",ans);
    if(ck) {
      cout << Max;
      for(int i=0; i<ans.size(); i++) cout << " " << ans[i];
      cout << endl;
    } else {
      if(Max==-1) cout << "error" << endl;
      else cout << "rejected" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1248
a, b = map(int, input().split())
s = 0
for n in range(a,b+1):
  n = str(n)
  l = len(n)
  for i in range(int((l+1)/2)):
    if n[i] != n[l-1-i]:
      break
    elif n[i] == n[l-1-i] and i == (l-1)/2:
      s+= 1
    else:
      continue
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define Set set<int>
#define int long long
#define P pair<int,int>
const int maxn = 1e6+5;
const int INF = 1e17 +6;
using namespace std;
int n,m,a[maxn],b[maxn],ans;
int32_t main()
{
    IOS;
    cin>>n;
    cout<<(n-2)*180;
    return 0;
}

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

using namespace std;

int main(){
	int k, x, i;

	scanf("%d%d", &k, &x);

	for (i = x - k + 1; i <= x + k - 1; i++){
		printf("%d ", i);
	}

	printf("\n");

	return 0;
}

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

int N, M;
int k[10 + 1];
int s[10 + 1][10 + 1];
int p[10 + 1];
bool flag[10 + 1];
int count;

void func() {
  int c, total;

  total = 0;
  for (int i = 1; i <= M; i++) {
    c = 0;

    for (int j = 1; j <= k[i]; j++) {
      if (flag[s[i][j]] == true) {
        c++;
      }
    }

    if (c % 2 == p[i]) {
      total++;
    }
  }

  if (total == M) {
    count++;
  }
}

void select(int ord) {
  if (ord > N) {
    func();
    return;
  }

  flag[ord] = true;
  select(ord + 1);
  flag[ord] = false;
  select(ord + 1);
}

int main() {
  std::cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    std::cin >> k[i];

    for (int j = 1; j <= k[i]; j++) {
      std::cin >> s[i][j];
    }
  }
  for (int i = 1; i <= M; i++) {
    std::cin >> p[i];
  }

  select(1);

  std::cout << count << std::endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e18;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll x=0,y=0;
    ll ans=INF;
    rep(i,n){
        cin >> a[i];
        x+=a[i];
    }
    rep(i,n-1){
        y+=a[i];
        x-=a[i];
        ans=min(ans,abs(x-y));
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 4800
#include <bits/stdc++.h>
using namespace std;
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int l = lcm(x, 360);
    cout << l / x << endl;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        sc.close();

        String judge = "No";

        while (true) {
            C = C - B;
            if (C <= 0) {
                judge = "Yes";
                break;
            }
          
            A = A - D;
            if (A <= 0) {
                break;
            }
        }
        System.out.println(judge);
    }

}

Measured memory_bytes: 35768
module qsort
    use iso_fortran_env
    implicit none
contains
    recursive function iqsort(m) result(res)
        integer, intent(in) :: m(:)
        integer :: res(size(m)) 
        if (size(m) <= 1) then 
            res = m
        else
            res = [iqsort( pack(m(2:), m(2:) >= m(1)) ), m(1), iqsort( pack(m(2:), m(2:) < m(1)) )]
        end if
    end function iqsort
end module qsort

program main
    use iso_fortran_env
    use qsort
    implicit none

    integer(int32) :: n, k
    integer(int32),allocatable :: p(:)
    integer(int32) :: i

    read(*,*) n, k
    allocate(p(n))
    read(*,*) (p(i), i = 1, n)

    p = iqsort(p)
    print *, sum(p(n-k+1:n))

end program main

Measured memory_bytes: 9100
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

vector<string> split(string delim,string str){
  vector<string> res;
  str += delim;
  for(int i=0;i<str.size();i++){
    for(int j=1;i+j<=str.size();j++){
      if(str.substr(i,j).find(delim) != string::npos){
        if(str.substr(i,j-1).size() >0 ) res.push_back(str.substr(i,j-1));
        i+=j-1;
        break;
      }
    }
  }

  return res;
}

const static char unit_prefix_name[][12] = {
  "yotta",
  "zetta",
  "exa",
  "peta",
  "tera",
  "giga",
  "mega",
  "kilo",
  "hecto",
  "deca",
  "deci",
  "centi",
  "milli",
  "micro",
  "nano",
  "pico",
  "femto",
  "ato",
  "zepto",
  "yocto",
};

const static int unit_prefix_powers[] = {
  24,
  21,
  18,
  15,
  12,
  9,
  6,
  3,
  2,
  1,
  -1,
  -2,
  -3,
  -6,
  -9,
  -12,
  -15,
  -18,
  -21,
  -24
};

string normalize(const string& original){
  bool flag = false;
  string res = "";
  for(int i = 0; i < original.size(); i++){
    if(flag && original[i] != '.'){
      res += original[i];
      continue;
    }
    if(original[i] != '0' && original[i] != '.'){
      flag = true;
      res += original[i];
      if(i + 1 < original.size()){
        res += ".";
      }
    }
  }
  return res;
}

int compute_power(const string& original,const string& prefix){
  int power = 0;
  for(int i = 0; i < sizeof(unit_prefix_name)/(sizeof(char)*12); i++){
    if(string(unit_prefix_name[i]) == prefix){
      power = unit_prefix_powers[i];
    }
  }

  int dot_pos = original.size();
  for(int i = 0; i < original.size(); i++){
    if(original[i] == '.'){
      dot_pos = i;
      break;
    }
  }
  int first_number_pos = 0;
  for(int i = 0; i < original.size(); i++){
    if(original[i] != '.' && original[i] != '0'){
      first_number_pos = i;
      break;
    }
  }
  return (dot_pos - first_number_pos - (dot_pos > first_number_pos ? 1 : 0)) + power;
}

void conv(const string& original,const string& prefix,const string& unit){
  int power = compute_power(original,prefix);
  printf("%s * 10^%d %s\n",normalize(original).c_str(),power,unit.c_str());
}

int main(){
  string str;
  while(getline(cin,str)){
    int total_test_cases = atoi(str.c_str());
    for(int test_i = 0; test_i < total_test_cases; test_i++){
      string line;
      getline(cin,line);
      vector<string> elements = split(" ",line);
      if(elements.size() == 3){
        conv(elements[0],elements[1],elements[2]);
      }
      else{
        conv(elements[0],"",elements[1]);
      }
    }
  }
}

Measured memory_bytes: 1232
package main
 
import (
  "bufio"
  "fmt"
  "os"
  "strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)

func  next() int {
  sc.Scan()
  i, _ := strconv.Atoi(sc.Text())
  return i
}

func main() {
  sc.Split(bufio.ScanWords)
  kawaisou := false
  n := make([]int, 3, 3)
  for i := 0; i < 3; i++ {
    n[i] = next()
  }
  if n[0] == n[1] && n[1] != n[2] {
    kawaisou = true
  } else if n[0] == n[2] && n[1] != n[2] {
    kawaisou = true
  } else if n[1] == n[2] && n[0] != n[1] {
    kawaisou = true
  }

  if kawaisou {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

Measured memory_bytes: 640
import java.util.*;
class Main{
	static int a,b;
	static boolean s;
	public static void main(String[]$){
		Scanner c=new Scanner(System.in);
		int k=c.nextInt(),x=c.nextInt(),y=c.nextInt();
		x*=a=x<0?-1:1;
		y*=b=y<0?-1:1;
		if(s=x<y)x^=y^(y=x);
		int n=(x+y+k-1)/k;
		if(k%2==0&&(x+y)%2==1){
			System.out.println(-1);
			return;
		}else if(x+y<k){
			if((x+y)%(n=2)==1){
				System.out.println(3);
				p(x,x-k);
				p(x+(k+x-y)/2,x-k+(k-x+y)/2);
				p(x,y);
				return;
            }
		}else if((k-(x+y)%k)%k%2==1)n++;
		System.out.println(n);
		int m=(k*n-x-y)/2,i=0;
		while(++i<=n)if(m>k*i)p(0,-k*i);
			else if(x+m>k*i)p(k*i-m,-m);
			else p(x,k*i-m-m-x);
	}
	static void p(int x,int y){
		System.out.println(a*(s?y:x)+" "+b*(s?x:y));
	}
}

Measured memory_bytes: 44432
#include<stdio.h>
main()
{
    int n,m,x,a,c=0,d=0;
    scanf("%d%d%d",&n,&m,&x);
    for(int i=1;i<=m;i++){
        scanf("%d",&a);
        for(int i=x;i<=n+1;i++){
        if(i==a){
            c+=1;
        }
    }
     for(int i=x;i>=0;i--){
        if(i==a){
            d+=1;
        }
     }
    }
     if(c<d){
        printf("%d",c);
     }
     else if(d<c){
        printf("%d",d);
     }
     return 0;
    }


Measured memory_bytes: 1696
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include<string>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9 + 7);

constexpr int vmax = 1000;
int n;
ll W;
vector<ll> w;
vector<int> v;
vector<vector<ll>> dp;

int main(void) {
	cin >> n >> W;
	w = vector<ll>(n + 1, 0);
	v = vector<int>(n + 1, 0);
	for (int i = 1; i < n + 1; i++)
		cin >> w[i] >> v[i];

	dp = vector<vector<ll>>(n + 1, vector <ll>(n * vmax + 1, INF));
	dp[0][0] = 0;
	for (int i = 1; i < n + 1; i++) {
		for (int j = 0; j < n * vmax + 1; j++) {
			if (j >= v[i])
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
			else
				dp[i][j] = dp[i - 1][j];
		}
	}

	int ret = n * vmax;
	while (dp[n][ret] > W)
		ret--;

	cout << ret << endl;
	return 0;
}

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

using namespace std;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long sum = 0;
  string s;
  cin >> s;
  for (auto it : s)
    sum += (it - '0');
  if (sum % 9 == 0)
    cout << "Yes";
  else
    cout << "No";
}


Measured memory_bytes: 3728
#include<iostream>
#include<string>
#include<algorithm>

typedef long long ll;
using namespace std;
int main()
{
	string a, b, c;
	int A, B, C;
	cin >> a >> b >> c;
	A = a.size();
	B = b.size();
	if (a[A - 1] == b[0] && b[B - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
A = [int(x) for x in input().split()]

from collections import Counter
import operator
def f():
    evn = Counter(A[::2])
    odd = Counter(A[1::2])

    a = sorted(odd.most_common(2), key=operator.itemgetter(1, 0), reverse=True)
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0), reverse=True)

    ac = a[0][1]
    bc = b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Measured memory_bytes: 18592
#include<iostream>
#include<vector>
#include<queue>
#define INF 2e9
using namespace std;

void Dikstra(const vector<vector<pair<int, int> > >& G, vector<int>& d){
    d[0] = 0;
    priority_queue<pair<int, int> , vector<pair<int, int> >, greater<pair<int, int> > > PQ;
    PQ.push(make_pair(0, 0));
    vector<bool> is_black(d.size(), false);
    is_black[0] = true;
    while (!PQ.empty()) {
        int t = PQ.top().second;
        PQ.pop();
        is_black[t] = true;
        for (int i = 0; i < G[t].size(); i++) {
            int v = G[t][i].first;
            int w = G[t][i].second;
            if (!is_black[v] && d[t] + w < d[v]) {
                bool flag = false;
                d[v] = d[t] + w;
                PQ.push(make_pair(d[v], v));
            }
        }
    }

}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > G(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            G[u].push_back(make_pair(v, c));
        }
    }
    vector<int> d(n, INF);
    Dikstra(G, d);
    for (int i = 0; i < n; i++) {
       cout << i << " " << d[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3116
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string s;
    cin >> s;

    FOR(i, 1, s.size()) {
        if ((s.size() - i) & 1) continue;

        int n = (s.size() - i) >> 1;
        bool f = true;
        REP(j, n) {
            f &= s[j] == s[n + j];
        }

        if (f) {
            print(2 * n);
            return 0;
        }
    }
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define all(c) c.begin(),c.end()
typedef pair<int,int> P;
vector<int> clll[60][60],t;
int main(){
	rep(i,12) rep(j,60) rep(k,60){
		int h[3]={5*i+j/12,j,k},a[3]={0,1,2};
		P p=P(100,100);
		do{
			int x=h[a[0]],y=h[a[1]],z=h[a[2]];
			p=min(p,P((y-x+60)%60,(z-x+60)%60));
		}while(next_permutation(a,a+3));
		clll[p.fs][p.sc].push_back(i*3600+j*60+k);
	}
	while(true){
		int n;
		cin >> n;
		if(n==0) break;
		t.clear();
		P type[10];
		rep(i,n){
			int s[3];
			cin >> s[0] >> s[1] >> s[2];
			P p=P(100,100);
			int a[3]={0,1,2};
			do{
				int x=s[a[0]],y=s[a[1]],z=s[a[2]];
				p=min(p,P((y-x+60)%60,(z-x+60)%60));
			}while(next_permutation(a,a+3));
			type[i]=p;
			rep(j,clll[p.fs][p.sc].size()) t.push_back(clll[p.fs][p.sc][j]);
		}
		sort(all(t));
		t.erase(unique(all(t)),t.end());
		int len=1e7,ans=-1;
		rep(i,t.size()){
			int mx=0;
			rep(j,n){
				P p=type[j];
				vector<int>::iterator it=lower_bound(all(clll[p.fs][p.sc]),t[i]);
				if(it==clll[p.fs][p.sc].end()){
					mx=1e7;
					break;
				}
				mx=max(mx,*it);
			}
			if(mx==1e7) break;
			if(len>mx-t[i]) len=mx-t[i],ans=t[i];
		}
		printf("%02d:%02d:%02d %02d:%02d:%02d\n",ans/3600,ans%3600/60,ans%60,(ans+len)/3600,(ans+len)%3600/60,(ans+len)%60);
	}
}

Measured memory_bytes: 1584
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
int t[100005];
int dp[100005];
int main(){
	cin>>n>>k;
	for(int i=1;n>=i;i++)
	{
		cin>>t[i];
		if(i>1)
		dp[i]=1000000000;
		for(int j=1;k>=j and i-j>=1;j++)
		{
			dp[i]=min(dp[i],dp[i-j]+abs(t[i]-t[i-j]));
		}
	}
	cout<<dp[n];
	return 0;
}


Measured memory_bytes: 1024
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10 , P = 1e9 + 7;
int n , a[N] , du[N] , in[N] , sz[N];
int circlecnt[N] , f[N];

int main(){
  cin >> n;
  rep(i,1,n+1) cin >> a[i] , in[a[i]]++;
  rep(i,1,n+1) du[i] = in[i] , sz[i] = 1;
  vi q;
  rep(i,1,n+1) if(!du[i]) q.pb(i);
  rep(i,0,sz(q)) {
    int c=q[i];
    sz[a[c]]+=sz[c];
    if(!--du[a[c]]) q.pb(a[c]);
  }
  rep(i,1,n+1) if(in[i]>2||(in[i]==2&&!du[i]))
    return puts("0") , 0;
  int ans = 1;
  rep(i,1,n+1) if(du[i]) {
    vi cir;
    for(int c=i;du[c];c=a[c])
      cir.pb(c),du[c]=0;
    vi branch;
    rep(i,0,sz(cir)) if(sz[cir[i]]!=1)
      branch.pb(i);
    if(sz(branch)) {
      branch.pb(branch[0]);
      rep(i,1,sz(branch)) {
        int from = branch[i - 1] , to = branch[i];
        int dis = to - from;
        if(dis <= 0) dis += sz(cir);
        if(dis < sz[cir[to]] - 1)
          return puts("0") , 0;
        else if(dis > sz[cir[to]] - 1)
          (ans *= 2) %= P;
      }
    } else circlecnt[sz(cir)]++;
  }
  rep(i,1,n+1) if(circlecnt[i]) {
    int x = circlecnt[i];
    f[0] = 1;
    rep(j,1,x+1) {
      f[j] = f[j - 1];
      if(i >= 3 && i % 2 == 1) (f[j] += f[j - 1]) %= P;
      if(j >= 2) (f[j] += ll(f[j - 2]) * (j - 1) % P * i % P) %= P;
    }
    ans = ll(ans) * f[x] % P;
  }
  cout << ans << endl;
  return 0;
}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%d", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long
#define float long double 
#define ll long long

const int inf = (int) 1e16;
const int upper = (int) 3e5 + 15;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;
	
vector<vi> adj;
int dp[upper][2];

void dfs (int root, int prev) {
	dp[root][0] = 1, dp[root][1] = 1;
	for (auto i: adj[root]) {
		if (i == prev) continue;
		dfs(i, root);

		dp[root][0] *= (dp[i][1] + dp[i][0]);
		dp[root][1] *= dp[i][0];

		dp[root][0] %= M;
		dp[root][1] %= M;
	}
}
	
signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	int n; cin >> n; 
	adj.resize(n + 1);

	for (int i = 1; i <= n - 1; i += 1) {
		int a, b; cin >> a >> 	b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	dfs(1, 1);

	int ans = dp[1][0] + dp[1][1];
	ans %= M;
	cout << ans;
 	end_routine();	
}

Measured memory_bytes: 14208