akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define N 20
#define Q 200

int USA(int , int);
int n, A[N];

int main(){
  int i, q, M[Q];

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

  for(i=0 ; i<q ; i++){
    if( USA(0, M[i]) == 1)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int USA(int i, int m){
  int res;
  if(m == 0)return 1;
  else if(i>=n) return 0;

  res = USA(i+1,m) || USA(i+1,m-A[i]);
  
  return res;
     
}




Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

// ソートする
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, t;
  cin >> n >> t;
  vector<pair<int, int>> dishes(n+1);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    dishes[i+1] = make_pair(a, b);
  }

  sort(ALL(dishes));

  // 1~i 番目の料理で j 分以内に完食できる美味しさの合計の最大値
  vector<vector<ll>> dp1(n+2, vector<ll>(t+1, 0));
  for (int i = 1; i < n+1; i++) {
    rep(j, t+1) {
      if (dishes[i].first > j) {  // 食べ終わらない
        dp1[i][j] = dp1[i-1][j];
      } else {
        dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-dishes[i].first] + dishes[i].second);
      }
    }
  }

  ll ans = 0;
  for (int i = 1; i < n+1; i++) {
    chmax(ans, dp1[i-1][t-1] + dishes[i].second);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

int a[55], b[55];
ll dp[55][55];
map<ll, ll, std::greater<ll> >mp;
int main(int argc, char const *argv[])
{
    // freopen("input.txt", "r", stdin);
    int N, A, B;
    cin>>N;
    for (int i = 0; i < N; ++i)
    {
        cin>>a[i];
        b[i] = a[i];
    }
    sort(a, a+N);
    int res = 0;
    for (int i = 0; i < N; ++i)
    {
        if(b[i] != a[i])res ++;
    }
    if(res <= 2)cout << "YES\n";
    else cout << "NO\n";
    return 0;
}


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

using namespace std;
typedef long long ll;
ll lenth(ll x)
{
    ll f=0;
    while(x>0)
    {
        x/=10;
        f++;
    }
    return f;
}
int main()
{
    ll n,c=0;
    cin >> n ;
    n++;
    while(n--)
    {
        if(lenth(n)%2==1)
            c++;
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
HRR = list(map(int,input().split()))


def calculate(n, hrr):

    result = []

    for index,value in enumerate(hrr):

        if index == 0:
            result.append(0)
        elif index == 1:
            result.append(abs(hrr[index]-hrr[index-1]) + result[index-1])
        else:
            s1 = abs(hrr[index] - hrr[index-1]) + result[index - 1]
            s2 = abs(hrr[index] - hrr[index-2]) + result[index - 2]
            result.append(min(s1,s2))

    print(result[-1])

calculate(N,HRR)


Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main(){
    // ll N,S,K;
    ll n,u,v;
    cin >>n >>u >>v;

    vector<pair<ll,ll>> e(n);
    vector<vector<ll>> e_n(n,vector<ll>());

    for (ll i = 0; i < n; i++){
        ll a,b;
        cin >> a >>b;
        e[i] = make_pair(a-1,b-1);
        e_n[a-1].push_back(b-1);
        e_n[b-1].push_back(a-1);
    }

    vector<ll> up(n,-1);
    vector<ll> vp(n,-1);

    ll dist =-1;

    u--;
    v--;
    vector<ll> tmp;
    tmp.push_back(u);
    ll count = 0;
    while(tmp.size()>0){
        vector<ll> tmp2;
        for(auto m:tmp){
            up[m] = count;
            if (m==v){
                dist = count;
            }
            for(auto k: e_n[m]){
                if (up[k]==-1){
                    tmp2.push_back(k);
                }
            }
        }
        tmp = tmp2;
        count++;
    }

    tmp.clear();
    tmp.push_back(v);
    count = 0;
    while(tmp.size()>0){
        vector<ll> tmp2;
        for(auto m:tmp){
            vp[m] = count;
            for(auto k: e_n[m]){
                if (vp[k]==-1){
                    tmp2.push_back(k);
                }
            }
        }
        tmp = tmp2;
        count++;
    }


    ll ans =0;
    vector<ll> ap(n,-1);

    tmp.clear();
    tmp.push_back(u); //高橋君 きるだけ遅くゲームが終了
    count = 0;
    while(tmp.size()>0){
        vector<ll> tmp2;
        for(auto m:tmp){
            ap[m] = count;
            if (ans < vp[m])ans=vp[m];
            for(auto k: e_n[m]){ //kは隣接したノード
                if (ap[k]==-1 && up[k] < vp[k]){ //逃げられるなら
                    tmp2.push_back(k);
                }
            }
        }
        tmp = tmp2;
        count++;
    }

    ans--;

    cout << ans;

}




Measured memory_bytes: 10596
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	for(int i=1; i<10; i++){
		for(int j=1; j<10; j++){
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}

	return 0;
}

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

// #define multitest 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<int> V(n);
	for (int &x : V)
		cin >> x;
	auto L = V;
	sort(V.begin(), V.end());
	int max1 = V[n - 1], max2 = V[n - 2];
	for (int i = 0; i < n; ++i)
		if (L[i] == max1)
			cout << max2 << '\n';
		else
			cout << max1 << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef TIME
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

int is_win (char a,char b){
  switch (a)
  {
      case 'r':
        switch (b)
        {
            case 'r':
              return 0;
            case 's':
              return -1;
            case 'p':
              return 1;
        }
        break;
      case 's':
        switch (b)
        {
            case 'r':
              return 1;
            case 's':
              return 0;
            case 'p':
              return -1;
        }
        break;
      case 'p':
        switch (b)
        {
            case 'r':
              return -1;
            case 's':
              return 1;
            case 'p':
              return 0;
        }
        break;
  }
  return -2;
}
void solve(long long N, long long K, long long R, long long S, long long P, std::string T){
  ll ans=0;
  string x="";
  REP(N){
    if(i<K||T[i]!=T[i-K]||is_win(T[i-K],x[i-K])!=1){
      switch (T[i])
      {
      case 'r':
        x+='p';
        ans+=P;
        break;
      case 's':
        x+='r';
        ans+=R;
        break;
      case 'p':
        x+='s';
        ans+=S;
        break;
      }
    }else{
      x+=T[i];
    }
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long R;
    scanf("%lld",&R);
    long long S;
    scanf("%lld",&S);
    long long P;
    scanf("%lld",&P);
    std::string T;
    std::cin >> T;
    solve(N, K, R, S, P, T);
    return 0;
}


Measured memory_bytes: 640
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
  s = input()
  if s == "AC":
    ac += 1
  elif s == "WA":
    wa += 1
  elif s == "TLE":
    tle += 1
  else:
    re += 1
print(f'AC x {ac}\nWA x {wa}\nTLE x {tle}\nRE x {re}')

Measured memory_bytes: 9140
s = input()

acgt = 'ACGT'

max_len = 0
for i in range(len(s)):
    j = 0
    while True:
        if i + j >= len(s) or s[i + j] not in acgt:
            if max_len < j:
                max_len = j
            break
        j += 1

print(max_len)


Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>

struct Point {double x, y;};

void koch(int n, Point a, Point b){
    if(n == 0) return;
    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}

int main(){
    Point a, b;
    int n;

    scanf("%d", &n);

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);

    return 0;
}


Measured memory_bytes: 2700
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int x,y;
	int ans;
	int i;
	cin>>x>>y;
	ans=(x-1)+(y-1)+2;
	for(i=1;i<y;i++){
		if(x*i%y==0){
			//cout<<i<<endl;
			ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int main(){
  int r,g,b,n;
  cin >> r >> g >> b >> n;
  int i,j;
  int ans = 0;
  for(i=0;i<=n;i++){
    if(r*i>n)break;
    for(j=0;j<=n;j++){
      if(r*i+g*j>n)break;
      else if((n-r*i-g*j)%b==0)ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <iomanip>


using namespace std;

int dp[21][50001]; // i ????????§j?????????????°?????????°?????????

int main() {
	int n,m;

	cin >> n >> m;


	int d[m];

	for (int i = 0; i < m; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < m + 1; i++) {
		for(int j = 0; j <= n; j++) {
			dp[i][j] = INT_MAX;
		}
	}

	for (int i = 1; i < m + 1; i++) {
		int curD = d[i - 1];

		for(int j = 1; j <= n; j++) {
			if (j % curD == 0) {
				dp[i][j] = j / curD; 
			} else {
				dp[i][j] = INT_MAX;
			}
			dp[i][j] = min(dp[i-1][j],dp[i][j]);

			if (j - curD > 0) {
				if (dp[i-1][j-curD] != INT_MAX) {
					dp[i][j] = min(dp[i][j] ,dp[i-1][j-curD] + 1);
				}
				if (dp[i][j-curD] != INT_MAX) {
					dp[i][j] = min(dp[i][j] ,dp[i][j-curD] + 1);
				}
			}
		}
	}

	cout << dp[m][n] << endl;
/*
	for (int i = 1; i < m + 1; i++) {
		for(int j = 1; j <= n; j++) {
			if (dp[i][j] == INT_MAX) {
				cout << setw(4) << -1;
			} else {
				cout << setw(4) << dp[i][j];
			}
		}
		cout << endl;
	}
*/

	return 0;
}

Measured memory_bytes: 5260
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


int main(){
	int n;
	cin >> n;
	for(int i=111;i<=999;i+=111){
		if(n<=i){
			cout << i << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,a,b,ans;
  cin>>n>>a>>b;
  ans = 0;
  ans = n/(a+b) * a;
  n %= a+b;
  ans += min(n, a);
  cout<<ans<<endl;
  return 0;
}

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

struct Node {
    int index = -1;
    int depth = -1;
    int parent = -1;
    int *child;
    int ccnt = 0;
    int type = 0;
};

void depth(Node *node, int x, int d) {
    node[x].depth = d;
    for (int i = 0; i < node[x].ccnt; ++i) {
        depth(node, node[x].child[i], d+1);
    }
}

int Root(Node *node, int x) {
    if (node[x].parent > -1) {
        Root(node, node[x].parent);
    } else {
        return x;
    }
}

int main() {
    int n, b, x, y, root;
    string child;
    string type[] = {"leaf", "internal node", "root"};
    cin >> n;
    Node a[n];
    for (int i = 0; i < n; ++i) {
        cin >> x >> y;
        a[x].index = x;
        a[x].child = new int[y];
        a[x].ccnt = y;
        for (int j = 0; j < y; ++j) {
            cin >> b;
            a[x].child[j] = b;
            a[x].type = 1;
            a[b].parent = x;
        }
    }
    
    root = Root(a, 0);
    a[root].type = 2;
    depth(a, root, 0);
    
    for (auto& i : a) {
        cout << "node " << i.index << ": ";
        cout << "parent = " << i.parent << ", ";
        cout << "depth = " << i.depth << ", ";
        cout << type[i.type] << ", ";
        child = "[";
        for (int j = 0; j < i.ccnt-1; ++j) {
            child += to_string(i.child[j]) + ", ";
        }
        if (i.ccnt) { 
            child += to_string(i.child[i.ccnt-1]) +  "]\n";
        } else {
            child += "]\n";
        }
        cout << child;
    }
    
    return 0;
}

Measured memory_bytes: 10624
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n=sc.nextInt();
        int []nums=new int[n];
        int count=0;

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

        for(int i=0;i<n;i+=2)
        {
            if(i%2==0&&nums[i]%2==1){
            count++;

            }
        }

        System.out.println(count);

    }
}




Measured memory_bytes: 35664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
const ll mod=1e9 + 7;
ll power(ll a,ll n)
{
        ll ans=1;
        a=a%mod;
        while(n>0)
        {
                if(n%2==1)
                {
                        ans=(ans*a)%mod;
                }
                n=n/2;
                a=(a*a)%mod;
        }
        return ans;
}
bool comp(pair<ll,ll> &a,pair<ll,ll> &b)
{
        if(a.ff==b.ff)
        {
                return a.ss<b.ss;
        }
        return a.ff<b.ff;
}
int main()
{
    ll n;
    cin>>n;
    ll t=0;
    vector<pair<ll,ll> > p;
    for(int i=0;i<n;i++)
    {
            ll a,b;
            cin>>a>>b;
            p.pb(mp(b,a));
    }
    sort(p.begin(),p.end(),comp);
    for(int i=0;i<n;i++)
    {
            if(t+p[i].ss<=p[i].ff)
            {
                    t=t+p[i].ss;
            }
            else
            {
                    cout<<"No";
                    return 0;
            }
            //cout<<t<<endl;
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N,D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));;
    REP(i, N) {
        REP(j, D) {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    REP(i, N) {
        FOR(j, i+1, N) {
            int dist = 0;
            REP(k, D) {
                dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            //cout << (int)floor(sqrt((double)dist));
            if((int)floor(sqrt((double)dist)) * (int)floor(sqrt((double)dist)) == dist) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

int d[61][200001];
int main() {
    ll N, K, t=1;
    cin >> N >> K;
    rep1(i,N) cin >> d[0][i];
    rep(b,60) rep1(i,N)
        d[b+1][i] = d[b][d[b][i]];
    rep(i,60)
        if (K & (1LL << i)) t = d[i][t];
    cout << t << endl;
}


Measured memory_bytes: 51260
#include<stdio.h>

int num[2];

void swap_num(int i, int j) {
	int temp = num[i];
	num[i] = num[j];
	num[j] = temp;
}

void compare_min(){
	if (num[0] > num[1]) swap_num(0, 1);
	if (num[1] > num[2]) swap_num(1, 2);
	if (num[0] > num[1]) swap_num(0, 1);
}

int main() {
	scanf("%d%d%d", &num[0], &num[1], &num[2]);
	compare_min();
	printf("%d %d %d\n", num[0], num[1], num[2]);

	return 0;
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, x, y;
	cin >> n >> x >> y;
	x--;
	y--;
	vector<int> ans(n);
	int q[10000];
	for (int beg = 0; beg < n; ++beg) {
		int b = 0;
		int e = 1;
		vector<int> d(n, -1);
		q[0] = beg;
		d[beg] = 0;
		while (b < e) {
			int cur = q[b++];
			ans[d[cur]]++;
			if (cur > 0 && d[cur - 1] == -1) {
				q[e++] = cur - 1;
				d[cur - 1] = d[cur] + 1;
			}
			if (cur < n - 1 && d[cur + 1] == -1) {
				q[e++] = cur + 1;
				d[cur + 1] = d[cur] + 1;
			}
			if (cur == x && d[y] == -1) {
				q[e++] = y;
				d[y] = d[cur] + 1;
			}
			if (cur == y && d[x] == -1) {
				q[e++] = x;
				d[x] = d[cur] + 1;
			}
		}
	}
	for (int i = 1; i < n; ++i) {
		cout << ans[i] / 2 << endl;
	}
}

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


int main() {
    int a,b,c;
    cin>>a>>b>>c;
    
    if(a<b){
        swap(a,b);
        if(b<c){
            swap(b,c);
            if(a<b){
                swap(a,b);
            }
        }
    }
    else{
        if(b<c){
            swap(b,c);
            if(a<b){
                swap(a,b);
            }
        }
    }
    
    cout<<b+c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstdio>

using namespace std;

int main()
{
    double x1, x2, y1, y2;

    cin >> x1 >> y1 >> x2 >> y2;

    printf("%.8lf\n", sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)));

}




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

int main(){
    int n,a;
    int _max = 1,count = 0;

    cin >> n;

    for(int i=0; i<n; i++){
        cin >> a;
        if(_max == a){
            _max++;
        }else{
            count++;
        }
    }
    if(count == n){
        cout << -1 << endl;
    }else{
        cout << count << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

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

string s[10], t[10];
bool same[10];
bool used[10];
int a[5];

vector<string> x;

set<vector<string>> ans;

void check(){
	int ret = 0;
	rep(i, 1 << 5){
		rep(j, 5){
			if (i&(1 << j)){
				rep(k, 5) x[k][j] = '1' - s[a[j]][k] + '0';
			}
			else{
				rep(k, 5) x[k][j] = '1' - t[a[j]][k] + '0';
			}
		}
		int cnt[10] = {};
		rep(j, 5) rep(k, 10){
			if (used[k]) continue;
			if (x[j] == s[k] || x[j] == t[k]){
				cnt[k] = 1;
				break;
			}
		}
		if (accumulate(cnt, cnt + 10, 0) == 5){
			ans.insert(x);
		}
	}
}

void dfs(int n){
	if (n == 5){
		check();
		return;
	}
	rep(i, 10){
		if (used[i]) continue;
		used[i] = true;
		a[n] = i;
		dfs(n + 1);
		used[i] = false;
	}
	return;
}

int main(){
	x.resize(5);
	rep(i, 5) x[i].resize(5);
	while (1){
		ans.clear();
		cin >> s[0];
		if (s[0] == "END") break;
		FOR(i, 1, 10) cin >> s[i];
		rep(i, 10) t[i] = string(REV(s[i]));
		rep(i, 10) if (s[i] == t[i]) same[i] = 1;

		dfs(0);
		cout << ans.size()/8 << endl;
	}

	return 0;
}

Measured memory_bytes: 1284
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	printf("%.8lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}



Measured memory_bytes: 2684
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

		String line = sc.nextLine();

		int[] num = new int[4];
		StringBuilder sb = new StringBuilder();

		num[0] = Character.getNumericValue(line.charAt(0));
		num[1] = Character.getNumericValue(line.charAt(1));
		num[2] = Character.getNumericValue(line.charAt(2));
		num[3] = Character.getNumericValue(line.charAt(3));

		// A [0] B [1] C [2] D
		// フラグはマイナスを管理
		for (int i = 0; i < (1<<3); i++) {
			int sum = num[0];
			for (int j = 0; j < 3; j++) {
				if ((i & (1<<j)) != 0) {
					sum -= num[j+1];
				} else {
					sum += num[j+1];
				}
			}

			if (sum == 7) {
				sb.append(num[0]);
				for (int j = 0; j < 3; j++) {
					if ((i & (1<<j)) != 0) {
						sb.append("-").append(num[j+1]);
					} else {
						sb.append("+").append(num[j+1]);
					}
				}
				sb.append("=7");
				break;
			}
		}

		System.out.println(sb.toString());
	}

	static class FastScanner {

		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }

	}


}


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

using namespace std;

long long gcd(long long a,long long b){
	if(a>b) swap(a,b);
	while(a>0){
		b%=a;
		if(b==0) return a;
		a%=b;
	}
	return b;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long n,x,d;
	cin >> n >> x >> d;
	if(x==0 && d==0){
		cout << 1 << "\n";
		return 0;
	}
	if(d==0){
		cout << (n+1) << "\n";
		return 0;
	}
	long long g=gcd(abs(x),abs(d));
	x/=g,d/=g;
	if(d<0){
		d*=-1,x*=-1;
	}
	long long res=0;
	multiset<pair<long long,pair<long long,long long>>> st;
	for(long long i=0;i<=n;i++){
		//x*i+i(i-1)/2*d .. x*i+((n-1)n/2-(n-i-1)(n-i)/2)*d
		
		long long v1=x*i+(i*(i-1)/2)*d;
		long long v2=x*i+((n-1)*n/2-(n-i-1)*(n-i)/2)*d;
		st.insert(make_pair(i%d,make_pair(v1,v2)));
	}
	for(int i=0;i<=n;i++){
		if(i==d) break;
		long long right=-(1LL<<60),left=right+1;
		pair<long long,pair<long long,long long>> key=make_pair(i,make_pair(right,left));
		auto itr=st.lower_bound(key);
		while(itr!=st.end()){
			auto p0=*itr;
			if(p0.first!=i) break;
			if(p0.second.first<=right){
				right=max(right,p0.second.second);
			}else{
				if(right>=left) res+=(right-left)/d+1;
				left=p0.second.first;
				right=p0.second.second;
			}
			itr++;
		}
		if(right>=left) res+=(right-left)/d+1;
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
#include <utility>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;




int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, n)cin >> v[i];
    sort(v.begin(), v.end());
    double ans = 0;
    ans = (v[0] + v[1]) / 2;
    rep(i, n-2) {
        ans = (ans + v[i + 2]) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
int main(){
  int i,j,n,R[200000],minv,maxv;
 
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
    if(R[i]<1 || R[i]>1000000000){
      exit(8);
    }
  }
 
  maxv=R[1]-R[0];
  minv=R[0];
 
  for(j=1;j<n;j++){
    if(maxv<R[j]-minv){
      maxv=R[j]-minv;
    }else if(maxv>R[j]-minv){
      maxv=maxv;
    }
 
    if(minv>R[j]){
      minv=R[j];
    }else if(minv<R[j]){
      minv=minv;
    }
  } 
 
  printf("%d\n",maxv);
 
  return 0;
}

Measured memory_bytes: 1376
#include <stdio.h>

int a[200001],b[200001], A[200001], Adash[200001],B[200001],Bdash[200001];

void propagate(int i, int parent, long counter[]){
  int x = A[i], y = B[i];
  while (x != -1){
    if (b[x] != parent){
      counter[b[x]] += counter[i];
      propagate(b[x], i, counter);
    }
    x = Adash[x];
  }
  while (y != -1){
    if (a[y] != parent){
      counter[a[y]] += counter[i];
      propagate(a[y], i, counter);
    }
    y = Bdash[y];
  }
  return;
}

int main(void)
{
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i = 0; i <= n; i++){
    A[i] = -1;
    Adash[i] = -1;
    B[i] = -1;
    Bdash[i] = -1;
  }
  for (int i = 0; i < n - 1; i++){
    scanf("%d %d", &a[i], &b[i]);
    Adash[i] = A[a[i]];
    A[a[i]] = i;
    Bdash[i] = B[b[i]];
    B[b[i]] = i;
  }
  
  long counter[n + 1];
  for (int i = 1; i <= n; i++){
    counter[i] = 0;
  }
  for (int i = 0; i < q; i++){
    int ind, add;
    scanf("%d %d", &ind, &add);
    counter[ind] += add;
  }

  propagate(1, -1, counter);
  
  for(int i = 1; i <= n; i++){
    printf("%ld ", counter[i]);
  }
  return 0;
}

Measured memory_bytes: 24192
#include <stdio.h>
#include <iostream>
#include <string>
int main(void)
{
	int A, B,S;
	char op;
	std::cin >> A >> op >> B;
	if (op == '+')
	{
		S = A + B;
		std::cout << S;
	}
	else if (op == '-')
	{
		S = A - B;
		std::cout << S;
	}

	return 0;
}
	

		
	

Measured memory_bytes: 256
n = gets.to_i
cards = {}
n.times do
  cards[gets.chomp] = 1
end

for m in ["S", "H", "C", "D"] do
  for i in 1..13 do
    card = m + " " + i.to_s
    if !cards.has_key?(card) then
      puts card
    end
  end
end



Measured memory_bytes: 6856
#include<iostream>

using namespace std;
bool search(int A[],int n,int key){
	int i=0;
	while(i<n && A[i]!=key) i++;
		
	return i<n;
}
int main(){
	int n,m;
	cin>>n;
	int* S=new int[n];
	for(int i=0;i<n;++i)cin>>S[i];
	cin>>m;
	int *T=new int[m];
	for(int i=0;i<m;++i)cin>>T[i];
	int sum=0;
for(int j=0;j<m;++j)
	if(search(S,n,T[j]))sum++;
    cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3100
// AOJ 1015: Dominating Set
// 2018.1.18 bal4u

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

int n, ans;
int to[31][31], hi[31];
char black[31], done[31];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int check()
{
	int i, j;

	for (i = 0; i < n; i++) {
		if (black[i]) continue;
		for (j = 0; ; j++) {
			if (j == hi[i]) return 0;
			if (black[to[i][j]]) break; 
		}
	}
	return 1;
}

void calc(int k, int cost)
{
	if (cost >= ans) return;

	if (k == n) {
		if (check()) ans = cost;
		return;
	}

	if (done[k]) calc(k+1, cost+black[k]);
	else {
		black[k] = 0, calc(k+1, cost);
		black[k] = 1, calc(k+1, cost+1);
	}
}

int main()
{
	int m, a, b;

	while (n = in()) {
		memset(hi, 0, sizeof(hi));

		m = in(); while (m--) {
			a = in(), b = in();
			to[a][hi[a]++] = b, to[b][hi[b]++] = a;
		}

		memset(black, 0, sizeof(black));
		memset(done, 0, sizeof(done));
		for (a = 0; a < n; a++) {
			if (done[a]) continue;
			if (!hi[a]) black[a] = 1, done[a] = 1;
			else if (hi[a] == 1) {
				b = to[a][0], black[b] = 1, done[a] = done[b] = 1;
			}
		}
		ans = n;
		calc(0, 0);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2040
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf (int)(1e9)
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

ll a[2222];
ll b[2222];
int main(void){
  ll n,x;
  cin>>n>>x;
  for(int i=1;i<=n;i++) {cin>>a[i];b[i]=a[i];}
  a[0]=a[n];
  ll res=(ll)1e16;
  for(int i=0;i<n;i++){
    ll tmp=0;
    for(int j=1;j<=n;j++){
      b[j]=min(b[j],a[(j-i+n)%n]);
    }
    for(int j=1;j<=n;j++) tmp+=b[j];
    res=min(res,tmp+x*i);
  }
  
  
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(0);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin>>s;
    int ans=inf;
    rep(i,s.length()-2){
        int t=0;
        rep(j,3){
            t=t*10+s[i+j]-'0';
        }
        ans=min(ans,abs(t-753));
    }
    cout<<ans<<endl;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int A,B;
    cin >> A >> B;

    if(A < 9 && B < 9) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <deque>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,r;
	
	while(cin >> n >> r , n){
		deque<int> card(n);
		rep(i,n)card[n-i-1]=i+1;

		rep(i,r){
			int p,c;
			cin >> p >> c;
			deque<int> t(c);
			rep(j,c)t[j] = card[p-1+j];
			rep(j,c)card.erase( remove(card.begin(),card.end(),t[c-1-j]),card.end() );
			rep(j,c)card.push_front(t[c-1-j]);
		}
		cout << card[0] << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    string s;
    cin>>s;
    vector<int>w,r;
    for (int i=0; i<x; i++)
    {
        if (s[i]=='R')
            r.push_back(i);
        else
            w.push_back(i);
    }
    int cnt=0,rr=r.size(),ww=w.size();
    for (int i=0; i<w.size(); i++)
    {
        if (r.empty())
            break;
        if (r.back()<w[i])
            break;
        cnt++;
        r.pop_back();
    }
    cout<<min({cnt,rr,ww});
    return 0;
}


Measured memory_bytes: 4600
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;

int main()
{
    char ch[100005];
    scanf("%s",ch);
    int flag=1;
    int ans=0;
    for(int i=0,j=strlen(ch)-1; i<=j;)
    {
        if(ch[i]==ch[j])
        {
            i++,j--;
        }
        else
        {
            if(ch[i]=='x')
            {
                i++;
                ans++;
            }
            else if(ch[j]=='x')
            {
                j--;
                ans++;
            }
            else
            {
                flag=0;
                break;
            }
        }
    }
    if(flag==0)
    {
        printf("-1\n");
    }
    else
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384
from sys import stdin
def input():
    return stdin.readline().strip()

h, w = map(int, input().split())
s = [input() for _ in range(h)]

def check(x, y, up, down, left, right):
    if s[x][y] == '.':
        return 0
    if up and s[x-1][y] == '#':
        return 0
    if down and s[x+1][y] == '#':
        return 0
    if left and s[x][y-1] == '#':
        return 0
    if right and s[x][y+1] == '#':
        return 0
    else:
        print('No')
        exit()

# (0, y)
check(0, 0, False, True, False, True)
for y in range(1, w-1):
    check(0, y, False, True, True, True)
check(0, w-1, False, True, True, False)

# (x, y)
for x in range(1, h-1):
    check(x, 0, True, True, False, True)
    for y in range(1, w-1):
        check(x, y, True, True, True, True)
    check(x, w-1, True, True, True, False)

# (h-1, y)
check(h-1, 0, True, False, False, True)
for y in range(1, w-1):
    check(h-1, y, True, False, True, True)
check(h-1, w-1, True, False, True, False)

print('Yes')

Measured memory_bytes: 67272
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var N, M int
var matrix [8][]int
var ans int

func dfs(done []bool, now, depth int) {
	//再帰の終了条件
	if depth == N-1 {
		ans++
		return
	}

	//訪問中の点を、訪問済みにする
	done[now] = true

	//次の候補について
	for _, nv := range matrix[now] {
		//訪問済みの場合はスキップ
		if done[nv] {
			continue
		}
		//未訪問の場合は、再帰呼び出し
		dfs(done, nv, depth+1)
	}

	//次の候補が無くなったら、自分を未訪問として、おわり
	done[now] = false
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M = nextInt(), nextInt()

	for i := 0; i < M; i++ {
		var a, b int
		a, b = nextInt(), nextInt()
		a--
		b--
		matrix[a] = append(matrix[a], b)
		matrix[b] = append(matrix[b], a)
	}

	done := make([]bool, N)
	ans = 0
	dfs(done, 0, 0)

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	char s[100];
	scanf("%s",s);
	int n=strlen(s);
	int gg=s[n-1]-'0';
	if(gg==2||gg==4||gg==5||gg==7||gg==9)
	{
		cout<<"hon"<<endl;
	}else if(gg==0||gg==1||gg==6||gg==8){
		cout<<"pon"<<endl;
	}else if(gg==3){
		cout<<"bon"<<endl;
	}
	
 	return 0;
}

Measured memory_bytes: 3760
N = int(input())
A = list(map(int, input().split()))

def solve():
    n = 0
    for a in A:
        if a % 2 == 1:
            n += 1

    if n % 2 == 0:
        return True
    return False

if solve():
    print('YES')
else:
    print('NO')


Measured memory_bytes: 14108
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

struct point{
    float x,y;
};

void kehe(point a,point b,int n){
    if(n==0){
        if(fabs(a.x-0.0)<0.000001)printf("%.6f %.6f\n",a.x,a.y);
        printf("%.6f %.6f\n",b.x,b.y);
    }
    else{
        double pi=M_PI/3.0;
        point p1,p2,p3;
        p1.x=2*a.x/3+b.x/3;
        p1.y=2*a.y/3+b.y/3;
        p3.x=a.x/3+2*b.x/3;
        p3.y=a.y/3+2*b.y/3;
        kehe(a,p1,n-1);
        p2.x=p1.x+(p3.x-p1.x)*cos(pi)-(p3.y-p1.y)*sin(pi);
        p2.y=p1.y+(p3.x-p1.x)*sin(pi)+(p3.y-p1.y)*cos(pi);
        kehe(p1,p2,n-1);
        kehe(p2,p3,n-1);
        kehe(p3,b,n-1);
    }
}

int main()
{
    int n;
    cin>>n;
    point a,b;
    a.x=0.0;a.y=0.0;
    b.x=100.0;b.y=0.0;
    kehe(a,b,n);
    return 0;
}
//int main(){
//    cout<<M_PI<<endl;
//    return 0;
//}

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

int main(){
  int ans = 0;
  int N;
  cin >> N;
  int K;
  cin >> K;
  string S;
  cin >> S;
  
  vector<int> Nums;
  int now = 1;//今見ている数
  int cnt = 0;//nowがいくつ並んでいるか
  for(int i=0;i<N;i++){
    if (S[i] == (char)('0' + now)) cnt++;
    else{
      Nums.push_back(cnt);
      now = 1 - now; //0と1を切り替える時の計算 now ^= 1;
      cnt = 1;
    }
  }
  if(cnt!=0) Nums.push_back(cnt);
  //1-0-1-0-1って感じの配列が欲しい
  //1-0-1-0みたいに0で終わってたら、適当に一つたす
  if(Nums.size() % 2 == 0) Nums.push_back(0);
  
  vector<int> sum(Nums.size() + 1);
  for(int i=0;i<Nums.size();i++){
    sum[i+1] = sum[i] + Nums[i];
  }
  int Add = 2 * K + 1;
  for(int i=0;i< Nums.size();i+=2){
    int tmp = 0;
    
    int left = i;
    int right = min(i+Add,(int)Nums.size());
    tmp = sum[right] - sum[left];
    
    ans = max(tmp,ans);
  }
  cout << ans << endl;
}
          
      


Measured memory_bytes: 1272
from collections import Counter

n = int(input())
aa = list(map(int,input().split()))

da = [ai//400 for ai in aa if ai<3200]
over = sum([ai>=3200 for ai in aa])

c = Counter(da)

min_v = max(1,len(c))
max_v = len(c)+over

print(min_v,max_v)

Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

void swap(char* M, int* A, int a, int b) {
    int tmp = A[a];
    A[a] = A[b];
    A[b] = tmp;
    char tmpc = M[a];
    M[a] = M[b];
    M[b] = tmpc;
}

int partition(char* M, int* A, int p, int r) {
    int div = A[r], i=p;
    for (int j=p; j<=r; j++) {
        if (A[j] <= div) {
            i++;
            swap(M, A, i-1, j);
        }
    }
    return i-1;
}

void quick(char* M, int* A, int p, int r) {
    if (p < r) {
        int q = partition(M, A, p, r);
        quick(M, A, p, q-1);
        quick(M, A, q+1, r);
    }
}

char LM[50002], RM[50002];
int LA[50002], RA[50002];

void merge(char* M, int* A, int n, int left, int mid, int right) {
    int i,j,k;
    int n1 = mid-left;
    int n2=right-mid;
    for (i=0; i<n1; i++) {
        LM[i] = M[left+i];
        LA[i] = A[left+i];
    }
    for (i=0; i<n2; i++) {
        RM[i] = M[mid+i];
        RA[i] = A[mid+i];
    }
    LA[n1] = RA[n2] = 2000000000;
    i=j=0;
    for (k=left; k<right; k++) {
        if (LA[i]<=RA[j]) {
            M[k]=LM[i];
            A[k]=LA[i];
            i++;
        } else {
            M[k]=RM[j];
            A[k]=RA[j];
            j++;
        }
    }
}

void mergesort(char* M, int* A, int n, int left, int right) {
    int mid;
    if (left+1<right) {
        mid = (left+right)/2;
        mergesort(M, A, n, left, mid);
        mergesort(M, A, n, mid, right);
        merge(M, A, n, left, mid, right);
    }
}

int main() {
    int n;
    std::cin>>n;
    int N[100001];
    char M[100001];
    int N_ref[100001];
    char M_ref[100001];
    for (int i=0; i<n; i++) {
        std::cin >> M[i] >> N[i];
        M_ref[i]=M[i];
        N_ref[i]=N[i];
    }
    quick(M, N, 0, n-1);
    mergesort(M_ref, N_ref, n, 0, n);
    bool stable = true;
    for (int i=0; i<n; i++) {
        if (M[i] != M_ref[i]) {
            stable = false;
        }
    }
    if (stable) {
        std::cout << "Stable" << std::endl;
    } else {
        std::cout << "Not stable" << std::endl;
    }
    for (int i=0; i<n; i++) {
        std::cout << M[i] << " " << N[i] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 4564
#include<iostream>
#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 what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
int n;
int p;
int* a;



void solve(){
	ll dp[2][n];
	FOR(i,2) FOR(j,n) dp[i][j]=0;
	a=new int[n];
	FOR(i,n) cin >> a[i];
	FOR(j,n)
		FOR(i,2){
			if(j==0){
				if(i==0) dp[i][j]=(a[j]%2==0)? 2: 1;
				else dp[i][j]=(a[j]%2==1) ? 1:0;
			}
			else
			dp[i][j]=(a[j]%2==0)? dp[i][j-1] + dp[i][j-1] : dp[(i+1)%2][j-1]+dp[i][j-1];
		}
	cout << dp[p][n-1];
}

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

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        
        ArrayList<Integer> p1 = new ArrayList<Integer>();
        ArrayList<Integer> p2 = new ArrayList<Integer>();

        for(int i=0;i<N;i++){
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        }

        Collections.sort(p2);

        int counter = 0;
        int c = 0;
        boolean r = false;
        for(int i=0;i<N;i++){
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        }

        
        if(counter == 3)
            System.out.println("NO");
        else{
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        }
    }
}

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

typedef long long ll;

const int maxn = 1e5 + 10;

int n;

ll A[maxn], B[maxn];

ll solve() {
    ll ans = 0;
    
    for(int i = n; i >= 1; --i) {
	A[i] += ans;

	if(A[i] && A[i] < B[i]) 
	    ans += B[i] - A[i];
	else
	    ans += (B[i] - (A[i] % B[i])) % B[i];
    }

    return ans;
}

int main() {
    cin >> n;

    for(int i = 1; i <= n; ++i)
	cin >> A[i] >> B[i];

    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1792