akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}


void cerrall(const vector<bool>& a){rep(i,a.size()) cerr << i << " " << (a[i]? "True" : "False") << "\n"; cerr << "\n";}
template<class T> void cerrall(const vector<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const set<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const multiset<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T, class U> void cerrall(const vector<pair<T,U>>& a){rep(i,a.size()) cerr << i << " : " << a[i].first << " " << a[i].second << "\n";}
template<class T, class U> void cerrall(const map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}
template<class T, class U> void cerrall(const unordered_map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}

template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}

template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int n,k;cin >> n >> k;
    int ans = 0;
    rep(i,n){
        int h;cin >> h;
        if(h >= k) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[] ) throws Exception {
    	new Main().exec(args);
    }

    public Main() {
    }

    public void exec(String args[]) throws Exception {
    	//初期化読み込み
    	Scanner sc = new Scanner(System.in);
    	String s=sc.next();
    	StringBuilder sb = new StringBuilder();
    	int countG=0;
    	int countP=0;
    	for(int i=0; i<s.length(); i++) {
    		if(s.charAt(i)=='g'){
    			countG++;
    		}else{
    			countP++;
    		}
    	}
    	int P = countG-countP;
    	System.out.println(P/2);
    }
}

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

int main() {
    string n;
    cin >> n;
    if (n[0] == n[1] && n[0] == n[2]) {
        cout << "Yes" << endl;
    } else if (n[1] == n[2] && n[1] == n[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import math
 
def solv(a, b, x):
    if x == a ** 2 * b:
        return 0
    elif x <= a**2 * b / 2:
        tanTheta = (2 * x) / (a * b ** 2)
    else:
        tanTheta = (a ** 3) / (2 * (a ** 2 * b - x))
    return 90 - math.degrees(math.atan(tanTheta))
 
a, b, x = map(int, input().split(" "))
print(solv(a, b, x))

Measured memory_bytes: 3064
#include<cmath>
#include<string>
#include<fstream>
#include<iostream>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){
	int A,B,C;
	int X;
	cin >> A >> B >> C;
	cin >> X;
	int cnt=0;
	rep(c,C+1) rep(a,A+1) if((X-50*c-500*a)>=0&&(X-50*c-500*a)%100==0&&(X-50*c-500*a)/100<=B) cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
num, time = map(int, input().split(' '))
# print(num, time)

columns = []
able_columns = []
my_dict = {}


for i in range(num):
    columns = (list(map(int,input().rstrip().split(' '))))
    if columns[1] <= time:
        able_columns.append(columns)

if able_columns == []:
    print('TLE')


else:
    for i in able_columns:
        my_dict[i[0]] = i[1]
    print(min(my_dict))


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

bitset<410> a[410];

int n, m, x[100010], y[100010], gg[410]; 

int main()
{
	gii(n, m);
	for (int i = 1; i <= m; ++i)
		gii(x[i], y[i]);
	for (int i = 1; i <= n; ++i)
	{
		a[i][i] = 1;
		for (int j = m; j; --j)
			if (a[i][x[j]] && a[i][y[j]])
			{
				gg[i] = 1;
				break;
			}
			else
			if (a[i][x[j]])
				a[i][y[j]] = 1;
			else
			if (a[i][y[j]])
				a[i][x[j]] = 1;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (gg[i]) continue;
		for (int j = i; j <= n; ++j)
		{
			if (gg[j]) continue;
			if ((a[i] & a[j]).count()) continue;
			++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	4 * MAX5;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll t = 1;
ll n, x, k, q, m, y, r;
string s;


// <------------- Implement Functions Here ----------> //




// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n ;
	ll mini = INF;
	vll a(n);
	for(ll i=0;i<n;i++) cin>>a[i];
	sort(all(a));
	for(ll i=a[0]; i<=a[n-1]; i++) {
		ll m = 0;
		for(ll j=0;j<n;j++) {
			m += pow(a[j]-i,2);
		}
		mini = min(mini,m);
	}
	cout<<mini;
}

int main() {
	fastio; randomINT;
	//cin >> t;
	while (t--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 13004
n = gets.to_i
l = gets.split.map(&:to_i)
l.sort!
h = {}
l.each do |m|
  if h.has_key?(m)
    h[m]+=1
  else
    h[m]=1
  end
end
keys = h.keys.sort!
a = keys.length
if a < 3
  puts 0
  exit
end
ans = 0
(0..a-3).each do |i|
  (i+1..a-2).each do |j|
    (j+1..a-1).each do |k|
      if keys[i] + keys[j] > keys[k]
        ans += h[keys[i]] * h[keys[j]] * h[keys[k]]
      end
    end
  end
end

puts ans

Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>

using namespace std;

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		(1000000)
#define Rep(i,n) for(int i = 0; i < (n); i++ )

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define	show(x)	 copy( (x).begin(), (x).end(), ostream_iterator<int>(cout, ",") );	// container<int>を全て表示

using namespace std;

typedef long long ll;

ll kaijo( ll N )
{
	// 階乗
	if( N == 0 ) return 1;
	return N * kaijo(N - 1);
}

map<ll, ll> prime_factor(ll N)
{
	// 素因数分解
	map<ll, ll> ret;
	for( ll i = 2; i * i <= N; i++ ){
		while( N % i == 0 ){
			ret[i]++;
			N /= i;
		}
	}
	if(N != 1) ret[N] = 1;
	return ret;
}

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

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

ll max( ll a, ll b )
{
	if( a > b ) return a;
	return b;
}
ll min( ll a, ll b )
{
	if( a > b ) return b;
	return a;
}

class UnionFind
{
public:
	vector<int> parent;
	vector<int> rank;

	UnionFind(int n)
	{
		Rep(i, n){
			parent.push_back(i);
			rank.push_back(1);
		}
	}
	int root(int x)
	{
		if( parent[x] != x ) parent[x] = root(parent[x]);
		return parent[x];
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if( rx == ry ) return;
		if( rank[rx] > rank[ry] ){
			parent[ry] = rx;
			rank[rx] += rank[ry];
		}
		if( rank[rx] <= rank[ry] ){
			parent[rx] = ry;
			rank[ry] += rank[rx];
		}
	}
};

int main()
{
	ll N = 0;
	ll ans = 0;
	string S = "";

	cin >> N >> S;

	for( ll i = 1; i < N - 1; ++i ){
		string X = S.substr(0, i);
		string Y = S.substr(i, N - i);
		set<char> tmp;

		for(ll j = 0; j < X.length(); ++j){
			for(ll k = 0; k < Y.length(); ++k){
				if(X[j] == Y[k]) tmp.insert(X[j]);
			}
		}
		ans = max(ans, tmp.size());
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M=map(int,input().split())
    edge=[[] for _ in range(N)]
    for _ in range(M):
        a,b=map(int1,input().split())
        edge[a].append(b)
        edge[b].append(a)
    que=deque([0])
    d=[INF]*N
    d[0]=0
    ans=[0]*N
    while que:
        v=que.popleft()
        for nv in edge[v]:
            if d[nv]==INF:
                d[nv]=d[v]+1
                ans[nv]=v
                que.append(nv)
    print('Yes')
    for i in range(1,N):
        print(ans[i]+1)

if __name__ == '__main__':
    main()


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

int main()
{
	int c[5][5];

	cin >> c[1][1] >> c[1][2] >> c[1][3] >> c[2][1] >> c[2][2] >> c[2][3] >> c[3][1] >> c[3][2] >> c[3][3];

	if(((c[1][1]-c[1][2]) == (c[2][1]-c[2][2])&& (c[1][1] - c[1][2]) == (c[3][1] - c[3][2]))
		&& ((c[1][2] - c[1][3]) == (c[2][2] - c[2][3]) && (c[1][2] - c[1][3]) == (c[3][2] - c[3][3]))
		&& ((c[1][1] - c[1][3]) == (c[2][1] - c[2][3]) && (c[1][1] - c[1][3]) == (c[3][1] - c[3][3]))
		&& ((c[1][1] - c[2][1]) == (c[1][2] - c[2][2]) && (c[1][1] - c[2][1]) == (c[1][3] - c[2][3]))
		&& ((c[1][1] - c[3][1]) == (c[1][2] - c[3][2]) && (c[1][1] - c[3][1]) == (c[1][3] - c[3][3]))
		&& ((c[2][1] - c[3][1]) == (c[2][2] - c[3][2]) && (c[2][1] - c[3][1]) == (c[2][3] - c[3][3]))) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

    return 0;
}

Measured memory_bytes: 256
c = input()
A = ["a", "b", "c", "d", "e", "f", "g" ,"h", "i",
     "j", "k", "l", "m", "n", "o", "p", "q", "r",
     "s", "t", "u", "v", "w", "x", "y", "z"]
for i in range(len(A)):
    if A[i] == c:
        print(A[i + 1])
        break

Measured memory_bytes: 3060
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll M,D;
    cin >> M >> D;
    ll ans = 0;
    rep(m,1,M+1){
        rep(d,1,D+1){
            if(d >= 10){
                string t = to_string(d);
                if(t[0]-'0' >= 2 && t[1] - '0' >= 2 && (d/10) * (d%10) == m) ans++;
            }
        }
    }
    print(ans);

    
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,k,c;
    string s;
    in>>n>>k>>c>>s;
    vector<int> id,L(n),R(n);
    fr(i,n) if(s[i]=='o') id.emplace_back(i);
    int l{},cnt{};
    vector<int> v(id.size(),-1);
    while(l<id.size()){
        //cout<<id[l]+1<<'\n';
        v[l]=cnt++;
        l=upper_bound(id.begin(),id.end(),id[l]+c)-id.begin();
    }
    if(cnt>k) return 0;
    vector<int> C(id.size()+1);
    ifr(i,id.size()){
        int ll=upper_bound(id.begin(),id.end(),id[i]+c)-id.begin();
        C[i]=C[ll]+1;
        //cout<<i<<" "<<ll<<" "<<C[i]<<endl;
    }
    fr(i,id.size()){
        if(v[i]==-1) continue;
        //cout<<id[i]<<" "<<v[i]<<" "<<C[i+1]<<'\n';
        if(v[i]+C[i+1]<k) cout<<id[i]+1<<'\n';
    }
}

Measured memory_bytes: 5772
//----------------------------------------------------------------
//C

#include <iostream>
using namespace std;

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) res = max(res, dp[N][j]);
    cout << res << endl;
}




Measured memory_bytes: 8296
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int ans=0;
	int ansc=0;
	for(int i=1;i!=a+1;i++) {
		int count=0;
		for(int j=i;j%2==0;count++,j/=2) {}
			if(ansc<count) {
				ans=i;
				ansc=count;
			}
	}
	System.out.println(a==1?1:ans);
}
}

Measured memory_bytes: 23124
N = int(input())
A = list(map(int, input().split()))
c = 0
for i in A:
    if i%2 == 0:
        if i%3 == 0 or i%5 == 0:
            pass
        else:
            c = 1
if c == 0:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 38384
# coding=utf-8

from collections import deque

A = deque([])
N = int(input())
for i in range(N):
    query = list(map(int, input().split()))
    if query[0] == 0:
        if query[1] == 0:
            A.appendleft(query[2])
        elif query[1] == 1:
            A.append(query[2])
    elif query[0] == 1:
        print(A[query[1]])
    elif query[0] == 2:
        if query[1] == 0:
            A.popleft()
        if query[1] == 1:
            A.pop()



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

int main(void){
	int n,r,c,p,a;
	while(1){
		cin >> n >> r;
		if(!n && !r) break;
		vector<int> d(n);
		for(int i=0;i<n;i++){
			d[i] = n-i;
		}
		for(int i=0;i<r;i++){
			cin >> p >> c;
			for(int j=c; j>0;j--){
				a = d[c+p-2];
				d.erase(d.begin()+c+p-2);
				d.insert(d.begin(),a);


			}
			// for(int j=0;j<n;j++){
			// cout << d[j] << endl;
			// }
		}
		// cout << "answer" << endl;
		// for(int i=0;i<n;i++){
		// 	cout << d[i] << endl;
		// }
		cout << d[0] << endl;
	}

	return 0;
}

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

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

using ll = long long;
const ll MOD = 1'000'000'007;
const int MN = 1'000'000;

int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    string s;
    cin >> s;
    int ans = 0;
    if(s[0]== 'S' && s[1] == 'S' && s[2]=='S') cout << 0 << endl;
    else if(s[0]== 'R' && s[1] == 'R' && s[2]=='R') cout << 3 << endl;
    else if(s[0]== 'R' && s[1] == 'R') cout << 2 << endl;
    else if(s[1] == 'R' && s[2]=='R') cout << 2 << endl;
    else cout << 1 << endl;

    

}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int Judge(int n)
{
	int m=0,t;
	while(n)
	{
		t=n%10;
		if(t==7)
		m=1;
		n/=10;
	}
	return m;
}
int main()
{
	int n;
	cin>>n;
	if(Judge(n))
	cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3676
#include <stdio.h>
#include <math.h>

 
int main()
{
    int i, n;
    int x[100], y;
    int d1 = 0, di = 0;
    double d2 = 0, d3 = 0;
	
    scanf("%d", &n);
    
	for(i=0; i<n; i++) {
        scanf("%d", &x[i]);
    }
    for(i=0; i<n; i++) {
        scanf("%d", &y);
        y = abs(y-x[i]);
        d1 += y;
        d2 += y * y;
        d3 += y * y * y;
    	if(di < y){
    		di = y;
    	}
    }
    printf("%d\n%f\n%f\n%d\n", d1, sqrt(d2), pow(d3, 1.0/3.0), di);
    return 0;
}

Measured memory_bytes: 672
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int N, M, R;
int sea[200][200], land[200][200];
ll dp[2][200];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, t;
    char _c;
    while(cin >> N >> M && N){
        rep(i, N) rep(j, N)
          sea[i][j] = land[i][j] = i == j ? 0: INF;
        rep(i, M){
            cin >> x >> y >> t >> _c; --x; --y;
            if(_c == 'L')
              land[x][y] = land[y][x] = min(land[x][y], t);
            else
              sea[x][y] = sea[y][x] = min(sea[x][y], t);
        }
        
        rep(k, N) rep(i, N) rep(j, N){
            sea[i][j] = min(sea[i][j], sea[i][k] + sea[k][j]);
            land[i][j] = min(land[i][j], land[i][k] + land[k][j]);
        }
        
        rep(i, 2) rep(j, 200) dp[i][j] = INF;
        int crr = 0, nxt = 1, from, to;
        cin >> R;
        rep(i, R){
            cin >> to; --to;
            rep(j, 200) dp[nxt][j] = INF;
            if(i == 0){
                dp[crr][to] = 0;
                from = to;
                continue;
            }
            rep(j, N){
                //from,to (through land)
                //corner case(because in general recursion, land[from][to] mistaken as land[from][j] + land[j][to])
                dp[nxt][j] = min(dp[nxt][j], dp[crr][j] + (ll)land[from][to]);
                rep(k, N)//from, k, j, to (through land, sea, land)
                  dp[nxt][j] = min(dp[nxt][j], dp[crr][k] + (ll)land[from][k] + (ll)sea[k][j] + (ll)land[j][to]);
            }
            swap(crr, nxt);
            swap(from, to);
        }
        
        ll ans = INF;
        rep(i, N) ans = min(ans, dp[crr][i]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1508
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;

  for(v=0; v<n; v++){
    if(M[u][v] == 0) continue;
    if( color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dsf() {
  int u;

  for(u=0; u<n; u++)
    color[u] = WHITE;

  tt = 0;

  for(u=0; u<n; u++)
    if(color[u] == WHITE) dfs_visit(u);

  for(u=0; u<n; u++)
    printf("%d %d %d\n", u+1, d[u], f[u]);
}

int main(){

  int i,j;
  int u,v,k;
  
  scanf("%d", &n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      M[i][j] = 0;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d %d", &u, &k);
    u--;
    for(j=0; j<k; j++){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }

  dsf();

  return 0;
}



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

int gcd(int x, int y);

int main(){
    int x, y;
    cin >> x >> y;
    int ans = gcd(x,y);
    cout << ans << '\n';
    return 0;
}

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


Measured memory_bytes: 3100
N = int(input())
S = input()
count = S[0:N].count('.')
min = count
for i in range(0, N):
    if S[i:i + 1] == '#':
        count += 1
    else:
        count -= 1
    if count < min:
        min = count
if N == 1:
    min = 0
print("{}".format(min))


Measured memory_bytes: 3500
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    map<int,map<int,int> >in;
    rep(i,n){
      int m;cin>>m;
      rep(j,m){
	int tmp;cin>>tmp;
	in[i][tmp]=1;
      }
    }
    int ans=-2;
    int m;cin>>m;
    vector<int>out(m);
    rep(i,m)cin>>out[i];
    rep(i,n){
      bool han=true;
      rep(j,m)if(!in[i][out[j]]){han=false;break;}
      if(han){
	if(ans==-2)ans=i+1;
	else ans=-1;
      }
    }
    if(ans<0)ans=-1;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1628
use proconio::{input, fastout};

fn upper_bound<T: Ord>(v: &Vec<T>, x: &T) -> usize {
    let mut ng = -1i64;
    let mut ok = v.len() as i64;
    while ok - ng > 1 {
        let mid = (ng + ok) / 2;
        if v[mid as usize] > *x  {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ok as usize
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        k: i64,
        a: [i64; n],
        b: [i64; m],
    }

    let mut cuma: Vec<i64> = vec![0];
    let mut cumb: Vec<i64> = vec![0];
    for i in 0..n {
        cuma.push(*cuma.last().unwrap() + a[i]);
    }
    for i in 0..m {
        cumb.push(*cumb.last().unwrap() + b[i]);
    }

    let mut ans: usize = 0;
    for i in 0..=n {
        if cuma[i] > k {
            break;
        }
        let ub = upper_bound(&cumb, &(k - cuma[i]));
        if i + ub - 1 > ans {
            ans = i + ub - 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 12700
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define     sorta(v)         sort(all(a))
#define     sortd(v)        sort(all(a), greater<ll >())
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

bool compare_float(double x, double y){
    return fabs(x - y) < DBL_EPSILON;
}

double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
// vll pwx(61);
// void cal(ll x){ pwx[0] = 1; rep(i, 1, 61)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005
vector<ll> ans(space, 0);

ll compute(ll x, ll y, ll z){
	return x*x + y*y + z*z + x*y + y*z + z*x;
}

void solve(){
	ll n;
	cin >> n;

	for(ll i = 1 ; i <= 100 ; i++){
		for(ll j = 1 ; j <= 100 ; j++){
			for(ll k = 1 ; k <= 100 ; k++){
				ans[compute(i, j, k)]++;
			}
		}
	}

	for(ll i = 1 ; i<= n ; i++)
		cout << ans[i] << nl;
}

 
int main(){
    boost;
    // cal(1);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 4700
#include<bits/stdc++.h>
#define rep(i, x) for (ll i = 0; i < (x); i++)
#define chmax(x, a)  do { x = max(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main(void) {
  map<string, ll> mp;
  ll n;
  cin >> n;
  rep(i, n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  for (auto s : vector<string> {"AC", "WA", "TLE", "RE"}) {
    cout << s << "  x " << mp[s] << endl;
  }
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    if(a+b <= 2*c) {
        cout << x*a + y*b;
    }
    else {
        if(x <= y) {
            if(2*c <= b) {
                cout << 2*y*c;
            }
            else {
                cout << (y - x)*b + 2*x*c;
            }
        }
        else {
            if(2*c <= a) {
                cout << 2*x*c;
            }
            else {
                cout << (x - y)*a + 2*y*c;
            }
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    
    for(int i = 1; i <= 50000; i++){
        int tmp = i * 1.08;
        if(tmp == N) {
            cout << i << endl;
            return 0;
        }
    }
    
    cout << ":(" << endl;
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int l = sc.nextInt();
		
		// 計算
		ArrayList<Integer[]> result = new ArrayList<Integer[]>();
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(l > 1){
		    if(l%2 == 0){
		        l = l/2;
		        list.add(2);
		    }else{
		        l = l - 1;
		        list.add(1);
		    }
		}
		int v = 1;
		int e = 1;
		for(int i = list.size(); i > 0; i--){
		    if(list.get(i-1) == 1){
		        Integer[] edge = {1, v, e};
		        e++;
		        result.add(edge);
		    }else{
		        for(Integer[] edge : result){
		            edge[2] *= 2;
		        }
		        Integer[] edge0 = {v, v+1, 0};
		        Integer[] edge1 = {v, v+1, 1};
		        v++;
		        e *= 2;
		        result.add(edge0);
		        result.add(edge1);
		    }
		}
		
		// 出力
		System.out.println(v + " " + result.size());
		for(Integer[] edge : result){
		    System.out.println(edge[0] + " " + edge[1] + " " + edge[2]);
		}
	}
}


Measured memory_bytes: 22996
import java.util.Scanner;

class Main {
    private static void solve() {
        final Scanner scanner = new Scanner(System.in);

        while (scanner.hasNextLine()) {
            final String[] words = scanner.nextLine().split(" ");
            final String[] keywords = { "the", "this", "that" };

            for (int i = 0; i <= 'z' - 'a'; i++) {
                boolean flag = false;
                for (String word: words) {
                    char[] w = word.toCharArray();
                    for (int j = 0; j < w.length; j++) {
                        if (w[j] != '.') {
                            w[j] = (char) ('a' + (w[j] - 'a' + i) % 
                                    ('z' - 'a' + 1));
                            assert Character.isLetter(w[j]);
                        }
                    }
                    for (int j = 0; j < keywords.length; j++) {
                        if (String.valueOf(w).startsWith(keywords[j])) {
                            flag = true;
                        }
                    }
                }
                if (flag) {
                    boolean space = false;
                    for (String word: words) {
                        char[] w = word.toCharArray();
                        for (int j = 0; j < w.length; j++) {
                            if (w[j] != '.') {
                                w[j] = (char) ('a' + (w[j] - 'a' + i) %
                                        ('z' - 'a' + 1));
                            }
                        }
                        if (space) {
                            System.out.print(" ");
                        }
                        System.out.print(String.valueOf(w));
                        space = true;
                    }
                    System.out.println();
                }
            }
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 12000
using System;
using System.IO;
using System.Collections.Generic;

namespace ABC117A
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var T = ss.Next(double.Parse);
            var X = ss.Next(double.Parse);
            sw.WriteLine(T / X);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
ll A[100100], B[100100];

ll f(){
    ll t1 = 0, t2 = 0;
    
    for(int i=1;i<N;++i){
        B[i] += t1 - t2;
        
        if(B[i-1] > 0 && B[i] >= 0){
            t2 += B[i] + 1;
            B[i] = -1;
        }else if(B[i-1] < 0 && B[i] <= 0){
            t1 += -B[i] + 1;
            B[i] = 1;
        }
    }

    return t1 + t2;
}

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

    std::cin >> N;

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

        if(i > 0){A[i] += A[i-1];}
    }

    ll res;

    if(A[0] == 0){
        copy(A, A+N, B);
        for(int i=0;i<N;++i){
            B[i] += 1;
        }
        res = f() + 1;

        copy(A, A+N, B);
        for(int i=0;i<N;++i){
            B[i] -= 1;
        }
        res = min(res, f() + 1);
    }else{
        copy(A, A+N, B);
        res = f();

        copy(A, A+N, B);
        int d;
        if(A[0] > 0){
            d = -(A[0] + 1);
        }else{
            d = -A[0] + 1;
        }
        for(int i=0;i<N;++i){
            B[i] += d;
        }
        res = min(res, f() + abs(d));
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main()
{
    char s[11];
    scanf("%s", s);
    bool f = true;

    if (s[0] != 'A') f = false;

    int cnt = 0, len = strlen(s);
    for (int i=2; i<=len-2; i++)
    {
        if (s[i] == 'C') cnt ++;
    }
    if (cnt != 1) f = false;

    for (int i=0; i<len; i++)
    {
        if (i==0 || s[i] == 'C') continue;
        if (!('a' <= s[i] && s[i] <= 'z')) f = false;
    }
    if (f) printf("AC\n");
    else printf("WA\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
int i;
int a;
int b;

for(i=0;i<10000;i++)
  {
    cin >> a >>b;
    if(a==0 && b==0)
      break;
    if(a>b)
      cout << b <<" "<< a <<"\n";
    else
      cout << a <<" "<< b <<"\n";
  }
}

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

int main() {
	int x, n;
	cin >> x >> n;

	vector<bool> p(101, true);
	for (int i = 0; i < n; ++i) {
		int pi;
		cin >> pi;

		p[pi] = false;
	}

	int l = 0;
	for (int i = 1; i <= x; ++i) {
		if (p[i]) {
			l = i;
		}
	}

	int r = 101;
	for (int i = 100; i >= x; --i) {
		if (p[i]) {
			r = i;
		}
	}

	if (x - l <= r - x) {
		cout << l;
	} else {
		cout << r;
	}
	
	return 0;
}
	

Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<cstdlib>
#include <memory>
using namespace std;

typedef struct Node {
    int key;
    Node *parent, *left, *right;
} Node;

Node *root, *NIL;

void insert(int k) {
    Node *x = root;
    Node *y = NIL;
    Node *z;
    
    z = new Node;

    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z -> parent = y;
    if (y == NIL) root = z;
    else {
        if ( z->key < y->key ) y->left = z;
        else y->right = z;
    }
}

void inorder(Node *u) {
    if ( u == NIL ) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if ( u == NIL ) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ) {
        cin >> com;
        if ( com == "insert" ) {
            scanf("%d", &x);
            insert(x);
        } else if ( com == "print" ) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 26704
n = int(input())
h = list(map(int, input().split()))


def dfs(left, right):
    if left >= right:
        return 0
    idx = left + h[left: right].index(min(h[left: right]))
    x = h[idx]
    for i in range(left, right):
        h[i] -= x
    return dfs(left, idx) + x + dfs(idx+1, right)


print(dfs(0, n))

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

k, n = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a.append(a[i]+k)
#print(a)

lis = []
for i in range(n):
    lis.append(a[i+n-1]-a[i])
#print(lis)

print(min(lis))


Measured memory_bytes: 92620
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    t=chomp(readline())
    n=length(s)
    s_t=Dict{Char,Set{Char}}()
    t_s=Dict{Char,Set{Char}}()
    for i in 1:n
        if haskey(s_t,s[i])
            push!(s_t[s[i]],t[i])
        else
            s_t[s[i]]=Set{Char}(t[i])
        end
        if haskey(t_s,t[i])
            push!(t_s[t[i]],s[i])
        else
            t_s[t[i]]=Set{Char}(s[i])
        end
    end
    ans="Yes"
    for i in values(s_t)
        if length(i)>1
            ans="No"
        end
    end
    for i in values(t_s)
        if length(i)>1
            ans="No"
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 174640
n = int(input())
x = list(map(int,input().split(" ")))
x_max = max(x)
x_min = min(x)
l =[]

for i in range(x_min,x_max + 1):
    si = 0
    for j in range(n):
        xj = x[j]
        xj_p = (xj - i) ** 2
        si += xj_p
    l.append(si)

l.sort()
print(l[0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void main_sub(void);
int main(int argc, char* argv[]) {
    main_sub();
    return 0;
}
// int を int64_t にする
// g++ に -DUSE_STRICT_INT をつけるか、
// 下のコメントアウトを外すと無効化
// #define USE_STRICT_INT
using i64 = int64_t;
#ifndef USE_STRICT_INT
#define int i64
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;

void main_sub(void) {
    int a, b, k;
    cin >> a >> b >> k;
    if (a > k) {
        cout << a - k << " " << b << endl;
    } else {
        cout << 0 << " " << max((i64)0, b - (k - a)) << endl;
    }
    return;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int INF = 1<<29;
int main(void){
    int n,m,ans = 0;
    cin >> n >> m;
    int a[1100],b[1100],c[1100],d[110][110];
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++)d[i][j] = INF;
        d[i][i] = 0;
    }
    
    for(int i = 0;i < m;i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }
    
    for(int k = 0;k < n;k++)
    for(int i = 0;i < n;i++)
    for(int j = 0;j < n;j++) 
    if(d[i][j] > d[i][k]+d[k][j]) d[i][j] = d[i][k]+d[k][j];
    
    for(int i = 0;i < m;i++){
        if(c[i] > d[a[i]][b[i]]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
const long long mod = 1e9+7;
long long f[200001], invf[200001];
//sumb: taken b black and the last is black,
//the probability that the number of taken white is smaller than i 
long long sumb[200001], sumw[200001];
long long invp2[200001];

long long power(long long a,long long b){
	long long res = 1;
	while(b){
		if(b&1) res = res*a%mod;
		 a = a*a%mod;
		 b /= 2;
	}
	return res;
}

long long inv(long long u){ return power(u,mod-2); }

void preWork(int n){
	f[0] = invf[0] = 1;
	invp2[0] = 1;
	long long inv2 = inv(2);
	for(int i = 1; i <= n; i++){
		f[i] = (long long)i*f[i-1]%mod;
		invf[i] = inv(f[i]);
		invp2[i] = invp2[i-1]*inv2%mod;
	}
}

long long getComb(int n,int m){
	if(m>n || m<0) return 0;
	else{
		long long res = f[n]*invf[m]%mod;
		res = res*invf[n-m]%mod;
		return  res;
	}
}

int main(){
	preWork(200000);
	int b,w;
	scanf("%d%d",&b,&w);
	sumb[0] = invp2[b];
	for(int i = 1; i <= w; i++){
		sumb[i] = sumb[i-1];
		sumb[i] += invp2[i+b]*getComb(i+b-1,i)%mod;
		if(sumb[i]>=mod) sumb[i] -= mod;
	}
	sumw[0] = invp2[w];
	for(int i = 1; i <= b; i++){
		sumw[i] = sumw[i-1];
		sumw[i] += invp2[i+w]*getComb(i+w-1,i)%mod;
		if(sumw[i]>=mod) sumw[i] -= mod;
	}
	long long inv2 = inv(2);
	for(int i = 1; i <= b+w; i++){
		long long allB = 0, allW = 0, both = 1;
		if(i<w) allB = 0;
		else allB = sumw[i-1-w];
		if(i<b) allW = 0;
		else allW = sumb[i-1-b];
		both -= allB;
		if(both<0) both += mod;
		both -= allW;
		if(both<0) both += mod;
		//printf("i = %d, allB = %lld, allW = %lld\n",i,allB,allW);
		long long ans = allB+both*inv2%mod;
		if(ans>=mod) ans -= mod;
		printf("%lld\n",ans);
	}
	return 0;
}


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

int main()
{
    int n, k, d, ss;
    set<int> s;
    cin >> n >> k;
    for (int i = 0; i < k; i++)
    {
        cin >> d;
        for (int i = 0; i < d; i++)
        {
            cin >> ss;
            s.insert(ss);
        }
    }
    cout << n - s.size();
    return 0;
}

Measured memory_bytes: 3608
import std.stdio;
import std.conv;
import std.string;

int maximizeHapiness(int money)
{
	int hapiness500 = money / 500 * 1000;
	int hapiness5 = (money%500) / 5 * 5;

	return hapiness500 + hapiness5;
}

void main(){
    string[] input = split(readln());
    auto money = to!int(input[0]);

    writeln(maximizeHapiness(money));
}

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

vector<string> split(const string &str, const string &delim){
  vector<string> res;
  size_t current = 0, found, delimlen = delim.size();
  while((found = str.find(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + delimlen;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}


void solve(string expr)
{
  bool answer = false;

  vector<string> strings = split(expr, "|");

  for (int i = 0; i < strings.size(); i++) {
    strings[i] = strings[i].substr(1, strings[i].size() - 2);
    // cout << strings[i] << endl;
    vector<string> sstrings = split(strings[i], "&");

    bool t[3];
    char c[3];
    for (int i = 0; i < 3; i++)
    {
      if (sstrings[i].size() == 1)
      {
        c[i] = sstrings[i][0];
        t[i] = false;
      }
      else
      {
        c[i] = sstrings[i][1];
        t[i] = true;
      }

      // cout << c[i] << t[i] << endl;
    }

    if (!((c[0] == c[1] && t[0] != t[1]) || (c[0] == c[2] && t[0] != t[2]) || (c[1] == c[2] && t[1] != t[2])))
    {
      answer = true;
      // cout << "false" << endl;
      break;
    }
  }

  cout << (answer ? "yes" : "no") << endl;
}

int main()
{
  while (true)
  {
    string input;
    cin >> input;

    if (input == "#") { break; }
    solve(input);
  }
}

Measured memory_bytes: 1192
#include<cstdio>
#include<cmath>
using namespace std;

const int D_MAX = 15;

const int N_MAX = 15;
const int R_MAX = 200;

int main(){
  int n, d;
  int X[N_MAX][D_MAX];

  scanf("%d %d", &n, &d);

  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      scanf("%d", &X[i][j]);
    }
  }

  int ans = 0;

  for(int i = 0; i < n - 1; i++){
    for(int k = i+1; k < n; k++){
      int r2 = 0;
      for(int j = 0; j < d; j++){
        r2 += (X[i][j] - X[k][j]) * (X[i][j] - X[k][j]);
      }
      for(int l = 1; l < R_MAX; l++){
        if (l * l == r2) ans++;
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define EPS 1e-9
using namespace std;

double add(double a,double b){
	if(abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
	return a + b;
}

struct vect{
	int num;
	double x,y;
	vect(){}
	vect(double x,double y,int num) : x(x),y(y),num(num){}
	vect operator + (vect v){
		return vect(add(x,v.x),add(y,v.y),-1);
	}
	vect operator - (vect v){
		return vect(add(x,-v.x),add(y,-v.y),-1);
	}
	vect operator * (double d){
		return vect(x * d,y * d,-1);
	}
	double dot(vect v){
		return add(x * v.x,y * v.y);
	}
	double det(vect v){
		return add(x * v.y,-y * v.x);
	}
};

bool comp_vect(const vect& v1,const vect& v2){
	if(v1.x != v2.x) return v1.x < v2.x;
	return v1.y < v2.y;
}

vector<vect> convex(vect* ps,int n){
	sort(ps,ps + n,comp_vect);
	int k = 0;
	vector<vect> qs(n * 2);
	for(int i = 0;i < n;i++){
		while(k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0.0) k--;
		qs[k++] = ps[i];
	}
	for(int i = n - 2,t = k;i >= 0;i--){
		while(k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0.0) k--;
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

double dist(vect p,vect q){
	return sqrt((p - q).dot(p - q));
}

int par[100],rnk[100];

void init(int n){
	for(int i = 0;i < n;i++){
		par[i] = i;
		rnk[i] = 0;
	}
}

int find(int x){
	if(par[x] == x) return x;
	return par[x] = find(par[x]);
}

void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rnk[x] < rnk[y]) par[x] = y;
	else{
		par[y] = x;
		if(rnk[x] == rnk[y]) rnk[x]++;
	}
}

bool same(int x,int y){
	return find(x) == find(y);
}

struct edge{ int u,v; double cost; };

bool comp(const edge& e1,const edge& e2){
	return e1.cost < e2.cost;
}

int main(){
	int n,m;
	double ans = 0;
	vect point[100],coor[100];
	cin >> n >> m;
	init(n);
	for(int i = 0;i < n;i++){
		double x,y;
		cin >> x >> y;
		point[i] = vect(x,y,i);
		coor[i] = point[i];
	}
	vector<vect> hull = convex(point,n);
	for(int i = 0;i < hull.size() - 1;i++){
		ans += dist(hull[i],hull[i + 1]);
		unite(hull[i].num,hull[i + 1].num);
	}
	ans += dist(hull[0],hull[hull.size() - 1]);
	vector<edge> edges;
	for(int i = 0;i < m;i++){
		int s,t;
		cin >> s >> t; s--;t--;
		edges.push_back({s,t,dist(coor[s],coor[t])});
	}
	sort(edges.begin(),edges.end(),comp);
	for(int i = 0;i < m;i++){
		edge e = edges[i];
		if(!same(e.u,e.v)){
			unite(e.u,e.v);
			ans += e.cost;
		}
	}
	printf("%.9lf\n",ans);
	return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000
using namespace std;
int main(){
    int N,M;
    while(1){
        cin >> N >> M;
        if(N+M==0) return 0;
        int A[N];
        for(int i=0;i<N;i++) cin >> A[i];

        int ans = 0, Max = 0;
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(i!=j){
                    int now = A[i]+A[j];
                    if(now<=M){
                        ans = max(ans,now);
                    }   
                }
            }
        }
        if(ans!=0) cout << ans << endl;
        else cout << "NONE" << endl;
    }
}


Measured memory_bytes: 3088