akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <vector>
using namespace std;

int main(){
	string str;
	while(getline(cin,str) && str != "."){
		string c;
		for(int i = 0 ; i < str.size() ; i++)
			if(str[i] == ')' || str[i] == '(' || str[i] == '[' || str[i] == ']')
				c += str[i];
		stack<char> s;
		bool f = true;
		for(int i = 0 ; i < c.length() ; i++){
			if(s.empty() || c[i] == '(' || c[i] == '[')
				s.push(c[i]);
			else if( (s.top() == '(' && c[i] == ')') || (s.top() == '[' && c[i] == ']') ){
				s.pop();
			}else{
				f = false;
				break;
			}
		}
		cout << (f && s.empty() ?"yes":"no") << endl;
	}
}


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

// bad knowhow
#define REP(i,n) for(long long i=0;i<(long long)n;++i)

#include <set>
set<int> g_p[100];
set<int> g_leak;

int main() {

	while (true) {
		int n;
		cin >> n;
		REP(i, 100) g_p[i].clear();
		g_leak.clear();
		if (n==0) break;
		REP(i, n) {
			int m;
			cin >> m;
			REP(j, m) {
				int p;
				cin >> p; --p;
				g_p[i].insert(p);
			}
		}
		int k;
		cin >> k;

		REP(i, k) {
			int l;
			cin >> l;
			--l;
			g_leak.insert(l);
		}

		int suspect = -2;
		for (int i = 0; i < n; ++i) {
			auto it = g_leak.begin();
			for (; it!=g_leak.end();++it) {
				if(g_p[i].count(*it)==0) break;
			}
			if (it==g_leak.end()){
				if (suspect == -2) suspect = i;
				else{
					suspect = -2;
					break;
				}
			};
		}

		cout << suspect + 1 << endl;
	}
}

Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
long long h[100005],dp[100005],k,n,K,i;
int main(){
	cin>>n>>K;
	for(k=1;k<=n;k++){
		cin>>h[k]; dp[k]=1e12;
	}
	dp[1]=0;
	long long f=1;
	for(k=2;k<=n;k++){
	
	for(i=k-1;i>=max(k-K,f);i--)
		dp[k]=min(dp[i]+abs(h[k]-h[i]),dp[k]);
	}
	cout<<dp[n];
}

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

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        if(a[i]==a[i+1]){
            cout << "NO"<<endl;
            return 0;
        }
        else continue;
    }
    cout << "YES"<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include<cstring>
using namespace std;
 
int main() {
    int n,w;
    cin>>n>>w;
    long long val[n];
    long long  weight[n];
    
    int i,j;
    for(i= 0 ;i < n; i++)
    {
        cin>>weight[i];
        cin>>val[i];
    }
    
    long long dp[w+1];
    memset(dp, 0, sizeof(dp));
    
    for(i= 1 ;i <= n; i++)
    {
        for(j= w; j >= 0 ;j --)
        {
            if(weight[i-1] <= j)
                dp[j] = max(val[i-1] + dp[j - weight[i-1]], dp[j]);
        }
    }
    cout<<dp[w];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define int long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1e15
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define pb push_back

using namespace std;
const int N = 100005;
int n, m;
vector<int>v[N];
int vis[N] = {};

vector<vector<int>>dp;

int32_t main()
{
	std::ios::sync_with_stdio(false);

// #ifndef ONLINE_JUDGE
// 	freopen("inputf.txt", "r", stdin);
// 	freopen("outputf.txt", "w", stdout);
// #endif

	int n, m;
	cin >> n >> m;
	int w[n], v[n];

	for (int i = 0; i < n; i++)
	{
		cin >> w[i] >> v[i];
	}



	dp.resize(n + 1, vector<int>(m + 1));

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= m; j++)
		{

			if (i == 0 || j == 0)
				dp[i][j] = 0;
		}\

	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			if (w[i - 1] > j)
			{
				dp[i][j] = dp[i - 1][j];
			}
			else
			{
				dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]);
			}
		}
	}
	cout << dp[n][m] << endl;

	return 0;

}

Measured memory_bytes: 85468
#include <bits/stdc++.h>
using ll = long long;
constexpr const ll INF = LLONG_MAX / 2;
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<pair<ll, ll>> AB(N);
    for (int i = 0; i < N; i++) {
        cin >> AB[i].first >> AB[i].second;
    }
    sort(AB.begin(), AB.end());

    vector<ll> S(N), D(N);
    for (ll i = 0, cursum = 0; i < N; i++) {
        cursum += AB[i].second;
        S[i] = cursum;
        D[i] = cursum - AB[i].first;
    }

    vector<ll> M(N);
    for (ll i = N-1, curmax = -INF, curmaxidx = -INF; i >= 0; i--) {
        if (curmax < D[i]) {
            curmax = D[i];
            curmaxidx = i;
        }
        M[i] = curmaxidx;
    }

    ll ma = -INF;
    for (ll i = 0; i < N; i++) {
        ll s = S[M[i]] - (i != 0 ? S[i-1] : 0);
        ma = max(ma, s - AB[M[i]].first + AB[i].first);
    }
    cout << ma << endl;

    return 0;
}



Measured memory_bytes: 22376
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = min(s1.size(), s2.size()); i > 0; --i) {
    vector<int> v1(26), v2(26);
    for (int j = 0; j < 26; ++j) v1[j] =v2[j] = 0;
    set<vector<int>> m;
    for (int j = 0; j < i; ++j) ++v1[s1[j] - 'a'];
    for (int j = 0; i + j <= (int)s1.size(); ++j) {
      m.insert(v1);
      --v1[s1[j] - 'a'];
      if (i + j != (int)s1.size()) ++v1[s1[i + j] - 'a'];
    }
    for (int j = 0; j < i; ++j) ++v2[s2[j] - 'a'];
    for (int j = 0; i + j <= (int)s2.size(); ++j) {
      if (m.count(v2)) {
        cout << i << endl;
        return 0;
      }
      --v2[s2[j] - 'a'];
      if (i + j != (int)s2.size()) ++v2[s2[i + j] - 'a'];
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 3836
#include <algorithm>
#include <iostream>
#include <cstdint>

int main()
{
  uint64_t v[3];
  std::cin >> v[0] >> v[1] >> v[2];
  if (v[0] % 2 == 0 || v[1] % 2 == 0 || v[2] % 2 == 0) {
    std::cout << 0 << std::endl;
  } else {
    std::sort(v, v+3);
    std::cout << v[0] * v[1] << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b - 1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;
static const double EPS = 1e-10;

int main(){
    int A, B; cin >> A >> B;
    
    cout << ((B-1) + (A- 2) )/ ( A - 1) << endl;
}

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

int main(){
    string S;
    cin>>S;
    string one,sec;

    for(int i=0; i<(S.size()-1)/2; i++){
        one.push_back(S[i]);
    } 

    for(int i=(S.size()+3)/2-1; i<S.size(); i++){
        sec.push_back(S[i]);
    }

    string cps,cpone,cpsec;

    cps = S;
    cpone = one;
    cpsec = sec;

    reverse(S.begin(),S.end());
    reverse(one.begin(),one.end());
    reverse(sec.begin(),sec.end());

    if(S == cps && cpone == one && cpsec == sec){
        cout<<"Yes"<<endl;
    }

    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static List<String> z;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String p = "";
        String q = "";
        for (int i = 0; i < n; i++) {
            p += sc.next();
        }
        for (int i = 0; i < n; i++) {
            q += sc.next();
        }
        String s = "";
        for (int i = 1; i <= n; i++) {
            s += i;
        }
        int first = 0;
        int second = 0;
        z = new ArrayList<>();
        permutation(s,"");
        for(int i = 0; i < z.size(); i++) {
            if(z.get(i).equals(p)) {
                first = i + 1;
            }
            if(z.get(i).equals(q)) {
                second = i + 1;
            }
        }
        int ans = Math.abs(first - second);
        System.out.println(ans);
    }

    public static void permutation(String q, String ans){
        if(q.length() <= 1) {
            z.add(ans + q);
         }
         else {
            for (int i = 0; i < q.length(); i++) {
                permutation(q.substring(0, i) + q.substring(i + 1),
                ans + q.charAt(i));
            }
         }
    }
}

Measured memory_bytes: 60788
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,a,b) for(int i=a;i<=b;i++)A
#define mp make_pair
#define deb(x) cout<<#x<<"-->"<<x<<endl;
#define deb1a(v) for(auto it:v) {cout<<it<<" ";} cout<<endl;
#define deb2a(v) for(auto it:v){for(auto it1:it) {cout<<it1<<" ";}cout<<endl;}
int32_t main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int n;
cin>>n;
int a[n];
fo(i,n)
cin>>a[i];
int curr=a[n-1]+1;
int ans=0;
for(int i=n-1;i>=0;i--)
{
    if(a[i]>=curr)
        {curr=a[i];a[i]=a[i+1]+1;}
    else
       {
       curr=a[i];
       a[i]=0;}
        ans=max(ans,a[i]);
}
//deb1a(a);
cout<<ans;

}


Measured memory_bytes: 1024
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

a=Counter(a).most_common()
a=sorted(a,reverse=True)

ans=0
for i,j in a:
    if j>=4 and ans==0:
        ans=i*i
        break
    elif j>=2 and ans==0:
        ans=i
    elif j>=2:
        ans*=i
        break
print(ans)

Measured memory_bytes: 21660
#include <cstdio>
#include <stack>
using namespace std;

int main()
{
	char ch;
	while (ch = getchar(), ch != '.') {
		stack<int> st;
		bool flag = true;
		while (ch != '\n') {
			if (ch == '[') {
				st.push(1);
			} else if(ch == '(') {
				st.push(2);
			} else if(ch == ']') {
				if (!st.empty() && st.top() == 1)
					st.pop();
				else
					flag = false;
			} else if(ch == ')') {
				if (!st.empty() && st.top() == 2)
					st.pop();
				else
					flag = false;
			}
			ch = getchar();
		}
		if (!st.empty())
			flag = false;
		if (flag)
			printf("yes\n");
		else
			printf("no\n");
	}
	return 0;
}

Measured memory_bytes: 960
n = gets.chomp.to_i
a = []
n.times do |i|
    a[i] = gets.chomp.to_i
end
k = 0
cnt = 0
while k != 1
    cnt += 1
    k = a[k]-1
    if cnt > n
        break
    end
end
if cnt <= n
    puts cnt
else
    puts -1
end

Measured memory_bytes: 2632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T>void chmax(T &a, const T &b) { a = max(a,b); }
template<class T>void chmin(T &a, const T &b) { a = min(a,b); }

ll INF = 1e8;
ll dp[105][105];

int main() {
    int H,W; cin >> H >> W;
    int m[H+1][W+1];
    rep(i,H) rep(j,W) {
        char s; cin >> s;
        m[i][j] = (s == '.') ? 0 : 1;
    }

    rep(i,105) rep(j,105) dp[i][j] = INF;
    dp[0][0] = m[0][0]; 

    rep(i,H) rep(j,W) {
        ll nr = (m[i][j] >= m[i][j+1]) ? 0 : 1;
        ll nd = (m[i][j] >= m[i+1][j]) ? 0 : 1;
        chmin(dp[i][j+1], dp[i][j] + nr);
        chmin(dp[i+1][j], dp[i][j] + nd);
    }
    cout << dp[H-1][W-1] << "\n";
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int a[3], b[3];
int c[3][3];

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

  REP(i, 3) REP(j, 3) cin >> c[i][j];

  int sum = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (c[i][j] - c[i][(j + 1) % 3] !=
          c[(i + 1) % 3][j] - c[(i + 1) % 3][(j + 1) % 3]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = 1e3;

int n, h, w; 
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> h >> w >> n;

    int a = (n / h), b = (n / w); 

    if (n % h != 0) a++;
    if (n % w != 0) b++;
    cout << min(a, b);
         
    return 0;
}

Measured memory_bytes: 256
const log = console.log;

// ----

function Main(input: string): void {
  const n = parseInt(input);

  for (let cakesAmount = 0; cakesAmount <= n; cakesAmount += 4) {
    for (let totalAmount = cakesAmount; totalAmount <= n; totalAmount += 7) {
      if (totalAmount !== n) continue;

      log("Yes");

      return;
    }
  }

  log("No");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll M = 1e9 + 7;

int main(void){
  int n, m; ll B;
  scanf("%d %d", &n, &m);

  vl ks(m, 0), ps(m); B = 1LL << n;
  vector<vl> dp(B, vl(m + 1, M));

  rep(i, m){
    int b;
    scanf("%lld %d", &ps[i], &b);
    rep(j, b){
      int c;
      scanf("%d", &c); c--;
      ks[i] |= 1LL << c;
    }
  }

  dp[0][0] = 0;
  rep(i, m){
    rep(bit, B){
      dp[bit][i + 1] = dp[bit][i];
      ll res = bit & ~ks[i];
      dp[bit][i + 1] = min(dp[bit][i + 1], dp[res][i] + ps[i]);
    }
  }

  ll ans = dp[B - 1][m];
  if (ans != M) cout << ans << endl;
  else cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 35372
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[30], isLeaf[30];
using Graph = vector< vector< pair<int, int> > >;

int solve(Graph &G, int cur, int par=-1) {
    if(dp[cur] >= 0) return dp[cur];
    dp[cur] = 0;
    int child = 0;
    for(auto e : G[cur]) {
        if(e.first == par) continue;

        child++;
        int to, cost; tie(to, cost) = e;
        int val = solve(G, to, cur);

        if(!isLeaf[to]) {
            chmax(dp[cur], val + cost);
        }
    }
    isLeaf[cur] = (child == 0);
    return dp[cur];
}
 
signed main() {
    int N;
    while(cin >> N, N) {
        memset(dp, -1, sizeof(dp));

        Graph G(N);
        for(int i=0; i<N-1; i++) {
            int a, b, t; cin >> a >> b >> t;
            a--; b--;
            G[a].push_back(make_pair(b, t));
            G[b].push_back(make_pair(a, t));
        }

        int sum = -solve(G, 0);
        for(int i=0; i<N; i++) {
            for(auto e : G[i]) {
                int u = i, v = e.first;
                if(u < v and !isLeaf[u] and !isLeaf[v]) sum += 2 * e.second;
            }
        }

        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define N 100005
using namespace std;
struct edge{
	int k,next;
}e[N<<1];
int n,home[N],cnt=-1,lg2[N<<1];
void add(int x,int y){
	cnt++;
	e[cnt].k=y;
	e[cnt].next=home[x];
	home[x]=cnt;
}
int f[N],sum[25];
void dfs(int k,int F){
	for(int i=home[k];~i;i=e[i].next)if(e[i].k!=F){
		dfs(e[i].k,k);
	}
	memset(sum,0,sizeof(sum));
	for(int i=home[k];~i;i=e[i].next)if(e[i].k!=F){
		int g=f[e[i].k],t;
		while(g) t=g&-g,sum[lg2[t]]++,g-=t;
	}
	int o=0;
	for(int i=20;~i;i--){
		if(sum[i]){
			if(!o) o=(1<<i);
			if(sum[i]>1){
				i++;
				while(sum[i]){
					f[k]^=(1<<i);
					i++;
				}
				f[k]|=(1<<i);
				return;
			}
			f[k]|=(1<<i);
		}else if(o){
			int h=0,g;
			while(i>=0){
				if(!sum[i]) g=(1<<i)|h;
				else h|=(1<<i);
				if(sum[i]>1) break;
				i--;
			}
			f[k]|=g;
			return;
		}
	}
	f[k]=o+o;
	if(!f[k]) f[k]=1;
}
int main(){
	//freopen("test.in","r",stdin);
	memset(home,-1,sizeof(home));
	for(int i=2;i<=200000;i++) lg2[i]=lg2[i>>1]+1;
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1,0);
	printf("%d\n",lg2[f[1]]);
	return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  string s;
  cin >> s;

  int ans = 0;
  
  for (int k = 0; k <= 999; k++) {
    int i = k;
    vector<int> gole;
    int gol3 = i % 10; i /= 10; gole.push_back(gol3);
    int gol2 = i % 10; i /= 10; gole.push_back(gol2);
    int gol1 = i % 10; gole.push_back(gol1);
    //cout << gol1<<" "<<gol2<<" "<<gol3<<endl;
    
    rep (j, n) {
      int c = s[j] - '0';
      if (c == gole[gole.size() - 1]) gole.pop_back();
      if (gole.size() == 0) {
        ans++;
        break;
      }
    }
    //cout<<k<<" "<<ans<<endl;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int k;
	cin >> k;

	long long ans = 0;

	for(int i = 1; i <= k; i++) {
		for(int j = 1; j <= k; j++) {
			for(int t = 1; t <= k; t++) {
				ans += __gcd(i, __gcd(j, t));
			}
		}
	}

	cout << ans;


	return 0;
}


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

#define N 1000000000

int main() {
    ll s;cin>>s;
    if(s<N)cout<<0<<' '<<0<<' '<<0<<' '
            <<1<<' '<<s<<' '<<0<<endl;
    else if(s==1000000000000000000)
        cout<<0<<' '<<0<<' '<<0<<' '
            <<N<<' '<<N<<' '<<0<<endl;
    else cout<<0<<' '<<0<<' '<<1<<' '
            <<N<<' '<<s/N+1<<' '<<(s/N+1)*N-s<<endl;
}

Measured memory_bytes: 256
m = map(int,raw_input().split())
if m[0] < m[1] < m[2] or m[0] == m[1] == m[2] or m[0] < m[1] == m[2] or m[0] == m[1] < m[2]:
 print m[0],m[1],m[2]
elif m[2] < m[0] < m[1] or m[2] < m[0] == m[1] or m[2] == m[0] < m[1]: 
 print m[2],m[0],m[1]
elif m[1] < m[2] < m[0] or m[1] < m[2] == m[0] or m[1] == m[2] < m[0]: 
 print m[1],m[2],m[0]
elif m[0] < m[2] < m[1]:
 print m[0],m[2],m[1]
elif m[2] < m[1] < m[0]:
 print m[2],m[1],m[0]
elif m[1] < m[0] < m[2]:
 print m[1],m[0],m[2]

Measured memory_bytes: 6480
#include<stdio.h>

int main(void){
    int a,b,c,x,cnt=0;
    
    scanf("%d %d %d",&a,&b,&c);
    for(x=a;x<=b;x++){
        if(c%x==0)
            cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}
    

Measured memory_bytes: 596
#include <stdio.h>
int main(){
    int n, i;
    int data[100];
    int max=-1, min=1001;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&data[i]);
        if(max<data[i]) max=data[i];
        if(min>data[i]) min=data[i];
    }
    printf("%d\n",max-min);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void){
	int a,b,c,d,e,f,g,i,n,m,w[16][16]={0},r=0;
	scanf("%d%d",&n,&m);
	for(i = 1;i <= m;i++){scanf("%d%d",&a,&b);w[a][b] = 1;w[b][a] = 1;}
	if(n == 8){
	for(a = 2;a <= 8;a++){
	for(b = 2;b <= 8;b++){if(b == a){continue;}
	for(c = 2;c <= 8;c++){if(c == a || c == b){continue;}
	for(d = 2;d <= 8;d++){if(d == a || d == b || d == c){continue;}
	for(e = 2;e <= 8;e++){if(e == a || e == b || e == c || e == d){continue;}
	for(f = 2;f <= 8;f++){if(f == a || f == b || f == c || f == d || f == e){continue;}
	for(g = 2;g <= 8;g++){if(g == a || g == b || g == c || g == d || g == e || g == f){continue;}
	if(w[1][a] && w[a][b] && w[b][c] && w[c][d] && w[d][e] && w[e][f] && w[f][g]){r++;}
	}
	}
	}
	}
	}
	}
	}
	}
	if(n == 7){
	for(a = 2;a <= 7;a++){
	for(b = 2;b <= 7;b++){if(b == a){continue;}
	for(c = 2;c <= 7;c++){if(c == a || c == b){continue;}
	for(d = 2;d <= 7;d++){if(d == a || d == b || d == c){continue;}
	for(e = 2;e <= 7;e++){if(e == a || e == b || e == c || e == d){continue;}
	for(f = 2;f <= 7;f++){if(f == a || f == b || f == c || f == d || f == e){continue;}
	if(w[1][a] && w[a][b] && w[b][c] && w[c][d] && w[d][e] && w[e][f]){r++;}
	}
	}
	}
	}
	}
	}
	}
	if(n == 6){
	for(a = 2;a <= 6;a++){
	for(b = 2;b <= 6;b++){if(b == a){continue;}
	for(c = 2;c <= 6;c++){if(c == a || c == b){continue;}
	for(d = 2;d <= 6;d++){if(d == a || d == b || d == c){continue;}
	for(e = 2;e <= 6;e++){if(e == a || e == b || e == c || e == d){continue;}
	if(w[1][a] && w[a][b] && w[b][c] && w[c][d] && w[d][e]){r++;}
	}
	}
	}
	}
	}
	}
	if(n == 5){
	for(a = 2;a <= 5;a++){
	for(b = 2;b <= 5;b++){if(b == a){continue;}
	for(c = 2;c <= 5;c++){if(c == a || c == b){continue;}
	for(d = 2;d <= 5;d++){if(d == a || d == b || d == c){continue;}
	if(w[1][a] && w[a][b] && w[b][c] && w[c][d]){r++;}
	}
	}
	}
	}
	}
	if(n == 4){
	for(a = 2;a <= 4;a++){
	for(b = 2;b <= 4;b++){if(b == a){continue;}
	for(c = 2;c <= 4;c++){if(c == a || c == b){continue;}
	if(w[1][a] && w[a][b] && w[b][c]){r++;}
	}
	}
	}
	}
	if(n == 3){
	for(a = 2;a <= 3;a++){
	for(b = 2;b <= 3;b++){if(b == a){continue;}
	if(w[1][a] && w[a][b]){r++;}
	}
	}
	}
	if(n == 2){
	for(a = 2;a <= 2;a++){
	if(w[1][a]){r++;}
	}
	}
	printf("%d\n",r);
	return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const char mp[] = "RYGB";
const int maxn = 1505;
int n, m, d, ans[maxn][maxn];

int main() {
  scanf("%d %d %d", &n, &m, &d);
  int tot = n + n + m;
  for (int i = 1; i <= tot; i++) {
    for (int j = 1; j <= tot; j++) {
      ans[i][j] = (((j - 1) % 4 + 1) + ((i & 1) ? 0 : 2) - 1) % 4;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x = (i + j + m) / d;
      int y = (i - j + m) / d;
      putchar(mp[(x & 1) << 1 | (y & 1)]);
//      putchar(mp[ans[x][y]]);
    }
    putchar(10);
  }
  return 0;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cout << x << endl;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;
int MAX_K = 150;

int main()
{
    int n;
    cin >> n;
    string t = "ACL";
    string ans = "";
    rep(i,n) ans += t;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int x, y;
	scanf("%d %d", &x, &y);

	if (x < y) {
		swap(x, y);
	}

	while (y > 0) {
		int r = x % y;
		x = y;
		y = r;
	}
	cout << x << endl;

	return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++)cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());

    if(n == 2) {
        cout << a[0] << endl;
        return 0;
    }
    ll sel = n - 2;

    ll sum = a[0];
    for(ll i = 1; i < n && sel > 0; i++) {
        sum += (sel >= 2 ? a[i] * 2 : a[i]);
        sel -= 2;
    }
    cout << sum << endl;
}

Measured memory_bytes: 4824
#include <iostream>
#include <vector>
#include <functional>

template <class Cost = int>
struct Edge {
    int from, to;
    Cost cost;
    Edge(int from = -1, int to = -1, Cost cost = 1)
        : from(from), to(to), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
class Graph {
public:
    int size;
    std::vector<std::vector<Edge<Cost>>> path;

    explicit Graph(int N = 0) : size(N), path(size) {}
    void span(int from, int to, Cost cost = 1) {
        path[from].push_back(Edge<Cost>(from, to, cost));
    }
    std::vector<Edge<Cost>>& operator[](int v) { return path[v]; }
};

int main() {
    int N;
    std::cin >> N;

    Graph<> graph(N);
    for (int i = 0; i < N - 1; ++i) {
        int x, y;
        std::cin >> x >> y;
        --x, --y;
        graph.span(x, y);
        graph.span(y, x);
    }

    std::function<int(int, int)> dfs = [&](int v, int r) {
        int ret = 0;
        for (auto e : graph[v]) {
            if (e.to == r) continue;
            ret ^= (dfs(e.to, v) + 1);
        }
        return ret;
    };

    std::cout << (dfs(0, -1) > 0 ? "Alice" : "Bob") << std::endl;
    return 0;
}


Measured memory_bytes: 13568
import java.io.*;
import java.util.*;
import java.util.Collections;
 
class Main{
    public static void main(String[] a) throws Exception{
    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    	Integer[] mountains=new Integer[10];
    	for(int i=0;i<10;i++){
    		mountains[i]=Integer.valueOf(br.readLine());
    	}
    	Arrays.sort(mountains, Collections.reverseOrder());
		for(int i=0;i<3;i++){
			System.out.println(mountains[i]);
		}    	
    }
}

Measured memory_bytes: 24212
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int mod=1e4+7;
const double eps=1e-8;
const LL inf=0x3f3f3f3f;
const double pi=acos(-1.0);
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
string s;
string ss="CODEFESTIVAL2016";
int main() {
	int n,a,b;
	cin>>n>>a>>b;
	cin>>s;
	int l=SZ(s);
	int ca=0,cb=0;
	for(int i=0;i<l;i++){
        if(s[i]=='c') puts("No");
        else if(s[i]=='a'){
            if(ca+cb<a+b){
                puts("Yes");
                ca++;
            }
            else puts("No");
        }
        else{
            if(cb<b&&ca+cb<a+b){
                puts("Yes");
                cb++;
            }
            else puts("No");
        }
	}
	return 0;
}

Measured memory_bytes: 896
import java.io.*;
import java.util.*;
import java.math.*;
 
public class Main {
 
        Scanner sc = new Scanner(System.in);
 
        final double MAX = Double.MAX_VALUE / 4;
        final double EPS = 1e-8;
        double[] in;
 
        void run() {
                int n = sc.nextInt();
                in = new double[n];
                for (int i = 0; i < n; i++) {
                        in[i] = sc.nextInt();
                }
                n++;
                double dp[][] = new double[123456][n];
 
                for (int i = 0; i < 123455; i++) {
                        Arrays.fill(dp[i], -MAX);
                }
 
                dp[1][0] = 0;
                
                for (int i = 1; i < n; i++) {
                        for (int j = 0; j < 123400; j++) {
                                if (dp[j][i-1] >= 0) {
                                        for (int jj = j; jj < 123400; jj += j) {
                                                double temp = Math.max(dp[j][i-1], Math.abs(jj- in[i-1])/in[i-1]);
                                                if(dp[jj][i] < 0){
                                                        dp[jj][i] = temp;
                                                }
                                                dp[jj][i] = Math.min(dp[jj][i], temp);
                                        }
                                }
                        }
                }
                
                double ans=MAX;
                for(int i = 0; i < 123450; i++){
                        if(dp[i][n-1] >= 0){
                        ans = Math.min(dp[i][n-1], ans);
                        }
                }
                System.out.printf("%.9f\n",ans);
        }
 
        public static void main(String[] args) {
                Main m = new Main();
                m.run();
        }
 
}
 

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;

////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define len(x) ((int)(x).size())
using pii = pair<int, int>;
using ll = long long;
using llu = long long unsigned;
using ld = long double;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
	return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod (ll x, int m = MOD) {
	return (int)(((x%m) + m)%m);
}

////////////////////////// Solution starts below. //////////////////////////////

const int N = 1e5+10;

int n;
int a[N][3];
int dp[N][3];

int solve (int day, int bef) {
	if (day > n)
		return 0;
	
	int &r = dp[day][bef];
	if (r != -1) return r;
	for (int i = 0; i < 3; i++)
		if (i != bef)
			r = max (r, solve (day+1, i) + a[day][i]);
		
	return r;
}

int main () {
	memset (dp, -1, sizeof dp);
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < 3; j++)
			scanf ("%d", &a[i][j]);
		
	int ans = -1;
	for (int i = 0; i < 3; i++)
		ans = max (ans, solve (2, i) + a[1][i]);
	printf ("%d\n", ans);

	return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	int N, T; cin >> N >> T;
	vector<int> t(N);
	REP(i,N) cin >> t[i];

	int ans = 0;
	FOR(i,1,N){
		if(t[i]-t[i-1] > T) ans += T;
		else ans += t[i] - t[i-1];
	}
	ans += T;
	
	cout << ans << endl;


	return 0;

}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n;cin>>n;
	vector<int>v;
	rep(i,n)v.push_back(i);
	vector<int>p(n),q(n);
	rep(i,n)scanf("%d",&p[i]),p[i]--;
	rep(i,n)scanf("%d",&q[i]),q[i]--;
	int a=0,b=0;
	int cnt=0;
	do{
		if(v==p)a=cnt;
		if(v==q)b=cnt;
		cnt++;
	}while(next_permutation(v.begin(),v.end()));
	cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char a[4];
	int i,c=0,hantei=0;
	scanf("%s",a);

	for(i=0;a[i]!='\0';i++){
		c++;
	}

	for(i=0;i<=c-1;i++){
		if(a[i] != a[c-1-i])
			hantei++;
	}
	
	printf("%s\n",hantei?"No":"Yes");
	return 0;
}

Measured memory_bytes: 128
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n, a[N], ans = 1, x;

int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    int w, a, b;
    cin>>w>>a>>b;

    int s_1 = a, s_2 = b, e_1 = a+w, e_2 = b+w;

    if((b<=e_1 && e_1<=b+w) || (b<=s_1 && s_1<=b+w))
    cout<<"0\n";
    else
    {
      int d1 = abs(e_1 - s_2);
      int d2 = abs(e_2 - s_1);
      int ans = min(d1, d2);
      cout<<ans<<endl;
    }







    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int ans = 0;
  multiset<int, greater<int>> s(begin(A), end(A));
  while(!s.empty()) {
    int mx = *s.begin();
    s.erase(s.begin());
    
    int cnt = 0;
    for (int tmp = mx; tmp > 0; tmp >>= 1) cnt++;
    
    int base = 1 << cnt;

    auto it = s.find(base - mx);
    if (it != s.end()) {
      s.erase(it);
      ans++;
    }
  }

  cout << ans << endl;
}


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

using namespace std;


void solve() {
    int n,m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> g(n), r(n);
    for (int i = 0; i < m; i++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        g[x].emplace_back(i,y);
        r[y].emplace_back(i,x);
    }
    vector<bool> trk(n, false);
    function<void(int)> dfs = [&](int u){
        trk[u] = true;
        for (auto& p: g[u]) {
            int i,v;
            tie(i,v) = p;
            if (!trk[v]) {
                dfs(v);
            }
        }
    };
    vector<bool> in_scc(m);
    for (int v = 0; v < n; v++) {
        fill(trk.begin(), trk.end(), 0);
        dfs(v);
        for (auto& p: r[v]) {
            int i,u;
            tie(i,u) = p;
            in_scc[i] = trk[u];
        }
    }
    vector<bool> use_extra(m);
    for (int u = 0; u < n; u++) {
        for (int _ = 0; _ < 2; _++) {
            fill(trk.begin(), trk.end(), 0);
            trk[u] = true;
            for (auto& p: g[u]) {
                int i,v;
                tie(i,v) = p;
                if (trk[v]) use_extra[i] = true;
                else dfs(v);
            }
            reverse(g[u].begin(), g[u].end());
        }
    }
    for (int i = 0; i < m; i++) {
        cout << (in_scc[i] == use_extra[i]? "same":"diff") << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 7424
N=int(input()) 
A=list(map(int,input().split()))
n=0
for i in range(N):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj=j
    if minj != i:
        x=A[i]
        A[i]=A[minj]
        A[minj]=x
        n+=1
print(*A)
print(n)


Measured memory_bytes: 5600
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    target = {1, -1}
    results = set()
    for sign in target:
        total = 0
        ans = 0
        for an in a:
            total += an
            if sign != ((total > 0) - (total < 0)):
                ans -= (total - sign) * sign
                total = sign
            sign *= -1
        results.add(ans)

    print(min(results))


if __name__ == "__main__":
    main()


Measured memory_bytes: 85784
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int f = 0;
  int x = 1;
  cin >> N;
  for (int i = 0; i < 8; i++) {
    f += N % (x * 10) / x;
    x *= 10;
  }
  if (N % f == 0) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
 	int n;
 	cin >> n;
 	int64_t res = 0;
 	for (int i = 1; i <= n; ++i) {
 		if (i%3 == 0 || i%5 == 0) continue;
 		res += i;
 	}   
 	cout << res << '\n';
}

Measured memory_bytes: 3608
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
         break
    for h in range(H):
        for w in range(W):
            if (h+w)%2==0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7004
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0 && n / i != i) {
      ll num = n / i - 1;
      if(n / num == n % num) {
        ans += n / i - 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(){
	int a[1005],m,n,tot=0,sum=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		tot+=a[i];
	}
	for(int i=1;i<=n;i++){
		if(a[i]*4*m>=tot) sum++;
	}
	if(sum>=m) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
fn main(){
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let n: i32 = s.trim().parse().unwrap();
	let mut m = n;
	let mut p = 0;
	while m > 0 {
		p += m % 10;
		p *= 10;
		m /= 10;
	}
	if n == (p / 10) {
		println!("Yes");
	} else {
		println!("No");
	}
}


Measured memory_bytes: 4352
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

INF = 1000000007

while True:
    A = raw_input()
    if A == '0':
        break
    B = raw_input()
    C = raw_input()
    A = A[::-1]
    B = B[::-1]
    C = C[::-1]

    if not max(len(A), len(B)) in [len(C), len(C) + 1]:
        print 0
        continue
    
    while len(A) < len(C):
        A += '0'
    
    while len(B) < len(C):
        B += '0'
    
    rem0 = 1
    rem1 = 0
    for index in range(len(C)):
        nex0 = 0
        nex1 = 0

        if A[index] == '?':
            la = range(max(0, index - len(C) + 2), 10)
        else:
            la = [int(A[index])]
        
        if B[index] == '?':
            lb = range(max(0, index - len(C) + 2), 10)
        else:
            lb = [int(B[index])]
        
        if C[index] == '?':
            lc = range(max(0, index - len(C) + 2), 10)
        else:
            lc = [int(C[index])]
        
        for a, b, c in it.product(la, lb, lc):
            if a + b == c:
                nex0 += rem0
            if a + b == 10 + c:
                nex1 += rem0
            if a + b == c - 1:
                nex0 += rem1
            if a + b == 10 + c - 1:
                nex1 += rem1
        rem0 = nex0 % INF
        rem1 = nex1 % INF
    print rem0


Measured memory_bytes: 5000
#include<bits/stdc++.h>
using namespace std;
vector<int> a[100001];
int n, m, u, v, d[100001], kq;
void nhap()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>u>>v;
        a[u].push_back(v);
    }
    memset(d, -1, sizeof d);
}
int dfs(int u)
{
    if(d[u]!=-1) return d[u];
    vector<int>::iterator v;
    int res=0;//phải khai báo res mới vì mỗi lần đệ quy là res mới, ko thể khai báo ở ngaoif rồi dô cho = 0;
    for(v=a[u].begin();v!=a[u].end();v++)
        res=max(res, dfs(*v));
    res++;
    return d[u]=res;
}
int main()
{
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
    nhap();
    for(int i=1;i<=n;i++)
        if(d[i]==-1) dfs(i);
    kq=0;
    for(int i=1;i<=n;i++) kq=max(kq, d[i]);
    cout<<kq-1;
    return 0;
}


Measured memory_bytes: 8192
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

vi g[100005];

int dfs(int now){
  vi v;
  int i;
  rep(i,g[now].size()) v.push_back(dfs(g[now][i]));
  sort(all(v));
  int tmp=0;
  for(i=1;i<=v.size();i++)tmp=max(tmp,i+v[v.size()-i]);
  return tmp;
}

int main(void) {
  int n,a,i;
  cin>>n;
  rep(i,n-1){
    cin>>a;
    g[a-1].push_back(i+1);
  }
  cout<<dfs(0)<<endl;
}


Measured memory_bytes: 13568
N = input() 
s = raw_input()

list = list(s)
count = 0
E_li = [0]

for i in range(0,N):
	if list[i] == 'E':
		count += 1
	E_li.append(count)

all_E = E_li[N]
n_W = 0
n_E = 0
ans = N

for i in range(0,N):
	n_W = i - E_li[i]
	n_E = all_E - E_li[i+1]
	ans = min(ans, n_W + n_E)

print ans

Measured memory_bytes: 24320
def solve(h,n,a,b):
    dp = [[0 for j in range(h+1)] for i in range(n+1)]

    for i in range(n):
        for j in range(h+1):
            if j <= a[i] and i == 0:
                dp[i+1][j] = b[i]
            elif i == 0:
                dp[i+1][j] = dp[i+1][j-a[i]]+b[i]
            elif j <= a[i]:
                dp[i+1][j] = min(dp[i][j],b[i])
            else:
                dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+b[i])
    return dp[n][h]

h, n = map(int,input().split())
a = []
b = []

for i in range(n):
    ai,bi = map(int,input().split())
    a.append(ai)
    b.append(bi)

print(solve(h,n,a,b))

Measured memory_bytes: 125788
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    /**
     * @return mixed
     */
    public function next() {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    /**
     * @return bool
     */
    public function hasNext() {
        return $this->pointer < $this->count;
    }

    /**
     * @return int
     */
    public function nextInt() {
        return (int)$this->next();
    }

    /**
     * @return float
     */
    public function nextDouble() {
        return (double)$this->next();
    }
}

/**
 * 優先度付きキュー(低い方が優先度高)
 * Class DijkstraPriorityQueue
 */
class DijkstraPriorityQueue extends SplPriorityQueue
{
    public function compare($priority1, $priority2) {
        if ($priority1 === $priority2) {
            return 0;
        }
        return $priority1 < $priority2 ? 1 : -1;
    }
}



// 初期化
$sc = new Scanner();
while(true) {
    $n = $sc->nextInt();
    $m = $sc->nextInt();
    if ($n == 0 && $m == 0) {
        break;
    }

    $costArray = [];
    for ($i = 0; $i < $n; $i++) {
        $costArray[$i] = $sc->nextInt();
    }

    $result = -1;
    foreach ($costArray as $i=>$cost) {
        for ($j = $i+1; $j < $n; $j++) {
            $sum = $cost + $costArray[$j];
            if ($result < $sum && $sum <= $m) {
                $result = $sum;
            }
        }
    }

    if ($result != -1) {
        echo $result . "\n";
    } else {
        echo 'NONE' . "\n";
    }
    
}


Measured memory_bytes: 9700
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;
int a[1001];
int main() {
    int N, M; scanf("%d%d", &N, &M);
    int c, d;
    memset(a, 0, sizeof(a));
    rep(_, M) {
        scanf("%d%d", &c, &d);
        --c; --d;
        a[c]++; a[d]--;
    }
    rep(i, N) a[i + 1] += a[i];
    int ans = N + 1;
    int start = 0; bool cnt = false;
    rep(i, N + 1) {
        if(cnt == false) {
            if(a[i]) {
                cnt = true;
                start = i;
            }
        }else {
            if(a[i] == 0) {
                ans += (i - start) * 2;
                cnt = false;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1196
H, W, D = map(int,input().split())
d = {}
for i in range(1, H+1):
    A = list(map(int,input().split()))
    for j in range(W):
        d[A[j]] = (i, j+1)
acc = [[] for _ in range(D)]
for i in range(1, D+1):
    acc[i-1].append(0)
    for j in range(i, H*W+1-D, D):
        x,y = d[j]
        a,b = d[j+D]
        #print("po:",j, j+D)
        acc[i-1].append(acc[i-1][-1]+abs(a-x)+abs(b-y))
    
Q = int(input())
for _ in range(Q):
    l, r = map(int,input().split())
    print(acc[(l-1)%D][(r-1)//D]-acc[(l-1)%D][(l-1)//D])


Measured memory_bytes: 32120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in insert
#define mp make_pair
#define F first
#define pb push_back
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll exp(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x); x=(x*x); y/=2; } return res;}

int main(){
    ll n,k; cin>>n>>k;
    ll count=0;
    while(n){
        n/=k;
        count++;
    }
    cout<<count;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

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

        Node nodes[] = new Node[n];
        for (int i=0; i<n; i++) nodes[i] = new Node();
        for (int i=0; i<n-1; i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            nodes[a].neighbors.add(nodes[b]);
            nodes[b].neighbors.add(nodes[a]);
        }

        for (int i=0; i<q; i++){
            int p = sc.nextInt()-1;
            nodes[p].offset += sc.nextInt();
        }

        dfs(null, nodes[0], 0);
        StringBuilder sb = new StringBuilder();
        for (int i=0; i<n; i++){
            sb.append(nodes[i].counter).append(" ");
        }
        System.out.println(sb.toString());


    }

    private static void dfs(Node parent, Node node, int sum){
        sum += node.offset;
        node.counter = sum;
        for (Node n: node.neighbors){
            if (n != parent){
                dfs(node, n, sum);
            }
        }
    }


    private static class Node{
        private List<Node> neighbors = new ArrayList<>();
        private int offset;
        private int counter;
    }
}

Measured memory_bytes: 207332
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdin = new Scanner(System.in);
		String readNum = stdin.nextLine();
		String[] twoNum = readNum.trim().split("\\s+");
		int a = Integer.parseInt(twoNum[0]);
		int b = Integer.parseInt(twoNum[1]);
		int c = Integer.parseInt(twoNum[2]);
		if ((a >= 0 && a <= 100) && (b >= 0 && b <= 100) && (c >= 0 && c <= 100)) {
			if (a < b && b < c) {
				System.out.println("Yes");
			} else  {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 26236