akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define ms memset
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define lower_bound lb
#define upper_bound ub

ll power(ll base, ll n, ll MOD){
    if (n == 0) return 1;
    if (n == 1) return base;
    ll halfn  = power(base,n/2,MOD);
    if (n % 2 == 1) return (((halfn * halfn) % MOD) * base) % MOD;
    return (halfn * halfn) % MOD;
}
ll inverse(ll n, ll MOD){
    return power(n, MOD-2, MOD);
}

int main()
{
    ll MOD = 1000000007;
    int n, m; cin >> n >> m;
    ll binom[n+1]; binom[0] = 1; FOR(i,1,n) binom[i] = (((binom[i-1]*(n-i+1)) %MOD)*inverse(i,MOD))% MOD;
    ll fact[m+1]; fact[m-n] = 1; FOR(i,m-n+1,m) fact[i] = (i * fact[i-1]) % MOD;
    ll ans = fact[m];
    FOR(i,1,n){
        ll a = (binom[i]*fact[m-i]) % MOD;
        if (i % 2 == 1) ans = (ans - a + MOD) % MOD;
        else ans = (ans + a) % MOD;
    }
    ans = (ans * fact[m]) % MOD;
    cout << ans << '\n';
    return 0;
}

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

int main() {
    string S;
    int K;
    cin >> S >> K;
    int len = S.size();

    vector<string> substrs;
    for (int l = 1; l <= 5; l++) {
        for (int i = 0; i + l <= len; i++) {
            substrs.push_back(S.substr(i, l));
        }
    }
    sort(begin(substrs), end(substrs));
    unique(begin(substrs), end(substrs));
    
    cout << substrs[K-1] << endl;

    return 0;
}

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

ll n,rez=1;
string s1,s2;
set<ll> pozicija;

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

    cin>>n>>s1>>s2;

    for(ll i=0;i<n;i++)
        if(s1[i]==s2[i])
            pozicija.insert(i);
    ll i=0;
    if(pozicija.count(0))
    {
        rez*=3;
        i++;
    }
    else
    {
        rez*=6;
        i+=2;
    }

    ll cnt=0;
    for(i;i<n;i++)
    {
        if(pozicija.count(i))
        {
            if(pozicija.count(i-1))
                rez*=2;
        }
        else
        {
            if(cnt==0)
                cnt++;
            else
            {
                cnt=0;
                if(pozicija.count(i-2))
                    rez*=2;
                else
                    rez*=3;
            }
        }
        rez%=1000000007;
    }

    cout<<rez<<endl;

    return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Long N = scanner.nextLong() + 1;
        scanner.close();

        // 桁数
        String s = String.valueOf(N);
        int length = s.length();
        int c = Integer.parseInt(s.substring(0, 1));
        int max = (c - 1) + 9 * (length - 1);

        System.out.println(max);
    }
}

Measured memory_bytes: 23380
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
l = sorted(l, key = lambda x: x[2], reverse=True)

def check(x,y):

    count = 0
    while l[count][2] == 0:
        count += 1
    h = l[count][2] + abs(x-l[count][0])+abs(y-l[count][1])

    for i,j,k in l[count:]:
        if k != max(h-abs(x-i)-abs(y-j),0):
            return False

    return x,y,h

for i in range(101):
    for j in range(101):
        if check(i,j):
            print(*check(i,j))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535
const long long int MOD = 998244353;
#define pb push_back
#define mp make_pair
#define fill(a)  memset(a, 0, sizeof (a))
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout << (#x) << " is " << (x) << endl;
const long long int MAXX = 2e5+5;
const long long int MINN = 2e6 + 5;
const long long int inf = 1e9;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector< iii > viii;

ll lcm(ll a, ll b) {
   return a / __gcd(a, b) * b;
}
int XOR(int x, int y){
  return (x | y) & (~x | ~y);
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
    return (a.second < b.second);
}
// bool isl = binary_search(x.begin(), x.end(), 5);
// __builtin_popcount(x)  - Returns the number of set bits in x
const long long int N = 1e7;
const int MAXN = 105;
int binsearch(int lo, int hi){
    while(lo<hi){
        int mid=(lo+hi)/2;
        if((mid))   // check(mid)
            hi=mid;
        else
            lo=mid+1;
    }
    return lo;
}
int power(int x,int y){
    int res=1;
    while(y>0){
      if(y&1) res=((res*x));

      y/=2;
      x=((x*x));
    }
    return res;
}


void fn(int n){
    set<iii> s;
    ll cnt=0;
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            int b=x+y;
            int c=n-(x*x+y*y+x*y);
            if(b*b+4*c>=0){
                int d = b*b+4*c;
                d = sqrt(d*1.0);
                if(d*d != b*b+4*c) continue;
                if(d-b >=0 && (d-b)%2 == 0 ){
                    int z = (d-b)/2;
                    if(z>=1){
                        // cout<<x<<" "<<y<<" "<<z<<"\n";
                        s.insert({x,{y,z}});
                        cnt++;
                    }
                }
            }
        }
    }
    cout<<s.size()<<"\n";
}
int main(){
    FAST    
    int nn;
    cin>>nn;
    for(int n=1;n<=nn;n++){
        fn(n);
    }
    return 0;
}




Measured memory_bytes: 3636
import sys
     
A=[]
fp =0
bp =0
 
n=int(raw_input())
while n:
    s = raw_input()
    if s[0] == 'i':
        A.append(int(s[7:]))
        fp += 1
    elif s[6] == ' ':
        try:
            i = A[::-1].index(int(s[7:]))
            if i!=-1:
                del A[-i-1]
                fp -=1
        except:
            pass
    elif s[6] == 'F':
        A.pop()
        fp -=1
    elif s[6] == 'L':
        bp +=1
    n -=1
 
for e in A[bp:fp+1][::-1]:
    print int(e),


Measured memory_bytes: 40624
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int n, k, arr[100000];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];

    int ans = 0;
    for (int i = 0; i < n - 1; i++)
        if (arr[i] >= k)
            ans += arr[i] - k + arr[i + 1], arr[i] = k, arr[i + 1] = 0;
        else if (arr[i] + arr[i + 1] >= k)
            ans += arr[i] + arr[i + 1] - k, arr[i + 1] = k - arr[i];
        else;
    cout << ans << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***


Measured memory_bytes: 1024
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
ll a[3050];

int main(){
int n=read();
ll llx=0;
for (;n--;){
  llx+=read()-1;
  }write(llx);
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
	//#include <vector>
	//#include<math.h>
	//#include <algorithm>
	//#include <functional>
	//#include <numeric>
	//#include<cmath>
	//#include <stdio.h> 
	//#include <cstdint>
	//#include <string>
	//#include <cstdlib>
	//#define pi 3.14159265359
using namespace std;


	int main() {

		int a;
		cin >> a;
		string b, c;

		cin >> b;
		cin >> c;

		for (int i = 0; i < a; i++) {
			cout << b[i];
			cout << c[i];
		}
		return 0;

	}

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

int main(){
    int n,num;
    char m ;
    cin >> n ;
    int trump[4][13]={0};

    for(int i=0;i<n;i++){
        cin >> m >> num;
        if(m == 'S'){
            trump[0][num-1] = 1;
        }
        else if(m == 'H'){
            trump[1][num-1] = 1;
        }
        else if(m == 'C'){
            trump[2][num-1] = 1;
        }
        else{
            trump[3][num-1] = 1;
        }
    }

    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(trump[i][j] == 0){
                if(i == 0){
                    cout << 'S' << " " << j+1 << endl;
                }
                else if(i == 1){
                    cout << 'H' << " " << j+1 << endl;
                }
                else if(i == 2){
                    cout << 'C' << " " << j+1 << endl;
                }
                else{
                    cout << 'D' << " " << j+1 << endl;
                }
            }
        }
    }

    return 0;

}

    



Measured memory_bytes: 3120
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <functional>
int main() {
	int N, a[300000];
	long long DPd[300000], DPu[300000];
	scanf("%d", &N);
	for (int i = 0; i < N * 3; i++)
		scanf("%d", &a[i]);
	{
		long long total = 0;
		std::priority_queue<int, std::vector<int>, std::greater<int>> smaller;
		for (int i = 0; i < N; i++) {
			total += a[i];
			smaller.push(a[i]);
		}
		DPd[N - 1] = total;
		for (int i = N; i < 2 * N; i++) {
			if (smaller.top() < a[i]) {
				total -= smaller.top();
				total += a[i];
				smaller.pop();
				smaller.push(a[i]);
			}
			DPd[i] = total;
		}
	}
	{
		long long total = 0;
		std::priority_queue<int> larger;
		for (int i = 3 * N - 1; 2 * N <= i; i--) {
			total += a[i];
			larger.push(a[i]);
		}
		DPu[2 * N] = total;
		for (int i = 2 * N - 1; N <= i; i--) {
			if (larger.top() > a[i]) {
				total -= larger.top();
				total += a[i];
				larger.pop();
				larger.push(a[i]);
			}
			DPu[i] = total;
		}
	}
	long long score = 0x8000000000000000ll;
	for (int i = N - 1; i < 2 * N; i++)
		score = std::max(score, DPd[i] - DPu[i + 1]);
	printf("%lld\n", score);
}

Measured memory_bytes: 6392
import itertools
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for y, z in itertools.combinations(x, 2):
    s = 0
    for _y, _z in zip(y, z):
        s += abs(_y - _z)**2

    if (math.sqrt(s)).is_integer():
        ans += 1

print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()0
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!

int n,k;
int xCordOf[105];

int distA(int y){
    return 2*abs(xCordOf[y]);
}
int distB(int y){
    return 2*abs(xCordOf[y]-k);
}
void solve(){
    cin>>n;
    cin>>k;
    for(int y=0;y<n;y++){
        int x;
        cin>>x;
        xCordOf[y]=x;
    }
    int sum=0;
    for(int y=0;y<n;y++){
        int d=min(distA(y),distB(y));
        if(d==INT_MAX){d=0;}
        sum+=d;
    }
    cout<<sum<<"\n";
}

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

Measured memory_bytes: 3632
N = int(input())
S = []

for i in range(N):
    S.append(input())

print('AC x {}'.format(S.count('AC')))
print('WA x {}'.format(S.count('WA')))
print('TLE x {}'.format(S.count('TLE')))
print('RE x {}'.format(S.count('RE')))

Measured memory_bytes: 16176
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<string> v[11];

void dfs(string s) {
  if (s[0] != '0') {
    v[s.length()].push_back(s);
  }
  if (s.length() == 10) {
    return;
  }
  for (int i = 0; i <= 9; i++) {
    if (s[0] - '0' - i >= -1 && s[0] - '0' - i <= 1) {
      char c = ('0' + i);
      dfs(c + s);
    }
  }
}

int main() {
  int k;
  scanf("%d", &k);
  dfs("1");
  dfs("2");
  dfs("3");
  dfs("4");
  dfs("5");
  dfs("6");
  dfs("7");
  dfs("8");
  dfs("9");
  dfs("0");
  for (int i = 1; i <= 10; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i = 1; i <= 10; i++) {
    if (k <= v[i].size()) {
      cout << v[i][k - 1] << endl;
      return 0;
    } else {
      k -= v[i].size();
    }
  }
  for (int i = 0; i < v[2].size(); i++) {
    cout << v[2][i] << endl;
  }
}

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

int f(int x){
	return x*x;
}

int main(void){
	int dx;
	while(cin>>dx){
		int sum=0;
		for(int i=1;i*dx<600;i++){
			sum+=dx*f(i*dx);
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 3096
import collections
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
 
    
    

N = rri()
arr = rrm()
dic = collections.Counter(arr)
s = sum(arr)
q = rri()
for _ in range(q):
    a, b= rrm()
    s+=dic[a]*(b-a)
    dic[b]+=dic[a]
    del dic[a]
    print(s)

Measured memory_bytes: 101580
#https://onlinejudge.u-aizu.ac.jp/solutions/problem/DSL_1_B/review/3161450/jakenu0x5e/Python3

import sys
readline = sys.stdin.readline
write = sys.stdout.write

n,m = map(int, readline().split())
*p, = range(n+1)
data = [0]*(n+1)

def root(x):
    if x == p[x]:
        return x
    r = p[x]
    p[x] = y = root(r)
    data[x] += data[r]

    return y
    
def unite(x, y, z):
    px = root(x); py = root(y)
    if px == py:
        return 0
    if px < py:
        p[py] = px
        data[py] = data[x] - data[y] + z
    else:
        p[px] = py
        data[px] = data[y] - data[x] - z
    return 1


ans = []

for i in range(m):
    li,ri,di = map(int, readline().split())
    pl = root(li); pr = root(ri)
    if pl == pr:
        if data[ri] - data[li] != di:
            print("No")
            exit()
    else:
        unite(li,ri,di)
#print(data)        
print("Yes")


Measured memory_bytes: 92348
# -*- coding: utf-8 -*-
s = input()
abcd = [c for c in s]

OP = ["+", "-"]

for op1 in OP:
    for op2 in OP:
        for op3 in OP:
            fomula_tmp = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]
            if eval(fomula_tmp) == 7:
                print(fomula_tmp + "=7")
                exit()


Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

// multi-dimensional vector (require c++14)
template <typename T, typename U>
static inline vector<U> make_nd_vector(T &&n, U &&val) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
static inline decltype(auto) make_nd_vector(T &&n, Args &&... args) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<decltype(make_nd_vector(forward<Args>(args)...))>(
      forward<T>(n), make_nd_vector(forward<Args>(args)...));
}
//
// Print from Iterator
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
//
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  string s;
  cin >> s;
  if (s == "ABC")
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
}


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


bool is_palindrome(const string& S){
  int N = S.size();
  for(int ii=0; ii<N/2; ii++){
    if(S[ii]!=S[N-1-ii]) return false;
  }
  return true;
}


int main(){
  string S;
  cin >> S;
  int N = S.size();
  if(
    is_palindrome(S) &&
    is_palindrome(S.substr(0, (N-1)/2)) &&
    is_palindrome(S.substr((N+1)/2))
  ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll x;
    cin >> x;
    PR(MIN(2*((x+10)/11),2*((x+4)/11)+1)); 

    return 0;
}

/*



*/

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){

  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int K = in(),X = in();
    REP(i,2*K-1)cout << X-K+i+1 << "\n";
}

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    string S,T; cin >> S;
    if(S=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;

    return 0;
}


Measured memory_bytes: 3572
#!/usr/bin/env python3
import sys
import math

def euclid_distance(x1,x2):
    dist = 0
    for i in range(len(x1)):
        dist += (x1[i] - x2[i])**2
    return dist

def LI():
  return [int(s) for s in input().split()]

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    cnt = 0
    N,D = LI()
    X = []
    for i in range(N):
        X.append(LI())


    for i in range(N-1):
        for j in range(i+1,N):
            dist = euclid_distance(X[i],X[j])
            for num in range(150):
                if int(dist) == (num**2):
                    cnt += 1
                    continue
    print(cnt)
                
if __name__ == '__main__':
    main()


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

int main() {
  string s;
  cin >> s;
  vector<int> v;
  for(int i=0; i<s.size(); i++) {
    if(s[i]=='e') {
      v.push_back(0);
      i+=2;
    } else {
      v.push_back(1);
      i+=6;
    }
  }
  vector<vector<int> > a;
  vector<int> b;
  b.push_back(v[0]);
  for(int i=1; i<v.size(); i++) {
    if(v[i-1]==v[i]) {
      a.push_back(b);
      b.clear();
    }
    b.push_back(v[i]);
  }
  a.push_back(b);
  int x=0,y=0;
  for(int i=0; i<a.size(); i++) {
    if(a[i].size()>x) {
      x=a[i].size();
      y=a[i][a[i].size()-1];
    }
  }
  if(!y) cout << "egg" << endl;
  else cout << "chicken" << endl;
  return 0;
}


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

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2];
int R[MAX / 2 + 2];

// mergeして増えた分の反転数を返す
llong merge(int A[], int n, int left, int mid, int right) {
    int i, j, k;
    llong cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++) L[i] = A[left + i];
    for (i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = SENTINEL;
    R[n2] = SENTINEL;
    i = 0; j = 0;
    for (k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
            cnt += n1 - i;
        }
    }
    return cnt;
}

llong mergeSort(int A[], int n, int left, int right) {
    int mid;
    llong v1, v2, v3;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        v1 = mergeSort(A, n, left, mid);
        v2 = mergeSort(A, n, mid, right);
        v3 = merge(A, n, left, mid, right);
        return v1 + v2 + v3;
    } else {
        return 0;
    }
}

int main() {
    int A[MAX];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    llong ans = mergeSort(A, n, 0, n);
    cout << ans << endl;
    return 0;
}



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

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static object Solve(Scanner scan) {
        double A = scan.NextDouble(), B = scan.NextDouble();
        var max = 101 * 10 - 1;
        var min = (int) B * 10;
        for (int i = min; i <= max; i++) {
            if (Math.Floor(i * 0.08) == A && Math.Floor(i * 0.1) == B) return i;
        }
        return -1;
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public long NextLong() => long.Parse(Next());
    public double NextDouble() => double.Parse(Next());
    public int[] ArrayInt(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) {
            array[i] = NextInt() + add;
        }
        return array;
    }
    public long[] ArrayLong(int len, long add = 0) {
        var array = new long[len];
        for (int i = 0; i < len; i++) {
            array[i] = NextLong() + add;
        }
        return array;
    }
    public double[] ArrayDouble(int len, double add = 0) {
        var array = new double[len];
        for (int i = 0; i < len; i++) {
            array[i] = NextDouble() + add;
        }
        return array;
    }
}

Measured memory_bytes: 27568
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long N, std::vector<long long> H){
  int maxN = 0;
  int cnt = 0;
  REP(x, N) {
    if (maxN <= H.at(x)) {
      maxN = H.at(x);
      cnt++;
    }
  }
  cout << cnt << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> H(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&H[i]);
  }
  solve(N, std::move(H));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200000+10;

char s[N];
int ans[N];

int main()
{
    scanf("%s",s);
    int len=strlen(s);
    int p1,p2,p3,p4;
    p1=0;
    p2=0;
    while(p4!=len-1)
    {
        while(s[p2+1]=='R')
            ++p2;
        p3=p4=p2+1;
        while(s[p4+1]=='L')
            ++p4;

        int n1=p2-p1+1;
        int n2=p4-p3+1;

        ans[p2]+=min(n1,n2);
        ans[p3]+=min(n1,n2);

        if(n1>n2)
        {
            n1-=n2;
            ans[p2]+=n1/2;
            ans[p3]+=n1/2;
            if(n1&1)
            {
                if((p2-p1)&1)
                    ++ans[p3];
                else ++ans[p2];
            }

        }
        else if(n2>n1)
        {
            n2-=n1;
            ans[p2]+=n2/2;
            ans[p3]+=n2/2;
            if(n2&1)
            {
                if((p4-p3)&1)
                    ++ans[p2];
                else ++ans[p3];
            }
        }
        p1=p2=p4+1;
    }
    for(int i=0; i<len; ++i)
        printf("%d ",ans[i]);
    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using namespace std;

int main() {
    int n,m;
    cin >> n;
    vector<int>a;
    vector<int>b;
    vector<int>c;
    for (int i=0;i<n;i++) {
        cin>>m;
        a.push_back(m);
    }
    vector<int>ans;
    for (int i=0;i<n;i++) {
        if (i%2==1) {
            b.push_back(a[i]);
        }
        else {
            c.push_back(a[i]);
        }
    }
    if (n%2==0) {
        reverse(b.begin(),b.end());

        // b.insert(b.end(),c.begin(),c.end());
        // size_t w = size(b);
        for (int i=0;i<b.size();i++) {
            cout<<b[i]<<" ";
        }
        for (int i=0;i<c.size();i++) {
            cout << c[i] << " ";
        }
        return 0;
    }
    else {
        reverse(c.begin(),c.end());
        for (int i=0;i<c.size();i++) {
            cout << c[i] << " ";
        }
        for (int i=0;i<b.size();i++) {
            cout << b[i] << " ";
        }
        return 0;
        
        // cout << " " << endl;
        // for (int i=0;i<c.size();i++) {
        //     cout << c[i] << " ";
        // }
        // c.insert(c.end(),b.begin(),b.end());
        // size_t w = size(c);
        // for (int i=0;i<c.size();i++) {
        //     cout << c[i] << " ";
        //     return 0;
        // }
        // for (int i=0;i<b.size();i++) {
        //     cout << b[i] << " ";
        //     return 0;
        // }
    }
    return 0;
}

Measured memory_bytes: 4212
char*p1,*p2,t1[301],t2[301];
d;
S(q){
	char*p=q,h=0;
	for(;h+=*p==40;p++)
		h-=*p==41,d&&putchar(*p);
	return p;
}
R(){
	if(*p1==40&&*p2==40){
		putchar(*p1++);
		R(p2++);
		putchar(*p1++);
		R(p2++);
		putchar(*p1++);
		p2++;
	}else{
		p1=S(p1);
		p2=S(p2);
	}
}
main(){
	for(;~scanf("%s%s%s",&d,p1=t1,p2=t2);puts(""))
		R(d&=4);
}

Measured memory_bytes: 0
from collections import Counter
H, W = map(int, input().split())
a = ''
for _ in range(H):
    a += input()
cnt_counter = list(Counter(a).values())
yes_flag = False
if H % 2 == 0 and W % 2 == 0:
    if all([i % 4 == 0 for i in cnt_counter]):
        yes_flag = True
elif H % 2 == 1 and W % 2 == 1:
    two_cnt = (H // 2) + (W // 2)
    four_cnt = (H // 2) * (W // 2)
    for i in range(len(cnt_counter)):
        if cnt_counter[i] % 2 == 1:
            cnt_counter[i] -= 1
            break
    else:
        print('No')
        exit()
    for i in range(len(cnt_counter)):
        if cnt_counter[i] <= 0:
            continue
        if cnt_counter[i] % 2 == 0 and cnt_counter[i] % 4 != 0:
            two_cnt -= 1
            cnt_counter[i] -= 2
        if two_cnt == 0:
            break
    for i in range(len(cnt_counter)):
        if cnt_counter[i] <= 0:
            continue
        if cnt_counter[i] % 4 != 0:
            break
        while two_cnt > 1 and cnt_counter[i]:
            two_cnt -= 2
            cnt_counter[i] -= 4
        while four_cnt > 0 and cnt_counter[i]:
            four_cnt -= 1
            cnt_counter[i] -= 4
    if two_cnt == four_cnt == 0:
        yes_flag = True
else:
    if H % 2 == 0:
        two_cnt = H // 2
    else:
        two_cnt = W // 2
    four_cnt = (H // 2) * (W // 2)
    for i in range(len(cnt_counter)):
        if cnt_counter[i] % 2 == 0 and cnt_counter[i] % 4 != 0:
            two_cnt -= 1
            cnt_counter[i] -= 2
        if two_cnt == 0:
            break
    for i in range(len(cnt_counter)):
        if cnt_counter[i] <= 0:
            continue
        if cnt_counter[i] % 4 != 0:
            break
        while two_cnt > 1 and cnt_counter[i]:
            two_cnt -= 2
            cnt_counter[i] -= 4
        while four_cnt > 0 and cnt_counter[i]:
            four_cnt -= 1
            cnt_counter[i] -= 4
    if two_cnt == four_cnt == 0:
        yes_flag = True
if yes_flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9492
module Main where

import Control.Applicative
import Text.Printf

main :: IO ()
main = do
  { [a,b,c] <- getInts
  ; print (count 0 a b c)
  }

count :: Int -> Int -> Int -> Int -> Int
count n x y z
  | x > y          = n
  | z `mod` x == 0 = count (n+1) (x+1) y z
  | otherwise      = count n     (x+1) y z

--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show



Measured memory_bytes: 4148
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<vector>
#define ll long long
#define mt(a) memset(a,0,sizeof(a))
#define MAXI 2000000000
#define PAI pair<int,int>

using namespace std;

ll a[200009], dp[200009];
int main()
{
	int n,k;
	scanf("%d%d", &n,&k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]);
		dp[i] = MAXI;
	}
	dp[1] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= min(n, i + k); j++)
			dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
	}
	printf("%lld\n", dp[n]);


	return 0;
}

Measured memory_bytes: 1792
N,D=map(int,input().split())
z=[]
for i in range(N):
    x=list(map(int,input().split()))
    z.append(x)
def judge_dis(K,L):
    d=0
    for k,l in zip(K,L):
        d+=(k-l)**2
    import math
    d=math.sqrt(d)
    return d.is_integer()
ans=0
for x in range(N-1):
    for i in range(x+1,N):
        if judge_dis(z[x],z[i]):
            ans+=1
print(ans)


Measured memory_bytes: 9144
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main() {
  int x1,x2,y1,y2;
  cin>> x1>>y1>>x2>>y2;

  cout<<x2-(y2-y1)<<" "<<y2+(x2-x1)<<" "<<x1-(y2-y1)<<" "<<y1+(x2-x1)<<endl;
}


Measured memory_bytes: 256
def f2(n):
    c = len(n)-1
    nn = n[1:]
    s = c*(c-1)//2 * 9*9 
    s += c * (int(n[0])-1)*9
    nn = str(int(nn))
    s += (len(nn)-1)*9 + int(nn[0])
    return s

n = input()
k = int(input())

if k == 1:
    print((len(n)-1)*9 + int(n[0]))
if k == 2:
    if len(n) >= 2:
        print(f2(n))
    else:
        print(0)
        
if k == 3:
    if len(n) >= 3:
        c = len(n)-1
        nn = n[1:]
        nn = str(int(nn))
        s = c*(c-1)*(c-2)//(3*2) * 9*9*9
        s += (int(n[0])-1) * c*(c-1)//2 * 9*9 
        if len(nn) >= 2:
            s += f2(nn)
        print(s)
    else:
        print(0)

Measured memory_bytes: 3064
#include <cassert>
#include <numeric>
#include <random>
#include <vector>
#include <iostream>
using namespace std;

vector<int> solve(int n, vector<int> *adj) {
    if (n == 2) return {1, 2};
    if (n == 3) return {1, 2, 3};
    vector<int> d(n, 0), d1(n, 0);
    for (int i = 0; i < n; i++) d[i] = adj[i].size();
    for (int i = 0; i < n; i++)
        for (int j : adj[i])
            if (d[j] == 1) d1[i]++;
    vector<bool> f(n);
    vector<int> es;
    for (int i = 0; i < n; i++) {
        if (d[i] == 1) continue;
        switch (d[i] - d1[i]) {
        case 0: continue;
        case 1: es.push_back(i);
        case 2: f[i] = true; break;
        default:
            cout << "-1\n";
            return {};
        }
    }
    if (es.empty()) {
        // star
        vector<int> ans;
        for (int i = 1; i < n; i++) if (i != 2) ans.push_back(i);
        ans.push_back(2);
        ans.push_back(n);
        return ans;
    }
    vector<int> path;
    // cerr << "es "; for (int d : es) cerr << d << " "; cerr << endl;
    for (int i : es) {
        vector<int> degs;
        vector<bool> visited(n, false);
        for (;;) {
            visited[i] = true;
            degs.push_back(d[i]);
            bool found = false;
            for (int k : adj[i]) {
                if (f[k] && !visited[k]) {
                    i = k;
                    found = true;
                    break;
                }
            }
            if (!found) break;
        }
        if (path.empty() || degs < path) path.swap(degs);
    }
    // for (int d : path) cerr << d << " "; cerr << endl;
    vector<int> ans;
    ans.push_back(1);
    for (int i = 2, j = 0; j < path.size(); j++) {
        for (int k = 0; k < path[j] - 2; k++) {
            ans.push_back(i+k+1);
        }
        ans.push_back(i);
        i += path[j] - 1;
    }
    ans.push_back(n);
    return ans;
}

int main() {
    int n; cin >> n;
    vector<int> adj[n];
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        adj[u-1].push_back(v-1);
        adj[v-1].push_back(u-1);
    }

    vector<int> ans = solve(n, adj);
    for (int x : ans) cout << x << " "; cout << endl;
}


Measured memory_bytes: 10260
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n,k;
ll a[MAX];
ll dp[MAX];
int main(){FAST;
cin>>n>>k;
for(ll i=1;i<=n;++i)cin>>a[i];
dp[1] = 0;
for(ll i=2;i<=n;++i){
  dp[i] = INF;
  for(ll j=1;j<=k;++j){
    if(i-j<1)break;
    dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
  }
}
cout<<dp[n];
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 5164
import java.util.Scanner;

public class Main {
    static int A;
    static int B;
    static int C;
    static int minCost = Integer.MAX_VALUE;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        dfs(arr, 0, 0, 0, 0, 0);
        System.out.println(minCost);
    }

    static void dfs(int[] arr, int idx, int currCost, int a, int b, int c) {
        if (idx == arr.length) {
            if (a == 0 || b == 0 || c == 0) return;
            currCost += Math.abs(A-a) + Math.abs(B-b) + Math.abs(C-c) - 30;
            minCost = Math.min(minCost, currCost);
            return;
        }
        dfs(arr, idx+1, currCost+10, a + arr[idx], b, c);
        dfs(arr, idx+1, currCost+10, a, b + arr[idx], c);
        dfs(arr, idx+1, currCost+10, a, b, c + arr[idx]);
        dfs(arr, idx+1, currCost, a, b, c);
    }
}

Measured memory_bytes: 22228
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($y = 0; $y < $H; $y++){
    fscanf(STDIN, "%s", $str);
    $map[$y] = str_split($str);
    for($x = 0; $x < $W; $x++){
        if($map[$y][$x] == "#"){
            $list[$y][$x] = 1;
        }
    }
}
$count = 0;
while($list){
    $nextList = [];
    foreach($list as $y => $xs)foreach($xs as $x => $_){
        if($x && $map[$y][$x-1] == ".")$nextList[$y][$x-1] = $map[$y][$x-1] = 1;
        if($y && $map[$y-1][$x] == ".")$nextList[$y-1][$x] = $map[$y-1][$x] = 1;
        if($x < $W-1 && $map[$y][$x+1] == ".")$nextList[$y][$x+1] = $map[$y][$x+1] = 1;
        if($y < $H-1 && $map[$y+1][$x] == ".")$nextList[$y+1][$x] = $map[$y+1][$x] = 1;
    }
    $list = $nextList;
    if($list)$count++;
}
echo $count;


Measured memory_bytes: 123384
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int const MAXN=110000;
int v;
vector<pair<int,int>> g[MAXN];
int sol[MAXN];
void color(int node=1, int parent=0){
	for(auto near:g[node])
		if(near.first!=parent){
			sol[near.first]=(near.second%2==0?sol[node]:1-sol[node]);
			color(near.first,node);
		}
}
int main(){	
	cin>>v;
	for(int i=0;i<v-1;i++){
		int f, t, w;
		cin>>f>>t>>w;
		g[f].push_back({t,w});
		g[t].push_back({f,w});
	}
	color();
	for(int i=1;i<=v;i++)
		cout<<sol[i]<<"\n";
}

Measured memory_bytes: 7808
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>
using namespace std;

int main() {
	int N;
	string S;

	cin >> N;
	cin >> S;

	int count_b = 0, count_w = 0;

	for (int i = 0; i < N; i++) {
		if (S[i] == '#')
			count_b++;
		else
			count_w++;
	}

	vector<int> change(N+1, 0);

	change[0] = count_w;//変えるべき数

	for (int i = 1; i <= N; i++) {
		if (S[i-1] == '.')
			change[i] = change[i - 1] - 1;
		else
			change[i] = change[i - 1] + 1;
	}

	int min = change[0];

	for (int i = 1; i <= N; i++) {
		if (change[i] < min) {
			min = change[i];
		}
	}

	cout << min << endl;

}



Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int m, n;
    cin >> m >> n;
    if (abs(m - n) > 1) {
        cout << 0 << endl;
        return 0;
    }
    
    lint ret = 1;
    const lint MOD = 1e9 + 7;
    
    repeat_from_to(i, 1, m) (ret *= i) %= MOD;
    repeat_from_to(i, 1, n) (ret *= i) %= MOD;
    
    if (abs(m - n) == 0) {
        (ret *= 2) %= MOD;
    }
    cout << ret << endl;
    return 0;
}   

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
int main()
{
    int n[3];
    std::cin >> n[0] >> n[1] >> n[2];
    
    for(int i=0;i<3;i++)
        for(int j=2;j>i;j--)
            if(n[i] > n[j])
            {
                int temp = n[i];
                n[i] = n[j];
                n[j] = temp;
            }
    
    std::cout << n[0] << " " << n[1] << " " << n[2] << std::endl;
}


Measured memory_bytes: 3100
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007


#define MAXN 200000
long long inv[MAXN + 1];//MODを法とする乗法の逆元
long long fact[MAXN + 1];//階乗
long long ifact[MAXN + 1];//階乗の逆元
void init() {
	inv[1] = 1;
	for (int i = 2; i <= MAXN; i++) inv[i] = inv[MOD%i] * (MOD - MOD / i) % MOD;
	fact[0] = ifact[0] = 1;
	for (int i = 1; i <= MAXN; i++) {
		fact[i] = i * fact[i - 1] % MOD;
		ifact[i] = ifact[i - 1] * inv[i] % MOD;
	}
}
long long C(int n, int r) {
	if (n < 0 || r < 0 || r > n)return 0;
	if (r > n / 2)r = n - r;
	return fact[n] * ifact[n - r] % MOD*ifact[r] % MOD;
}



int h, w, n;
pair<int, int> rc[3000];

int dp[3000];

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

	init();

	cin >> h >> w >> n;
	rep(i, n)cin >> rc[i].first >> rc[i].second;
	rep(i, n) {
		rc[i].first--;
		rc[i].second--;
	}
	sort(rc, rc + n);

	int ans = C(h + w - 2, h - 1);

	rep(i,n) {
		int a = C(rc[i].first + rc[i].second, rc[i].first);
		rep(j, i) if(rc[j].first <= rc[i].first && rc[j].second <= rc[i].second){
			a -= dp[j] * C(rc[i].first - rc[j].first + rc[i].second - rc[j].second, rc[i].first - rc[j].first) % MOD;
			a %= MOD;
		}
		dp[i] = (a%MOD + MOD) % MOD;
	}

	rep(i,n) {
		ans -= (long long)dp[i] * C(h + w - 2 - rc[i].first - rc[i].second, h - 1 - rc[i].first) % MOD;
		ans = (ans%MOD + MOD) % MOD;
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int n;
int l[10];
int a, b, c;
int aans = 1e9;

void cnt(vector<int> v){
    int A=0, B=0, C=0;
    int aa=0,bb=0,cc=0;
    for(int i=0; i<v.size(); i++){
        if(v[i]==0) continue;
        if(v[i]==1) {
            A+=l[i];
            aa++;
        }
        if(v[i]==2){
            B+=l[i];
            bb++;
        } 
        if(v[i]==3) {
            C+=l[i];
            cc++;
        }
    }
    if(A==0 || B==0 || C == 0) return;
    int ans = abs(A-a) + abs(B-b) + abs(C-c) + (aa+bb+cc-3)*10;
    aans = min(ans, aans);
}

void dfs(int depth, vector<int> v){
    if(depth == n) {
        cnt(v);
        return;
    }
    for(int i=0; i<4; i++){
        v[depth] = i;
        dfs(depth+1, v);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>a>>b>>c;
    rep(i, n){
        cin >> l[i];
    }
    vector<int> tmp(n+10, 0);
    dfs(0,tmp);
    // dfsして状態全列挙
    cout<<aans<<endl;

}

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

int main() {
  
  int n;
  cin >> n;
  
  int ans = 1;
  
  vector<string> s(n);
  for(int i = 0; i < n; i++) cin >> s[i];
  
  sort(s.begin(), s.end());
  for(int i = 1; i < n; i++){
    if(s[i-1] != s[i]) ans++;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 9528
$%=<>;
@c=(0,2,5,5,4,5,6,3,7,6)[@a=sort{$a-$b}glob<>];
$M=-//,map($M+=$-=($'<$_?-9:$p[$'-$_]+1)-$M,@c),$p[$']=$M for 1..$%;
$i=(grep$p[$#_=$%-$c[$_]]+1==$p[$%],0..$#a)[-1],$%-=$c[$i],print$a[$i]while$%

Measured memory_bytes: 1280
loop do
  h, w = gets.split.map(&:to_i)
  break if h.zero? && w.zero?

  h.times do |i|
    if i.zero? || i == h - 1
      puts '#' * w
    else
      puts '#' + ('.' * (w - 2)) + '#'
    end
  end
  puts
end

Measured memory_bytes: 8860
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		if (n % 2 == 0) {
			System.out.println(n / 2);
		}

		if ( n % 2 == 1) {
			System.out.println(n / 2 + 1);
		}

	}

}

Measured memory_bytes: 35496