akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int abc[3];
int main(){
  string str;
  bool f = true;
  cin>>str;
  for(int i=0;i<3;i++)
  {
    if(str[i]=='a') abc[0]++;
    if(str[i]=='b') abc[1]++;
    if(str[i]=='c') abc[2]++;
  }
  for(int i=0;i<3;i++)
  {
    if(abc[i]!=1)
    {
      f=false; break;
    }
  }
  if(f)
  {
    cout<<"Yes"<<"\n";
  }
  else
  {
    cout<<"No"<<"\n";
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<vector>
#include<numeric>
#include<algorithm>

using namespace std;

typedef bitset<30000> BS;

BS absbs;
BS is[3000];
vector<int> idx;
int a[32345],b[32345];

int rec(const BS &bs,int nth,int r){
  if(r<0)return r;
  if(bs==absbs)return r;
  while((is[idx[nth]]&~bs).none()){
    nth++;
  }
  BS n=is[idx[nth]]&~bs;
  if(n.count()==1){
    for(int i=0;;i++){
      if(n[i]){
	return rec(bs|is[a[i]^b[i]^idx[nth]],nth+1,r-1);
      }
    }
  }else{
    int rv=rec(bs|is[idx[nth]],nth+1,r-1);
    BS o=bs;
    int c=0;
    for(int i=0;n.any();i++){
      if(n[i]){
	o|=bs|is[a[i]^b[i]^idx[nth]];
	c++;
	n[i]=false;
      }
    }
    return max(rv,rec(o,nth+1,r-c));
  }
}

int main(){
  int N,M,K;
  cin>>N>>M>>K;
  int pop[32345]={};
  for(int i=0;i<M;i++){
    absbs[i]=true;
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
    pop[a[i]]++;
    pop[b[i]]++;
    is[a[i]][i]=true;
    is[b[i]][i]=true;
  }
  idx.resize(N);
  iota(begin(idx),end(idx),0);
  sort(begin(idx),end(idx),[pop](int a,int b){
      return pop[a]>pop[b];
    });
  int r=rec(BS(),0,K);
  if(r<0){
    cout<<"Impossible"<<endl;
  }else{
    cout<<K-r<<endl;
  }
}

Measured memory_bytes: 17356
s = input()
while True:
    if s[-5:] == "dream":
        s = s[:-5]
        continue
    if s[-5:] == "erase":
        s = s[:-5]
        continue
    if s[-7:] == "dreamer":
        s = s[:-7]
        continue
    if s[-6:] == "eraser":
        s = s[:-6]
        continue
    break
print("YES" if s == "" else "NO")

Measured memory_bytes: 134644
m = int(input())

ans = 0

num = 0
for i in range(m):
    d, c = map(int, input().split())
    num += d * c
    ans += c
ans -= 1

nums = str(num)
if len(nums) <= 1:
    print(ans)
    exit()

while len(nums) > 1:
    up = nums[:len(nums)-1]
    ans += int(up)

    num = int(up) + int(nums[-1])
    nums = str(num)

print(ans)
exit()

Measured memory_bytes: 44248
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9 ,11]
c = [2]

if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9104
<?php

[$N] = fscanf(STDIN, "%d");

$array = fscanf(STDIN, str_repeat("%d", $N));
$half = intdiv($N,2)-1;
$ans = array_fill(0,$N,-1);

for($i=$N;$i>0;$i--){
    $start = intdiv($N, $i) * $i;
    $sum = 0;
    for($j = $start; $j>= $i; $j-=$i){
        if($j === $i){
            $ans[$i-1] = $array[$i-1] ^ $sum;
        }else{
            $sum += $ans[$j-1];
            $sum %= 2;
        }
    }
}

$sum = 0;
$list = [];
foreach($ans as $key => $value){
    if($value === 1){
        $sum++;
        $list[] = $key+1;
    }
}

echo $sum.PHP_EOL;
echo implode(" ", $list);



Measured memory_bytes: 35540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  in(n);
  vector<ll> a(100000);
  rep(i, 100000){
    if(i * i <= n && (i + 1) * (i + 1) > n){
      out(i * i);
      memi;
      return 0;
    }
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	if(a<b)
		cout << 0;
	else
		cout << 10;
	return 0;
}

Measured memory_bytes: 3648
fun main(args: Array<String>) {
    val (n, x0) = readLine()!!.split(" ").map(String::toInt)
    val x = (readLine()!!.split(" ").map(String::toInt) + x0).sorted()

    val delta = (0 until x.size-1).mapIndexed{i, n ->
        x[i+1] - x[i]
    }
    print(delta.reduce{a, b -> gcd(a,b)})
}

tailrec fun gcd(a: Int, b: Int): Int{
    if(b == 0) return a
    return gcd(b, a%b)
}

Measured memory_bytes: 55884
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,x,t;
  cin>>n>>x>>t;
  long long int ans=(n/x)*t;
  if(n%x!=0){
    ans+=t;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int A,B,C;
    cin >> A >> B>>C;
    cout << (A*B)/2 << endl;
    return 0;
}

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

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

	double x = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 2 == 1) {
			x++;
		}
	}
	cout << fixed << setprecision(6);
	cout << x / n << endl;
}


Measured memory_bytes: 256
import sys


if __name__ == '__main__' :
    
    S = input()
    K = int(input())

    # Sが1で始まりかつKの長さがまで1が続くようであれば1
    for i in range(0,K):
        if S[i] == '1' and i < K:
            continue
        elif S[i] != '1':
            print(S[i])
            exit()
    print('1')

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n + 1), b(n);
    rep(i, 0, n + 1){
        cin >> a[i];
    }
    rep(i, 0, n){
        cin >> b[i];
    }
    ll ans = 0;
    rep(i, 0, n){
        if(a[i] < b[i]){
            if(a[i+1] > b[i] - a[i]){
                ans += b[i];
                a[i+1] -= b[i] - a[i];
            }else{
                ans += a[i+1] + a[i];
                a[i+1] = 0;
            }
        }else{
            ans += b[i];
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
from decimal import *
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
input = sys.stdin.readline

temp = input().split(" ")
a = Decimal(temp[0])
b = Decimal(temp[1])
ans = a*b
print(math.floor(ans))


Measured memory_bytes: 9924
N = int(input())

for l in range(N):
    x,y,b,p = [int(i) for i in input().split()]
    
    ans = x*b + y*p
    
    if b < 5:
        b = 5
    if p < 2:
        p = 2
            
    ans = min(ans, (x*b + y*p) * 4 // 5)

    print(ans)


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ll x, k; cin >> x >> k;
  vector<ll> r(k+1);
  vector<ll> lo(k+1);
  vector<ll> up(k+1);
  vector<ll> lonow(k+1);
  for(int i=1; i<=k; i++) {
    cin >> r[i];
  }

  lonow[0] = 0;
  lo[0] = 0;
  up[0] = x;
  ll now = 0;
  rep(i, k) {
    ll d = r[i+1]-r[i];
    if (i%2==0) {
      now += d;
      lonow[i+1] = max(lonow[i]-d, 0LL);
    } else {
      now -= d;
      lonow[i+1] = min(lonow[i]+d, x);
    }
    lo[i+1] = max(lo[i], now);
    up[i+1] = min(up[i]-x, now)+x;
  }

  int q; cin >> q;
  while(q--) {
    int t, a; cin >> t >> a;

    auto it = upper_bound(r.begin(), r.end(), t);
    it--;
    auto p = distance(r.begin(), it);
    debug(p, lo[p], up[p], lonow[p]);
    auto s = t - r[p];
    auto ret = lonow[p];
    if (lo[p] < a && a < up[p]) {
      auto d = a - lo[p];
      ret = lonow[p] + d;
    } else if (lo[p] < up[p] && up[p] <= a) {
      auto d = up[p] - lo[p];
      ret = lonow[p] + d;
    }
    if (p%2 == 0) {
      ret = max(0LL, ret-s);
    } else {
      ret = min(x, ret+s);
    }
    cout << ret << '\n';
  }
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main{

    public static void main(String[] args)throws IOException{
    	br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
	int n = nextInt();
	out.println((long)Math.pow(n,3));
        out.close();
    }
        
    static BufferedReader br;
    static StringTokenizer st = new StringTokenizer("");
    static String next()throws IOException{
    	while(!st.hasMoreTokens()){
    	    st = new StringTokenizer(br.readLine());
    	}
    	return st.nextToken();
    }
    static int nextInt()throws IOException{
    	return Integer.parseInt(next());
    }
    static long nextLong()throws IOException{
    	return Long.parseLong(next());
    }
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> a(3 * N), b(N + 1, 0), c(N + 1, 0);
    rep(i, 3 * N) cin >> a[i];
    priority_queue<ll> qb, qc;
    rep(i, N) {
        b[0] += a[i];
        qb.push(-a[i]);
        c[0] += a[2 * N + i];
        qc.push(a[2 * N + i]);
    }
    rep(i, N) {
        b[i + 1] = b[i] + a[N + i];
        qb.push(-a[N + i]);
        ll p = qb.top();
        qb.pop();
        b[i + 1] += p;
        c[i + 1] = c[i] + a[2 * N - 1 - i];
        qc.push(a[2 * N - 1 - i]);
        p = qc.top();
        qc.pop();
        c[i + 1] -= p;
    }
    ll ans = -1e18;
    rep(i, N + 1) {
        ans = max(ans, b[i] - c[N - i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 5996
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int M;
  cin>>M;
  vector<ll> D(M),C(M);
  rep(i,M) cin>>D[i]>>C[i];
  ll ans=-1;
  rep(i,M) ans+=C[i];
  ll sum=0;
  rep(i,M) sum+=D[i]*C[i];
  ans+=(sum-1)/9;
  cout<<ans<<endl;
}

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

x_now, y_now, t_now = 0, 0, 0

for i in range(n):
    t, x, y = map(int, input().split())
    distance = (t -t_now) - abs(x-x_now) - abs(y-y_now)
    if distance >= 0 and distance % 2 == 0:
        x_now,y_now,t_now = x,y,t
    else:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 45672
#include<cstdio>
using namespace std;
int a[100001]={0};
int flag[100001]={0};
void Find_Prime()
{
    for(int i=2;i<=100000;i++)
        if(a[i]==0)
        {
            for(int j=i+i;j<=100000;j+=i)
                a[j]=1;
        }
    return;
}
int main()
{
    Find_Prime();
    a[0]=a[1]=1;
    for(int i=1;i*2-1<=100000;i++)
        if(a[i]==0&&a[i]==a[i*2-1])
            flag[i*2-1]=1;
    for(int i=1;i<=100000;i++)
        flag[i]+=flag[i-1];
    int n,l,r;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&l,&r);
        printf("%d\n",flag[r]-flag[l-1]);
    }
}


Measured memory_bytes: 1280
N, M = map(int,input().split())

# S:N, c:M
# c+c = S

if M < 2*N :
    print(M // 2)
else :
    ans = N
    r = M - 2 * N  # 残り個数

    ans += r // 4  # (c + c)cc で一つ

    print(ans)

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

#define ll long long

using namespace std;

const int mod = 1e9 + 7, N = 1005;

int n, m;
ll dp[N][N];

char c[N][N];

int main () {
    cin >> n >> m;
    for (int i = 1;i <= n;i ++) {
        for (int j = 1;j <= m;j ++) {
            cin >> c[i][j];
        }
    }
    dp[1][0] = 1;
    for (int i = 1;i <= n;i ++) {
        for (int j = 1;j <= m;j ++) {
            if (c[i - 1][j] != '#')dp[i][j] += dp[i - 1][j];
            if (c[i][j - 1] != '#')dp[i][j] += dp[i][j - 1];
            dp[i][j] %= mod;
        }
    }
    cout << dp[n][m];
}


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

using namespace std;

long long n,m,k,l,i,j,a,b,c,d[200005],dp[200005],mx=1000001;

struct LCtree{
    long long k,b;
    LCtree *L,*R;
    LCtree(){
        k=b=1000000000000000000;
        L=R=NULL;
    }
};

long long val(LCtree *&nw,long long x){
    return nw->k*x+nw->b;
}

void upd(LCtree *&it,long long l,long long r,LCtree *&nw){
    //cout<<i<<" "<<l<<" "<<r<<" "<<nw->k<<" "<<nw->b<<" \n";
    if(it==NULL) { it=new LCtree();it->k=nw->k;it->b=nw->b;return;}
    long long mid1=(val(it,(l+r)/2) > val(nw,(l+r)/2));
    long long l1=(val(it,l) > val(nw,l));
    long long r1=(val(it,r-1) > val(nw,r-1));
    if(mid1) {swap(it->k,nw->k);swap(it->b,nw->b);}
    if(r-l==1)
        return;
    if(l1!=mid1)
        upd(it->L,l,(l+r)/2,nw);
    else
        if(r1!=mid1)
        upd(it->R,(l+r)/2,r,nw);
     //   cout<<mid1<<" "<<l1<<" "<<r1<<endl;
    //    cout<<l<<" "<<r<<" "<<it->k<<" "<<it->b<<endl;
}

long long fnd(LCtree *&it,long long l,long long r,long long x){
    if(it==NULL) return 1000000000000000000;//cout<<l<<" "<<r<<" "<<x<<" "<<it->k<<" "<<it->b<<" "<<val(it,x)<<endl;
    if(r-l==1) return val(it,x);
    if(x<(l+r)/2) return min(val(it,x),fnd(it->L,l,(l+r)/2,x));
    else return min(val(it,x),fnd(it->R,(l+r)/2,r,x));
}
main(){

cin>>n>>c;cin>>d[1];

LCtree *root=new LCtree();
LCtree *nw=new LCtree();
root->k=-2*d[1];
root->b=d[1]*d[1]+c;
for(i=2;i<=n;i++){
    cin>>d[i];
    dp[i]=fnd(root,1,mx+1,d[i])+d[i]*d[i];
   // cout<<dp[i]<<"\n";
    nw->k=-2*d[i];
    nw->b=d[i]*d[i]+c+dp[i];
    upd(root,1,mx+1,nw);
}

cout<<dp[n];

}
/*

8 1000
1 3 4 5 10 11 12 13


*/


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

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

    int n;
    cin >> n;
    int l[n];

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

    int sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        sum += l[i];        
    }
    
    if (sum > l[n - 1]) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
/*
    Author : Ritesh Singh
*/
 
#include <bits/stdc++.h>
using namespace std;
#define lct long long int t;cin>>t;while(t--)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define el '\n'
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int mod = 1e9+7;
typedef long long ll;


int32_t main()
{
    IOS;
    ll n; cin>>n;
    ll ans = 0, x, curr_max = INT_MIN;
    cin>>x;
    curr_max = x;
    rep(i,1,n)
    {
        cin >> x;
        if(x < curr_max)
            ans += (curr_max-x);
        else if(x > curr_max)
            curr_max = x;
    }
    cout<<ans<<endl;

}



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

struct Card{
  char Illust;
  int Num;
};

void Disp(Card *c,int n){
  for(int i = 0;i < n-1;i++){
    cout << c[i].Illust << c[i].Num << " ";
  }cout << c[n-1].Illust << c[n-1].Num << endl;
}

bool isStable(Card *c1,Card *c2,int n){
  for(int i = 0;i < n;i++){
    if(c1[i].Illust != c2[i].Illust){
      return false;
    }
  }
  return true;
}

void BubbleSort(Card *c,int n){
  for(int i = 0;i < n;i++){
    for(int j = n-1;j > i;j--){
      if(c[j].Num < c[j-1].Num){
        swap(c[j].Num,c[j-1].Num);
        swap(c[j].Illust,c[j-1].Illust);
      }
    }
  }
}

void SelectionSort(Card *c,int n){
  int minv;
  for(int i = 0;i < n-1;i++){
    minv = i;
    for(int j = i;j < n;j++){
      if(c[j].Num < c[minv].Num){
        minv = j;
      }
    }
    swap(c[i].Num,c[minv].Num);
    swap(c[i].Illust,c[minv].Illust);
  }
}


int main(){
  int n;
  Card c_1[101],c_2[101];
  cin >> n;
  
  for(int i = 0;i < n;i++){
    cin >> c_1[i].Illust >> c_1[i].Num;
    c_2[i] = c_1[i];
  }
  
  BubbleSort(c_1,n);
  SelectionSort(c_2,n);
  Disp(c_1,n);
  cout << "Stable" << endl;
  Disp(c_2,n);
  if(isStable(c_1,c_2,n)){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3096
import sys
for e in sys.stdin:
    H, W = map(int,e.split())
    if H == 0 and W == 0:
        break
    else:
        l_odd = ["#","."]*(W//2) + ["#"]*(W%2)
        l_even = [".","#"]*(W//2) + ["."]*(W%2)
        for i in range(H):
            if (i%2) == 0:
                print("".join(l_odd))
            else:
                print("".join(l_even))
            
        print()
            


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

P minmax(ll a,ll b){
  return P( min(a,b) , max(a,b) );
}
using Graph = vector<vector< ll >>;

map< P , ll > Cost;

vector< ll > Sum;
vector< ll > Parent;

set< P > bridges(Graph &g) {
  vector< P > bri;
  
  int n = g.size();
  vector< ll> cmp(n);
  stack< ll > s, roots;
  vector< ll > ord(n, -1);
  int id = 0, k = 0;
  vector< ll > onS(n);
  function<void(ll, ll)> dfs = [&](ll v, ll u) {
    Parent[v]=u;
    
    ord[v] = id++;
    s.emplace(v);
    onS[v] = true;
    roots.emplace(v);
    for (auto &e : g[v]) {
      ll w = e;
      if (ord[w] == -1) {
        dfs(w, v);
        Sum[v] += Sum[w];
        
        Sum[v] += Cost[ minmax(v,w) ];
        
      } else if (u != w && onS[w]) {
        Sum[v] += Cost[ minmax(v,w) ];
        
        while (ord[roots.top()] > ord[w]) roots.pop();
      }
    }
    
    if (v == roots.top()) {
      bri.emplace_back( minmax(u, v) );
      while (true) {
        ll w = s.top();
        s.pop();
        onS[w] = false;
        cmp[w] = k;
        if (v == w) break;
      }
      roots.pop();
      k++;
    }
  };
  
  rep(i, n) {
    if (ord[i] != -1) continue;
    dfs(i, -1);
    bri.pop_back();
  }
  return set< P > (bri.begin(), bri.end());
}

int main() {
  ll total=0;
  
  int N, M;
  cin >> N >> M;
  Graph g(N);
  rep(i, M) {
    ll u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
    Cost[ minmax(u,v) ]=w;
    total += w;
  }
  
  Parent.resize(N, -1);
  Sum.resize(N, 0 );
  
  set< P > es = bridges(g);

  ll mini=(1LL<<60);
  
  P ans=P(N+N, N+N);
  
  for(ll i=0;i<N;i++){
    
    for(ll j : g[i] ){
      ll a=i;
      ll b=j;
      
      if( es.count( minmax(a,b) )==0){
        ll tmp = total - Cost[ minmax(a,b) ];
        if( mini > tmp ){
          mini = tmp;
          ans = P(N+N, N+N);
        }
        if( mini == tmp ){
          ans= min( ans, minmax(a,b) );
        }
        continue;
      }
      
      if( Parent[a] != b ){
        swap(a,b);
      }
      
      // panret[a]==b;
      ll tmp = abs((Sum[a])-(total-Sum[a]- Cost[ minmax(a,b) ]));
      
      if( mini > tmp ){
        mini = tmp;
        ans = P(N+N, N+N);
      }

      if( mini == tmp ){
        ans= min( ans, minmax(a,b) );
      }
      
    }
  }

  cout<<ans.first+1<<' '<<ans.second+1<<endl;
  return 0;

}





Measured memory_bytes: 27024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

template<typename T>
using vec2 = vector<vector<T>>;
template<typename T>
using vec3 = vec2<vector<T>>;
template<typename T>
using vec4 = vec3<vector<T>>;
template<typename T>
using vec5 = vec4<vector<T>>;
template<typename T>
using vec6 = vec5<vector<T>>;



int main(){
    int N,M;cin>>N>>M;
    vector<set<ll>> graph(N, set<ll>());
    for(int i = 0;i < M;i++){
        int a,b;cin>>a>>b;a--;b--;
        graph[a].insert(b);
        graph[b].insert(a);
    }
    vector<int> visited(N, -1);
    queue<pair<int,int>> q;
    int ans = 0;
    for(int i = 0;i < N;i++){
        if(visited[i] != -1)continue;
        q.push(make_pair(i,i));
        while(!q.empty()){
            pair<int,int> p = q.front();q.pop();
            int person = p.first;
            int num = p.second;
            if(visited[person] != -1)continue;
            // cout<<"-----"<<endl;
            // cout<<person<<" "<<num<<endl;
            visited[person] = num;
            // ans = max(ans,num);
            for(ll n : graph[person]){
                if(visited[n] != -1)continue;
                // cout<<n<<endl;
                q.push(make_pair(n, num));
            }
        }
    }
    vector<int> B(N);
    for(int i = 0;i < N;i++){
        B[visited[i]]++;
    }
    
    for(int i = 0;i < N;i++){
        ans = max(ans,B[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 33488
#include <iostream>
#include <algorithm>
 
constexpr int MAX_N = 101, MAX_W = 10001, MAX_VW = 1001;
 
int n, max_w, w[MAX_N], v[MAX_N], dp[MAX_N][MAX_W];
 
void fill_dp(){
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= max_w; ++j){
            if(j < w[i]) dp[i + 1][j] = dp[i][j];
            else dp[i + 1][j] = std::max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
        }
    }
    return;
}
 
void solve(){
    fill_dp();
    std::cout << dp[n][max_w] << std::endl;
    return;
}
 
int main(){
    std::cin >> n >> max_w;
    for(int i = 0; i < n; ++i)
        std::cin >> v[i] >> w[i];
    solve();
     
    return 0;
}

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

using namespace std;
const long int maxn=1000000;
long long int n,i,c=0,t, a[maxn][3];
int main(){
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i][1];
        a[i][2]=0;
    }

    for(i=1;i<=n;i++){
        t=a[i][1];
        if(i!=t&&i==a[t][1]&&(a[i][2]==0&&a[t][2]==0)){
            c++;
            a[i][2]=a[t][2]=1;
        }
    }
    cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 2560
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
    n: usize,
    r: usize,
    );
    let ans = if n >= 10 {r} else { r + 100 * (10 - n) };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(){
    int i;
    int a = 0;
    int b = 0;
    int ab = 0;
    int o = 0;
    char str[10];
    while(1){
        if(scanf("%d,%s",&i,str) == -1)break;
        if(str[0] == 'A'){
            if(str[1] == 'B'){
                ab = ab + 1;
            }
            else{
                a = a + 1;
            }
        }
        else if(str[0] == 'B'){
            b = b + 1;
        }
        else if(str[0] == 'O'){
            o = o + 1;
        }
    }
    printf("%d\n",a);
    printf("%d\n",b);
    printf("%d\n",ab);
    printf("%d\n",o);
    return 0;
}

Measured memory_bytes: 592
import sys
n,y = map(int,input().split())
m = []
for i in range(0,n+1):
    for j in range(0,n-i+1):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print('{0} {1} {2}'.format(i,j,n-i-j))
            sys.exit()

print('{0} {1} {2}'.format(-1,-1,-1))


Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, ans;

int main() {
	cin >> N;
	for (int i = 1; i <= 164; i++) {
		string S = "";
		if (i % 9 != 0) S += to_string(i % 9);
		for (int j = 0; j < i / 9; j++) S += "9";
		long long val = stoll(S);
		if (val > N) { ans = i - 1; break; }
	}
	cout << ans << endl;
	return 0;
}

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

N = int(input())
As = list(map(int,input().split()))

mn_cost = 1e10
for v in range(-100,101):
    cost = sum((v - a) ** 2 for a in As)
    if cost < mn_cost:
        mn_cost = cost
print(mn_cost)


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

using namespace std;

int main() {
	int temp = 1, count = 1;
	vector<int> Vec;
	for (;;) {
		cin >> temp;
		if (temp != 0) {
			Vec.push_back(temp);
		}
		else {
			break;
		}
	}
	for (int i=0; i<Vec.size(); i++) {
		cout << "Case " << i+1 << ": " << Vec[i] << endl;
	}
}


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


int main() {
    char c;
    cin >> c;
    if (c == 'a') cout << "vowel" << endl;
    else if (c == 'e') cout << "vowel" << endl;
    else if (c == 'i') cout << "vowel" << endl;
    else if (c == 'o') cout << "vowel" << endl;
    else if (c == 'u') cout << "vowel" << endl;
    else cout << "consonant" << endl;

}


Measured memory_bytes: 3600
import java.util.*;
 
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
   		String B = sc.next();
        int n = B. length();
      if(A>=n){   
   			System.out.println(B);
  	  }else{
		    System.out.println(B.substring(0,A)+"...");
}
    }
}

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    ll h[n];
    rep(i, n) cin >> h[i];

    ll l = 1e+9 + 10, r = 0;

    while(l - r > 1){
        ll t = (l + r) / 2;
        ll res = 0;
        bool flag = false;
        rep(i, n){
            ll y = max(h[i] - t * b, ll(0));
            res += ll(ceil(double(y) / double(a - b)));
        }

        if (res <= t) flag = true;

        if (flag) l = t;
        else r = t;
    }

    cout << l << endl;
}

Measured memory_bytes: 1024
from fractions import gcd

A, B, C, D = map(int, input().split())

cnt_c = B//C - (A-1)//C
cnt_d = B//D - (A-1)//D

lcm = C * D // gcd(C, D)
cnt_cd = B//lcm - (A-1)//lcm

divisible = cnt_c + cnt_d - cnt_cd
print(B-A+1-divisible)


Measured memory_bytes: 5600
from itertools import accumulate
import sys
N, Q = map(int, input().split())
S = input()
rs = [0] * N

for i in range(N - 1):
    if S[i] + S[i + 1] == "AC":
        rs[i + 1] = 1

rm = [0] + list(accumulate(rs))

for i in range(Q):
    ans = 0
    l, r = map(int, sys.stdin.readline().split())
    if S[l] == "C":
        ans -= 1
    ans = rm[r] - rm[l]
    print(ans)

Measured memory_bytes: 56224
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String result = "No";
        if(S.charAt(0) == S.charAt(1)){
            if(S.charAt(0) != S.charAt(2) && S.charAt(2) == S.charAt(3)){
                result = "Yes";
            }
        } else if(S.charAt(0) == S.charAt(2)){
            if(S.charAt(0) != S.charAt(1) && S.charAt(1) == S.charAt(3)){
                result = "Yes";
            }
        } else if(S.charAt(0) == S.charAt(3)){
            if(S.charAt(0) != S.charAt(1) && S.charAt(1) == S.charAt(2)){
                result = "Yes";
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main{
	static int[] dp=new int[50001];
	static int n, m;
    static int[] c=new int[21];
	static void dp() {
		
    	for(int i=0; i<m; i++) {
    		for(int j=0; j+c[i]<=n; j++) {
    			if(dp[j+c[i]] == 0)  dp[j+c[i]]=dp[j]+1;
                else dp[j+c[i]]=Math.min(dp[j+c[i]], dp[j]+1);
    		}
    	}
    }
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        for(int i=0; i<m; i++) {
        	c[i]=sc.nextInt();
        }
        dp();
        System.out.println(dp[n]);
        
	}
}


Measured memory_bytes: 26892
n=int(input())
dp=[1 for i in range(n+2)]
dp[0]=dp[1]=dp[2]=0
modd=1e9+7
for i in range(3,n):
    for j in range(3,n-i+1):
        dp[i+j]=(dp[i+j]+dp[i])%modd
print(int(dp[n]))

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

bool sortby(const pair<int, pair<string,int>> &a,
                const pair<int, pair<string,int>> &b)
{
        return a.second.first < b.second.first ||
                ((a.second.first == b.second.first) && (a.second.second > b.second.second));
}
int main()
{
        int N,P;
        string S;
        vector<pair<int, pair<string, int>>> SP(1000);
        cin >> N;
        for (int i=0;i<N;i++) {
                cin >> S >> P;
                SP[i] = make_pair(i+1, make_pair(S,P));
        }
        sort(SP.begin(), SP.begin()+N, sortby);
        for (int i=0;i<N;i++) {
                cout << SP[i].first << endl;
        }
        return 0;
}


Measured memory_bytes: 256
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


N = int(input())
MAX = 10 ** 5 + 1
while True:
    if is_prime(N):
        print(N)
        exit()
    else:
        N += 1


Measured memory_bytes: 38896
def r(x):
 while u[x]>=0:x=u[x]
 return x
(n,m),_,*e=[map(int,t.split())for t in open(0).readlines()];u=[-1]*-~n;a=[n*~-n//2]
for x,y in e[::-1]:
 t=a[-1];x,y=sorted((r(x),r(y)))
 if x!=y:t-=u[x]*u[y];u[x]+=u[y];u[y]=x
 a.append(t)
print(*a[::-1],sep='\n')

Measured memory_bytes: 55916
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

const int cm = 1<<17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha(){
	if(ci-cn == cm){ fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

inline int getint(){
	int A = 0;
	if(ci-cn+16 > cm) while((ct=getcha()) >= '0') A = A*10 + ct - '0';
	else while ((ct=*ci++) >= '0') A = A*10 + ct - '0';
	return A;
}

const int dm = 1<<20;
char dn[dm], *di = dn;
inline void putint(int x){
	char c[10];
	int d; for(d=0; x; d++, x/=10) c[d] = x%10 + '0';
	for(int i=d-1; i>=0; --i) *di++ = c[i];
	*di++ = '\n';
}

int main(){
	int N = getint();
	int G[N], C[N-1];
	rp(i, 0, N-1){
		int p = getint(); C[i] = getint();
		G[--C[i]] = p-1;
	}

	int K = 1;
	int pre_colors[N]; rp(i, 0, N) pre_colors[i] = 0;

	rp(c, 1, N){
		int p = G[c];
		int color = pre_colors[p] + 1;
		pre_colors[p] = G[c] = color==G[p]? ++color: color;
		K = max(K, color);
	}

	putint(K);
	for(int c:C) putint(G[c]);
	fwrite(dn, 1, di - dn, stdout);
}

Measured memory_bytes: 1920
local n = io.read("*n", "*l")
local s = io.read()
local t = {}
for i = 1, n do
  t[i] = s:sub(i, i) == "#" and 1 or 0
end
local sum = {t[1]}
for i = 2, n do
  sum[i] = sum[i - 1] + t[i]
end
local ret = n - sum[n]
for i = 1, n do
  local not_white = sum[i]
  local not_black = (n - i) - (sum[n] - sum[i])
  ret = math.min(ret, not_white + not_black)
end
print(ret)


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

int N;
vector<int> stones;

int kode_festival(int depth, int position){
    if(depth == N){
        return stones[position];
    }else{
        int left = kode_festival(depth + 1, position * 2);
        int right = kode_festival(depth + 1, position * 2 + 1);
        if(left == right){
            return left;
        }else{
            return max(left, right) - min(left, right);
        }
    }
}

int main(){
    cin >> N;
    stones.resize(1 << N);
    for(int i = 0; i < (1 << N); i++){
        cin >> stones[i];
    }
    cout << kode_festival(0, 0) << endl;
}


Measured memory_bytes: 1280
if __name__ == "__main__":
    
    n = int(input())
    
    ans = 0
    
    for i in range(n):
        x,u = input().split()
        if u == "JPY":
            ans += int(x)
        else:
            ans += 380000*float(x)
            
    print(ans)
    

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define pii pair<int , int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000 + 7;
const ll LINF = INF * (ll)INF;
const int mod = INF;
const int MAX = 1 << 25;
int q[100005] , w[100005];
int main()
{
	ios_base::sync_with_stdio(0);
	int a , b , m;
	cin >> a >> b >> m;
	int mn1 = INF , mn2 = INF;
	for(int i = 0; i < a; i++)
	{
		cin >> q[i];
		mn1 = min(mn1 , q[i]);
	}
	for(int i = 0; i < b; i ++)
	{
		cin >> w[i];
		mn2 = min(mn2 , w[i]);
	}
	int s = mn1 + mn2;
	while(m--)
	{
		int x , y , c;
		cin >> x >> y >> c;
		x--;y--;
		s = min(s , q[x] + w[y] - c);
	}
	cout << s;
	
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define print(x,y) (cout << (x) << (y))
#define inf INT_MAX
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
const int MOD = 1e9 + 7; //998244353;


int main(){
    int n;
    cin >> n;
    int dp[n];
    vi a(n);
    for(int &i : a) cin >> i;
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(int i = 2;i<n;i++){
        dp[i] = min(abs(a[i] - a[i-1]) + dp[i-1] , abs(a[i] - a[i-2]) + dp[i-2]);
    }
    cout << dp[n-1];
}





Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

void insertionSort(int *a, int n){
  for(int k=0;k<n;k++){
    if(k!=n-1){
      cout << a[k] << " ";
    }else{
      cout << a[k] << endl;
    }
  }

  for(int i=1;i<n;i++){
    int v = a[i];
    int j = i-1;


    while(j>=0 && a[j]>v){
      a[j+1] = a[j];
      j--;
    }
    
    a[j+1] = v;

        
    for(int k=0;k<n;k++){
      if(k!=n-1){
	cout << a[k] << " ";
      }else{
	cout << a[k] << endl;
      }
    }

  }
}

int main(){
  int n;
  cin >> n;
  int *a = new int[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  insertionSort(a, n);

}
  
    

Measured memory_bytes: 1188
c = 0
h = 0
while True:
    try:
        a, b, c = [int(x) for x in input().split(",")]
    except:
        break
    
    if a**2 + b**2 == c**2:
        c += 1
    elif a == b:
        h += 1

print(c)
print(h)



Measured memory_bytes: 5596
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> PP;
 
/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/
 
vector<vector<int> > G;
unordered_map<ll, ll> C;
 
unordered_map<ll, int> D;
unordered_map<ll, ll> E;

int N;

ll mp(ll a, int b) {
	return ((a << 30) | b);
}

void cal2(int a, int p, ll d, ll e) {
	if (p != -1) {
		D[mp(p, a)] = d;
		E[mp(p, a)] = e;
	}
	ll tol = 0;
	for (int n = 0;n < G[a].size();n++) {
		if (G[a][n] != p) tol += E[mp(G[a][n], a)];
	}
	for (int n = 0;n < G[a].size();n++) {
		if (G[a][n] != p) {
			ll d_n = N - D[mp(G[a][n], a)];
			ll e_n = e + d_n * 2 * C[mp(G[a][n], a)] + tol - E[mp(G[a][n], a)];
			cal2(G[a][n], a, d_n, e_n);
		}
	}
	return;
}

void cal(int a, int b) {
	// Calculate following contents:
	// (1) Number of child in subtree root as a, without branch b.
	// (2) Sum of path sum till subtree a.
	if (D.find(mp(a, b)) != D.end()) return;
	int child = 1;
	ll sum = 0;
	for (int n = 0;n < G[a].size();n++) {
		int m = G[a][n];
		if (m == b) continue;
		cal(m, a);
		child += D[mp(m, a)];
		sum += E[mp(m, a)];
	}
	if (b == -1) return;
	sum += C[mp(a, b)] * 2 * child;
	E[mp(a, b)] = sum;
	D[mp(a, b)] = child;
	return;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin >> N;
    G.resize(N);
    for (int i = 1;i < N;i++) {
    	int a, b, c;
    	cin >> a >> b >> c;
    	a--;
    	b--;
    	G[a].push_back(b);
    	G[b].push_back(a);
    	C[mp(a, b)] = c;
    	C[mp(b, a)] = c;
    }
    cal(0, -1);
    cal2(0, -1, 0, 0);
    ll ans = 0;
    for (int i = 0;i < N;i++) {
    	// Try use i as root.
    	int ma = 0;
    	int idx = 0;
    	ll sol = 0;
    	for (int j = 0;j < G[i].size();j++) {
    		if (D[mp(G[i][j], i)] > ma) {
	    		ma = max(ma, D[mp(G[i][j], i)]); // Maximum branch.
	    		idx = G[i][j];
	    	}
    		sol += E[mp(G[i][j], i)];
    	}
    	int rem = N - 1 - ma;
    	if (ma > rem + 1) continue; // Could not pair.
    	if (ma == rem + 1) {
    		sol -= C[mp(i, idx)];
    	}
    	else {
    		// Remove one branch.
    		ll mi = 1E9;
    		for (int j = 0;j < G[i].size();j++) {
    			mi = min(mi, C[mp(i, G[i][j])]);
    		}
    		sol -= mi;
    	}
    	ans = max(ans, sol);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 39880
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(void)
{
  int a, b;
  vector <int> leap;
 
  while (true) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    for (int i = a; i <= b; i++)
      if (i % 400 == 0 || (i % 100 && i % 4 == 0))
        leap.push_back(i);
    leap.push_back(-1);
  }
  
  bool hoge = false;
  for (int i = 0; i < leap.size()-1; i++) {
    if (leap[i] < 0 && hoge) {
      cout << "NA\n" << endl;
      hoge = false;
    } else if (leap[i] < 0) {
      cout << endl;
      hoge = true;
    } else {
      cout <<  leap[i] << endl;
      hoge = false;
    }
  }
  return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()
#define pb push_back

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;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,M,Q;
int a[50],b[50],c[50],d[50];
int num[10];
int ans;
void dfs(int x,int y){
	if(x==N){
		int res=0;
		rep(i,Q){
			if(num[b[i]]-num[a[i]]==c[i])res+=d[i];
		}
		chmax(ans,res);
		return;
	}
	num[x]=y;
	for(int i=y;i<=M;i++)dfs(x+1,i);
}
signed main(){
	cin>>N>>M>>Q;
	rep(i,Q){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;b[i]--;
	}
	REP(i,M+1)dfs(0,i);
	cout<<ans<<endl;
}


Measured memory_bytes: 3636
n = int(input())
l = [0, 0, 0, 0]
for _ in range(n) :
    s = input()
    if s == "AC" :
        l[0] += 1
    if s == "WA" :
        l[1] += 1
    if s == "TLE" :
        l[2] += 1
    if s == "RE" :
        l[3] += 1
print("AC x " + str(l[0]) + "\nWA x " + str(l[1]) + "\nTLE x " + str(l[2]) + "\nRE x " + str(l[3]))

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

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

int main()
{
    int X;
    cin >> X;
    if(X == 3 || X == 5 || X == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int n,p;
    cin >> n;
    vector<int> P;
    vector<int> PP;
    int cnt = 0;
    rep(i,n) {
        cin >> p;
        P.pb(p);
    }
    int minn = INF;
    rep(i,P.size()) {
        if (P[i] < minn){
            minn = P[i];
            cnt++;
        }
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 1400
Nap = []

n,m = map(int,input().split())
for i in range(n):
    v,w = map(int,input().split())
    Nap.append([v,w])
DP = [[0 for j in range(m + 1)] for i in range(n + 1)]
for i in range(1,n+1):
        for j in range(m+1):
            if j - Nap[i-1][1] >= 0:
                DP[i][j] = max(DP[i-1][j],DP[i - 1][j - Nap[i - 1][1]] + Nap[i - 1][0])
            else:
                DP[i][j] = DP[i-1][j]
print(DP[n][m]) 

Measured memory_bytes: 28036
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n,d; cin >> n >> d;
    VVI x(n,VI(d)); REP(i,n) REP(j,d) cin >> x[i][j];
    int ans = 0;
    REP(i,n)FOR(j,i+1,n){
        int norm = 0;
        REP(k,d){
            int diff = abs(x[i][k]-x[j][k]);
            norm += diff*diff;
        }
        bool ok = 0;
        REP(k,norm+1) if(k*k==norm) ok = 1;
        if(ok) ans++;
    }
    out(ans);

    return 0;
}

Measured memory_bytes: 256