akhauriyash/Code-Regression huggingface dataset:
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll a[100005];

int main()
{
  ll n, ans = 1, cnt = 0;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
    scanf("%lld", a + i);
  sortdown(a, n);
  for (int i = 0; i < n; i++)
  {
    if (a[i] == a[i + 1])
    {
      ans *= a[i];
      i++;
      cnt++;
    }
    if (cnt >= 2)
      break;
  }
  printf("%lld\n", ans == 1 ? 0 : ans);
  return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int INF = 1000000007;
    int MAX = 1000100;

    vector<int> pollock;
    vector<int> dp(MAX, INF);
    vector<int> oddDp(MAX, INF);
    for (int i = 1; i <= int(pow(6 * MAX, 1.0 / 3.0)); i++) {
        pollock.push_back(i * (i + 1) * (i + 2) / 6);
    }
    dp[0] = 0;
    oddDp[0] = 0;
    for (int i = 0; i <= MAX; i++) {
        for (int j = 0; j < pollock.size(); j++) {
            if (i + pollock[j] > MAX) continue;
            dp[i + pollock[j]] = min(dp[i] + 1, dp[i + pollock[j]]);
            if (pollock[j] % 2 == 1) {
                oddDp[i + pollock[j]] = min(oddDp[i] + 1, oddDp[i + pollock[j]]);
            }
        }
    }
    while (1) {
        int n;
        cin >> n;
        if (!n) break;
        cout << dp[n] << " " << oddDp[n] << endl;
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int x;
	cin >> x;
	int res = 0;
	res += (x / 500) * 1000;
	x %= 500;
	res += (x / 5) * 5;
	cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <math.h>

int main(void) {
	double a,b,c,d,e,f,x,y;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF){
	x = (c*e-b*f)/(a*e-b*d);
	y = (a*f-c*d)/(a*e-b*d);
	if (x == -0) x=0;
	if (y == -0) y=0;
	printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 652
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        boolean[] ans = new boolean[N];
        Unionfind uf = new Unionfind(N);
        
        for(int i = 0; i < M; i++){
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            int z = sc.nextInt();
            uf.unite(x, y);
        }
        
        long count = 0;
        for(int i = 0; i < N; i++){
            if( !ans[uf.root(i)] ){
                ans[uf.root(i)] = true;
                count++;
            }
        }
        
        System.out.println(count);
        
    }
    
    static class Unionfind{
        int[] parent;
        
        public Unionfind(int n){
            this.parent = new int[n];
            for(int i = 0; i < n; i++){
                parent[i] = i;
            }
        }
        
        public int root(int t){
            
            if ( parent[t] == t ){
                return t;
            } else {
                return parent[t] = root(parent[t]);
            }
        }
        
        public void unite(int x, int y){
            if ( isSame(x, y) ) return;
            
            int xroot = root(x);
            int yroot = root(y);
            parent[yroot] = xroot;
        }
        
        public boolean isSame(int x, int y){
            return root(x) == root(y);
        }
    }
}


Measured memory_bytes: 90296
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	
	string s;
	cin >> s;
	
	long long int a = 0;
	long long int ans = 0;

	for (long long int i = 0; i < s.size(); i++) {
		if (s[i] == 'W') {
			ans += i - a;
			a++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
//define
#define int long long
#define vint vector<int>
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define pb() push_back()
#define mod 100000007
#define elif else if
#define str string
//main
signed main(){
  int N,M,O,Q,count=0,count2=0,count3=0;
  double D=0;
  int c='A'-'a';
  //char C;
  str S,T;
  cin>>N;
  vint A(N);
  rep(0,N)cin>>A[i];
  while(1){
    REP(0,N){
      if(A[j]%2==0)count++;
    }
    if(count==N){
      REP(0,N){
        A[j]/=2;
        count2++;
      }
    }
    else break;
    count=0;
  }
  cout<<count2/N<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k;
  string s;
  cin>>k>>s;
  if(s.size()<=k){cout<<s<<endl;}
 else {
    for (int i=0;i<k;i++){
      cout<<s.at(i);
    }
    cout<<"..."<<endl;}
}

Measured memory_bytes: 3576
import math
k = int(input())
if k == 3:
    print("2 5 63")
elif k == 4:
    print("3 9 2 4")
elif k == 6:
    print("3 9 2 4 8 10")
elif k <= 15002:
    prints = set([3, 9]) 
    k -= 2
    for i in range(int(math.ceil(k / 3))):
        prints.add(i*6+2)
        prints.add(i*6+4)
        prints.add(i*6+6)
    if 3 - k % 3 == 1:
        prints.remove(6)
    if 3 - k % 3 == 2:
        prints.remove(6)
        prints.remove(12)
    print(" ".join([str(item) for item in prints]))
else:
    prints = set() 
    for i in range(5000):
        prints.add(i*6+2)
        prints.add(i*6+4)
        prints.add(i*6+6)
    k -= 15000
    for i in range(int(math.ceil(k / 2))):
        prints.add(i*12+3)
        prints.add(i*12+9)
    if 2 - k % 2 == 1:
        prints.remove(6)
    print(" ".join([str(item) for item in prints]))

Measured memory_bytes: 5488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
 int A,B,C,X;
 cin>>A>>B>>C>>X;
 int ans=0;
 rep(i,A+1){
     rep(j,B+1){
         rep(k,C+1){
             if(i*500+j*100+k*50==X){
             ans++;
             }
         }  
     }
 }
 cout<<ans<<endl;
}




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

using namespace std;

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);

	int x, y, z;
	cin >> x >> y >> z;
	cout << z << ' ' << x << ' ' << y << ' ' << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int a,b,c,temp ;

scanf("%d %d %d",&a,&b,&c) ;

if(a>b){
temp=a ;
a=b;
b=temp;
}

if(b>c){
temp=b ;
b=c;
c=temp;
}

if(a>b){
temp=a ;
a=b;
b=temp;
}

printf("%d %d %d\n",a,b,c) ;

return 0 ;

}

Measured memory_bytes: 596
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define eps 1e-8
//#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
//typedef long double ld;
typedef pair<int,int>pii;
//const ll mod= 998244353;
//long double PI = acosl(-1);
//const ll infl = 1e15;
const int inf = 2e9;
const int nmax = 1e5+5;
//const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

vector<int>g[nmax];
int outdeg[nmax];
vector<pii>ans;

int vis[nmax];

void dfs(int u, int p=0){
    vis[u] = 1;
    for(int v : g[u]) if(v!=p){
        if(vis[v]==1){
            ans.push_back({u, v});
            outdeg[u]++;
        }
        else if(!vis[v]) dfs(v, u);
    }
    if(p){
        if(outdeg[u]%2==0){
            ans.push_back({p, u});
            outdeg[p]++;
        }
        else ans.push_back({u, p}), outdeg[u]++;
    }
    vis[u] = 2;
}

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

    int n,m;
    cin>>n>>m;
    for(int i=1; i<=m; i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    if(m%2) cout<<"-1", exit(0);
    dfs(1);
    for(pii z : ans)
        cout<<z.first<<" "<<z.second<<"\n";
}


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

int main(){
  string S,T;
  cin >> S >> T;
  int ls=S.size();
  int lt=T.size();
  for (int i=ls-lt;i>=0;i--){
    bool f=true;
    for (int j=0;j<lt;j++){
      if(S[i+j]!=T[j] and S[i+j]!='?') f=false;
    }
    if(f){
      repeat(k,ls){
        S[k]=S[k]=='?'?'a':S[k];
        if (k>=i and k<i+lt) S[k]=T[k-i];
      }
      cout << S << "\n";
      return 0;
    }
  }
  cout << "UNRESTORABLE" << "\n";
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int cnt = 0;
    ll ans = 1;
    while (n--) {
        int x;
        cin >> x;
        if (x >= 2 * cnt + 1) ++cnt;
        else ans = ans * (cnt + 1) % MOD;
    }
    fore(i, 1, cnt) ans = ans * i % MOD;
    cout << ans << '\n';
}


Measured memory_bytes: 892
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    ll N, X;
    cin >> N >> X;

    pair<ll, ll> c[N + 1];
    c[0] = make_pair(1, 0);
    FOR(i, 1, N + 1) {
        ll p = 2 * c[i - 1].first + 1;
        ll b = 2 * c[i - 1].second + 2;
        c[i] = make_pair(p, b);
    }

    ll ans = 0;
    ll cur = N;
    ll res = X;
    while (cur >= 0) {
        if (cur == 0) {
            ans += res;
            break;
        }
        if (res == 0) break;
        if (res == 1) break;
        if (res == c[cur].first + c[cur].second) {
            ans += c[cur].first;
            break;
        }
        if (res == 1 + c[cur - 1].first + c[cur - 1].second + 1) {
            ans = ans + c[cur - 1].first + 1;
            break;
        }
        if (res < 1 + c[cur - 1].first + c[cur - 1].second + 1) {
            res = res - 1;
            cur--;
        }
        else {
            ans = ans + c[cur - 1].first + 1;
            res = res - 1 - c[cur - 1].first - c[cur - 1].second - 1;
            cur--;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  string s;
	      	  cin >> s;

	      	  int n=s.size(),ans=0;
	      	  if('A'==s[0]) ans++;
	      	  REP(i,n-1){
	      		  if(s[i]>=s[i+1]) ans++;
	      	  }

	      	  cout << ans << endl;

	          return 0;
}

Measured memory_bytes: 3172
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>

using namespace std;
long a[251];
int main(){
	int H; scanf("%d",&H);
	for (int i = 1; i <= H; ++i) scanf("%ld",&a[i]);
	for (int i = 1; i <= H; ++i){
		cout << "node " << i << ": key = " << a[i] << ", ";
		int tmp = i / 2;
		if (tmp >=1 ) cout << "parent key = " << a[tmp] << ", ";
		tmp = 2 * i;
		if (tmp <= H)	cout << "left key = " << a[tmp] << ", ";
		tmp = 2 * i + 1;
		if (tmp <= H) cout << "right key = " << a[tmp] << ", ";
		cout << '\n';
	}
}

Measured memory_bytes: 1204
#include<iostream>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long int li;

int main(){
  set<int> s;
  rep(i,3){
    int n; cin >>n;
    s.insert(n);
  }
  printf("%s",(s.size()==2)?"Yes":"No");

}


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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string x;
    cin >> x;
    if(x == "Y"){
      cout << "Four" << endl;
      break;
    }
    else if(i == N - 1){
      cout << "Three" << endl;
    }
  }  
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;


int main() {
  int n;
  cin >> n;
  if (n % 10 == 3) {
    cout << "bon" << endl;
  }
  else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}



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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

struct uf_tree
{
    vector<ll> par, rank;
    uf_tree(ll n) : par(n), rank(n)
    {
        for (ll i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 1;
        }
    }

    ll find(ll x)
    {
        if (x == par[x])
            return x;
        return par[x] = find(par[x]);
    }

    void unite(ll x, ll y)
    {
        x = find(x);
        y = find(y);

        if (x == y)
            return;

        if (rank[x] < rank[y])
            swap(x, y);
        par[y] = x;
        rank[x] += rank[y];
    }

    bool same(ll x, ll y)
    {
        return find(x) == find(y);
    }

    ll size(ll x)
    {
        return rank[par[x]];
    }
};

int main()
{

    ll n, m;
    cin >> n >> m;
    uf_tree uf(n);

    ll ans[m + 1];

    ans[m] = n * (n - 1) / 2;

    ll a[m], b[m];
    rep(i, m) cin >> a[i] >> b[i];
    for (int i = m - 1; i >= 0; i--)
    {
        a[i]--, b[i]--;
        if (uf.same(a[i], b[i]))
            ans[i] = ans[i + 1];
        else
        {
            ans[i] = ans[i + 1] - uf.size(a[i]) * uf.size(b[i]);
            uf.unite(a[i], b[i]);
        }
    }

    for (int i = 1; i <= m; i++)
        OP(ans[i]);

    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    pair<ll, bool> a[9];
    rep(i, 0, 9)
    {
        ll data;
        input(data);
        a[i] = pair<ll, bool>(data, false);
    }

    ll N;
    input(N);

    for (ll k = 0; k < N; k++)
    {
        ll data;
        input(data);
        rep(i, 0, 9)
        {
            if (a[i].first == data)
            {
                a[i].second = true;
                break;
            }
        }
    }

    rep(i, 0, 3)
    {
        if (a[3 * i + 0].second && a[3 * i + 1].second && a[3 * i + 2].second)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    rep(j, 0, 3)
    {
        if (a[j + 0].second && a[j + 3].second && a[j + 6].second)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    if ((a[0].second && a[4].second && a[8].second) || (a[2].second && a[4].second && a[6].second))
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int n,k,q;
    cin>>n>>k>>q;
    Vi correct_num(n,0);

    for(int i=0; i<q; i++){
        int a;
        cin>>a;
        correct_num[a-1]++;
    }

    for(int i=0; i<correct_num.size(); i++){
        if(k>q-correct_num[i]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);

        for (; ; ) {
            int m = sc.nextInt();
            int nMin = sc.nextInt();
            int nMax = sc.nextInt();

            if(m == 0 && nMin == 0 && nMax == 0){
                System.exit(0);
            }

            int n = nMin;
            int maxGap = 0;
            int  successMin = sc.nextInt();

            for (int i = 2; i <= m; i++) {
                int failMax = sc.nextInt();

                if(i >nMax+1){
                    continue;
                }

                if(i > nMin){
                    int gap = successMin - failMax;
                    if(gap >= maxGap){
                        maxGap = gap;
                        n = i-1;
                    }
                }

                successMin = failMax;

            }

            System.out.println(n);
        }

    }




}

Measured memory_bytes: 57240
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()

	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextInt64() int64 {
	sc.Scan()

	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextF64() float64 {
	sc.Scan()

	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}
func f(x int) int {
	if x == 1 {
		return 1
	}
	return f(x/2)*2 + 1
}

func main() {
	sc.Split(bufio.ScanWords)
	s := strings.Split(nextLine(), "")

	low := 0
	high := math.MaxInt32
	num := 753
	for i := 2; i < len(s); i++ {
		val, _ := strconv.Atoi(s[i-2] + s[i-1] + s[i])
		if num > val && val > low {
			low = val
		} else if num < val && val < high {
			high = val
		} else if num == val {
			fmt.Println(0)
			return
		}
	}
	if num-low > high-num {
		fmt.Println(high - num)
	} else {
		fmt.Println(num - low)
	}

}


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

int main(void){
    int n, a[100010], visit[100010];
    cin >> n;
    for(int i=0;i<n;++i){
      cin >> a[i];
      visit[i+1] = 0;
    }
    int next = 1, cnt=0;
    visit[next] = 1;
    while(true){
      ++cnt;
      next = a[next-1];
      if(next==2) break;
      if(visit[next]){
        cout << "-1" << endl;
        return 0;
      }else{
        visit[next] = 1;
      }
    }
    cout << cnt << endl;
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    int X,A,B;
    cin>>X>>A>>B;
    if(X==A){
        cout<<"0\n";
        return 0;
    }
    cout<<(X-A)%B<<'\n';
    return 0;
}

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

int main() {
  string s;
  int sz = 0, so = 0;
  cin >> s;
  for(int i = 0; i < s.length(); i++) {
    if(i % 2 == s.at(i) - '0')
      so++;
    else
      sz++;
  }
  cout << min(sz, so) << endl;
}

Measured memory_bytes: 512
import sys
def prime(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0] * ((h-1-i-x)/x+1)
    N[0]=2
    return filter(None,N)
PRIMES=prime(105000)
while 1:
    n = input()
    if n==0: break
    s = sum(PRIMES[:n])
    print s

Measured memory_bytes: 7716
from collections import deque


def main():
    n, m = map(int, input().split())
    g = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        g[a].append(b)
        g[b].append(a)
    max_val = 10 ** 9 + 7
    dist = [max_val for _ in range(n)]
    prev = [-1 for _ in range(n)]
    dist[0] = 0
    q = deque([0])
    cnt = 0
    while q:
        now = q.popleft()
        for next in g[now]:
            if prev[next] < 0:
                if prev[next] < 0:
                    q.append(next)
                    cnt += 1
                prev[next] = now + 1
                dist[next] = dist[now] + 1
    if cnt == n:
        print("Yes")
        for i in range(1, n):
            print(prev[i])
    else:
        print("No")


if __name__ == '__main__':
    main()



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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    string s;
    cin >> s;
    string ans="";
    for(int i = 0; i < 3; i++){
        if(s[i] == '1')ans+="9";
        else ans+="1";
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,a,b,first=0,second=0,third=0,i;
    cin >> n >> a >> b;
    int ar[n];
    for(i=0;i<n;i++) {
    	cin >> ar[i];
    	if(ar[i]<=a) first++;
    	else if(ar[i]>=a+1&&ar[i]<=b) second++;
    	else third++;
    }
    cout << min(first,min(second,third)) << "\n";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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; }
//#define int long long

void solve() {
	double a, b, c; cin >> a >> b >> c;
    double s = (a + b + c) / 2;
    double ans = sqrt(s * (s - a) * (s - b) * (s - c));
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(0);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int MAX_N = 1<<18;
const int N = MAX_N;
const int INF = 1LL<<55;
int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}

class RSQ2{
public:
  ll n;
  vector<ll> dat,td;
  //初期化
  RSQ2(){
    dat.resize(MAX_N*2 - 1,0);
    td.resize(MAX_N* - 12,0);
    n=MAX_N;
  };
  RSQ2(int n_){
    n=1;
    while(n<n_)n*=2; //要素数nを2のべき乗に
    dat.resize(n*2- 1, 0);
    td.resize(n*2 - 1, 0);
  }
  
  //[a,b)の区間にxを加算する,query(a,b,x);
  ll add(int a,int b,ll x,int k=0,int l=0,int r=-1){
    if(r==-1) r=n;
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b){
      dat[k]+=(r-l)*x; 
      td[k]+=x;
      return dat[k];
    }

    dat[k]+=(min(r,b)-max(l,a))*x;
    ll kl=k*2+1,kr=k*2+2,t=td[k]*(r-l)/2;
    dat[kl]+=t, dat[kr]+=t;
    td[kl]+=td[k], td[kr]+=td[k];
    td[k]=0;

    ll vl=add(a,b,x,k*2+1,l,(l+r)/2);
    ll vr=add(a,b,x,k*2+2,(l+r)/2,r);
    return vl+vr;
  }
  
  //[a,b)の総和を得る
  ll sum(int a,int b){return add(a,b,0);}
};

int A[N],n;


int solve(){
  RSQ2 T(n);
  for(int i=0;i<n;i++) T.add(i,i+1,A[i]);
  int sum  = 0;
  while(1){
    int psum = sum;
    for(int i=0;i<n;i++){
      int s = T.sum(i,i+1)/n;
      if(s == 0)continue;
      sum += s;
      T.add(0,n,s);
      T.add(i,i+1, -s*n - s);
    }
    if(psum == sum) return sum;
  }
}


signed main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];

  cout<<solve()<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	char str[1200];
	int i, j;
	int string_count;
	
	for(i = 0;i < 1200;i++){
		str[i] = '\0';
	}
	
	for(i = 0;i < 1200;i++){
		scanf("%c", &str[i]);
		if(str[i] == '\0'){
			break;
		}
	}
	
	for(i = 0;i < 1200;i++){
		if(str[i] >= 'A' && str[i] <= 'Z'){
			str[i + j] += 32;
		}
		else if(str[i] >= 'a' && str[i] <= 'z'){
			str[i] -= 32;
		}
		else;
	}
	
	for(i = 0;str[i] != '\0';i++){
		printf("%c", str[i]);
	}
	
	return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  char X;
  string T = "ABCDEFGHIJELMNOPQRSTUVWXYZ";
  int ans;
  cin >> X;
  
  ans = T.find(X);
  
  if(ans == -1){
    cout << "a" << endl;
  }
  else{
    cout << "A" << endl;
  }
}

Measured memory_bytes: 3528
#include <cstdio>
#include <iostream>

using namespace std;

int main(){
	float a,b,c,d,e,f;
	float x,y;
	while( cin>>a>>b>>c>>d>>e>>f ){
		x = (e*c-b*f)/(a*e-b*d);
		y = (a*f-d*c)/(a*e-b*d);
		if (x == 0) x = 0.000;
		if (y == 0) y = 0.000;
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;

	vl a(n);
	FOR(i,0,n) cin >> a[i];
	sort(all(a));
	
	a.resize(max(0LL,n-k));
	cout << accumulate(all(a),0LL) << endl;

}



Measured memory_bytes: 1792
#include <stdio.h>
 
int main(void)
{
  int m, f, r;
  int x;
  while(1) {
 
    scanf("%d %d %d", &m , &f , &r);
    x = m + f;
    if(m == -1 && f ==-1 && r == -1) {
      break;
    }
 
    if(m == -1 || f == -1) {
      printf("F\n");
    } else if(x >= 80) {
      printf("A\n");
    } else if (x >= 65) {
      printf("B\n");
    } else if(x >= 50) {
      printf("C\n");
    } else if ( x >=30) {
      if(r >= 50) {
    printf("C\n");
      } else {
    printf("D\n");
      }
    } else if (x < 30) {
      printf("F\n");

    }
  }
  return 0;
}


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

int main() {
  int N , A , B , c;
  c = 0;
  cin >> N >> A >> B;
  for (int i = 0; i< N ; i++){
    int x = (i+1)/10000%10 + (i+1)/1000%10 + (i+1)/100%10 + (i+1)/10%10 + (i+1)%10;
    if (A <= x && x <= B) c += (i+1);
  }
  cout << c << endl;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, M; cin >> N >> M;
  int count[N] = {};
  bool ok[N] = {};
  rep(i,M) {
    int p; string S; cin >> p >> S; p--;
    if (S=="AC") ok[p] = true;
    else if (!ok[p]) count[p]++;
  }

  int ac = 0, wa = 0;
  rep(i,N) if(ok[i]) { ac++; wa += count[i]; }
  cout << ac << " " << wa << endl;
  // cout << result << endl;
  return 0;
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  ll n, k, a, b, ans;
  cin >> n >> k;
  ll result[100001] = {0};
  rep(i, n){
    cin >> a >> b;
    result[a-1] += b;
  }
  rep(i, 100001){
    if (result[i] >= k) {
      ans = i;
      break;
    }else{
      k -= result[i];
    }
  }
  puts(ans+1)
}


Measured memory_bytes: 1024
#include<iostream>
#include<numeric>
#include<vector>
#include<limits>
 
std::vector<std::int64_t> a;
std::vector<std::vector<std::int64_t>> memo;
const auto nil = std::numeric_limits<std::int64_t>::min();
 
std::int64_t solve(int n,int k){
    if(memo[n][k-n/2] != nil){
        return memo[n][k-n/2];
    }
    std::int64_t r ;
    {
        if(n==0 || k==0){
            r = 0;
        }
        else if(n == 1){
            r = a[0];
        }
        else if(n%2==1 && k == (n/2+1)){
            r = solve(n-2,k-1) + a[n-1];
        }
        else{
            auto r1 = solve(n-2,k-1) + a[n-1];
            auto r2 = solve(n-1,k);
            r = std::max(r1,r2);
        }
    }
 
    memo[n][k-n/2] = r;
    return r;
}
 
int main(){
    int n;
 
    std::cin>>n;
    for(int i=0;i<n;++i)
    {
        int tmp;
        std::cin>>tmp;
        a.push_back(tmp);
    }
    for(int i=0;i<n+2;++i){
        memo.push_back(std::vector<std::int64_t>(3,nil) );
    }
 
    std::cout<<solve(n,n/2);
    
    
}

Measured memory_bytes: 20592
n, m = map(int, input().split())
l = [[0]*n for _ in range(m)]
for i in range(m):
  k, *s = map(int, input().split())
  for j in range(k):
    l[i][s[j]-1] = 1
p = list(map(int, input().split()))

ans = 0
str = '{:0'+str(n)+'b}'
for i in range(2**n):
  s = list(map(int, str.format(i)))
  b = True
  for j in range(m):
    if sum([x & y for x, y in zip(s, l[j])]) % 2 != p[j]:
      b = False
  if b:
    ans += 1

print(ans) 

Measured memory_bytes: 9228
#include<iostream>

using namespace std;

int main(){
    int a, b, c, k;
    a = 0; b = 0; c = 0; k = 0;
    cin >> a >> b >> c >> k;

    for(int i = 0; i < k; i++){
        if(a >= b && a >= c){
            a *= 2;
        }else if(b >= a && b >= c){
            b *= 2;
        }else if(c >= a && c >= b){ 
            c *= 2;
        }
    }

    cout << a + b + c << endl;

    return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    string str;
    
    for(int i = 0; i < n; i++){
        int ans = 0;
        set<string> aft;
        string temp1, temp2, flip1, flip2;
        vector<bool> ch;
        
        cin >> str;
        
        for(int j = 1; j < str.size(); j++){
            temp1 = str.substr(0, j);
            temp2 = str.substr(j);
            
            flip1.resize(temp1.size());
            flip2.resize(temp2.size());
            
            for(int k = 0; k < temp1.size(); k++){
                flip1[k] = temp1[temp1.size() - k - 1];
            }
            
            for(int l = 0; l < temp2.size(); l++){
                flip2[l] = temp2[temp2.size() - l - 1];
            }
            
            aft.insert(temp1 + temp2);
            aft.insert(temp2 + temp1);
            aft.insert(flip1 + temp2);
            aft.insert(temp2 + flip1);
            aft.insert(temp1 + flip2);
            aft.insert(flip2 + temp1);
            aft.insert(flip1 + flip2);
            aft.insert(flip2 + flip1);
        }
        
        cout << aft.size() << endl;
    }
    
    return 0;
}

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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    int cnt=0;
    cin >> s;
    for (int i = 0; i < 6 ; ++i) {
        cnt += s[i] -'0';
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
N,T=list(map(int,input().split()))
min_=10**9+1
max_=0
num=0
for x in map(int,input().split()):
    tmp=x-min_
    if x<min_:
        min_=x
    elif tmp>max_:
        max_=tmp
        num=1
    elif  tmp==max_:
        num+=1
print(num)
        

Measured memory_bytes: 11608
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 8264
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int sum = 1;
  for(int i = 1; i < n; i++) {
    if(s[i] != s[i-1]) sum++;
  }
  cout << sum << "\n";
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a,b;
  cin>>a>>b;
  cout<<a*b-a-b+1;
}

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

int main() {
  int N; cin >> N;
  vector<pair<long long, long long>> S(N);
  for (int i = 0; i < N; i++) {
    long long A, B; cin >> A >> B;
    S.at(i) = make_pair(A, B);
  }
  sort(S.begin(), S.end());
  cout << S.at(N-1).first + S.at(N-1).second << endl;
}

Measured memory_bytes: 1792
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;

int main (){
    int n,d;cin>>n>>d;
    vector<vector<int>>a(n,vector<int>(d));
    rep(i,0,n)rep(j,0,d)cin>>a[i][j];
    int ans=0;
    rep(i,0,n){
        rep(j,i+1,n){
            if(i==j)continue;
            double c=0;
            rep(k,0,d){
                c+=pow(a[i][k]-a[j][k],2);
            }
            if(fmod(sqrt(c),1)==0)ans++;
        }
    }
    cout << ans<< endl;
    return 0;
}

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

int countpaths(vector<vector<char>> &grid,int i,int j,vector<vector<int>> &dp){
    if(i >=0 && j >= 0 && i < grid.size() && j < grid[i].size()){
        if(i==grid.size()-1 && j==grid[i].size()-1){
            return 1;
        }
        if(grid[i][j]=='#'){
            return 0;
        }
        if(dp[i][j]!=-1){
            return dp[i][j];
        }
        dp[i][j] =  (((countpaths(grid,i+1,j,dp)%mod) + (countpaths(grid,i,j+1,dp   )%mod))%mod);

        return dp[i][j];
    }
    return 0;
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<char>> grid(n,vector<char>(m));
    vector<vector<int>> dp(n,vector<int>(m,-1));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>grid[i][j];
        }
    }

    cout<<countpaths(grid,0,0,dp)<<endl;



    return 0;
}


Measured memory_bytes: 8552
n,k,*a=`dd`.split.map &:to_i
a=(b=[0])+a
1.upto(a.size-1){|i|b[i]=b[i-1]+[0,a[i]].max;a[i]+=a[i-1]}
p k.upto(a.size-1).map{|i|b[-1]-(b[i]-b[i-k])+[a[i]-a[i-k],0].max}.max

Measured memory_bytes: 13820
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
string st;
int main()
{
cin>>st;
for(int i=0; i<st.size(); i++)
{
	if(st[i]=='C')
	{
		for(int j=i+1; j<st.size(); j++)
		{
			if(st[j]=='F')
			{
				cout<<"Yes";
				return 0;
			}
		}
	}
}
cout<<"No";
return 0;
}


Measured memory_bytes: 256
from collections import deque
import copy

N, M = map(int,input().split())
e_list = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int,input().split())
    e_list[a - 1].append(b - 1)
    e_list[b - 1].append(a - 1)

waiting = deque()
flag_s = [0]*N
start_point = 0
waiting.append([start_point, flag_s])
cnt = 0
while len(waiting) != 0:
    cur_node, flag = waiting.pop()
    flag = copy.deepcopy(flag)
    flag[cur_node] = 1
    if sum(flag) == N: cnt += 1
    for e in e_list[cur_node]:
        if flag[e] != 1:
            waiting.append([e, flag])

print(cnt)

Measured memory_bytes: 76300
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000009
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)

bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}


ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}


int main(){

    ll n;
    cin>>n;
    string s(n,'a'),q(n,'b'),so(n,'s'),qo(n,'2');
    rep(i,0,n,1){
        ll temp;
        cin>>temp;
        s[i]=(temp +'0');
        so[i]=s[i];
    }
    rep(i,0,n,1){
        ll temp;
        cin>>temp;
        q[i]=(temp+'0');
        qo[i]=q[i];
    }

    sort(s.begin(),s.end());
    sort(q.begin(),q.end());
    ll a=0,b=0;
    if(s==so)a=1;
    if(s==qo)b=1;
    ll i=1;
    while(next_permutation(s.begin(),s.end())){
          i++;

        if(s==so)a=i;
         if(s==qo)b=i;

    }


    cout<<abs(a-b)<<endl;
}


Measured memory_bytes: 81180
'use strict'

function main(input) {
  const inputList = input.split('\n');
  const s = inputList[0]
  const t = inputList[1]

  if (s.length+1 === t.length && s === t.slice(0, t.length-1)) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

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

Measured memory_bytes: 30124
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int h = scanner.nextInt();
		System.out.println(((a+b)*h)/2);
		scanner.close();
	}

}


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

int main(int argc, char *argv[]) {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> sn(n);
  for (int i = 0; i < k; ++i) {
    int d;
    std::cin >> d;
    for (int j = 0; j < d; ++j) {
      int a;
      std::cin >> a;
      ++sn.at(a - 1);
    }
  }

  int count = 0;
  for (auto &i : sn)
    if (i == 0)
      ++count;

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


Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(void){
    int N,cnt=0;
    string s;
    cin>>N>>s;
    FOR(i,1,N){
        if(s[i-1]!=s[i])cnt++;
    }
    cout<<cnt+1<<endl;
}


Measured memory_bytes: 512
N=int(input())
count=0
m=[]
s=input()
m.append(s)
for i in range(N-1):
    l=input()
    if l not in m and m[i][-1]==l[0]:
        count+=1
    m.append(l)
if count==N-1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
main :: IO ()
main = do
    [n, m] <- map read . words <$> getLine
    answer $ solve n m

type Answer = Int
answer :: Answer -> IO ()
answer = print

solve :: Int -> Int -> Answer
solve n m
  | n * 2 > m = m `div` 2
  | otherwise = n + (m - n * 2) `div` 4



Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0;

int main (){
    ll n;   cin >> n;
    string s ;      cin >> s;
    for(int i=0;i<1000;i++){
    int c[3] = {i / 100 , (i/10) % 10 ,i % 10};
    int f=0;
    for(int j=0;j<n;j++){
        if(c[f] == s.at(j)- '0') f++;
        if(f == 3)break;
    }
    if(f==3)cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

const double PI=acos(-1);

int main(){
    double a,b,theta;
    cin>>a>>b>>theta;

    double c,S,L,h;
    theta=theta*PI/180;

    c=sqrt(a*a+b*b-2*a*b*cos(theta));
    S=a*b*sin(theta)/2;
    L=a+b+c;
    h=b*sin(theta);
    
    cout<<fixed<<setprecision(10)<<S<<" "<<L<<" "<<h<<endl;
}



Measured memory_bytes: 3516
def main():
    line = input()
    s1 = []
    s2 = []
    sum = 0
    for i, s in enumerate(line):
        if s == "\\":
            # 谷の位置をスタックに積む
            s1.append(i)
        elif s == "/" and len(s1) > 0:
            # 山で対応する谷があるなら、面積に追加
            j = s1.pop()
            sum += i - j  # 谷から山の距離を水たまりの面積に追加
            # jより前に位置する水たまりの面積を追加
            a = i - j
            while len(s2) > 0 and s2[-1][0] > j:
                a += s2.pop()[1]
            # (水たまりの左端の位置, 水たまりの面積)のタプルをスタックに積む
            s2.append((j, a))

    print(sum)
    if len(s2) > 0:
        print(len(s2), end="")
        for x in s2:
            print(f" {x[1]}", end="")
        print()
    else:
        print(len(s2))


if __name__ == "__main__":
    main()



Measured memory_bytes: 6408