akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.readline
from collections import deque
from math import isinf
INF = float("inf")
sys.setrecursionlimit(200000)
n = int(readline())
G = [[] for _ in range(n)]
D = [INF] * n
for _ in [0] * (n - 1):
    s, t, w = map(int, readline().split())
    G[s].append([t, w])
    G[t].append([s, w])
def bfs(s, D):
    dq = deque([s])
    D = [INF] * n
    D[s] = 0
    while dq:
        u = dq.popleft()
        for i in range(len(G[u])):
            e = G[u][i]
            if isinf(D[e[0]]):
                D[e[0]] = D[u] + e[1]
                dq.append(e[0])
    return D
D = bfs(0, D)
maxv = 0
tgt = 0
for i in range(n):
    if isinf(D[i]): continue
    if maxv < D[i]:
        maxv = D[i]
        tgt = i
D = bfs(tgt, D)
print(max(D[i] for i in range(n) if not isinf(D[i])))

Measured memory_bytes: 55628
#include<bits/stdc++.h>
using namespace std;
int main() {
	int y,m,d;
	char s;
	while(cin>>y>>s>>m>>s>>d){
		if(y>2019){
			cout<<"TBD"<<endl;
		}
		else if(y==2019){
			if(m>4){
				cout<<"TBD"<<endl;
			}
			else{
				cout<<"Heisei"<<endl;
			}
		}
		else{
			cout<<"Heisei"<<endl;
		}
	}
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

vector<pair<int, long long>> adj[100001];
int colour[100001];

int main(){

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    for(int i = 0; i < n; ++i){

        if(i + 1 < n){
            int a, b, weight;
            cin >> a >> b >> weight;

            adj[a - 1].push_back(make_pair(b - 1, weight));
            adj[b - 1].push_back(make_pair(a - 1, weight));
        }

        colour[i] = -1;

    }

    queue<pair<int, long long>> q;
    q.push(make_pair(0, 0));
    colour[0] = 0;

    while(!q.empty()){

        pair<int, long long> state = q.front();
        q.pop();

        for(auto nx : adj[state.first]){
            if(colour[nx.first] != -1)
                continue;
            colour[nx.first] = (state.second + nx.second) % 2;
            q.push(make_pair(nx.first, state.second + nx.second));
        }

    }

    for(int i = 0; i < n; ++i)
        cout << colour[i] << "\n";

    return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

const long long mod = 1e9 + 7;

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

	vector<int> alpha(26, 0);
	for (char c: s) {
		alpha[c - 'a']++;
	}


	long long ans = 1;
	for (int x: alpha) {
		ans = ans * (x + 1) % mod;
	}

	ans = (ans + mod - 1) % mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n, m, a[114514];
int imos[200005];
int mai[200005];
signed main() {
	cin >> n >> m;
	rep(i, n)cin >> a[i];
	int sum = 0;
	REP(i, n) {
		int k = a[i - 1], l = (a[i - 1] < a[i] ? a[i] : a[i] + m);
		sum += l - k;
		if (l - k == 1)continue;
		imos[k + 2]++;
		imos[l + 1]--;
		mai[l + 1] += l - k - 1;
	}
	rep(i, 2 * m + 1) {
		imos[i + 1] += imos[i];
	}
	rep(i, 2 * m + 1) {
		imos[i] -= mai[i];
		imos[i + 1] += imos[i];
	}
	for (int i = m + 1; i <= 2 * m; i++)imos[i % m] += imos[i];
	int ma = 0;
	rep(i, m + 1) {
		chmax(ma, imos[i]);
	}
	cout << sum - ma << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    vec a(3);
    rep(i,3) cin>>a[i];
    ll ma = max({a[0], a[1], a[2]});
    ll minus = 0;
    rep(i,3) minus += ma - a[i];
    if(minus&1){
        cout<<(minus + 3)/2<<endl;
    }else{
        cout<<minus/2<<endl;
    }
}

Measured memory_bytes: 256
n = int(input())
songs = []
for _ in range(n):
    s, t = input().split()
    t = int(t)
    songs.append((s, t))
x = input()

ans = 0
flag = False
for s, t in songs:
    if flag:
        ans += t
    if s == x:
        flag = True

print(ans)


Measured memory_bytes: 9156
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt(),b=scan.nextInt(),c=scan.nextInt();
		if(a+b>=c) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}}}

Measured memory_bytes: 35700
#include <stdio.h>

int
main(void)
{
	int a;
	int b;
	int c;
	int d = 0;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a > b) {
		d = b;
		b = a;
		a = d;
	}
	if (b > c) {
		d = c;
		c = b;
		b = d;
	}
	if (a > b) {
		d = b;
		b = a;
		a = d;
	}
	
	printf("%d %d %d\n", a, b, c);
	
	return 0;
}



Measured memory_bytes: 2036
#include <cstdio>
#include <algorithm>
using namespace std;
struct me{
    long long pos;
    long long value;
}my[100005];
bool cmp(struct me a,struct me b){
    return a.pos<b.pos;
}
long long v1[100005],v2[100005];
int main(){
    int n;
    long long c;
    scanf("%d%lld",&n,&c);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&my[i].pos,&my[i].value);
    }
    sort(my+1,my+1+n,cmp);
    long long sum=0;
    for(int i=1;i<=n;i++){
        sum+=my[i].value;
        v1[i]=max(v1[i-1],sum-my[i].pos);
    }
    sum=0;
    for(int i=n;i>=1;i--){
        sum+=my[i].value;
        v2[i]=max(v2[i+1],sum-(c-my[i].pos));
    }
    long long mmax1=v2[1],mmax2=v1[n];
    sum=0;
    for(int i=1;i<=n;i++){
        sum+=my[i].value;
        mmax1=max(mmax1, v2[i+1]+sum-2*my[i].pos);
    }
    sum=0;
    for(int i=n;i>=1;i--){
        sum+=my[i].value;
        mmax2=max(mmax2, v1[i-1]+sum-2*(c-my[i].pos));
    }
    printf("%lld\n",max(mmax1, mmax2));
    return 0;
}


Measured memory_bytes: 3328
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <algorithm>   //sort,二分探索,など
#include <bitset>      //固定長bit集合
#include <chrono>      //実行時間計測
#include <cmath>       //pow,logなど
#include <complex>     //複素数
#include <deque>       //両端アクセスのキュー
#include <functional>  //sortのgreater
#include <iomanip>     //setprecision(浮動小数点の出力の誤差)
#include <iostream>    //入出力
#include <iterator>    //集合演算(積集合,和集合,差集合など)
#include <map>         //map(辞書)
#include <numeric>     //iota(整数列の生成),gcdとlcm,accumulate
#include <queue>       //キュー
#include <set>         //集合（順序保持）
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair
#include <vector>  //可変長配列
using namespace std;
typedef long long ll;
typedef long double ld;

#define REP(i, n) for (int i = 0; i < ll(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < ll(b); i++)
#define FORD(i, a, b) for (int i = a; i > ll(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく
const long long INF = 1e12;
const int MOD = 1e9 + 7;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define Umap unordered_map
#define Uset unordered_set
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85
void print() { cout << endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}

template <class T> void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}

void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}
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;
}

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    int sum = 0;
    REP(i, n) {
        cin >> A.at(i);
        sum ^= A[i];
    }

    REP(j, n) { cout << (sum ^ A[j]) << " "; }
    cout << endl;
}


Measured memory_bytes: 3940
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using pint = tuple<int64_t, int64_t>;
using vint = vector<int64_t>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

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>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    int n; cin >> n;
    vstr s(n); vin(s);
    set<string> set;
    rfor(c, s) set.insert(c);
    println(set.size());

    return 0;
}


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

#define N 3
#define N2 9

struct Puzzle {
	int f[N2];
	int space;
	bool operator <( const Puzzle p ) const
	{
		for( int i = 0; i < N2; i++ ) {
			if( f[i] == p.f[i] ) continue;
			return f[i] < p.f[i];
		}
		return false;
	}
};

bool isTarget( Puzzle &u )
{
	for( int i = 0; i < N2; i++ ) {
		if( u.f[i] != i + 1 ) return false;
	}
	return true;
}

int main()
{
	Puzzle s;
	for( int i = 0; i < N2; i++ ) {
		cin >> s.f[i];
		if( s.f[i] == 0 ) {
			s.space = i;
			s.f[i] = N2;
		}
	}

	int dirh[] = { 0, 0, -1, 1 };
	int dirv[] = { -1, 1, 0, 0 };
	queue<pair<Puzzle, int>> que;
	map<Puzzle, int> m;
	int ans;
	que.push( make_pair( s, 0 ) );
	m[s] = 1;
	while( !que.empty() ) {
		Puzzle u;
		int cnt;
		tie( u, cnt ) = que.front();
		que.pop();
		if( isTarget( u ) ) {
			ans = cnt;
			break;
		}
		int sy = u.space / N;
		int sx = u.space % N;
		for( int i = 0; i < 4; i++ ) {
			int nx = sx + dirh[i];
			int ny = sy + dirv[i];
			if( nx < 0 || N <= nx || ny < 0 || N <= ny ) continue;
			int ni = ny * N + nx;
			Puzzle v;
			v = u;
			swap( v.f[ni], v.f[v.space] );
			v.space = ni;
			if( m.find( v ) == m.end() ) {
				que.push( make_pair( v, cnt + 1 ) );
				m[v] = 1;
			}
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 20500
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>
#include<stack>

const long long MOD = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    string S;
    cin >> S;
    llong cnt=0;
    llong maxv = -1;
    for(int i=0; i<S.size(); i++){
        if(S[i]!='A' && S[i]!='C' && S[i]!='G' && S[i]!='T'){
            maxv = max(cnt, maxv);
            cnt = 0;
            continue;
        }
        cnt++;
    }
    maxv = max(cnt, maxv);
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3120
const INF: i64 = 100000000;

fn main() {
  let (n, m, _): (usize, usize, usize) = read_tuple(); 
  let rs: Vec<usize> = read_vec();
  let es: Vec<(usize, usize, i64)> = read_tuples(m);
  
  let mut wf: Vec<Vec<i64>> = vec![vec![INF; n+1]; n+1];
  for (a, b, c) in es {
    wf[a][b] = c;
    wf[b][a] = c;
  }
  
  for k in 1 .. n+1 {
    for i in 1 .. n+1 {
      for j in 1 .. n+1 {
        wf[i][j] = std::cmp::min(wf[i][j], wf[i][k] + wf[k][j]);
      }
    }
  }
  
  let ans =
    permutations(&rs).
    iter().
    map(|r| r.windows(2).fold(0, |a,w| a + wf[w[0]][w[1]])).
    min().
    unwrap();
  
  println!("{}", ans);
}

fn permutations<T: Clone + std::fmt::Debug>(vec: &Vec<T>) -> Vec<Vec<T>> {  
  fn go<T: Clone + std::fmt::Debug>(vec: &Vec<T>, n: usize, m: usize, k: usize, buf: &mut Vec<usize>, acc: &mut Vec<Vec<T>>) {
    if k == 0 {
      let r: Vec<T> = buf.iter().map(|&i| vec[i-1].clone()).collect();
      acc.push(r);
    } else {
      for x in n .. m + 1 {
        if !buf.contains(&x) {
          buf.push(x);
          go(vec, n, m, k-1, buf, acc);
          buf.pop();
        }
      }
    }
  }
  
  let mut acc = vec![];
  go(vec, 1, vec.len(), vec.len(), &mut vec![], &mut acc);
  acc
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
}

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr, T3: std::str::FromStr>() -> (T1, T2, T3) {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  let z = it.next().unwrap().parse::<T3>().ok().unwrap();
  (x, y, z)
}

fn read_tuples<T1: std::str::FromStr, T2: std::str::FromStr, T3: std::str::FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
  let mut vec: Vec<(T1, T2, T3)> = vec![];
  for _ in 0 .. n {
    vec.push(read_tuple());
  }
  vec
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

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

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

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

    char maze[h][w];
    int white = 0;
    rep(i, h){
        rep(j, w){
            cin >> maze[i][j];
            if(maze[i][j] == '.') ++white;
        }
    }

    int ans[h][w];
    fill_n(*ans, h*w, -1);
    queue<pint> q;
    ans[0][0] = 0;
    q.push(make_pair(0, 0));
    while(!q.empty()){
        pint tmp = q.front();
        q.pop();
        int x = tmp.second, y = tmp.first;

        rep(i, 4){
            int nx = x+dx[i], ny = y+dy[i];
            if(nx < 0 or nx >= w or ny < 0 or ny >= h) continue;

            if(maze[ny][nx] == '.' and ans[ny][nx] == -1){
                ans[ny][nx] = ans[y][x] + 1;
                q.push(make_pair(ny, nx));
            }
        }

    }


    if(ans[h-1][w-1] == -1)
        ppp(-1);
    else{
        ppp(white-ans[h-1][w-1]-1);
    }


    rep(i, h){
        rep(j, w){
            cerr << setw(3) << ans[i][j];
        }
        cerr << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))

S = set()
for i in range(1<<n):
  s = 0
  for j in range(n):
    if (i>>j)&1:
      s += A[j]
  S.add(s)


for j in q:
  if j in S:
    print("yes")
  else:
    print("no")


Measured memory_bytes: 5644
from collections import defaultdict

N, M = map(int, input().split())
A = list(map(int, input().split()))

numCnt = defaultdict(int)

for a in A:
    numCnt[a] += 1

for _ in range(M):
    B, C = map(int, input().split())
    numCnt[C] += B

ans = 0
numList = list(numCnt.items())
numList.sort(reverse=True)

for num, cnt in numList:
    while N > 0 and cnt > 0:
        ans += num
        N -= 1
        cnt -= 1

print(ans)

Measured memory_bytes: 42452
#include <iostream>
#include <stack>
using namespace std;
 
int main() {
	stack<int> st;
    int train;
    while(cin >> train){
        if(train) st.push(train);
        else{
            cout << st.top() << endl;
            st.pop();
        }
    }
	return 0;
}

Measured memory_bytes: 1196
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

lines = [set(x) for x in a] + [set(x) for x in zip(*a)] + [set([a[0][0], a[1][1], a[2][2]]), set([a[0][2], a[1][1], a[2][0]])]
bs = set(b)

if any(line.issubset(bs) for line in lines):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
main() {
	int H, W;
	cin >> H >> W;
	if (H == 1 || W == 1) cout << "1\n";
	else if (H & 1) cout << W * (H / 2) + W - (W / 2);
	else cout << W * (H / 2) << '\n';
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int t,u,r,l;

char mark[100][100];
bool flag = 0;
int n;
/*
0:ツ湘」
1:ツ右
2:ツ可コ
3:ツ債カ
*/
void saiki(int x,int y,int turn){
	if(flag){
		if(n%2==0)mark[x][y]='#';
		return;
	}
	mark[x][y]='#';
	if( turn == 0 && y==t ){
		l+=2;
		if(x+1>=r){flag=1;}
		saiki(x+1,y,(turn+1)%4);
	}else if(turn == 2 && y==u ){
		r-=2;
		if(x-1<=l){flag=1;}
		saiki(x-1,y,(turn+1)%4);
	}else if(turn == 3 && x == l){
		u-=2;
		if(y-1<=t){flag=1;}
		saiki(x,y-1,(turn+1)%4);
	}else if(turn == 1 && x == r){
		t+=2;
		if(y+1>=u){flag=1;}
		saiki(x,y+1,(turn+1)%4);
	}else {
		if(turn == 0)saiki(x,y-1,turn);
		else if(turn == 1)saiki(x+1,y,turn);
		else if(turn == 2)saiki(x,y+1,turn);
		else if(turn == 3)saiki(x-1,y,turn);
	}
}

int main(){
	int c = 0;
	cin >> n;
	while(cin >> n){
		if(c++)cout << endl;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				mark[j][i]=' ';
		}
		flag = 0;
		l = t = 0;
		r = u = n-1;
		saiki(0,n-1,0);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				cout << mark[j][i];
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<

using namespace std;

namespace Math {
  const int N = (int)2e5 + 5;
  const int MOD = (int)1e9 + 7;

  int Add(int a, int b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
  }

  int Mul(int a, int b) {
    return 1LL * a * b % MOD;
  }

  int Pow(int b, int e) {
    if (e < 0) e += MOD - 1;
    int ans = 1;
    while (e) {
      if (e & 1) ans = Mul(ans, b);
      b = Mul(b, b);
      e >>= 1;
    }
    return ans;
  }

  int fact[N], tcaf[N];

  void Precalc() {
    fact[0] = 1;
    for (int i = 1; i < N; ++i) {
      fact[i] = Mul(fact[i - 1], i);
    }
    tcaf[N - 1] = Pow(fact[N - 1], -1);
    for (int i = N - 2; i >= 0; --i) {
      tcaf[i] = Mul(tcaf[i + 1], i + 1);
      assert(Mul(fact[i], tcaf[i]) == 1);
    }
  }

  int Choose(int n, int k) {
    return Mul(fact[n], Mul(tcaf[n - k], tcaf[k]));
  }
}

using namespace Math;

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

  Precalc();

  int n, m, a, b; cin >> n >> m >> a >> b;
  int ans = 0;
  for (int c = b; c < m; ++c) {
    int r = n - a - 1;
    ans = Add(ans, Mul(Choose(r + c, c), 
                       Choose(n - r + m - c - 3, m - c - 1))); 
  }
  cout << ans << endl;
}


Measured memory_bytes: 5192
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) { //gcdを返す
	if(a == 0){
		return b;
	} else if (b == 0){
		return a;
	} else {
	  if(a < b) return gcd(b, a);
	  ll r;
	  while ((r=a%b)) {
	    a = b;
	    b = r;
	  }
	  return b;
	}
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(){
	ll N;
	cin >> N;
	vector<long double> v(N);
	REP(i, N){
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	long double ans = v[0];
	for(ll i = 1; i < N; i++){
		ans = (ans + v[i]) / 2;
	}
	cout << ans << endl;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a.at(i);
	}
	b=a;
	sort(a.begin(),a.end(),greater<int>());
	for(int i=0;i<n;i++){
		if(b.at(i)==a.at(0)){
			cout<<a.at(1)<<endl;
		}else{
			cout<<a.at(0)<<endl;
		}
	}

}


Measured memory_bytes: 3200
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << x + y / 2 << endl;
}



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

using namespace std;

int main(){
    int n;
    long long int ans = 1000000000000000000;
    long long int ans2 = 1;
    cin >> n;

    vector<long long int>v(n);

    for(int i = 0;i < n;i++){
        long long int a;
        cin >> a;
        v[i] = a;
        if(a==0)ans2 = 0;
    }

    for(int i = 0;i < n;i++){
        if(ans2 == 0){
            break;
        }
        
        ans /= v[i];
        if(ans == 0){
            cout << -1 << endl;
            return 0;
        } 
        ans2 *= v[i];
    }

    cout << ans2 << endl;

    return 0;
}

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

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) -> 
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "
const int M = 1024 * 256;

int n[2], x, mi[2];
int T[2][M];

int32_t main()
{
	scanf("%d%d%d", n, n + 1, &x);
	mi[0] = 1e9;
	mi[1] = 1e9;
	FOR(i, 0, 1)
	{
		FOR(j, 1, n[i])
		{
			scanf("%d", T[i] + j);
			mini(mi[i], T[i][j]);
		}
	}
	int res = mi[0] + mi[1];
	FOR(i, 1, x)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		mini(res, T[0][a] + T[1][b] - c);
	}
	printf("%d\n", res);
}














Measured memory_bytes: 1024
program main
  implicit none
  integer :: ab, i
  character(6) :: sa, sb, sab
  read(*, *) sa, sb
  sab = trim(sa) // trim(sb)
  read(sab, *) ab
  do i = 1, 1000
    if (i * i == ab) then
      write(*, "(a)") "Yes"
      stop 0
    end if
  end do
  write(*, "(a)") "No"
  ! if (nint(ab ** 0.5) ** 2 == ab) then
  !   write(*, "(a)") "Yes"
  ! else
  !   write(*, "(a)") "No"
  ! end if
end program main


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

char c[1001][1001];
int d[1001][1001];
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};

int main() {
	int n,m,s1,s2,e1,e2;
	scanf("%d%d%d%d%d%d",&n,&m,&e1,&e2,&s1,&s2);
	s1--,s2--,e1--,e2--;
	for(int i=0; i<n; i++) scanf("%s",c[i]);

	queue<int> q, que;
	
	memset(d,-1,sizeof(d));
	que.push(e1); que.push(e2);
	q.push(e1); q.push(e2);
	d[e1][e2]=0;

	while (!q.empty() || !que.empty()) {
		if(!que.empty()) {
			while (!que.empty()) {
				int x=que.front(); que.pop();
				int y=que.front(); que.pop();
				for(int i=0; i<4; i++) {
					int nx2=dx[i]+x;
					int ny2=dy[i]+y;
					if (nx2<0 || nx2>=n || ny2<0 || ny2>=m || c[nx2][ny2]=='#') continue;
					if (d[nx2][ny2]==-1||d[nx2][ny2]>d[x][y]) {
						d[nx2][ny2]=d[x][y];
						que.push(nx2); que.push(ny2);
						q.push(nx2); q.push(ny2);
					}
				}
			}
		}
		else {
			int x=q.front(); q.pop();
			int y=q.front(); q.pop();
			for(int i=x-2; i<x+3; i++) {
				for(int j=y-2; j<y+3; j++) {
					if (i<0 || i>=n || j<0 || j>=m || (i==x && j==y) || c[i][j]=='#') continue;
					if (d[i][j]==-1||d[i][j]>d[x][y]+1) {
						d[i][j]=d[x][y]+1;
						que.push(i); que.push(j);
						q.push(i); q.push(j);
					}
				}
			}
		}
	}
	printf("%d\n", d[s1][s2]);
	return 0;
}

Measured memory_bytes: 8712
#include <stdio.h>

int main(void){
    int A,B,C;
    int X;
    int i,j,k;
    int cnt=0;
    scanf("%d%d%d%d",&A,&B,&C,&X);
    for(i=0;i<=A;i++){
        for(j=0;j<=B;j++){
            for(k=0;k<=C;k++){
                if(500*i+100*j+50*k==X) cnt++;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int gcd(long long ,long long);
int main(){
  long long a,b,c;
  while(cin>>a>>b){
  c=gcd(a,b);
  cout<<c<<endl;
  }
  return 0;
}

int gcd(long long x,long long y){
  while(x!=y){
    if(x>y){
      x=x%y;
      if(x==0) return y;
    }
    else{
      y=y%x;
      if(y==0) return x;
    }
  }
  return x;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const i64 INF = 1LL << 40;

auto closest(const vector<i64>& v, i64 x) -> pair<i64, i64> {
  auto it = lower_bound(v.begin(), v.end(), x);
  i64 d1 = INF, d2 = INF, y1 = INF, y2 = INF;
  if (it != v.end()) {
    d1 = *it - x;
    assert(d1 >= 0);
    y1 = *it;
  }
  if (it != v.begin()) {
    --it;
    d2 = x - (*it);
    assert(d2 >= 0);
    y2 = *it;
  }
  if (d1 <= d2) {
    return {d1, y1};
  }
  return {d2, y2};
}

auto calc(const vector<i64>& v1, const vector<i64>& v2, i64 x) -> i64 {
  i64 res = INF;
  auto it = lower_bound(v1.begin(), v1.end(), x);
  if (it != v1.end()) {
    i64 d1 = *it - x;
    assert(d1 >= 0);
    auto [d2, z] = closest(v2, *it);
    res = min(res, d1 + d2);
  }
  if (it != v1.begin()) {
    --it;
    i64 d1 = x - (*it);
    assert(d1 >= 0);
    auto [d2, z] = closest(v2, *it);
    res = min(res, d1 + d2);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<i64> ps(A), pt(B);
  REP(i, A) cin >> ps[i];
  REP(i, B) cin >> pt[i];
  REP(i, Q) {
    i64 x;
    cin >> x;
    i64 res = min(calc(ps, pt, x), calc(pt, ps, x));
    cout << res << '\n';
  }
}


Measured memory_bytes: 4744
import java.util.Scanner;

/**
 * Main
 */
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int A = s.nextInt();
        int B = s.nextInt();

        if (0 < A && A < 10 && 0 < B && B < 10) {
            System.out.println(A * B);
        } else {
            System.out.println(-1);
        }

        s.close();
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <cstdint>

template <std::uint_fast64_t Modulus>
class modint {
    using u64 = std::uint_fast64_t;

public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
    constexpr u64& value() noexcept { return a; }
    constexpr const u64& value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint& operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint& operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint& operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint& operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};

using Mint = modint<998244353>;

int main() {
    int n, s;
    std::cin >> n >> s;

    std::vector<int> a(n);
    for (auto&& e : a)
        std::cin >> e;

    Mint ans = 0;
    std::vector<Mint> sums(s);
    for (int i = 0; i < n; ++i) {
        sums[0] += 1;
        if (a[i] > s)
            continue;

        ans += sums[s - a[i]] * (n - i);

        for (int j = s - a[i] - 1; j >= 0; --j)
            sums[j + a[i]] += sums[j];
    }

    std::cout << ans.a << std::endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)


function main()
    ans = 0
    K = parseInt(readline())
    for a in 1:K
        for b in 1:K
            for c in 1:K
                ans += gcd(a,b,c)
            end
        end
    end
    println(ans)
end

main()

Measured memory_bytes: 158676
<?php

$inp = trim( fgets( STDIN ) );
$new_str = 0;

while( true ) {
  if ( preg_match( '/(1B|0B|B)/', $inp ) === 0 ) {
    echo $inp;
    return;
  }
  $inp = preg_replace( '/(1B|0B|B)/', '',  $inp, 1 );
}


?>

Measured memory_bytes: 4604
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    G = [[-1 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        a = Scanner.int()
        for _ in range(a):
            x, y = Scanner.map_int()
            x -= 1
            G[i][x] = y
    ans = 0
    for i in range(1 << N):
        V = [0 for _ in range(N)]
        for j in range(N):
            if (i >> j) & 1:
                V[j] = 1
        isOk = True
        for j in range(N):
            for k in range(N):
                if V[k] == 0:
                    continue
                if G[k][j] == -1:
                    continue
                if G[k][j] != V[j]:
                    isOk = False
        if isOk:
            ans = max(ans, V.count(1))
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 43624
#include <iostream>
#include <string>

#define C "Cat"
#define R "Rabbit"

using namespace std;

string s;

void fn(int i)
{
	if(i+2<s.size()){
		if(s[i+1]=='m') fn(i+1);
		if(s[i+1]=='e'){
			if(s[i+2]=='m') fn(i+2);
			if(s[i+2]=='w') {
				s.erase(i,3);
			}
		}
	}
}

int main(void)
{	
	int i1,i2;

	cin>>s;
	fn(0);
	if(s.empty()) cout<<C<<endl;
	else cout<<R<<endl;

	return 0;
} 

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int N=4005;
int cnt, r[N], g[N], b[N];
signed main(){
	int n;
	string s;
	cin>>n;//字符的个数 
	cin>>s;//s是字符串 
	
	for(int i=n-1;i>=0;i--)//后缀和，时间O(n) 
	{
		//如果是R字符，那就等于下一个的R的个数+1 
		if(s[i]=='R') r[i]=r[i+1]+1;
		else r[i]=r[i+1];
		//如果是G
		if(s[i]=='G') g[i]=g[i+1]+1;
		else g[i]=g[i+1];
		//如果是B
		if(s[i]=='B') b[i]=b[i+1]+1;
		else b[i]=b[i+1];
	}
	
	int i,j,k;
	for(i=0;i<n-2;i++)
	{
		for(j=i+1;j<n-1;j++)
		{//k从j+1 
			if(s[j]!=s[i]){
				//判断剩下的应该是什么颜色 
				char re;//第三种颜色字符 
				if(s[i]!='R' && s[j]!='R') re='R';
				else if(s[i]!='G' && s[j]!='G') re='G';	
				else if(s[i]!='B' && s[j]!='B') re='B';
				//如果第三种颜色是R则加上从j+1到结尾总共还有多少个R 
				if(re=='R') cnt+=r[j+1];
				else if(re=='G') cnt+=g[j+1];
				else if(re=='B') cnt+=b[j+1];
				//如果j+(j-i)的位置恰好是第三种颜色则数值减去1 
				if(2*j-i<n && s[2*j-i]==re) cnt--;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3700
import math
from collections import Counter

n, m = map(int, input().split())
mod = 10**9 + 7

K = 50
fact = [0] * (n+1+K)
ifact = [0] * (n+1+K)
fact[0] = 1
for i in range(1,n+1+K):
    fact[i] = fact[i-1] * i % mod
ifact[n+K] = pow(fact[n+K], mod-2, mod)
for i in reversed(range(1,n+1+K)):
    ifact[i-1] = ifact[i] * i % mod

def comb(n, k):
    return fact[n] * ifact[n-k] % mod * ifact[k] % mod

def getprime(n):
    primes = []
    i = 2
    while n >= i * i:
        while n % i == 0:
            n //= i
            primes.append(i)
        i += 1
    if n != 1:
        primes.append(n)
    return primes

ans = 1
counter = Counter(getprime(m))
for k in counter.values():
    ans *= comb(n+k-1, k)
    ans %= mod
print(ans)

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

int64_t gojou(int64_t n){
    return n*n*n*n*n;
}
 
int main(void)
{
    int i,j;
    int64_t X,A,B,sum,max,ans1,ans2;
    bool can;

    can = false;

    max = 1000000000000000;

    cin >> X;

    for(i=1;i<max;i++){
        for(j=i-1;j<max;j--){
            sum = gojou(i) - gojou(j);
            if(sum == X){
                can = true;
                ans1 = i;
                ans2 = j;
                break;
            }
            if(sum > X){
                break;
            }
        }
        if(can)break;
    }

    cout << ans1 << " " << ans2 << endl;

    
    return 0;
}

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

int main(){
  int H = 0,W = 0;
  cin >> H >> W;
  for (int i = 0; i < W + 2 ; i++){
    cout << "#" ;
  }
  cout << endl;
  for (int i = 0; i < H; i++){
    string str;
    cin >> str;
    cout << "#" << str << "#" << endl;
  }
  for(int i = 0; i < W + 2 ; i++){
    cout << "#" ;
  }
}
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

long long SumRect(vector<long long> A)
{
	int n = A.size();
	long long sum = 0;
	for (int i = 0;i < n / 2;i++)
	{
		int r = (n - 1) - i;
		int factor = i - r;

		sum = (sum + (factor * A[i]) - (factor * A[r])) % mod;
	}

	return sum;
}

int main()
{
	long long ans = 0;

	int N, M;
	cin >> N >> M;

	vector<long long> X(N);
	vector<long long> Y(M);

	for (int i = 0;i < N;i++)
		cin >> X[i];

	for (int i = 0;i < M;i++)
		cin >> Y[i];


	long long Xsum = 0;
	long long Ysum = 0;
	Xsum = SumRect(X);
	Xsum %= mod;

	Ysum = SumRect(Y);
	Ysum %= mod;

	ans = (Xsum * Ysum) % mod;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int n;
int a[100100][3], dp[100100][3];

int max(int a, int b) {
    return (a > b ? a : b);
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) scanf("%d", &a[i][j]);
    }
    for (int i = 0; i < 3; i++) dp[0][i] = a[0][i];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 3; i++) ans = max(ans, dp[n - 1][i]);
    printf("%d\n", ans);
}

Measured memory_bytes: 2560
import java.io.*; 
import java.util.*;

public class Main
{
  public static void main(String[] args) { new Main(); }
  Scanner in = new Scanner(System.in);
  PrintWriter out = new PrintWriter(System.out);
  
  int a, b;
  
  Main()
  {
    a = in.nextInt();
    b = in.nextInt();
    if ((a % 2) != (b % 2)) out.println("IMPOSSIBLE");
    else out.println((a+b)/2);
    out.close();
  }
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int lli;
double EPS = 1e-8;

lli solve(lli n){
    lli total = 2*n*n +8*n;
    lli s = n/2;
    lli rem = 0;
    lli sqrts = ceil(sqrt((long double)s));
    rem += (s-sqrts)*(s-sqrts);
    for(lli i=1; i<sqrts; i++){
        rem += ( s - (s+i-1)/i ) *2;
    }
    return total -rem*8;
}

int main(){
    while(1){
        lli n;
        cin >> n;
        if(n==0) break;
        cout << solve(n) << endl;
    }
    return 0;
}



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

//ダブリングを使った解法
// 1 2 3 4 5
// 4 3 5 2 2 1回進んだ先
// 2 5 2 3 3 2回進んだ先
// 5 3 5 2 2 4回進んだ先
// 2 5 2 3 3 8回進んだ先
//...
//


const int D = 60;
const int MAX_N = 2000005;
int to[D][MAX_N];

int main(){
    
    int n;ll k;
    cin >> n >> k;
    
    rep(i,n){
        cin >> to[0][i];
        to[0][i]--;
    }
    //to[i][j]: jから2^i個たどった先
    
    rep(i,D-1){
        rep(j,n){
            to[i+1][j] = to[i][to[i][j]];
        }
    }
    
    int v = 0;
    
    rep(i,D){
        if(1LL<<i & k)
            v = to[i][v];
    }
    
    
    /*
    for(int i=D-1; i>=0; i--){
        //ll l = 1LL<<i;
        if(1LL<<i & k)
            v = to[i][v];
    }
    */
    
    cout << v+1 << endl;
    
    return 0;
}

Measured memory_bytes: 50700
#include<iostream>
#include<vector>
#define _USE_MATH_DEFINES
#include<math.h>
#include<algorithm>
#include<memory>
#include<string>
typedef long long ll;
#define Rep(i,n) for(int i = 0;i < (n);i++)	

int gcd(int a, int b) { if (b == 0)  return a;  else  return gcd(b, a % b);  }
int lcm(int a, int b) { return a * b / gcd(a, b); }
void swap(int& a, int& b) { int temp = a; a = b; b = temp; return; }
int ncr(int n, int r) { int a = 1; Rep(i, r) a = (a * (n - i)) / (i + 1); return a; }
int npr(int n, int r) { int a = 1; Rep(i, r) a *= n - i; return a; }
int mod(int a, int b) { return a % b; }

int main() {
	double a;
	std::cin >> a;
	printf("%20.10f", 2 * a * M_PI);
	/*
	int n, m;
	std::vector<int> A;
	std::cin >> n >> m;
	int sum = 0;
	Rep(i, m) {
		int k;
		std::cin >> k;
		sum += k;
	}
	if (sum <= n) {
		std::cout << n - sum << std::endl;
	}
	else {
		std::cout << -1 << std::endl;
	}
	*/
	return 0;
}

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

using System.Collections;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());

        int[] aList = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int[] arr = new int[N];
        arr[0] = aList[0];

        for(int i = 1; i < N; i++)
        {
            var pre = arr[i - 1];
            var next = aList[i];

            while(true)
            {
                if(pre > next)
                {
                    if (pre % next != 0)
                        pre = pre % next;
                    else
                        break;
                }
                else
                {
                    if (next % pre != 0)
                        next = next % pre;
                    else
                        break;
                }
            }

            arr[i] = Math.Min(pre, next);
        }

        Console.WriteLine(arr[N - 1]);
    }
    
}

Measured memory_bytes: 22112