akhauriyash/Code-Regression huggingface dataset:
program anti_division
  implicit none
  integer(8) :: a, b, c, d, mc, md, mcd, l
  read(*,*) a, b, c, d
  mc = b/c-(a-1_8)/c
  md = b/d-(a-1_8)/d
  l = c*d/gcd(c,d)
  mcd = b/l-(a-1_8)/l
  write(*,'(i0)') b-a+1-mc-md+mcd
  stop
contains
  recursive function gcd(x,y) result(z)
    implicit none
    integer(8), intent(in) :: x,y
    integer(8) :: z
    if (x.lt.y) then
      z = gcd(y,x)
      return
    end if
    z = x
    if (y.eq.0_8) return
    z = gcd(y,mod(x,y))
    return
  end function gcd
end program anti_division

Measured memory_bytes: 640
/*THERE'S ALWAYS SOMETHING , NOT THAT YOU WOULD UNDERSTAND . YOU ARE LIKE MY SISTER ,
 EVERYTHING ALWAYS CAME EASY TO HER .
 SHE'S A FIRE BENDING PRODIGY AND EVERY ONE ADORE HER . MY FATHER SAYS
 SHE WAS BORN LUCKY ,HE SAYS I WAS LUCKY TO BE BORN . I DON'T NEED LUCK THOUGH .
 I DON'T WANT IT . I'VE ALWAYS HAD TO STRUGGLE AND FIGHT
 AND THAT'S MADE ME STRONG . IT MADE ME WHO I AM .*/
#include<bits/stdc++.h>
#define prdouble(x) cout<<fixed<<setprecision(10)<<x;
using namespace std;
double dp[3005][3005];

double solve(vector<double>& a,int i,int x)
{
    if(x==0)return 1;
    if(i==0)return 0;
    if(dp[i][x]>-0.9)return dp[i][x];
    return dp[i][x]=a[i]*solve(a,i-1,x-1)+(1-a[i])*solve(a,i-1,x);
}
main()
{
    int n;
    cin>>n;
    memset(dp,-1,sizeof dp);
    vector<double> a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    prdouble(solve(a,n,(n+1)/2));
}

















































































































/* WHATEVER DOESNT KILL ME ONLY MAKES ME STRONGER .*/


Measured memory_bytes: 74568
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",strout);
	cin>>a>>b;
	if((a+b)%3==0 || a%3==0 || b%3==0)
	{
		cout<<"Possible";
		return 0;
	}
	else
	{
		cout<<"Impossible";
		return 0;
	}

	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
n,c=map(int,input().split())
time=[0]*(10**5+2)
stc=[]
for i in range(n):
	s,t,c=map(int,input().split())
	stc.append([s,t,c])
stc.sort(key=lambda x:(x[2],x[0]))
for i in range(n-1):
	if stc[i][2]==stc[i+1][2]:
		if stc[i][1]==stc[i+1][0]:
			stc[i+1][0]=stc[i][0]
			stc[i]=[-1]
lis=[]
for i in range(n):
	if stc[i]!=[-1]:
		lis.append(stc[i])
for i in range(len(lis)):
	time[lis[i][0]-1]+=1
	time[lis[i][1]]-=1
print(max(accumulate(time)))

Measured memory_bytes: 28472
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

/*
 * A
 * BB
 * AAB, BAA
 * BBABB, ABBBB
 * At one point any string could be made one of A, B, {}
 * If you say that both the strings could be made equal 
 * then you can go on making the strings one of the above chars
 */
int main() {
	string s, t;
	cin >> s >> t;
	int n = (int) s.size();
	int m = (int) t.size();
	vector <int> c1(n + 1), c2(m + 1);
	for (int i = 0; i < n; i++) {
		c1[i + 1] = c1[i] + (s[i] == 'A'); 
	}
	for (int i = 0; i < m; i++) {
		c2[i + 1] = c2[i] + (t[i] == 'A'); 
	}
	int q;
	cin >> q;
	while(q--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int val1 = (c1[b] - c1[a - 1]) + (b - a + 1 - (c1[b] - c1[a - 1])) * 2;
		int val2 = (c2[d] - c2[c - 1]) + (d - c + 1 - (c2[d] - c2[c - 1])) * 2;
		cout << (val1 % 3 == val2 % 3 ? "YES\n" : "NO\n");
	}
}


Measured memory_bytes: 1664
#include <stdio.h>
  int n=0;
   int hure[101];
   int hure_heikin=0;
   int hure_sa[101];
   int ans;
   int main(void){
    // Your code here!
   scanf("%d",&n);;
   for(int i=0;i<n;i++){
       scanf("%d",&hure[i]);
       hure_heikin+=hure[i];
   }
   
   for(int j=0;j<n;j++){
       if(hure[j]*n-hure_heikin>0) {hure_sa[j]=hure[j]*n-hure_heikin;}
       if(hure[j]*n-hure_heikin<0) {hure_sa[j]=(hure[j]*n-hure_heikin)*-1;}
       if(j==0) {ans=0;}
       if(hure_sa[j]<hure_sa[ans]) {ans=j;}
   }
   
   printf("%d\n",ans);
}

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

const int MAXN = 1e5 + 10;

int arr[MAXN], pref[MAXN], suf[MAXN], N, best;

int gcd(int a, int b){
	if(a < b) swap(a, b);
	if(b == 0) return a;
	return gcd(b, a % b);
}

int main(){

	cin >> N;
	for(int i = 1;i<=N;i++){
		cin >> arr[i];
		pref[i] = gcd(pref[i-1], arr[i]);
	}

	for(int i = N;i>=1;i--) suf[i] = gcd(suf[i+1], arr[i]);

	for(int i = 1;i<=N;i++) best = max(best, gcd(pref[i-1], suf[i+1]) );

	cout << best << endl;

	return 0;

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	ull ans = 0;
	ll n,a,b;
	cin>>n>>a>>b;
	int last;
	cin>>last;n--;
	while(n--) {
		int val;
		cin>>val;
		ans+=min((val-last)*a,b);
		last = val;
	}
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3612
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>

int main(){
  long long int a;
  char s[11];
  
  scanf("%lld", &a);
  scanf("%s", &s);
  
  if(a >= 3200){
    std::cout << s;
  }
  else
    std::cout << "red";
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int N, K, h, ans = 0;
int main(){
	scanf("%d%d",&N,&K);
	for(int i=0; i<N; i++){
		scanf("%d",&h);
		ans += (h >= K);
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long;

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = min(n * a, b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

typedef std::pair<int, int> P;

bool is_vis[1003][1003];
bool is_fin[1003][1003];
bool is_cycle;

void dfs(map<P, vector<P>> &g, P p) {
  int player1 = p.first;
  int player2 = p.second;

  is_vis[player1][player2] = true;

  for (int i = 0; i < (int)g[p].size(); i++) {
    P nxt = g[p][i];
    int nxt_player1 = nxt.first;
    int nxt_player2 = nxt.second;

    if (is_fin[nxt_player1][nxt_player2]) {
      continue;
    }
    if (is_vis[nxt_player1][nxt_player2] && !is_fin[nxt_player1][nxt_player2]) {
      is_cycle = true;
      return;
    }
    dfs(g, nxt);
  }
  is_fin[player1][player2] = true;
}

int dp[1003][1003];
int rec(map<P, vector<P>> &g, P p) {
  int player1 = p.first;
  int player2 = p.second;
  if (dp[player1][player2] != -1) {
    return dp[player1][player2];
  }
  int res = 0;
  for (int i = 0; i < (int)g[p].size(); i++) {
    res = max(res, rec(g, g[p][i]) + 1);
  }
  return dp[player1][player2] = res;
}

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

  int n;
  cin >> n;

  map<P, vector<P>> g;

  vector<vector<int>> A(n, vector<int>(n - 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n - 1; j++) {
      int pre_1 = i + 1, pre_2 = A[i][j - 1];
      if (pre_1 > pre_2) {
        swap(pre_1, pre_2);
      }
      int nxt_1 = i + 1, nxt_2 = A[i][j];
      if (nxt_1 > nxt_2) {
        swap(nxt_1, nxt_2);
      }
      g[make_pair(pre_1, pre_2)].push_back(make_pair(nxt_1, nxt_2));
    }
  }

  // 閉路検出の処理
  // https://qiita.com/drken/items/a803d4fc4a727e02f7ba#4-6-サイクル検出
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i >= j) {
        continue;
      }
      if (g.find(make_pair(i, j)) == g.end()) {
        continue;
      }
      if (is_vis[i][j]) {
        continue;
      }
      is_cycle = false;
      dfs(g, make_pair(i, j));
      if (is_cycle) {
        cout << -1 << "\n";
        return 0;
      }
    }
  }

  for (int i = 0; i < 1003; i++) {
    for (int j = 0; j < 1003; j++) {
      dp[i][j] = -1;
    }
  }
  // 最長経路を求める
  // EDPC (https://atcoder.jp/contests/dp/tasks/dp_g) で見た
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i >= j) {
        continue;
      }
      ans = max(ans, rec(g, make_pair(i, j)) + 1);
    }
  }
  cout << ans << "\n";

  return 0;
}

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

int main()
{
	int n;
	int a[4][3][10] = { 0 };
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		b--, f--, r--;
		a[b][f][r] += v;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				cout << " " << a[i][j][k];
			}
			cout << endl;
		}
		if (i == 3) break;
		for (int j = 0; j < 20; j++) {
			cout << "#";
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3084
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// my code goes here
		
		var x = Console.ReadLine().Split().Select(y => int.Parse(y)).ToArray();
		int n = x[0];
		int m = x[1];
		var h = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
		int[,] a = new int[m,2];
		for(int i=0;i!=m;i++){
			x = Console.ReadLine().Split().Select(c => int.Parse(c)).ToArray();
			a[i,0] = x[0];
			a[i,1] = x[1];
		}
		int[] counter = new int[n];
		int d = 0;
		int e = 0;
		int f = 0;
		for(int j=0;j!=m;j++){
			d = a[j,0];
			e = a[j,1];
			if(h[d-1]>=h[e-1]){
				f = a[j,1];
				counter[f-1] += 1;
			}
			if(h[d-1]<=h[e-1]){
				f = a[j,0];
				counter[f-1] += 1;
			}
		}
		int ans = 0;
		for(int k=0;k!=n;k++){
			if(counter[k]==0){ans++;}
		}
		
		Console.WriteLine(ans);
		
	}
}

Measured memory_bytes: 49496
var inf = Number.MAX_SAFE_INTEGER;
function Main(input) {
	input = input.split("\n");
	var n = input[1]-0;
	var arr = input[0].split("");
	var ans = "";
	for(var i=0;i<arr.length;i++){
		if(i%n==0) ans += arr[i];
	}
	console.log(ans)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 9420
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	//ll R, C, sy, sx, gy, gx; cin >> R >> C >> sy >> sx >> gy >> gx;
	ll R, C, sy, sx, gy, gx; cin >> R >> C;
	sy = 0, sx = 0, gy = R - 1, gx = C - 1;
	char c[50][50] = {};
	int d[50][50] = {};
	bool v[50][50] = {};
	int x[4] = { 1,0,0,-1 };
	int y[4] = { 0,1,-1,0 };

	int ps = 0;
	int pe = 0;
	ll qx[10000] = {};
	ll qy[10000] = {};

	ll white = 0;
	ll black = 0;
	rep(i, 0, R) {
		rep(j, 0, C) {
			cin >> c[i][j];
			if (c[i][j] == '.')white++;
			if (c[i][j] == '#')black++;
		}
	}

	qy[pe] = sy;
	qx[pe] = sx;
	d[sy][sx] = 1;
	v[sy][sx] = true;
	pe++;

	while (ps != pe) {
		//pop
		ll cy = qy[ps];
		ll cx = qx[ps];
		ps++;
		if (cy == gy && cx == gx) {
			break;
		}

		rep(i, 0, 4) {
			//push
			ll ny = cy + y[i];
			ll nx = cx + x[i];

			if (ny >= 0 && ny < R && nx >= 0 && nx < C && c[ny][nx] != '#' && !v[ny][nx]) {
				qy[pe] = ny;
				qx[pe] = nx;
				pe++;
				v[ny][nx] = true;
				d[ny][nx] = d[cy][cx] + 1;
			}
		}
	}
	if (d[gy][gx] == 0) {
		cout << -1 << endl;
	}
	else {
		cout << white - d[gy][gx] << endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,y,k;

int main(){
	cin>>n>>y;
	for(int i=y/10000;i>=0;i--)
		for(int j=0;j<=n-i and i*10000+j*5000<=y;j++){
			int k=n-i-j;
			if(i*10000+j*5000+k*1000==y){
				cout<<i<<' '<<j<<' '<<k<<endl;return 0;
			}
		}
	cout<<-1<<' '<<-1<<' '<<-1<<endl;	
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x, vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1, s) + f(x - 2, s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m - 1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}
void press(string& v) { v.erase(unique((v).begin(), (v).end()), v.end()); }

int main() {
	string s;
	int k;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> s >> k;
	rep(i, 0, s.size()) {
		if (i < k) {
			if (s[i] == '1')x++;
			if (y == 0&&s[i]!='1') {
				y++;
				ans = s[i] - '0';
			}
		}
	}
	if (k == x)ans = 1;
	cout << ans << endl;

	return 0;
}

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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;

int32_t main()
{	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int s,w;
	cin>>s>>w;

	if(w>=s)
	{
		cout<<"unsafe"<<'\n';
	}
	else
	{
		cout<<"safe"<<'\n';
	}


	return 0;
}	

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include<vector>
using namespace std;
vector<string> v;
string buf[5001],s;
int main(){
	cin>>s;
	for(int i=0;i<s.length();i++){
		for(int j=i;j<s.length()&&j<i+6;j++){
			v.push_back(s.substr(i,j-i+1));
		}
	}
	sort(v.begin(),v.end());
	int k;
	cin>>k;
	k--;
	v.erase(unique(v.begin(),v.end()),v.end());
	cout<<v[k];
}


Measured memory_bytes: 1916
#include<bits/stdc++.h>
#define N 2009
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int A,B;
ll dp[N][N],g[N][N],c[N][N],ans;
inline ll rd(){
    ll x=0;char c=getchar();bool f=0;
    while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return f?-x:x;
}
inline void MOD(ll &x){x=x>=mod?x-mod:x;}
inline ll power(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1)ans=ans*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return ans;
}
int main(){
    A=rd();B=rd();
    if(B==1){
        printf("%d\n",A+1);
        return 0;
    }
    int n=max(A,B)+1;
    for(int i=0;i<=n;++i){
        c[i][0]=1;
        for(int j=1;j<=i;++j)MOD(c[i][j]=c[i-1][j-1]+c[i-1][j]);
    }
    for(int i=0;i<=n;++i){
        for(int j=1;j<=n;++j){
            MOD(g[i][j]=g[i][j-1]+c[i][j-1]);
            MOD(dp[i][j]=dp[i][j-1]+g[i][j]);
        }
    }
    for(int i=1;i<=A+1;++i)
        for(int j=0;j<i;++j){
            if(j==0){ans++;continue;}
          MOD(ans+=c[B-1][j]*dp[j-1][i-j]%mod);
        }
    cout<<ans;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    int d , t , s;
    cin >> d >> t >> s;
    int x= d/s ;
    if(d%s!=0)
        x++;
    if(x<=t)
    {
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

void solve()
{
    int x,n;
    cin>>x>>n;
    int min_diff = INT_MAX, ans=INT_MAX;
    vector<int> used(105);
    for (int i=0; i<n; i++) {
        int a;
        cin>>a;
        used[a] = 1;
    }   
    for (int i=0; i<=101; i++) {
        if (abs(i-x)<min_diff && !used[i]) {
            min_diff = abs(i-x);
            ans = i;
        }
    }
    cout << ans << "\n";
}

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

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

  int dpa[N], dpb[N], dpc[N];
  REP(i, N)
  dpa[i] = dpb[i] = dpc[i] = 0;

  int a, b, c;
  REP(i, N)
  {
    cin >> a >> b >> c;

    if (i == 0)
    {
      dpa[i] = a;
      dpb[i] = b;
      dpc[i] = c;
      continue;
    }

    dpa[i] = max(dpb[i - 1], dpc[i - 1]) + a;
    dpb[i] = max(dpc[i - 1], dpa[i - 1]) + b;
    dpc[i] = max(dpa[i - 1], dpb[i - 1]) + c;
  }

  cout << max(dpa[N - 1], max(dpb[N - 1], dpc[N - 1])) << endl;
  return 0;
}


Measured memory_bytes: 1408
import sys
import heapq


def input():
    return sys.stdin.readline().strip()


def dijkstra(start, n_nodes, edge):
    dist = [float("inf")] * n_nodes
    dist[start] = 0
    # 優先度キューの準備
    q = [(dist[start], start)]
    heapq.heapify(q)
    while q:
        # スタートから最も最短距離のものを取り出す
        d, i = heapq.heappop(q)
        # 記録してある情報よりも，取り出した要素に入っている距離情報の方が大きければ
        # 打ち切り．次の要素を取り出す操作に戻る
        if dist[i] < d:
            continue
        # そこから移動できる頂点を探し，最短距離が更新できるものがあれば，
        # 距離を更新して，その頂点への距離と頂点の方法を優先度キューにpush
        for cost, j in edge[i]:
            if dist[j] > dist[i] + cost:
                dist[j] = dist[i] + cost
                heapq.heappush(q, (dist[j], j))
    return dist


def main():
    N = int(input())
    edge = [[] for _ in range(N)]
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        edge[u - 1].append((w, v - 1))
        edge[v - 1].append((w, u - 1))
    D = dijkstra(0, N, edge)
    for d in D:
        if d % 2 == 0:
            print(0)
        else:
            print(1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 42872
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

main()
{
	IOS
	
	int n, Mojo;
	cin >> n >> Mojo;
	
	int sum = 0;
	
	int mi = Mojo;
	
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		
		sum += x;
		
		amin(mi, x);
	}
	
	Mojo -= sum;
	
	cout << n + Mojo / mi;
}

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

int dp[100010], n, k, h[100010];

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%d", &h[i]);
	memset(dp, 0x7f, sizeof(dp));
	dp[1] = 0;
	for (int i = 2; i <= n; i++)
		for (int j = max(1, i-k); j <= i-1; j++)
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
	printf("%d\n", dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int n,sum,i;
    while(~scanf("%d",&n))
    {
        if(n>=1&&n<=100)
        {
            sum=0;
            for(i=1;i<=n;i++)
            {
                sum+=i;
            }
            printf("%d\n",sum);
        }
        else
            continue;
    }
    return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

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

#define INF 1000000000
#define EPS 1e-10

#define MAX_N 1000

int N, M;
int po[MAX_N];

vector<int> ans_list;

int main(){

	while (true){
		cin >> N >> M;
		if (N == 0 && M == 0)
			break;
		for (int i = 0; i < N; i++){
			cin >> po[i];
		}
		vector<int> A, B;
		A.push_back(0);
		B.push_back(0);

		for (int i = 0; i < N/2; i++){
			A.push_back(po[i]);
		}

		for (int i = N / 2; i < N; i++){
			B.push_back(po[i]);
		}

		for (int i = 0; i < N/2; i++){
			for (int j = i; j < N/2; j++){
				A.push_back(po[i] + po[j]);
			}
		}

		for (int i = N/2; i < N; i++){
			for (int j = i; j < N; j++){
				B.push_back(po[i] + po[j]);
			}
		}

		sort(A.begin(), A.end());
		sort(B.begin(), B.end());

		int ans = 0;

		for (int i = 0; i < A.size(); i++){
			int tmp = A[i];
			int max_tmp = M - tmp;
			if (max_tmp < 0)
				break;
			int lb = 0, ub = B.size();
			while (ub - lb > 1){
				int mid = (ub + lb) / 2;
				if (max_tmp < B[mid])
					ub = mid;
				else
					lb = mid;
			}
			ans = max(ans, M - (max_tmp - B[lb]));
		}
		for (int i = 0; i < A.size(); i++){
			int tmp = A[i];
			int max_tmp = M - tmp;
			if (max_tmp < 0)
				break;
			int lb = 0, ub = A.size();
			while (ub - lb > 1){
				int mid = (ub + lb) / 2;
				if (max_tmp < A[mid])
					ub = mid;
				else
					lb = mid;
			}
			ans = max(ans, M - (max_tmp - A[lb]));
		}
		for (int i = 0; i < B.size(); i++){
			int tmp = B[i];
			int max_tmp = M - tmp;
			if (max_tmp < 0)
				break;
			int lb = 0, ub = B.size();
			while (ub - lb > 1){
				int mid = (ub + lb) / 2;
				if (max_tmp < B[mid])
					ub = mid;
				else
					lb = mid;
			}
			ans = max(ans, M - (max_tmp - B[lb]));
		}
		for (int i = 0; i < B.size(); i++){
			int tmp = B[i];
			int max_tmp = M - tmp;
			if (max_tmp < 0)
				break;
			int lb = 0, ub = A.size();
			while (ub - lb > 1){
				int mid = (ub + lb) / 2;
				if (max_tmp < A[mid])
					ub = mid;
				else
					lb = mid;
			}
			ans = max(ans, M - (max_tmp - A[lb]));
		}

		ans_list.push_back(ans);

	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

}

Measured memory_bytes: 2604
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N;
int a;
int ans=0;
int P[100005];

int main() {
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> a;
    P[a]++;
  }
  for (int i=1; i<=100000; i++) {
    ans = max(ans, P[i-1]+P[i]+P[i+1]);
  }
  cout << ans << endl;
}


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

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 3500; i++) {
		for (int j = 1; j <= 3500; j++) {
			if ((ll)4 * i * j - n * j - n * i != 0) {
				if ((ll)n * i * j % (4 * i * j - n * j - n * i) == 0 && (ll)n * i * j / (4 * i * j - n * j - n * i) > 0) {
					cout << i << " " << j << " " << (ll)n * i * j / (ll)(4 * i * j - n * j - n * i) << endl;
					return 0;
				}
			}
		}
	}
}

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
using Graph = vector<vector<int>>;


int main(){
  int N;
  cin >> N;
  cout << (N+2-1)/2 << endl;
}

Measured memory_bytes: 256
import numpy as np

N=input()
K=input()
dp=np.zeros((len(str(N))+10,len(str(N))+10,2))
dp=dp.tolist()


x0=int(N[0])
dp[0][0][0]=1


for i in range(0,len(N),1):
    for j in range(0,4,1):
        for k in range(0,2,1):
            nd=int(N[i])
            for d in range(0,10,1):
                ni=i+1
                nj=j
                nk=k
                if not(d==0):
                    nj=nj+1
                if ((k==0)and(d<nd)):
                    nk=1
                if (not(nj>int(K)))and(not((k==0)and(d>nd))):
                    dp[ni][nj][nk]=dp[ni][nj][nk]+dp[i][j][k]


print(int(dp[len(N)][int(K)][0]+dp[len(N)][int(K)][1]))


Measured memory_bytes: 13892
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    void init(string& s) {
        for (auto c : s) {
            Q.push_back(c);
        }
        rev = 0;
    }

    void reverse() {
        rev ^= 1;
    }

    void update(int f, char ch) {
        f -= 1;
        f ^= rev;
        if (f == 0) {
            Q.push_front(ch);
        } else {
            Q.push_back(ch);
        }
    }

    string get() {
        string res;
        for (auto c : Q) {
            res += c;
        }
        if (rev) {
            ::reverse(begin(res), end(res));
        }
        return res;
    }
private:
    deque<char> Q;
    int rev;
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    Solution sol;
    sol.init(s);

    int q;
    cin >> q;
    while (q-- > 0) {
        int t;
        cin >> t;
        if (t == 1) {
            sol.reverse();
        } else {
            int f;
            char ch;
            cin >> f;
            cin >> ch;
            sol.update(f, ch);
        }
    }

    cout << sol.get() << "\n";

    return 0;
}

Measured memory_bytes: 1368
using System;
using System.IO;

namespace Atcoder {
    class abc043d {
        public static void Main(){
            string s = Console.ReadLine();

            for(int i = 0; i < s.Length - 1; i++){
                if(s[i] == s[i+1]){
                    Console.WriteLine((i+1) + " " + (i+2));
                    Environment.Exit(0);
                }
            }

            for(int i = 0; i < s.Length - 2; i++){
                if(s[i] == s[i+2]){
                    Console.WriteLine((i+1) + " " + (i+3));
                    Environment.Exit(0);
                }
            }

            Console.WriteLine("-1 -1");
        }
    }
}




Measured memory_bytes: 3032
#include <stdio.h>
#include <string.h>
#define M 36

typedef struct {
  char mark;
  int value;
} Card;

void BubbleSort(Card *, int);
void SelectionSort(Card *, int);
void disply(Card *, int);
int isStable(Card *, Card *, int);

int main()
{
  Card c1[M+1], c2[M+1];
  int i, N;

  scanf("%d", &N);

//文字列と数字でそれぞれ格納
  for( i = 0 ; i < N ; i++ ){
    scanf(" %c%d", &c1[i].mark, &c1[i].value);
  }

//BubbleSortとSelectionSortで比較するためにもう一つの配列に格納する
  for( i = 0 ; i < N ; i++ ) c2[i] = c1[i];

  BubbleSort(c1, N);
  disply(c1, N);
  //BubbleSortは常に安定なソートとなるため比較不要
  printf("Stable\n");

  SelectionSort(c2, N);
  disply(c2, N);

//c1に安定ソートされた文字列数字が格納されているためそれと比較し、同じでなければNot Stable
  if( isStable(c1, c2, N) == 0 ) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}
void BubbleSort(Card c1[], int N)
{
  int i, j;
  Card t;

  for( i = 0 ; i < N ; i++ ){
    for( j = N-1 ; j > i ; j-- ){
      if( c1[j].value < c1[j-1].value ){
        t = c1[j];
        c1[j] = c1[j-1];
        c1[j-1] = t;
      }
    }
  }
}

void SelectionSort(Card c2[], int N)
{
  int i, j, minj;
  Card t;

  for( i = 0 ; i < N ; i++ ){
    minj = i;
    for( j = i ; j < N ; j++ ){
      if( c2[j].value < c2[minj].value ) minj = j;
    }
    t = c2[i];
    c2[i] = c2[minj];
    c2[minj] = t;
  }
}

void disply(Card c[], int N)
{
  int i;

  for( i = 0 ; i < N ; i++ ){
    if( i > 0 ) printf(" ");
    printf("%c%d", c[i].mark, c[i].value);
  }
  printf("\n");
}

int isStable(Card c1[], Card c2[], int N)
{
  int i;

  for( i = 0 ; i < N ; i++ )
  if( c1[i].mark != c2[i].mark ) return 1;

  return 0;
}



Measured memory_bytes: 2112
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

//Watchin' TVA
class Program{
public:
	int time;
	string name;
	Program(int _time, string _name) : time(_time), name(_name) {}

	bool operator < (const Program& p) const{
		return time < p.time;
	}
};

int main(){
	int N,P;
	

	while(~scanf("%d",&N)){
		if(N==0) break;
		map<int,vector<Program> > PRO;
		map<string,bool> FAV;

		for(int i=0;i<N;i++){
			string name;
			int day;
			int time;
			cin >> name >> day >> time;
			int m = time % 100;
			int h = time / 100;
			int total = h * 60 + m;
			PRO[day].push_back(Program(total,name));
		}
		scanf("%d",&P);
		for(int i=0;i<P;i++){
			string name;
			cin >> name;
			FAV[name] = true;
		}

		bool failed = false;
		int res = 0;
		for(map<int,vector<Program> >::iterator it = PRO.begin(); it != PRO.end(); it++){
			bool reserve[10000];
			memset(reserve,0,sizeof(reserve));
			sort(it->second.begin(),it->second.end());
			for(int i=0;i< it->second.size(); i++){
				if(FAV.find(it->second[i].name) != FAV.end()){
					for(int j=it->second[i].time; j<it->second[i].time+30;j++){
						if(reserve[j]){
							failed = true;
							goto next;
						}
						reserve[j]=true;
					}
					res++;
				}
			}

			for(int i=0;i< it->second.size(); i++){
				if(FAV.find(it->second[i].name) == FAV.end()){
					bool tmp[10000];
					memcpy(tmp,reserve,sizeof(reserve));

					for(int j=it->second[i].time; j<it->second[i].time+30;j++){
						if(tmp[j]){
							goto cancel;
						}
						tmp[j]=true;
					}
					memcpy(reserve,tmp,sizeof(tmp));
					res++;
				}		
cancel:;
			}
		}
next:;

		if(failed){
			printf("%d\n",-1);
		}
		else{
			printf("%d\n",res);
		}
	}
}

Measured memory_bytes: 1364
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

calc :: [Int] -> [[Int]] -> Int -> Int -> Int -> Int
calc xs [] i j d = j
calc xs (ys : yss) i j d | d' == 0 = i
                         | j > 50 = calc xs yss (i + 1) i d'
                         | otherwise = calc xs yss (i + 1) j' d''
  where
    [x1, y1] = xs
    [x2, y2] = ys
    d' = abs (x1 - x2) + abs (y1 - y2)
    [d'', j'] = if d' < d then [d', i] else [d, j]

calcAll (xs : xss) yss = do
  print $ calc xs yss 1 51 (10^8+1)
  when (xss /= []) $ calcAll xss yss

main = do
  [n, m] <- getIntList
  xss <- getIntNList n
  yss <- getIntNList m
  calcAll xss yss


Measured memory_bytes: 4184
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <fstream>
#include <cmath>

using namespace std;

typedef unsigned long long ll;
const ll INF=18000000000000000000ULL;


map<int,int> prime_decompos(int a){
	map<int,int> res;
	for(int i=2;i*i<=a;i++){
		if(a%i==0){
			res[i]++;
			a/=i;
			i--;
		}
	}
	if(a!=1)res[a]++;
	return res;
}

int main(){
	int n;
	ll m;
	string str;
	while(cin>>n>>str&&!(n==0&&str=="0")){
		ll mul=1;
		m=0;
		for(int i=str.size()-1;i>=0;i--){
			ll a=str[i]-'0';
			if(str[i]>='A'&&str[i]<='Z')a=10+str[i]-'A';
			m+=a*mul;
			mul*=n;
		}
		if(m==0){
			cout<<0<<endl;
			continue;
		}
		map<int,int> np=prime_decompos(n);
		ll res=INF;
		for(map<int,int>::iterator it=np.begin();it!=np.end();it++){
			ll a=it->first;
			int b=it->second;
			ll cnt=0;
			int loop=(log((long double)m)/log((long double)a)+(1e-10));
			while(loop--){
				cnt+=(m/a);
				a*=it->first;
			}
			res=min(res,cnt/b);
		}
		cout<<res<<endl;
	}

	return 0;
}

Measured memory_bytes: 956
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> f;
vector<int> c;
vector<int> c1;
vector<int> c2;
int main()
{
    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;
    for(int i=0;i<n;i++)
    {

        int x;
        cin>>x;
        f.push_back(x);
    }

    for(int i=0;i<n;i++)
    {
        if(f[i]<=a )
        {
           c.push_back(f[i]);
        }
        if(f[i]>=a+1 && f[i]<=b)
        {

            c1.push_back(f[i]);
        }
        if(f[i]>=b+1)
        {

            c2.push_back(f[i]);
        }
    }
    cout<<min(c2.size(),min(c1.size(),c.size()))<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long a,b,c,d;
    a=sc.nextLong();
    b=sc.nextLong();
    c=sc.nextLong();
    d=c-a-b;
    
	if(d>0&&d*d>4*a*b){
      System.out.print("Yes");
    }else{
      System.out.print("No");
    }
  }
}

Measured memory_bytes: 21972
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    X,Y,A,B,C = map(int,input().split())
    p = list(map(int,input().split()))
    q = list(map(int,input().split()))
    r = list(map(int,input().split()))

    p.sort(reverse=True)
    q.sort(reverse=True)

    p = p[:X]
    q = q[:Y]

    all = p + q + r

    all.sort(reverse=True)
    all = all[:X+Y]

    res = sum(all)

    print(res)



main()


Measured memory_bytes: 23472
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int N, M, X;
	int *A;
	int i;
	int cost1 = 0, cost2 = 0;

	scanf("%d %d %d", &N, &M, &X);

	A = (int *)malloc(sizeof(int) * M);

	for(i = 0; i < M; i++)
		scanf("%d", &A[i]);

	if(X >= A[M - 1])
	{
		printf("01\n");
		return 0;
	}

	for(i = 0; A[i] < X && i < M; i++)
		cost1++;
	cost2 = M - cost1;

	if(cost1 < cost2)
		printf("%d\n", cost1);
	else
		printf("%d\n", cost2);

	return 0;

}


Measured memory_bytes: 128
<?php
// Your code here!
fscanf(STDIN,"%d %d",$x,$y);

$b=($y-2*$x)/2;
$a=$x-$b;

if(is_int($a)&&is_int($b) && $a >= 0 && $b >= 0){
    echo 'Yes';
}else{
    echo 'No';
}
?>


Measured memory_bytes: 16220
N = int(input())
color = [None] * N
UV = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    UV[u].append((v, w))
    UV[v].append((u, w))

color[0] = True
li = [0]
while li:
    p = li.pop()
    for q, w in UV[p]:
        if color[q] is not None:
            continue
        if w & 1:
            color[q] = not color[p]
        else:
            color[q] = color[p]
        li.append(q)

print(*[int(i) for i in color], sep="\n")

Measured memory_bytes: 40352
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(void){
    int a;
    string buf;
    cin >> a >> buf;

    if(a>=3200){
        cout << buf << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizeof(a))
struct Node
{
    int u,v,val;
    bool operator < (const Node &a) const
    {
        return val<a.val;
    }
}g[50005];
int fa[505],E[505];
int n,m,pos;
const int inf = 1<<30;
int Find(int x)
{
    return x==fa[x]?x:fa[x]=Find(fa[x]);
}
int kruscal(int x)
{
    int sum=0,edge=0;
    for (int i=1;i<=n;++i) fa[i]=i;
    for (int i=1;i<=m;++i)
    {
        if (i!=x)
        {
            int u=Find(g[i].u);
            int v=Find(g[i].v);
            if (u!=v)
            {
                sum+=g[i].val;
                fa[u]=v;
                if (!x) E[++pos]=i;
                ++edge;
            }
        }
    }
    return edge!=n-1?inf:sum;
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for (int i=1;i<=m;++i)
            scanf("%d%d%d",&g[i].u,&g[i].v,&g[i].val);
        sort(g+1,g+1+m);
        pos=0;
        int tmp=kruscal(0);
        int ans=0,sum=0;
        for (int i=1;i<=pos;++i)
            if (kruscal(E[i])>tmp)
            {
                ++ans;
                sum+=g[E[i]].val;
            }
        printf("%d %d\n",ans,sum);
    }
}

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

#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define str string
#define vint vector<int>
#define vchar vector<char>
#define vool vector<bool>
#define pb() pushback
#define elif else if
#define all(x) x.begin(),x.end()

main(){
    int N,b,count=0,count2=0,H,W;
    double r,pai=3.141592653589;
    int C='A'-'a';
    char op;
    str S,T;
      while(1){
        cin>>H>>W;
        if(H>0&&W>0){
          vector<vchar> sharp(H,vchar(W));
          rep(0,H){
            REP(0,W){
            if(i==0||i==H-1)sharp[i][j]='#';
            else{
              sharp[i][j]='.';
              sharp[i][0]='#';
              sharp[i][W-1]='#';
            }
            cout<<sharp[i][j];
            }
            cout<<endl;
          }
          cout<<endl;
        }
        else break;
      }
}



Measured memory_bytes: 3152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		long sum = m * 1900 + (n - m) * 100;
		sum *= 1 << m;
		System.out.println(sum);
	}
}


Measured memory_bytes: 23636
def main():
    from collections import deque
    N = int(input())
    G = [[] for _ in range(N)]
    keys = [tuple(int(i)-1 for i in input().split()) for _ in range(N-1)]
    for e in keys:
        G[e[0]].append(e[1])
        G[e[1]].append(e[0])
    max_deg = 0
    for g in G:
        max_deg = max(max_deg, len(g))
    edge_color = {k: 0 for k in keys}

    G_color = ['WHITE' for _ in range(len(G))]
    G_parent = ['NIL' for _ in range(len(G))]

    def bfs(s):
        G_color[s] = 'GRAY'
        Q = deque()
        Q.append(s)
        while Q:
            u = Q.popleft()
            c = 0
            if G_parent[u] != "NIL":
                c = ((edge_color[(G_parent[u], u)])+1) % max_deg
            for v in G[u]:
                if G_color[v] == 'WHITE':
                    G_color[v] = 'GRAY'
                    G_parent[v] = u
                    Q.append(v)
                    edge_color[(u, v)] = c
                    c = (c+1) % max_deg
            G_color[u] = 'BLACK'

    bfs(0)
    print(max_deg)
    for k in keys:
        print(edge_color[k] + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 95516
import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        for(int k=0;;k++){
        int H = sc.nextInt();
        int W = sc.nextInt();
            if(H==0&&W==0) break; 
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(i==0||i==H-1||j==0||j==W-1){
                        System.out.printf("#");
                    }else{
                        System.out.printf(".");
                    }
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}







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

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

    vector<bool> ok(n, false);
    rep (i, k)
    {
        int d;
        cin >> d;
        rep (i, d)
        {
            int a;
            cin >> a;
            ok[a - 1] = true;
        }
    }

    int ans = 0;
    rep (i, n)
        if (ok[i] == false)
            ans++;

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

Measured memory_bytes: 3640
#include<iostream>

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define v(d_type) vector<d_type>
#define loop(i, s, n) for(int i = s; i < n; i++)
#define min(x, y) (x) > (y) ? (y) : (x)
#define max(x, y) (x) < (y) ? (y) : (x)
#define print_vec(X) loop(i, 0, X.size()) cout << X[i] << "\n"
 
int main()
{
  int r;
  cin >> r;
  
  cout << 3*r*r << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
      int K = in.nextInt();
      int A = K + K*K + K*K*K;
     
       
            System.out.println(A);
     
    }
}

Measured memory_bytes: 35788
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	int max = 7368792;
	Scanner sc = new Scanner(System.in);
	public void run(){
		while(true){
			int m = sc.nextInt();
			int n = sc.nextInt();
			if(m==0 && n==0) break;
			calc(m, n);
		}
	}
	public void calc(int m,int n){
		char[] list = new char[max];
		
		int now = m;
		for(int i = 0; i < n; i++){
			while(now < max){
				if(list[now] == 0){
					int k = now;
					while(k < max){
						list[k] = 1;
						k += now;
					}
					now += 1;
					break;
				}
				now+=1;
			}
		}
		
		int ans = 0;
		int flag = 0;
		for(int i = m; i < max; i++){
			if(list[i] == 0){
				if(flag == 1) {
					ans = i;
					break;
				}
			}
			else flag = 1;
		}
		
		System.out.println(ans);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
}

Measured memory_bytes: 492076
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; cin >>N;
  vector<ll> A(N); rep(i, N) cin >>A[i];
  vector<ll> Asum(N+1); rep(i, N) Asum[i+1] = Asum[i] + A[i];
  map<ll,ll> score;
  ll res = 0;
  rep(i, Asum.size()){
    res += score[Asum[i]]; score[Asum[i]]++;
  }
  cout <<res <<endl;
}


Measured memory_bytes: 15872
#include <stdio.h>
int main(void)
{
	unsigned int S;
	unsigned int h;
	unsigned int m;
	unsigned int s;

	scanf("%d", &S);
	h = S / 3600;
	m = (S % 3600) / 60;
	s = (S % 3600) % 60;

	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	long long N, ans = 10000000000000LL;
	scanf("%lld", &N);
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) ans = min(ans, i + N / i - 2);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 128
s = input()
n = len(s)
ans = 0
if n == 1:
    print(int(s))
else:
    for i in range(1 << n - 1):
        c = ""
        b = format(i, "b").zfill(n - 1)

        for j in range(len(b)):
            c += s[j]
            if b[j] == "1":
                c += "+"
        c += s[-1]
        total = sum(map(int, c.split("+")))
        ans += total
    print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string>
#include <vector>
#include <tuple>

int main(int argc, char* argv[]){
    std::vector<std::tuple<int, int> > inputs = {};
    int a, b;
    while(true) {
        scanf("%d %d", &a, &b);
        if (a + b == 0){
            break;
        }
        inputs.push_back(std::make_tuple(a, b));
    }
    for(auto each: inputs){
        printf("%d %d\n",
            std::min(std::get<0>(each), std::get<1>(each)),
            std::max(std::get<0>(each), std::get<1>(each))
        );
    }

}


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

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

  int a[110] = {};
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a,a+n, greater<int>());

  int alice = 0, bob = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0){
      alice += a[i];
    }else{
      bob += a[i];
    }
  }

  cout << alice - bob << endl;
}


Measured memory_bytes: 256