akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll  long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
void solve()
{
    ll n,m,k,x,y,res=0,l,cnt=0,sum=0,z,sum1=0,cnt1=0,h,res1,cnt2=0;
   //cin>>n;
   string s1;
   cin>>s1;
   x=sz(s1);
   rep(i,0,x)
   {
       if(s1[i]=='A' || s1[i]=='C' || s1[i]=='T' || s1[i]=='G')
         cnt++;
       else
        cnt=0;
       res=max(res,cnt);
   }
   cout<<res;



}
int main()
{   speed_up
    ll t;
   // cin>>t;
    t=1;
    while(t--)
        solve();
}


Measured memory_bytes: 256
n,m=map(int,input().split())
s=input()
t=input()

from fractions import gcd

lcm=n*m//gcd(n,m)

if s[0]!=t[0]:
    print(-1)
    exit(0)

ans=lcm
# sについて
dn={}
for i in range(n):
    if i==0:
        dn[1]=s[i]
    else:
        dn[i*int((lcm)/n) +1]=s[i]

for j in range(m):
    if j==0:
        continue
    else:
        k = j*int(lcm/m) + 1

        if k in dn:
            if dn[k]!=t[j]:
                ans=-1
        else:
            dn[k]=t[j]

print(ans)





Measured memory_bytes: 17960
#include <bits/stdc++.h>
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-9
#define f first
#define s second
using namespace std;
int n;
int arr[100005][3];
ll memo[100005][3];
ll solve(int idx, int last){
    if (idx == n)
        return 0;
    ll &res = memo[idx][last];
    if(res != -1)
        return res;
    for(int i = 0; i < 3; ++i){
        if(i==last)
            continue;
        res = max(res, arr[idx][i]+solve(idx+1, i));
    }
    return res;
}
int main(){
    IO;
    cin >> n;
    memset(memo, -1, sizeof memo);
    for(int i = 0; i < n; ++i)
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    cout << solve(0, 3);
    return 0;
}


Measured memory_bytes: 13568
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
     
    while(x!=NIL){
        y=x;
        if(z->key < x->key) x=x->left;
        else x=x->right;
    }
    z->parent=y;
    if(y==NIL) root=z;
    else if(z->key < y->key) y->left=z;
    else y->right=z;
     
}
 
void inorder(Node u){
    if(u->left != NIL){
    inorder(u->left);
  }
  printf(" %d",u->key);
  if(u->right != NIL) inorder(u->right);
}
 
void preorder(Node u){
    printf(" %d",u->key);
    if(u->left != NIL){
        preorder(u->left);
    }
    if(u->right != NIL){
        preorder(u->right);
    }
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
 
  return 0;
}


Measured memory_bytes: 25172
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll n;
  cin >> n;
  ll l[100];
  l[0] = 2;
  l[1] = 1;
  for(int i=2;i<100;i++){
    l[i] = l[i-1]+l[i-2];
  }
  cout << l[n]<<endl;
}


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

int main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int>ac;
	for (int i = 1; i < s.length(); i++) {
		if (s.at(i - 1) == 'A' && s.at(i) == 'C') {
			ac.push_back(i - 1);
		}
	}
	for (int i = 0; i < q; i++) {
		ll l, r;
		cin >> l >> r;
		l--;
		r--;
		ll ans = (lower_bound(ac.begin(), ac.end(), r) - ac.begin()) - (lower_bound(ac.begin(), ac.end(), l) - ac.begin());
		cout << ans << endl;
	}
}

Measured memory_bytes: 1276
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, K; cin >> N >> K;
	vector<bool>Snuke(N, false);
	for (int i = 0; i < K; i++) {
		int num = 0; cin >> num;
		for (int j = 0; j < num; j++) {
			int sn; cin >> sn;
			Snuke.at(sn - 1) = true;
		}
	}
	int nas = 0;
	for (int i = 0; i < N; i++) {
		if (!Snuke.at(i))nas++;
	}
	cout << nas << endl;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A = int(input())
B = int(input())

for i in range(1, 4):
    if i not in (A, B):
        print(i)




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

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

    int h, n;
    cin >> h >> n;

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

    const int INF = 1001001001;
    vector<int> dp(22000, INF);
    dp[0] = 0;
    rep1(i, 22000){
        rep(j, n){
            if(a[j] <= i) dp[i] = min(dp[i], dp[i-a[j]] + b[j]);
        }
    }

    int res = INF;
    for(int i = h; i < 22000; ++i) res = min(res, dp[i]);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    int S, W;
    cin >> S >> W;
    if(S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

string a[510];

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

    ll N;
    cin >> N;
    REP(i, N){
    	cin >> a[i];
    }

    vector<ll> w(N, 0);
    bool ok = false;
    REP(i, N){
    	REP(j, N){
    		w[i] += (a[i][j]=='.');
    		if(a[i][j] == '#') ok = true;
    	}
    }
    if(!ok){
    	cout << -1 << endl;
    	return 0;
    }

    vector<ll> isb(N);
    ll ato = 0;
    REP(j, N){
    	ll tmp = 0;
    	REP(i, N){
    		if(a[i][j]=='#') tmp++;
    	}
    	isb[j] = (tmp>0 ? 0 : 1);
    	if(tmp<N) ato++;
    }

    ll res = (1ll<<60);
    REP(i, N) res = min(res, w[i]+isb[i]);
    cout << res + ato << endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N,A;
    cin>>N>>A;
    v x(N);
    v p,m,z;
    rep(i,0,N){
        cin>>x[i];x[i]-=A;
        if(x[i] > 0)p.PB(x[i]);
        if(x[i] == 0)z.PB(x[i]);
        if(x[i] < 0)m.PB(-x[i]);
    }
    sort(all(p));
    sort(all(m));
    v p_sum(2501);
    v m_sum(2501);
    p_sum[0] = 1;
    m_sum[0] = 1;
    rep(i,0,p.size()){
       for(ll j = 2500; j>=0; j--){
            if(j+p[i] <= 2500)p_sum[j+p[i]] += p_sum[j];
        }
    }
    rep(i,0,m.size()){
        for(ll j = 2500; j>=0; j--){
            if(j+m[i] <= 2500)m_sum[j+m[i]] += m_sum[j];
        }
    }
    ll zN = z.size();
    ll n2 = 1;
    rep(i,0,zN)n2 *= 2;
    ll ans = 0;
    rep(i,1,2501){
        ans += p_sum[i] * m_sum[i];
    }
    cout<<n2-1 + n2 * ans;
    return 0;
}

Measured memory_bytes: 256
# C
N, M = map(int, input().split())
hight_list = list(map(int, input().split()))
non_good = []
for i in range(M):
    a, b = map(int, input().split())
    if (hight_list[a-1] > hight_list[b-1]):
        non_good.append(b-1)
    elif(hight_list[a-1] == hight_list[b-1]):
        non_good.append(a-1)
        non_good.append(b-1)
    else:
        non_good.append(a-1)

print(N - len(set(non_good)))

Measured memory_bytes: 20040
N=int(input())
A=[int(x) for x in input().split()]
#重複始点終点調査
se=[]
c=sum(A)-N*(N+1)/2
for i in range(len(A)):
  if A[i]==c:
    se.append(i)
l=se[0]
r=se[1]

mod=10**9+7
 
#階乗計算
factorial=[1]
inverse=[1]
for i in range(1,N+2):
    factorial.append(factorial[-1]*i %mod)
    inverse.append((pow(factorial[i], mod-2, mod)))
#combination計算
def nCr(n,r):
  if n<r or n==0 or r==0:
    return 0
  return factorial[n] * inverse[r] * inverse[n-r] % mod

print(N)
for i in range(2,N+2):
    print(int(nCr(N+1,i)-nCr(l+N-r,i-1))%mod)


Measured memory_bytes: 17112
//organize and stay in moment - Abhinav IIIT-A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,x,n) for(int i=x;i<n;++i)
#define ar array
#define MAXN (int)2e5+5
#define pb push_back
int mod= 998244353;
int arr[MAXN];
int as;
void input(){
  cin>>as;
  f(i,0,as) cin>>arr[i];
}
void q1(){
  string s; cin>>s;
  int a=0,b=0;
  f(i,0,3)
  s[i]=='A'  ? ++a : ++b;
  if(a&&b)
    cout<<"Yes";
  else cout<<"No";
}
void q2(){
  int n,a,b;
  cin>>n>>a>>b;
  int t=a+b;
  int q=n/t;
  int ans=q*a;
  int r=n%t;
  ans+=min(r,a);
  cout<<ans;
}
void q3(){
  int a,b; cin>>a>>b;
  for(int i=1;i<=100000;++i){
    int x=i*8; x/=100;
    int y=i*10; y/=100;
    if(x==a && y==b){
      cout<<i;
      return ;
    }
  }
  cout<<-1;
}
void q4(){
  string s; cin>>s;
  deque<int> q;
  f(i,0,s.size())
  q.push_back(s[i]);
  int Q; cin>>Q;
  int curr=0; 
  //wtf....
  while(Q--){
    int t;
    cin>>t;
    if(t==1){
      curr=1-curr;
    }else{
      int f;char c; cin>>f>>c;
      if(curr==0 && f==1)
        q.push_front(c);
      else if(curr==0 && f==2)
        q.push_back(c);
      else if(curr==1 && f==1)
        q.push_back(c);
      else q.push_front(c);
    }
    //cout<<curr<<" ";
    
  }
  string ret="";
  while(!q.empty()){
    ret+=q.front();
    q.pop_front();
  }
//  cout<<curr<<" ";
  if(curr)
     reverse(ret.begin(),ret.end());
   cout<<ret;
   return ;
}
void q5(){
  int n,p; cin>>n>>p;
  string s; cin>>s;
  int ans=0;
  if(p==2){
    f(i,0,n)
    if((s[i]-'0')%2==0)
      ans+=i+1;
  }else if(p==5){
    f(i,0,n)
    if((s[i]-'0')%5==0)
      ans+=i+1;
  }else {
    int tt=1;
    int curr=0;
     map<int,int> mp;
     mp[0]++;
     for(int i=n-1;i>=0;--i){
        curr+=(s[i]-'0')*tt;
        tt*=10;
        tt%=p; curr%=p;
        ans+=mp[curr];
        ++mp[curr];
     }
  }
  cout<<ans;
}
int mod2=998244353;
void solve(){
 
}
int32_t main()
{
  int t; t=1; //cin>>t;
  while(t--) q4();
  return 0;
}


Measured memory_bytes: 3464
from sys import exit
import math

N, K = map(int, input().split())

a = 0
b = []

for i in range(N):
    if i + 1 == K:
        # 考えなくていいもの
        a = N - K + 1
        break

    if math.ceil(math.log2(K / (i + 1))) >= 0:
        b.append(1/N * (1/2)**math.ceil(math.log2(K / (i + 1))))
    else:
        b.append(1/N)

ans = a / N + sum(b)

print(ans)


Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    int year = ((s[0]-'0')*10+s[1]-'0');
    int month = ((s[2]-'0')*10+s[3]-'0');
    if(1 <= month && month <= 12){
        if(1 <= year && year <= 12){
            cout << "AMBIGUOUS" << endl;
        }
        else{
            cout << "YYMM" << endl; 
        }
    }    
    else{
        if(1 <= year && year <= 12){
            cout << "MMYY" << endl;
        }
        else cout << "NA" << endl;
    }
    return 0;
}

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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef complex<double> com;

#define endl '\n'
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;

void test()
{
	int i,j;
	string s;
	cin>>s;
	for(i=0;i<s.length();i++)
	{
		if(s[i]=='A')
			break;
	}
	for (j=s.length()-1;j>0;j--)
	{
		if(s[j]=='Z')
			break;
	}
	cout<<j-i+1;
}

int main()
{   
fast_io();
cout << fixed << setprecision(15);
int t = 1;

//cin>>t;

for(int i = 0; i < t; i++)
{
	test();
}
return 0;
}

Measured memory_bytes: 720
// ctrl+shift+b
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    if (N == 1){
        cout << "Hello World" << endl;
    } else {
        ll a, b; cin >> a >> b;
        cout << a + b << endl;
    }
}

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


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

ll n;
int dfs(ll x, bool b3,bool b5, bool b7){
    if(x>n) return 0;
    int ret=0;
    if(b3&&b5&&b7) ret++;
    ret += dfs(x*10+3,true,b5,b7);
    ret += dfs(x*10+5,b3,true,b7);
    ret += dfs(x*10+7,b3,b5,true);
    return ret;
}

int main(){
    cin>>n;
    ll ans = dfs(0,false,false,false);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string N;
  cin >> N;
  if(N[0]==N[1] && N[1]==N[2] || N[1]==N[2] && N[2]==N[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;

namespace AtCoder_Beginner_Contest_131
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var pass = ReadLine();
            char pre = 'a';
            foreach(var c in pass)
            {
                if (pre == c)
                {
                    WriteLine("Bad");
                    return;
                }
                pre = c;
            }
            WriteLine("Good");
        }
    }
}


Measured memory_bytes: 13140
package main

import "fmt"

func main() {
	var (
		k int
	)
	fmt.Scan(&k)

	array := []int{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}

	fmt.Println(array[k-1])
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;

const int mod=1e9+7;
const int maxn=5111;

vector<int> g[maxn];
int n,dp[maxn][maxn],way[maxn],sz[maxn],tmp[maxn];

void dfs(int x,int f)
{
	dp[x][1]=1;sz[x]=1;
	for(auto v:g[x])if(v!=f)
	{
		dfs(v,x);
		memset(tmp,0,sizeof(tmp));
		for(int i=0;i<=sz[x];i++)for(int j=0;j<=sz[v];j++)tmp[i+j]=(tmp[i+j]+(LL)dp[x][i]*dp[v][j])%mod;
		sz[x]+=sz[v];
		for(int i=0;i<=sz[x];i++)dp[x][i]=tmp[i];
	}
	for(int i=2;i<=sz[x];i+=2)
	{
		dp[x][0]-=(LL)dp[x][i]*way[i/2]%mod;
		if(dp[x][0]<0)dp[x][0]+=mod;
	}
}

int main()
{
	way[0]=1;
	for(int i=1;i<maxn;i++)way[i]=(LL)way[i-1]*(i+i-1)%mod;
	
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1,0);
	printf("%d\n",(mod-dp[1][0])%mod);
	return 0;
}

Measured memory_bytes: 100608
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

const int INF = 1 << 29;

int N, M; 

vector<int> graph[101010];

set<pair<int, int>> edges;

int main() {
    cin >> N >> M;
    for (int j = 0; j < M; ++j) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);

        if (a > b) swap(a, b);
        edges.emplace(a, b);
    }

    int dist[101010];
    fill(dist, dist+N, INF);
    dist[0] = 0;

    queue<pair<int, int>> q;
    q.emplace(0, 0);
    int v, d;
    while (!q.empty()) {
        tie(v, d) = q.front();
        q.pop();

        for (const int w : graph[v]) {
            if (dist[w] == INF) {
                dist[w] = d+1;
                q.emplace(w, d+1);
            }
        }
    }

    bool f = false;
    for (pair<int, int> e: edges) {
        if (dist[e.first] == dist[e.second]) {
            f = true;
            break;
        }
    }

    if (f) {
        cout << ((i64)N*(N-1)/2-M) << endl;
        return 0;
    }

    int re[101010], ss[101010];
    fill(re, re+101010, 0);
    for (int j = 0; j < N; ++j) {
        ++re[dist[j]];
    }

    for (int j = N; j >= 0; --j) {
        ss[j] = re[j] + ss[j+2];
    }

    i64 ans = -M;
    for (int j = 0; j < N; ++j) {
        ans += re[j] * (re[j+1] + ss[j+3]);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;

struct node {
  int key;
  node *parent,*right, *left;
};
typedef node* nodep;
nodep root,NIL;
void insert(int key){
  nodep y=NIL,x=root,z=(nodep)malloc(sizeof(node));
  z->key=key;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else{
    if(z->key<y->key)y->left=z;
    else y->right=z;
    }
}
nodep find(nodep d,int key){
  while(d!=NIL&&d->key!=key){
    if(key<d->key)d=d->left;
    else d=d->right;
  }
  return d;
}
void inorder(nodep u){
  if(u==NIL)return;
  inorder(u->left);
  cout<<" "<<u->key;
  inorder(u->right);
}
void preorder(nodep u){
  if(u==NIL)return;
  cout<<" "<<u->key;
  preorder(u->left);
  preorder(u->right);
}
int main(){
  string buf;
  int a,n;
  cin>>n;
  rep(i,n){
    cin>>buf;
    if(buf[0]=='i'){
      cin>>a;
      insert(a);
    }
    else if(buf[0]=='f'){
      cin>>a;
      if(find(root,a)==NIL)cout<<"no"<<endl;
      else cout<<"yes"<<endl;
    }
    else{
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
  }


  return 0;
}


Measured memory_bytes: 21888
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    for (int i=1;i<n;i++){
        int v=a[i];
        int j=i-1;
        for (int k=0;k<n-1;k++){
                cout<<a[k]<<" ";
        }
        cout<<a[n-1]<<endl;
        while(j>=0&&a[j]>v){
            int t=a[j+1];
            a[j+1]=a[j];
            a[j]=t;
            j--;
        }
        a[j+1]=v;
    }
    for (int k=0;k<n-1;k++){
        cout<<a[k]<<" ";
    }cout<<a[n-1]<<endl;
    return 0;
}


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

int q;
string X, Y;
vector< vector<int> > L;

int rec(int i, int j){
  if(i < 0 || j < 0)
    return 0;
  else{
    if(L[i][j] < 0){
      if(X[i] == Y[j])
        L[i][j] = 1+rec(i-1, j-1);
      else
        L[i][j] = max(rec(i, j-1), rec(i-1, j));
    }
    return L[i][j];
  }
}

int main(){
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> X >> Y;
    int m=X.length(), n=Y.length();
    L.assign(m, vector<int>(n, -1));
    int ans;
    ans= rec(m-1, n-1);
    cout << ans << endl;
  }
}


Measured memory_bytes: 6752
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
if len(s)%2==1:
    print('No')
else:
    for i in range(len(s)):
        if s[i]!=('h' if i%2==0 else 'i'):
            print('No')
            exit()
    print('Yes')


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main(void) {
  long N, Y;
  cin >> N >> Y;

  Y -= 1000 * N;
  for (long i = 0; i <= N; i++) {
    long tmp = Y - 4000 * i;
    if (tmp < 0) continue;
    if (tmp % 5000 == 0 and (tmp / 5000) <= i) {
      cout << tmp / 5000 << " " << i - tmp / 5000 << " " << N - i << endl;
      return 0;
    }
  }

  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
l = []
for i in range(3, n + 1):
    if i % 3 == 0:
        l.append(i)
    else:
        x = i
        while x:
            if x % 10 == 3:
                l.append(i)
                break
            else:
                x = x // 10
print("", *l)

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

int main(){

  int n,m;
  cin>>n>>m;
  ll ans;
  ans = (n*100+m*1800)*pow(2,m);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		if(n==1) System.out.println(k);
		else {
			Map<Integer,List<Integer>> map = new HashMap<>();
			for(int i=0;i<n-1;i++) {
				int a = in.nextInt();
				int b = in.nextInt();
				if(map.containsKey(a)) map.get(a).add(b);
				else {
					List<Integer> list = new ArrayList<>();
					list.add(b);
					map.put(a, list);
				}
				if(map.containsKey(b)) map.get(b).add(a);
				else {
					List<Integer> list = new ArrayList<>();
					list.add(a);
					map.put(b, list);
				}
			}
			
			long ans = k;
			long mod = 1000000007;
			Deque<Integer> que = new ArrayDeque<>();
			
			boolean[] used = new boolean[n+1];
			
			List<Integer> list = map.get(1);
			for(int i=0;i<list.size();i++) {
				que.add(list.get(i));
				ans = (ans * (k-1-i))%mod;
			}
			used[1] = true;
			
			while(!que.isEmpty()) {
				int tmp = que.poll();
				if(!used[tmp]) {
					list = map.get(tmp);
					for(int i=0;i<list.size();i++) {
						que.add(list.get(i));
					}
					for(int i=0;i<list.size()-1;i++) {
						ans = (ans * (k-2-i))%mod;
					}
					used[tmp] = true;
				}
			}
			System.out.println(ans);
		}
		in.close();

	}

}


Measured memory_bytes: 108704
n = int(input())
ab = []

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

ba = list(sorted(ab))


now = 0
bad = False
for b, a in ba:
    now += a
    if now <= b:
        pass
    else:
        bad = True
        break

if bad:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 31748
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
	int n, m;
	int maximum;
	int a[1000];
	while(true) {
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		maximum = 0;
		for (int j = 0; j < n; j++) {
			cin >> a[j];
		}
		for (int j = 0; j < n - 1; j++) {
			for (int t = j + 1; t < n; t++) {
				if (a[j] + a[t] <= m) {
					maximum = max(maximum, a[j] + a[t]);
				}
			}
		}
		if (maximum == 0) {
			cout << "NONE" << endl;
		}
		else {
			cout << maximum << endl;
		}
	}

}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin>>n;
ll a[n];
bitset<33> b[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
b[i]=a[i];
}
ll fr[n],bk[n];
fr[0]=a[0];
bk[n-1]=a[n-1];
for(int i=1;i<n;i++)
fr[i]=fr[i-1]^a[i];
for(int i=n-2;i>=0;i--)
bk[i]=bk[i+1]^a[i];
cout<<bk[1]<<" ";
for(int i=1;i<n-1;i++)
{
	ll x=bk[i+1]^fr[i-1];
cout<<x<<" ";
}
cout<<fr[n-2]<<" ";
return 0;
}
// Problem : E - Red Scarf
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



Measured memory_bytes: 9760
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;

int main() {
    int K, now = 9;
    cin >> K;
    vector<int64_t> A(1000000);
    for (int i = 0; i < 9; i++){
        A.at(i) = i + 1;
    }
    for (int i = 0; i < K; i++){
        if (A.at(i) % 10 == 0){
            A.at(now) = A.at(i) * 10;
            now++;
            A.at(now) = A.at(i) * 10 + 1;
            now++;
        }
        else if (A.at(i) % 10 == 9){
            A.at(now) = A.at(i) * 10 + 8;
            now++;
            A.at(now) = A.at(i) * 10 + 9;
            now++;
        }
        else {
            A.at(now) = A.at(i) * 10 + A.at(i) % 10 - 1;
            now++;
            A.at(now) = A.at(i) * 10 + A.at(i) % 10;
            now++;
            A.at(now) = A.at(i) * 10 + A.at(i) % 10 + 1;
            now++;
        }
        if (now > K){
            break;
        }
    }
    cout << A.at(K - 1) << endl;

}

Measured memory_bytes: 8064
fun main(args: Array<String>) {
    val l = readLine()!!.toString().map { it.toInt() - 48}
    var black = 0
    var white = 0
    for(i in 0 until l.count()){
        if (i % 2 != l[i]) black += 1
        else white += 1
    }
    print(Math.min(black, white))
}

Measured memory_bytes: 34240
S = input()
S_tmp = []
for c in S:    
    if c in "ACGT":
        S_tmp.append(1)   
    else:
        S_tmp.append(0)    
        
ans = 0 
for l in range(len(S)):
    for r in range(l+1,len(S)+1):
        if sum(S_tmp[l:r])==(r-l):
            ans = max(ans,r-l)
print(ans)  

Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      String S = sc.next();
      int[] A = new int[N];
      int rCount = 0;
      int gCount = 0;
      int bCount = 0;
      for(int i=0;i<N;i++){
        A[i] = S.charAt(i);
        if(A[i]=='R'){
          rCount++;
        }else if(A[i]=='G'){
          gCount++;
        }else{
          bCount++;
        }
      }
      long ans = (long)rCount*gCount*bCount;
      for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
          int k = j+j-i;
          if(k<N && A[i]!=A[j] && A[i]!=A[k] && A[j]!=A[k]){
            ans--;
          }
        }
      }      
      System.out.println(ans);
    }
}

Measured memory_bytes: 36072
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2197>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int N;
ll solve(){
    ll res = 0;
    for(int i = 1; i <= N;i++){
        int T = i;
        for(int j = i + 1; j <= N;j++){
            T += j;
            if(T == N){
                res++;
                break;
            }
            if(T > N) break;
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> N,N){
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3004
#include<bits/stdc++.h>
#include<sstream>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define loop(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revloop(i,a,b) for(i=(int)a;i>=(int)b;i--)
#define stloop(it,v) for(it=v.begin();it!=v.end();++it)
#define ii pair<int,int>
#define MP make_pair
#define pb push_back
#define ll long long int
#define PI acos(-1.0)
#define f first
#define se second
#define rs resize
int main()
{  std::ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long double a;
   cin>>a;
   a=(-1.0+sqrt(1.0+8*a))/2.0;
   if(a==(int)a)
    cout<<a;
   else
    cout<<(int)a+1;
   return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  if (S == U) {
    cout << A - 1 << " " << B << endl;
  } else {
    cout << A << " " << B - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){
    int a, b;
    cin >> a >> b;
    cout <<(a-1)*(b-1) fin;
    
    return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int count( vector<vector<char>>& table){
    int count = 0;
    for(int i = 0 ; i < table.size(); i++ ){
        for(int j = 0 ; j < table[i].size(); j++ ){
            if( table[i][j] == '#'  ) count++;
        }
    }
    return count;
}

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll H, W, K;

    cin >> H >> W >> K;

    vector<vector<char>> table(H, vector<char>(W));
    REP(i, H){
        REP(j, W){
            char c;
            cin >> c;
            table[i][j] = c;
        }
    }
    ll total= 0;
    for(int i = 0; i < (1<<H); i++ ){
            for(int j = 0; j < (1<<W); j++ ){
                    vector<vector<char>> tmp = table;
                    for(int I = 0 ; I < H; I++){
                        if(i & (1<<I)) {
                                for( int jj = 0; jj < W; jj++){
                                    tmp[I][jj] = '!';
                                }
                        }
                    }
                    for(int J = 0 ; J < W; J++){
                        if(j & (1<<J)) {
                                for( int ii = 0; ii < H; ii++){
                                    tmp[ii][J] = '!';
                                }
                        }
                    }
                    if( count(tmp) == K ){
                        total++;
                    }
            }
    }
    cout << total << endl;
}

Measured memory_bytes: 3628
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e7;
const int MOD=1e9+7;
const int MAAX=1e15;
const long double EPS=1e-6;
const int N=1e6;
int prime(int x){
    if(x<2)
        return 0;
    for(int i=2;i*i<=x;i++){
        if(x%i==0)
            return 0;
    }
    return 1;
}
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2)%MOD;
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a % MOD * a % MOD;
}
long double sq(int x){
    long double s=0,e=x,mid;
    while(e-s>=EPS){
        mid=(s+e)/2;
        if(mid*mid<=x){
            s=mid;
        }
        else{
            e=mid-EPS;
        }
    }
    return s;
}
vector<int> primes;
bool visted[N+5];
void sieve(){
    visted[0]=visted[1]=1;
    for(int i=2;i*i<=N;i++){
        if(visted[i]==0){
            primes.pb(i);
            for(int j=i*i;j<=N;j+=i){
                visted[j]=1;
            }
        }
    }
    for(int i=sqrt(N)+1;i<=N;i++){
        if(visted[i]==0)
            primes.pb(i);
    }
    return;
}
int check(int x){

}
int ternary(int s,int e){
    int mid,mid2;
    while(s+3<e){
        mid=s+(e-s)/3;
        mid2=s+(e-s)/3*2;
        if(mid>=mid2)
            e=mid2;
        else{
            s=mid;
        }
    }
    int mx=0;
    while(s<e){
        mx=max(mx,check(s));
        s++;
    }
    return mx;
}
int binary(int s,int e){
    int mid;
    while(s<e){
        mid=ceil((s+e)/2.0);
        if(check(mid))
            s=mid;
        else
            e=mid-1;
    }
    return s;
}

int s[20][20],k[20],p[20],fr[20][20];

in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //sieve();
    //scanf("%lld",&tc);
    while(tc--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=0;i<m;i++){
            cin>>k[i];
            for(int j=0;j<k[i];j++){
                cin>>s[i][j];
                fr[i][s[i][j]]=1;
            }
        }
        for(int i=0;i<m;i++)
            cin>>p[i];
        int lim=power(2,n),ans=0;
        for(int i=0;i<lim;i++){
            int freq[20]={0};
            for(int j=0;j<n;j++){
                if((i>>j)&1)
                for(int k=0;k<m;k++)
                    if(fr[k][j+1])
                        freq[k]++;
            }
            bool bol=1;
            for(int j=0;j<m;j++){
                bol&=(freq[j]%2==p[j]%2);
            }
            ans+=bol;
        }
        cout<<ans<<endl;
    }
    RETURN;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <unordered_map>

using namespace std;

const int64_t MOD = 998244353;

int main() {
	int n;
	cin >> n;
	vector<int> as;
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		as.push_back(a);
		sum += a;
	}
	vector<int64_t> dp(sum+1,0);
	dp[0] = 1;
	for (auto val : as) {
		vector<int64_t> ndp(sum + 1, 0);
		for (int i = 0; i <= sum; ++i) {
			if(i+val <= sum)
				ndp[i + val] = (ndp[i + val]+dp[i])%MOD;
			ndp[i] = (ndp[i]+ (2 * dp[i])%MOD)%MOD;
		}
		dp = ndp;
	}
	int64_t invalid_pat = 0;
	for (int i = sum / 2+1; i <= sum; ++i) {
		invalid_pat = (invalid_pat + dp[i]) % MOD;
	}
	int64_t whole_pat = 1;
	for (int i = 0; i < n; ++i) {
		whole_pat = (3 * whole_pat) % MOD;
	}
	int64_t correct_pat = (whole_pat + ((MOD - invalid_pat)*3)%MOD ) % MOD;
	if (sum % 2 == 0) {
		int64_t cov = dp[sum / 2];
		correct_pat = (correct_pat + ((MOD - cov) * 3) % MOD) % MOD;

		vector<int64_t> tdp(sum + 1, 0);
		tdp[0] = 1;
		for (auto val : as) {
			vector<int64_t> tndp(sum + 1, 0);
			for (int i = 0; i <= sum; ++i) {
				if (i + val <= sum)
					tndp[i + val] = (tndp[i + val] + tdp[i]) % MOD;
				tndp[i] = (tndp[i] + tdp[i]) % MOD;
			}
			tdp = tndp;
		}
		int64_t cov2 = tdp[sum / 2];
		correct_pat = (correct_pat + (cov2 * 3) % MOD) % MOD;
	}
	cout << correct_pat << endl;
	return 0;
}

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

using namespace std;

int main()
{
    long long int n = 0, a = 0, sum = 0;
    
    vector<long long> persoane;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a;
        persoane.push_back(a);
    }
    for (int i = 0; i < n-1; i++) {
        if (persoane[i] <= persoane[i + 1]) {
            sum += 0;
        }
        else {
            sum += (persoane[i] - persoane[i + 1]);
            persoane[i + 1] = persoane[i];
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 5356
n, m = gets.split.map(&:to_i)
s = Array.new(m, 0)
m.times do |i|
  b = gets.split.map(&:to_i)[1..-1]
  b.each do |x|
    s[i] |= (1 << (x - 1))
  end
end
p = gets.split.map(&:to_i)


bits = Array.new(2 ** n, 0)
(2 ** n).times do |x|
  y = x
  while y != 0
    bits[x] += 1 if (y & 1) != 0
    y = y >> 1
  end
end

ans = 0
(2 ** n).times do |x|
  c = 0
  m.times do |i|
    c += 1 if bits[x & s[i]] % 2 == p[i] 
  end
  ans += 1 if c == m
end
puts ans



Measured memory_bytes: 1788
#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 gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
    ll A, B;
    cin >> A >> B;
    cout << (A * B) / gcd(A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

// (x, y) を始点とした BFS をして、(x, y) から最も遠いマスへの距離を答える
int bfs(const vector<string> &v, ll x, ll y) {
    ll H = v.size(), W = v[0].size();
    vvl dist(H, vl(W, -1));//-1で埋める
    queue<pair<ll,ll>> que;

    ll res = 0;
    que.push(make_pair(x,y));
    dist[x][y] = 0;
    while (!que.empty()) {
        ll x = que.front().first, y = que.front().second;
        res = max(res, dist[x][y]);
        que.pop();
        rep(dir,4){
            ll nx = x+ dx[dir], ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (v[nx][ny] == '.'&&dist[nx][ny]==-1){ //未探索の道なら
                dist[nx][ny] = dist[x][y] + 1; //前のマス+1
                que.push({nx, ny}); //4方位をqueueに追加
            }
        }
    }
    return res;
}
ll ans=0;
int main() {
     SS(string,S,s)
     p(s+S);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N,M;
    cin >> N >> M;
    int* K;
    K = new int [N];
    int **A = new int *[N];        
  	for(int j=0;j<N;j++){
            A[j] = new int [M];
        }
    for(int i=0;i<N;i++){
        cin >> K[i];
      	for(int j=0;j<K[i];j++){
            cin >> A[i][j];
        }
    }
    int *count;
    count = new int [M];
    for(int i=0;i<N;i++){
        for(int j=0;j<K[i];j++){
            count[A[i][j]-1]++;
        }
    }
    int kindnum = 0;
    for(int i=0;i<M;i++){
        if(count[i]==N){
            kindnum++;
        }
    }
  	cout << kindnum <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K,Q; cin>>N>>K>>Q;
  vector<int> A(Q);
  vector<int> B(N);
  for(int i = 0; i < Q; i++){
    cin >> A.at(i);
    B.at(A.at(i)-1)++;
  }
 // cout << A.at(1);
  for (int i = 0; i < N; i++) {
    if(Q-B.at(i)< K) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1408
import itertools
N = int(input())
a = list(map(int,input().split()))
count=0
for a in list(itertools.combinations(a,3)):
  if a[0]!=a[1] and a[1]!=a[2] and a[0]!=a[2]:
    if a[1]+a[2]>a[0] and a[0]+a[2]>a[1] and a[0]+a[1]>a[2]:
      count+=1
  
print(count)

Measured memory_bytes: 20612
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1100100100;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> coin(m);
    for(int i = 0; i < m; i++) cin >> coin[i];
    
    vector<int> memo(n+10, INF);
    memo[0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < m; j++){
            if(i-coin[j] >= 0 && memo[i-coin[j]]+1 < memo[i]){
                memo[i] = memo[i-coin[j]]+1;
            }
        }
    }
    
    cout << memo[n] << endl;
    return 0;
}


Measured memory_bytes: 3180
n, m, c = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)
a_ary = []
n.times do
  a_ary.push(gets.chomp.split(" ").map(&:to_i))
end
sum = 0
count = 0
a_ary.each_with_index do |a, index|
  m.times do |num|
    sum += a[num] * b[num]
  end
  sum += c
  if sum > 0
    count += 1
  end
  sum = 0
end
puts count

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

int main()
{
    const double pi = 3.141592653589793238;
    double a, b, h, m;
    cin >> a >> b >> h >> m;
  
    // with reference to 12:00  
    double hour_angle = 0.5 * (h * 60 + m);  
    double minute_angle = 6 * m;  
  
    double angle = abs(hour_angle - minute_angle);  
  
    angle = min(360 - angle, angle);
    cout << setprecision(15) << sqrt(a*a + b*b - 2*a*b*cos(angle * pi / 180));

    return 0;
}

Measured memory_bytes: 4200