akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define rep(i, n) for(int i=0; i<n; i++)

  
int main(){
 string n;
  cin >> n ;
  int l=n.size();
  VI nn(l);
  int s=0;
  
  rep(i,l){
   nn.at(i)=n.at(i)-48;
    s+=nn.at(i);
  }
  vector<ll> NN(l);
  ll N=0;
  rep(i,l){
    NN.at(i)=pow(10,l-i-1)*nn.at(i);
    N+=NN.at(i);
  }
  if(N%s==0) cout << "Yes" << endl;
  else if(N%s!=0) cout <<"No" <<endl;
}

Measured memory_bytes: 256
k = gets.split(" ").map{|t| t.to_i}
a = gets.split(" ").map{|t| t.to_i}.sort.reverse
b = gets.split(" ").map{|t| t.to_i}.sort.reverse
c = gets.split(" ").map{|t| t.to_i}.sort.reverse
 
if k[0] >= k[3] then
  ak = k[3]
else
  ak = k[0]
end
  
if k[1] >= k[3] then
  bk = k[3]
else
  bk = k[1]
end
  
if k[2] >= k[3] then
  ck = k[3]
else
  ck = k[2]
end
  
kari = Array.new
ak.times{|n|
bk.times{|m|
    kari.push(a[n]+b[m])
    }}
 
  
if kari.count >= k[3] then
  kk = k[3]
else
  kk = kari.count
end
  
kari.sort!.reverse!
kotae = Array.new
kk.times{|n|
    ck.times{|m|
        kotae.push(kari[n]+c[m])
        }}
 
kotae.sort!.reverse!
puts kotae[0..k[3]-1]


Measured memory_bytes: 70132
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  long long int H, ans;
  cin >> H;
  ans = 1;
  for (;;) {
    H /= 2;
    ans *= 2;
    if (H <= 0) {
      break;
    }
  }
  --ans;
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int H, W;
    cin >> H >> W;
    int h, w;
    cin >> h >> w;

    cout << H * W - ( H * w + W * h - ( w * h ) ) << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,j=0,k,cnt=0;
    string str;
    cin>>n>>str;
    string str1="ABC";
    for(i=0;i<n-2;i++)
    {
        if((str[i]=='A') && (str[i+1]=='B') && (str[i+2]=='C'))
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    multiset<int> nums;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        nums.insert(a);
    }
    int ans = 0;
    while (!nums.empty())
    {
        int biggest = *--nums.end();
        nums.erase(--nums.end());
        int two = 1 << 30;
        while ((two >> 1) > biggest)
            two >>= 1;
        if (nums.find(two - biggest) != nums.end())
        {
            ans++;
            nums.erase(nums.find(two - biggest));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9600
import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int,input().split()))
l = [((i-1)//n, (i-1) % n) for i in l]
check = [[1]*n for i in range(n)]
d =  [[min(i, n-i-1, j, n-j-1) for j in range(n)] for i in range(n)]

ans = 0
for x,y in l:
    check[x][y] = 0
    ans += d[x][y]
    q = [(x,y,d[x][y])]
    while q:
        bx,by,z = q.pop()

        if bx != 0:
            if d[bx-1][by] > z:
                d[bx-1][by] = z
                q.append((bx-1,by,z+check[bx-1][by]))
        if bx != n-1:
            if d[bx+1][by] > z:
                d[bx+1][by] = z
                q.append((bx+1,by,z+check[bx+1][by]))
        if by != 0:
            if d[bx][by-1] > z:
                d[bx][by-1] = z
                q.append((bx,by-1,z+check[bx][by-1]))
        if by != n-1:
            if d[bx][by+1] > z:
                d[bx][by+1] = z
                q.append((bx,by+1,z+check[bx][by+1]))  
print(ans)



Measured memory_bytes: 196044
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

int main(){
  string s,t; cin >> s >> t;
  int n = s.size(), m = t.size();

  int ans = 100000;
  rep(i,n){
    string ss = s.substr(i,m);
    if (ss.size()<m) continue;
    int cnt = 0;
    rep(j,m){
      if (ss[j]!=t[j]) cnt++;
    }
    chmin(ans, cnt);
  }
  cout << ans << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define ll long long int
using namespace std;
int x[100010];

int main() {
	int Q, N;
	ll sum = 0;
	cin >> N ;
	vector<int> a(N);
	for (int i = 0; i < N; i++){
		cin >> a[i];
	}
	cin >> Q;
	vector<int> b(Q), c(Q);
	for (int i = 0 ; i < Q ; i++){
		cin >> b[i] >> c[i];
	}

	for (int i = 0; i < N; i++){
		x[a[i]]++;
		sum += a[i];
	}
	for (int i = 0; i < Q;i++){
		x[c[i]] += x[b[i]];
		sum = sum + (c[i] - b[i])*x[b[i]];
		x[b[i]] = 0;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
typedef long long ll;
//
int main(){
   int n;cin>>n;
   int ans=n;
   int t=0;
   while(n>0){
      n-=1000;
      t++;
   }
   
   cout<<1000*t-ans<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = int_fast64_t;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,a,b;
    cin >> n;
    if (n == 1) {
        cout << "Hello World" << endl;
    } else {
        cin >> a >> b;
        cout << a + b << endl;
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 768
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      String str = sc.next();
      String[] strArr = str.split(",");
      int[] l = new int[10];
      int d = 0;
      for (int i = 0; i < 10; i++) {
        l[i] = Integer.parseInt(strArr[i]);
        d += l[i];
      }
      int[] v = {Integer.parseInt(strArr[10]),Integer.parseInt(strArr[11])};
      double t = (double)d/(v[0] + v[1]);
      d = 0;
      for(int i = 0; i < 11; i++) {
        if(v[0]*t <= d) {
          System.out.println(i);
          break;
        }
        else {
          d += l[i];
        }
      }
    }
  }
}

Measured memory_bytes: 11000
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  vector<int> cnt(26, 0);
  for (int i = 0; i < H; ++i) {
    cin >> a[i];
    for (int j = 0; j < W; ++j) {
      ++cnt[a[i][j] - 'a'];
    }
  }
  vector<vector<char>> res(H, vector<char>(W, 0));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (!res[i][j]) {
        int needed = 1;
        if (H % 2 == 0 || i != H / 2) {
          needed *= 2;
        }
        if (W % 2 == 0 || j != W / 2) {
          needed *= 2;
        }
        //cout << needed << endl;
        char c = 0;
        for (int i = 0; i < 26; ++i) {
          if (cnt[i] >= needed) {
            //cout << 'a' + i << endl;
            if (!c) {
              c = 'a' + i;
            }
            if (cnt[i] < cnt[c - 'a']) {
              c = 'a' + i;
            }
          }
        }
        //cout << c << endl;
        if (!c) {
          cout << "No\n";
          return 0;
        }
        cnt[c - 'a'] -= needed;
        res[i][j] = c;
        if (H % 2 == 0 || i != H / 2) {
          res[H - i - 1][j] = c;
        }
        if (W % 2 == 0 || j != W / 2) {
          res[i][W - j - 1] = c;
        }
        if ((H % 2 == 0 || i != H / 2) && (W % 2 == 0 || j != W / 2)) {
          res[H - i - 1][W - j - 1] = c;
        }

      }
    }
  }
  cout << "Yes\n";
  //for (auto& v : res) {
  //  for (auto c : v) {
  //    cout << c;
  //  }
  //  cout << "\n";
  //}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    int tmp=n;
    int digit=0;
    while(tmp!=0){
        tmp/=10;
        digit++;
    }
    // cout<<digit<<endl;
    if(digit==1){
        cout<<n<<endl;
    }
    else if(digit==2){
        cout<<9<<endl;
    }
    else if(digit==3){
        cout<<n-99+9<<endl;
    }
    else if(digit==4){
        cout<<909<<endl;
    }
    else if(digit==5){
        cout<<n-9999+900+9<<endl;
    }
    else if(digit==6){
        cout<<90000+900+9<<endl;
    }





    return 0;
}


Measured memory_bytes: 256
// 二分探索法
#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>;
#define INF ll(1e+18)+100;

int main(){
    set<int> s;
    int k;
    cin>>k;
    int x=7%k;
    ll b=7;
    ll i=1;
    while(x%k!=0){
//        int pre=x;
        s.insert(x);
        b*=10;
        x+=b%k;
        x%=k;
        if(s.count(x)){
            cout<<"-1"<<endl;
            return 0;
        }
        b%=k;
        i++;
    }
    /*
    rep(i,20){
                b*=10;
        x+=b%k;
        x%=k;
        b%=k;
        cout<<x%k<<endl;
        i++;
    }
    */
    cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 50424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i < n; i++)
#define ALL(n) begin(n), end(n)

int x, joy = 0;

int main()
{
  cin >> x;

  joy += (x / 500) * 1000;
  joy += (x % 500) / 5 * 5;

  cout << joy << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b, x, i, check=0;

    scanf("%d %d", &a, &b);

    if(b < 10)
        x = b + a*10;
    else if(b < 100)
        x = b + a*100;
    else
        x = b + a*1000;
    
    i=1;
    while(i*i <= x){
        if(i*i == x)
            check=1;
        i++;
    }

    if(check == 1)
        printf("Yes\n");
    else
        printf("No\n");
    
    return 0;
}

Measured memory_bytes: 128
# include <bits/stdc++.h>
# pragma GCC optimize("Ofast")
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define forn(i, n) for (int i = 0; i < int(n); i++)
# define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define fore(i, l, r) for (int i = int(l); i < int(r); i++)
# define fors(i, s) for (int i = 0; s[i]; i++)
# define in freopen("input.txt", "r", stdin)
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
 
using namespace std;
 
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 7;
 
int main()
{
	speed;
	ll n, a , b, ans1, ans2, ans3 = INF, ans4, ans5;
	cin >> n >> a >> b;
	ll c = b;
	c -= a;
	c -= 1;
	if ( c % 2ll == 1 ) {
		ans3 = c / 2 + 1;
	}
	ans1 = b;
	ans1--;
	ans2 = n;
	ans2 -= a;	
	ans4 = a - 1;
	ll d = b - (a - 1);
	if ( d % 2 == 0 ) {
		ans4++;
		d--;
		ans4 += d - (d + 1) / 2;
	}
	else ans4 = INF;
	ans5 = n - b;
	d = a + (n - b);
	if ( (n - d) % 2 == 1 ) {
		ans5++;
		d++;
		ans5 += n - (n + d) / 2;
	} 
	else ans5 = INF;
	cout << min( {ans2, ans1, ans3, ans4, ans5} ) << endl;
	time;
}

Measured memory_bytes: 256
/**
 *   created: 28 April 2019  23:46:46
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
// #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================
vector< vll  > adj;
vl dist;
vi vis;
void dfs(int node){
	// trace1(node);
	vis[node]=1;
	for(auto x:adj[node]){
		if(!vis[x.first]){
			dist[x.first] = dist[node] + x.second;
			dfs(x.first);
		}
	}
}
int main()
{
	optimizeIO();
	int tt=1;
	// cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		adj.resize(n+1);
		dist.resize(n+1);
		vis.resize(n+1,0);
		rep(i,1,n){
			int a,b,c;
			cin>>a>>b>>c;
			adj[a].push_back({b,c});
			adj[b].push_back({a,c});
		}
		dist[1]=0;
		dfs(1);
		cout<<0<<endl;
		rep(i,2,n+1){
			if(dist[i]%2==0)
				cout<<0<<endl;
			else
				cout<<1<<endl;
		}
	}
	return 0;
}





Measured memory_bytes: 9600
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> d(10,0);
    rep(i,k) {
        ll a;cin >> a;
        d[a] = 1;
    }

    auto check = [&](ll x){
        while(x){
            if(d[x % 10])return false;
            x /= 10;
        }
        return true;
    };

    for(ll i = n;i < 1e6;i++){
        if(check(i)){
            cout << i << endl;
            return 0;
        }
    }

    return 0;

}

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

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

typedef pair<int,int> pi;

int main()
{
	int i,j;
	while(1)
	{
		int m;
		cin >>m;
		if(m==0) break;

		vector<pi> a(m);
		rep(i,m) scanf(" %d %d",&a[i].fi,&a[i].sc);

		int n;
		cin >>n;
		vector<pi> b(n);
		set<pi> s;
		rep(i,n){
			scanf(" %d %d",&b[i].fi,&b[i].sc);
			s.insert(b[i]);
		}

		int x=0,y=0;
		//a[0]??¨b[i]????????????
		rep(i,n)
		{
			bool valid=true;
			int dx=b[i].fi-a[0].fi;
			int dy=b[i].sc-a[0].sc;
			rep(j,m)
			{
				pi tmp(a[j].fi+dx,a[j].sc+dy);
				if(s.find(tmp)==s.end())
				{
					valid=false;
					break;
				}
			}

			if(valid)
			{
				x=dx;
				y=dy;
				break;
			}
		}

		printf("%d %d\n",x,y);
	}
}

Measured memory_bytes: 3192
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i = (a) ; i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i!= (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end)

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-6
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef complex<double> P;
typedef vector<P> G;
int n;

namespace std{
    bool operator<(const P &a, const P &b) {
	return abs(real(a)-real(b)) > EPS ? real(a) < real(b): imag(a) < imag(b);
    }
}

struct cmp
{
    bool operator ()(const double &a, const double &b) {
	return a + EPS < b;
    }
};

P rotate(const P &a, double th) { return a*polar(1.0, th); }
double angle(const P &a, const P &b) { return arg(conj(a)*b); }

P centerG(const G &g) {
    P p = P(0, 0);
    rep(i, n) p += g[i];
    p /= n;
    return p;
}

int main(){
    while(cin >> n, n) {
	G g1(n), g2(n);
	rep(i, n) cin >> g1[i].real() >> g1[i].imag();
	rep(i, n) cin >> g2[i].real() >> g2[i].imag();
	P c1 = centerG(g1), c2 = centerG(g2);
	rep(i, n) {
	    g1[i] -= c1;
	    g2[i] -= c2;
	}
	//cout <<"c " << c1 << " " << c2 << endl;
	G tg = g2;
	double ans = INF;
	sort(all(g1));
	rep(i, n) {
	    g2 = tg;
	    double th = angle(g2[i], g1[0]); 
	    rep(j, n) g2[j] = rotate(g2[j], th);
	    bool flag = true;
	    
	    sort(all(g2));
	    rep(j, n) if(abs(g1[j] - g2[j]) > EPS) flag = false;
	    
	    //cout << "a "<< i << endl;
	    //rep(j, n) cout << g1[j] << g2[j] << endl;
	    
	    if(flag) {
		if(th < 0) th = -th;
		if(th > PI) th = 2*PI - th;
		ans = min(ans, th);
	    }
	}
	printf("%.11f\n", ans);
    }
    return 0;
}

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

/**
 * abc173-B https://atcoder.jp/contests/abc173/tasks/abc173_b
 * 
 */
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int cases = Integer.parseInt(reader.readLine());
            int ac = 0;
            int wa = 0;
            int tle = 0;
            int re = 0;
            while (cases-- > 0) {
                String input = reader.readLine();
                switch (input) {
                    case "AC":
                        ac++;
                        break;
                    case "WA":
                        wa++;
                        break;
                    case "TLE":
                        tle++;
                        break;
                    case "RE":
                        re++;
                        break;

                }
            }
            System.out.println("AC x " + ac);
            System.out.println("WA x " + wa);
            System.out.println("TLE x " + tle);
            System.out.println("RE x " + re);

        } catch (NumberFormatException | IOException e) {
            e.printStackTrace();
        }
    }

}

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

int N,X,Y;

int measure(int i,int j);

int main(void){
    int i,j;
    scanf("%d %d %d",&N,&X,&Y);
    int count[N-1];
    for(i=0;i<N-1;i++){
        count[i]=0;
    }
    for(i=1;i<N;i++){
        for(j=i+1;j<=N;j++){
            int Measure=measure(i,j);
            count[Measure-1]++;
        }
    }
    for(i=0;i<N-1;i++){
        printf("%d\n",count[i]);
    }
    return 0;
}

int measure(int i,int j){
    int routeA,routeB;
    routeA=j-i;
    routeB=abs(X-i)+abs(Y-j)+1;
    if(routeA>=routeB){
        return routeB;
    }else{
        return routeA;
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e6+5;
ll inf=1e15;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    
    while(t--)
    {
        
        string s1,s2;
        cin>>s1>>s2;
        int n=s1.length();
        int m=s2.length();
        int dp[n+1][m+1];
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=m;j++)
            {
                if(i==0 or j==0)
                    dp[i][j]=0;
                else if(s1[i-1]==s2[j-1])
                    dp[i][j]=1+dp[i-1][j-1];
                else
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

            }
        }
        string res="";
        int i=n,j=m;
        while(i>0 and j>0)
        {
            if(s1[i-1]==s2[j-1])
            {
                res+=s1[i-1];
                i--;
                j--;

            }
            else
            {
                if(dp[i-1][j]>dp[i][j-1])
                {
                    i--;
                }
                else
                {
                    j--;
                }
            }
        }

        reverse(res.begin(),res.end());
        cout<<res<<endl;
    }

    return 0;
}

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

int main() {
	int N;
	cin >> N;
	int a[110];
	for (int i = 0; i < N; ++i)	cin >> a[i];

	int sum_a = 0;
	int sum_b = 0;
	sort(a, a + N, greater<int>());

	for (int i = 0; i < N; i = i + 2) {
		sum_a += a[i];
	}
	
	for (int i = 1; i < N; i = i + 2) {
		sum_b += a[i];
	}
	cout << sum_a - sum_b << endl;
}


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

using namespace std;


#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
     
#define ll long long int
#define ld long double


#define fr first
#define se second



#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define sunq(v) sort(all(v));v.resize(distance(v.begin(),unique(all(v))))


#define pb push_back
#define mp make_pair

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define emla(a, val) memset(a, val, sizeof(a))

#define easm(a, b) (a + b - 1)/b 


#define PI 3.141592653589793238
#define E  2.718281828459045235


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


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

int n, w;
ll dp[111][100101], we[111], v[111];

ll solve(int i, int wi){
  if(i == n)return 0;
  if(wi > w)return 0;
  ll &re = dp[i][wi];
  if(re != -1)return re;
  ll mx = solve(i + 1, wi);
  if(wi + we[i] <= w)
    mx = max(mx, solve(i + 1, wi + we[i]) + v[i]);
  return re = mx;
}


int main(){
  IOS;
  //freopen("input.in", "r", stdin);
  //freopen("output.txt", "w", stdout);
  clock_t z = clock();
  emla(dp, -1);
  cin >> n >> w;
  for(int i = 0; i < n; i++)cin >> we[i] >> v[i];
  cout << solve(0, 0) << endl;
  debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
  /*
  *try tricky test cases:
    -bounds
    -integer overflow
    -small input (0, 1)
    -big input
    -random tests
  */
  return 0;
}

Measured memory_bytes: 87040
// Problem Statement
// Given is a positive integer N
// Find the number of pairs
// (A,B) of positive integers not greater than N hat satisfy the following condition:
// When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of
// A is equal to the last digit of B.

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}
int last_digit(int n)
{
    int ans = 0;
    while (n != 0)
    {
        ans = n % 10;
        n /= 10;
    }
    return ans;
}
int main()
{
    int n, k;
    cin >> n >> k;
    ll a[n];
    cn(a, n);
    sort(a, a + n);
    ll ans = 0;
    for (int i = 0; i < (n - k); i++)
    {
        ans += a[i];
    }
    cout << ans;
}


Measured memory_bytes: 5172
N = gets.to_i
A = gets.split.map(&:to_i)

flag = true
A.each do |n|
  next if n % 2 != 0
  if n % 3 != 0 && n % 5 != 0
    flag = false
  end
end

if flag
  puts 'APPROVED'
else
  puts 'DENIED'
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll y,m,d;
    char c1,c2;
    cin >> y >> c1 >> m >> c2 >> d;
    
    cout << (4 >= m? "Heisei" : "TBD" );
    
    return 0;
}



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

using namespace std;
#define REP(i, n) for(int i=0; i < (int)(n); ++i)
#define REPR(i, n) for(int i=n; i>= 0; --i)
#define FOR(i, m, n) for(int i=m; i<(n); ++i)

using ll = long long;

int main(){
    int A, B;
    cin >> A >> B;
    int ans = 0, sum = 1;
    while(sum < B){
        ans++;
        sum += A-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

void solve() {
	string s;
	cin >> s;
	if (s == "Sunny") {
		ce("Cloudy");
	}
	else if (s == "Cloudy") {
		ce("Rainy");
	}
	else if (s == "Rainy") {
		ce("Sunny");
	}
}



int main()
{

	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll allscore(int i, int d, vector<vector<int>>s, vector<vector<int>>t, vector<int>c) {
	ll res = 0;
	int fury = 0;
	for (int j = 0; j < d; j++) {
		if (t.at(i).at(j) == 1) {
			res += s.at(j).at(i);
			fury = 0;
		}
		else {
			fury++;
			res -= fury * c.at(i);
		}
	}
	return res;
}
ll fastscore(vector<int>bl,int date,int fury) {
	int l = -1;
	int r = bl.size();
	for (int i = date - 1; i >= 0; i--) {
		if (bl.at(i) == 1) {
			l = i;
			break;
		}
	}
	for (int i = date + 1; i < r; i++) {
		if (bl.at(i) == 1) {
			r = i;
			break;
		}
	}
	ll ans = (r - date) * (date - l) * fury;
	return ans;
}
vector<int>greedy(int d, vector<vector<int>>s) {
	vector<int>ans(d);
	for (int i = 0; i < d; i++) {
		int res = 0;
		int tmp = -1;
		for (int j = 0; j < 26; j++) {
			if (res < s.at(i).at(j)) {
				res = s.at(i).at(j);
				tmp = j;
			}
		}
		ans.at(i) = tmp;
	}
	return ans;
}
int main() {
	//input
	int d; cin >> d;
	vector<int>c(26);
	for (int i = 0; i < 26; i++)cin >> c.at(i);
	vector<vector<int>>s(d, vector<int>(26));
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < 26; j++)cin >> s.at(i).at(j);
	}
	vector<int>td = greedy(d, s);
	vector<vector<int>>t(26, vector<int>(d, 0));
	for (int i = 0; i < d; i++) {
		int x = td.at(i);
		t.at(x).at(i)++;
	}
	int m = 100;
	vector<pair<int, int>>dq;
	for (int i = 0; i < m; i++) {
		int x = rand() % d;
		int y = rand() % 26;
		dq.push_back({ x, y });
	}
	
	//Q.B
	vector<int>sum(26,0);
	for (int i = 0; i < 26; i++) {
		sum.at(i) = allscore(i, d, s, t, c);
	}
	ll ans = 0;
	for (int i = 0; i < 26; i++)ans += sum.at(i);

	//Q.C
	for (int i = 0; i < m; i++) {
		int day = dq.at(i).first;
		int change = dq.at(i).second;
		if (t.at(change).at(day) == 1)continue;
		int before = td.at(day);

		//backup
		vector<vector<int>>tbu = t;
		vector<int>tdbu = td;
		//変更前と変更後について再計算、sumに反映
		t.at(before).at(day) = 0;
		t.at(change).at(day) = 1;
		td.at(day) = change;
		ll befs = fastscore(t.at(before), day, c.at(before)) + s.at(day).at(before);
		ll chgs = fastscore(t.at(change), day, c.at(change)) + s.at(day).at(change);
		if (-befs + chgs >= 0) {
			ans = ans - befs + chgs;
			sum.at(before) -= befs;
			sum.at(change) += chgs;
		}
		else{
			t = tbu;
			td = tdbu;
		}
	}
	for (int i = 0; i < d; i++)cout << td.at(i)+1 << endl;
}

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

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto deque = Deque!int(400_000);
    int q = readint;
    for (int i = 0; i < q; i++) {
        auto xs = readints;
        switch (xs[0]) {
        case 0:
            if (xs[1] == 0) deque.insertFront(xs[2]);
            else deque.insertBack(xs[2]);
            break;
        case 1:
            writeln(deque[xs[1]]);
            break;
        case 2:
            if (xs[1] == 0) deque.removeFront();
            else deque.removeBack();
            break;
        default:
            break;
        }
    }
}

struct Deque(T) {
    private T[] _buffer;
    private int _front;
    private int _back;

    this(int size) {
        _buffer = new int[size * 3];
        _front = _back = (size * 3) / 2;
    }

    bool empty() @property { return  _front == _back; }
    int length() @property { return _back - _front; }

    void insertFront(T value) {
        if (empty) {
            _buffer[_front] = value;
            _back++;
            return;
        }

        _buffer[--_front] = value;
    }

    void insertBack(T value) {
        if (empty) {
            _buffer[_front] = value;
            _back++;
            return;
        }

        _buffer[_back++] = value;
    }

    void removeFront() {
        assert(!empty);
        ++_front;
    }

    void removeBack() {
        assert(!empty);
        --_back;
    }

    T opIndex(int index) {
        return _buffer[_front + index];
    }
}



Measured memory_bytes: 7932
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

int N;
int P[200000];
int idx[200001];

int main(){
    cin>>N;
    rep(i,N) cin>>P[i];

    rep(i,N) idx[P[i]]=i;

    int ans=0;
    int cnt=0;
    int prev=-1;
    repn(i,N){
        if(prev<idx[i]) cnt++;
        else{
            ans=max(ans,cnt);
            cnt=1;
        }
        prev=idx[i];
    }
    ans=max(ans,cnt);
    
    ans=N-ans;
    cout<<ans<<endl;
}

Measured memory_bytes: 5192
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

int main()
{
	int N, D;
	cin >> N >> D;
	vector<double> X(N);
	vector<double> Y(N);
	rep(i, N) {
		cin >> X[i] >> Y[i];
	}
	
	int ans = 0;
	double dist;
	rep(i, N){
		dist = sqrt(X[i] * X[i] + Y[i] * Y[i]);
		if (dist <= D) {
			ans += 1;
		}
	}

	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 6488
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;

int N;
int a[100010];

void Main()
{
    cin >> N;
    rep(i, N) cin >> a[i];
    ll sum = 0;
    rep(i, N)
    {
        sum ^= a[i];
    }
    if (sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


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

struct tree{
  int p;
  int l;
  int r;
  int d;
};

tree t[100000];

void dfs(int n,int d){
  if(n==-1)return;
  t[n].d=d;
  dfs(t[n].r,d),dfs(t[n].l,d+1);
}

int main(){
  int n,a,b,c,tmp;
  cin>>n;
  for(int i=0;i<n;i++)t[i].l=-1,t[i].p=-1,t[i].r=-1,t[i].d=0;
  for(int i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    for(int j=0;j<b;j++){
      scanf("%d",&c);
      t[c].p=a;
      if(j)t[tmp].r=c;
      tmp=c;
      if(j==0)t[a].l=c;
    }
  }
  for(int i=0;i<n;i++)if(t[i].p==-1)dfs(i,0);
  for(int i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,t[i].p,t[i].d);
    if(t[i].l==-1){
      if(t[i].p==-1)printf("root, []\n");
      else printf("leaf, []\n");
    }
    else{
      if(t[i].p==-1)printf("root, [");
      else printf("internal node, [");
      tmp=t[i].l;
      while(1){
	if(t[tmp].r==-1){
	  printf("%d]\n",tmp);
	  break;
	}
	printf("%d, ",tmp);
	tmp=t[tmp].r;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 7860
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  long long n;
  cin>>n;
  long m = sqrt(n);
  for(long i=m;i>0;--i){
    if(n%i==0){
      cout<<i+n/i-2;
      return 0;
    }
  }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> s;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(s[0] != s[1] && s[1] != s[2] && s[2] != s[0]) anss = "Yes";
  else anss = "No";

  cout << anss << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define mit(a,b) map<a,b>::iterator
#define sit(a) set<a>::iterator
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vec4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
int gi(){
    int x=0,w=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=0,ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}
void print(ll x)
{
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);putchar(x % 10 + '0');
}
int main()
{
     io;
    int T=1;
    //T=gi();
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
        int n,i,j,k,l;
        string s;
        cin>>n>>s;
        int r=count(s.begin(),s.end(),'R');
        int ans=count(s.begin(),s.begin()+r,'W');
        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = ll(1e18) + 1;
typedef pair<int,int> P;// pair型は２つの値の組を表せる

int main(){
    int N; cin >> N;
    vector <int> X(N);
    double sum=0;
    rep(i,N){
        cin >> X[i];
        sum+=X[i];
    }
    
    int mid=round(sum/N);
    ll ans=0;
    rep(i,N){
        ans+=pow(X[i]-mid,2);
    }
    cout << ans;
}

Measured memory_bytes: 256
import sys

S = input()

operators = ['+', '-']

for op1 in operators:
    for op2 in operators:
        for op3 in operators:
            exp = S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]
            if eval(exp) == 7:
                print("{}{}{}{}{}{}{}=7".format(S[0], op1, S[1], op2, S[2], op3, S[3]))
                sys.exit(0)


Measured memory_bytes: 3060
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        w: [chars;n]
    }

    let mut is_ok = true;
    let hset = w .iter().cloned().collect::<std::collections::HashSet<_>>();
    if hset.len() != w.len() {is_ok = false;}
    for i in 0..n-1 {
        if w[i][w[i].len()-1] != w[i+1][0] {
            is_ok = false;
        }
    }
    println!("{}", if is_ok {"Yes"} else {"No"});
}

Measured memory_bytes: 4352
import sys 

K, N = [int(i) for i in sys.stdin.readline().strip().split(" ")]
A = [int(i) for i in sys.stdin.readline().strip().split(" ")]

s = 0 
m = -1
a = []
for i in range(0, N-1):
    n = A[i+1] - A[i]
    m = max(m, n)
    s += n

n = K-A[-1] + A[0]
m = max(m, n)
s += n

print(s - m)


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

int main() {
	int k,a,b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,n;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    ll dp[n];
    dp[0]=0;
    for(i=1;i<n;i++)
    {
        if(i>=2)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        else
        dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main()
{
  char a;
  int sum;
  while((a=cin.get())!='0'){
    sum = (int)a-48;
    while((a=cin.get())!='\n'){
      sum += (int)(a)-48;
    }
    cout << sum << endl;
  }
  return 0;
}



Measured memory_bytes: 3084
# coding: utf-8
class Case01

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  def read
    @s, @t = gets.chomp.split
    @a, @b = gets.chomp.split.map(&:to_i)
    @u = gets.chomp
  end

  def solve
    if @u == @s then
      @a -= 1 
    else
      @b -= 1
    end
  end
  
  def output
    puts "#{@a} #{@b}"
  end

end

Case01.new.execute if $0 == __FILE__


Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(){
  int total,a,b,c,d,e,n,max,min;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }
    max=-100;
    min=100000;
    for(int i=0;i<n;i++){
      cin >> a >> b >> c >> d >> e;
      total=a+b+c+d+e;
      if(total>max){
	max=total;
      }
      if(total<min){
	min=total;
      }
    }
    cout << max << " " << min << endl;
  }
}

Measured memory_bytes: 1160