akhauriyash/Code-Regression huggingface dataset:
#include <iostream>                                             
#include <cmath>                                                
using namespace std;                                            
                                                                
bool isprime(int x) {                                           
  if (x==2) {                                                   
    return true;                                                
  }                                                             
  if (x<2 || x%2==0) {                                          
    return false;                                               
  }                                                             
  int i=3; //for (i=3; i*i<=x; i+=2) {                          
  while (i<=sqrt(x)) { // i=???x                                 
    if (x%i==0) {                                               
      return false;                                             
    }                                                           
    i+=2;                                                       
  }                                                             
  return true;                                                  
}                                                               
                                                                
int main(void) {                                                
  int n;                                                        
  cin >> n;                                                     
  int a, ans=0;                                                 
  for (int i=0; i<n; i++) {                                     
    cin >> a;                                                   
    if (isprime(a)) {                                           
      ans++;                                                    
    }                                                           
  }                                                             
    cout << ans << endl;                                        
                                                                
}                                                               
                      

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int n,k,q,tag[2005],a[2005],ans=2e9;
pair<int,int>lis[2005];
int solve()
{
	vector<int>vec,cnt,vec2,vec3;
	for(int i=0;i<=n+1;++i)if(tag[i])vec.push_back(i);
	int tot=0,mi=2e9;
	for(int i=0;i<vec.size()-1;++i)tot+=max(0,vec[i+1]-vec[i]-k),cnt.push_back(max(0,vec[i+1]-vec[i]-k));
	if(tot<q)return 1;
	for(int i=0;i<cnt.size();++i)
	{
		if(cnt[i])
		{
			vec2.clear();
			for(int j=vec[i]+1;j<vec[i+1];++j)mi=min(mi,a[j]),vec2.push_back(a[j]);sort(vec2.begin(),vec2.end());
			for(int j=0;j<cnt[i];++j)vec3.push_back(vec2[j]);
		}
	}
	sort(vec3.begin(),vec3.end());
	//for(int i=0;i<vec3.size();++i)cout<<vec3[i]<<" ";cout<<endl;
	ans=min(ans,vec3[q-1]-vec3[0]);
	return 0;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>k>>q;for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n;++i)lis[i]={a[i],i};
	sort(lis+1,lis+1+n);tag[0]=tag[n+1]=1;
	ans=lis[q].first-lis[1].first;
	for(int i=1;i<=n;++i)
	{
		//cout<<i<<" "<<ans<<endl;
		tag[lis[i].second]=1;
		if(solve())break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	String trim(String tar){
		String ret = "";
		for(char ch:tar.toCharArray()){
			if("()[]".indexOf(ch) >=0){
				ret = ret + "()[]".indexOf(ch);
			}
		}
		return ret;
	}
	void run() {
		for (;;) {
			String buffer = sc.nextLine();
			if (buffer.equals(".")) {
				break;
			}
			buffer = trim(buffer);
			
			for(int i =0 ;i < 50;i++){
				buffer = buffer.replace("01","");
				buffer = buffer.replace("23","");
			}
			boolean ok = buffer.length() ==0;
			System.out.println(ok?"yes":"no");
		}
	}

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string>) {}
template<typename T1,typename T2> ostream& operator<<(ostream& os, pair<T1,T2> buf) {
  return os << "(" << buf.first << ": " << buf.second << ")"; }
#define DefOut(Con) template<typename T>ostream&operator<<(ostream&os,Con<T>&A){ bool f = false; os << "{"; \
  for (const auto e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
#define DefOut2(Con) template<typename K,typename V>ostream&operator<<(ostream&os,Con<K,V>&A) \
{ bool f = false; os << "{"; for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
template<typename T>ostream &operator << (ostream &os,vector<vector<T>>& A) {
  for (auto &B: A) os << '\n' << B; return os; }
DefOut(vector) DefOut(set) DefOut(multiset) DefOut2(map) 
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1000000007;
long long const INF = 1e18;
#define PI 3.14159265358979323846
/***********************************************************************/

int32_t main() {

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

  int n;
  cin >> n;
  cout << (n - 2) * 180 << endl;

  return 0;
}


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

using namespace std;

int main() {
  int num_5 = 0, num_7 = 0;
  for (int i = 0; i < 3; i++) {
    int N;
    cin >> N;
    if (N == 5) {
      num_5++;
    } else if (N == 7) {
      num_7++;
    }
  }

  if (num_5 == 2 && num_7 == 1) {
    cout << "YES";
  } else {
    cout << "NO";
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	int i,j;
	char a[200],b[200],c[200];
	scanf("%d",&n);
	scanf("%s%s",&a,&b);
	for(i=0;i<2*n;i++)
	{
		if(i%2==0) c[i]=a[i/2];
		else c[i]=b[i/2];
	}
	for(i=0;i<2*n;i++)
	   printf("%c",c[i]);
	return 0;
 } 

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

#define INF 50000

int main(){
  int N;
  string S;
  cin >> N >> S;
  
  //vector<int> u(1000, 0);
  int ans = 0;
  bool flag1 = false, flag2 = false;
  
  for (int i = 0; i < 10; i++) {
   for (int j = 0; j < 10; j++) {
     for (int k = 0; k < 10; k++) {
       
       flag1 = false;
       flag2 = false;
       
       for (int l = 0; l < N; l++) {
         if ((int)(S.at(l) - '0') == i && !flag1 && !flag2) {
           flag1 = true;
           continue;
         }
         if ((int)(S.at(l) - '0') == j && flag1 && !flag2) {
           flag2 = true;
           continue;
         }
         if ((int)(S.at(l) - '0') == k && flag1 && flag2) {
           //u.at(i * 100 + j * 10 + k) = 1;
           ans++;
           break;
         }         
       }

      }
    }
  }
  
  cout << ans;
  return 0;

}



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

struct D {
  int n;
  int s;
  int r;
  D() {};

  D(const D &obj) {
    this->n = obj.n;
    this->s = obj.s;
    this->r = obj.r;
  }

  D &operator=(const D &obj) {
    this->n = obj.n;
    this->s = obj.s;
    this->r = obj.r;
  }
};

bool greater_s(const D &l, const D &r) {
  return (l.s > r.s);
}

bool less_n(const D &l, const D &r) {
  return (l.n < r.n);
}

int main() {
  D x[100];
  D tmp;
  D *p;
  int a, i, cur_s, cur_r;
  i = 0;
  while (1) {
    scanf("%d,%d", &tmp.n, &tmp.s);
    if (!tmp.n && !tmp.s) break;
    x[i] = tmp;
    ++i;
  }
  sort(x, x+i, greater_s);
  cur_s = x[0].s;
  cur_r = 1;
  for (int j=0; j<i; j++) {
    if (x[j].s == cur_s) {
      x[j].r = cur_r;
    } else {
      cur_s = x[j].s;
      x[j].r = ++cur_r;
    }
  }
  sort(x, x+i, less_n);
  while (scanf("%d", &tmp.n)==1) {
    p = lower_bound(x, x+i, tmp, less_n);
    printf("%d\n", p->r);
  }

  return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,ans=0;
	cin >> N;
	vector<ll> A(N+1,0),B(N+1,0);
	FOR(i,1,N+1)cin >> A[i] >> B[i];
	FORR(i,1,N+1){
		ll k = (A[i]+ans)%B[i];
		if(B[i]!=1)ans += (B[i]-k)%B[i];
	}
	cout << ans << endl;
}


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

typedef long long ll;
#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

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

    if(a+b>=c){
        cout<<b+c<<endl;
    }
    else {
        cout<<a+b*2+1<<endl;
    }
}


Measured memory_bytes: 256
billdings = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]


def printstate(billdings):
    """
    for billnum, billding in enumerate(billdings):
        for flooor in billding:
            for room in flooor:
                print(" {}".format(room), end="")
            print()
        print("#"*20 if billnum != len(billdings)-1 else "")
    """
    for i in range(len(billdings)):
        for j in range(len(billdings[0])):
            for k in range(len(billdings[0][0])):
                print(" "+str(billdings[i][j][k]), end="")
            print()
        if i != len(billdings)-1:
            print("#"*20)


n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    b, f, r = b-1, f-1, r-1
    billdings[b][f][r] += v

printstate(billdings)



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

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> sizes; // size[i]:iの属する木の要素数

  UnionFind(int N) : par(N), sizes(N,1) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x){
      return x;
    }
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(sizes[rx]>sizes[ry]){ // 小さい方を大き方にくっつける
      par[ry]=rx;
      sizes[rx]+=sizes[ry];
    }
    else{
      par[rx]=ry;
      sizes[ry]+=sizes[rx];
    }
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }

  int size(int x){
    return sizes[x]=sizes[root(x)];
  }
};

int main(){
  int N,M,K;
  cin >> N >> M >>K;
  UnionFind fri(N);
  vector<int> frinum(N,0);
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    --a;
    --b;
    fri.unite(a,b);
    frinum[a]++;
    frinum[b]++;
  }
  vector<vector<int>> block(N);
  for(int i=0;i<K;i++){
    int c,d;
    cin >> c >> d;
    --c;
    --d;
    block[c].push_back(d);
    block[d].push_back(c);
  }
  for(int i=0;i<N;i++){
    int count=fri.size(i)-frinum[i]-1;
    for(int x:block[i]){
      if(fri.same(i,x)){
        --count;
      }
    }
    cout << count;
    if(i!=N-1){
      cout << " ";
    }
    else{
      cout << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 9572
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

int main(){
    double x, h;
    while(true){
        cin >> x >> h;
        if(x == 0 && h == 0) break;
        cout << fixed;
        cout << x * x + x * 2 * sqrt(x * x / 4 + h * h) << endl;
    }
}


Measured memory_bytes: 3172
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
int p[210000];
int q[210000];
long long fact[510000];
long long inv[510000];
long long finv[510000];
long long C(int a,int b){
	if(a<b)return 0;
	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
int cm[210000];
int has[210000];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	fact[0]=finv[0]=inv[1]=1;
	for(int i=1;i<510000;i++){
		fact[i]=fact[i-1]*i%mod;
	}
	for(int i=2;i<510000;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<510000;i++){
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	for(int i=0;i<a;i++){
		cm[i]=mod;
	}
	for(int i=0;i<a;i++){
		scanf("%d%d",p+i,q+i);
		p[i]--;
		cm[p[i]]=min(cm[p[i]],q[i]);
	}
	int mm=mod;
	int mc=-1;
	for(int i=0;i<a;i++){
		if(mm>q[i]){
			mm=q[i];
			mc=p[i];
		}
	}
	int om=mod;
	for(int i=0;i<a;i++){
		if(p[i]==mc)continue;
		om=min(om,q[i]);
	}
	int n=0;
	for(int i=0;i<a;i++){
		if(mm+cm[p[i]]>c)continue;
		if(cm[p[i]]+q[i]>b&&(mm+q[i]>c||(p[i]==mc&&om+q[i]>c)))continue;
		has[p[i]]++;
		n++;
	}
	long long ret=1;
	for(int i=0;i<a;i++){
		ret=ret*C(n,has[i])%mod;
		n-=has[i];
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 15232
package main

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

func main() {
	io, flash := NewIO()
	defer flash()

	n, t, a := io.ScanInt(), io.ScanFloat64(), io.ScanFloat64()
	heights := io.ScanFloat64s(n)

	minDiff := AbsDiffFloat64(t-heights[0]*0.006, a)
	minIdx := 0
	for i, h := range heights[1:] {
		diff := AbsDiffFloat64(t-h*0.006, a)
		if diff < minDiff {
			minDiff = diff
			minIdx = i + 1
		}
	}
	fmt.Println(minIdx + 1)
}

func AbsDiffFloat64(n1, n2 float64) float64 {
	return math.Abs(n1 - n2)
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	int n,a,b;
	cin >> n >> a >> b;
	if(a*n >= b){
		cout << b << endl;
	}else{
		cout << a*n << endl;
	}
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

const ll mod =  998244353;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // long longの1次元の型に vll という別名をつける
using vvll = vector<vll>; // long longの2次元の型に vvll という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pll という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int main() {
   ll n,k;
   cin>>n>>k;
   vll l(k),r(k);
   rep(i,k)cin>>l.at(i)>>r.at(i);
   
   vll ans(n,0);
   ans.at(0)=1;
   
   rep(i,n-1){
       rep(j,k){
           if(i+l.at(j)<n)ans.at(i+l.at(j))+=(ans.at(i));
           if(i+r.at(j)+1<n)ans.at(i+r.at(j)+1)-=(ans.at(i));
       }
     // rep(i,n)cout<<ans.at(i)<<" ";
      //cout<<endl;
      if(i>0)ans.at(i+1)+=ans.at(i);
      if(ans.at(i+1)>=0)ans.at(i+1)%=mod;
      else{
           ans.at(i+1)%=mod;
           ans.at(i+1)+=mod;
      }
      
      //cout<<ans.at(i+1)<<endl;
   }
   //rep(i,n)cout<<ans.at(i)<<" ";
   cout<<ans.at(n-1)<<endl;
   
    
}



Measured memory_bytes: 4828
#include<stdio.h>
int main(void)
{
        int i,n,m,x,a[100],s=0;
        scanf("%d %d %d",&n,&m,&x);
        for(i=0;i<m;i++) scanf("%d",&a[i]);
        for(i=0;i<m;i++) if(a[i]<x) s++;
        if(m-s<s) s=m-s;
        printf("%d",s);
        return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;


int main(){
    int n;
    cin >> n;
    // vector<string> s(n);
    map<string, int> s;
    rep(i, n){
        string tmp;
        cin >> tmp;
        s[tmp]++;
    }

    cout << "AC x " << s["AC"] << endl;
    cout << "WA x " << s["WA"] << endl;
    cout << "TLE x " << s["TLE"] << endl;
    cout << "RE x " << s["RE"] << endl;
    return 0;
}


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(1000010);

int main() {
  int x, y; cin >> x >> y;
  if ((x + y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  int m = (2 * y - x)/3;
  int n = (2 * x - y)/3;
  mint ans = comb(m + n, m);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 15872
#include<cstdio>
const int MaxN=55;
int N;
struct Edge{int to;Edge*next;};
struct Tree{
	Edge E[MaxN*2],*ne,*fir[MaxN];
	void link(int u,int v){*ne=(Edge){v,fir[u]};fir[u]=ne++;}
	void init(int n){
		ne=E;for(int i=1;i<=N;i++)fir[i]=0;
	}
	void read(int n){
		init(n);
		for(int i=1,u,v;i<N;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
	}
}A,B,I;
bool vis[MaxN],del[MaxN],in[MaxN];
int deg[MaxN],stk[MaxN];
void ff(int i){
	if(vis[i])return;
	vis[i]=del[i]=1;
	for(Edge*e=I.fir[i];e;e=e->next)ff(e->to);
}
int main(){
	int T;scanf("%d",&T);
	while(T--){
		scanf("%d",&N);
		A.read(N);
		B.read(N);
		I.init(N);
		for(int i=1;i<=N;i++)vis[i]=0;
		for(int i=1;i<=N;i++){
			for(Edge*e=A.fir[i];e;e=e->next)vis[e->to]=1;
			for(Edge*e=B.fir[i];e;e=e->next)if(vis[e->to])I.link(i,e->to);
			for(Edge*e=A.fir[i];e;e=e->next)vis[e->to]=0;
		}
		int ans=-1;
		for(int ty=0;ty<2;ty++){
			for(int i=1;i<=N;i++)if(ty?!A.fir[i]->next:!vis[i]){
				for(int j=1;j<=N;j++){
					del[j]=deg[j]=in[j]=0;
					for(Edge*e=A.fir[j];e;e=e->next)deg[j]++;
				}
				//printf("(");
				//for(int j=1;j<=N;j++)if(del[j])printf(" %d ",j);puts(")");
				int*top=stk,tot=0;
				if(ty)del[*top++=i]=1;
				else{
					ff(i);
					for(int j=1;j<=N;j++)if(del[j])
						for(Edge*e=B.fir[j];e;e=e->next)if(!del[e->to])in[e->to]=1,deg[e->to]<2?del[*top++=e->to]=1:1;
				}
				while(top>stk){
					int x=*--top;
				//	if(ty)printf("i=%d del %d\n",i,x);
					for(Edge*e=A.fir[x];e;e=e->next)if(!del[e->to]&&--deg[e->to]<2&&in[e->to])del[*top++=e->to]=1;
					for(Edge*e=B.fir[x];e;e=e->next)if(!del[e->to]&&(in[e->to]=1)&&deg[e->to]<2)del[*top++=e->to]=1;
					tot++;
				}
				for(int j=1;j<=N;j++)if(!del[j])tot=-1;
				if(tot>-1&&(ans==-1||tot<ans))ans=tot;
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 128
n = int(input())
if n < 3:
    print(0)
    exit()
L = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if L[i] != L[j] and L[i] != L[k] and L[j] != L[k]:
                m = max(L[i],L[j],L[k])
                s = L[i]+L[j]+L[k]
                if m < s-m:
                    ans += 1
print(ans)

Measured memory_bytes: 9060
#include<stdio.h>
int main(){
   int S,h,m,s;
 
   scanf("%d",&S);
   h=S/3600;
   S=S%3600;
   m=S/60;
   s=S%60;
   printf("%d:%d:%d\n",h,m,s);
 
   return 0;
}


Measured memory_bytes: 2724
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

ll c[200005];

void solve()
{
    IN(n);
    INS(string, s);
    rep(i, n)
        c[i+1] = c[i] + (s[i] == 'R');
    ll r = INF;
    rep(i, n+1) {
        chmin(r, max(i-c[i], c[n]-c[i]));
    }
    cout << r << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 5336
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        int count4 = 0;
        for (char c : s.toCharArray()) {
            if (c == 'N') count1++;
            if (c == 'W') count2++;
            if (c == 'S') count3++;
            if (c == 'E') count4++;
        }
        if ((count1 > 0 && count3 == 0) || (count3 > 0 && count1 == 0)
            || (count2 > 0 && count4 == 0) || (count4 > 0 && count2 == 0)) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

ll n, a, b, c, d;

int main() {
    cin >> n >> a >> b >> c >> d;
    b -= a;
    b = abs(b);
    --n;
    for (int i = 0; i <= n; i += 2) {
        ll l = (n - i) * c;
        ll r = (n - i) * d;
        l -= (i / 2) * (d - c);
        r += (i / 2) * (d - c);
        if (b >= l && b <= r) {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
    return 0;
    return 0;
}




Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())

class UF():
  def __init__(self, N):
    self._parent=[n for n in range(0, N)]
    self._size=[1] * N

  def find_root(self, x):
    if self._parent[x]==x:return x
    self._parent[x]=self.find_root(self._parent[x])
    return self._parent[x]

  def unite(self, x, y):
    gx=self.find_root(x)
    gy=self.find_root(y)
    if gx==gy:return

    if self._size[gx]<self._size[gy]:
      self._parent[gx]=gy
      self._size[gy]+=self._size[gx]
    else:
      self._parent[gy]=gx
      self._size[gx]+=self._size[gy]

  def size(self, x):
    return self._size[self.find_root(x)]

  def samegroup(self, x, y):
    return self.find_root(x)==self.find_root(y)

  def groupnum(self):
    N=len(self._parent)
    ans=0
    for i in range(N):
      if self.find_root(i)==i:
        ans+=1
    return ans

cf=[[] for i in range(n)]
cb=[[] for i in range(n)]

UFa=UF(n)
UFb=UF(n)
for i in range(m):
  x,y=map(int,input().split())
  UFa.unite(x-1,y-1)
  UFb.unite(x-1,y-1)
  cf[x-1].append(y-1)
  cf[y-1].append(x-1)
UFa.groupnum()

for i in range(k):
  x,y=map(int,input().split())
  cb[x-1].append(y-1)
  cb[y-1].append(x-1)

ans=[]
for i in range(n):
  x=(UFa.size(i)-1)-len(cf[i])
  for j in range(len(cb[i])):
    if UFa.samegroup(i,cb[i][j]):
      x-=1
  ans.append(str(x))
print(' '.join(ans))

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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;

int main(){
    ll x,k,d;
    cin >> x >> k >> d;
    if(x<0) x=-x;
    ll kyori=x/d;
    ll temp_k=k-kyori-1; 
    if(temp_k<0){
        cout << x-k*d << endl;
        return  0;
    }
    k=temp_k;
    x=x-kyori*d-d;
    if(k>0&&k%2==1) x+=d;
    cout << abs(x) << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int castnumber = 0;
  for (int i = 0; i < N ; i++){
   int l,r;
   cin >> l >> r;
   castnumber += r - l + 1;
  }
  cout << castnumber << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;
int main()
{
    int d;
    cin >> d;
    cout << "Christmas ";

    rep(i, 25 - d) cout << "Eve" << ((i == 25 - d - 1) ? "" : " ");
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

const int N = 100;


void warshallFloyd(int m[N][N], int n){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                assert(m[i][k] + m[k][j] <= INF * 2);
                m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
            }
        }
    }
}

int main(){
    int n, mm, l, k, a, h;
    while(cin >> n >> mm >> l >> k >> a >> h,n||mm||l||k||a||h){
        int m[N][N], M[N][N];
        bool L[N] = {0};
        rep(i,N) rep(j,N) m[i][j] = INF;
        rep(i,n) m[n][n] = 0;
        memcpy(M, m, sizeof(m));

        L[a] = 1;
        L[h] = 1;
        rep(i,l){
            int inp;
            cin >> inp;
            L[inp] = 1;
        }

        rep(i,k){
            int a, b, t;
            cin >> a >> b >> t;
            assert(t < INF);
            m[a][b] = m[b][a] = t;
        }

        warshallFloyd(m, n);

        rep(i,n){
            rep(j,n){
                if(m[i][j] > mm) continue;
                if(L[i] && L[j]){
                    M[i][j] = m[i][j];
                }
            }
        }

        warshallFloyd(M, n);
        if(M[a][h] == INF) cout << "Help!" << endl;
        else cout << M[a][h] + max(M[a][h] - mm, 0) << endl;
    }
}

Measured memory_bytes: 3248
elems = STDIN.read.lines.map { |x| x.split(/\s+/).map(&:to_i) }[1..-1]
min_r, max_l = 10 ** 6, -1
elems.each { |l, r|
  min_r = r if r < min_r
  max_l = l if max_l < l
}
a = min_r - max_l + 1
a = 0 if a < 0
puts a

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

namespace ABC_Training
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = double.Parse(Console.ReadLine());
            var x = l / 3.0;
            Console.WriteLine(x * x * x);
        }
    }
}

Measured memory_bytes: 13140
package main
 
import (
	"bufio"
	"fmt"
	"os"
    "strconv"
)

// override by `ldflags`
var env = "online"

func checkLocal() bool {
	return env == "local"
}

func debugPrint(format string, args ...interface{}) {
	// debug out to stderr
	if checkLocal() {
		fmt.Fprintf(os.Stderr, format, args...)
	}
}

var (
	BufferSize = 10^9 + 10
)

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getGcd(x, y int) int {
    if x < y {
		x, y = y, x
	}
	if y == 0 {
		return x
	} else {
		return getGcd(y, x%y)
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	price := make([]int, n)
	for i := 0; i < n; i++ {
		price[i] = scanInt(sc)
	}

	var min, max int
	min = price[0]
	max = -price[0]

	for i := 1; i < n; i++ {
		if max < price[i] - min {
			max = price[i] - min
		}
		if price[i] < min {
			min = price[i]
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 5412
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long lint;

using namespace std;

#define NMAX 100001
lint N,M;

// 木を実装
lint parent[NMAX];
lint kazu[NMAX];


void init(int n) {
	rep(i,n) parent[i] = i;//shokika. parent[i] == i -> parent.
	rep(i,n) kazu[i] = 1;
}
int root(int x) {
	if (parent[x] == x) {
		return x; // if node == parent
	}
	else {
		return parent[x] = root(parent[x]); // compression & return root
	}
}


bool same(int x, int y) {
	return root(x) == root(y);
}
void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) return;
	parent[x] = y;// unite parents
	kazu[y] += kazu[x];
	kazu[x] = kazu[root(x)]; // 親のサイズと同じにする
}




int main()
{
	cin >> N >> M;
	
//	cout << "input: " << N << M << endl;

	vector<lint> A(M,0);
	vector<lint> B(M,0);

	rep(i,M) { 
//		cout << "i:" << i << endl;
		cin >> A[i] >> B[i]; 
		A[i]--;
		B[i]--;
		}


	//============ process

	init(N);
	vector<lint> ans(M,0);
	ans[M - 1] = (lint) (N * (N - 1) / 2);

	for (lint i = M - 1; i > 0; i--) {
		if (root(A[i]) != root(B[i])) {
		ans[i-1] =  (lint) ans[i] - (lint) (kazu[root(A[i])] * kazu[root(B[i])]);
		unite(A[i],B[i]);
		}
		else {
			ans[i-1] = ans[i];
		}

	}

	for (auto a : ans) {
		cout << a << endl;
	}


	return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string st;
    cin >> st;
    
    rep(i, st.size()) {
        if (st[i] == '?') {
            cout << "D";
        } else {
            cout << st[i];
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3784
_,*s=open(0);t='.';b=t*101;q=range(101);i=0
for s in s:
 a=[i];i+=1
 for x,y,z,c in zip(b,t+s,s,q):a+=min(c+(x==t>z),a[-1]+(y==t>z)),
 b,q=s,a[1:]
print(a[-2])

Measured memory_bytes: 3064
// Program.cpp

#include <bits/stdc++.h>
using namespace std;

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

#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n)           for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

void solve(int TEST_CASE){
    int n;
    cin >> n;
    int k;
    cin >> k;
    int arr[n];
    int m[n];
    fr(i,n){
    	cin >> arr[i];
    	m[i] = INF;
    }
    for(int i=0;i<n;++i){
    	if(i==0)
    		m[i] = 0;
    	else{
    		int min = INF;
    		for(int j=1;j<=k;++j){
    			if(j>i)
    				break;
    			min = m[i-j] + abs(arr[i] - arr[i-j]);
    			if(min<m[i])
    				m[i] = min;
    		}
    	}
    }
	cout << m[n-1] << endl;
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 4428
#include <iostream>
#include <algorithm>
#define MAX 100001
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  int x[MAX],l[MAX];
  for(int i = 0;i < M;i++){
    cin >> x[i];
  }
  sort(x,x+M);
  for(int i = 0;i < M - 1;i++){
    l[i] = x[i+1] - x[i];
  }
  sort(l,l+M-1);
  int total = 0;
  for(int i = 0;i < M - N;i++){
    total+= l[i];
  }
  cout << total << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++) cin>>a[i];
    map <int,long long int> m;
    for (int i=0;i<n;i++) m[a[i]]++;
    long long int ans=0;
    for (auto i : m) ans+=(i.second*(i.second-1))/2;
    for (int i=0;i<n;i++){
        long long int temp=ans-(m[a[i]]*(m[a[i]]-1))/2;
        temp+=((m[a[i]]-1)*(m[a[i]]-2))/2;
        cout<<temp<<"\n";
    }
	return 0;
}

Measured memory_bytes: 12344
#include <iostream>
using namespace std;
int Max(int a[],int n) {
	int x=0;
	int res;

	for (int i = 1; i < n; i++)
	{
		if (a[x] < a[i]) {
			x = i;
		}
	}
	res = a[x];
	a[x] = 0;
	
	return res;
}

int main() {
	int A = 0, B = 0;
	int N;
	int a[100];
	cin >> N;

	

	for (int i = 0;i < N;i++) {
		cin >> a[i];
	}
	int cnt = 0;
	while (1) {
		if ((cnt++) != N)
			A += Max(a, N);
		else
			break;
		if ((cnt++) != N)
			B += Max(a, N);
		else
			break;
	}

	cout << ((A > B)?(A - B):(B - A))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

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

using namespace std;

int main()
{
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x = x2 - x1, y = y2 - y1;

    cout << x2 - y << ' ' << y2 + x << ' ' << x1 - y<< ' ' << y1 + x;
}

Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

// const ll MOD = 1000000007;

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
static const int MODVAL = 1000000007;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) {}
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) {}
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }

int n;
ll cs[200000+10];

int main(void) {
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld", &cs[i]);
  }
  sort(cs, cs+n);
  reverse(cs, cs + n);
  mint res = 0;
  mint g = 1;
  REP(i, n) {
    // cerr << "> " << g << endl;
    res += mint(cs[i]) * POW(2, n-i-1) * g;
    g = g*2 + POW(2, i);
  }
  res *= POW(2, n);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define F first
#define S second
#define X real()
#define Y imag()
#define PB push_back 
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef complex<int> cld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut,pr> ppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
typedef vector<ppr> Vppr;
const int SIZE=1+1e+5;
int able[SIZE];
int size[SIZE];
VI nums;
int p[SIZE];
int times[SIZE];
int plusminus(int x){
	if(x)
	return x/abs(x);
	return 0;
}
int main(){
	int N;
	cin >> N;
	REP(i,N){
		cin >> p[i];
		if(i==0) continue;
		int n=plusminus(p[i]-p[i-1]);
		if(!nums.empty() && n==nums.back()) continue;
		if(n&&!nums.empty()){
			if(nums.back())
				if(n==-1) times[3]++;
				else times[4]++;
			else{
				int c=0;
				if(nums[nums.size()-2]==-1) c++;
				if(n!=nums[nums.size()-2])
					times[c]++;
				else
					times[2]++;
			} 
		}
		if(!nums.empty() || n)
		nums.PB(n);
	}
	REP(i,5){
		if(i) cout <<" ";
		cout << times[i];
	}
	cout << endl;
}


Measured memory_bytes: 2520
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		Point2D.Double v1, v2, v3;
		String str[];
		double s;

		s = 0.0;
		str = sc.next().split(",");
		v1 = new Point2D.Double(Double.valueOf(str[0]), Double.valueOf(str[1]));
		str = sc.next().split(",");
		v2 = new Point2D.Double(Double.valueOf(str[0]), Double.valueOf(str[1]));
		while (sc.hasNext()) {
			str = sc.next().split(",");
			v3 = new Point2D.Double(Double.valueOf(str[0]), Double.valueOf(str[1]));
			double a = Math.sqrt(Math.pow(v2.x - v1.x, 2) + Math.pow(v2.y - v1.y, 2));
			double b = Math.sqrt(Math.pow(v3.x - v1.x, 2) + Math.pow(v3.y - v1.y, 2));
			double c = Math.sqrt(Math.pow(v3.x - v2.x, 2) + Math.pow(v3.y - v2.y, 2));
			double z = (a + b + c) / 2;
			s += Math.sqrt(z * (z - a) * (z - b) * (z - c));
			v2 = v3;
		}
		System.out.println(s);
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;

mint solve(int N,int T){
	vector<mint> dp(N+1,1);
	rep(t,T){
		vector<mint> ndp(N+1,0);
		rep(r,N+1) if(dp[r]){
			int b = N-r;
			rep(j,2){
				int nr = r-j;
				int nb = b-(1-j);
				if(nr<0||nb<0) continue;
				rep(k,2){
					int nnr = nr + k;
					ndp[nnr] += dp[r];
				}
			}
		}
		dp = ndp;
	}
	mint res = 0;
	rep(i,N+1) res += dp[i];
	return res;
}

int main(){
	int N,T;
	cin>>N>>T;
	cout<<solve(N,T)-solve(N-1,T)<<endl;
}

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

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

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    vector<int> inp[m];
    for (int i = 0; i < m; i++) {
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int num;
            scanf("%d", &num);
            num--;
            inp[i].push_back(num);
        }
    }

    int p[m];
    for (int i = 0; i < m; i++)
        scanf("%d", &p[i]);

    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        int sum[m] = {0};
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                for (int k = 0; k < m; k++) {
                    for (auto l : inp[k])
                        if (l == j) {
                            sum[k]++;
                            break;
                        }
                }
            }
        }

        bool ok = true;
        for (int j = 0; j < m; j++) {
            if ((sum[j] % 2) != (p[j] % 2))
                ok = false;
        }
        if (ok)
            ans++;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
import sys
from heapq import *
input = sys.stdin.readline
N, K = map(int, input().split())
D, H, var, res = [], [], set(), 0
for _ in range(N):
    t,d = map(int, input().split())
    D.append((t,d))
D.sort(key=lambda x: x[1], reverse=True)
for t, d in D[:K]:
    if t not in var: var.add(t)
    else: heappush(H, d)
    res += d
x = len(var)
res += x**2
tmp = res
for t, d in D[K:]:
    if H and t not in var:
        tmp += d-heappop(H)+2*x+1
        x += 1
        var.add(t)
        res = max(res,tmp)
print(res)

Measured memory_bytes: 90532
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def solve():
    N,L = map(int,input().split())
    As = list(map(int,input().split()))
    for i in range(N-1):
        if As[i] + As[i+1] >= L:
            print("Possible")
            keep = i + 1
            for n in range(1,keep):
                print(n)
            for n in range(N-1, keep, -1):
                print(n)
            print(keep)
            return
    print("Impossible")
        
solve()



Measured memory_bytes: 14148
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int INF=1001001001;
int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  int cnt=0;
  for (int i=0;i<n-1;++i){
    if (s[i]==s[i+1]) cnt++;
  }
  int ans=0;
  ans=min(cnt+2*k,n-1);
  

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

Measured memory_bytes: 512