akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    string s;
    cin >> s;
    
    rep (i, 4) cout << s[i];
    cout << " ";
    for (int i = 4; i < s.size(); i++) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void putQueen( int);
void initialization( void);
void print( void);
 int judge[8][8];
int re[8],de[2*8-1],c[8],dp[2*8-1];

 
int main(){
    int i,j,a,b,c;
     
    initialization();
 
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            judge[i][j] = 0;
        }
    }
    scanf("%d",&a); 
    for(i=0;i<a;i++){
        scanf("%d%d",&b,&c);
        judge[b][c] = 1;
    }
 
    putQueen(0);
 
    return 0;
}


void putQueen(int a){
    int j;
 
    if(a == 8){
        print();
        return 0;
    }
    for(j=0;j<8;j++){
        if(c[j] == -1 || dp[a+j] == -1 || de[a-j+8-1] ==-1){
            continue ;
        }
        re[a] = j;
        c[j] = dp[a+j] = de[a-j+8-1] = -1;
       putQueen(a+1);
        c[j] = dp[a+j] = de[a-j+8-1] = 1;
	 
    }
}
void initialization(){
    int i;
 
    for(i=0;i<8;i++){
        re[i] = c[i] = 1;
    }
    for(i=0;i<2*8-1;i++){
        dp[i] = de[i] = 1;
    }
}
void print(){
    int i,j;
 
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(judge[i][j] == 1){
                if(re[i] != j){
                    return 0;
                }
            }
	}
    }
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(re[i] == j){
                printf("Q");
            }
            else{
                printf(".");
            }
        }
        printf("\n");
    }
}



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

int main(){
  int n;
  cin >> n;
  int a[10000];
  for(int i =0;i < n;i++) cin >> a[i];
  int mn = a[0];
  int mx = a[0];
  long long sum = 0;
  for(int i =0;i < n;i++){
    mn = min(mn,a[i]);
    mx = max(mx,a[i]);
    sum += a[i];
  }
  cout << mn << " " << mx << " " << sum << endl;
  return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric> 

#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 999999999
using namespace std;

int main()
{
    int n;
    cin >> n;
    long bt = 0;
    long at = 0;
    long t[n];
    int a;
    long fans = 0;
    REP(i, n) {
        cin >> t[i];
    }
    
    REP(j, 2) {
        long ans = 0;
        if(j % 2 == 0) {
            bt = 1;
        }else {
            bt = -1;
        }
        REP(i, n) {
            a = t[i];
            at = a + bt;
            if(i == 0) {
                at = a;
            }
            if((at > 0 && bt < 0) || (at <0 && bt >0)) {
                bt = at;
            } else if( bt > 0) {
                ans += abs(at) + 1;
                bt = at - (abs(at) + 1);
            } else {
                ans += abs(at) + 1;
                bt = at + (abs(at) + 1);
            }
        }

        if(j == 0) {
            fans = ans;
        } else {
            fans = min(fans, ans);
        }
    }

    cout << fans << endl;
    return 0;
}


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

struct Card{char suit,value;};

int main()
{
	int n=0;cin>>n;
	Card a[100]={0},b[100]={0};
	for(int i=0;i<n;i++)
	{
		cin>>a[i].suit>>a[i].value;
		b[i]=a[i];
	}
	
//<bubble>
	int f=1;
	for(int j=0;f==1;j++)
	{
		f=0;
		for(int i=n-1;i>j;i--)
		{
			if(a[i].value<a[i-1].value)
			{
				swap(a[i],a[i-1]);
				f=1;
			}
		}
	}
	
	cout<<a[0].suit<<a[0].value;
	for(int i=1;i<n;i++)
	{
		cout<<" "<<a[i].suit<<a[i].value;
	}
	cout<<endl<<"Stable"<<endl;
//</bubble>
	
//<selection>
	for(int i=0;i<n;i++)
	{
		int minj=i;
		for(int j=i;j<n;j++)
		{
			if(b[j].value<b[minj].value)
			{
				minj=j;
			}
		}
		swap(b[i],b[minj]);
	}
	
	cout<<b[0].suit<<b[0].value;
	for(int i=1;i<n;i++)
	{
		cout<<" "<<b[i].suit<<b[i].value;
	}
	f=0;
	for(int i=0;i<n;i++)
	{
		if(a[i].suit!=b[i].suit)
		{
			cout<<endl<<"Not stable"<<endl;
			f=1;break;
		}
	}
	if(f==0)cout<<endl<<"Stable"<<endl;
//</selection>
	
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 100010
using namespace std;
int n,a[N],cnt[N],sum=0;
int main()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(i=1;i<=n;i++) if(a[i]%4==0) cnt[i]=2; else if(a[i]%2==0) cnt[i]=1; else cnt[i]=0; 
	for(i=1;i<=n;i++) sum+=(cnt[i]==1); if(sum>0)sum--;
	for(i=1;i<=n;i++) sum+=(cnt[i]==2 ? 2 : 0);
	//printf("%d",cnt[2]);
	if(sum>=n-1) puts("Yes"); else puts("No");
	return 0;
}

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

int main(int argc, const char * argv[]) {

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0; i<n; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    int counter = 1;
    for(int j=0; j<n-1; j++){
        if(vec.at(j) != vec.at(j+1)){
            counter++;
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var S, T string
  
  fmt.Scanf("%s\n%s", &S, &T)
  
  var maxLen = 0
  for i := 0; i <= len(S) - len(T); i++ {
    var cnt = 0
    for j := 0; j < len(T); j++ {
      if S[i + j] == T[j] {
        cnt++
      }
    }
    if cnt > maxLen {
      maxLen = cnt
    }
  }
  
  fmt.Println(len(T) - maxLen)
}

Measured memory_bytes: 1856
//\\//\\ * * * //\\// ||
#include <bits/stdc++.h> 

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

template <typename T>
class fenwick {
 public:
  vector<T> fenw;
  int n;
  
  fenwick(int _n) : n(_n) {
    fenw.resize(n);
  }
  
  void modify(int x, T v) {
    while (x < n) {
      fenw[x] += v;
      x |= (x + 1);
    }
  }
 
  T get(int x) {
    T v{};
    while (x >= 0) {
      v += fenw[x];
      x = (x & (x + 1)) - 1;
    }
    return v;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, tt;
  cin >> n >> tt;
  fenwick<ll> fenw(n);
  auto Get = [&](int l, int r) {
    return (l == 0 ? fenw.get(r) : fenw.get(r) - fenw.get(l - 1));
  };
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    fenw.modify(i, x);
  }
  while (tt--) {
    int q;
    cin >> q;
    if (q == 1) {
      int l, r;
      cin >> l >> r;
      cout << Get(l, r - 1) << '\n';
    } else {
      int p;
      cin >> p;
      ll x;
      cin >> x;
      fenw.modify(p, x);
    }
  }
  return 0;
}


Measured memory_bytes: 8252
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let h: Vec<u64> = (&mut iter).take(n).map(|x| x.parse().unwrap()).collect();
    
    println!("{}", count(&h, 0));
}

fn count(h: &[u64], base: u64) -> u64 {
    let &m = h.iter().min().unwrap();
    let mut cnt = m - base;
    for t in split_series(h, m) {
        cnt += count(&t, m);
    }
    cnt
}

#[allow(dead_code)]
fn split_series<T: Clone + Eq>(series: &[T], sep: T) -> Vec<Vec<T>> {
    let mut l = 0;
    let mut ret = vec![];
    for r in 0..series.len() {
        if series[r] == sep {
            if l != r {
                ret.push(series[l..r].to_vec());
            }
            l = r + 1;
        }
    }
    if l != series.len() {
        ret.push(series[l..series.len()].to_vec());
    }
    ret
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
#define min(q,w) ((q)>(w)?(w):(q))
#define max(q,w) ((q)<(w)?(w):(q))
#define PR(...) printf(__VA_ARGS__)
#define EPR(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long LL;
const int N=100500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,ans;
int a[N];
bool z[N];
int B[2*N][2],A[N],B0;
void link(int q,int w)
{
	B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w;
	B[++B0][0]=A[w],A[w]=B0,B[B0][1]=q;
}
int main()
{
	// freopen("!.in","r",stdin);
//	freopen(".out","w",stdout);
	int q,w;
	read(n),read(m);
	printf("%d\n",n-m+1);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  
  string ans = "";
  
  for (char c: s) {
    if(c == '0'){
      ans += "0";
    } else if (c == '1') {
      ans += "1";
    } else if (!ans.empty() && c == 'B') {
      ans.pop_back();
    }
  }
  
  cout << ans << endl;
    
}

Measured memory_bytes: 256
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*考えを書くスペース


*/

//main.cpp----------------------------
#define MAX 1000

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

  cout << (int)((t+0.5)/a)*b;


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>

using namespace std;


void swap(int* a,int s,int v){
	int c;
	c=a[s];
	a[s]=a[v];
	a[v]=c;
	return;
}

int main(){
	int w,n;
	int ans[100];
	int sw[2];
	
	scanf("%d %d",&w,&n);
	int i;
	for(i=1;i<=w;i++){
		ans[i]=i;
	}
	for(i=0;i<n;i++){
		sw[1]=sw[0]=0;
		scanf("%d,%d",&sw[0],&sw[1]);
		swap(ans,sw[0],sw[1]);
	}
	
	for(i=1;i<=w;i++){
		printf("%d\n",ans[i]);
	}
	
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
#define MOD 1000000007

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll mod = pow(10, 9) + 7;

    ll N;
    cin >> N;
    vector<ll> A(N);

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

    map<ll, ll> count;

    for(ll i = 0; i < N; i++) {
        ll s = A[i];
        for(ll i = 2; i * i <= s; i++) {
            ll c = 0;
            while(s % i == 0) {
                c++;
                s /= i;
            }
            if(count[i])
                count[i] = max(count[i], c);
            else
                count[i] = c;
        }
    
        if(s != 1LL) {
            if(count[s])
                count[s] = max(count[s], 1LL);
            else
                count[s] = 1LL;
        }
    }

    ll ans = 0;
    ll base = 1LL;

    for(auto j = begin(count); j != count.end(); j++) {
        ll a = j -> first;
        ll c = j -> second;
        base *= modpow(a, c, mod) % mod;
        base %= mod;
    }

    for(int i = 0; i < N; i++) {
        ans += base * (modpow(A[i], mod - 2LL, mod) % mod) % mod;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4324
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l;
    cin>>n>>l;
    string a[n+2];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        cout<<a[i];
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int N, K; cin >> N >> K;
	int ans = 0;
	while (N > 0) {
		N /= K;
		ans++;
	}
	cout << ans << endl;

	return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, k; cin >> n >> k;
    int p[n];
    rep(i,n) cin >> p[i];

    int sumpi[1005];
    rep(i,1005){
        if(i == 0){
            sumpi[i] = i;
            continue;
        }
        sumpi[i] = i + sumpi[i-1];
    }

    double prov[n];
    rep(i,n){
        prov[i] = (double)sumpi[p[i]] / (double)p[i];
    }
    rep(i,n){
        if(i == 0) continue;
        prov[i] = prov[i] + prov[i-1];
    }
    
    double ans = -1;
    rep(i,n-k+1){
        if(i == 0){
            ans = max(ans, prov[k-1]);
        }else{
            ans = max(ans, prov[i+k-1]-prov[i-1]);
        }
    }
    /*
    rep(i,n) cout << prov[i] << " ";
    cout << endl;
    */

    printf("%f\n",ans);
    return 0;
}

Measured memory_bytes: 6040
def main(a, b, c, k):
  abc = sorted([a, b, c])
  abc[-1] *= 2**k
  print(sum(abc))

# tests = [
#   [5, 3, 11, 1],  # 30
#   [3, 3, 4, 2],  # 22
# ]

# for test in tests:
#   main(*test)

a, b, c = [int(i) for i in input().split()]
k = int(input())
main(a, b, c, k)

Measured memory_bytes: 3060
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
use std::cmp;
use std::fmt::Debug;

fn main() {
    input! {
        n: usize,
        h: [i32; n],
    }

    let mut dp = [0; 100000];
    dp[0] = 0;
    dp[1] = (h[1] - h[0]).abs();

    for i in 2..n {
        dp[i] = cmp::min(dp[i-1] + (h[i-1]-h[i]).abs(), dp[i-2] + (h[i-2]-h[i]).abs());
    }

    println!("{}", dp[n-1]);
    //print(&dp[0..4]);

}

fn print<T, U>(n: T) 
where T: IntoIterator<Item=U>,
    U: Debug 
{
    for elt in n {
        println!("{:?}", elt);
    }
}

Measured memory_bytes: 4732
L = int(input())
ans = []
N = 20
M = 0
for i in range(1, N-1):
    ans.append((i, i+1, 0))
    ans.append((i, i+1, 1<<(i-1)))
    M+=2
if L>=(1<<N-1):
    ans.append((N-1, N, 0))
    ans.append((N-1, N, 1<<(N-2)))    
    M+=2
    cnt = (1<<N-1)
    L-=(1<<N-1)
else:
    cnt = 0
for i in range(N-1):
    if L&(1<<i):
        ans.append((i+1, N, cnt))
        M+=1
        cnt+=(1<<i)
print(N, M)
for i in range(M):
    print(*ans[i])

Measured memory_bytes: 38256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 1e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}


vector<ll>adj[Max+10];
ll indeg[Max+10];

void addEdege(ll u,ll v)
{
    indeg[v]++;

    adj[u].eb(v);
}

ll cost[Max+10];

ll connect[Max+10];


ll topsort(ll s,ll last)
{


    queue<ll>q;

    q.push(s);

    cost[s]=1;

    ll u;

    while(!q.empty())
    {
        u=q.front();

        q.pop();

        for(auto v  : adj[u])
        {
            cost[v]=(cost[v]+cost[u])%Mod;

            indeg[v]--;

            if(!indeg[v])
                q.push(v);
        }
    }


    return cost[last]%Mod;
}

int main()
{

    fastread();

    ll i,j,p,n,m,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;


    bool flag=true;




    ll id=1;

    cin>>n>>m;

    string str[n+2];

    for(i=0; i<n; ++i)
        cin>>str[i];

    indeg[1]=1;

    for(i=0; i<n; i++)
    {
        id=(m*i)+1;



        for(j=0; j<m; j++,id++)
        {
            if(str[i][j]=='.' && indeg[id])
            {


                if(j+1<m && str[i][j+1]=='.' )
                    addEdege(id,id+1);


                if(i+1<n && str[i+1][j]=='.' )
                {
                    addEdege(id,id+m);
                }

            }




        }
    }



    cout<<topsort(1,n*m)<<endl;











}


Measured memory_bytes: 74956
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long
#define ld double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#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>
#define int long long
ll binpow(ll a,ll b,ll m=mod)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        res=(a*res)%m;
        a=(a*a)%m;
        b/=2;
    }
    return res;
}
vector<ll> ar[200001];
bool vis[200001];
ll w=0;
void dfs(ll s)
{   vis[s]=true;
    ++w;
    for(auto it : ar[s])
    {
        if(!vis[it])
            dfs(it);
    }
}
main()
{
    IO
    ll n,m;
    cin>>n>>m;
    memset(vis,false,sizeof(vis));
    ll u,v;
    for(int x=0;x<m;x++)
    {
        cin>>u>>v;
        ar[u].pb(v);
        ar[v].pb(u);
    }
    ll as=0;
    for(int x=1;x<=n;x++)
    {
        if(!vis[x]){w=0;
            dfs(x);
        as=max(w,as);
        }
    }
    cout<<as;
}


Measured memory_bytes: 20956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
constexpr int MX = 10005, MOD = 1e9+7;
int n;
map<int,int> mp;
ll a, x, y, ac = 1, ac2;
void exgcd(ll a, ll b, ll &x, ll &y){
	if(b){
		exgcd(b, a%b, y, x);
		y -= a/b*x;
	}else{
		x = 1; y = 0;
	}
}
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%lld", &a);
		exgcd(a,MOD,x,y);
		ac2 += x;
		for(int t=2; t*t<=a; t++) if(a%t == 0){
			int k=0;
			for(; a%t == 0; a/=t) k++;
			mp[t] = max(mp[t],k);
		}
		if(a>1) mp[a] = max(mp[a],1);
	}
	ac2 %= MOD; ac2 += MOD;
	for(pair<int,int> it: mp){
		tie(x,y) = it;
		rep(i,y) (ac *= x) %= MOD;
	}
	printf("%lld\n",ac*ac2%MOD);
}

Measured memory_bytes: 768
#include <stdio.h>

int n;
int v[20];
int c[20];

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&v[i]);
    for(int i=0;i<n;i++) scanf("%d",&c[i]);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(v[i]>c[i])ans+=v[i]-c[i];
    }
    printf("%d\n",ans);
}

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

int const MAX = 100005;
int const NIL = -1;

struct Node {int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print( int u ){
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if( T[u].p == NIL ) cout << "root, ";
  else if( T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for(i=0, c=T[u].l; c != NIL; i++, c = T[c].r){
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

//再帰的に深さを求める
int rec(int u, int p){
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r, p);
  if(T[u].l != NIL) rec(T[u].l, p+1);
}

int main(){
  int i, j, d, v, c, l, r;
  cin >> n; //How many nodes
  rep(i,n) T[i].p = T[i].l = T[i].r = NIL;

  rep(i,n){
    cin >> v >> d; //ノード番号, 次数
    rep(j,d){
      cin >> c; //children node number
      if( j == 0) T[v].l = c; // 選択の次数が0のとき,0番目の子(一番左)にｃを代入
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  rep(i,n){
    if(T[i].p == NIL)r = i; //根ノードを探す
  }

  rec(r,0); //根ノードを親として子供を数えて深さを取得

  rep(i,n) print(i); //入力された順番に出力

  return 0;
}


Measured memory_bytes: 7740
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

// 最大公約数 O(log(n))
ll gcd(ll a, ll b)
{
    if(b==0) swap(a,b);
    if(a%b == 0){
        return(b);
    }
    else{
        return(gcd(b, a%b));
    }
}

int main()
{
    ll N, i, A[100001], L[100010], R[100010], max=0;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> A[i];
    }

    L[0] = 0;
    for(i=1; i<=N; i++){
        L[i] = gcd(L[i-1], A[i]);
    }

    R[N+1] = 0;
    for(i=N; i>=1; i--){
        R[i] = gcd(R[i+1], A[i]);
    }

    for(i=1; i<=N; i++){
        chmax(max, gcd(L[i-1], R[i+1]));
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 2560
n = gets.to_i
s = gets.chomp.chars

left = {}
right = {}
('a'..'z').each { |c| left[c] = 0; right[c] = s.count(c) }

ans = 0
cnt = 0
s.each do |c|
  b1 = left[c] > 0 && right[c] > 0
  left[c] += 1
  right[c] -= 1
  b2 = left[c] > 0 && right[c] > 0

  if !b1 && b2
    cnt += 1
  elsif b1 && !b2
    cnt -= 1
  end
  ans = cnt if ans < cnt
end
puts ans

Measured memory_bytes: 3836
#include<stdio.h>
int main()
{
    int i, j, n, m, b, c, d;
    int a[7];
    for (i = 1; i < 7; i++) {
        scanf("%d", &a[i]);
    }
    for (j = 1; j <= 4; j++) {
        for (i = 1; i <= 4 - 1; i++) {
            if (a[i] < a[i + 1]) {
                m = a[i];
                a[i] = a[i + 1];
                a[i + 1] = m;
            }
        }
    }
        if (a[5] > a[6]) {
            b = a[5];
        }
        else {
            b = a[6];
        }
        c = a[1] + a[2] + a[3] + b;
        printf("%d\n", c);
    return 0;
}
        

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

int main(){
    int N;
    cin >> N;
    int A[N];
    int sum = 0;
    REP(i,N){
        cin >> A[i];
        sum += A[i];
    }
    int sig = 1;
    if(sum < 0){
        sig = -1;
        sum = -sum;
    }
    int p = sum / N + ((sum % N) * 2 < N ? 0 : 1);
    p *= sig;
    int s = 0;
    REP(i,N){
        s += (A[i] - p) * (A[i] - p);
    }
    cout << s << endl;
}

Measured memory_bytes: 256
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    double ele;
    cin >>n;
    priority_queue<double, vector<double>, greater<double>> pq;
    for(int i = 0; i < n; i++){
        cin >>ele;
        pq.push(ele);
    }
    while(pq.size() != 1){
        double a = pq.top();
        pq.pop();
        double b = pq.top();
        pq.pop();
        pq.push((a + b)/2);
    }
    cout <<pq.top();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>

using namespace std;

const int MAXN = 3e5+10;
int n ,  a[MAXN];
long long ans = -1e18 , f[MAXN] , r[MAXN];

int main()
{
    //freopen("B.inp" , "r" , stdin);
    //freopen("B.out" , "w" , stdout);
    scanf("%d",&n);
    for(int i = 1 ; i<=3*n ; i++)
        scanf("%d",&a[i]);
    priority_queue<int , vector<int> , greater<int> > q;
    for(int i = 1 ; i<=n ; i++)
    {
        q.push(a[i]);
        f[n] += a[i];
    }
    for(int i = n+1 ; i<=2*n ; i++)
    {
        if(a[i] <= q.top()) f[i]  = f[i-1];
        else
        {
            f[i]= f[i-1] + a[i] - q.top();
            q.pop();
            q.push(a[i]);
        }
    }

    priority_queue<int> qq;

    for(int i = 3*n ; i>=2*n+1 ; i--)
    {
        r[2*n+1] += a[i];
        qq.push(a[i]);
    }

    for(int i = 2*n ; i>=n+1 ; i--)
    {
        if(a[i] >= qq.top()) r[i] = r[i+1];
        else
        {
            r[i] = r[i+1] + a[i] - qq.top();
            qq.pop();
            qq.push(a[i]);
        }
    }

    for(int i = n ; i <= 2*n ; i++)
        ans = max(ans , f[i] - r[i+1]);

    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = int;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    Graph G(N);
    for (int i = 0; i < N - 1; i++)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<ll> c(N);
    for (int i = 0; i < N; i++)
    {
        ll tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    RSORT(c);
    vector<int> ans(N);

    int ind = 0;

    ll sum = accumulate(c.begin(), c.end(), 0) - c[0];

    vector<bool> dist(N, false);
    queue<int> que;

    dist[0] = true;
    que.push(0);
    ans[0] = c[ind];
    ind++;
    while (!que.empty())
    {
        int v = que.front();
        que.pop();

        for (auto &&nv : G[v])
        {
            if (dist[nv])
                continue;
            ans[nv] = c[ind];
            ind++;
            que.push(nv);
            dist[nv] = true;
        }
    }
    cout << sum << endl;

    for (int i = 0; i < N; i++)
    {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : (x))
#define all(x) x.begin(), x.end() // sort(all(x))
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair((x), (y))

typedef long long ll;

typedef double T;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tiii;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<T> vt;
typedef vector<vt> vvt;
typedef vector<pii> vpi;
typedef vector<pii> vpl;
typedef vector<vpi> graph;
typedef complex<T> Pt;
typedef pair<Pt, Pt> Line;

const ll MOD = 1e9 + 7; // 998244353;
const T EPS = 1e-10;
const int INF = 1e9 + 1;

/* Mod Library */

struct Mod {
    ll x;
    Mod (ll x = 0) : x(x) {}
    Mod operator+(Mod b) { return Mod((x + b.x)%MOD); }
    Mod operator-(Mod b) { return Mod((x - b.x + MOD)%MOD); }
    Mod operator*(Mod b) { return Mod((x * b.x)%MOD); }
    Mod operator/(Mod b) { return *this * inverse(b); }
    Mod operator%(Mod b) { return Mod(x % b.x); }

    static ll euclid(ll a, ll b, ll &x, ll &y) {
        if (b) {
            ll d = euclid(b, a%b, y, x);
            y -= a/b*x;
            return d;
        }
        x = 1; 
        y = 0;
        return a;
    }
    
    Mod inverse(Mod a) {
        ll x, y, g = euclid(a.x, MOD, x, y);
        assert(g == 1);
        return Mod((x + MOD)%MOD);
    }

    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this^(e/2);
        r = r*r;
        return e&1 ? *this*r : r;
    }
};

/* Input Library */
template <typename A, typename B>
istream& operator>>(istream &in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template <typename A, typename B>
ostream& operator<<(ostream &out, pair<A, B> &p) {
    out << p.first << " " << p.second;
    return out;
}

template <typename I>
istream& operator>>(istream &in, vector<I> &a) {
    trav(i, a) in >> i;
    return in;
}

template <typename I>
ostream& operator<<(ostream &out, vector<I> &a) {
    rep(i, 0, sz(a)) {
        if (i) out << " ";
        out << a[i];
    }
    return out;
}

void fast_io() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    //cout.tie(0);
    cin.exceptions(cin.failbit);
} 

void solve_test() {
  vi ans(10101);
  for (int x = 1; x < 100; ++x) {
    for (int y = 1; y < 100; ++y) {
      for (int z = 1; z < 100; ++z) {
        int n = x*x + y*y + z*z + x*y + x*z + y*z;
        if (n <= 1e4) {
          ans[n]++;
        }
      }
    }
  }

  int n; 
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cout << ans[i] << endl;
  }
}

void setup() {
}

int main() {
    setup();
    srand(time(0));
    fast_io();
    int t = 1;
    //cin >> t;
    while (t--) {
        solve_test();
    }
}


Measured memory_bytes: 3660
//https://atcoder.jp/contests/abc126/tasks/abc126_c

import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double N = sc.nextDouble();
        double K = sc.nextDouble();
        double ans = 0;
        for (int i=1;i<=N;i++){
            int point = i;
            int cnt = 0;
            while (point<K){
                point *= 2;
                cnt++;
            }
            ans += 1/N*Math.pow(0.5,cnt);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<string>
 
using namespace std;
 
int main()
{
    int n;cin>>n;
    long long int sum=0;
    for(int i=1;i<=n;++i){
        if(i%3==0||i%5==0)continue;
        sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
using namespace std;
int a[3];
void readData(){
	for(int i=0;i<3;i++) scanf("%d",&a[i]);
}
void solve(){
	sort(a,a+3);
	int ans=a[2]-a[1];
	a[0]+=a[2]-a[1];
	if((a[2]-a[0])&1)
		ans+=((a[2]-a[0])>>1)+2;
	else
		ans+=(a[2]-a[0])>>1;
	printf("%d\n",ans);
}
int main(){
	readData();
	solve();
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

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

	char str[2][101];
	scanf("%s%s", str[0], str[1]);

	for (int i = 0; i < n; i++)
		printf("%c%c", str[0][i], str[1][i]);
	putchar('\n');
}


Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<vector>

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

int main(){
    int n, m;
    cin >> n >> m;
    int a[n], b[n];
    vector<int> v[m+1];
    rep(i, n) {
        cin >> a[i] >> b[i];
        if (a[i] <= m) {
            v[a[i]].push_back(b[i]);
        }
    }
    priority_queue<int> q;
    int dp[m+1];
    dp[m] = 0;

    for(int i = m - 1; i >= 0; i--){
        if (v[m - i].size() > 0) {
            rep(j, v[m-i].size()) q.push(v[m-i][j]);
        }

        if (q.size() > 0) {
            dp[i] = dp[i+1] + q.top();
            q.pop();
        }else{
            dp[i] = dp[i+1];
        }
        


        
        // cout << "i = " << i << ":" << dp[i] << endl;
    }
    cout << dp[0] << endl;
}

Measured memory_bytes: 6784
#
# coding: utf-8
 
def bubbleSort(arr, n):
 
    flag = True
    swap_num = 0
 
    while flag:
        flag = False
        for j in xrange(n-1, 0, -1):
            if arr[j] < arr[j-1]:
                arr[j], arr[j-1] = arr[j-1], arr[j]
                swap_num += 1
                flag = True
        pass
    return swap_num
 
 
n = int(raw_input())
arr = map(int, raw_input().split())
 
num = bubbleSort(arr, n)
print " ".join(map(str, arr))
print num

Measured memory_bytes: 6380
//in progress
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define forn(i,n) for(int i =0; i < (int)(n); i++)
#define rfr(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define PI 3.14159265
int n,a[100010],store[100010];
int recur(int ind)
{
  if(ind>=n-1)
  return 0;
  else if(ind==n-2)
  return abs(a[n-1]-a[n-2]);
  if(store[ind+1]==-1)
  store[ind+1]=recur(ind+1);
  if(store[ind+2]==-1)
  store[ind+2]=recur(ind+2);
  return min(store[ind+1]+abs(a[ind+1]-a[ind]),store[ind+2]+abs(a[ind+2]-a[ind]));
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //freopen("a.in", "r", stdin);
  //freopen("a.out", "w", stdout);
  cin>>n;
  memset(store,-1,sizeof(store));
  for(int i=0;i<n;i++)
  cin>>a[i];
  cout<<recur(0)<<"\n";
  return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    ll n,k,mod=pow(10,9)+7;
    cin>>n>>k;
    ll a[n+1],ans=0,b[n+1],ans1=0;
    // a[0]=0;
    // b[n]=n;
    // for(ll i=1;i<n+1;i++)    a[i]=(a[i-1]%mod+i%mod)%mod;
    // for(ll i=n-1;i>=0;i--)    b[i]=(b[i+1]%mod+i%mod)%mod;
    // for(ll i=0;i<n+1;i++)   cout<<a[i]<<" "<<b[i]<<endl;
    for(ll i=k;i<=n+1;i++){
        // ans=(ans%mod+b[n-i+1]%mod)%mod;
        // ans1=(ans1%mod+a[i-1]%mod)%mod;
        ll t=(i*(2*n-i+1))/2;
        ll t1=(i*(i-1))/2;
        // cout<<t<<" "<<t1<<endl;
        ans=(ans%mod + (t-t1)%mod + 1 ) %mod; 
        // ans=(ans%mod+(((k*(2*n-k+1))/2)-((k*(k-1))/2)+1)%mod)%mod;
    }
    // ans=(ans%mod-ans1%mod)%mod;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	vector<vector<int>> list;
	for (auto i = 0; i < M; ++i)
	{
		int k;
		cin >> k;
		vector<int> temp;
		for (auto j = 0; j < k; ++j)
		{
			int s;
			cin >> s;
			--s;
			temp.push_back(s);
		}
		list.push_back(temp);
	}

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

	auto ans = 0;
	for (auto i = 0; i < 1 << N; ++i)
	{
		auto valid = true;
		for (auto j = 0; j < M; ++j)
		{
			auto sum = 0;
			for (auto s : list[j])
			{
				auto bit = 1 << s;
				if ((i & bit) != 0)
				{
					++sum;
				}
			}

			if (sum % 2 != p[j])
			{
				valid = false;
				break;
			}
		}
		if (valid)
		{
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {

  // u: from
  // v: to
  case class Edge(u: Int, v: Int, w: Long)

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    // ここ、0オリジン化した方がいい
    val edges = IndexedSeq.fill(n-1)(Edge(sc.nextInt(), sc.nextInt(), sc.nextInt()))
    (n, edges)
  }

  def solve(n:Int, edges:IndexedSeq[Edge]): IndexedSeq[Int] = {
    val nextList = IndexedSeq.fill(n+1)(ArrayBuffer.empty[Edge])
    for(edge <- edges){
      val from = edge.u
      val to = edge.v
      nextList(from).append(edge)
      nextList(to).append(Edge(to, from, edge.w))
    }
    val visited = Array.fill(n+1)(false)
    // 1から
    visited(1) = true
    val open: java.util.Queue[Int] = new java.util.ArrayDeque[Int]()
    //add, remove
    open.add(1)
    //白:false ,黒:true
    val colors = Array.fill(n+1)(true)
    colors(1) = false


    while(!open.isEmpty){
      val current = open.remove()
      for(edge <- nextList(current)){
        val next = edge.v
        if(!visited(next)) {
          val w = edge.w
          if (w % 2 == 0) {
            colors(next) = colors(current)
          } else {
            colors(next) = !colors(current)
          }
          visited(next) = true
          open.add(next)
        }
      }
    }
    colors.takeRight(n).map(p => if(p) 1 else 0)
  }

  def output1(result: IndexedSeq[Int]) = {
    result.foreach(println)
  }

  def output2(result: IndexedSeq[Int]) = {
    result.foreach(System.out.println)
  }

  def output3(result: IndexedSeq[Int]) = {
    val out = new java.io.PrintWriter(System.out)
    result.foreach(out.println)
    out.flush()
  }

  def main(args: Array[String]): Unit = {
    val (n, edges) = read()
    output2(solve(n,edges))
  }
}

Measured memory_bytes: 120088
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] arr = s.toCharArray();
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == 'b') {
				arr[i] = 'd';
			} else if (arr[i] == 'd') {
				arr[i] = 'b';
			} else if (arr[i] == 'p') {
				arr[i] = 'q';
			} else if (arr[i] == 'q') {
				arr[i] = 'p';
			}
		}
		StringBuilder sb = new StringBuilder(new String(arr));
		sb.reverse();
		if (s.equals(sb.toString())) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26932
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int main() {
  int n;
  cin >> n;
  vector<vector<int>> dist(n, vector<int>(n, -1)), mat(n, vector<int>(n, 1));
  queue<pair<int, int>> q;
  auto add = [&](int i, int j) {
    if (dist[i][j] == -1)
      q.push({i, j});
  };
  for (int i = 0; i < n; ++i) {
    add(i, 0);
    dist[i][0] = 0;
    add(i, n - 1);
    dist[i][n - 1] = 0;
    add(0, i);
    dist[0][i] = 0;
    add(n - 1, i);
    dist[n - 1][i] = 0;
  }
  while (!q.empty()) {
    auto [i, j] = q.front();
    q.pop();
    for (int k = 0; k < 4; ++k) {
      int ni = i + dy[k], nj = j + dx[k];
      if (ni < 0 || ni >= n || nj < 0 || nj >= n)
        continue;
      if (dist[ni][nj] == -1) {
        dist[ni][nj] = dist[i][j] + 1;
        q.push({ni, nj});
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < n * n; ++i) {
    int idx;
    cin >> idx;
    idx--;
    int r = idx / n, c = idx % n;
    ans += dist[r][c];
    mat[r][c] = 0;
    q.push({r, c});
    while (!q.empty()) {
      auto [ci, cj] = q.front();
      q.pop();
      for (int k = 0; k < 4; ++k) {
        int ni = ci + dy[k], nj = cj + dx[k];
        if (ni < 0 || ni >= n || nj < 0 || nj >= n)
          continue;
        if (dist[ni][nj] > dist[ci][cj] + mat[ci][cj]) {
          dist[ni][nj] = dist[ci][cj] + mat[ci][cj];
          q.push({ni, nj});
        }
      }
    }
  }

  cout << ans;
}

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int h, w;
  cin >> h >> w;

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

  string row = "";
  for (int i = 0; i < w + 2; i++) {
    row += "#";
  }

  cout << row << endl;
  for (int i = 0; i < h; i++) {
    cout << "#" << a[i] << "#" << endl;
  }
  cout << row << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

S, W = read_int()

def solve():
    ans = 'unsafe'
    if S > W:
        ans = 'safe'
    return ans

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 9976
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

long long gcd(long long x, long long y) { return y ? gcd(y,x%y) : x;}

int main(){
    int n;
    cin >> n;
    ll ans = 0;
    rep(i,1,n){
        rep(j,1,n){
            rep(k,1,n){
                ans += gcd(i,gcd(j,k));
            }
        }
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

const int max_n = 100003;


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

    if(N%2==0) cout << N << endl;
    else cout << N*2 << endl;

    return 0;
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main() {
    int n;
    cin >> n;
    vi x(n);
    REP(i, n) {
        cin >> x[i];
    }
    SORTALL(x);
    ll ans = LLONG_MAX;
    FOR(p, x[0], x[n - 1] + 1) {
        ll tmp = 0;
        REP(i, n) {
            tmp += (x[i] - p) * (x[i] - p);
        }
        ans = min(ans, tmp);
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<string>
using namespace std;
const int INF = 1e9;
int main(){
    int n;
    int maxn = 0, minn = INF;
    cin >> n;
    int x[105];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        maxn = max(maxn, x[i]);
        minn = min(minn, x[i]);
    }
    int minns = INF;
    for (int i = minn; i <= maxn; i++) {
        int sum = 0;
        for (int j = 0; j < n; j++) {
            sum += (i - x[j]) * (i - x[j]);
        }
        minns = min(minns, sum);
    }
    cout << minns << endl;
    return 0;
}

Measured memory_bytes: 256