akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> v;
pair<int,int> p;
map<int,int> m;
deque<int> d;
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int x[n];
for(int i=0;i<n;i++)
    cin>>x[i];
int sum = 0;
for(int i=0;i<n;i++)
    sum += x[i];
float p = float(sum)/float(n);
int sum2 = 0;
for(int i=0;i<n;i++)
    sum2+=pow(x[i]-round(p),2);
cout<<sum2<<endl;
return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll h,w,ch[100][100],dx[]={0,1},dy[]={1,0},nx,ny;
string s[100];
queue<P> que;
int main(void){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ch[i][j]=1e9;
        }
    }
    que.push({0,0});
    ch[0][0]=1;
    while(que.size()){
        P q=que.front();
        que.pop();
        for(int i=0;i<2;i++){
            nx=q.F+dx[i],ny=q.S+dy[i];
            if(0<=nx&&nx<h&&0<=ny&&ny<w){
                if(s[q.F][q.S]!=s[nx][ny]&&(ch[nx][ny]>ch[q.F][q.S]+1)){
                    ch[nx][ny]=ch[q.F][q.S]+1;
                    que.push({nx,ny});
                }
                else if(s[q.F][q.S]==s[nx][ny]&&(ch[nx][ny]>ch[q.F][q.S])){
                    ch[nx][ny]=ch[q.F][q.S];
                    que.push({nx,ny});
                }
            }
        }
    }
    if(s[0][0]=='#'&&s[h-1][w-1]=='#')cout<<ch[h-1][w-1]/2+1<<endl;
    else cout<<ch[h-1][w-1]/2<<endl;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{
	int m=0,f=0,r=0;
	
	while((m!=-1)||(f!=-1)||(r!=-1))
	{
		scanf("%d %d %d",&m,&f,&r);
		if((m!=-1)||(f!=-1)||(r!=-1))
		{
			if(m+f>=80)
			{printf("A\n");}

			if((m+f>=65)&&(m+f<80))
			{printf("B\n");}
	
			if((m+f>=50)&&(m+f<65))
			{printf("C\n");}

			if(m==-1||f==-1||m+f<30)
			{printf("F\n");}

			if((m!=-1)&&(f!=-1)&&(m+f>=30)&&(m+f<50))
			{
				if(r>=50)
				{printf("C\n");}
				if(r<50)
				{printf("D\n");}
			}
		}
		
	}
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < 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++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

struct UnionFind{
    vector<int> data;
    //data[i] = -x ... iが根であり、サイズがx
    //data[i] = x ... iの親がx

    //最初は全員根
    UnionFind(int size): data(size,-1){}

    bool union_set(int x, int y){//サイズがx>yになるようにしてから、xにyをつなげる
        x=root(x);
        y=root(y);
        if(x != y){
            if(data[y] < data[x]) swap(x,y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find_set(int x, int y){//ルートが一致するかどうかを返す
        return root(x) == root(y);
    }
    int root(int x){//根を見つける。ついでに深さ2にしちゃう
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

struct Edge{
    int s,t,cost;
    bool operator<(const Edge &o) const{
        return cost < o.cost;
    }
};


int main() {
    int n,q; cin >> n >> q;
    UnionFind uf(n);
    REP(i,q){
        int com,x,y; cin >> com >> x >> y;
        if(com == 0){
            uf.union_set(x,y);
        }
        if(com == 1){
            cout << uf.find_set(x,y) << endl;
        }

    }
    return 0;
}




Measured memory_bytes: 3140
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#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 <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll v[1000000];
ll a[1000000];
ll acopy[1000000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
int main() {
	cin>>N;
	if(N==1){
		cout<<"Hello World"<<endl;
	}else{
		ll A,B;
		cin>>A>>B;
		cout<<A+B<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(i) (int)(i.size())
#define setto(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define ld long double
#define inf LONG_MAX
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int mod = 1000000007;
using namespace std;

#define meta __FUNCTION__<<" : "<<__LINE__<<" "
#define tr1(x) cerr<<meta<<"| "<<#x<<" : "<<x<<" | "<<endl
#define tr2(x,y) cerr<<meta<<"| "<<#x<<" : "<<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<endl
#define tr3(x,y,z) cerr<<meta<<"| "<<#x<<" : "<<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<" "<<#z<<" : "<<z<<" | "<<endl
#define tr4(w,x,y,z) cerr<<meta<<"| "<<#w<<" : "<<w<<" | "<<" "<<#x<<" : " <<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<" "<<#z<<" : "<<z<<" | "<<endl
#define tr5(v,w,x,y,z) cerr<<meta<<"| "<<#v<<" : "<<v<<" | "<<" "<<#w<<" : "<<w<<" | "<<" "<<#x<<" : "<<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<" "<<#z<<" : "<<z<<" | "<<endl
#define tr6(u,v,w,x,y,z) cerr<<meta<<#u<<" : "<<u<<" | "<<" "<<#v<<" : "<<v<<" | "<<" "<<#w<<" : "<<w<<" | "<<" "<<#x<<" : "<<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<" "<<#z<<" : "<<z<<" | "<<endl

template<class T> void smin(T& a, T val) {if (a > val) a = val;}
template<class T> void smax(T& a, T val) {if (a < val) a = val;}
template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
//Check N size twiceeeeeeeeeeeeeeeeee, and verify it

const int N = 1e7 + 10;

int n, m;
int main(){_
	cin>>n>>m;

	int ans = 1;
	for (int i = 1; i <= N; ++i)
	{
		// gcd is i
		if(m % i)continue;
		int tt = m/i;
		if(i >= n){
			smax(ans, tt);
		}
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

using U = unsigned char;
// comp, x, y, h-1
U mw[185][185][185];
// comp, x, y, w-1
U mh[185][185][185];

int a[185][185], s1[2][185], sum[185][185];

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int H, W; std::cin >> H >> W;
  for(int h = 0; h < H; ++h) for(int w = 0; w < W; ++w) {
    char ch; std::cin >> ch;
    a[h][w] = ((ch/8)&1);
  }
  memset(s1[0], 0, sizeof s1);
  memset(sum[0], 0, sizeof sum);
  for(int h = 0; h < H; ++h) for(int w = 0; w < W; ++w) {
    s1[h%2][w] = a[h][w] + s1[(h-1)%2][w];
    sum[h][w] = s1[h%2][w];
    if(w > 0) sum[h][w] += sum[h][w-1];
  }
  auto comp0 = [&](int x, int y, int w, int h) {
    --x; --y;
    if(y+h >= H || x+w >= W) return false;
    int s = sum[y+h][x+w];
    if(x >= 0 && y >= 0) s += sum[y][x];
    if(x >= 0) s -= sum[y+h][x];
    if(y >= 0) s -= sum[y][x+w];
    return s == 0 || s == w*h;
  };
  memset(mw[0][0], 0, sizeof mw);
  memset(mh[0][0], 0, sizeof mh);
  // complexity 0
  for(int x = 0; x < W; ++x) for(int y = 0; y < H; ++y) {
    // mw
    int ww = W-x;
    for(int h = 1; y+h <= H; ++h) {
      while(ww > 0 && !comp0(x, y, ww, h)) --ww;
      mw[x][y][h-1] = ww;
    }
    // mh
    int hh = H-y;
    for(int w = 1; w <= W; ++w) {
      while(hh > 0 && !comp0(x, y, w, hh)) --hh;
      mh[x][y][w-1] = hh;
    }
  }
/*for(int x = 0; x < W; ++x) for(int y = 0; y < H; ++y) for(int h = 1; y+h <= H; ++h) {
std::cout << "mw[" << x << "][" << y << "][" << h-1 << "] = " << (int)mw[x][y][h-1] << "\n";
}
for(int x = 0; x < W; ++x) for(int y = 0; y < H; ++y) for(int w = 1; x+w <= W; ++w) {
std::cout << "mh[" << x << "][" << y << "][" << w-1 << "] = " << (int)mh[x][y][w-1] << "\n";
}*/
  if(mw[0][0][H-1] == W || mh[0][0][W-1] == H) fin(0);
 
  // complexity c>= 1
  auto ch_max = [](U&x, U y)->void { if(x < y) x = y; };
  for(int c = 1; c < 16; ++c) {
    // mw
    for(int h = 1; h <= H; ++h) {
      for(int y = 0; y <= H-h; ++y) for(int x = 0; x < W; ++x) {
        int tw = mw[x][y][h-1];
        if(x+tw < W) {
          int tw2 = mw[x+tw][y][h-1];
          mw[x][y][h-1] += tw2;
        }
      }
    }
    // mh
    for(int w = 1; w <= W; ++w) {
      for(int x = 0; x <= W-w; ++x) for(int y = 0; y < H; ++y) {
        int th = mh[x][y][w-1];
        if(y+th < H) {
           int th2 = mh[x][y+th][w-1];
           mh[x][y][w-1] += th2;
        }
      }
    }
    // mh->mw, mw->mh
    for(int x = 0; x < W; ++x) for(int y = 0; y < H; ++y) {
      int ww = W;
      for(int h = 1; h <= H; ++h) {
        while(ww > 0 && mh[x][y][ww-1] < h) --ww;
        ch_max(mw[x][y][h-1], ww);
      }
      int hh = H;
      for(int w = 1; w <= W; ++w) {
        while(hh > 0 && mw[x][y][hh-1] < w) --hh;
        ch_max(mh[x][y][w-1], hh);
      }
    }
    if(mw[0][0][H-1] == W || mh[0][0][W-1] == H) fin(c);
  }
  fin(16);
  return 0;
}


Measured memory_bytes: 16240
#include<bits/stdc++.h>
#define ll          long long
#define ld          long double
#define mod         (1000000000+7)
#define ull         unsigned long long
#define pb          push_back
#define	endl		'\n'
#define pi          acos(-1)
#define pii         pair<ll int,ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define SIZE(X)     ((int)((X).size()))
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define FOR(i,s,n)  for(int i=s;i<n;i++)
#define FORE(i,s,n) for(int i=s;i<=n;i++)
#define ERASE(x)    x.erase(unique(x.begin(),x.end()),x.end()) //removes repeated element;
#define Fast        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);

using namespace std;
const int N = 100010;
vector <ll> is_prime(N+1 , true);
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b){return (a.first > b.first);}
bool sortbysecdesc(const pair<int,int> &a,const pair<int,int> &b){return a.second>b.second;}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) {return (a.second < b.second);}
ll int pow(ll int x, ll int y) { ll int res = 1; while (y > 0) { if (y & 1) res = ((res) * (x)); res %= N; y = y >> 1; x = ((x) * (x)); } return res; }
int powm(int x, int y, int p)  {  int res = 1; x = x % p; while (y > 0) {if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;}   return res; }
ll int power(ll int a , ll int b) { if(b == 1) return a; if(b == 0) return 1; ll int m1 = power(a,b/2); if(b%2) return m1*m1*a; return m1*m1; }
void seive_of_eras(ll n) { is_prime[0] = 0; is_prime[1] = 0; for(ll i=2;i*i<=n;i++) { if(is_prime[i]) { for(ll j=i*i;j<=n;j+=i) { is_prime[j] = false; } } } }
bool isprime (ll a) { if(a<=1) return false; if(a==2||a==3) return true; if(a%2==0||a%3==0) return false; for(ll i=5;i*i<=a;i=i+6) { if(a%i==0||a%(i+2)==0) return false; } return true; }

void codeit()
{
    ll x; cin>>x;
    if(x>=30)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return;
}

int main()
{
    //Fast
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ull tt; //cin>>tt;
    tt = 1;
    for(ull i=0;i<tt;i++)
        codeit();
}


Measured memory_bytes: 3868
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<iostream>
using namespace std;
#define EPS (1e-9)
int N,M;
double calc(int an){
  //  int an2 = 180-90;
  double rad = (double)an * M_PI/180.0;
  // double rad2 = (double)(an/2.0) * M_PI/190.0;
  //return sqrt(2.0-cos(rad)*2.0);
  return 0.5*sin(rad);
}
bool equal(double a,double b){ return abs(a-b) < EPS; }
int main(){
  while(cin >> N && N ){
    double a1=0.0,a2=0.0;
    int an,suman=0;
    for(int i=0;i<N-1;i++){
      cin >> an;
      //cout << "an " <<calc(an) << endl;
      a1 += calc(an);
      suman+=an;
    }
    a1 += calc(360-suman);
    cin >> M;
    suman = 0;
    for(int i=0;i<M-1;i++){
      cin >> an;
      //    cout << "an " <<calc(an) << endl;
      a2 += calc(an);
      suman += an;
    }
    a2 += calc(360-suman);
    //    cout << a1 << " " <<a2<<endl;
    if( equal(a1,a2) ) cout << 0 << endl;
    else if( a1 > a2 ) cout << 1 << endl;
    else cout << 2 <<endl;
  }
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>

using namespace std;
string ld="qwertasdfgzxcvb";
string rd="yuiophjklnm";

int che(char c){
	if(ld.find(c)!=string::npos)return 0;
	return 1;
}
int main(){
	string str;
	while(cin>>str&&str[0]!='#'){
		int old=che(str[0]);
		int ans=0;
		for(int i=1;i<str.size();i++){
			if(old!=che(str[i]))ans++;
			old=che(str[i]);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < 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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
ll k;
ll cntbit(ll x){
    ll ans=0;
    while((x>>ans)!=1){
        ans++;
    }
    return ans;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin >> n;
  cin >> k;
  vector<ll> a(n+1);
  FOR(i,1,n+1){
      cin >> a[i];
      a[i] += a[i-1];
  }
  vector<ll> st0;
  REP(i,n+1){
      FOR(j, i+1, n+1){
          st0.pb(a[j]-a[i]);
      }
  }
  sort(all(st0));
  ll bit = cntbit(*(st0.end()-1));
  ll ans = 0;
  vector<ll>  st1;
  int phase=0;
  while(bit>=0){
      if(phase%2==0){
          int cnt=0;
          for(auto x: st0){
              if(((x>>bit) &1 )== 1){
                  cnt++;
              }
          }
          if(cnt>=k){
              ans+=1ll<<bit;
              for(auto x:st0){
                  if(((x>>bit) & 1) ==1){
                      st1.push_back(x);
                  }
              }
              st0.clear();
              phase = 1;
          }
          bit--;
      }else{
          int cnt=0;
          for(auto x: st1){
              if(((x>>bit) &1 )== 1){
                  cnt++;
              }
          }
          if(cnt>=k){
              ans+=1ll<<bit;
              for(auto x:st1){
                  if(((x>>bit) & 1) ==1){
                      st0.push_back(x);
                  }
              }
              st1.clear();
              phase = 0;
          }
          bit--;
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6384
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline LL ri() {LL x; scanf("%lld", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


string s;

int main() {
  cin >> s;
  int c = 0;
  LL res = 0;
  for (auto x: s) {
    if (x == 'W') {
      res += c;
    } else {
      c ++;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,x,t;
    cin >> n >> x >> t;
    long long ans = n / x;
    if(n%x!=0){
    ans++;

    }
    ans = ans * t;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
const ll mod = 1e9+7;

ll modpow (ll a, ll n, ll m) {
  ll res = 1;
  while (n > 0) {
  if (n & 1) res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll k = modpow(10, n, mod) + modpow(8, n, mod) - 2*modpow(9, n, mod);
  while (k < 0) {
    k += mod;
  }
  cout << k << endl;
}

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

int main(){
    int N;
    cin >> N;
    double tmp;
    double ans = 0.0;
    for( int n=0; n<N; n++ ){
        cin >> tmp;
        ans += 1.0 / tmp;
    }
    ans = 1.0 / ans;
    cout << setprecision(16) << ans << endl;
} 

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int n;
vector<int> G[100000];
// dp[i][j] := 頂点iを色j(j=0:白，j=1:黒)で塗った場合の，
// 頂点iを根とした部分木の各頂点を塗る組み合わせの数
ll dp[100000][2];

void dfs(int c, int p) {  // 頂点pは頂点cの親
  dp[c][0] = 1;
  dp[c][1] = 1;
  REP(i, G[c].size()) {
    if (G[c][i] == p) continue;
    dfs(G[c][i], c);
    dp[c][0] *= (dp[G[c][i]][0] + dp[G[c][i]][1]) % MOD;
    dp[c][0] %= MOD;
    dp[c][1] *= dp[G[c][i]][0];
    dp[c][1] %= MOD;
  }
}

int main() {
  cin >> n;
  REP(i, n - 1) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(0, -1);
  cout << (dp[0][0] + dp[0][1]) % MOD << endl;
  return 0;
}

Measured memory_bytes: 14208
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>

#define ll long long

int main()
{
    ll N;
    std::cin >> N;

    ll sum = 0;
    for(ll i=1; i <= N; i++) {
        if(i % 3 == 0) {
            continue;
        }
        else if(i % 5 == 0) {
            continue;
        }
        sum += i;
    }
    std::cout << sum << std::endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define faster cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define mod (int)(1e9+7)


// input matrix
vector<vector<int>> arr(22,vector<int>(22,0));
int n;


int dp[22][(1<<22)-1];

ll find(int curr,int mask)
{
	
	if(curr==n) return mask==0;
	if(dp[curr][mask]!=-1) return dp[curr][mask];
	
	ll ans=0;
	for(int j=0;j<n;j++)
	{
		bool available=(mask&(1<<j));
		if(available && arr[curr][j])
		{
			ans=(ans+find(curr+1,mask^(1<<j))%mod);
		}
	}
	return dp[curr][mask]=ans%mod;
	// return ans;
}

int main()
{

	cin>>n;
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>arr[i][j];
		}
	}
	memset(dp, -1, sizeof(dp));
	cout<<find(0,(1<<n)-1)<<endl;
}
	


Measured memory_bytes: 360832
#include<bits/stdc++.h>
using namespace std;
     
     
typedef long long ll;
typedef vector <int> vi;
typedef pair <int,int> pi;
typedef tuple <int,int,int> ti;

#define forn(i,a,n) for(int i = a; i < n ; i++)
#define mem(str,a) memset(str, a, sizeof(str));
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(nullptr)
const int MOD = 1e9+7, N = 1e7 + 10, E = 1e-9;
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//vector <int> show;
//for (auto x : show)
//   cout << x << " ";
getline(cin,s);


*/

int main() {
    string s;
    getline(cin, s);
    cout << s[0] << s[8] << s[s.size()-7] << endl;
    return 0;
}

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

int main() {
	int a,b,n,i,x,y;
	while(1){
	a = 0;
	b = 0;
	cin >> n;
	if(n == 0)break;
	for(i=0;i<n;i++){
		cin >> x >> y;
		if(x < y){
			b += x + y;
		}
		else if(x == y){
			a += x;
			b += y;
		}
		else {
			a += x + y;
		}
	}
	cout << a << " " << b << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void) {
	int h, w;
	int i, j;
	
	while (scanf("%d %d", &h, &w), h || w) {

		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				putchar('#');
			}
			puts("");
		}
		puts("");
	}
	return 0;
}

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

int main()
{
    int i,n,anus=0;;
    cin>>n;
    for(i=0;i<=n;i++){
        int ii=i,cnt=0;
        while(ii){
            ii=ii/10;
            cnt++;
        }
        if(cnt%2)
            anus++;
            
    }
    cout<<anus;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  bool n,w,so,e;
  n=so=w=e=false;
  for(int i=0;i<s.size();i++){
    if(s[i]=='S') so=true;
    if(s[i]=='W') w=true;
    if(s[i]=='E') e=true;
    if(s[i]=='N') n=true;
  }
  if(w==e&&so==n) cout<<"Yes";
  else cout<<"No";
}

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

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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    for(int i = 0; i < len; i++)
    {
        if(i%2 == 0)
        {
            if(s[i] == 'L')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            if(s[i] == 'R')
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const int _ = 52;

int n;
string nam[_];int val[_];

int main()
{	
	cin>>n;
	for(int i=1;i<=n;i++)cin>>nam[i]>>val[i];
	string cut;
	cin>>cut;

	for(int i=1;i<=n;i++)
	{
		if(nam[i]==cut)
		{
			lint ans=0;
			for(int j=i+1;j<=n;j++)ans+=val[j];
			cout<<ans<<endl;
			return 0;
		}
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef ll Weight;
void add_edge(vector<vector<Weight>>& g, Weight from, Weight to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

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

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

  int d; cin >> d;
	cout << (10000 - d) % 1000 << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=12e4;

int a[N],b[N],aa[N],bb[N];
int n,m,hs,ans;
int fa[N];

map<int,int> s;

inline int get(int o)
{return (fa[o]==o)?o:(fa[o]=get(fa[o]));}

int main()
{
	cin>>n;
	fo(i,1,n)scanf("%d",&a[i]),a[n+1]^=a[i];
	fo(i,1,n)scanf("%d",&b[i]),b[n+1]^=b[i];
	++n;
	fo(i,1,n)aa[i]=a[i],bb[i]=b[i];
	sort(aa+1,aa+n+1); sort(bb+1,bb+n+1);
	fo(i,1,n)if(aa[i]!=bb[i]){
		puts("-1");
		return 0;
	}
	int p=0;
	aa[0]=-1;
	fo(i,1,n)if(aa[i]!=aa[i-1]){
		++p;
		s[aa[i]]=p;
	}
	fo(i,1,n)a[i]=s[a[i]];
	fo(i,1,n)b[i]=s[b[i]];
	fo(i,1,n)if(a[i]!=b[i])fa[a[i]]=a[i],fa[b[i]]=b[i],ans=ans+1;
	fo(i,1,n)if(a[i]!=b[i])fa[get(a[i])]=get(b[i]);
	fo(i,1,p)if(!fa[i])fa[i]=get(i);
	fo(i,1,p)if(fa[i]==i)++ans;
	if(a[n]!=b[n])ans-=2;
	else if(fa[a[n]]!=0)--ans;
	if(ans<0)ans=0;
	cout<<ans;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){
int N;
cin>>N;
long long K;
cin>>K;
long long A[N];
long long s[N+1];
s[0]=0;
rep(i,N){
    cin>>A[i];
    s[i+1]=s[i]+A[i];
}
map<int,int>mp;


long long ans=0;
queue<int>q;

for(int i=0;i<=N;i++){

long long now=(s[i]-i)%K;
ans+=mp[now];
mp[now]++;
q.push(now);
    if(q.size()==K)
    {
    //幅がKまでなのでKを超えたら一個外に出す。
    mp[q.front()]--;
    q.pop();
    }
}
cout<<ans<<endl;
 return 0;
}
/*
5 4
1 4 2 3 5

4


8 4
4 2 4 2 4 2 4 2

7


10 7
14 15 92 65 35 89 79 32 38 46

8
*/

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

int main(){
    int n,x,t;
    int ans = 0;
    cin>>n>>x>>t;
    while(n > 0){
        ans++;
        n -= x;
    }
    cout<<ans*t<<endl;
    return 0;
}

Measured memory_bytes: 3544
module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = loop

loop :: IO()
loop = do
  { [m, f, r] <- getInts
  ; -- if m == -1 && f == -1 && r == -1 then return ()
    -- else if m == -1 || f == -1 then putStrLn "F" >> loop
    -- else if m + f >= 80 then putStrLn "A" >> loop
    -- else if m + f >= 65 then putStrLn "B" >> loop
    -- else if m + f >= 50 then putStrLn "C" >> loop
    -- else if m + f >= 30 then putStrLn (if r >= 50 then "C" else "D") >> loop
    -- else putStrLn "F" >> loop
    if m == -1 && f == -1 && r == -1 then done
    else printGrade m f r
  }

done :: IO()
done = return ()

printGrade :: Int -> Int -> Int -> IO ()
printGrade m f r = putStrLn (grade m f r) >> loop

grade :: Int -> Int-> Int -> String
grade m f r = if m == -1 || f == -1 then "F"
              else if mpf >= 80 then "A"
              else if mpf >= 65 then "B"
              else if mpf >= 50 then "C"
              else if mpf >= 30 then (if r >= 50 then "C" else "D")
              else "F"
   where
     mpf = m + f

--

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

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

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 4288
object Main extends App {
  val src: List[Int] = io.Source.stdin.getLines.toList.tail.map(_.toInt)

  def isPrime(n: Int): Boolean = {
    if (n == 1) false
    else ! ((2 to Math.sqrt(n).toInt) exists (n%_ == 0))
  }

  println(src.count(isPrime))
}

Measured memory_bytes: 120088
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define fs first
#define sc second
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;

const D EPS = 1e-8;

namespace std{
  bool operator<(const P &a,const P &b){
    return EQ(real(a),real(b))?imag(a)<imag(b):real(a)<real(b);
  }
  bool operator==(const P &a, const P &b){return EQ(a,b);}
}

inline D dot(P x, P y){return real(conj(x)*y);}
inline D cross(P x, P y){return imag(conj(x)*y);}

inline int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

inline bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}

inline bool is_cp(L a,L b){
  if(para(a,b))return false;
  if(ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    if(ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0)return true;
  return false;
}

inline P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

vector<P> p[2];
inline D len(D x, int id){
  L l = L( P(x,-1000), P(x,1000) );
  vector<P> res;
  rep(i,p[id].size()){
    L a = L( p[id][i], p[id][(i+1)%p[id].size()] );
    if(is_cp(a,l)){
      P cp = line_cp(a,l);
      if(!EQ(cp,p[id][i]))res.push_back(cp);
    }else if(para(a,l) && ccw(l.fs,l.sc,a.sc)==0){
      res.push_back(a.sc);
    }
  }

  if(res.size()<2)return 0;
  return abs(res[0]-res[1]);
}

inline D f(D x){
  return len(x/2,0) * len(x/2,1);
}

int main(){
  int m,n;
  while(cin >> m >> n, m){
    int minx[2], maxx[2];
    p[0].resize(m); p[1].resize(n);
    minx[0] = minx[1] = 1000;
    maxx[0] = maxx[1] = -1000;

    rep(i,m){
      int x,y;
      cin >> x >> y;
      p[0][i] = P(x,y);
      minx[0]=min(minx[0],x);
      maxx[0]=max(maxx[0],x);
    }

    rep(i,n){
      int x,z;
      cin >> x >> z;
      p[1][i] = P(x,z);
      minx[1]=min(minx[1],x);
      maxx[1]=max(maxx[1],x);
    }

    D ans = 0;
    for(D i=-199;i<200;i+=2){
      if(2*minx[0]<=i && i<=2*maxx[0]){
	if(2*minx[1]<=i && i<=2*maxx[1]){
	  ans += f(i-1)+4*f(i)+f(i+1);
	}
      }
    }
    cout << fixed << setprecision(9) << ans/6 << endl;
  }
}

Measured memory_bytes: 1288
import sys
from random import randint

a, b = map(int, sys.stdin.readline().split())

def isPrime(n, k=5): # miller-rabin
	if n < 2: return False
	for p in [2,3,5,7,11,13,17,19,23,29]:
		if n % p == 0: return n == p
	s, d = 0, n-1
	while d % 2 == 0:
		s, d = s+1, d//2
	for i in range(k):
		x = pow(randint(2, n-1), d, n)
		if x == 1 or x == n-1: continue
		for r in range(1, s):
			x = (x * x) % n
			if x == 1: return False
			if x == n-1: break
		else: return False
	return True

x = min(a, b)
def divisors(a, b):
	divs = set()
	i = 1
	while i*i <= x:
		if a%i == 0 and b%i==0:
			if isPrime(i):
				divs.add(i)
		other = a//i 
		if a%other == 0 and b%other==0:
			if isPrime(other):
				divs.add(other)
		i += 1
	return divs

res = divisors(a, b)
print(len(res)+1)	


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

int main()
{
	ll n,W;
	cin>>n>>W;
	ll A[n][2];
	for(int i=0;i<n;i++){
		cin>>A[i][0]>>A[i][1];
	}
//	w v
	ll dp[n+1][W+1];
	memset(dp,0,sizeof(dp));
	
	for(int i=1;i<=n;i++){
		
		for(int j=1;j<=W;j++){
			dp[i][j]=max(dp[i][j],dp[i-1][j]);
			if(j>=A[i-1][0]){
				dp[i][j]=max(dp[i][j], dp[i-1][j-A[i-1][0]] + A[i-1][1]);
			}
			
		}
	}
	cout<<dp[n][W]<<endl;
	return 0;
}


Measured memory_bytes: 82396
A, B, C, D = map(int, input().split())

T_time = C // B
if not C % B == 0 :
  T_time += 1

A_time = A // D
if not A % D == 0 :
  A_time += 1

if T_time <= A_time :
  print("Yes")
else :
  print("No")

Measured memory_bytes: 9120
import System.IO (hSetBuffering, stdin, BufferMode (NoBuffering))

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine :: IO [Int]
  hSetBuffering stdin NoBuffering
  ds <- getContents :: IO String
  let
    s = length . filter id . (zipWith (==) <$> id <*> tail) $ ds :: Int
  print $ (s + 2 * k) `min` (n - 1)


Measured memory_bytes: 4956
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>

using namespace std;

class customIO{
public:
    istream& in; ostream& out; customIO(istream& _in, ostream& _out):in(_in),out(_out){}
    string next() {string s;in >> s;return s;} double nextDouble() {return stod(next());}
    int nextInt() {return stoi(next());} long long nextLong() {return stoll(next());}
    template <typename T> void print(T t) {out << t;} template <typename T, typename ...U>
    void print(T t, U ...u) {out << t;print(u...);} template <typename T, typename ...U>
    void println(T t, U ...u) {print(t, u..., "\n");} void println() {print("\n");}
};


class BBreakNumber {
public:
    void solve(customIO &io) {
        int n = io.nextInt();
        int res = 1;
        while(res < n) {
            res *= 2;
        }
        if(res > n) res /= 2;
        io.println(res);
    }
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed;
    cout.precision(20);
    istream &in(std::cin);
    ostream &out(std::cout);
    customIO io(in, out);

    BBreakNumber solver;
    solver.solve(io);
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

signed main() {
	llint a;
	cin >> a;
	llint ans = 0;
	hei(llint) s(a + 1, 0);
	for(llint i=1;i<=a;i++){
		for (llint j = 1; i * j <= a; j++) {
			s[i*j]++;
		}
		ans += s[i] * i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 81400
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

A,B=get_i
if (A+B).odd?
    puts "IMPOSSIBLE"
else
    puts (A+B)/2
end

Measured memory_bytes: 1788
//
//AtCoder Beginner Contest 175
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    ll x , k , d;
    cin >> x >> k >> d;

    
    ll kk = k - (abs(x)/d);
    ll am = abs(x)%d;

    if (kk>0){
        if (kk%2==0) cout << abs(am) << endl;
        else cout << abs(am-d) << endl;
    }else{
        if (x>0) cout << abs(x - k*d) << endl;
        else cout << abs(x + k*d) << endl;
    }
    return 0;
}


Measured memory_bytes: 3516
w = input()
flag = True
wlist = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split()
for i in range(26) :
    if w.count(wlist[i]) % 2 == 1 :
        print("No")
        flag = False
        break
if flag :
    print("Yes")

Measured memory_bytes: 2940
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

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

		if ((a * b) % 2 == 0) {
			System.out.println("Even");
		}else if ((a * b) % 2 == 1) {
			System.out.println("Odd");
		}

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
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 int NIL = -1;
const int INF = (1<<21);
const long long MOD = 1e9+7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};


int main() {
  int N; cin >> N;
  int V[N], C[N];
  for (int i = 0; i < N; ++i) cin >> V[i];
  for (int i = 0; i < N; ++i) cin >> C[i];
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (V[i] > C[i]) ans += V[i]-C[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>

int main(){
  char w[104];  scanf("%s", w);
  int length = strlen(w);
  int table[30] = {0};
  for(int i=0; i<length; i++)
    table[(int)(w[i]-'a')]++;
  
  for(int i=0; i<30; i++)
    if(table[i] % 2){
      printf("No\n");
      return 0;
    }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;


const int INF5 = 100000;

int main() {
    int n; cin >> n;
    vi v(n); rep(i, n) cin >> v[i];

    vp nums_even(INF5);
    vp nums_odd(INF5);

    rep(i, INF5) nums_even[i] = mp(0, i);
    rep(i, INF5) nums_odd[i] = mp(0, i);

    rep(i, n) {
        if (i % 2 == 0) nums_even[v[i]].fi += 1;
        else nums_odd[v[i]].fi += 1;
    }
    sort(nums_even.rbegin(), nums_even.rend());
    sort(nums_odd.rbegin(), nums_odd.rend());

    if (nums_even[0].se != nums_odd[0].se) {
        cout << n - nums_even[0].fi - nums_odd[0].fi;
    }
    else {
        if (nums_even[1].fi >= nums_odd[1].fi) {
            cout << n - nums_even[0].fi - nums_even[1].fi;
        } else {
            cout << n - nums_odd[0].fi - nums_odd[1].fi;
        }
    }
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int n;
    string s, ans;

    cin >> n;
    cin >> s;

    int need_front = 0;
    int need_back = 0;

    int cnt_front = 0; // '('の出現数
    int cnt_back  = 0; // ')'の出現数

    for(int i=0; i<n; i++){
        char c = s[i];
        if(c == '('){
            cnt_front++;
        }else if(c == ')'){
            if(cnt_front - cnt_back <= 0){
                need_front++;
            }else{
                cnt_back++;
            }
        }
    }
    need_back = max(cnt_front - cnt_back, 0);

    for(int i=0; i< need_front; i++){
        ans += '(';
    }
    ans += s;
    for(int i=0; i< need_back; i++){
        ans += ')';
    }

    cout << ans << endl;

    return 0;
}

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

ans = 10e9
mint = min(A)
maxt = max(A)

for t in range(mint, maxt + 1):
    temp = 0
    for ai in A:
        temp += pow(abs(t - ai), 2)
    if temp < ans:
        ans = temp

print(ans)

Measured memory_bytes: 3064
// import std = require('tstl')

{
  type Print = void | string | number | string[] | number[]
  let outs: Print[] = []

  const main = (): Print => {
    const r = _io()
    const [N] = r.nn()

    let n = N - 1
    let i = 1

    for (; i < 100; i++) {
      if (n >= 26 ** i) {
        n -= 26 ** i
      } else {
        break
      }
    }
    // i桁

    const strs = n.toString(26).padStart(i, '0')
    const chr = (s: string) => s.charCodeAt(0)
    const ord = String.fromCharCode

    return strs
      .split('')
      .map((v) => {
        if (v <= '9') {
          return 'abcdefghij'[+v]
        }
        return ord(chr(v) + 10)
      })
      .join('')
  }

  const _io = (i = 0) => {
    const str = require('fs').readFileSync('/dev/stdin', 'utf8')
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')

    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map((v) => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  outs.push(main())

  console.log(
    outs
      .map((line) => (typeof line === 'object' ? line.join(' ') : String(line)))
      .join('\n')
  )
}


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

int main()
{
    long x;
    long happy=0;
    cin >> x;
    if(x>=500){
        happy=(x/500)*1000;
        x%=500;
    }
    if(x>=5){
        happy+=(x/5)*5;
        x%=5;
    }
    cout << happy << endl;
}

Measured memory_bytes: 256
(defun coins (a b c x)
  (let ((ans 0))
  (dotimes (i (+ a 1))
  	(dotimes (j (+ b 1))
	  (dotimes (k (+ c 1))
	  (if (eq (+ (* i 500) (* j 100) (* k 50) ) x)
	  (incf ans))
	  )
	)
  )
  ans
  )
)
(format t "~D~%" (coins (read) (read) (read) (read)))

Measured memory_bytes: 4196
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;

void main() {
    size_t n;
    string s1, s2;
    readf("%d\n%s\n%s\n", &n, &s1, &s2);
    auto a1 = s1.split.map!(to!int).array;
    auto a2 = s2.split.map!(to!int).array;
    foreach (i; 1..n) {
        a1[i] += a1[i-1];
        a2[n-i-1] += a2[n-i];
    }
    a1[] += a2[];
    sort(a1);
    writeln(a1[n-1]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() 
{
  int h,n;
  cin>>h>>n;
  vector<int> dp(h+1,100000005);
  dp[0] = 0;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    for(int j=0;j<=h;j++){
      int nj = min(h,j+a);
      dp[nj] = min(dp[j]+b,dp[nj]);
    }
  }
  cout << dp[h] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main(){
    char s[10];
    int ma=0,t=0;
    cin>>s;
    for(int i=0;i<10;i++){
        if(s[i]=='A') t++;
        else if(s[i]=='T') t++;
        else if(s[i]=='G') t++;
        else if(s[i]=='C') t++;
        else t=0;
        if(ma<t) ma=t;
    }
    cout<<ma;
}


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

const int N = 111111;
int occ[N];
int n;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        int cur;
        cin >> cur;
        occ[cur]++;
    }
    int ans = 0;
    for(int i = 0; i < N - 1; i++) {
        int cur = occ[i];
        if(i) cur += occ[i - 1];
        cur += occ[i + 1];
        ans = max(ans, cur);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int sw = 0, se = 0;
  for(int i=1; i<n; i++)
    if(s[i] == 'E') se++;
  int ans = se;
  for(int i=1; i<n; i++){
    if(s[i-1] == 'W') sw++;
    if(s[i] == 'E') se--;
    ans = min(ans, se+sw); 
  }
  cout << ans << endl;
}

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

int main() {
	int long long a,b,c;
	cin >> a >> b >> c;
  if(c <= a){
    cout << a-c << " " << b << endl;
  }
  else if(c <= a+b){
    cout << 0 << " " << b-(c-a) << endl;
  }
  else{
    cout << 0 << " " << 0 << endl;
  }
}

Measured memory_bytes: 256