akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
using namespace std;
string s;
int n,ans=1e9;
int a[200004];
int main(){
	cin>>n>>s;
	for (int i=0;i<n;i++)
		a[i+1]+=a[i]+(s[i]=='#'?1:0);
	for (int i=0;i<=n;i++)
		ans=min(ans,a[i]+(n-i)-(a[n]-a[i]));
	cout<<ans;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vi h(n);
    REP(i,0,n){
        cin>>h[i];
    }
    vi maxi(n);
    vi mini(n);
    maxi[0]=h[0];
    for(int i=1;i<n;i++){
        maxi[i]=max(h[i],maxi[i-1]);
    }
    mini[n-1]=h[n-1];
    for(int i=n-2;i>=0;i--){
        mini[i]=min(h[i],mini[i+1]);
    }
    // deb(maxi);
    // deb(mini);
    int f=1;
    for(int i=0;i<(n-1);i++){
        if((maxi[i]-mini[i+1])>1){
            f=0;
        }
    }
    if(f==1){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }



    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int r;

	cin >> r;
	
	
  	
  	int ans = 3 * pow(r,2);
  	
   	cout << ans << endl;
  	
 	return 0;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};




int main(){
    LL n;cin >> n;
    LL ans = 0;
    map<P,int> m;
    for (int i = 1; i <= n; i++) {
        int t = i;
        int a, b = i % 10;
        while(t){
            a = t % 10;
            t /= 10;
        }
        m[mp(a,b)]++;
    }
    for (int i = 1; i <= n; i++) {
        int t = i;
        int a, b = i % 10;
        while(t){
            a = t % 10;
            t /= 10;
        }
        ans += m[mp(b,a)];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
v[4]={10,50,100,500},a[4],r[4];main(N,c,m,i){
	for(N=0;scanf("%d",&c),c;N++){
		if(N)puts("");
		scanf("%d%d%d%d",a,a+1,a+2,a+3);
		for(m=i=0;i<4;i++)m+=a[i]*v[i];
		m-=c;
		r[3]=m/500,r[2]=m%500/100,r[1]=m%100/50,r[0]=m%50/10;
		for(i=0;i<4;i++)if((a[i]-=r[i])>0)printf("%d %d\n",v[i],a[i]);
	}
	return 0;
}

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

using namespace std;

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N, T;
  cin >> N >> T;
  vector<pair<int, int>> AB(N);
  for (int i = 0; i < N; i++) {
    cin >> AB[i].first >> AB[i].second;
  }
  sort(AB.begin(), AB.end());
  vector<int> dp(T + 1, 0);

  for (auto& p : AB) {
    for (int k = T - 1; 0 <= k; k--) {
      chmax(dp[min(T, k + p.first)], dp[k] + p.second);
    }
  }

  cout << dp.back() << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input());
    a1 = list(map(int, input().split()))
    a2 = list(map(int, input().split()))

    maximum = 0
    for i in range(n):
        score = sum(a1[0:i+1]) + sum(a2[i:n])
        if score > maximum:
            maximum = score

    print(maximum)
    return


if __name__ == '__main__':
    main()


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


i64 N;

int main() {
    cin >> N;

    cout << N / 2 + (N % 2 > 0) << endl;

    return 0;
}

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

int a[100];
int main() {
    int n;
    long long sum = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            sum += a[i] * a[j];
        }
    }

    cout << sum << endl;

    return 0;
}//
// Created by Kevin Weng on 2019/10/28.
//



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,a[100001],b[100001];
  ll ans=0;
  cin >> N;
  REP(i,N)cin >> a[i];
  deque<int> que,cons;
  sort(a,a+N);
  REP(i,N)que.push_back(a[i]);
  bool f=0;
  if(!que.empty()){
    int d = que.back();que.pop_back();
    cons.push_front(d);
  }
  REP(i,N){
    while(!que.empty()){
      if(f==0){
        if(!que.empty()){
          int d = que.front();que.pop_front();
          cons.push_front(d);
        }
        if(!que.empty()){
          int d = que.front();que.pop_front();
          cons.push_back(d);
        }
        f=1;
      }else{
        if(!que.empty()){
          int d = que.back();que.pop_back();
          cons.push_front(d);
        }
        if(!que.empty()){
          int d = que.back();que.pop_back();
          cons.push_back(d);
        }
        f = 0;
      }

    }
  }
  ll res=0,d=0;
  while(!cons.empty()){
    b[d++] = cons.front();cons.pop_front();
  }
  REP(i,N-1){
  
    res += abs(b[i+1] - b[i]);
  }
  ans = res;
  REP(i,N)que.push_back(a[i]);
  f=1;
  if(!que.empty()){
    int d = que.front();que.pop_front();
    cons.push_front(d);
  }
  REP(i,N){
    while(!que.empty()){
      if(f==0){
        if(!que.empty()){
          int d = que.front();que.pop_front();
          cons.push_front(d);
        }
        if(!que.empty()){
          int d = que.front();que.pop_front();
          cons.push_back(d);
        }
        f=1;
      }else{
        if(!que.empty()){
          int d = que.back();que.pop_back();
          cons.push_front(d);
        }
        if(!que.empty()){
          int d = que.back();que.pop_back();
          cons.push_back(d);
        }
        f = 0;
      }

    }
  }
  d = 0;
  while(!cons.empty()){
    b[d++] = cons.front();cons.pop_front();
  }
  res = 0;
  REP(i,N-1){
    res += abs(b[i+1] - b[i]);
  }
  ans = max(res,ans);
  cout << ans << endl;
  return 0;
}



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

int main() {
  int N, A, tmp = 0, ans = 0;
  cin >> N >> A;

  while (A % 2 == 0){
    ans += 1;
    A /= 2;
  }

  for (int i = 0; i < N - 1; i++){
    cin >> A;

    while (A % 2 == 0){
      tmp += 1;
      A /= 2;
    }

    ans = min(ans, tmp);
    tmp = 0;
  }

  cout << ans << endl;
}


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

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

    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            if (i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 15
#define int long long
using namespace std;

int n,m,ans=2e9;
int p[N],c[N];

int work(int s)
{
	int sum=0,ok=0,now=0;
	for(int i=1;i<=n;i++)
		if((s>>i-1)&1)
			sum+=p[i]*i*100+c[i],ok++,now+=p[i];
	if(sum>=m) return now;
	int t=2e9;
	for(int i=1;i<=n;i++)
		if(((s>>i-1)&1)==0 and sum+p[i]*i*100>=m)
			t=min(t,(int)ceil(1.0*(m-sum)/(i*100)));
	return now+t;
}

signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>p[i]>>c[i];	
	for(int i=0;i<(1<<n);i++)
		ans=min(ans,work(i));
	cout<<ans;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

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

int [] b;

bool h (int [] a, int n) {
  int p = a.reduce! ( (a, b) => a * b);
  auto c = iota (2, 29999).filter! (i => a.any! (j => (i % j) == 0)).array;
 
  b[0 .. n - 2] = c[0 .. n - 2];
  int s = b.sum;
  bool find = false;
  int gg = b[0 .. n - 2].reduce! ((x, y) => gcd (x, y));
  foreach (i; n - 2 .. c.length.to!(int)) {
    int u = ((s + c[i] + p - 1) / p) * p;
    int t = u - (s + c[i]);
    //if (t != u && b[0 .. n-2].find(t).empty && t > 1 && t < 30000 && gcd (gcd (gg, c[i]), t) == 1 && gcd (t, (s + c[i])) != 1 && !a.all! (j => (t % j) == 0)) {
    //debug {stderr.writeln(t);}
    if (t != u && b[0 .. n-2].assumeSorted.equalRange(t).empty && t > 1 && t < 30000 && gcd (gcd (gg, c[i]), t) == 1 && gcd (t, (s + c[i])) != 1) {
      b[n-2] = c[i];
      b[n-1] = t;
      return true;
    }
  }
  return false;
}


void main() {
  int n;
  readf (" %d", &n);
  b = new int[n];
 
  bool found = false;
  foreach (t; [ [2, 3, 5, 7, 11, 13], [2, 3, 5, 7, 11, 17], [2, 3, 5, 7, 11, 19], [2, 3, 5, 7, 11, 23], [2, 3, 5, 7, 11, 29],
                [2, 3, 5, 7, 13, 17], 
                [2, 3, 5, 7, 13, 19], 
                [2, 3, 5, 7, 13, 23], 
                [2, 3, 5, 7, 13, 23], 
                [2, 3, 5, 7, 17, 19], 
                [2, 3, 5, 7, 17, 23], 
                [2, 3, 5, 7, 19, 23]]
           ) {
    
    if (h (t, n)) {
      found = true;
      break;
    }
  }

  assert (found);
  int s = b.sum;
  foreach (i; 0 .. n) {
    assert (gcd (b[i], s - b[i]) > 1);
  }
  //debug { stderr.writeln (b); }
  assert (b.reduce! ((x, y) => gcd (x, y)) == 1);
  assert (b.reduce! (min) >= 1);
  assert (b.reduce! (max) < 30000);

  /*
  while (k < n - 1) {
    if (a.any! (j => (i % j) == 0)) {
      b[k++] = i;
      i++;
    } else {
      i++;
    }
  }
  b[n-1] = p - a[0 .. n - 1].sum;
  */
  b.map! (i => i.text).join(" ").writeln;
}


Measured memory_bytes: 3068
n, m = map(int, input().split())

dp = [0] * (n + 1)
broken = [0] * (n + 1)

for _ in range(m):
    broken[int(input())] = 1

dp[0] = 1

if broken[1] == 1:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n+1):
    if broken[i] == 1:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[n])

Measured memory_bytes: 7668
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#define NMAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n";
#define scan(arg) cin>>arg;
using namespace std;
int n;
int a[NMAX];
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	scan(n);
	rep(i,n) scan(a[i]);
	int res=a[0];
	rep1(i,n-1){
		res=gcd(res,a[i]);
	}
	prin(res);
	
	return 0;
}


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

int di(int f) {
	if (f == 0) return 0;
	return f % 10 + di(f / 10);
}

int main() {
    
    int n;
    cin >> n;
    if (n % di(n)) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
    
}


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

typedef long long LL;

const string temp = "AKIHABARA";

int vis[26];

int main() {
   // freopen("in.txt", "r", stdin);
    string s;
    cin >> s;
    int n = s.length(), m = 0;
    for (int i = 0; i < n; i++) {
        vis[s[i] - 'a'] ++;
        m = max(m, vis[s[i] - 'a']);
    }
    puts((m - 1) * 3 + 1 <= n ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a+b==15)cout<<"+"<<endl;
    else if(a*b==15)cout<<"*"<<endl;
    else cout<<"x"<<endl;
    return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
  public static String s = "";
  public static int n = 0;

  public static long dfs(int count, String ss) {
    if (count == n) {
      String[] ss_split = ss.split("\\+");
      long sum = 0;
      for (int i = 0; i < ss_split.length; i++) {
        sum += Long.parseLong(ss_split[i]);
      }
      return sum;
    }
    return dfs(count + 1, ss.replaceFirst(" ", "+")) + dfs(count + 1, ss.replaceFirst(" ", ""));
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    s = sc.next();
    n = s.length() - 1;
    String s_space = "";
    for (int i = 0; i < s.length() * 2 - 1; i++) {
      if (i % 2 == 1) {
        s_space += " ";
      } else {
        s_space += s.charAt(i / 2);
      }
    }
    System.out.println(dfs(0, s_space));
  }
}


Measured memory_bytes: 25680
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

struct uf
{
	vector<INT> p;

	uf(INT n) : p(n)
	{
		for (size_t i = 0; i < n; i++)
		{
			p[i] = i;
		}
	}

	INT rt(INT n)
	{
		return p[n] == n ? n : p[n] = rt(p[n]);
	}

	void un(INT n, INT m)
	{
		p[rt(n)] = p[rt(m)];
	}

	bool eq(INT n, INT m)
	{
		return rt(n) == rt(m);
	}
};

int main()
{
	int n;
	cin >> n;
	for (size_t i = 1; i <= 9; i++)
	{
		if (n % i == 0 && n / i <= 9)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan =new Scanner(System.in);
    		String x=scan.next();
    		if (x.equals("5")||x.equals("7")||x.equals("3")) {
    			System.out.print("YES");
    		}else {
    			System.out.print("NO");
    		}
    }
    }
// end 

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


bool check(string s) {
  int dig = 0;
  for(auto itr : s) {
	dig += (itr - '0');
	dig %= 9;
	//	cout << dig << endl;
  }
  return dig % 9 == 0;
}


int main() {
  ll N;
  cin >> N;
  if(N%1000 == 0) cout << 0 << endl;
  else {
	cout << 1000 - N%1000 << endl;
  }

  return 0;
}



Measured memory_bytes: 3184
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>

#pragma warning(disable : 4996)

#define INF (1LL << 60)

using namespace std;

int main()
{
	int V, E, X, A, B, C;

	scanf("%d", &V);
	scanf("%d", &E);
	scanf("%d", &X);

	vector<long long> R(V);

	vector<vector<pair<int, long long> > > G(V);

	for (int i = 0; i < V; i++)
	{
		scanf("%lld", &R[i]);
	}

	for (int i = 0; i < E; i++)
	{
		scanf("%d", &A);
		scanf("%d", &B);
		scanf("%d", &C);

		G[A - 1].push_back(make_pair(B - 1, C));
		G[B - 1].push_back(make_pair(A - 1, C));
	}

	vector<long long> D(V, INF); D[0] = 0;
	vector<long long> F(V, INF); F[0] = X;

	queue<int> que; que.push(0); // node

	while (!que.empty())
	{
		int node = que.front(); que.pop();

		int high = F[node];

		for (int i = 0; i < G[node].size(); i++)
		{
			int went = G[node][i].first;
			int cost = G[node][i].second;

			if (R[node] >= cost)
			{
				if (high - cost <= 0)
				{
					long long t = D[node] + (cost - high) + cost; // high --> cost --> 0 meters

					if (t < D[went])
					{
						D[went] = t;
						F[went] = 0;
						
						que.push(went);
					}
				}
				else if(high - cost <= R[went])
				{
					long long t = D[node] + cost; // high --> high --> (high - cost) meters

					if (t < D[went])
					{
						D[went] = t;
						F[went] = high - cost;
						
						que.push(went);
					}
				}
				else
				{
					long long t = D[node] + high - R[went]; // high --> (R[went] + cost) --> R[went]

					if (t < D[went])
					{
						D[went] = t;
						F[went] = R[went];

						que.push(went);
					}
				}
			}
		}
	}

	printf("%lld\n", D[V - 1] != INF ? D[V - 1] + R[V - 1] - F[V - 1] : -1);

	return 0;
}

Measured memory_bytes: 23296
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
	if (!y)
		return x;
	return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

vector<string> split(char d,string s)
{
	stringstream ss(s);
	string t;
	vector<string> words;
	while(getline(ss,t,d))
	{
		words.pb(t);
	}

	return words;
}
VII lev(200006,0);
vector<VII> adj(200005);
void dfs(int u)
{
	for(auto it:adj[u])
	{
		dfs(it);
		lev[u]+=lev[it];
	}
	lev[u]++;
}
int main(int argc, char *argv[])
{
#ifdef LOCAL
	auto start = chrono::high_resolution_clock::now();
#endif
	
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	for(int i=2;i<=n;++i)
	{
		int x;
		cin>>x;
		adj[x].pb(i);
	}

	//dfs(1);
	for(int i=1;i<=n;++i)
	cout<<adj[i].size()<<'\n';



#ifdef LOCAL
	auto end = chrono::high_resolution_clock::now();
	double time_taken =
		chrono::duration_cast<chrono::nanoseconds>(end - start).count();

	time_taken *= 1e-9;

	cerr << "\nTime taken by program is : " << fixed
		 << time_taken << setprecision(9);
	cerr << " sec" << endl;
#endif
	return 0;
}

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

// i < j かつ A[i] < A[j] なるものをすべてつぶす
// A[j] - A[i] (i < j) の最大値の個数を数えればよい
// ともに最大値を与える添字の組 (i, j), (i', j') があったらその区間 [i, j], [i', j'] は共通部分を持たない
// i < j < i' < j' のとき，必ず A[i] >= A[i'], A[j] >= A[j']

int main(void) {
	using namespace std;
	int N, T;
	vector<int> A;
	cin >> N >> T;
	int nummax = 0;
	int valmax = 0;
	int maxA = 0, minA = 0;
	for(int i = 0; i < N; ++i) {
		int A;
		cin >> A;
		if(i == 0) {
			minA = maxA = A;
		} else {
			if(maxA < A) {
				maxA = A;
				if(valmax == maxA - minA) {
					++nummax;
				}
				if(valmax < maxA - minA) {
					valmax = maxA - minA;
					nummax = 1;
				}
			}
			if(A < minA) {
				minA = maxA = A;
			}
		}
	}
	cout << nummax << '\n';
	return 0;
}



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

int main(void){
    int n;
    
    cin >> n;
    int a[n];
    int b[n];
    int c[n];
    
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    rep(i,n-1){
        cin >> c[i];
    }
    
    int sum=0;
    rep(i,n){
        sum+=b[i];
    }
    rep(i,n-1){
      if((a[i+1]-a[i])==1){
        sum+=c[a[i]-1];
      }
    }
    
    cout << sum << endl;
    
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

u32 n;
u32 *A;

inline void print_array()
{
    string str;
    rep (i, n)
    {
        str += to_string(A[i]) + ' ';
    }
    str.erase(str.end() - 1);
    str += '\n';
    cout << str;
}

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

    cin >> n;

    A = new u32[n];

    rep (i, n)
    {
        cin >> A[i];
    }

    u32 v;

    print_array();
    for (int i = 1; i < n; ++i)
    {
        v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v)
        {
            A[j + 1] = A[j];
            --j;
        }
        A[j + 1] = v;
        print_array();
    }

    return 0;
}



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

using namespace std;

int N,Q;
string s;
set<int> v[26];

int main(){
    cin >> N;
    cin >> s;
    cin >> Q;
    for(int i=0;i<N;i++) v[s[i]-'a'].insert(i);
    for(int i=0;i<26;i++) v[i].insert(N+1);
    vector<int> ans;
    for(int i=0;i<Q;i++){
        int C = 0;
        int a;
        cin >> a;
        if(a == 1){
            int b;
            char c;
            cin >> b >> c;
            v[s[b-1]-'a'].erase(b-1);
            s[b-1] = c;
            v[s[b-1]-'a'].insert(b-1);
        }else{
            int b,c;
            cin >> b >> c;
            for(int j=0;j<26;j++){
                if(c > *(v[j].lower_bound(b-1))){
                    C++;
                }
            }
            ans.push_back(C);
        }
    }
    for(auto &e : ans) cout << e << endl;
    return 0;
}

Measured memory_bytes: 26244
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Text;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        void Omame()
        {
            cin = new Scanner();
            double L = cin.nextInt();
            double A = L / 3;
            double B = L / 3;
            double C = L / 3;

            Console.WriteLine(A * B * C);
        }
    }
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

int main() {
  int H, W; cin >> H >> W;
  vector<string> a(H);
  REP(i, H) {
    cin >> a[i];
  }

  vector<string> ans;
  REP(i, H) {
    bool flag = false;
    REP(k, W) {
      if(a[i][k] == '#') flag = true;
    }
    if(flag) ans.push_back(a[i]);
  }

  vector<vector<string>> ans2;
  REP(i, W) {
    bool flag = false;
    REP(k, ans.size()) {
      if(ans[k][i] == '#') flag = true;
    }
    if(flag) {
      vector<string> tmp;
      REP(k, ans.size()) {
        tmp.push_back(char_to_string(ans[k][i]));
      }
      ans2.push_back(tmp);
      tmp.clear();
    }
  }

  REP(i, ans.size()) {
    REP(k, ans2.size()) {
      cout << ans2[k][i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 896
/*
  AOJ #3017
  title:
  @kankichi573
  2017/12/26 WA 22/26
*/
#include <stdio.h>
#define max(x,y) (((x)>(y))?(x):(y))
int n,x,p,r,c,f,max_;

int main()
{
  int i;

  scanf("%d",&n);
  scanf("%d",&p);
  r=1;
  max_=1;
  f=-2;  // start only
  for(i=0;i<n-1;i++)
    {
      scanf("%d",&c);
      //printf("|%d(%d)|",c,p);
      if(c > p)
        {
          //printf("inc:%d\n",c);
          if(f == -1 || f==-2)
          { max_=max(max_,r);
            r=2,f=1;
          }
          else
          r++;
        }
      else if(c < p)
        {
          //printf("dec:%d\n",c);
          if(f == 1 || f==-2)
            { max_=max(max_,r);
              r=2,f=-1;
            }
          else
            r++;
        }
      p=c;
    }
  max_=max(max_,r);
  printf("%d\n",max_);
  return(0);
}

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

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

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, w;
  cin >> n >> w;
  V<pii> item(n);
  REP(i, n) {
    cin >> item[i].fi >> item[i].se;
  }
  VV<ll> dp(n + 1, V<ll>(w + 1, -1LL));
  dp[0][0] = 0;
  REP(i, n) FOR(j, 0, w) if (dp[i][j] > -1) {
    MAX(dp[i + 1][j], dp[i][j]);
    if (j + item[i].fi <= w) MAX(dp[i + 1][j + item[i].fi], dp[i][j] + item[i].se);
  }
  cout << *max_element(ALL(dp[n])) << endl;
}


Measured memory_bytes: 80256
$_ = <STDIN>;
@param = split(/\s+/, $_);
if( ($param[0] + $param[1]) >= ($param[2]-1)){
  $y = $param[1] + $param[2];
} else {
  $y = $param[0] + 2 * $param[1] + 1;
}
print $y."\n";


Measured memory_bytes: 640
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    long long int h,w;
    scanf("%lld %lld",&h,&w);
    if(h==1||w==1)
      printf("1");
  else
  {
      long long int ans=((h/2)*(w/2))+(h-(h/2))*(w-(w/2));
    printf("%lld",ans);}
}

Measured memory_bytes: 128
let make_list f t step =
  let rec make_list_inner c t lst =
    if c >= t then lst else make_list_inner (c+step) t (c::lst)
  in
  List.rev (make_list_inner f t [])

let print_list str list = Printf.printf "%s: [ " str; List.iter (fun (q,r) -> Printf.printf "(%d, %d); " q r) list; Printf.printf "]\n"

let solve a b c = match (a,b,c) with
    (5,7,5) -> "YES"
  | (7,5,5) -> "YES"
  | (5,5,7) -> "YES"
  | _ -> "NO"

let () =
  let rec read () =
    try let ans = (Scanf.scanf "%d %d %d\n" solve ) in
        Printf.printf "%s\n" ans
    with End_of_file -> ()
  in
  read ()
;;


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll x;
  cin >> x;

  ll ans = 1;
  while (1) {
    if (ans * x % 360 == 0) {
      break;
    }

    ans++;
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int fc1(vector<int> &count){
  int n = count.size();
  int ret = -1, mn = 1001001001;
  rep(i, n){
    if(count.at(i) != 0){
      if(mn > count.at(i)){
        ret = i;
        mn = count.at(i);
      }
    }
  }
  return ret;
}

int fc2(vector<vector<bool>> &able, vector<int> &jcount, int index){
  int n = jcount.size();
  int ret = -1, mn = 1001001001;
  rep(i, n){
    if(able.at(index).at(i) == true){
      if(jcount.at(i) < mn){
        mn = jcount.at(i);
        ret = i;
      }
    }
  }
  jcount.at(ret) = 0;
  return ret;
}

int main(){
  int n;
  cin >> n;
  vector<vector<bool>> able(n, vector<bool>(n, false));
  vector<pair<int, int>> ab(n);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    ab.at(i) = make_pair(a, b);
  }
  vector<pair<int, int>> cd(n);
  rep(i, n){
    int c, d;
    cin >> c >> d;
    cd.at(i) = make_pair(c, d);
  }
  vector<int> icount(n, 0), jcount(n, 0);
  rep(i, n){
    auto ncd = cd.at(i);
    rep(j, n){
      auto nab = ab.at(j);
      if(nab.first < ncd.first && nab.second < ncd.second){
        able.at(i).at(j) = true;
        cerr << i << " " << j << endl;
        icount.at(i)++;
        jcount.at(j)++;
      }
    }
  }
  int ans = 0;
  while(1){
    // cerr << endl;
    // rep(i, n){
    //   rep(j, n){
    //     cerr << able.at(i).at(j) << " ";
    //   }
    //   cerr << endl;
    // }
    int index = fc1(icount);
    if(index == -1) break;
    ans++;
    int rm = fc2(able, jcount, index);
    icount.at(index) = 0;
    rep(i, n){
      able.at(index).at(i) = false;
    }
    
    rep(i, n){
      if(able.at(i).at(rm) == true){
        able.at(i).at(rm) = false;
        icount.at(i)--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// AOJ ALDS1_2_D Shell Sort
// 2018.4.27 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cnt;

void insertion_sort(int n, int *a, int g)
{
	int i, j, key;

	for (i = g; i < n; i++) {
		key = a[i];
		j = i-g;
		while (a[j] > key) {
			a[j+g] = a[j];
			j -= g;
cnt++;
			if (j < 0) break;
		}
		a[j+g] = key;
	}
}

int m;
int g[102];

void shell_sort(int n, int *a)
{
	int i, lim;

	lim = n / 9;		// 要素数/9
	if (lim < 40) lim = 40;
	g[0] = 1;
	for (m = 1; ; m++) {
		g[m] = 3*g[m-1]+1;
		if (g[m] >= n || g[m] > lim) break;
	}

	cnt = 0;
	for (i = m-1; i >= 0; i--) insertion_sort(n, a, g[i]);
}

// バッファを経ずstdinから数値を得る
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int a[1000002];

int main()
{
	int N, i;

	N = in();
	for (i = 0; i < N; i++) a[i] = in();
	shell_sort(N, a);
	printf("%d\n", m);
	printf("%d", g[m-1]);
	for (i = m-2; i >= 0; i--) printf(" %d", g[i]);
	printf("\n%d\n", cnt);
	for (i = 0; i < N; i++) printf("%d\n", a[i]);
	return 0;
}


Measured memory_bytes: 5544
while 1:
    try:
        a = list(map(float, input().split(',')))
        dis = sum(a[:10])
        x = a[10] * dis / (a[10] + a[11])
        for i in range(0, 11):
            if x <= sum(a[:i]):
                print(i)
                break
    except:
        break



Measured memory_bytes: 5580
#include<iostream>

using namespace std;

int main(){

  while(1){

    int n;

    cin >> n;

    if(n == 0) break;

    double min;
    int minnum;
    double bmi[n];

    for(int i = 0; i < n; i++){
      int num;
      double tall, wei;

      cin >> num >> tall >> wei;

      bmi[i] = wei / (tall / 100) / (tall / 100);

      bmi[i] -=22;

      if(bmi[i] < 0) bmi[i] *= -1;
      if(i == 0){
	minnum = num;
	min = bmi[i];
      }

 
      if(min > bmi[i]){
	minnum = num;
	min = bmi[i];
      }

      if(min == bmi[i]){
	if(minnum > num) minnum = num;
      }

    }
    cout << minnum << endl;
  }
  return 0;

}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    cin >> str;
    if(str == "Sunny"){
        cout << "Cloudy" << endl;
    }
    else if(str == "Rainy"){
        cout << "Sunny" << endl;
    }
    else if(str == "Cloudy"){
        cout << "Rainy" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double a, b, h, m;
        a = in.nextDouble();
        b = in.nextDouble();
        h = in.nextDouble();
        m = in.nextDouble();
        in.close();
        double h_angle = 0.5 * (h * 60 + m);
        double m_angle = 6 * m;
        double angle = Math.abs(h_angle - m_angle);
        angle = Math.min(angle, 360 - angle);
        double res = Math.sqrt(a*a + b*b - 2*a*b*Math.cos(angle*Math.PI/180));
        System.out.printf("%.20f\n", res);
    }
}


Measured memory_bytes: 37500
d = {}

N = int(input())
for i in range(N):
    s = input()
    d[s] = d.get(s, 0) + 1

M = int(input())
for i in range(M):
    t = input()
    d[t] = d.get(t, 0) - 1

print(max(max(d.values()), 0))


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define M 2000001
#define X 10001

int main(){
  unsigned short *A, *B;

  int C[X];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for ( i = 0; i <= X; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ){
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= X; i++ ) C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

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

using namespace std;

bool dp[100000][11];
int col[100000];
vector<int> G[100000];

void dfs(int v, int d, int c){
    if(col[v] == 0) {
        col[v] = c;
    }
    for(int i = d; i >= 0; i--) dp[v][i] = true;
    if(d == 0){
        return;
    }
    for(int i = 0; i < G[v].size(); i++){
        if(!dp[G[v][i]][d-1]) dfs(G[v][i], d-1, c);
    }
}

int main(){
    int N, M ,Q;
    int v[100000];
    int d[100000];
    int c[100000];
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cin >> Q;
    for(int i = 0; i < Q; i++){
        cin >> v[i] >> d[i] >> c[i];
        v[i]--;
    }
    for(int i = Q-1; i >= 0; i--){
        if(!dp[v[i]][d[i]]){
            dfs(v[i], d[i], c[i]);
        }  
    }
    for(int i = 0; i < N; i++){
        cout << col[i] << endl;
    }
}

Measured memory_bytes: 9080
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int rate;
	std::cin >> rate;
	std::string result = rate < 1200 ? "ABC" : "ARC";
	std::cout << result << std::endl;
	return 0;
}


Measured memory_bytes: 256
import math 

A, B = [int(item) for item in input().split()]

def gdc(A, B):
    if B == 0:
        return A
    else:
        return gdc(B, A % B)

def chk_pn(num):
    flag = True
    if num  <= 3:
        pass
    else:    
        for i in range(2, int(math.sqrt(num)) + 1):
            if num % i == 0:
                flag = False
                break
    return flag

def mk_factor(num):
    max_divisor = int(math.sqrt(num))+1
    divisor = 2
    factor_list = [1]

    while divisor <= max_divisor:
        if num % divisor == 0:
            factor_list.append(divisor)
            num /= divisor
        else:
            divisor += 1

    factor_list.append(num) #割り残った数を約数に含める事を忘れない
    return factor_list

GDC = gdc(A, B)
pn_factor = [i for i in mk_factor(GDC) if chk_pn(i) is True]
# print(pn_factor)
print(len(set(pn_factor)))

Measured memory_bytes: 3064
#include <stdio.h>

int solve(int, int);

int n ,A[20];

int main(){
  int q,mi;
  int i;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  
  for(i=0;i<q;i++){
    scanf("%d",&mi);
    if( solve(0,mi) == 1) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int  solve(int i,int m){
  
  int res;
  
  if(m == 0)return 1;
	
  if(i >= n)return 0;
  
  res = solve(i+1,m) || solve(i+1,m-A[i]);
  
  return res;
}

Measured memory_bytes: 580
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include <iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {X=X;}
#define TF(f) {f=f;}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF =  1000000000;
const ll SIZE= 100010;
    ll N,A,B,C;
    ll ans=-1;
    bool flag=false;

int main() {
    ios_base::sync_with_stdio(false);
    cin>>A>>B>>C;
    if(B>C||(A==1&&B!=C))ans=0;
    else if(A==1&&B==C)ans=1;
    else{
        ans=(C-B)*(A-2)+1;
    }

    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import numpy as np

n = int(input())
A = np.array(input().split(), np.int64)
B = np.array(input().split(), np.int64)

A = np.sort(A)
B = np.sort(B)

C = [0]*30
for k in range(30):
    A_ = A%(2**(k+1))
    B_ = B%(2**(k+1))
    A_ = np.sort(A_)
    B_ = np.sort(B_)
    A0 = A_[A_<=2**k]
    A1 = A_[A_>2**k]
    C[k] += (np.searchsorted(B_, 2**(k+1)-A0, side='left')-np.searchsorted(B_, 2**k-A0, side='left')).sum()
    C[k] += (np.searchsorted(B_, 2**(k+1)-A1, side='left')-np.searchsorted(B_, 0, side='left')).sum()
    C[k] += (np.searchsorted(B_, 2**(k+1), side='left')-np.searchsorted(B_, 2**(k+1)+2**k-A1, side='left')).sum()

ans = 0
for i in range(len(C)):
    if C[i]%2 == 1:
        ans += 2**i
#print(C)
print(ans)

Measured memory_bytes: 37520
<?php
$n = trim(fgets(STDIN));
for($i = 0; $i < $n; $i++){
    $data[] = explode(" ", trim(fgets(STDIN)));
}
for($i = 0; $i < $n; $i++){
    $map[] = explode(" ", trim(fgets(STDIN)));
}
$max = -10**10;
for($i = 1; $i < 2**10; $i++){
    $flagStr = sprintf("%010d", decbin($i));
    $sum = 0;
    for($j = 0; $j < $n; $j++){
        $c = 0;
        for($k = 0; $k < 10; $k++){
            if($data[$j][$k] && $flagStr[$k])$c++;
        }
        $sum+=$map[$j][$c];
    }
    $max=max($max,$sum);
}
echo $max;


Measured memory_bytes: 4604
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)


typedef map<string, int> map_type;
typedef pair<string, int> value_type;

struct second_order {
  bool operator()(const value_type& x, const value_type& y) const {
    if( x.second != y.second) return x.second < y.second;
    return x.first > y.first;
  }
};

typedef priority_queue<value_type, vector<value_type>, second_order> pqueue_type;


pqueue_type map_to_pqueue(map_type m) {
    pqueue_type que;
    for(auto it=m.begin(); it!=m.end(); ++it) {
        que.push(*it);
    }
    return que;
}


int main(void){
    int n, k;
    cin >> n >> k;
    ll count = 0;
    
    //累積和
    vector<ll> left(n+1);
    vector<ll> right(n+1);
    left[0] = 0;
    right[n] = n;
    FOR(i, 1, n) left[i] = left[i-1]+i;
    for(int i=n-1; i>=0; i--) right[i] = right[i+1]+i;
    
    FOR(i, k, n+1) {
        ll min_v=left[i-1];
        ll max_v=right[n+1-i];
        count += max_v - min_v + 1;
        //cout << max_v << " " << min_v << endl;
    }
    cout << count % MOD << endl;
    return 0;
}


Measured memory_bytes: 6428
a,b=map(int,input().split())
s=[]
for i in range(a,b+1):
    s.append(str(i))
#print(s)
count=0
#print(s[0][0::2])
#print(s[0][-1::-2])
for i in range(len(s)):
    if s[i][0::2]==s[i][-1::-2] and s[i][1::2]==s[i][-2::-2]:
        count+=1
        #print(s[i])
print(count)

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

int main(){
  while(1){
    int m,f,r;cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1)return 0;
    else if(m == -1 || f == -1)cout << "F" << endl;
    else if(m + f >= 80)cout << "A" << endl;
    else if(m + f >= 65 && m + f < 80)cout << "B" << endl;
    else if(m + f >= 50 && m + f < 65)cout << "C" << endl;
    else if(m + f >= 30 && m + f < 50 && r < 50)cout << "D" << endl;
    else if(m + f >= 30 && m + f < 50 && r >= 50)cout << "C" << endl;
    else if(m + f < 30)cout << "F" << endl;
  }
  return 0;
}


Measured memory_bytes: 3068