akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define boostup ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
double polyapothem(double n) 
{ 
  
    // Side and side length cannot be negative 
    // Degree converted to radians 
    return 1 / (2 * tan((180 / n) * 3.14159 / 180)); 
}
vector <ll> adj[200000+1];
ll dist[200000+1]; 
bool visited[200001]; 
ll n;
void Multisource_BFS(vector<ll> graph[],queue<ll>q) 
{ 
    while(!q.empty()) 
    { 
        ll k = q.front(); 
        q.pop(); 
      
        for(auto i:graph[k]) 
        { 
            if(!visited[i]) 
            { 
      
                // Pushing the adjacent unvisited vertices 
                // with distance from current source = this 
                // vertex's distance + 1 
                q.push(i); 
                dist[i]=k;
                //dist[i] = dist[k] + 1;  
                visited[i] = true; 
            }
        }
    } 
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            cout<<"No";
        }
    }
    cout<<"Yes"<<endl;
    for(ll i=2;i<=n;i++)
    {
        cout<<dist[i]<<endl;
    }
} 
  
  
// This function calculates the distance of each  
// vertex from nearest source 
void nearestTown(vector<ll> graph[],ll n,ll sources[],ll s) 
{ 
    //Create a queue for BFS 
    queue<ll> q; 
  
    //Mark all the source vertices as visited and enqueue it  
    for(ll i = 0;i < s; i++) 
    { 
        q.push(sources[i]); 
        visited[sources[i]]=true; 
    } 
  
    Multisource_BFS(graph,q); 
  
  
    //Printing the distances 
    // for(ll i = 2; i <= n; i++) 
    // { 
    //     cout<< dist[i]<<" " << endl; 
    // } 
  
} 
  
int main()
{
    boostup;
    ll m;
    cin>>n>>m;
    ll i,j;
    ll x,y;
    for(i=1;i<=m;i++)
    {
        
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    ll sources[] = { 1};  
  
    ll S = sizeof(sources) / sizeof(sources[0]);  
  
    nearestTown(adj, n, sources, S); 
}

Measured memory_bytes: 15468
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

ll v[50];
ll C[52][52];
signed main() {
	C[1][1] = 1;
	for (int i = 2; i <= 51; i++)for (int j = 1; j <= i; j++) {
		if (j == 1 || j == i)C[i][j] = 1;
		else C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
	}
	int n, a, b; scanf("%d%d%d", &n, &a, &b);
	rep(i, n)scanf("%lld", &v[i]);
	sort(v, v + n, greater<>());
	ll sum = 0;
	int cnt = 0;
	rep(i, a) {
		sum += v[i];
		if (v[i] == v[a - 1])cnt++;
	}
	int k = 0;
	rep(i, n) {
		if (v[i] == v[a - 1])k++;
	}
	printf("%.12lf\n", sum / (double)a);
	if (v[0] == v[a - 1]) {
		ll ans = 0;
		for (int i = a; i <= min(k, b); i++)ans += C[k + 1][i + 1];
		cout << ans << endl; return 0;
	}
	cout << C[k + 1][cnt + 1] << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int n, k;
int a[100005];

int min(int x, int y){
	return x < y ? x : y;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		//if(a[i] < 0) a[i] = a[i] * 2;
	}
	int ans = 0x3f3f3f3f;
	for(int i=1; i+k-1<=n; i++){
        int l=i,r=i+k-1;
        ans=min(ans,a[r]-a[l]+min(abs(a[l]),abs(a[r])));

	}
	printf("%d\n", ans);

	return 0;
}


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

int main() {
    
    string s;
    cin >> s;
    
    for (long unsigned int i=0; i<s.length()-2; i++){
        if (s[i] == s[i+1]){
            cout << i+1 << " " << i+2;
            return 0;
        }
        if (s[i] == s[i+2]){
            cout << i+1 << " " << i+3;
            return 0;
        }
    }
    
    if (s[s.length()-2] == s[s.length()-1]){
        cout << s.length()-1 << "  " << s.length();
    }
    else{
        cout << "-1 -1";
    }
    
    return 0;   
}

Measured memory_bytes: 512
n = int(input())

def isPrime(x):
  if x==2:
    return True
  elif x<2 or x%2==0:
    return False
  for i in range(3, int(x**0.5)+1, 2):
    if x%i==0:
      return False
  return True

ans = 0
for i in range(n):
  x = int(input())
  if isPrime(x):
    ans += 1
print(ans)


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

int main(){
  ll X, Y;
  cin >> X >> Y;
  ll n = Y/X;
  int ans = 1;
  while(n >= 2){
    n /= 2;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest118-C
#  https://atcoder.jp/contests/abc118/tasks/abc118_c
#  ref https://note.nkmk.me/python-gcd-lcm/

def gcd(small,big):
	if big < small:
		big,small = small,big
	if small == 0:
		return big
	else:
		return gcd(big % small,small)

def solveProblem(PowerGauge):
	nowGcd = 0
	for i in range(0,len(PowerGauge),+1):
		nowGcd = gcd(nowGcd,PowerGauge[i])
	answer = nowGcd
	return answer


if __name__ == '__main__':
	_ = int(input().strip())
	An = list(map(int,input().strip().split(' ')))
	solution = solveProblem(An)
	print("{}".format(solution))


Measured memory_bytes: 15020
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str_s = scan.next();
		int s1 = Integer.parseInt(str_s.charAt(0) + "");
		int s2 = Integer.parseInt(str_s.charAt(1) + "");
		int s3 = Integer.parseInt(str_s.charAt(2) + "");
		int sum = s1 + s2 + s3;
		System.out.println(sum);
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(){
cin.tie(NULL);
 ios::sync_with_stdio(false);

 int a[256];
 for(int i=0;i<3;i++){
   cin>>a[i];
 }
 sort(a,a+3);
 cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<"\n";

 return 0;
}



Measured memory_bytes: 3188
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
	let cin = stdin();
	let cin = cin.lock();
	let mut sc = Scanner::new(cin);
    let n : usize= sc.read();
    let mut arr = Vec::<u64>::new();
    for _ in 0..n { arr.push(sc.read()) }
    println!("{}", arr.iter().fold(64, |ans, x| {cmp::min(ans, x.trailing_zeros()) }));
	
}



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

using namespace std;

int x,y;
int asex[16005],asey[16005],cntx=0,cnty=0;

bitset <16005> hobex;
bitset <16005> hobey;

int main()
{
    char s[8005];
    scanf("%s %d%d",s,&x,&y);
    int sumx=0,sumy=0;
    int len=strlen(s),bam=0,h=0;
    s[len]='T';
    for(int i=0; i<=len; i++)
    {
        if(s[i]=='F')
        {
            h++;
        }
        else
        {
            if(bam==0)
            {
                sumx+=h;
                asex[cntx++]=2*h;
                bam=1;
                h=0;
            }
            else
            {
                sumy+=h;
                asey[cnty++]=2*h;
                bam=0;
                h=0;
            }
        }
    }
    hobex.set(0);
    hobey.set(0);
    hobex[sumx+8000]=1;
    hobey[sumy+8000]=1;
    for(int i=1;i<cntx;i++)
    {
            hobex|=(hobex>>asex[i]);
    }
    hobex[0]=0;
    for(int i=0;i<cnty;i++)
    {
            hobey|=(hobey>>asey[i]);
    }
    hobey[0]=0;
    if(hobex[x+8000]&&hobey[y+8000])
        printf("Yes\n");
    else
        printf("No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,num;
  cin>>n>>k;
  vector<int> arr;
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>num;
    arr.push_back(num);
  }
  sort(arr.begin(),arr.end());
  for(int i=0;i<k;i++){
    sum+=arr[i];
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <deque>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e6 + 10, S2 = 1e7 * 2, MOD = 1e9 + 7, INF = 1e9 * 1e7 * 100;



int main() {
    fastInp;

    ll n;
    cin >> n;
    ll s = 0;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        s += a[i];
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > b[i]) ans = max(ans, (s - b[i]));
    }

    cout << ans;

    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n,m;
  cin>>n>>m;
  int a[m],b[m];
  int c[m][n];
  rep(i,m){
    cin>>a[i]>>b[i];
    rep(j,b[i]){
      cin>>c[i][j];
    }
  }
  
  vector<ll> dp(5000,INF);
  dp[0]=0;
  rep(i,m){
    int now=0;
    rep(j,b[i]){
      now |= 1<<(c[i][j]-1);
    }
    
    for(int bit=0;bit<(1<<n);bit++){
      dp[bit | now]=min(dp[bit|now],dp[bit]+a[i]);
    }
  }
  
  if(dp[(1 << n) - 1] == INF) dp[(1 << n) - 1] = -1;
  cout << dp[(1 << n) - 1] << endl;
  
}
  
  
  

Measured memory_bytes: 384
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    N = int(input())
    counter = defaultdict(int)
    for i in range(2, N+1):
        while i % 2 == 0:
            counter[2] += 1
            i //= 2
        f = 3
        while f * f <= i:
            if i % f == 0:
                counter[f] += 1
                i //= f
            else:
                f += 2
        if i != 1:
            counter[i] += 1
    ans = 1
    mod = 10**9 + 7
    for v in counter.values():
        ans *= (v+1)
        ans %= mod
    print(ans%mod)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
x1,y1,x2,y2=map(int,input().split())

vec12=[x2-x1,y2-y1]
vec23=[-vec12[1],vec12[0]]
vec34=[-vec23[1],vec23[0]]

x3=x2+vec23[0]
y3=y2+vec23[1]
x4=x3+vec34[0]
y4=y3+vec34[1]

print(x3,y3,x4,y4)

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

int n, m;
char c[60][60];
int d1[] = {0, 0, -1, 1};
int d2[] = {-1, 1, 0, 0};

int moze(int x, int y) {
	for (int i = 0; i < 4; i ++) {
		int x1 = x + d1[i];
		int y1 = y + d2[i];
		if (c[x1][y1] == '#') return 1;
	}
	
	return 0;
}

int main () {

	cin >> n >> m;
	for (int i = 0; i <= n+1; i ++) {
		for (int j = 0; j <= m+1; j ++) {
			c[i][j] = '.';
		}
	}
	
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			cin >> c[i][j];
		}
	}
	
	int da = 1;
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			if (c[i][j] == '#') {
				if (moze(i, j) == 0) {
					da = 0;
					break;
				}
			}
		}
		if (da == 0) break;
	}

	if (da == 1) cout << "Yes";
	else {cout << "No";}

	return 0;
}

Measured memory_bytes: 256
let lines = [];
let reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

// 標準入力の読み込み
reader.on('line', function(line) {
    lines.push(line);
});

reader.on('close', function() {
    // 処理の記述
    let str = lines[0];

    if (str[str.length - 1] == 's') {
        str += 'es';
    } else {
        str += 's';
    }


    // 表示
    console.log(str);
});

Measured memory_bytes: 30064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, x, a, b, q, r, ans = 0;
	cin >> n >> x;
	a = n - x; b = x;
	while (true) {
		q = a / b; r = a % b;
		ans += 3 * b * q;
		if (r == 0) break;
		a = b; b = r;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
s=input()
n=int(input())
t=""
for _ in range(n):
  q=input().split()
  if q[0]=="1":
    t,s=s,t
  else:
    if q[1]=="1":
      t+=q[2]
    else:
      s+=q[2]
t=t[::-1]
print(t+s)

Measured memory_bytes: 4316
//04
#include<iostream>
#include<complex>
#include<iomanip>
#include<cmath>
#include<algorithm>

#define S(X) ((X)*(X))

using namespace std;

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    complex<double> p[3];
    for(int j=0;j<3;j++){
      double x,y;
      cin>>x>>y;
      p[j]=complex<double>(x,y);
    }
    complex<double> t[2];
    t[0]=p[1]-p[0];
    t[1]=p[2]-p[0];
    if(t[0].real()*t[1].imag()-t[0].imag()*t[1].real()<0){
      swap(p[1],p[2]);
    }
    double d[3];
    for(int j=0;j<3;j++){
      d[j]=abs(p[j]-p[(j+1)%3]);
    }
    double r=d[0]/2/sqrt(1-S((S(d[1])+S(d[2])-S(d[0]))/2/d[1]/d[2]));
    complex<double> c=p[0]+polar(r,arg(p[1]-p[0])+acos(d[0]/2/r));
    cout<<fixed<<setprecision(3)<<c.real()<<' '<<c.imag()<<' '<<r<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
#define MAX 1000000

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
    int H, i, A[MAX+1];

    cin >> H;
    for ( i = 1; i <= H; i++ ) cin >> A[i];

    for ( i = 1; i <= H; i++ ) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if ( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
        if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
        if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	unsigned long long N;
	cin >> N;
	auto n = N;
	auto sum = 0ull;
	for (auto i = 0; i < 10; ++i)
	{
		sum += N % 10;
		N /= 10;
	}

	if ((n % sum) == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;

string s,t;

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    cin >> t;
    s = s+s;
    bool flag = true;
    int count = 0;
    REPP(i,count,t.length()){
        flag = true;
        REP(j,t.length()){
            if(!(s[j+i] == t[j])){ 
                flag = false;
                break;
            }
        }
        if(flag) break;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  string S;
  cin >> S;
  int countB = 0;
  int countW = 0;
  for (int i = 0; i < S.size(); i++) {
    if ((S[i] == '0' && i % 2 == 0) || (S[i] == '1' && i % 2 != 0)) {
      countB++;
    } else {
      countW++;
    }
  }
  cout << min(countB, countW) << endl;
}

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

int main(int argc, char **argv) {
  int a, b;
  cin >> a >> b;
  int diff = max(a, b) - min(a,b);
  if (diff > 1) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <map>
#include <numeric>
#include <cassert>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOADVEC3(type,name0,name1,name2,N) std::vector<type>name0(N),name1(N),name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn];cin >> name2[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/

void proc() {
	LOAD(int, A);
	LOAD(int, B);
	LOAD(int, C);
	if (A == B && B == C) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


#endif


Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
S = []
con= 0
for _ in range(D):
    S.append(list(map(int, input().split())))
t = [-1]*D
best = [0]*D
last = [0]*26

for i in range(D):#1日ごと
    for x in range(26):#どの問題を選ぶか
        if i==0:
            con = 0
        else:
            con = best[i-1]
        
        con += S[i][x]
        last[x] = i+1
        for j in range(26): #減少量の計算 #問題ごと
            con -= C[j]*(i-last[j]+1)
            
        if con>best[i]:
            last[x]=i+1
            best[i]=con
            t[i]=x+1
            
#print(best)
for i in range(D):
  print(t[i])


Measured memory_bytes: 68360
MAX_VAL = (1 << 31) - 1

### subroutines

def lay(i0, i1, st, lcache)
  return 0 if i0 >= i1
  return lcache[i0][i1] if ! lcache[i0][i1].nil?

  min_sum = MAX_VAL

  for j in (i0...i1)
    sum =
      lay(i0, j, st, lcache) + lay(j + 1, i1, st, lcache) +
      st[i0][0] * st[j][1] * st[j + 1][0] * st[i1][1]
    min_sum = sum if min_sum > sum
  end

  lcache[i0][i1] = min_sum
end

### main

n = gets.strip.to_i

stocks = n.times.map{gets.strip.split(' ').map{|s| s.to_i}}
lcache = (0...n).map{(0...n).map{nil}}

puts lay(0, n - 1, stocks, lcache)

Measured memory_bytes: 6220
#include<bits/stdc++.h>
using namespace std;
int n,dp[4200003];
bool a[22][22];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>a[i][j];
	dp[0]=1;
	for(int i=0;i<1<<n;i++){
		int cnt=0,tmp=i;
		while(tmp)
			cnt+=tmp%2,
			tmp/=2;
		//cout<<i<<' '<<cnt<<endl;
		for(int j=0;j<n;j++)
			if(a[cnt][j]&&~i&(1<<j))
				dp[i+(1<<j)]=(dp[i+(1<<j)]+dp[i])%1000000007;
	}
	cout<<dp[(1<<n)-1];
}

Measured memory_bytes: 10496
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	private static final boolean TEST = false;

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		do {
			int n = in.nextInt();
			int m = in.nextInt();
			PriorityQueue<Integer> pq = new PriorityQueue<>();
			for (int i = 0; i < n; i++)
				pq.add(-1 * in.nextInt());
			System.out.println(solve(n, m, pq));
		} while (TEST);
	}

	private static long solve(int n, int m, PriorityQueue<Integer> pq) {
		for (int i = 0; i < m; i++)
			pq.add(pq.poll() / 2);
		long r = 0;
		for (int i : pq)
			r -= i;
		return r;
	}
}

Measured memory_bytes: 57852
#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() {
    long long n;cin>>n;
    vector<int>s(26);
    for (int i=0;i<n;i++) {
        char ss; cin>>ss;
        s[ss-'a']++;
    }

    long long ans=1;
    rep(i,26){
        ans*=s[i]+1;
        ans%=mod;
    }
    ans=(ans+mod-1)%mod;
    cout<<ans<<endl;
}


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

int getLength(int w, int h)
{
    return (w + h) * 2;
}

int getArea(int w, int h)
{
    return w * h;
}

int main()
{
    int w, h;
    cin >> w >> h;
    cout << getArea(w, h) << " " << getLength(w, h) << endl;
    
    return 0;
}

Measured memory_bytes: 1164
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int r = sc.nextInt();
    
    if (r < 1200) {
      System.out.println("ABC");
    } else if (r < 2800) {
      System.out.println("ARC");
    } else {
      System.out.println("AGC");
    }
  }
}

Measured memory_bytes: 21844
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7
ans = 0

A_sum = [A[0] for i in range(N)]
for i in range(1, N):
    A_sum[i] = A_sum[i-1] + A[i]

for i in range(1, N):
    ans += A[i] * A_sum[i-1]
    ans %= mod

print(ans)


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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin() , v.end());
    int m;
    cin >> m;
    for(int i = 0; i< m; i++){
        int p;
        cin >> p;
        /*
        if(p >= v[n-1]){
            cout << n << endl;
        }
        else {
            auto itr = lower_bound(v.begin(), v.end(), p);
            cout << itr-v.begin() << endl;
        }
        */
        auto itr = lower_bound(v.begin(), v.end(), p) - v.begin();
        cout << itr << endl;
    }
}


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

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var max = new[] { nums[0] * 2 - 1, nums[0] + nums[1], nums[1] * 2 - 1 }.Max();
            Console.WriteLine(max);
        }
    }
}


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n, tmp;
	cin >> n;
	int ans[n];
	int l= n/2;
	int r = l- (n%2==0?1:-1);
	//cout << l << " " << r << endl;
	REP(i, 0, n){
		cin >> tmp;
		if(n % 2 == 0){
			if(i % 2 == 0){
				ans[l] = tmp;
				++l;
			}
			else{
				ans[r] = tmp;
				--r;
			}
		}
		else{
			if(i % 2 == 0) {
				ans[l] = tmp;
				--l;
			}
			else{
				ans[r] = tmp;
				++r;
			}
		}
		//cout << l << " " << r << endl;
	}
	REP(i, 0, n) cout << ans[i] << " ";
}


Measured memory_bytes: 2944
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,a[100005],b[100005],c[100005];
int main(){
    in(n);
    for(int i=1;i<=n;i++)in(a[i]);
    for(int i=1;i<=n;i++){
        b[i]=a[i]-1;
    }
    for(int i=2;i<=n;i++){
        if(a[i-1]==a[i])c[i]=c[i-1];
        if(a[i-1]>a[i]){
            if(b[i-1]>a[i]||c[i-1]){
                puts("No");
                return 0;
            }
            else c[i]=1;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n;
  char s[1000];
  cin >> s;
  n=strlen(s);
  for(int i=0;i<n;i++){
    if(s[i]=='A'){
      s[i]='X';
    }
    else if(s[i]=='B'){
      s[i]='Y';
    }
    else if(s[i]=='C'){
      s[i]='Z';
    }
    else{
      s[i]=s[i]-3;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    char S;
    set<char> s;
    rep(i, 0, N)
    {
        cin >> S;
        s.insert(S);
    }
    cout << (s.size() == 3 ? "Three" : "Four") << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MAXN=10;
int map[MAXN][MAXN],jilu[100][MAXN][MAXN];
int lie[10],zuoxie[20],youxie[20];
int v[100],q[100];
int tot=0;
void wwq(){
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++) jilu[tot][i][j]=map[i][j];
	}
	tot++;
}
void dfs(int i){
	for(int j=0;j<8;j++){
		if(lie[j]==0 && zuoxie[i+j]==0 && youxie[i-j+7]==0){
			lie[j]=1;
			zuoxie[i+j]=1;
			youxie[i-j+7]=1;
			map[i][j]=1;
			if(i==7) wwq();
			else dfs(i+1);
			lie[j]=0;
			zuoxie[i+j]=0;
			youxie[i-j+7]=0;
			map[i][j]=0;
		}
	}
} 
int main(){
	dfs(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>v[i]>>q[i];
	for(int i=0;i<92;i++){
		for(int i1=1;i1<=n;i1++){
			if(jilu[i][v[i1]][q[i1]]!=1) break;
			if(i1==n){
				for(int j=0;j<8;j++){
					for(int k=0;k<8;k++){
						if(jilu[i][j][k]==0) cout<<".";
						if(jilu[i][j][k]==1) cout<<"Q";
					}
					cout<<endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define mod (ll)(1e9+7)
#define INF (ll)(1e9)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int gcd(int A,int B) {if(!B)return A;return gcd(B,A%B);}
int a[200004];
int main()
{
 int n;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  int ans = a[0];
  for(int i=1;i<n;i++)ans = gcd(ans,a[i]);
  cout<<ans;
  
  
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
  
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
  
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<ll> s(n + 1, 0);
    REP(i, n) s[i + 1] = s[i] + a[i];

    vector<ll> v(n * (n + 1) / 2);
    int count = 0;
    REP(i, n) FOR(j, i + 1, n + 1) v[count++] = s[j] - s[i];
    sort(ALL(v));

    int l = v.size();

    ll mx = 1;
    while (mx < v[l - 1]) {
        mx <<= 1;
    }

    ll ans = 0;
    while (mx > 0) {
	    mx >>= 1;
        int c = 0;
        for (ll x : v) if ((x & (ans + mx)) == (ans + mx)) c++;
        if (c >= k) ans += mx;
    }

    cout << ans << endl;
}


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

vector<int> mark;
vector<vector<int>> f;

void search(int i, int x) {
    if(mark[i] == 0) {
        mark[i] = x;
        rep(j,f[i].size()) {
            search(f[i][j],x);
        }
    }
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    
    vector<int> a(m), b(m);
    rep(i,m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    
    vector<int> c(k), d(k);
    rep(i,k) {
        cin >> c[i] >> d[i];
        c[i]--;
        d[i]--;
    }
    
    f = vector<vector<int>> (n);
    rep(i,m) {
        f[a[i]].push_back(b[i]);
        f[b[i]].push_back(a[i]);
    }
    
    mark = vector<int> (n);
    
    int x = 1;
    rep(i,n) {
        if(mark[i] == 0) {
            search(i,x);
            x++;
        }
    }
    
    vector<int> cnt(n+1);
    rep(i,n) {
        cnt[mark[i]]++;
    }
    
    vector<int> ans(n);
    rep(i,n) {
        ans[i] = cnt[mark[i]];
    }
    
    rep(i,m) {
        if(mark[a[i]] == mark[b[i]]) {
            ans[a[i]]--;
            ans[b[i]]--;
        }
    }
    
    rep(i,k) {
        if(mark[c[i]] == mark[d[i]]) {
            ans[c[i]]--;
            ans[d[i]]--;
        }
    }
    
    rep(i,n) {
        if(i == n-1)
            cout << ans[i] - 1 << endl;
        else
            cout << ans[i] - 1 << " ";
    }
    
    
    return 0;
}


Measured memory_bytes: 12372
#include<iostream>
using namespace std;
 
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d){
    cout << "Yes" << endl;
  }else{
   cout << "No" << endl; 
  }
}

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

int main(void){
    int n,i;
    int a[251];
    
    cin>>n;
    
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    
    for(i=1;i<=n;i++){
        printf("node %d: key = %d, ",i,a[i]);
        if(i!=1)printf("parent key = %d, ",a[i/2]);
        if(i*2<=n)printf("left key = %d, ",a[i*2]);
        if(i*2+1<=n)printf("right key = %d, ",a[i*2+1]);
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3228
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

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

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

        n = n >> 1;
    }

    return res;
}

void solve()
{
    int N;
    cin >> N;

    vector<pair<ll, ll>> A(N);
    map<pair<ll, ll>, int> mp;
    set<pair<ll, ll>> S;
    int zero_count = 0;

    for(int i = 0; i < N; i++)
    {
        ll a, b;
        cin >> a >> b;

        ll GCD = 1;
        if(a != 0 && b != 0)
            GCD = gcd(abs(a), abs(b));

        A[i].first = a / GCD;
        A[i].second = b / GCD;

        if(A[i].second < 0)
        {
            A[i].first *= -1;
            A[i].second *= -1;
        }
        if(A[i].first == 0 && A[i].second == 0)
        {
            zero_count++;
        }
        else if(A[i].second == 0)
        {
            A[i].first = 1;
        }
        else if(A[i].first == 0)
        {
            A[i].second = 1;
        }
        S.insert(A[i]);

        mp[A[i]]++;
    }
    
    ll ans = 1;
    vector<pair<ll, ll>> B;

    for(auto x : S)
    {
        B.push_back(x);
    }
    
    int M = B.size();
    set<pair<ll, ll>> S1;
    for(int i = 0; i < M; i++)
    {
        pair<ll, ll> bad = {(-1) * B[i].second, B[i].first};

        if(B[i].first == 0 && B[i].second == 0)
        {
            continue;
        }

        if(bad.second < 0)
        {
            bad.first *= -1;
            bad.second *= -1;
        }

        if(B[i].first == 0)
        {
            bad.first = 1;
            bad.second = 0;
        }
        else if(B[i].second == 0)
        {
            bad.first = 0;
            bad.second = 1;
        }

        if(S1.find(B[i]) != S1.end() && S1.find(bad) != S1.end())
        {
            continue;
        }

        ll n = mp[B[i]];
        ll m = mp[bad];

        ll x = 0;
        x += power(2, n);
        x %= MOD;

        x += power(2, m);
        x %= MOD;

        x--;

        ans *= x;
        ans %= MOD;

        S1.insert(B[i]);
        S1.insert(bad);
        
    }
    ans -= 1;
    ans %= MOD;
    ans += MOD;
    ans %= MOD;
    ans += zero_count;
    ans %= MOD;
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;
    
    while (T--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 71780
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	ll x, cur = 100;
	cin >> x;
	int it = 0;
	while(cur < x){
		cur += cur / 100;
		it++;
	}
	cout << it << endl;

	return 0;
}

Measured memory_bytes: 3652
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    map<ll, ll> m;

    REP(i, N) m[i - A[i]]++;

    ll ans = 0;
    REP(i, N) {
        m[i - A[i]]--;
        ans += m[A[i] + i];
    }

    cout <<  ans << endl;
}


Measured memory_bytes: 27456
<?php
	fscanf( STDIN, "%d", $n );
	$i = 1;
	
	$output = array();
	do {
		$x = $i;
		if( 0 == $x % 3 ) {
			array_push( $output, ' '.$i );
		} else {
			do {
				if( 3 == $x % 10 ) {
					array_push( $output, ' '.$i );
					break;
				} else {
					$x /= 10;
				} 
			} while( $x );
		}
	} while( ++$i <= $n );
	array_push( $output, PHP_EOL );

    print implode( '', $output );
	
	return;

?>

Measured memory_bytes: 7588
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element


int N, M;
vector<int> S[11];
int P[11];

signed main()
{
	cin >> N >> M;
	REP(i, M)
	{
		int k;
		cin >> k;
		REP(j, k)
		{
			int s;
			cin >> s;
			S[i].push_back(s);
		}
	}
	REP(i, M)
	{
		cin >> P[i];
	}

	int ans = 0;
	int max = (1LL << N) - 1;
	for (int i = 0; i <= max; i++)
	{
		bool full = true;
		for (int j = 0; j < M; j++)
		{
			int cur = 0;
			for (int s : S[j])
			{
				if ((i & (1LL << (s - 1))) > 0)
				{
					cur ^= 1;
				}
			}
			if (cur != P[j])
			{
				full = false;
			}
		}
		if (full)
		{
			ans++;
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,a[1000],c;
	while(true){
		cin>>n;
		if(n==0){
			break;
		}
		c=0;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n);
		for(int i=1;i<n-1;i++){
			c+=a[i];
		}
		cout<<c/(n-2)<<endl;
	}
	return 0;
}


Measured memory_bytes: 3036
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        int[] c = new int[N];
        for(int i=0;i<N;i++){
            a[i] = scan.nextInt();
            b[i] = scan.nextInt();
            c[i] = scan.nextInt();
        }

        int[][] dp = new int[N][3];
        fill(dp);
        int max = Integer.MIN_VALUE;
        max = Math.max(maxValue(a,b,c,N-1,2,dp),max);
        fill(dp);
        max = Math.max(maxValue(a,b,c,N-1,2,dp),max);

        fill(dp);
        max = Math.max(maxValue(a,b,c,N-1,3,dp),max);
        System.out.println(max);


    }

    public static void fill(int[][] dp){
        for(int i=0;i<dp.length;i++){
            for(int j=0;j<3;j++){
                dp[i][j] = -1;
            }
        }
    }

    public static int maxValue(int[] a,int[] b,int[] c,int index,int lastElement,int[][] dp){
        if(index<0){
            return 0;
        }

        if(dp[index][lastElement-1]!=-1)
            return dp[index][lastElement-1];
        if(lastElement == 1){
            return dp[index][lastElement-1] = Math.max(maxValue(a,b,c,index-1,2,dp) + b[index],maxValue(a,b,c,index-1,3,dp) + c[index]);
        }
        else if(lastElement == 2){
            return dp[index][lastElement-1] = Math.max(maxValue(a,b,c,index-1,1,dp)+a[index] , maxValue(a,b,c,index-1,3,dp)+c[index]);
        }
        else{
            return dp[index][lastElement-1] = Math.max(maxValue(a,b,c,index-1,1,dp)+a[index],maxValue(a,b,c,index-1,2,dp)+b[index]);
        }
    }
}

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

def main():
  N = int(input())
  li = [input().strip().split(' ')for _ in range(N)]
  yen = 0.0
  ratio = 380000.0
  for x, u in li:
    if u == 'JPY':
      yen += float(x)
    if u == 'BTC':
      yen += (ratio * float(x))
  print(yen)

  pass

if __name__=='__main__':
  main()

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

bool vis[int(1e6) + 5];
vector<int> g[int(1e6) + 5];

int main() {
	faster;

	ll n, m;
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int mxn = 1;

	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			stack<int> q;
			int temp = 1;
			q.push(i);
			vis[i] = true;
			while (!q.empty()) {
				int curr = q.top();
				q.pop();
				for (auto x : g[curr]) {
					if (!vis[x]) {
						vis[x] = true;
						q.push(x);
						temp++;
						mxn = max(mxn, temp);
					}
				}
			}
		}
	}

	cout << mxn << endl;
	return 0;
}

Measured memory_bytes: 33924
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX_H = 80; 
const int MAX_W = 80;
const int MAX_D = (MAX_H + MAX_W) * 40;

vector<vector<int> > diff(MAX_H, vector<int>(MAX_W));
vector<vector<vector<bool> > > searched(MAX_H, vector<vector<bool> >(MAX_W, vector<bool>(MAX_D + 1, false)));
vector<vector<vector<bool> > > memo(MAX_H, vector<vector<bool> >(MAX_W, vector<bool>(MAX_D + 1, false)));

bool dp(int i, int j, int k) {
    if (!searched[i][j][k]) {
        if (i == 0 && j == 0) {
            if (k == diff[i][j]) {
                memo[i][j][k] = 1;
            } else {
                memo[i][j][k] = 0;
            }
        } else if (i == 0) {
            if (dp(i, j - 1, abs(k - diff[i][j]))) memo[i][j][k] = true;
            if (k + diff[i][j] <= MAX_D) {
                if (dp(i, j - 1, k + diff[i][j])) memo[i][j][k] = true;
            }
        } else if (j == 0) {
            if (dp(i - 1, j, abs(k - diff[i][j]))) memo[i][j][k] = true;
            if (k + diff[i][j] <= MAX_D) {
                if (dp(i - 1, j, k + diff[i][j])) memo[i][j][k] = true;
            }

        } else {
            if (dp(i - 1, j, abs(k - diff[i][j])) || dp(i, j - 1, abs(k - diff[i][j]))) memo[i][j][k] = true; 
            if (k + diff[i][j] <= MAX_D) {
                if (dp(i - 1, j, k + diff[i][j]) || dp(i, j - 1, k + diff[i][j])) memo[i][j][k] = true;
            }
        }
        searched[i][j][k] = true;
    }
    return memo[i][j][k];
}

int main() {
    int H, W; cin >> H >> W;
    vector<vector<int> > As(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> As[i][j];
        }
    }
    vector<vector<int> > Bs(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> Bs[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            diff[i][j] = abs(As[i][j] - Bs[i][j]);
        }
    }
    for (int i = 0; i < MAX_D; i++) {
        if (dp(H-1, W-1, i)) {
            cout << i << endl;
            break;
        }
    }
}


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

int main() {
  ll n, k;
  cin >> n >> k;

  ll mod = 1000000000 + 7;
  ll ans = 0;
  
  for (ll i = k; i <= n; i++) {
    ans += (n*(n+1)/2 - (n-i)*(n-i+1)/2 - i*(i-1)/2 + 1) % mod;
    ans %= mod;
  }
  ans += 1;
  ans %= mod;

  cout << ans << endl;
}


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

int main(){
	int x,a,b;
	cin >> x >> a >> b;
	
	int tmp=x-a;
	int ans;
	while(tmp>0){
		ans=tmp-b;
		tmp=tmp-b;
		if(ans<0)
			ans=tmp+b;
	}

	cout << ans;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int kumi = 0;
            int[] l = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            for(int i=0; i<a;i++)
            {
                for(int j=i+1; j<a;j++)
                {
                    for(int k=j+1; k<a;k++)
                    {
                        int a1 = l[i];
                        int b1 = l[j];
                        int c1 = l[k];
                        if(a1 != b1 && b1 !=c1 && c1 !=a1)
                        {
                            if(a1+b1 > c1 && b1+c1 >a1 && c1+a1 >b1)
                            {
                                ++kumi;
                            }
                        }
                    }
                }

            }
            Console.WriteLine(kumi);
        }
    }
}


Measured memory_bytes: 27392
import numpy as np
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = [int(i) for i in input().split()]

f_inf = float('inf')
dp = np.zeros(n, dtype=int)
h = np.array(h)
for i in range(1, n):
    start = max(0, i - k)
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))

print(dp[n-1])


Measured memory_bytes: 23052
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            a /= 2;
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int a,b,c;
  int d=0;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b>>c;
    c=(c-b)+1;
    d=c+d;
  }
  cout<<d<<"\n";
}

Measured memory_bytes: 256
S = input()
L = len(S)
ans = 0
for i in range(L):
  if i % 2 == 0:
    if S[i] == 'L':
      ans = 1
      break
  else:
    if S[i] == 'R':
      ans = 1
      break
if ans == 1:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 3060