akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>

using namespace std;

// 2 4 8 15
//
//
int gcd(int a, int b)
{
	if(b == 0) return a;
	else return gcd(b, a % b);
}

int main()
{
	int n;

	cin >> n;

	vector<int> a(n);
	vector<int> l(n);
	vector<int> r(n);

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

	l[0] = a[0];
	for(int i = 1; i < n; ++i)
	{
		l[i] = gcd(a[i], l[i - 1]);
	}

	r[n - 1] = a[n - 1];
	for(int i = n - 2; i >= 0; --i)
	{
		r[i] = gcd(a[i], r[i + 1]);
	}
	
	//cout << l[2] << endl;
	//cout << r[3] << endl;

	int ans = 1;
	for(int i = 0; i < n; ++i)
	{
		if(i == 0) ans = max(ans, r[1]);
		else if(i == n - 1) ans = max(ans, l[n - 2]);
		else ans = max(ans, gcd(l[i - 1], r[i + 1]));
	}

	cout << ans << endl;

	return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    string N;
    cin >> N;
    
    if (N[0] == N[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;
typedef pair<int, int> ii;
// #define int long long int

inline void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}

signed main() {
    int N, K; cin >> N >> K;
    vector<int> V(N);
    for (int i = 0; i < N; i++) {
        int _v; cin >> _v;
        V[i] = _v;
    }

    int ans = 0;
    for (int p = 0; p <= K; p++) {
        for (int q = 0; q <= K - p; q++) {
            if (p + q > N) continue;

            int hand = 0;
            priority_queue<int, vector<int>, greater<int> > neg;
            for (int i = 0; i < p; i++) {
                int v = V[i];
                hand += v;
                if (v < 0) neg.push(v);
            }

            for (int i = 0; i < q; i++) {
                int v = V[(N - 1) - i];
                hand += v;
                if (v < 0) neg.push(v);
            }

            const int k = K - (p + q);
            for (int i = 0; i < k && !neg.empty(); i++) {
                int negV = neg.top(); neg.pop();
                hand -= negV;
            }
            ans = max(hand, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int n,m,k,a[20][20],sum[15],c[15],ans=0x3f3f3f3f,g;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<n;i++){
	scanf("%d",&c[i]);	
	for(int j=0;j<m;j++) scanf("%d",&a[i][j]); 
	}
	for(int i=1;i<(1<<n);i++){
	  memset(sum,0,sizeof(sum)); g=0;
	 for(int j=0;j<n;j++){
	  if(!(i&(1<<j))) continue;
	  for(int l=0;l<m;l++) sum[l]+=a[j][l];
	  g+=c[j];
	 }
	bool flag=0;
	for(int j=0;j<m;j++) {
	 if(sum[j]<k) {
	 	flag=1;
	 	break;
	 }
	}
	if(!flag) ans=min(ans,g);
	}
	printf("%d\n",ans==0x3f3f3f3f? -1:ans);
 } 

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
	bool ch[101000];
int main() {
	ll n;
	cin>>n;
	ch[0]=true;
	for(ll i=0;i<=100000;i++){
		if(ch[i]){
			for(ll j=0;j<=5;j++){
				ch[i+100+j]=true;
			}
		}
	}
	if(ch[n]){
		cout <<1;
	}
	else{
		cout << 0;
	}
	// your code goes here
	return 0;
}

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

#define max(a,b) ((a > b) ? (a) : (b))

typedef long long ll;

int main()
{
  ll n, a[200001];
  ll p = 0, ans = 0;
  
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(i == 0){
      if(a[i] != 0){
        cout << -1 << endl;
        return 0;
      }
    } else {
      if(a[i-1] + 1 < a[i]){
        cout << -1 << endl;
        return 0;
      }
    }
  }

  for(int i = 0; i < n-1; i++){
    if(a[i] + 1 == a[i+1]){
      ans++;
    } else {
      ans += a[i+1];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

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

	int N=in(),M=in();
	vvll C(N,vll(N,0));
	REP(i,M){
		int u=in()-1,v=in()-1;
		C[u][v]=1;
		C[v][u]=1;
	}
	vector<int> P(N-1);
	iota(ALL(P),1);
	ll A=0;
	do{
		int S=0;
		bool exist = true;
		REP(i,N-1){
			if(!C[S][P[i]]){
				exist = false;
				break;
			}
			S = P[i];
		}
		if(exist) A++;
	}while(next_permutation(ALL(P)));
	out(A);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll h,w ; cin >> h >> w;
    vector<ll> cnt(26,0);
    rep(i,h){
        string a; cin >> a;
        rep(j,w){
            ll x = a.at(j) - 'a';
            cnt.at(x)++;
        }
    }

    bool ok = true;
    ll cnt2 = 0 , cnt4 = 0;
    ll cnt2lim,cnt4lim;
    if(h%2 && w%2){
        cnt2lim = (h-1)/2 + (w-1)/2;
        cnt4lim = (h-1)*(w-1)/4;
    }else if(h%2){
        cnt2lim = w/2;
        cnt4lim = (h-1)*w/4;
    }else if(w%2){
        cnt2lim = h/2;
        cnt4lim = (w-1)*h/4;
    }else{
        cnt4lim = h*w/4;
        cnt2lim = 0;
    }

    rep(i,26){
        while(cnt.at(i)>=4){
            if(cnt4==cnt4lim) break;
            cnt.at(i)-=4;
            cnt4++;
            if(cnt4==cnt4lim) break;
        }           
        if(cnt4==cnt4lim) break; 
    }
    rep(i,26){
        while(cnt.at(i)>=2){
            if(cnt2==cnt2lim) break;
            cnt.at(i)-=2;
            cnt2++;
            if(cnt2==cnt2lim) break;
        }           
        if(cnt2==cnt2lim) break; 
    }
    if(cnt2!=cnt2lim || cnt4!=cnt4lim){
        ok = false;
    }

    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  int n;
  cin >> n;
  vector<ld> p(1, 1);
  for (int i = 0; i < n; ++i) {
    vector<ld> nx(p.size()+1);
    ld pi; cin >> pi;
    for (int from = 0; from < p.size(); ++from) {
      nx[from] += p[from] * (1-pi);
      nx[from+1] += p[from] * pi;
    }
    p.swap(nx);
  }
  ld ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i*2 > n) {
      ans += p[i];
    }
  }
  cout << ans << nl;

  return 0;
}



Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
ll from, to, cost;
bool operator<(const E &b) const { return cost < b.cost; }
bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
template<typename T>
void print_vec(vector<T>a) {
	for (int i = 0; i < a.size(); i++) {
		cout << (i == 0 ? "" : " ") << a[i];
	}
	cout << endl;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[20][20];
int dp[1 << 18];
int dp2[1 << 18];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < (1 << n); i++) {
		dp[i] = -Inf;
		if (i == 0) dp[i] = 0;
		for (int j = 0; j < n; j++) {
			if (i&(1 << j)) {
				int sum = 0;
				for (int z = 0; z < n; z++) {
					if (i&(1 << z)) {
						sum += a[z][j];
					}
				}
				dp[i] = max(dp[i], dp[i ^ (1 << j)] + sum);
			}
		}
	}
	for (int i = 0; i < (1 << n); i++) {
		for (int t = i; t > 0; t = (t - 1)&i) {
			dp[i] = max(dp[i], dp[t] + dp[i^t]);
		}
	}
	int ans = -Inf;
	for (int i = 0; i < (1 << n); i++) {
		ans = max(ans, dp[i] + dp[((1 << n) - 1) ^ i]);
	}
	cout << ans << endl;
}

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

int main() {
  
  int a , b;
  cin >> a >> b ;
  
  if (a*b%2==0 ){
  cout << "Even" << endl;
  }
 
  else {
  cout << "Odd" << endl;
  }

  }


                      
  

Measured memory_bytes: 256
#include <iostream>  
#include <cstdio>  
#include <algorithm>  
#include <set>  
#include <string>  
#include <cstring>  
#include <cmath>  
#include <map>  
#define N 505  
using namespace std;  
typedef long long ll;  
int c[505]; //到一个车站的花费时间  
int s[505]; //一个车站出发的等待时间  
int f[505];  //一个车站每f秒出发一个车  
int main()  
{  
    int a;  
    scanf("%d",&a);  
    for(int i=1;i<=a;i++)  
        scanf("%d%d%d",&c[i],&s[i],&f[i]);  
    for(int i=1;i<=a;i++){  
        int ans=0;  
        for(int j=i;j<a;j++){  
            if(ans<s[j])   //小于等待时间重新赋值  
                ans=s[j];  
            if(ans%f[j]!=0)    //是否处于间隔时间  
                ans=ans+f[j]-ans%f[j];  
            ans+=c[j];  
        }  
        printf("%d\n",ans);  
    }  
}  

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

int stack[100];
int top = 0;

int push(int n) {
    stack[top] = n;
    top++;
    return 0;
}

int pop(void) {
    top--;
    return stack[top];
}



int main(void) {
    char x;
    int y, tmp;

    while (scanf("%s", &x) == 1) {
        y = atoi(&x);
        if (y == 0) {
            tmp = pop();
            switch (x) {
            case '+':
                push(pop()+tmp);
                break;
            case '-':
                push(pop()-tmp);
                break;
            case '*':
                push(pop()*tmp);
            default:
                break;
            }
        } else {
            push(y);
        }
    }
    printf("%d\n", pop());

    return 0;
}


Measured memory_bytes: 2112
N = input().split()
n= int(N[0])
k = int(N[1])
o = [0 for _ in range(n)]
a = 0
for i in range(k):
    A= input()
    a = int(A)
    q = input().split()
    for j in range(a):
        o[int(q[j])-1] += 1

print(o.count(0))

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
using namespace std;

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

	int k,x;
	cin>>k>>x;

	if(k*500>=x){
		cout<<"Yes";
	}else{
		cout<<"No";
	}

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class State implements Comparable<State>{
  int cityId;
  int usedTicket;
  double cost;

  State(int cityId, int usedTicket, double cost){
    this.cityId = cityId;
    this.usedTicket = usedTicket;
    this.cost = cost;
  }

  public int compareTo(State st){
    if(this.cost < st.cost)
      return -1;
    if(this.cost == st.cost)
      return 0;
    return 1;
  }
}

class Edge{
  int from, to, cost;

  Edge(int from, int to, int cost){
    this.from = from;
    this.to = to;
    this.cost = cost;
  }
}

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

    while(true){
      int n = sc.nextInt();
      int m = sc.nextInt();
      int p = sc.nextInt();
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;

      if(n == 0) break;

      int[] t = new int[n];

      for(int i = 0; i < n; i++){
        t[i] = sc.nextInt();
      }

      ArrayList<ArrayList<Edge>> graph = new ArrayList<ArrayList<Edge>>();

      for(int i = 0; i < m; i++){
        graph.add(new ArrayList<Edge>());
      }

      for(int i = 0; i < p; i++){
        int x = sc.nextInt() - 1;
        int y = sc.nextInt() - 1;
        int z = sc.nextInt();

        graph.get(x).add(new Edge(x, y, z));
        graph.get(y).add(new Edge(y, x, z));
      }

      PriorityQueue<State> open = new PriorityQueue<State>();
      open.add(new State(a, 0, 0));
      boolean[][] closed = new boolean[m][1 << n];
      double ansCost = -1;

      while(!open.isEmpty()){
        State st = open.poll();

        if(closed[st.cityId][st.usedTicket]) continue;
        closed[st.cityId][st.usedTicket] = true;

        if(st.cityId == b){
          ansCost = st.cost;
          break;
        }

        for(int i = 0; i < n; i++){
          if((st.usedTicket & (1 << i)) != 0) continue;

          for(Edge edge : graph.get(st.cityId)){
            int nextUsedTicket = st.usedTicket | (1 << i);
            double nextCost = st.cost + (double)edge.cost / t[i];

            open.add(new State(edge.to, nextUsedTicket, nextCost));
          }
        }
      }

      if(ansCost == -1){
        System.out.println("Impossible");
      }
      else{
        System.out.printf("%.3f\n", ansCost);
      }
    }
  }
}

Measured memory_bytes: 99460
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=1000000007
l1=0
l2=0
for i in range(n):
  for j in range(n):
    
    if i!=j:
      
      if a[i]>a[j]:
        l1+=1
        
        if i<j:
          l2+=1

k=k%mod
print((l2*k+l1*k*(k-1)//2)%mod)

Measured memory_bytes: 3188
k = int(input())

m = 7
mm = set()

i = 1
while True:
    m = m % k
    if m == 0:
        print(i)
        exit(0)
    if m in mm:
        break
    mm.add(m)
    i += 1
    m = m * 10 + 7

print(-1)


Measured memory_bytes: 78088
#include <bits/stdc++.h>
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
 
//define
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int 

//typedef
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long inf = 1000000000000000000;

using namespace std;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void update(int n, vi &v, int x, int ch)
{
    while(x<=n)
    {
        v[x]+=ch;
        x+=(x&(-x));
    }
}

int query(vi &v, int x)
{
    int ans=0;
    while(x>0)
    {
        ans+=v[x];
        x-=(x&(-x));
    }
    return ans;
}

void solve()
{
    string s;
    cin>>s;
    ll a=0;
    int n=s.length();
    rep(i,n)
    {
        a+=(ll)(s[i]-'0');
        a%=9;
    }
    if(a%9)
        cout<<"No\n";
    else
        cout<<"Yes\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3872
fun main(arg: Array<String>) {
    val N = nextInt()
    val TA = Array(N) { listOfLong() }
    var T = 1L
    var A = 1L
    for ((t, a) in TA) {
        val d = Math.max(T.ceilDiv(t), A.ceilDiv(a))
        T = t * d
        A = a * d
//System.err.println("T:$T A:$A")
    }
    val ans = T + A
    println(ans)
}
fun Long.ceilDiv(n: Long) = (this + n - 1) / n

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


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

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

    int L, R, d; cin >> L >> R >> d;
    int multiple = 0;
    for (int i = L; i <= R; i++) {
        if (i % d == 0) multiple++;
    }
    cout << multiple << "\n";
    return 0;
}


Measured memory_bytes: 3636
M1,D1 = list(map(int,input().split()))
M2,D2 = list(map(int,input().split()))

if M1 == 4 or M1 == 6 or M1 == 9 or M1 == 11:
    if D1 == 30:
        print(1)
    else:
        print(0)
elif M1 == 2:
    if D1 == 28:
        print(1)
    else:
        print(0)
else:
    if D1 == 31:
        print(1)
    else:
        print(0)
        

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

using namespace std;

string A, B;
int lIdx, rIdx;

int get(string& s, int& idx)
{
  int num = 0;
  while(isdigit(s[idx])) num = num * 10 + s[idx++] - '0';
  return (num);
}

void dfs()
{
  bool left = A[lIdx] == '(';
  bool right = B[rIdx] == '(';
  bool mid = left & right;
  if(!left & !right) return;
  lIdx += left;
  rIdx += right;
  if(mid) cout << "(";
  dfs();
  if(mid) cout << ")";
  lIdx += left * 2;
  rIdx += right * 2;
  int value = get(A, lIdx) + get(B, rIdx);
  if(mid) cout << "[" << value << "]";
  lIdx += left * 2;
  rIdx += right * 2;
  if(mid) cout << "(";
  dfs();
  if(mid) cout << ")";
  lIdx += left;
  rIdx += right;
  if(lIdx == A.size() && rIdx == B.size()) cout << endl;
}

int main()
{
  cin >> A;
  cin >> B;
  dfs();
}

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


int main(){
    int N, X, T;
    cin >> N >> X >> T;
    if(N%X == 0){
        cout << (N/X) * T << endl;
    } else {
        cout << (N/X + 1) * T << endl;
        }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
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;
const ll MAX_N=200,INF=1e18;
ll N;
ll G[MAX_N][MAX_N];
ll col[MAX_N];
bool dfs(ll v,ll c){
	col[v]=c;
	REP(i,N){
		if(i==v)continue;
		if(G[i][v]==1){
			if(col[i]!=0&&col[i]==c){
				return false;
			}
			if(col[i]==0&&!dfs(i,-c))return false;
		}
	}
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N){
		string S;
		cin>>S;
		REP(j,N){
			G[i][j]=(S[j]=='1'?1:INF);
		}
	}
	REP(i,N)G[i][i]=0;
	if(dfs(0,1)){
		REP(k,N)REP(i,N)REP(j,N){
			if(G[i][k]+G[k][j]<G[i][j]){
				G[i][j]=G[i][k]+G[k][j];
			}
		}
		ll ans=0;
		REP(i,N)REP(j,N){
			ans=max(ans,G[i][j]+1);
		}
		cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
}

Measured memory_bytes: 640
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <vector>
#define rep(i, n) for (int64_t i = 0; i < (n); i++)
using namespace std;

struct event {
  int64_t t;
  bool type;
  int64_t val;
  bool operator<(const event& a) { return t < a.t; }
};

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, Q;
  cin >> N >> Q;

  vector<event> events;
  rep(i, N) {
    int64_t s, t, x;
    cin >> s >> t >> x;
    s -= x;
    t -= x;
    events.push_back({s, true, x});
    events.push_back({t, false, x});
  }
  sort(events.begin(), events.end());

  vector<int> answer(Q, -1);
  multiset<int64_t> st;
  int k = 0;
  rep(i, Q) {
    int64_t D;
    cin >> D;

    while (k < (int)events.size() && events[k].t <= D) {
      if (events[k].type) {
        st.emplace(events[k].val);
      } else {
        st.erase(st.find(events[k].val));
      }
      k++;
    }

    if (st.empty()) {
      answer[i] = -1;
    } else {
      answer[i] = *st.begin();
    }
  }

  rep(i, Q) cout << answer[i] << endl;
  return 0;
}


Measured memory_bytes: 22796
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int kaijo (int a, int result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo(a-1, result * a);
  }
}

int kaijo(int a) {
  return kaijo(a,1);
}

ll kaijo_ll (ll a, ll result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo_ll(a-1, result * a);
  }
}

ll kaijo_ll(ll a) {
  return kaijo_ll(a,1);
}

vector<ll> loc[1 << 17];
int main () {
  int n,m;
  cin >> n >> m;
  std::vector<int> a(n),b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  rep(i, n) {
		if (m - a[i] < 0)continue;
		loc[m - a[i]].push_back(b[i]);
	}
  ll ans = 0;
	priority_queue<ll> q;
	for (int i = m; i >= 0; i--) {
		rep(j, loc[i].size())q.push(loc[i][j]);
		if (!q.empty()) {
			ans += q.top(); q.pop();
		}
	}
  cout << ans << endl;
}


Measured memory_bytes: 7168
#include<stdio.h>
int main(void)
{
	int h,w,a[25][25],max,tate,yoko,sum,i,j,k,l;
	max=210000000;
	sum=0;
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			for(k=0;k<h;k++){
				for(l=0;l<w;l++){
					if(k!=i&&l!=j){
					   tate=(k-i)*a[k][l];
					   yoko=(l-j)*a[k][l];
					   if(tate<0){
						   tate=-tate;
					   }
					   if(yoko<0){
						   yoko=-yoko;
					   }
					   if(tate<yoko){
						   sum+=tate;
					   }
					   else{
						   sum+=yoko;
					   }
					}
				}
			}
			if(sum<max){
				max=sum;
			}
			sum=0;
		}
	}
	printf("%d\n",max);
    return 0;
}


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

int n, k, M;

void add(int &a, int b){
    a += b;
    if(a >= M){
        a -= M;
    }
}

const int maxn = 305;
int dp[maxn][maxn];
int comb[maxn][maxn];
int pre[maxn][maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> k >> M;
    memset(dp, 0, sizeof(dp));
    memset(comb, 0, sizeof(comb));
    memset(pre, 0, sizeof(pre));
    dp[1][0] = 1;
    pre[1][0] = 1;
    comb[0][0] = 1;
    for(int i = 1;i < maxn;i++){
        comb[i][0] = comb[i][i] = 1;
        for(int j = 1;j < i;j++){
            comb[i][j] = comb[i - 1][j];
            add(comb[i][j], comb[i - 1][j - 1]);
        }
        dp[1][i] = 1;
        pre[1][i] = i + 1;
    }
    for(int i = 2;i <= n + 1;i++){
        for(int x = 0;x <= k;x++){
            for(int j = 1;j < i;j++){
                int coeff = comb[i - 2][j - 1];
                int sum = (pre[j][k] - pre[j][x] + M) % M;
                sum = 1LL * coeff * sum % M;
                sum = 1LL * dp[i - j][x] * sum % M;
                add(dp[i][x], sum);
            }
            pre[i][x] = dp[i][x];
            if(x > 0)
                add(pre[i][x], pre[i][x - 1]);
        }
    }
    cout << dp[n + 1][0] << endl;
    return 0;
}


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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    int n;
    cin >> n;

    set<string> cores;
    int cont3200 = 0;
    vector<string> ratings = {"gray", "brown", "green", "cyan", "blue", "yellow", "orange", "red"};
    fo(i, n) {
        int a;
        cin >> a;
        a /= 400;
        if ( a >= 3200 / 400 ) cont3200++;
        else cores.insert(ratings[a]);
    }

    cout << max(1, (int) cores.size()) << " " << (int) cores.size() + cont3200 << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main()
{
    string s, p, check;
    cin >> s >> p;

    int ssize = s.size();
    rep(i, s.size())
    {
        if (s[i] == p[0])
        {
            check.clear(); //checkデータの初期化

            rep(j, p.size())
            {
                if (ssize > (i + j))
                {
                    check += s[i + j];
                }
                else if (ssize <= (i + j)) //s.size() - (i + j) <= 0は 常にfalse(0以下)となってしまうので× s.sizeはunsignで入れられない。
                {
                    check += s[i + j - ssize];
                }

                if (check == p)
                {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }


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


Measured memory_bytes: 3224
from math import gcd
def resolve():
    def prime_factorize(n):
        if 2 <= n < 4:
            return [n]
        res = []
        i = 2
        while i * i <= n:
            while n % i == 0:
                res.append(i)
                n //= i
            i += 1
        if n != 1:
            res.append(n)

        return set(res)

    a, b = map(int, input().split())

    g = gcd(a, b)
    ans = prime_factorize(g)
    print(len(ans) + 1)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9196
//copied from PG111002(UVa10054)
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>

#define hi(_x) ((_x)>>16)
#define lo(_x) ((_x)&0xffff)
using namespace std;
#define rotate(v, index) rotate((v).begin(), (v).begin()+(index), (v).end())

inline int unite(vector<int> &u, vector<vector<int>*> &array){
  int _array, _u, _each;
  while(array.size()){
    for(_array=0; _array<array.size(); _array++){//今まで作ったeuler閉路すべてに対しuと結合できるかどうか調べる
      vector<int> each = *(array[_array]); //eachはeuler閉路を構成すると仮定する
      for(_u=0; _u<u.size(); _u++){
        for(_each=0; _each<each.size(); _each++){
          if(lo(u[_u])==hi(each[_each])){
            if(_each)rotate(each,_each); //each[_each]が先頭に来るよう頭だし
            u.insert(u.begin()+_u+1,each.begin(),each.end());
            delete array[_array];
            array.erase(array.begin()+_array);
            goto next;
          }
        }
      }
    }
    //fail
    return 0;
    next:
    /*continue*/;
  }//while
  return 1;
}

inline int sort(vector<int>&s,vector<int>&v){
  int x=hi(v[0]), y=lo(v[0]), i, a=0;
  v.erase(v.begin());
  s.push_back((x<<16)+y);
  while(1){
    for(i=0; i<v.size(); i++){
      if(lo(s[a])==hi(v[i])||lo(s[a])==lo(v[i]))goto in;//break;
    }
    /*if(i==v.size())*/break;
in:
    x=hi(v[i]), y=lo(v[i]);
    v.erase(v.begin()+i);
    if(lo(s[a])==y)swap(x,y);
    s.push_back((x<<16)+y);
    a++;
  }//while
  return hi(s[0])==lo(s[a]);
}

char s[99];
int A[10],a,b;
int main(){
  int i=0, k;
  int n, l, x, y;
  vector<int> vorig;
  vector<vector<int>*> varray;
  vector<int> vunite;

  for(;~scanf("%d",&l);){
	memset(A,0,sizeof(A));
    for(k=0;k<l;k++){
      //scanf("%d %d",&x, &y);
      scanf("%s",s);
      x=s[0]-48,y=s[strlen(s)-1]-48;
      vorig.push_back((x<<16)+y);
	  A[x]++,A[y]++;
    }
	for(a=b=-1,k=0;k<10;k++){
		if(A[k]&1){
			if(a==-1)a=k;
			else if(b==-1)b=k;
			else goto fail;
		}
	}
	if(a!=-1)vorig.push_back((a<<16)+b);

    while(vorig.size()){
      vector<int> *p = new vector<int>;
      if(!sort(*p,vorig))goto fail;
      varray.push_back(p);
    }

    vunite = *(varray[0]);
    delete varray[0];
    varray.erase(varray.begin());
    if(!unite(vunite,varray))goto fail;

    while(vunite.size()){
      //printf("%d %d\n",hi(vunite[0]),lo(vunite[0]));
      vunite.erase(vunite.begin());
    }
	puts("Yes");
    continue;

fail:
    while(varray.size()){
      delete varray[0];
      varray.erase(varray.begin());
    }
    puts("No");
	vorig.clear();
    vunite.clear();
  }//for
}//main

Measured memory_bytes: 1036
#include<iostream>
using namespace std;
int main()
{
int lx,ly,x,y,r;
cin >> lx >> ly >> x >> y >> r;
if(lx>=x+r && 0<=x-r && ly>=y+r && 0<=y-r) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}

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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;
const LL INF = 1e18;

LL n, m;

LL get1(LL n, LL m)
{
	LL res = INF;
	for (int i = 1; i < n; i ++ )
	{
		LL a = (n - i) / 2LL, b = n - i - a;
		LL area[] = {i * m, a * m, b * m};
		sort(area, area + 3);
		res = min(res, area[2] - area[0]);
	}
	return res;
}

LL get2(LL m, LL n)
{
	LL res = INF;
	for (int i = 1; i < n; i ++ )
	{
		LL a = m / 2, b = m - a, c = n - i;
		LL area[] = {a * c, b * c, i * m};
		sort(area, area + 3);
		res = min(res, area[2] - area[0]);
	}
	return res;
}

int main()
{
	cin >> n >> m;
	cout << min(min(get1(n, m), get1(m, n)), min(get2(n, m), get2(m, n)));
    return 0;
}

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

int main(){
  long long N;
  cin >> N;
  long long SUM=0;
  for(long long i=1;i<N+1;i++){
    long long counter=0;
    long long check=0;
    check= floor(N/i);
    SUM = SUM +  i*((1+check)*check/2);;
  }
   
  cout << SUM << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define lli long long
int main() {
    lli n,k,q;
    cin>>n>>k>>q;
    lli a[q],c[n+1],i,count[100001]={0};
    for(i=0;i<q;i++)
        cin>>a[i];
    for(i=0;i<q;i++)
    {
        count[a[i]]++;
    }
    for(i=1;i<=n;i++)
        c[i]=k-(q-count[i]);
    for(i=1;i<=n;i++)
    {
        if(c[i]<=0)
        {
            cout<<"No\n";
        }
        else
        {
            cout<<"Yes\n";
        }
    }
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cctype>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int n;

int dfs(int i, VI a){
    if (i == n) return 0;
    if (a[i] == 0) return dfs(i+1, a);
    int res = 10, x = a[i];
    FOR(j,i,n-1){
        a[j] = (a[j] - x + 10) % 10;
        res = min(res, dfs(i+1, a) + 1);
    }
    return res;
}

int main() {
    while (cin >> n && n){
        string s, t;
        VI a(n);
        cin >> s >> t;
        REP(i,n){
            a[i] = (s[i] - t[i] + 10) % 10;
        }
        cout << dfs(0, a) << endl;
    }

    return 0;
}

Measured memory_bytes: 3000
from collections import deque

N, X, Y = map(int, input().split())

graph = [[] for _ in range(N)]

for i in range(N - 1):
    graph[i].append(i + 1)
    graph[i + 1].append(i)

graph[X - 1].append(Y - 1)
graph[Y - 1].append(X - 1)

# print(graph)


def bfs(s):
    q = deque([])
    q.append(s)
    dist[s][s] = 0

    while q:
        x = q.popleft()

        for nx in graph[x]:
            if dist[s][nx] != 0:
                continue
            else:
                dist[s][nx] = dist[s][x] + 1
                q.append(nx)


inf = 10 ** 9

dist = [[0] * N for _ in range(N)]

dist_lis = [0] * N

for i in range(N):
    bfs(i)

for i in range(N):
    for j in range(i + 1, N):
        dist_lis[dist[i][j]] += 1

# print(dist)
# print(dist_lis)

for i in range(1, N):
    print(dist_lis[i])


Measured memory_bytes: 79196
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
    ll n,a,b,m;
    cin>>n>>a>>b;
    if(n<a+b-1||n>b+a-1+(a-1)*(b-1)){
        cout<<-1<<endl;
        return 0;
    }
    
    for(int i=b;i>1;i--){
        cout<<i<<" ";
    }
    cout<<1;
    m=n;
    while(m>b){
        int v=min(m-b, a-1);
        for(int i=0;i<v;i++){
            cout<<" "<<m-v+1+i;
        }
        m-=v;
    }
    
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef dsu uf;
typedef fenwick_tree<ll> fw;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
 ll n,m;
  cin >> n >> m;
 scc_graph G(n);
  rep(i,0,m){
   ll a,b;
    cin >> a >> b;
    G.add_edge(a,b);
  }
  
  auto res=G.scc();
  cout << res.size() << endl;
  for(auto g:res){
  cout << g.size() << " ";
   for(auto v:g) cout << v << " "; 
    cout << endl;
  }
  
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 40612
#include<stdio.h>
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
 
int main() {
	int n;
	int a=100, b=10, c;
	int ans_a,ans_b,ans_c;
 
	cin >> n;
 
	ans_a = n / a;
	if (ans_a == 7) {
		cout<<"Yes";
		return 0;
	}
	ans_b = (n - ans_a * 100) / b;
	if (ans_b == 7) {
		cout << "Yes";
		return 0;
	}
 
	ans_c = n - ans_a * 100 - ans_b * 10;
	if (ans_c == 7) {
		cout << "Yes";
		return 0;
	}
	cout << "No";
 
 
	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main()
{
	int n,ans=1,j=0,k;
	cin>>n>>k;
	while(j<n)
	{
		if(ans>=k)
		{
			ans=ans+k;
			j++;
		}
		if(ans<k)
		{
			ans=ans+ans;
			j++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

N,K = inpl()
Als = inpl()

for i in range(N-K):
    if Als[i] < Als[i+K]:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 104508
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;

typedef long long ll;
const int maxm = 100010,rhl = 1000000007;
int N,M,X[maxm];
struct Matrix
{
	ll A[4][4]; int n,m;
	inline Matrix(int _n = 0,int _m = 0):n(_n),m(_m) { for (int i = 0;i < n;++i) memset(A[i],0,sizeof(A[i])); }
	inline ll &operator()(int a,int b) { return A[a][b]; }
	inline ll operator()(int a,int b) const { return A[a][b]; }
	static inline Matrix unit(int _n) { Matrix ret(_n,_n); for (int i = 0;i < _n;++i) ret(i,i) = 1; return ret; }
	friend inline Matrix operator*(const Matrix &a,const Matrix &b)
	{
		Matrix ret(a.n,b.m);
		for (int i = 0;i < ret.n;++i)
			for (int j = 0;j < ret.m;++j)
				for (int k = 0;k < a.m;++k)
				{
					ret(i,j) += a(i,k)*b(k,j)%rhl;
					if (ret(i,j) >= rhl) ret(i,j) -= rhl;
				}
		return ret;
	}
}mul(4,4),ans(1,4);

inline Matrix qsm(Matrix a,int b)
{
	Matrix ret = Matrix::unit(a.n);
	for (;b;b >>= 1,a = a*a) if (b&1) ret = ret*a;
	return ret;
}

inline int gi()
{
	char ch; int ret = 0,f = 1;
	do ch = getchar(); while (!(ch >= '0'&&ch <= '9')&&ch != '-');
	if (ch == '-') f = -1,ch = getchar();
	do ret = ret*10+ch-'0',ch = getchar(); while (ch >= '0'&&ch <= '9');
	return ret*f;
}

int main()
{
	//freopen("E.in","r",stdin);
	//freopen("E.out","w",stdout);
	N = gi(); M = gi();
	for (int i = 1;i <= M;++i) X[i] = gi();
	ans(0,0) = ans(0,1) = ans(0,2) = ans(0,3) = 1;

	mul(0,0) = 2; mul(0,1) = 1; mul(0,2) = 1; mul(0,3) = 1;
	mul(1,0) = 1; mul(1,1) = 1; mul(1,2) = 1;
	mul(2,0) = 2; mul(2,2) = 1;
	for (int i = 1;i <= M;++i)
	{
		ans = ans*qsm(mul,X[i]-X[i-1]);
		ll t = ans(0,3);
		for (int i = 0;i < 4;++i)
		{
			ans(0,i) -= t;
			if (ans(0,i) < 0) ans(0,i) += rhl;
		}
	}
	ans = ans*qsm(mul,N-X[M]);
	cout << ans(0,3) << endl;
	return 0;
}


Measured memory_bytes: 640
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>

using namespace std;


int main(){

    int H,W,h,w;
    cin>>H>>W>>h>>w;

    cout<<H*W-(h*W+w*(H-h));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;
    int ans = 0;
    rep(i, 6) if (S[i] == '1') ans += 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
N = int(2**n)
d = []

for i in range(N):
    b = "{:0{}b}".format(i, n)
    d.append(sum(A[j] for j in range(n) if b[j] == '1'))

    #print(b)

for i in range(q):
    if m[i] in d:
        print("yes")
    else:
        print("no")

Measured memory_bytes: 44972
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc= new Scanner(System.in);
    String s=sc.next(), t=sc.next();
    int si=sc.nextInt(), ti=sc.nextInt();
    String u =sc.next();
    
    if(u.equals(s)) si--;
    else ti--;
    
    System.out.println(si +" "+ti);
  }
}

Measured memory_bytes: 38820
#include "iostream"
using namespace std;

int a,b,k;
int main(){
	cin>>a>>b>>k;
	if((k>=b-a+1)||(b-a+1<=2*k)){
		for(int i=a;i<=b;i++)
			cout<<i<<endl;
	}
	else{
		int x=1;
		for(int i=a;i<=b;i++){
			if(x<=k){
				cout<<i<<endl;
				x++;
			}
			else
				break;
		}
		int t=b-k+1;
		cout<<t<<endl;
		while(t<b){
			t++;
			cout<<t<<endl;
		}
	}
	return 0;
}

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

int main()
{
  int N, M, C;
  cin >> N >> M >> C;
  int A[N][M] = {}, B[M] = {};

  for(int i = 0; i < M; i++){
    cin >> B[i];
  }

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

  
  int count = 0;

  for(int i = 0; i < N; i++){
    int sum = 0;
    for(int j = 0; j < M; j++){
      sum += A[i][j]*B[j];
    }
    sum += C;
    if(sum > 0){
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

n, m = map(int, input().split())

wa=defaultdict(lambda: 0)
ac=set()
cnt = 0
for line in sys.stdin:
  p, s = line.split()
  p = int(p)
  if p in ac:
    continue

  if s == "AC":
    cnt+=1
    ac.add(p)
  else:
    wa[p] += 1

print(cnt, sum(wa[i] for i in ac))


Measured memory_bytes: 22888
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

k = int(input())
s = input()
if len(s) <= k:
  print(s)
else:
  print( s[:k]+ "...")

Measured memory_bytes: 65212
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = [INT() for _ in range(N)]

zipped = {x:i+1 for i, x in enumerate(sorted(A))}
A = [zipped[x] for x in A]

print(sum(x%2==0 for x in A[::2]))

Measured memory_bytes: 25988
from collections import deque

class Cave():
    def __init__(self):
        self.graph = {}
    def add_room(self, r):
        self.graph[r] = []
    def add_passage(self, r1, r2):
        self.graph[r1].append(r2)
        self.graph[r2].append(r1)
    def next_rooms(self, r):
        return self.graph[r]
    def __str__(self):
        return self.graph.__str__()

def main():
    N, M = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(M)]

    cave = Cave()
    for i in range(1, N+1):
        cave.add_room(i)
    for r1, r2 in AB:
        cave.add_passage(r1, r2)

    q = deque()
    q.append(1)
    visited = [0]*(N+1)
    visited[1] = -1

    while q:
        r_now = q.popleft()
        for r_next in cave.next_rooms(r_now):
            if visited[r_next] == 0:
                visited[r_next] = r_now
                q.append(r_next)

    print('Yes')
    for i in visited[2:]:
        print(i)
main()

Measured memory_bytes: 65804
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct Card { internal int num, vol; }

    class Problem
    {
        readonly int MAX = 1000;
        readonly int m;

        Card[] cards;
        int[,] dp;

        public Problem(int m)
        {
            this.m = m;
            cards = new Card[m];
            dp = new int[m + 1, MAX + 1];
            dp[0, 0] = 1;
        }

        public void SetCards()
        {
            for (int i = 0; i < m; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                cards[i].num = int.Parse(input[0]);
                cards[i].vol = int.Parse(input[1]);
            }
        }

        public void MakeDP()
        {
            for (int i = 0; i < m; i++)
            {
                for (int j = MAX; j >= 0; j--)
                {
                    if (dp[i, j] == 0) continue;

                    for (int k = 0; k <= cards[i].vol; k++)
                    {
                        int sum = j + cards[i].num * k;
                        if (sum > MAX) continue;
                        dp[i + 1, sum] += dp[i, j];
                    }
                }
            }
        }

        public int GetConmination(int n)
        {
            return dp[m, n];
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int m = int.Parse(Console.ReadLine());

                if (m == 0) break;

                Problem p = new Problem(m);
                p.SetCards();
                p.MakeDP();

                int g = int.Parse(Console.ReadLine());

                while (g-- > 0)
                {
                    int n = int.Parse(Console.ReadLine());
                    sb.AppendLine(p.GetConmination(n).ToString());
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9292
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  
  if (A + B < C + D) {
    cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 256