akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
#define mo 1000000007
#define LL long long
struct Edge{
	int next,to;
}edge[maxn*2];
int fi[maxn],size[maxn],n,se,Pow[maxn];LL inv,ans;
inline void add_edge(int u,int v){edge[++se].next=fi[u],edge[se].to=v,fi[u]=se;}
inline void add(int u,int v){add_edge(u,v),add_edge(v,u);}
LL power(LL a,int b){
	LL ans=1;
	while(b){
		if(b&1)ans=ans*a%mo;
		a=a*a%mo,b>>=1;
	}
	return ans;
}
void dfs(int x,int fa){
	size[x]=1;
	LL w=1,w1=0;
	for(int i=fi[x];i;i=edge[i].next){
		int v=edge[i].to;if(v==fa)continue;
		dfs(v,x),size[x]+=size[v];
		(w-=inv*Pow[size[v]])%=mo,w1++;
	}
	(w-=inv*Pow[n-size[x]])%=mo;
	(w+=inv*w1+mo)%=mo;
	ans+=w*power(2,mo-2)%mo;
}
int main(){
	int u,v;scanf("%d",&n);
	Pow[0]=1;
	for(int i=1;i<n;i++)scanf("%d%d",&u,&v),add(u,v),Pow[i]=2ll*Pow[i-1]%mo;
	inv=power(Pow[n-1],mo-2);
	dfs(1,0);
	printf("%d",ans%mo);
	return 0;
}

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

using namespace std;

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

	int d,n; cin >> d >> n;

	int ans = 1;
	int n2 = n;

	while(n%100 == 0){
		n2++;
		n /= 100;
	}

	for (int i = 0;i < d;i++){
		ans *= 100;
	}	

	cout << ans * n2 << endl;

	return 0;

}


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

int main(){
	int n;
	string a;
	int r=0;
	int l = 0;
	int before;
	bool flag = true;

	cin >> n;

	cin >> a;
	string s = a;

	
		
	while(1){
		before = s.length();
		for(int i = 0;i < s.length()-1;++i){
			
			if(s[i] == '(' && s[i+1] == ')'){
				s.erase(s.begin()+i+1);
				s.erase(s.begin() + i);
				break;
			}
		}
	
		if(s.length() == 0 || before == s.length()){
		if(s.length() == 0)
			flag = false;
			break;
		}
	}
	



	if(flag){
		for(int i = 0; i < s.length();++i){
			if(s[i] == ')')
				++r;
			else
				++l;
		}
		for(int i = 0;i < r;++i){
			cout << '(';
		}

		cout << a;

		for(int i = 0;i < l;++i){
			cout << ')';
		}

		cout << endl;
		return 0;

	}
	else{
		cout << a <<endl;
		return 0;
	}
}

Measured memory_bytes: 256
from fractions import gcd
lim=10**9+7
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return int(x)


n=int(input())
A=[int(i) for i in input().split()]
A_inv = [pow(a,lim-2,lim) for a in A]

Z = A[0]
k=1
for i in range(1, n):
    Z = Z // gcd(Z, A[i]) * A[i]
ans=0

Z=Z % lim
for i in range(n):
    ans = ( ans + Z*A_inv[i] ) % lim
print(ans)

Measured memory_bytes: 69276
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------
// [gcd]
template<class T> T gcd(T a,T b)
{if (a < b) swap(a,b);return b ? gcd(b, a % b) : a;}
template<class T> T lcm(const T a, const T b)
{return (a * b / gcd(a, b));}
void Main(){
  ll n;
  vl a(5);
  cin>>n;
  cin>>a;
  auto m = min_element(rng(a));
  if(n>*m){
    cout<< 4+dup(n,*m)<<endl;
  }else{
    cout<<5<<endl;
  }
} int main(int argc,char** argv)
{fastio; myio; Main();}


Measured memory_bytes: 256
c_mod=1000000007
n,m = map(int,input().split())
 
a_list=[]
for i in range(m):
    a_list.append(int(input()))

fib=[0]*(n+1)
fib[0]=1
fib[1]=1
for i in range(2,n+1):
    fib[i]=fib[i-1]+fib[i-2]

def count(s,e):
    return fib[e-s]
 
c_mod=1000000007
start=0
end=0
ans=1
before=100000
for a in a_list:
    if abs(before-a)==1:
        print(0)
        exit()
    # 各部分の移動方法
    end=a-1
    ans=ans*count(start,end)%c_mod
    start=a+1
    before=a
if end<n:
    end=n
    ans=ans*count(start,end)%c_mod
print(ans)

Measured memory_bytes: 464048
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MAXN 81
#define FF (MAXN * 2 * MAXN + 100)
bitset<FF> bs[MAXN][MAXN];

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

	int n, m, i, j, k, x, xx, y, ans, r;
	cin >> n >> m;
	vector<vector<vector<int>>> c(n, vector<vector<int>>(m, vector<int>(2, 0)));
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) cin >> c[i][j][0];
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) cin >> c[i][j][1];
	}
	r = (n + m) * (MAXN);

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if (i + j == 0) {
				x = abs(c[i][j][0] - c[i][j][1]);
				bs[i][j][x] = 1;
			}

			if (i < n - 1) {
				y = c[i + 1][j][0] - c[i + 1][j][1];
				for (k = 0; k < r; k++) {
					if (bs[i][j][k]) {
						bs[i + 1][j][abs(k + y)] = 1;
						bs[i + 1][j][abs(k - y)] = 1;
					}
				}
			}

			if (j < m - 1) {
				y = c[i][j + 1][0] - c[i][j + 1][1];
				for (k = 0; k < r; k++) {
					if (bs[i][j][k]) {
						bs[i][j + 1][abs(k + y)] = 1;
						bs[i][j + 1][abs(k - y)] = 1;
					}
				}
			}
		}
	}

	for (i = 0; i < r; i++) {
		if (bs[n - 1][m - 1][i]) {
			ans = i;
			break;
		}
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 11136
#include <bits/stdc++.h>
template <long long mod>
class Combination
{
    std::vector<long long> fact, finv, inv;
public:
    Combination() {}
    Combination(int sz)
    {
        fact.resize(sz);
        finv.resize(sz);
        inv.resize(sz);
        fact[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            fact[i] = fact[i - 1] * i % mod;
        }
        inv[0] = 0;
        inv[1] = 1;
        for (int i = 2; i < sz; ++i)
        {
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        }
        finv[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    long long C(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return (fact[n] * finv[k] % mod) * finv[n - k] % mod;
    }
    long long P(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fact[n] * finv[n - k] % mod;
    }
    long long H(long long n, long long k)
    {
        return this->C(n + k - 1, k);
    }
    long long getfact(int i)
    {
        return fact[i];
    }
    long long getinv(int i)
    {
        return inv[i];
    }
    long long getfinv(int i)
    {
        return finv[i];
    }
};
template< typename T >
T mod_pow(T x, T n, const T &p) {
  if(x < 0) return 0;
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
const double eps = 1e-8;
const ll MOD = 998244353;
const ll INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(ll i=0;i<((ll)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll n, m, k; cin >> n >> m >> k;
  if(m == 1 && k == n - 1) {
    cout << 1 << endl;
    return 0;
  }
  Combination<MOD> comb(1000000);
  ll tmp = 0;
  ll po = mod_pow<ll>(m-1, n-1, MOD);
  for(ll i=0;i<(k+1);++i) {
    tmp += comb.C(n-1, i) * po % MOD;
    tmp %= MOD;
    po *= comb.getinv(m-1);
    po %= MOD;
  }
  cout << tmp * m % MOD << endl;
}


Measured memory_bytes: 26632
from operator import itemgetter
n,m=map(int,input().split())
a=[]
for i in range (n):
    x,y=map(int,input().split())
    a.append([y,x])

a=sorted(a,key=itemgetter(1))

co=0
for i in range (n):
    if(m>=a[i][0]):
        co+=(a[i][0]*a[i][1])
        m-=a[i][0]

    else:
        co+=(m*a[i][1])
        m=0
print(co)


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

#define ll long long
using namespace std;

void dfs(int vtx , vector<int>& dp , vector<vector<int>>& g,int par)
{
    dp[vtx] = 0;
   
    for(int x : g[vtx])
    {
        if(x == par)
          continue;
    
        if(dp[x] ==  -1)
          dfs(x , dp , g , vtx);

         dp[vtx] =  max(dp[x] + 1 , dp[vtx]);
    }

}
int main()
{
    
    int n,m;
    cin>>n>>m;
    
    vector<vector<int>>g(n+1);
    for(int i = 0 ; i<m ;i++)
    {
        int a,b;
        cin>>a>>b;

        g[a].push_back(b);
    }
   
    vector<int>dp(n+1 , -1);

    int omax = 0;
    for(int i = 1 ; i<= n ;i++)
    {

        if(dp[i] == -1)
        dfs(i , dp , g , -1);
    }
    
    for(int i = 1 ; i<= n; i++)
     omax = max(omax , dp[i]) ;

    cout<<omax<<endl;
}

Measured memory_bytes: 12404
/*
                IftekharMd.Shishir
                Dept. of Information and Communication Engineering
                University of Rajshahi
*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#define ll  long long
#define ull  unsigned long long
#define ld  long double
#define f(i,n)  for(i=0;i<n;i++)
#define F(i,n)  for(i=n-1;i>=0;i--)
#define fa(i,a,b)  for(i=a;i<=b;i++)
#define Fa(i,a,b)  for(i=a;i>=b;i--)
#define printArray(i,a,n)  f(i,n)cout<<a[i]<<" "; cout<<endl;
#define printSet(a)  for(auto setData:a) cout<<setData<<" ";cout<<endl;
#define printMap(a)  for(auto mapData:a) cout<<mapData.first<<" "<<mapData.second<<endl;
#define printVector(a)  for(auto vectorData:a)cout<<vectorData<<" ";cout<<endl;
#define printLinkedList()  temp=head;while(temp){cout<<temp->data<<" ";temp=temp->post;} cout<<endl;

#define pb(x)  push_back(x)
#define all(a)  a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()

#define bs  binary_search
#define lb  lower_bound
#define ub  upper_bound
#define mp  make_pair
#define TxtIO  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define TxtTest freopen("C:/Users/Iftekhar/Documents/what/input.txt", "r", stdin);
#define FastIO  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
#define TestCase  ll t;cin>>t;while(t--)
#define points(x)  fixed<<setprecision(x)
#define scd(a,x,y)  a/__gcd(x,y);
#define nl  cout<<endl;
#define done  return 0

const ld PI= 3.14159265358979323846264338327950288;  //2*acos(0.0);
const long long MOD= 1000000007;
const long long MAX = 32000;

// stringstream demo(str);  demo >> x;
// stringstream demo;  demo << x;  name=demo.str();

using namespace __gnu_pbds;
using namespace std;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main()
{
        FastIO;
        //TxtTest;
        ll n,i,a,b,cnt=0,bb=0;
        string s;
        cin>>n>>a>>b>>s;
        ll sum=a+b;
        for(auto ch:s){
                if(ch=='c') cout<<"No"<<endl;
                else if(ch == 'a' && cnt<sum){
                        cnt++;
                        cout<<"Yes"<<endl;
                }
                else if(ch == 'a' && cnt>=sum){
                        cout<<"No"<<endl;
                }
                else if(ch=='b' && cnt<sum && bb<b){
                        cnt++;
                        bb++;
                        cout<<"Yes"<<endl;
                }
                else{
                        cout<<"No"<<endl;
                }
        }
        done;
}

Measured memory_bytes: 3756
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int n;
	cin>>n;
	vi in(n);
	rep(i,n){
		int a,b;cin>>a>>b;
		in[i]=a-b;
	}
	rep(i,n-2)if(in[i]==in[i+1]&&in[i]==in[i+2]&&in[i]==0){
		yes;
		return 0;
	}
	no;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)

// #define M 360

#define M 100000


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(48);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  long long x[111], y[111];

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> x[i] >> y[i];

  double tp = -1.0, sp = -1.0;

  for (int t = 0; t < M; t ++) {
    double theta = 2 * M_PI / M * t, X = cos(theta), Y = sin(theta);

    double s = 0.0;

    for (int i = 0; i < N; i ++) {
      double det = x[i] * X + y[i] * Y;

      if (det > 0.0)
        s += det;
    }

    if (s > sp) {
      tp = t;
      sp = s;
    }
  }

  double theta = 2 * M_PI / M * tp, X = cos(theta), Y = sin(theta), xx = 0.0, yy = 0.0;

  for (int i = 0; i < N; i ++) {
    double det = x[i] * X + y[i] * Y;

    if (det > 0.0) {
      xx += x[i];
      yy += y[i];
    }
  }

  std::cout << sqrt(xx * xx + yy * yy) << std::endl;

  return 0;
}


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

using namespace std;

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

#define pb push_back
#define mp make_pair


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

        int ans[200000] = {};

        if(n == 2){
                if(x != n){
                        cout << "No";
                        return 0;
                }
        }

        if(x == 1 || x == 2 * n - 1){
                cout << "No";
                return 0;
        }
        vector<char> used(2 * n, false);

        if(x == 2 * n - 2){
                ans[n - 1] = x + 1;
                ans[n] = x;
                ans[n + 1] = x - 2;
                ans[n - 2] = x - 1;

                used[x + 1] = 1;
                used[x] = 1;
                used[x - 2] = 1;
                used[x - 1] = 1;
        }
        else{
                ans[n - 1] = x - 1;
                ans[n] = x;
                ans[n + 1] = x + 2;
                ans[n - 2] = x + 1;

                used[x - 1] = 1;
                used[x] = 1;
                used[x + 2] = 1;
                used[x + 1] = 1;
        }

        int pointer = 1;
        if(used[pointer]) pointer += 4;
        for(int i = 0; i < 2 * n - 1; i++){
                if(ans[i] == 0) ans[i] = pointer++;
                if(used[pointer]) pointer += 4;
        }

        cout << "Yes\n";
        for(int i = 0; i < 2 * n - 1; i++) cout << ans[i] << '\n';



        return 0;
}


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

int main(){
  int N, Y;
  cin >> N >> Y;
  int t10000 = -1;
  int t5000 = -1;
  int t1000 = -1;
  bool fnsh = false;
  for(int i=0; i<N+1;i++){
    if (i*10000 > Y) break;
    for(int j=0; j<N+1 - i;j++){
      if (i*10000+j*5000 > Y) break;
      int t1 = Y - i*10000 - j*5000;
      if (t1%1000 == 0 && t1/1000 == N - i - j){
        t10000 = i;
        t5000 = j;
        t1000 = t1/1000;
        fnsh = true;
        break;
      }
    }
    if (fnsh) break;
  }
  cout << t10000 << " " << t5000  << " " << t1000<< endl;
}

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

int main(){
  string str;
  uint32_t times; 
  cin >> str >> times;
  
  bool same_edge = false;
  if (*cbegin(str) == *(cend(str) - 1))
    same_edge = true;
  
  char head = str.at(0);
  uint8_t head_num = 1;
  bool head_chained = true;
  uint64_t count = 0;
  bool prev_replace = false;
  for (auto iter = cbegin(str) + 1, end = cend(str); iter != end; iter++){
    if (head_chained){
      if (head == *iter){
        head_num += 1;
      } else{
        head_chained = false;
      }
    }
    if (prev_replace){
      prev_replace = false;
    } else{
      if (*iter == *(iter - 1)){
        count += 1;
        prev_replace = true;
      }
    }
  }
  
  count *= times;
  if (!prev_replace && same_edge && (head_num % 2) == 1){
    if (head_num != str.size()){
      count += times - 1; 
    } else{
      count += times / 2;
    }
  }
  cout << count << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n,k;
  cin>>n>>k;
  puts(n%k==0 ? "0" : "1");
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

h, n = map(int, input().split())
ab = np.array(sys.stdin.read().split(), dtype=np.int64)
aaa = ab[0::2]
bbb = ab[1::2]

dp = np.zeros(10001, dtype=np.int64)
for i in range(1, h + 1):
    dp[i] = (dp[i - aaa] + bbb).min()
print(dp[h])


Measured memory_bytes: 14532
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

int main(void) {
    int n, x;
    cin >> n >> x;
    vector<int> m;
    int num = 0;
    REP(i, n) {
        int input;
        cin >> input;
        m.push_back(input);
        x -= input;
        num++;
    }

    int minimum = *min_element(m.begin(), m.end());
    num += x / minimum;

    cout << num << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    String s = scan.next();
    String t = scan.next();
    if(s.equals(t.substring(0, s.length()))){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }

}

Measured memory_bytes: 35684
N, M = list(map(int, input().split(" ")))
A = {int(input()) for _ in range(M)}

memo = [0] * (N + 1)
memo[0] = 1
memo[1] = 0 if 1 in A else 1

if N == 1:
    print(memo[1])
else:
    for i in range(2, N + 1):
        if i in A:
            continue
        memo[i] = (memo[i - 2] + memo[i - 1]) % 1000000007

    print(memo[N])


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> rows(H);
  for (int i = 0; i < H; i++) {
    cin >> rows.at(i);
  }
  for (int i = 0; i < W+2; i++) {
    cout << '#';
  }
  cout << endl;
  for (int i = 0; i < H; i++) {
    cout << '#' + rows.at(i) + '#' << endl;
  }
  for (int i = 0; i < W+2; i++) {
    cout << '#';
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
static const int MAX = 10;
vector<vector<int>> adj_mat(MAX, vector<int>(MAX, 0));
vector<int> permutation(MAX);
vector<bool> used(MAX, false);
int N, M, num=0;

void solve(int pos, int v){
    // printf("pos=%d node=%d ", pos, v);
    if(pos==N-1){
        // printf("return\n");
        num ++;
        return;
    }
    // printf("no\n");
    for(int i=0;i<N;i++){
        if(used[i]){
            continue;
        }else if(adj_mat[v][i]){
            used[i] = true;
            solve(pos+1, i);
            used[i] = false;
        }
    }

}

int main(){
    scanf("%d %d", &N, &M);
    int u, v;
    for(int i=0;i<M;i++){
        scanf("%d %d", &u, &v);
        adj_mat[u-1][v-1] = 1;
        adj_mat[v-1][u-1] = 1;
    }
    used[0] = true;

    solve(0, 0);

    printf("%d\n", num);

}


Measured memory_bytes: 256
from bisect import bisect_left
n,m = map(int, input().split())
py = []
l = [[] for _ in range(n+1)]
for _ in range(m):
  p,y = map(int, input().split())
  l[p].append(y)
  py.append((p,y))
  
for i in l: i.sort()

for p,y in py:
  s = str(p)
  t = str(bisect_left(l[p],y)+1)
  ans = "0"*(6-len(s))+s + "0"*(6-len(t))+t
  print(ans)

Measured memory_bytes: 32716
N,A,B = map(int,input().split())
list_N = list(range(1,N+1))
result = []
for i in range(N):
    cnt = 0
    tmp = 0
    tmp = str(list_N[i])
    tmp_len = len(tmp)
    for j in range(tmp_len):
            cnt += int(tmp[j])
    if A <= cnt and B >= cnt:
        result.append(tmp)    
    else:
        continue
print(sum(list(map(int,result))))


Measured memory_bytes: 4340
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
int n, k, ans;
vi in;
vvi G;

int dfs(int a){
    int t = inf;
    if(!G[a].size()){
        if(in[a])ans++;
        return 1;
    }
    rep(i,G[a].size()) t = min(t, dfs(G[a][i]));
    t++;
    if(t <= k && in[a]) ans++;
    return t;
}

int main(){
    cin >> n >> k;
    in = vi(n);
    G = vvi(n);
    rep(i, n){
        cin >> in[i];
        if(in[i]) G[in[i] - 1].push_back(i);
    }
    rep(i, n){
        if(!in[i]){
            ans++;
            dfs(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 13360
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    int x =0;
    for(int i=0;i<N;i++){
      int D =sc.nextInt();
      int E =sc.nextInt();
      if(D==E){x=x+1;}
      else{x=0;}
      if(x==3){System.out.println("Yes");System.exit(0);}
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 36108
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

int N;
int B[102];
u64 ret;

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


    cin >> N;

    B[0] = 100001;
    B[N] = 100001;
    rep(i, N - 1)
    {
        cin >> B[i + 1];
    }

    rep(i, N + 1)
    {
        ret += MIN(B[i], B[i + 1]);
    }

    cout << ret << "\n";

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    double a,b;cin>>a>>b;
    rep(i,1000000){
        int aa = floor(((double)i/100.0)*8);
        int bb= floor(((double)i/100.0)*10);
        if(aa==a&&bb==b){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

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

using namespace std;

const int mxn = 1e6;
int cnt[mxn + 11] = {0};
int f[mxn + 11];

int main(){
   // freopen("input.txt", "r", stdin);
   int n;
   scanf("%d", &n);
   f[1] = n;
   cnt[n] = 1;
   for (int i = 2; i; i++){
       if (f[i - 1] & 1)
            f[i] = f[i - 1] * 3 + 1;
       else
            f[i] = f[i - 1] / 2;
        cnt[f[i]]++;
        if (cnt[f[i]] > 1){
            printf("%d\n", i);
            break;
        }
   }
   return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

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

	int n, k; cin >> n >> k;
	vector<int> as(n); for (auto& a : as) cin >> a;

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

	int sum = 0;
	FOR_LT(i, 0, k) {
		sum += as[i];
	}
	cout << sum << endl;
	return 0;
}

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

#define int long long

int n, m;
int x[100010], y[100010];

vector<int> xx[100010], yy[100010];
set<int> xs[100010];
set<int> ys[100010];
class UnionFind{
    public:
        vector<int> tree;

        void init(){
            for(int i = 0;i < tree.size();i++){
                tree[i] = -1;
            }
            return;
        }

        UnionFind(int n){
            n++;
            tree.resize(n);
            init();
            return;
        }

        int root(int i){
            if(tree[i] < 0) return i;
            return tree[i] = root(tree[i]);
        }

        bool unite(int i, int j){
            i = root(i);
            j = root(j);
            if(i == j) return false;

            tree[i] += tree[j];
            tree[j] = i;
            return true;
        }

        int size(int i){
            return -tree[root(i)];
        }

        bool same(int i, int j){
            return root(i) == root(j);
        }
};

signed main(){
    cin >> n;

    for(int i = 0;i < n;i++){
        cin >> x[i] >> y[i];
        xx[x[i]].push_back(i);
        yy[y[i]].push_back(i);
    }


    UnionFind uf(n+10);

    for(int i = 0;i < 100010;i++){
        for(int j = 0;j < (int)xx[i].size()-1;j++){
            uf.unite(xx[i][j], xx[i][j+1]);
        }


        for(int j = 0;j < (int)yy[i].size()-1;j++){
            uf.unite(yy[i][j], yy[i][j+1]);
        }
    }


    for(int i = 0;i < n;i++){
        xs[uf.root(i)].insert(x[i]);
        ys[uf.root(i)].insert(y[i]);
    }

    int ans = 0;
    for(int i = 0;i < 100010;i++){
        ans += xs[i].size() * ys[i].size();
    }

    cout << ans-n << endl;

    return 0;
}

Measured memory_bytes: 24960
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
#include <queue>
#include <stack>
using namespace std;

int main(){
  string s; cin >> s;
  vector<char> out;
  for(const auto &c : s){
    if(c == '0') out.push_back('0');
    if(c == '1') out.push_back('1');
    if(c == 'B'){
      if(!out.empty()) out.pop_back();
    }
  }
  for(int i = 0; i < out.size(); i++) cout << out[i];
  cout << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("Os")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
int main()
{
    vok();
    int n;
    IN n;
    vll a(n), b(n);
    loop(i,0,n)
    {
        IN a[i]>>b[i];
        a[i]*=2;
        b[i]*=2;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll l=0, r=0;
    if(n%2==0)
    {
        l=a[n/2]+a[n/2-1];
        l/=2;
        r=b[n/2]+b[n/2-1];
        r/=2;
    }
    else
    {
        l=a[n/2];
        r=b[n/2];
    }
    ll range=r-l+1;
    if(n%2)
    {
        range/=2;
        range++;
    }
    OUT range<<endl
    return 0;
}

Measured memory_bytes: 6356
use std::io::stdin;

fn main() {

    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let vs: Vec<usize> = s.trim().split_whitespace().map(|token| token.parse().ok().unwrap()).collect();
    let (n, m) = (vs[0], vs[1]);

    let mut bridges:Vec<Vec<usize>> = vec![];
    for _ in 0..m {
        s = String::new();
        stdin().read_line(&mut s).ok();
        bridges.push(s.trim().split_whitespace().map(|token| token.parse().ok().unwrap()).collect());
    }

    let mut uni = UnionFind::new(n + 1);
    let maximum = n * (n - 1) / 2;
    let mut results: Vec<u64> = vec![maximum as u64; m + 1];
    for (i, bridge) in bridges.iter().skip(1).enumerate().rev() {
        let (left, right) = (bridge[0], bridge[1]);
        results[i] = results[i + 1];
        if !uni.same(left, right) {
            let (lsize, rsize) = (uni.size(left) as u64, uni.size(right) as u64);
            uni.unite(left, right);
            results[i] -= lsize * rsize;
        }
    }

    for i in results.iter().take(m) {
        println!("{}", i);
    }
}

struct UnionFind {
    parent: Vec<isize>
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: vec![-1; n]
        }
    }

    fn root(&mut self, i: usize) -> usize {
        let par = self.parent[i];
        if par < 0 {
            i
        } else {
            let res = self.root(par as usize);
            self.parent[i] = res as isize;
            res
        }
    }

    fn same(&mut self, l: usize, r: usize) -> bool {
        self.root(l) == self.root(r)
    }

    fn unite(&mut self, l:usize, r:usize) -> bool {
        if self.same(l, r) {
            return false;
        }
        let u = |s: &mut UnionFind, p, c| {
            let proot = s.root(p);
            let croot = s.root(c);
            s.parent[proot] += s.parent[croot];
            s.parent[croot] = p as isize;
        };
        if self.size(l) < self.size(r) {
            u(self, r, l);
            // let (l, r) = (r, l);
        } else {
            u(self, l, r);
        }
        true
    }

    fn size(&mut self, i: usize) -> usize {
        let r = self.root(i);
        -self.parent[r as usize] as usize
    }
}


Measured memory_bytes: 12792
using System;
using System.Linq;

namespace _0547
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x.Max() == 0) break;
                int[,] dpleft = new int[x[0],x[1]]; int[,] dpdown = new int[x[0],x[1]];
                dpleft[0,0] = 1; dpdown[0,0] = 1;
                for (int i = 0; i < x[0]; i++)
                {
                    for (int j = 0; j < x[1]; j++)
                    {
                        if (i == 0 && j == 0) continue;
                        else if (i == 0) dpleft[i,j] = 1;
                        else if (j == 0) dpdown[i,j] = 1;
                        else
                        {
                            dpleft[i,j] = (dpleft[i,j - 1] + dpdown[i - 1,j - 1]) % 100000;
                            dpdown[i,j] = (dpleft[i - 1,j - 1] + dpdown[i - 1,j]) % 100000;
                        }
                    }
                }
                Console.WriteLine((dpleft[x[0] - 1,x[1] - 1] + dpdown[x[0] - 1,x[1] - 1]) % 100000);
            }
        }
    }
}


Measured memory_bytes: 9528
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,h;
  cin>>a>>b>>h;
  cout<<(a+b)*h/2;
}

Measured memory_bytes: 256
module Color
  WHITE = 0
  GRAY = 1
  BLACK = 2
end

def dijkstra(s)
  d = Array.new($n, Float::INFINITY)
  color = Array.new($n, Color::WHITE)
  
  d[s] = 0

  while true
    # puts d.join(' ')
    mincost = Float::INFINITY
    u = nil
    $n.times do |i|
      if color[i] != Color::BLACK && d[i] < mincost
        mincost = d[i]
        u = i
      end
    end

    if mincost == Float::INFINITY
      break
    end

    color[u] = Color::BLACK

    $n.times do |v|
      if color[v] != Color::BLACK && $m[u][v]
        if d[u] + $m[u][v] < d[v]
          d[v] = d[u] + $m[u][v]
          color[v] = Color::GRAY
        end
      end
    end
  end
  d
end

$n = gets.to_i
$m = Array.new($n) { Array.new($n) }
$n.times do |i|
  u, k, *arr = gets.split.map(&:to_i)
  arr.each_slice(2) do |v, c|
    $m[u][v] = c
  end
end
# puts "====="
# $m.each do |k|
#   puts k.join(' ')
# end
# puts "====="

d = dijkstra(0)
d.each_with_index do | v, i |
  puts "#{i} #{v}"
end



Measured memory_bytes: 7112
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> a(N * 2 - 1);
		for(int i = 0; i < N * 2 - 1; ++ i)
			scanf("%d", &a[i]);
		int lo = 1, up = N * 2 - 1;
		while(up - lo > 0) {
			int mid = (lo + up + 1) / 2;
			vector<bool> v(a.size()), nv;
			rep(i, N * 2 - 1)
				v[i] = a[i] >= mid;
			bool ans = v[0];
			for(int k = 0; k <= N - 2; ++ k) {
				if(v[N - 2 - k] == v[N - 1 - k]) {
					ans = v[N - 2 - k];
					break;
				}
				if(v[N - 1 + k] == v[N + k]) {
					ans = v[N - 1 + k];
					break;
				}
			}
			if(ans)
				lo = mid;
			else
				up = mid - 1;
		}
		printf("%d\n", lo);
	}
	return 0;
}


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

struct Node
{
    int x, p;
};
bool cmp(Node a, Node b)
{
   return  a.x < b.x;
}
int main()
{   
 	Node a[100005], b[100005];
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].x;
        a[i].p = i;
    }
    
    sort(a+1,a+n+1,cmp); //默认降序，cmp改为升序 
    
	int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if( abs(a[i].p-i) % 2 != 0) ans++;
    }
    
    cout << ans/2 << endl;
    
    return 0;
}

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

result = 0
has_odd = False
for a_i in a:
    if (a_i % 2) != 0:
        has_odd = True
while not has_odd:
    for i in range(n):
        a[i] //= 2
        if (a[i] % 2) != 0:
            has_odd = True

    result += 1

print(result)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N = 55, MOD = 1e9 + 7;
int dp[N][3][3];
char s[2][N];
void upd(int &x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}
int main() {
	int n;
	scanf("%d", &n);
	scanf("%s", s[0] + 1);
	scanf("%s", s[1] + 1);
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; ++ i) {
		for (int x = 0; x < 3; ++ x) {
			for (int y = 0; y < 3; ++ y) {
				for (int a = 0; a < 3; ++ a) {
					for (int b = 0; b < 3; ++ b) {
						if ((s[0][i] != s[1][i]) != (a != b)) continue;
						if (i > 1 && (s[0][i] != s[0][i - 1]) != (a != x)) continue;
						if (i > 1 && (s[1][i] != s[1][i - 1]) != (b != y)) continue;
						upd(dp[i][a][b], dp[i - 1][x][y]);
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 3; ++ i) {
		for (int j = 0; j < 3; ++ j) {
			upd(ans, dp[n][i][j]);
		}
	}
	printf("%d\n", ans);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    vector<int> v(5);
    REP(i,5){
        cin>>v[i];
    }
    REP(i,5){
        if(v[i]==0)cout<<i+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> ac(n, 0), wa(n, 0);
    rep(i, m){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC") ac[p]++;
        if(s == "WA" && ac[p] == 0) wa[p]++;
    }

    int corAns = 0, penalty = 0;
    rep(i, n){
        if(ac[i] != 0){
            corAns++;
            penalty += wa[i];
        }
    }
    printf("%d %d\n", corAns, penalty);
}

Measured memory_bytes: 1024
import std.stdio, std.math, std.conv, std.array, std.string, std.algorithm;

void main() {
    string str;
    while((str = readln()).length != 0) {
        int[] ax = map!(to!int)(str.chomp.split).array;
        int[] bx = map!(to!int)(readln().chomp.split).array;
        int intersect_num = 0;
        foreach(a ; ax) {
            foreach(b ; bx) {
                if (a == b) { ++intersect_num; }   
            }
        }
        int hit = 0;
        for (uint i = 0; i < 4; ++i) {
            if (ax[i] == bx[i]) { ++hit; }
        }
        int blow = intersect_num - hit;
        writef("%d %d\n", hit, blow);
    }
}

Measured memory_bytes: 1068
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();

    println!("{}", (a*b)-(a+b-1));
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define vec_all(vec) vec.begin(), vec.end()

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

    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    ll price_sum;
    price_sum = accumulate(vec_all(a), 0LL);

    vector<int> discounts;
    rep(i, n) {
        int tmp = a[i];
        while (tmp > 0) {
            int half = tmp / 2;
            if (tmp % 2 == 0) {
                discounts.push_back(half);
            } else {
                discounts.push_back(half + 1);
            }

            tmp = half;
        }
    }

    if (discounts.size() < m) {
        cout << 0 << endl;
        return 0;
    }

    sort(vec_all(discounts));
    reverse(vec_all(discounts));

    ll sum = 0;
    rep(i, m) {
        sum += discounts[i];
    }

    cout << price_sum - sum << endl;

    return 0;
}

Measured memory_bytes: 18920
const N=parse(Int,readline())
const M=length(readline())-1
const O=10^9+7
function f(D)
	[(D[i>0?i:1]*(i>0?2:1)+(i<N?D[i+2]:0))%O for i=0:N]
end
function main()
	D=zeros(Int,N+1)
	D[1]=1
	for _=1:N
		D=f(D)
	end
	println(D[M+1]*invmod(powermod(2,M,O),O)%O)
end
main()


Measured memory_bytes: 173696
import java.util.Scanner;

/**
 *
 * @author k17075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int i = 0;
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        for (int j = x; j <= y; j++) {
            if ((z % j) == 0) {
                i++;
            }
        }
        System.out.println(i);
    }
}


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


Measured memory_bytes: 2032
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
invtwo = pow(2, mod-2, mod)
s = sum(a) % mod
ans = 0
for x in a:
  ans += (s-x) * x
  ans %= mod
print((ans * invtwo) % mod)

Measured memory_bytes: 31444
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, cls[501][501];

int main() {
  cin >> n;
  for (i64 b = 0; b <= 10; ++b) {
    for (i64 i = 1; i <= n - 1; ++i) {
      for (i64 j = i + 1; j <= n; ++j) {
        if (((i >> b) & 1) != ((j >> b) & 1) && cls[i][j] == 0) 
          cls[i][j] = b + 1;
      }
    }
  }
  for (i64 i = 1; i <= n - 1; ++i) {
    for (i64 j = i + 1; j <= n; ++j) {
      cout << cls[i][j] << ' ';
    }
    cout << '\n';
  }
  return 0;
}



Measured memory_bytes: 2432
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	map<string, int> m;
	int q;
	cin >> q;
	while(q--){
		string t, p;
		cin >> t >> p;
		if(t == "insert")
			m[p]++;
		else {
			if(m[p])puts("yes");
			else puts("no");
		}
	}
	return 0;
}



Measured memory_bytes: 47472