akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <assert.h>
#define MAX 4001

int  ans[MAX][2];
long long sum[MAX];

int tasu(int);

main(){
  long long p, q;
  int id;
  int i, j, n, f, temp;

  while(1){
    scanf("%d", &n);
    if(n==0) break;

    f=0;
    j=0;
    ans[0][0]=-1;
    for(i=0;i<n;i++){
      sum[i]=0;
    }

    for(i=0;i<n;i++){
      scanf("%d %lld %lld", &id, &p, &q);
      assert(id < 1000000);

      temp=tasu(id);
     
      sum[temp]+=p*q;
    }

    for(i=0;;i++){
      if(ans[i][0]==-1) break;
      if(sum[i]>=1000000){
	ans[i][1]=1;
	f=1;
      }
      else ans[i][1]=0;
    }

    if(f==0){
      printf("NA\n");
      continue;
    }

    for(i=0;;i++){
      if(ans[i][0]==-1) break;
      if(ans[i][1]==1){
	printf("%d\n", ans[i][0]);
      }
    }
  }
  return 0;
}


int tasu(int a){
  int i, f=0, temp;

  for(i=0;;i++){
    if(ans[i][0]==-1){
      temp=i;
      break;
    }
    if(ans[i][0]==a){
      f=1;
      return i;
    }
  }

  ans[temp][0]=a;
  ans[temp+1][0]=-1;

  return temp;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>

using namespace std;
using ll = long long;

int main(){ 
        int x,y;
        cin >> x >> y;
        if((x+1)/2>=y)  cout << "YES";
        else cout << "NO";
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<ll> sum(n+1, 0);
    for(int i = 0; i < n; i++) sum[i+1] = sum[i] + a[i];
    int ans = 1;
    for(int i = n-1; i >= 0; i--) {
        if(sum[i]*2>=a[i]) ans++;
        else break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using ll = long long;
using namespace std;

int main(){
  ll N; 
  cin >> N;

  ll cnt = 0;
  for(ll i=1;i<=N;i++){
    if(i%3 != 0 && i%5 != 0){
      cnt += i;
    }
  }

  cout << cnt << endl;


  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	ll a, b, c; cin >> a >> b >> c;
	ll d =c-a-b; 
	if( d > 0  && d*d-4*a*b > 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())

x = list(map(int, input().split()))

y = []
for i in range(1, len(x)):
	y.append(a*(x[i] - x[i-1]))

for i, l in enumerate(y):
	if l > b:
		y[i] = b

print(sum(y))

Measured memory_bytes: 14252
import java.util.Scanner;



public class Main {
	public static int fib(int n){
	int a[]=new int[n+1];
    a[0]=1;
	a[1]=1;
	if(n<2){
		return a[n];
	}
	for(int i=2;i<=n;i++){
		a[i]=a[i-1]+a[i-2];
	}
			return a[n];
	}


	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int n=Integer.parseInt(sc.next());
	
	System.out.println(fib(n));
		
		

  }
}

Measured memory_bytes: 17280
# coding: utf-8

def solve(a,begin,end,queue):
  if begin>=end:
    return
  maxx = sorted(list(map(abs,a[begin:end+1])),reverse=True)[0]
  if maxx in a[begin:end+1]:
    m = a[begin:end+1].index(maxx)+begin
  else:
    m = a[begin:end+1].index(-1*maxx)+begin
    maxx = -1*maxx
  if maxx==0:
    return []
  if maxx>0:
    solve(a,begin,m-1,queue)
    for i in range(max(0,m-1),end):
      if a[i+1]>=a[i]:
        continue
      else:
        a[i+1]+=a[i]
        queue.append((i,i+1))
        if a[i+1]<a[i]:
          a[i+1]+=a[i]
          queue.append((i,i+1))
    return queue
  if maxx<0:
    solve(a,m+1,end,queue)
    for i in reversed(range(begin,min(len(a)-1,m+1))):
      if a[i]<=a[i+1]:
        continue
      else:
        a[i]+= a[i+1]
        queue.append((i+1,i))
        if a[i]>a[i+1]:
          a[i]+=a[i+1]
          queue.append((i+1,i))
    return queue

if __name__ == '__main__':
  n = int(input())
  a = list(map(int,input().split()))
  queue = solve(a,0,len(a)-1,[])
  print(len(queue))
  for i in range(len(queue)):
    print(queue[i][0]+1,queue[i][1]+1)


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

#define ll long long
#define pii pair <int, int>

using namespace std;

string s;
int a[500005];

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

    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == '<')
            a[i + 2] = a[i + 1] + 1;
    }
    /*for (int i = 1; i <= s.length() + 1; ++i)
        cout << a[i] << " ";
    cout << '\n';*/
    for (int i = s.length() - 1; i >= 0; --i) {
        if (s[i] == '>')
            a[i + 1] = max(a[i + 1], a[i + 2] + 1);
    }
    ll rez = 0;
    for (int i = 1; i <= s.length() + 1; ++i)
        rez += a[i];
    return cout << rez, 0;
}


Measured memory_bytes: 2972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    ld T, A;
    cin >> N >> T >> A;
    ld H[N];
    ld m = 1000000000;
    int ans;
    rep(i, N){
        cin >> H[i];
        ld t = T-H[i]*0.006;
        if(abs(t-A) < m){
            m = abs(t-A);
            ans = i+1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text;

namespace ALDS1_5_B {
    public class Problem {
        private int[] _A;
        private int _n, _count;

        public Problem(int[] A,int n) {
            _A = A;
            _n = n;
        }

        public int Count {
            get { return _count; }
        }

        public void Run() {
            _count = 0;
            MergeSort(0, _n);

            StringBuilder sb = new StringBuilder();
            sb.Append(_A[0]);
            foreach (int a in _A.Skip(1)) {
                sb.AppendFormat(" {0}", a);
            }
            sb.AppendFormat("\n{0}\n", _count);
            Console.Write(sb);
        }

        private void MergeSort(int left,int right) {
            if (left + 1 < right) {
                int mid = (left + right) / 2;
                MergeSort(left, mid);
                MergeSort(mid, right);
                Merge(left, mid, right);
            }
        }

        private void Merge(int left,int mid,int right) {
            int n1 = mid - left;
            int n2 = right - mid;

            int[] L = new int[n1 + 1];
            for(int i = 0; i < n1; i++) {
                L[i] = _A[left + i];
            }
            L[n1] = int.MaxValue;

            int[] R = new int[n2 + 1];
            for(int i = 0; i < n2; i++) {
                R[i] = _A[mid + i];
            }
            R[n2] = int.MaxValue;

            int x = 0;
            int y = 0;
            for (int i = left; i < right; i++) {
                if (L[x] <= R[y]) {
                    _A[i] = L[x];
                    x++;
                }
                else {
                    _A[i] = R[y];
                    y++;
                }
                _count++;
            }
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int[] S = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            Problem p = new Problem(S, n);
            p.Run();
        }
    }
}

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

int main()
{
  int a, b, c, d;

  cin >> a >> b >> c >> d;
  a = (a - 1) / d + 1;
  c = (c - 1) / b + 1;
  cout << (c <= a ? "Yes" : "No") << endl;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n,sum=0;cin>>n;
    vector<int>p(n);
    rep(i,n){
        cin>>p[i];
        sum+=p[i];
    }

    sort(p.begin(),p.end());
    sum-=p[n-1]/2;

    cout<<sum<<endl;
}


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

int main() {
  int N;cin>>N;
  int m=0,wa=0;
  for(int i=0; i<N; i++){
    int p;cin>>p;
    wa+=p;
    m=max(m,p);
  }
  cout<<wa-m/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

const int MOD = 1000000007;
const int INF = 1 << 30;

struct SegmentTree {
    int n;
    vi seg;

    SegmentTree(vi v) {
        n = 1;
        int n_ = v.size();
        while (n < n_) n *= 2;

        seg.resize(2 * n - 1);
        rep(i, 2*n-1) seg[i] = 0;

        init(n_, v);
    }

    void init(int n_, vi v) {
        rep(i, n_) {
            update(i, v[i]);
        }
    }

    void update(int k, int a) {
        k += n - 1;
        seg[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            seg[k] = seg[k * 2 + 1] | seg[k * 2 + 2];
        }
    }

    int query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return 0;

        if (a <= l && r <= b) return seg[k];
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return vl | vr;
        }
    }
};

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

    vi ss(n);
    rep(i, n) {
        int cv = s[i] - 'a';
        ss[i] = 1 << cv;
    }
    SegmentTree st(ss);

    int q;
    cin >> q;

    rep(k, q) {
        int t; cin >> t;
        if (t == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            int cc = c - 'a';
            int f = 1 << cc;
            st.update(i, f);
        }
        else {
            int l, r;
            cin >> l >> r;
            l--;
            int bit = st.query(l, r, 0, 0, st.n);
            cout << __builtin_popcount(bit) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 10884
#include<stdio.h>
#include<math.h>
int main(void){
    int i,n;
    int s[1000];
    double m,sum,a;
    while(1){
        scanf("%d",&n);
        if(n==0){
            break;
        }
        a=0;
        sum=0;
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            sum+=s[i];
        }
        m=sum/n;
        for(i=0;i<n;i++){
            a+=pow(s[i]-m,2.0);
        }
        a/=n;
        printf("%f\n",pow(a,0.5));
    }
    return 0;
}


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

const int MAX_N = 100000;

int main(){
    int N, abc[MAX_N][3], flag, dp[MAX_N][3];
    flag = 0;
    memset(dp, -1, sizeof(dp));
    cin >> N;
    rep(i, N) {
        cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    }

    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;

    for (int i = 1; i <= N; i++) {
        rep(j, 3) {
            rep(k, 3) {
                if (j != k) {
                    dp[i][k] = max(dp[i][k], dp[i - 1][j] + abc[i - 1][k]);
                }
            }
        }
    }
    
    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  int n;
  cin>>n;
  vector<int>a(n),b(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  int sum=0;
  rep(i,n)sum+=b[i];
  vector<int>c(n-1);
  rep(i,n-1)cin>>c[i];
  vector<int>v;
  rep(i,n-1){
    if(a[i]+1==a[i+1])v.pb(a[i]-1);
  }
  rep(i,v.size()){
    sum+=c[v[i]];
  }
  cout<<sum;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int dp[50][500][500];
int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int n, ma, mb;
	cin >> n >> ma >> mb;
	vector<int> a, b, c;

	a.push_back(0);
	b.push_back(0);
	c.push_back(0);

	for(int i=0; i<n; i++){
		int t1, t2, t3;
		cin >> t1 >> t2 >> t3;
		a.push_back(t1);
		b.push_back(t2);
		c.push_back(t3);
	}

	for(int i=0; i<=n; i++){
		for(int j=0;j<=400; j++){
			for(int k=0; k<=400; k++){
				dp[i][j][k] = INF;
			}
		}
	}
	dp[0][0][0] = 0;

	for(int i=1; i<=n; i++){
		for(int j=0; j<=400; j++){
			for(int k=0; k<=400; k++){
				dp[i][j][k] = dp[i-1][j][k];
				if(j - a[i] >= 0 && k - b[i] >= 0){
					dp[i][j][k] = min(dp[i-1][j][k], dp[i-1][j-a[i]][k-b[i]] + c[i]);
				}
			}
		}
	}

	int ans = INF;
	for(int j=1; j<=400; j++){
		for(int k=1; k<=400; k++){
			if(ma*k == mb*j){
				ans = min(ans, dp[n][j][k]);
			}
		}
	}
	if(ans == INF){
		ans = -1;
	}

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


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

using namespace std;

int main(){
    string s;
    cin >> s;
    int idx[5] = {-1,-1,-1,-1,-1};
    int count=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='K'){
            idx[0] = i;
        }else if(s[i]=='I'){
            idx[1] = i;
        }else if(s[i]=='H'){
            idx[2] = i;
        }else if(s[i]=='B'){
            idx[3] = i;
        }else if(s[i]=='R'){
            idx[4] = i;
        }
        if(s[i]=='A'||s[i]=='K'||s[i]=='I'||s[i]=='H'||s[i]=='B'||s[i]=='R'){
            
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    
    for(int i=0;i<5;i++){
        if(idx[i]==-1){
            cout << "NO" << endl;
            return 0;
        }
    }
    
    if(idx[0]<idx[1]&&idx[1]<idx[2]&&idx[2]<idx[3]&&idx[3]<idx[4]&&s.length()<10){
        if(idx[0]<=1&&idx[1]==idx[0]+1&&idx[2]==idx[1]+1&&idx[3]-idx[2]<=2&&idx[4]-idx[3]<=2&&s.length()-idx[4]<=2){
            cout << "YES" << endl;
            //cout << s.length() << " " << idx[4] << endl;
        }else{
            cout << "NO" << endl;    
            //cout << s.length() << " " << idx[4] << endl;
        }
        
    }else{
        cout << "NO" << endl;
        //cout << s.length() << " " << idx[4] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
char a[110][110];
char b[110][110];
int main()
{
    int n,m,i,j,k,x,t;
    cin >> n >> m;
    k=0;
    for(i=0;i<n;i++)
    {
        t=0;
        for(j=0;j<m;j++)
        {
            cin >> a[k][j];
            if(a[k][j]=='#')
                t=1;
        }
        if(t)
            k++;
    }
    x=0;
    for(i=0;i<m;i++)
    {
        t=0;
        for(j=0;j<k;j++)
        {
            b[j][x]=a[j][i];
            if(a[j][i]=='#')
                t=1;
        }
        if(t)
            x++;
    }
    for(i=0;i<k;i++)
    {
        for(j=0;j<x;j++)
            cout << b[i][j];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll a[100001]={0};
int main()
{//ios_base::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;ll i=1;
    while(a>0&&c>0)
    {   if(i%2)
        c-=b;
        else
            a-=d;
        i++;
    }
    if(a<=0)
        cout<<"No";
    else
        cout<<"Yes";
}


Measured memory_bytes: 3632
n=int(input())
a=[int(i) for i in input().split()]
dic={}
for i in a:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1

ans=0
for i,j in dic.items():
    if j >=i:
        ans+=j-i
    else:
        ans+=j
print(ans)
    

Measured memory_bytes: 17780
n,m=map(int,input().split())
vis,ci,cb,cc=[0]*(n+1),0,0,0
g=[[] for i in range(n+1)]
for i in range(m):
	u,v=map(int,input().split())
	g[u]+=[v]
	g[v]+=[u]
for i in range(1,n+1):
	if vis[i]==0:
		if len(g[i])==0:
			ci+=1
		else:
			s,f=[(i,1)],True
			while len(s):
				u,col=s.pop()		
				if vis[u]:
					f&=(vis[u]==col)
					continue
				vis[u]=col
				for i in g[u]:
					s+=[(i,3-col)]
			cb+=f
			cc+=f^1
print(ci*ci+2*ci*(n-ci)+cc*cc+2*cb*cc+2*cb*cb)

Measured memory_bytes: 94480
#include<stdio.h>
int main(){
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  while(A>0&&C>0){
     C=C-B;
    if(C<=0){
      printf("Yes");
      break;
    }
    A=A-D;
    if(A<=0){
      printf("No");
      break;
    }
   
  }
  return(0);
}


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

int main(){
	int i , n, x;
	cin >> n;
	
	for(i = 1; i <= n; i++){
		x = i;
		if(x%3 == 0){
			cout << ' ' << i;
			continue;
		}
		if(x%10 == 3){
			cout << ' ' << i;
			continue;
		}
		for(x /= 10; x > 0; x /= 10){
			if(x%10 == 3){
				cout << ' ' << i;
				break;
			}
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

ll f(ll a, ll b) {
    ll res = 1;
    rep(_, b) { res = (res * 2) % MOD; }
    return res;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> cnt(N);
    rep(i, N) { cnt[A[i]]++; }
    int ok = 1;
    if(N % 2) {
        rep(i, N) {
            if(i == 0 && cnt[i] != 1)
                ok = 0;
            else if(i != 0 && i % 2 == 0 && cnt[i] != 2)
                ok = 0;
        }
    } else {
        rep(i, N) {
            if(i % 2 == 1 && cnt[i] != 2)
                ok = 0;
        }
    }
    if(ok) {
        cout << f(2, N / 2) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
pattern = ['S', 'H', 'C', 'D']

trump_flag = [[False] * 4 for i in range(13)]

num = int(input())

for i in range(num):
    trump = input().split()
    for j in range(4):
        if pattern[j] == trump[0]:
            pattern_index = j
    trump_flag[int(trump[1]) - 1][pattern_index] = True

for i in range(4):
    for j in range(13):
        if trump_flag[j][i] == False:
            print(f'{pattern[i]} {j+1}')


Measured memory_bytes: 5608
K = int(input())
A = list(map(int, input().split()))

if A[-1] != 2:
    result = -1
else:
    result = 0
    cand_max = 2
    cand_min = 2
    for i in range(len(A))[::-1]:
        comp = int(cand_min / A[i]) * A[i]
        if cand_min <= comp <= cand_max:
            pass
        elif cand_min <= comp + A[i] <= cand_max:
            comp += A[i]
        else:
            result = -1
            break
        cand_max = int(cand_max / A[i] + 1) * A[i] - 1
        cand_min = comp

if result == -1:
    print(-1)
else:
    print(cand_min, cand_max)


Measured memory_bytes: 14224
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> c(b),e(a,0),f(a,0);
  vector<string> d(b);
  rep(i,b)
    cin>>c[i]>>d[i];
  int g=0,h=0;
  rep(i,b){
  if(e[c[i]-1]==0){
  if(d[i]=="AC"){
  g++;
    e[c[i]-1]=1;
  }
    else{
    f[c[i]-1]++;
    }
  }
  }
  rep(i,a){
  if(e[i]==1)
    h+=f[i];
  }
  cout<<g<<' '<<h<<endl;
}

Measured memory_bytes: 8736
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define n_max int(2*1e5 +5)
#define MOD llong(1e9 + 7)






llong fac[n_max];  /// fac[n] = n!
llong finv[n_max]; /// (fac[n] * finv[n]) % MOD = 1
llong inv[n_max];  /// (n * inv[n]) % MOD = 1
 
void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR (i, 2, n_max) {
    fac[i] = fac[i-1]*i % MOD;
    inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
    finv[i] = finv[i-1]*inv[i] % MOD;
  }
}
 
llong nCk (int n, int k) {
  if (n < k || k < 0 || n < 0) return 0;
  return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}


int main(){
    init();
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    llong ans = 0;

    REP(i,h-a){
        ans += nCk(b-1+i,i) * nCk(w-b-1+h-1-i,w-b-1) % MOD;
        ans%=MOD;
    }
    cout << ans << endl;
}

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

int main()
{
  int N,M;
  std::cin>>N>>M;
  
  std::vector<int> H(N+1);
  for(size_t i=1;i!=N+1;i++)
  {
    std::cin>>H[i];
  }
  
  std::vector<bool> c(N+1);
  for(size_t i=1;i!=N+1;i++)
  {
    c[i]=true;
  }
  for(size_t i=0;i!=M;i++)
  {
    int a,b;
    std::cin>>a>>b;
    
    if(H[a]>H[b])
    {
      c[a]=c[a]==false?false:true;
      c[b]=false;
    }
    else if(H[a]<H[b])
    {
      c[a]=false;
      c[b]=c[b]==false?false:true;
    }
    else
    {
      c[a]=false;
      c[b]=false;
    }
  }
  
  int result=0;
  for(size_t i=1;i!=N+1;i++)
  {
    if(c[i])
      result++;
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <unordered_map>       // ヘッダファイルインクルード

using namespace std;

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

    vector<unsigned int> bits;

    long int sum = 0;
    long int base_exp = 0;
    long int base = 1;

    while(sum != N) {
        base_exp ++;
        base *= 2;
        long int b = abs(N - sum) % (long int)base;
        if(base_exp%2==0) {
            b *= -1;
        }
        bits.push_back(b==0 ? 0 : 1);
        sum += b;
    }
    if(N==0) {
        bits.push_back(0);
    }

    reverse(bits.begin(), bits.end());
    for(auto b:bits) {
        cout << b;
    }
    cout << endl;
}


Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

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

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

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 30;
const int N = (int)3e5 + 7;
const int MAXN = (int)3e6 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e17;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

void solve() {
	string s; cin >> s;
	if (s[1] == 'B')
		cout << "ARC";
	else
		cout << "ABC";
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 3664
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

vector<int> path[1000];
long double dp[1005];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	long double da,db,dc,s;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a>>b;
		a--,b--;
		path[a].push_back(b);
	}
	s=INF;
	for(k=0;k<n;k++){
		for(i=0;i<n-1;i++)dp[i]=INF;
		for(i=n-1;i>=0;i--){
			da=0,a=0;
			for(auto to:path[i]){
				if(dp[to]==INF)continue;
				da+=dp[to];
				a++;
			}
			if(a==0)continue;
			dp[i]=da/a+1;
			if(a==1 || i!=k)continue;
			for(auto to:path[i]){
				if(dp[to]==INF)continue;
				dp[i]=min(dp[i],(da-dp[to])/(a-1)+1.0);
			}
		}
		s=min(s,dp[0]);
	}
	cout<<fixed<<setprecision(10)<<s<<endl;
}

Measured memory_bytes: 1408
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();

		}

     public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];

			var aArray = retreiveLongArray();

			var hako = Enumerable.Repeat(0, (int)N + 1).ToArray();
			var ans = new List<long>();
			for (var i = N; i >= 1; i--) {
				var inp = aArray[i - 1];

				//箱が0で、かつinpが1の場合　もしくは　箱が1でinpが0の場合は、i番目の箱にボールを入れる
				if ((hako[i]==0 && inp==1) | (hako[i]==1 && inp==0)) {
					ans.Add(i);

					for (int j = 1; j <= Math.Sqrt(i); j++) {

						if (i%j ==0) {
							hako[j] = hako[j] == 0 ? 1 : 0;
							if (i/j != j) {
								hako[i/j] = hako[i/j] == 0 ? 1 : 0;
							}
						}
					}
				}


			}
			//答えの出力
			Console.WriteLine(ans.Count());
			var sortedAns = ans.OrderBy(x =>x).ToArray();
			foreach (var item in sortedAns) {
			  Console.WriteLine(item);
			}

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


Measured memory_bytes: 49724
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a[5],k;
	scanf("%d %d %d %d",&a[1],&a[2],&a[3],&k);
	sort(a+1,a+4);
	a[3]*=pow(2,k);
	printf("%d\n",a[1]+a[2]+a[3]);
	return 0;
}

Measured memory_bytes: 384
import Foundation

func readInts() -> [Int] {
    readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let nab = readInts()
    let (n,a,b) = (nab[0],nab[1],nab[2])
    var ans = 0
        
    ans = n / (a + b) * a
    let rem = n % (a + b)
    ans += rem < a ? rem: a
    print(ans)
}
main()


Measured memory_bytes: 13444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    ll n, a, b;
    cin >> n >> a >> b;
    ll block = n / (a+b);
    ll amari = n % (a+b);
    ll ans = block * a + min(amari, a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        int a, b, c, k;

        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();
        k = scanner.nextInt();

        if(k <= a) {
            System.out.println(k);
        }
        else if(k <= a+b) {
            System.out.println(k-b);
        }
        else if (k <= a+b+c) {
            System.out.println(a-(k-(a+b)));
        }
    }
}

Measured memory_bytes: 35680
#include <iostream>
using namespace std;
long long int unco[105][4][4];
int deta[10125];
int main() {
	int n, k;
	long long int unchi = 0;
	cin >> n >> k;
	for (int i = 0; i < k; i++){
		int x, y;
		cin >> x >> y;
		deta[x] = y;
	}
	unco[0][0][0] = 1;
	for(int hi = 0; hi <= n; hi++) {
		for(int one = 0; one <= 3; one++){
			for(int two = 0; two <= 3; two++) {
				if(deta[hi]) {
					if(!(deta[hi] == one && one == two)) {
						unco[hi][deta[hi]][one] += unco [hi - 1][one][two];
						unco[hi][deta[hi]][one] %= 10000;
					}
				}
				else {
					for(int l = 1; l <= 3; l++) {
						if(!(l == one && one == two)) {
							unco[hi][l][one] += unco[hi - 1][one][two];
							unco[hi][l][one] %= 10000;
						}
					}
				}
			}
		}
	}
	for(int i = 1; i<=3; i++){
		for(int j = 1; j<=3; j++){
			unchi += unco[n][i][j];
			unchi %= 10000;
		}
	}
	cout << unchi % 10000<<endl;
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> P(N);
	REP(i, N) scanf("%d", &P[i]);
	
	int mn = INF, ans = 0;
	REP(i, N) if (chmin(mn, P[i])) ++ans;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
import heapq

n,m=map(int,input().split())
l=list(map(int,input().split()))
l=list(map(lambda x: -x,l))

heapq.heapify(l)

while m>0:
    a=heapq.heappop(l)
    if a//2==a/2:
        heapq.heappush(l,a//2)

    else:
        heapq.heappush(l,a//2+1)
    m=m-1

print(-sum(l))


Measured memory_bytes: 74520
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

ll comb(ll N_, ll C_) {
	const int NUM_ = 400001;
	static ll fact[400002], factr[400002], inv[400002];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mod, factr[i] = factr[i - 1] * inv[i] % mod;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mod*factr[N_ - C_] % mod;
}
ll modpow(ll a, ll n = mod - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mod, a = a * a%mod, n >>= 1;
	return r;
}

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

	int N, K; cin >> N >> K;
	VI A(N);
	REP(i, N)cin >> A[i];
	SORT(A);
	int ma = 0, mi = 0;
	if (K == 1) {
		cout << 0 << endl;
		return 0;
	}
	REP(i, N) {
		int cnt = comb(i, K - 1);
		ma += A[i] * cnt;
		ma %= mod;

		cnt = comb(N - i - 1, K - 1);
		mi += A[i] * cnt;
		mi %= mod;
	}
	cout << (ma - mi + mod) % mod << endl;
	return 0;
}



Measured memory_bytes: 10368
s = int(input())
t = int(input())
k = 0
#print(s,t)
if s == 1: 
  if t == 2:
    k = 3
  else:
    k = 2
elif s == 2:
  if t == 1:
    k = 3
  else:
    k = 1
else:
  if t == 2:
    k = 1
  else: 
    k = 2

print(k)


Measured memory_bytes: 2940
<?php

$blow = function ($a, $b) {
    for ($i = 0; $i < 4; $i++) {
        yield $a[$i] == $b[$i] ? 1 : 0;
    }
};
while (true) {
    list($r, $a) = explode(' ', trim(fgets(STDIN)));
    if (0 == $r && 0 == $a) break;

    $cnt = 0;
    $r_dash = str_split($r);
    $a_dash = str_split($a);
    foreach ($blow($r_dash, $a_dash) as $num) {
        $cnt += $num;
    }

    $answer = [];
    $answer[] = $cnt;
    $answer[] = 4 - count(array_diff($r_dash, $a_dash)) - $cnt;
    echo implode(' ', $answer) . PHP_EOL;
}


Measured memory_bytes: 9396
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder_Beginner_Contest_126
{
    class Program
    {
        struct tdst
        {
            public int top;
            public int dst;            
        }
        static void Main(string[] args)
        {
            var MK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var M = MK[0];
            var K = MK[1];
            var max = (long)Math.Pow(2, M);
            if (max <= K)
            {
                Console.WriteLine(-1);
                return;
            }
            if (1 == K & 1 == M)
            {
                Console.Write(-1);
                return;
            }
            if (0 == K)
            {
                for (long i = 0; i < max; ++i)
                {
                    Console.Write($"{i} {i} ");
                }
                return;
            }

            for (long i = 0; i < max; ++i)
            {
                if (i == K) continue;
                Console.Write($"{i} ");
            }
            Console.Write($"{K} ");
            for (long i = max - 1; 0 <= i; --i)
            {
                if (i == K) continue;
                Console.Write($"{i} ");
            }
            Console.Write($"{K} ");
        }
    }
}


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

int main(){
  int dp[45] = {};



  for(int i=0;i<45;i++){
    dp[i] =0;
  }

  dp[0] = 1;

  for(int i=0;i<40;i++){
    dp[i+1] += dp[i];
    dp[i+2] += dp[i];
    dp[i+3] += dp[i];
  }

  while(1){
    int a;
    a=0;
    cin >> a;
    if(a ==0)break;
    cout << dp[a] / 3650 + 1 << endl;

  }
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long int
#define mod 100000007
#define start int t;cin>>t;while(t--)
#define debug(x) cout<<"#"<<x<<"\n"
#define en "\n"
#define vi vector<int>
#define vli vector<long long int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define print_all(x) for(auto t:x) cout<<t<<" "; cout<<en
#define F first
#define S second
#define ss(s) scanf("%s",&s)
#define si(x) scanf("%d",&x)
#define sli(x) scanf("%lld",&x)
#define ss(s) scanf("%s",&s)
using namespace std;
ll mod_pow(ll x, int n){
    if(n == 0)      return 1;
 
    ll res = 1;
    while(n > 0){
        if(n & 1)   res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
 
    return res;
}
vector<ll> allDivisors(ll n) 
{ 
    vector<ll> v;
    for (ll i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            if (n/i == i) 
                v.pb(i);
  
            else {
                v.pb(i);
                v.pb(n/i);
            } 
        }
    }
    return v;
} 
//int hash[1001];
void solve(){
    int n;
    int a[33]={-5,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin>>n;
    cout<<a[n]<<en;
}

int main(){
    fast;
    //start{
        solve();
    //}
    return 0;
}



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

int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    int n, g, a;
    cin >> n >> g;
    for(int i = 1; i < n; i++){
        cin >> a;
        g = gcd(g, a);
    }
    cout << g << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <array>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <numeric>
#include <cassert>
#include <functional>
using namespace std;

typedef unsigned long long int llui;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
constexpr double pi = 3.141592653589793238462643383279502884L;
typedef tuple<int, int, char> iic;

// TODO: Mod class

const int sz = 1e3 + 10;

int C[2][2][sz][sz];

int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<iic> desire(n);
  for (auto& i : desire) {
    cin >> get<0>(i) >> get<1>(i) >> get<2>(i);
    int color = get<2>(i) == 'B' ? 0 : 1;
    int x = get<0>(i) % (k + k);
    int y = get<1>(i) % (k + k);
    int zone = !((x < k && y < k) || (x >= k && y >= k));
    bool valid = zone == color;
    ++C[color][valid][get<0>(i) % k][get<1>(i) % k];
  }

  for (int c = 0; c < 2; ++c) {
    for (int v = 0; v < 2; ++v) {
      for (int i = 0; i < k; ++i) {
        for (int j = 0; j < k; ++j) {
          if (i > 0) {
            C[c][v][i][j] += C[c][v][i - 1][j];
          }
          if (j > 0) {
            C[c][v][i][j] += C[c][v][i][j - 1];
          }
          if (i > 0 && j > 0) {
            C[c][v][i][j] -= C[c][v][i - 1][j - 1];
          }
        }
      }
    }  // for each valid
  }  // for each c

  int initv = C[0][1][k - 1][k - 1] + C[1][1][k - 1][k - 1];
  int initiv = C[0][0][k - 1][k - 1] + C[1][0][k - 1][k - 1];

  int ans = max(initv, initiv);
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= k; ++j) {
      int v = initv;
      int iv = initiv;
      if (i > 0) {
        v += -C[0][1][i - 1][k - 1] + C[0][0][i - 1][k - 1];
        v += -C[1][1][i - 1][k - 1] + C[1][0][i - 1][k - 1];

        iv += -C[0][0][i - 1][k - 1] + C[0][1][i - 1][k - 1];
        iv += -C[1][0][i - 1][k - 1] + C[1][1][i - 1][k - 1];
      }
      if (j > 0) {
        v += -C[0][1][k - 1][j - 1] + C[0][0][k - 1][j - 1]; 
        v += -C[1][1][k - 1][j - 1] + C[1][0][k - 1][j - 1]; 

        iv += -C[0][0][k - 1][j - 1] + C[0][1][k - 1][j - 1]; 
        iv += -C[1][0][k - 1][j - 1] + C[1][1][k - 1][j - 1]; 
      }
      if (i > 0 && j > 0) {
        v += C[0][1][i - 1][j - 1] * 2 - C[0][0][i - 1][j - 1] * 2;
        v += C[1][1][i - 1][j - 1] * 2 - C[1][0][i - 1][j - 1] * 2;

        iv += C[0][0][i - 1][j - 1] * 2 - C[0][1][i - 1][j - 1] * 2;
        iv += C[1][0][i - 1][j - 1] * 2 - C[1][1][i - 1][j - 1] * 2;
      }
      ans = max(ans, v);
      ans = max(ans, iv);
    }
  }

  cout << ans << endl;
}


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

int main() {
    int a,b;
    string s;
    cin >> a >> b;
    cin >> s;
    for(int i=0; i<a+b+1; i++) {
        if(!(i != a && s[i]>='0' && s[i]<='9')) {
            if(!(i==a && s[i] == '-')) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <queue>
#include <algorithm>
#include <map>
#include <iostream>

using namespace std;

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

  priority_queue<int> data;
  int t;
  for (int i=0; i<n; i++) {
    cin>>t;
    data.push(t);
  }

  while (m > 0) {
    if (data.size() == 0) break;
    m--;

    int now = data.top();
    data.pop();
    now /= 2;
    if (now > 0) data.push(now);
  }

  int64_t ans = 0;
  while (data.size() > 0) {
    int now = data.top();
    data.pop();
    ans += now;
  }
  cout<<ans<<endl;

  return 0;
}




Measured memory_bytes: 892
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = 0

    if a[0] > 0:
        print(-1)
        exit()

    # KeyInsight:
    # ◯: 2マスの値を比べる。
    #    右側 - 左側 = 1のときは、答えに1加算。
    #    同じ値のときは、その値を答えに加算。
    # ◯: a0以外のときと、2マスの差が2以上のときは、条件を満たさない。
    # △: 上記の考察を実装したが、10ケースWA。
    # △: 条件を満たさない場合を先に持ってくると、その後の条件がシンプルに。

    # See:
    # https://atcoder.jp/contests/agc024/submissions/15705631
    for pre, cur in zip(a, a[1:]):
        if pre + 1 < cur:
            print(-1)
            exit()

        if pre + 1 == cur:
            ans += 1
        else:
            ans += cur

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18628