akhauriyash/Code-Regression huggingface dataset:
N, = map(int, input().split())
G = [set() for _ in range(N+1)]
d = dict()
for i in range(N-1):
    a, b = map(int, input().split())
    G[a].add(b)
    G[b].add(a)
    d[(a,b)] = i
    d[(b,a)] = i
ps = []
M, = map(int, input().split())
for _ in range(M):
    a, b = map(int, input().split())
    stack = [a]
    path = []
    vs = set([a])
    while stack:
        v = stack.pop()
        if v > 0:
            path.append(v)
            if v == b:
                break
            vs.add(v)
            for u in G[v]:
                if u in vs:
                    continue
                vs.add(u)
                stack += [-v, u]
        else:
            path.pop()
    es = 0
    for i in range(len(path)-1):
        es += 1<<d[(path[i], path[i+1])]
    ps.append(es)

r=0
for i in range(2**M):
    p=m=j=0
    x=0
    while i:
        if i%2:
            x=x|ps[j]
            p+=1
        i >>= 1
        j+=1
    r+=(-1 if p%2 else 1)*(1<<(N-1-bin(x).count("1")))
print(r)


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

int main (){
    int N;
    cin >> N;
    vector<string> s(N);

    map<string, ll> list;
    for (int i = 0; i < N; i++)
    {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        list[s[i]]++;
        
    }
    
    ll ans = 0;
    for (auto x: list)
    {
        if (x.second != 1)
        {
            ll y = x.second * (x.second - 1) / 2;
            ans += y;
        }
    }
    
    
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 18176
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 2000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
typedef unsigned long long int ull;
using namespace std;

int LIS(int* A,int L){
  int DP[L];
  fill(DP,DP+L,INF);
  rep(i,L) *upper_bound(DP,DP+L,A[i])=A[i];
  return lower_bound(DP,DP+L,INF)-DP;
}
int LCM(int a,int b){
  int tmp,r,x;
  x=a*b;
  if(a<b) tmp=a,a=b,b=tmp;
  r=a%b;
  while(r!=0) a=b,b=r,r=a%b;
  x=x/b;
  return x;
}
int GCD(int a,int b){
  return (a*b)/LCM(a,b);
}

int main(void){
  int N,K;
  cin >> N >> K;
  int h[N],dp[N],jump[K];
  rep(i,N) cin >> h[i];
  dp[0]=0,dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<min(K,N);i++){
    fill(jump,jump+K,INF);
    rep(j,i) jump[j]=abs(h[i]-h[j])+dp[j];
    dp[i]=*min_element(jump,jump+K);
  }
  for(int i=max(K,2);i<N;i++){
    fill(jump,jump+K,INF);
    rep(j,K) jump[j]=abs(h[i]-h[i-j-1])+dp[i-j-1];
    dp[i]=*min_element(jump,jump+K);
  }
  cout << dp[N-1] << endl;
}

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

int main () {
	string S, T; cin >> S >> T;
	int N = S.size(), M = T.size();
	int ans = 1000;
	for (int i = 0; i <= N - M; i++) {
		int temp = 0;
		for (int j = 0; j < M; j++) {
			if (S[i + j] != T[j]) temp++;
		}
		if (ans > temp) ans = temp;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3612
import scala.io.Source

object Main extends App {
  val src = Source.stdin.getLines.toList.flatMap(_.split(" ").map(_.toLowerCase).toList)
  val target = src(0)

  def removeOthers(src: List[String]): List[String] = {
    for {
      word <- src.tail
      if (word == target)
    } yield word
  }

  println(removeOthers(src).length)
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
ll n,d,h,sum,mod=1e9+7,f=1;
int main(){
	FAST
	cin>>n>>h>>d;
	FOR(i,1,n)f*=i,f%=mod,sum+=f,sum%=mod;
	vector<ll> dp(h+1,0);
	dp[0]=f;
	ll mult=dp[0];
	FOR(i,1,h){
		if(i-d-1 >= 0) mult -= dp[i-d-1], mult += mod, mult %= mod;
		dp[i]=mult * sum % mod;
		if(i<h)mult += dp[i], mult %= mod;
	}
	cout<<mult<<'\n';
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
 
#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

int32_t main()
{	
	IOS
	int n;
	cin >> n;
	set <string> st;
	while (n--)
	{
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 19244
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int n;
string ans = "";

int p[101010];

int q[101010];

int main() {
  cin >> n;
  for(int i = 0;i < n;i++) {
    cin >> p[i];
  }
  for(int i = 0;i < n;i++) {
    q[p[i]] = i + 1;
  }

  vector<int> vec;

  int cnt = 1;

  for(int i = 1;i <= n;i++) {
    vec.push_back(q[i]);
    ans += "(";
    while(!vec.empty() && vec.back() == cnt) {
      ans += ")";
      vec.pop_back();
      cnt++;
    }
  }
  if(ans.size() == 2 * n)
    cout << ans << endl;
  else {
    cout << ":(" << endl;
  }
}



Measured memory_bytes: 4144
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#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++)
#define mm (1e16)

ll Mod=(1e9+7);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    cout<<(n-1)*n/2;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll A, B;
    char c;
    cin >> A >> c >> B;
    if(c == '+')cout << A + B << endl;
    else cout << A - B << endl;

    return 0;
}

Measured memory_bytes: 256
/*

#      #      #####   ##   ##  #####      ##     #  #      #   #  #####
#      #      #   #  #  ###  # #          # ##   #  #      #   #  #   #
#      #      #   #  #   #   # #          #  ##  #  #      #   #  #   #
#      #      #   #   #     #  #####      #   #  #  #       ###   #####
#      #      #   #    #   #   #          #  ##  #  #        #    #   #
#      #      #   #     ###    #          # ##   #  #        #    #   #
#      #####  #####      #     #####      ##     #  #####    #    #   #

*/

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <llong> vl;
typedef vector <string> vs;
typedef vector <vector <llong>> matrix;

typedef pair <llong, llong> pll;

typedef map <llong, llong> mll;

typedef set <llong> sl;

const llong MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;};

llong n, m;
llong d[MXN];

vector <pll> g[MXN];

bool used[MXN];

void dfs (llong v, llong dist = 0) {
    if (used[v]) {
        if (dist != d[v]) {
            cout << "No";
            exit (0);
        }
        else {
            return ;
        }
    }
    d[v] = dist;
    used[v] = 1;
    for (pll it : g[v]) {
        dfs (it.F, dist + it.S);
    }
}

int main () {
    android;
    random_device rand;
    #ifdef I_LOVE_DILYA
        freopen ("input.txt", "r", stdin);
    #endif
    cin >> n >> m;
    for (llong i = 1; i <= m; ++ i) {
        llong u, v, w;
        cin >> u >> v >> w;
        g[u].pb ({v, w});
        g[v].pb ({u, -w});
    }
    for (llong i = 1; i <= n; ++ i) {
        if (!used[i]) dfs (i);
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 38144
#include <iostream>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ans;
  for(int i=1;i<10;i++){
    ans = 100*i + 10*i + i;
    if(ans>=n){
      cout<<ans<<endl;
      break;
    }
  }
  
  return 0;
}

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

struct Record
{
        int pos, plus;
        int curc;
        Record () {}
        Record ( int pos, int plus, int curc ) : pos(pos), plus(plus), curc(curc) {}
};

stack < int > cnt[200005];
int main()
{
        string S;
        stack < Record > record;
        int curc = 0;
        long long ans = 0;
        cin >> S;
        
        for ( int i = 0; i < S.size(); i++ ) {
                switch ( S[i] ) {
                case '(':
                        curc++;
                        cnt[curc].push(cnt[curc].empty() ? 1 : cnt[curc].top() + 1);
                        record.emplace(curc, 0, curc - 1);
                        break;
                case ')':
                        if ( !cnt[curc].empty() ) ans += cnt[curc].top();
                        record.emplace(-1, cnt[curc].empty() ? 0 : cnt[curc].top(), curc);
                        cnt[curc + 1].push(0);
                        if ( curc > 0 ) curc--;
                        break;
                case '-':
                        if ( record.empty() ) break;
                        Record dat = record.top(); record.pop();
                        if ( dat.pos == -1 ) {
                                ans -= dat.plus;
                                curc = dat.curc;
                                cnt[curc + 1].pop();
                        } else {
                                cnt[dat.pos].pop();
                                curc = dat.curc;
                        }
                        break;
                }
                cout << ans << endl; /*" " << record.size() << endl;*/
        }

        return ( 0 );
}



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

int main(){
  long long  a,b,c,d;
  cin >> a >> b >> c >> d;
  vector <long long> z(4);
  z.at(0) = a*c;
  z.at(1) = a*d;
  z.at(2) = b*c;
  z.at(3) = b*d;
  sort(z.begin(),z.end());
  cout << z.at(3);
  
}

Measured memory_bytes: 3628
import java.util.*;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

    int r=sc.nextInt();
    int d=sc.nextInt();
    int x=sc.nextInt();

    for(int i=0;i<10;i++){
      x=r*x-d;
      System.out.println(x);
    }

	}
}

Measured memory_bytes: 23636
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll n;
    string s;
    cin>>n>>s;
    vector<vector<ll>> dp(n,vector<ll>(n,0));
    dp[0][0]=1;
    for(ll i=0;i+1<n;i++){
        if(s[i]=='<'){
            for(int t=1;t<n;t++){dp[i][t]+=dp[i][t-1]; dp[i][t]%=MOD;}
            for(int t=1;t<=i+1;t++){dp[i+1][t]=dp[i][t-1];}
        }
        else{
            for(ll t=n-2;t>=0;t--){dp[i][t]+=dp[i][t+1]; dp[i][t]%=MOD;}
            for(int t=0;t+1<n;t++){dp[i+1][t]=dp[i][t];}
        }
    }
    for(int i=1;i<n;i++){dp[n-1][i]+=dp[n-1][i-1]; dp[n-1][i]%=MOD;}
    cout<<dp.back().back()<<endl;
    
    
    return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;

int main(){

	int x,y,z;
	cin>>x>>y>>z;
	x-=z;
	cout<<x/(y+z)<<endl;



    return 0;
}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T> struct range_add {
  static constexpr T inf = numeric_limits<T>::max() / 2;
  struct node { T delta = 0, min = inf, max = -inf, len = 0, sum = 0; };
  static node op(const node& l, const node& r) {
    return {
      l.delta + r.delta,
      std::min(l.min, l.delta + r.min), std::max(l.max, l.delta + r.max),
      l.len + r.len, l.sum + l.delta * r.len + r.sum
    };
  }
  static node make_node(T a) { return {a, a, a, 1, a}; }
  const int n;
  vector<node> t;
  range_add(const vector<T>& v) : n(v.size() + 1), t(2 * n) {
    for (int i = n - 1; i--; ) t[n + i] = make_node(v[i] - (i ? v[i - 1] : 0));
    for (int i = n; i-- > 1; ) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
  node fold(int l, int r) const {
    node a, b;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) a = op(a, t[l++]);
      if (r & 1) b = op(t[--r], b);
    }
    return op(a, b);
  }
  T get(int i) const { return fold(0, i + 1).delta; }
  T min(int l, int r) const { return get(l - 1) + fold(l, r).min; }
  T max(int l, int r) const { return get(l - 1) + fold(l, r).max; }
  T sum(int l, int r) const { return get(l - 1) * (r - l) + fold(l, r).sum; }
  void set(int i, const node& a) {
    t[i += n] = a;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
  void add(int l, int r, T a) {
    set(l, make_node(t[n + l].delta + a));
    set(r, make_node(t[n + r].delta - a));
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  map<int, vector<int>> mp;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    --a[i], --b[i];
    mp[a[i]].push_back(i);
  }
  vector<int> v(m + 1);
  iota(begin(v), end(v), 0);
  range_add<int> ra(v);
  int res = n - m;
  for (int l = 0; l <= m; ++l) {
    for (int i : mp[l - 1]) {
      ra.add(0, b[i] + 1, 1);
    }
    res = max(res, ra.max(l, m + 1) - (m + l));
  }
  cout << res << '\n';
}


Measured memory_bytes: 29696
n = int(input())
aN = list(map(int, input().split()))
sum_board = 0
aN_max = aN[0]
for i in range(1,n):
    if aN[i] < aN_max:
        sum_board +=  aN_max - aN[i]
    else:
        aN_max = aN[i]

print(sum_board)

Measured memory_bytes: 32200
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= N; i++) {
            final int a = sc.nextInt();
            if (((i % 2) != 0) && ((a % 2) != 0)) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35716
n = int(input())
h = list(map(int,input().split())) + [10**10+1]
Min = min(h)
for i in range(n):
    if h[-i-1] < h[-i-2]:
        h[-i-2] -=1
for i in range(n):
    if h[i] > h[i+1]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 14252
import math
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]
kumi= n*(n-1)/2 #階乗
keiro = math.factorial(n)
kaisu = keiro*(n-1)/kumi
total = 0

for i in range(n):
    a = 0
    for j in range(i+1,n):
        kyori = ((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**0.5
        a += kyori*kaisu
    total += a

print(total/keiro)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
 
int dsc(const void *a, const void *b){
  return *(int *)b - *(int *)a;
}
 
int main(){
  int X,Y,A,B,C;
  int *p, *q, *r;
  scanf("%d %d %d %d %d", &X, &Y, &A, &B, &C);
  p = (int *)malloc(sizeof(int) * A);
  q = (int *)malloc(sizeof(int) * B);
  r = (int *)malloc(sizeof(int) * (C+X+Y));
  for(int i=0; i<A; i++) scanf("%d ", &p[i]);
  for(int i=0; i<B; i++) scanf("%d ", &q[i]);
  for(int i=0; i<C; i++) scanf("%d ", &r[i]);
 
  qsort(p, A, sizeof(int), dsc);
  qsort(q, B, sizeof(int), dsc);
  
  for(int i=0; i<X; i++) r[C+  i] = p[i];
  for(int i=0; i<Y; i++) r[C+X+i] = q[i];
  
  qsort(r, C+X+Y, sizeof(int), dsc);
  
  long s=0;
  for(int i=0; i<X+Y; i++){
    s += r[i];
  }
  
  printf("%ld\n", s);
}
 

Measured memory_bytes: 3572
a, b, k = map(int, input().split())
if a - k > 0:
    a = a - k
elif a - k < 0:
    if b - (k - a) > 0:
        b = b - (k - a)
        a = 0
    else:
        b = 0
        a = 0
else:
    a = 0
print(a, b)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m, q;
	cin >> n >> m >> q;
	vector<int> a(q);
	for(int i = 0; i < q; ++i){
		cin >> a[i];
		--a[i];
	}
	vector<int> occur(m);
	vector<int> order;
	for(int i = q - 1; i >= 0; --i){
		if(occur[a[i]] == 0){ order.push_back(a[i]); }
		++occur[a[i]];
	}
	const int k = order.size();
	bool is_ordered = true;
	for(int i = 0; i < k; ++i){
		if(order[i] != i){ is_ordered = false; }
	}
	if(is_ordered){
		cout << "Yes" << endl;
		return 0;
	}
	vector<int> lookup(m);
	for(int i = 0; i < k; ++i){ lookup[order[i]] = i; }
	vector<int> reach(k + 1);
	reach[0] = n;
	for(int i = q - 1; i >= 0; --i){
		const int t = lookup[a[i]];
		if(reach[t + 1] < reach[t]){ ++reach[t + 1]; }
	}
	set<int> s;
	for(int i = 0; i < m; ++i){ s.insert(i); }
	bool possible = true;
	for(int i = 0; possible && i < k; ++i){
		if(reach[i + 1] < n && *(s.begin()) != order[i]){
			possible = false;
		}
		s.erase(order[i]);
	}
	cout << (possible ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 6904
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
#include <unordered_map> 
#include <iomanip>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
#define PN 1000000007
typedef long long LL;
//#define int long long


//booooooooooooost
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int), 多倍長小数(mp::cpp_dec_float_100)



int inv_mod(int a, int m)
{
	int b, x, u, q, tmp;

	b = m; x = 1; u = 0;
	while (b > 0) {
		q = a / b;
		tmp = u; u = x - q * u; x = tmp;
		tmp = b; b = a - q * b; a = tmp;
	}

	return (x < 0) ? m + x : x;
}




LL f(LL B, LL N) {
	if (N < B) return N;
	else return f(B, N / B) + (N % B);
}

signed main() {

	LL n, s;
	cin >> n >> s;
	LL ans = -1;

	if (s == n) ans = n + 1;
	else {
		for (LL b = 2; b <= sqrt(n); ++b) {
			if (f(b, n) == s) { ans = b; break; }
			else ans = -1;
		}
	}
	if (ans == -1) {
		for (LL p = 1; p < sqrt(n); ++p) {
			long double b = (n - s) / p + 1;
			if (b - floor(b) < 0.000001 && b >= 2 && f((LL)b, n) == s) ans = b;
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {
    int m = -1;
    vector<int> num(3);
    int sum = 0;
    for (auto &n: num) {
        cin >> n;
        sum += n;
        if (n >= m) m = n;
    }
    bool match_odd_or_even = (m % 2 == 0 && sum % 2 == 0) || (m % 2 == 1 && sum % 2 == 1);
    if (match_odd_or_even) {
        cout << ((3 * m - sum) / 2) << endl;
    } else {
        cout << ((3 * (m + 1) - sum) / 2) << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

int n[201]={},p[201]={},q[201]={};
int m,N,c;

scanf("%d",&N);scanf("%d",&m);
for(int i=0;i<2*N;i++)
n[i]=(i+1);

//for(int i=0;i<2*N;i++)
//printf("%d\n",n[i]);

for(int jj=0;jj<m;jj++)
{scanf("%d",&c);
if(c!=0){
for(int i=0;i<c;i++)
p[i]=n[i];

//for(int i=0;i<c;i++)
//printf("%d\n",p[i]);

for(int i=c;i<2*N;i++)
{q[i-c]=n[i];}//printf("%d\n",q[i]);}

//for(int i=0;i<2*N-c;i++)
//printf("%d\n",q[i]);


for(int i=0;i<2*N-c;i++)
if(i<2*N-c)n[i]=q[i];
for(int i=2*N-c;i<2*N;i++)
n[i]=p[i-(2*N-c)];

}
else {
for(int i=0;i<2*N;i++)
{
if(i<N)p[i]=n[i];
else if(i>=N)q[i-N]=n[i];
}


for(int i=0;i<2*N;i+=2)
{n[i]=p[i/2];n[i+1]=q[i/2];}

//for(int i=0;i<2*N;i++)
//printf("%d\n",p[i]);

}
}
for(int i=0;i<2*N;i++)
printf("%d\n",n[i]);

return 0;
}


 

Measured memory_bytes: 1032
/* Code by Saborit */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast") 
#define MX 200005
#define INF (1<<30)
#define EPS 1e-9
#define MOD 1000000007
#define mid (x+xend)/2
#define izq nod*2
#define der nod*2+1
#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define unique(X) (X).resize(unique(all(X)) - (X).begin())
#ifdef LOCAL 
	#include "debug.h"
#endif
using namespace std;
using namespace __gnu_pbds;
typedef long long int64;
typedef unsigned long long unt64;

int N, K;
int A[MX], sum[MX];
map<int, int> cant;

int main(void){
    //~ freopen("a.in", "r", stdin);
    //~ freopen("a.out", "w", stdout);
    
    scanf("%d%d", &N, &K);
    for(int i=1; i<=N; i++)
		scanf("%d", &A[i]);
	
	if( K == 1 )
	    return !printf("0\n");
		
	for(int i=1; i<=N; i++)
		sum[i] = (sum[i-1] + A[i]) % K;
		
	int64 sol = 0;
	
	cant[0]++;
	for(int i=1; i<=N; i++){
		if( cant.count(sum[i] - i) )
			sol += cant[sum[i] - i];
		
		if( cant.count(sum[i] - i + K) )
			sol += cant[sum[i] - i + K];
		
		//~ db() << i << " " << cant[sum[i] - i] << " + " << cant[sum[i] - i + K];
		
		cant[sum[i] - i]++;
		if( i-K+1 >= 0 ){
			cant[sum[i-K+1] - (i-K+1)]--;
		}
	}
    
    printf("%lld\n", sol);
    
   return 0;
}


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

int main() {

    int N, A, B;
    cin >> N >> A >> B;
    char S[N];
    for(int i = 0; i < N; i++){
        cin >> S[i];
    }

    int through = 0;
    int rank_b = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == 'a'){
            if(through < (A+B)){
                through++;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else if(S[i] == 'b'){
            rank_b++;
            if((through < (A+B)) && (rank_b <= B)){
                through++;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else if(S[i] == 'c'){
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3696
#include<iostream>
#define EPS 1e-10
using namespace std;


int main()
{

  int a,b,c,d,e,f;
  double x,y;

  while(cin >> a >> b >> c >> d >> e >> f){
    x = (double)(c*e - f*b) / (a*e - d*b) + EPS;
    y = (double)(c*d - f*a) / (b*d - e*a) + EPS;

    printf("%.3lf %.3lf\n",x,y);
   }

  return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

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

    int a[21]; a[0]=1;
    REP(i,20) a[i+1]=a[i]*3;
    int n; cin>>n;
    cout<<lower_bound(a,a+21,n)-a<<endl;

}



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

bool isPrime(int n){
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0) return false;
	}
	return true;
}

int main(){
	int prime[250000] = {0};

	for(int i=2;i<250000;i++){
		prime[i] = isPrime(i);
	}
	for(int i=1;i<250000;i++){
		prime[i] += prime[i-1];
	}

	int n;
	while(cin >> n,n){
		cout << prime[2*n] - prime[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 4024
N, K = map(int, input().split())
D = list(map(int, input().split()))

dp = [[[False for ___ in range(N+1)] for __ in range(N+1)] for _ in range(K+1)]

dp[0][0][N] = True

for k in range(K):
    for i in range(N+1):
        for j in range(i, N+1):
            if j+1<=N and i-1>=0:
                dp[k+1][i][j] = dp[k][i][j+1] or dp[k][i-1][j]
            elif j+1<N:
                dp[k+1][i][j] = dp[k][i][j+1]
            elif i-1>=0:
                dp[k+1][i][j] = dp[k][i-1][j]
                

ans = 0
for k in range(K+1):
    for n in range(K-k+1):
        for i in range(N+1):
            for j in range(i, N+1):
                if not dp[k][i][j]:
                    continue
                on_hand = D[:i]+D[j:]
                m = len(on_hand)
                if m < n:
                    continue
#                print(on_hand)
#                print(k, i, j, n, sorted(on_hand,reverse=True)[:m-n], sum(sorted(on_hand,reverse=True)[:m-n]))
                ans = max(ans, sum(sorted(on_hand,reverse=True)[:m-n]))
print(ans)
            
            
            


Measured memory_bytes: 5748
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<long long> v;
	long long a;
	long long cnt = 0;

	for (int i = 0; i < n; i++) {
		cin >> a;
		v.push_back(a);
	}

	sort(v.begin(), v.end());


	cnt = v.at(n / 2) - v.at(n / 2-1);

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1400
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
            .replaceAll(",", "").split(" ");
    
    int k = Integer.parseInt(br.readLine());
    System.out.println(s[k-1]);
  }
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int a,b,c,n;
	cin>>a>>b>>c>>n;
	int ans=0;
	for(int i=0;true;i++){
		if(i*a>n) break;
		int r=n-i*a;
		for(int j=0;true;j++){
			if(j*b > r) break;
			int p=r-j*b;
			if(p%c==0) ans++;
		}
	}
	cout<<ans;
}

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

using namespace std;

int main()
{
    int m, k;

    cin >> m >> k;

    if (k == 0)
    {
        for (int i = 0; i < pow(2, m); i++)
        {
            cout << i << " ";
            cout << i << " ";
        }
    }
    else if (k == 1 && m == 1)
    {
        cout << -1 << endl;
    }
    else if (k > 0 && k <= pow(2, m) - 1)
    {
        for (int i = 0; i < pow(2, m); i++)
        {
            if (i == k)
            {
                continue;
            }
            cout << i << " ";
        }
        cout << k << " ";
        for (int i = 0; i < pow(2, m); i++)
        {
            if (pow(2, m) - 1 - i == k)
            {
                continue;
            }
            cout << pow(2, m) - 1 - i << " ";
        }
        cout << k << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
class Main
{
	static StringBuilder sb;
	public static final boolean ONLINE_JUDGE=false;
	public static void main(String []args)throws IOException
	{
		sb=new StringBuilder();
		Scanner sc=new Scanner(System.in);
		if(ONLINE_JUDGE)
		{
			File file=new File("output.txt");
			sc=new Scanner(new FileReader(new File("input.txt")));
			PrintStream ps=new PrintStream(file);
			System.setOut(ps);
		}
		int t=1;
		for(int tt=1;tt<=t;tt++)
		{
			int n=sc.nextInt();
			int k=sc.nextInt();
			int a[]=new int[n];
			for(int i=0;i<n;i++)
				a[i]=sc.nextInt();
			int dp[]=new int[n];
			Arrays.fill(dp,Integer.MAX_VALUE);
			dp[0]=0;
			for(int i=0;i<n;i++)
			{
				for(int j=i+1;j<=i+k;j++)
				{
					if(j>=n)continue;
					dp[j]=Math.min(dp[j],dp[i]+Math.abs(a[i]-a[j]));
				}
			}
			System.out.println(dp[n-1]);
		}
	}
}

Measured memory_bytes: 51144
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main implements Runnable {
	public static void main(String[] args) throws FileNotFoundException {
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).run();
	}

	int N, M;
	int[] A, B;
	int[] col;
	int[][] cnt;
	ArrayList<Integer>[] g;

	public void run() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		A = new int[M];
		B = new int[M];
		col = new int[N];
		g = new ArrayList[N];
		boolean[][] connect = new boolean[N][N];
		cnt = new int[N][2];
		for (int i = 0; i < N; ++i)
			g[i] = new ArrayList<>();
		Arrays.fill(col, -1);
		for (int i = 0; i < M; ++i) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			--A[i];
			--B[i];
			connect[A[i]][B[i]] = true;
			connect[B[i]][A[i]] = true;
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i != j && !connect[i][j]) {
					g[i].add(j);
				}
			}
		}
		for (int i = 0; i < N; ++i) {
			if (col[i] == -1) {
				col[i] = 0;
				dfs(i, -1);
				++p;
			}
		}
		if (!flag) {
			System.out.println(-1);
			return;
		}
		boolean[][] ok = new boolean[1000][1000];
		ok[0][0] = true;
		for (int i = 0; i + 1 <= N; ++i) {
			for (int j = 0; j < 1000; ++j) {
				if (ok[i][j]) {
					if (ok[i + 1].length > j + cnt[i][0])
						ok[i + 1][j + cnt[i][0]] = ok[i][j];
					if (ok[i + 1].length > j + cnt[i][1])
						ok[i + 1][j + cnt[i][1]] = ok[i][j];
				}
			}
		}
		long ans = Long.MAX_VALUE / 3;
		for (int i = 0; i < ok[p].length; ++i) {
			if (ok[p][i]) {
				ans = Math.min(ans, i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2);
			}
		}
		System.out.println(ans);
		System.exit(0);
	}

	int p = 0;
	boolean flag = true;

	void dfs(int cur, int par) {
		cnt[p][col[cur]]++;
		for (int dst : g[cur]) {
			if (dst == par)
				continue;
			if (col[dst] == -1) {
				col[dst] = col[cur] ^ 1;
				dfs(dst, cur);
			} else {
				if (col[dst] != (col[cur] ^ 1)) {
					// System.out.println(-1);
					// System.exit(-1);
					flag = false;
				}
			}
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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

int main(void)
{
	set<string> s;
	string a;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		s.insert(a);
	}
	cout<<s.size();
	return 0;
}

Measured memory_bytes: 19128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int x;
  cin >> x;
  if(x<1200) {
    cout << "ABC" << endl;
  } else {
    cout << "ARC" << endl;
  }
  return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int a = Integer.parseInt(in.readLine());
    int b = Integer.parseInt(in.readLine());
    int sum = 6;
    System.out.println(sum-a-b);
  }
}

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

int main() {
  int N,K;
  cin>>N>>K;
  vector<int> vec(N);
  int ans=0;
  for(int i=0;i<N;i++) {
    cin>>vec.at(i);
  }
  for(int i=0;i<N;i++) {
    int O=min(abs(vec.at(i)), abs(K-vec.at(i)));
    ans+=O;
  }
  cout<<2*ans<<endl;
}

Measured memory_bytes: 256
from operator import itemgetter
import bisect
import math

N,d,a = map(int, input().split())
xh = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
x = []
for X,h in xh:
  x.append(X)
ans = 0
attack_start = [i for i in range(N)]
now = 0
cumsum = [0] * (N+1)
for L,(X,H) in enumerate(xh):
  R = bisect.bisect_right(x,X+2*d)
  for i in range(now,R):
    attack_start[i] = L
  now = R
  damage = (cumsum[L] - cumsum[attack_start[L]]) * a
  attack_time = max(0,math.ceil((H - damage) / a))
  ans += attack_time
  cumsum[L+1] = ans
print(ans)



Measured memory_bytes: 113820
import collections
n, m = map(int, input().split())
par = [i for i in range(n)]
# print(par)
s = list()
"""
# union find(parには0も入れているので、par[1]=1になる)
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
"""


def find(x):

    while par[x] != x:
        tmp = par[x]
        par[x] = par[par[x]]
        x = par[x]

    return x


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        par[x] = y


# 各要素をunionする
for j in range(m):
    a, b = map(int, input().split())
    union(a - 1, b - 1)

# 1～nの親を探してsに入れていき、一番多い親を答えにする
for k in range(n):
    s.append(find(k))
# print(s)
c = collections.Counter(s)
print(max(c.values()))


Measured memory_bytes: 40200
n = gets.to_i
li = []
flag = true
n.times do
  a,b = gets.split.map(&:to_i)
  c = b - a
  if c < 0
    puts 'No'
    exit
  end
  li << [a,b,c]
end

li = li.sort { |(a1,b1),(a2,b2)| b1 <=> b2 }

sum = 0
li.each do |a,b|
  sum += a
  if sum > b
    flag = false
    break
  end
end

if flag
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 19420
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int a, b;
	cin >> a >> b;
	if(a % 500 <= b) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	rtn 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<string,int> P;

ll C[30];

int main(){
    ll ans=0;
    string s;
    cin>>s;
    ll n=s.size();
    for(int i=0;i<(int)s.size();i++){
        C[s[i]-'a']++;
    }

    for(int i=0;i<26;i++){
        ans+=(C[i]-1)*C[i]/2;
    }
    cout<<n*(n-1)/2+1-ans<<endl;
}


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

long long permutation(int n, int k)
{
    long long result;

    result = 1;
    if (n < k) {printf("Error: perm (%d, %d)\n", n, k);exit(1);}
    while(k > 0) {
        result *= n;
        n--; k--;
        result %= 1000000007;
    }
    return result;
}

int qsort_int(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int solve(int n, int m, int a[], int b[])
{
    int i;
    int row, col; //残りの行数，列数
    int count;
    int inc;
    int a_ptr, b_ptr;
    long long ans;

    // 重複チェック
    for (i = 1; i < n; i++) {
        if (a[i - 1] == a[i]) {return 0;}
    }
    for (i = 1; i < m; i++) {
        if (b[i - 1] == b[i]) {return 0;}
    }

    a_ptr = 0; b_ptr = 0;
    row = n; col = m;
    ans = 1;
    count = 0;

    while(1) {
        if (a_ptr >= n || b_ptr >= m) {break;}

        if (a[a_ptr] == b[b_ptr]) {
            inc = row + col - 1;
            if (a[a_ptr] < count + inc) {return 0;}
            ans *= permutation(a[a_ptr] - count - 1, inc - 1);
            count += inc;
            row--; col--;
            a_ptr++; b_ptr++;
        } else if (a[a_ptr] < b[b_ptr]) {
            inc = col;
            if (a[a_ptr] < count + inc) {return 0;}
            ans *= permutation(a[a_ptr] - count - 1, inc - 1);
            ans %= 1000000007;
            ans *= inc;
            count += inc;
            row--;
            a_ptr++;
        } else { //b[b_ptr] < a[a_ptr]
            inc = row;
            if (b[b_ptr] < count + inc) {return 0;}
            ans *= permutation(b[b_ptr] - count - 1, inc - 1);
            ans %= 1000000007;
            ans *= inc;
            count += inc;
            col--;
            b_ptr++;
        }

        ans %= 1000000007;
    }

    return (int) ans;
}

int main(int argc, char *argv[])
{
    int n, m;
    int a[1000], b[1000];
    int i;
    int ans;

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

    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (i = 0; i < m; i++) {
        scanf("%d", &b[i]);
    }

    qsort(a, n, sizeof(int), qsort_int);
    qsort(b, m, sizeof(int), qsort_int);

    ans = solve(n, m, a, b);

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

    return(0);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long r,g,b;
    scanf("%ld%ld%ld", &r, &g, &b);

    if((r*100+g*10+b)%4==0) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;
int n,a[maxn];
struct stu{
 int idx,total;
 bool operator <(const stu& s)const{
      return total<s.total;
 }
}s[maxn];

int main()
{
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  cin>>a[i];
  s[i].idx=i;
  s[i].total=a[i];
 } 
 sort(s+1,s+n+1);
 for(int i=1;i<=n;i++)
 {
  cout<<s[i].idx<<" ";
 }
 return 0;
}   


Measured memory_bytes: 2048
#include<iostream>
using namespace std;
float A[1005];
int main(){
  int N,M;
  cin>>N>>M;
  float votes=0;
  for(int i=0; i<N; i++){
    cin>>A[i];
    votes+=A[i];
  }
  float threshold=float(votes)/(4.0*M);
  float cnt=0;
  for(int i=0; i<N; i++){
    if(A[i]>=threshold) cnt++;
  }
  if(cnt>=M) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main() {
    int h1, h2;
    cin >> h1 >> h2;
    int num = h1 * h2;
    if (num % 2 == 0) {
        cout << "Even" << endl ;
    }else{
        cout << "Odd" << endl;
    }
}

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

int main(){
  //小数点以下12ケタを表示させるためのおまじない
  cout<<fixed<<setprecision(12);
  double x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;

  double X=pow(x1-x2,2);
  double Y=pow(y1-y2,2);
  cout<< sqrt( X+Y ) <<endl;
  return 0;  
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

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

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

ll fact(ll n){
    if(n==0)
        return 1;
    else
        return n*fact(n-1);
}

string cal(string a,string b){

   ll a1=a.size(), b1=b.size();
   ll dp[a1+1][b1+1]={},i,j;

   for(i=1;i<=a1;i++){
        for(j=1;j<=b1;j++){
            if(a[i-1]==b[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
                //a[i-1] = ' ';
            }
            else{
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
            }
        }
   }

   /*for(i=1;i<=a1;i++){
    for(j=0;j<=b1;j++)
        cout<<dp[i][j]<<" ";
    cout<<"\n";
   }*/
   string s;

   i = a1, j = b1;
   while(dp[i][j]!=0){
        //cout<<dp[i][j]<<" ";
        if(dp[i][j]==dp[i-1][j]){
            i--;
        }
        else if(dp[i][j]==dp[i][j-1])
            j--;
        else{
            s = a[i-1] + s;
            i--;
            j--;
        }
   }
   //cout<<s<<"\n";
   return s;

}

void solve(){

    string a,b;
    cin>>a>>b;
    cout<<cal(a,b);

}

int main(){
    //freopen("D:\\codes\\1input.txt","r",stdin);
    //freopen("D:\\codes\\1output.txt","w",stdout);
    ll T=1;
    //cin>>T;
    for(ll t=1;t<=T;t++){

        //cout<<"Case #"<<t<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 73964
<?php

fscanf(STDIN, '%d', $w);
fscanf(STDIN, '%d', $n);
$bs = array();
for ($i = 0; $i < $n; $i++) {
    $bs[] = fscanf(STDIN, '%d,%d');
}

$g = array();
for ($i = 0; $i < $w; $i++) {
    $g[$i] = null;
}
for ($i = 0; $i < $w; $i++) {
    $p = $i + 1;
    for ($j = 0; $j < $n; $j++) {
        if ($bs[$j][0] === $p) {
            $p = $bs[$j][1];
        } elseif ($bs[$j][1] === $p) {
            $p = $bs[$j][0];
        }
    }
    $g[$p - 1] = $i + 1;
}

foreach ($g as $v) {
    echo $v . PHP_EOL;
}

Measured memory_bytes: 6612
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    cout << n * n - a << endl;
}

Measured memory_bytes: 256
<?php

list($s) = explode(' ', trim(fgets(STDIN)));
list($q) = explode(' ', trim(fgets(STDIN)));

$direction_changed = false;
$unshift_str = [];
$push_str = [];
for ($i = 1; $i <= $q; ++$i) {
    $input = explode(' ', trim(fgets(STDIN)));
    if ($input[0] === '1') {
        $direction_changed = !$direction_changed;
    } else {
        if ($input[1] === '1') {
            if ($direction_changed) {
                $push_str[] = $input[2];
            } else {
                $unshift_str[] = $input[2];
            }
        } else {
            if ($direction_changed) {
                $unshift_str[] = $input[2];
            } else {
                $push_str[] = $input[2];
            }
        }
    }
}
$unshift_str = strrev(implode('', $unshift_str));
$push_str = implode('', $push_str);

$s = $unshift_str . $s . $push_str;

if ($direction_changed) {
    $s = strrev($s);
}

echo $s;


Measured memory_bytes: 20980
data class Edge(val to: Int, val distance: Long)
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val graph = Array(N, { mutableListOf<Edge>()}).toList() // contains edge index

    for (i in 0 until N - 1) {
        val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
        val from = a - 1
        val to = b - 1
        graph[from].add(Edge(to, c.toLong()))
        graph[to].add(Edge(from, c.toLong()))
    }
    val (Q, K) = readLine()!!.split(" ").map { it.toInt() }

    // Compute distance from K for each node
    // Kを単一始点として、最短距離を求める。
    // O (ElogV) = (ELogE)
    //val distanceFromK = dijkstra(graph, K - 1)

    // DFS O(2N)
    val d = LongArray(N)
    val defaultValue = Long.MAX_VALUE
    d.fill(defaultValue);
    d[K-1] = 0
    fun dfs(current: Int) {
        graph[current].forEach { edge ->
            if (d[edge.to] == defaultValue) {
                d[edge.to] = d[current] + edge.distance
                dfs(edge.to)
            }
        }
    }
    dfs(K-1)

    // Process queries O(Q)
    for (i in 0 until Q) {
        val (x, y) = readLine()!!.split(" ").map { it.toInt() }
        val xk = d[x - 1]
        val ky = d[y - 1]
        println(xk + ky)
    }
}

Measured memory_bytes: 111888
// 2014/05/23 Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		int i[1000], p[1000], q[1000], r[1000];
		for(int j=0; j<n; j++){
			cin >> i[j] >> p[j] >> q[j] >> r[j];
		}

		int P, Q, R, C;
		cin >> P >> Q >> R >> C;

		bool flg = false;

		for(int j=0; j<n; j++){
			if(p[j]<=P && q[j]<=Q && r[j]<=R && 4*p[j]+9*q[j]+4*r[j]<=C){
				cout << i[j] << endl;
				flg = true;
			}
		}

		if(!flg){
			cout << "NA" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1176
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string s;
  cin >> s;
  vector<int>a(75);
  rep(i,s.size()){
    a.at(s.at(i)-'0')++;
  }
  int flag=0;

  for(int i = 49; i<=74;i++){
    if(a.at(i)==0){
      flag = 1;
      cout << char(i+48) << endl;
      break;
    }
  }
  if(flag==0) cout << "None"<<endl;
}

Measured memory_bytes: 512