akhauriyash/Code-Regression huggingface dataset:
function solve()
    N, M = parse.(Int, split(readline()))
    adj = [[] for _ = 1:N]

    for _ = 1:M
        A, B = parse.(Int, split(readline()))
        push!(adj[A], B)
        push!(adj[B], A)
    end

    cnt = 0

    visited = zeros(Int, N)

    for i = 1:N
        if visited[i] == 1 continue end

        cnt += 1

        s = [i]
        while !isempty(s)
            now = pop!(s)
            visited[now] = 1
            for next = adj[now]
                if visited[next] == 0 push!(s, next) end
            end
        end
    end

    println(cnt-1)
end

solve()


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

int main(){
	int k;
	string s;
	cin >> k >> s;
	if(s.length() <= k){
		cout << s << "\n";
	}
	else{
		cout << (s.substr(0, k) + "...") << "\n";
	}
	return 0;
}

Measured memory_bytes: 3104
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }

#define X first
#define Y second

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

	for(int n; cin >> n, n;) {
		int w, h;
		cin >> w >> h;

		vector<vector<int> > field(h + 1, vector<int>(w + 1));
		for(int i = 0; i < n; ++i) {
			int x, y;
			cin >> x >> y;
			++field[y][x];
		}

		for(int i = 1; i <= h; ++i)
			for(int j = 0; j <= w; ++j)
				field[i][j] += field[i - 1][j];

		for(int j = 1; j <= w; ++j)
			for(int i = 0; i <= h; ++i)
				field[i][j] += field[i][j - 1];

		int s, t;
		cin >> s >> t;

		int ans = 0;
		for(int i = 0; i + t <= h; ++i)
			for(int j = 0; j + s <= w; ++j)
				chmax(ans, field[i+t][j+s] + field[i][j] - field[i][j+s] - field[i+t][j]);

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){

    int n, k;
    cin>>n>>k;
    string s;
    cin>>s;

    vector<int> nums;
    int now = 1;
    int cnt = 0;
    rep(i,n){
        if(s[i]==(char)('0'+now)) cnt++;
        else{
            nums.push_back(cnt);
            now ^= 1;
            cnt=1;
        }
    }
    if(cnt!=0) nums.push_back(cnt);

    //1-0-1-0-1-0-1のような配列
    if(nums.size() % 2 == 0) nums.push_back(0);

    int add = 2 * k + 1;
    vector<int> sum(nums.size()+1, 0);
    for(int i=0;i<nums.size();i++){
        sum[i+1] = sum[i] + nums[i];
    }

    int ans=0;
    for(int i=0;i<nums.size();i+=2){
        int left = i;
        int right = min(i+add, (int)nums.size());
        int tmp = sum[right] - sum[left];
        ans = max(tmp, ans);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4220
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#define INF 1000000000
#define MOBD 1000000007
using namespace std;
using ll = long long;
int main()
{
    string s;
    cin >> s;
    int blue = 0, red = 0;
    int ans = 0;
    bool now = false;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == '0')
        {
            blue++;
        }
        else
        {
            red++;
        }
    }
    cout << 2 * min(red, blue) << endl;
}


Measured memory_bytes: 512
import math
dlst = []

N, D=map(int, input().split())

for i in range(N):
    grid = list(map(int, input().split()))
    dlst.append(grid)

count=0
distance = 0

for i in range(N-1):
    for m in range(i+1,N):
        distance = 0
        for j in range(D):
            distance += (dlst[i][j] - dlst[m][j])**2
        judge=math.sqrt(distance)
        if judge.is_integer():
            count += 1
print(count)

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	hps := scanIntSlice(n)

	sort.Sort(sort.Reverse(sort.IntSlice(hps)))

	count := 0
	for i := k; i < n; i++ {
		count += hps[i]
	}

	fmt.Printf("%d\n", count)
}

func scanIntSlice(size int) []int {
	input := []int{}
	for i := 0; i < size; i++ {
		var in int
		fmt.Scanf("%d", &in)
		input = append(input, in)
	}
	return input
}


Measured memory_bytes: 7424
#include <cstdio>
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

struct aa{
    int x;
    int y;
    int cost;
};
int main()
{
    while(true){
        int W,H;cin>>W>>H;
        if(!W)break;
        vector<vector<vector<int>>>walls(H,vector<vector<int>>(W,vector<int>(4,1)));
        for(int y=0;y<2*H-1;++y){
            if(y%2){
                //テヲツィツェテァツキツ?   
                for(int x=0;x<W;++x){
                    int a;cin>>a;
                    if(!a){
                        walls[y/2][x][1]=false;
                        walls[y/2+1][x][3]=false;
                    }
                }
            }else{
                //テァツクツヲテァツキツ?
                for(int x=0;x<W-1;++x){
                    int a;cin>>a;
                    if(!a){
                        walls[y/2][x+1][0]=false;
                        walls[y/2][x][2]=false;
                    }
                }
            }
        }
        queue<aa>que;
        vector<vector<int>>memo(H,vector<int>(W,100000));
        memo[0][0]=0;
        que.push(aa{0,0,0});
        while(!que.empty()){
            aa atop(que.front());
            que.pop();
            for(int way=0;way<4;++way){
                if(!walls[atop.y][atop.x][way]){
                    int nextx=atop.x+dx[way];
                    int nexty=atop.y+dy[way];
                    int nextcost=atop.cost+1;
                    if(nextx>=0&&nextx<W&&nexty>=0&&nexty<H){
                        if(memo[nexty][nextx]>nextcost){
                            memo[nexty][nextx]=nextcost;
                            que.push(aa{nextx,nexty,nextcost});
                        }
                    }
                }
            }
        }
        int ans=memo[H-1][W-1];
        if(ans>10000){
            ans=0;
        }else{
            ans++;
        }
        cout<<ans<<endl;

        //bfs

    }
    
    return 0;
}

Measured memory_bytes: 3164
//by spli
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;

int a,b;
char s[20];

int main(){
	scanf("%d%d",&a,&b);
	scanf("%s",s+1);
	bool flag=1;
	for(int i=1;i<=a;++i)
		if(s[i]<'0'||s[i]>'9') {flag=0;break;}
	for(int i=1;i<=b;++i)
		if(s[a+1+i]<'0'||s[a+1+i]>'9') {flag=0;break;}
	if(s[a+1]!='-') flag=0;
	if(flag) puts("Yes");
	else puts("No");
	return 0;
}



















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

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> k(M,vector<int>(N));
  vector<int> k_num(M);
  vector<int> p(M);
  
  for(int i=0;i<M;++i){
    cin >> k_num[i];
    for(int j=0;j<k_num[i];++j){
      cin >> k[i][j];
    }
  }
  for(int i=0;i<M;++i){
    cin >> p[i];
  }
  
  int answer = 0;
  for(int i=0;i<(1<<N);++i){
    bool flag = true;
    for(int j=0;j<M;++j){
      int on_tmp = 0;
      for(int l=0;l<k_num[j];++l){
        if((i>>(k[j][l]-1))&1){
          on_tmp++;
        }
      }
      if(on_tmp%2!=p[j]){
        flag = false;
        break;
      }
    }
    
    if(flag){
      answer++;
    }
    
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <vector>

using namespace std;

bool compare_F(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second > b.second;
  }
}

bool compare_S(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second > b.second;
  } else {
    return a.first > b.first;
  }
}

template <typename T>
void ArrayInput(vector<T> &A) {
  for (auto itr = A.begin(); itr != A.end(); ++itr) {
    cin >> *itr;
  }
}
template <typename T>
void ArrayPut(vector<T> &A) {
  for (auto itr = A.begin(); itr != A.end(); ++itr) {
    cout << *itr << " ";
  }
  cout << endl;
}

using Graph = vector<vector<uint32_t>>;
vector<bool> seen;
vector<uint32_t> dis, A_dis, T_dis;

void dfs(Graph &G, uint32_t v) {
  seen[v] = true;

  for (auto itr = G[v].begin(); itr != G[v].end(); ++itr) {
    if (seen[*itr]) continue;
    dis[*itr] = dis[v] + 1;
    dfs(G, *itr);
  }
}
int main() {
  uint64_t N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  map<char, uint64_t> score;
  score['r'] = P;
  score['s'] = R;
  score['p'] = S;

  vector<string> partial;
  for (uint32_t i = 0; i < K; ++i) {
    string t;
    for (uint32_t j = i; j < T.size(); j += K) t += T[j];
    partial.push_back(t);
  }
  uint64_t res = 0;
  for (auto itr = partial.begin(); itr != partial.end(); ++itr) {
    char prev = ' ';
    for (auto rsp = itr->begin(); rsp != itr->end(); ++rsp) {
      if (*rsp == prev) {
        prev = ' ';
        continue;
      } else {
        prev = *rsp;
        res += score[*rsp];
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 5236
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#define _for(i,n) for(int i = 0; i <= n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

using namespace std;

int main() {
  int R,G,B,n;
  cin >> R >> G >> B >> n;
  int rmax = n/R;
  int gmax = n/G;
  int bmax = n/B;
  int count = 0;
  _for(r,rmax) _for(g,(n-r*R)/G) if ((n-r*R-g*G)%B==0) count++;
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str,str2;
    cin>>n;
    a=n/11;
    b=n%11;
    a=a*2;
    if(b>=7) a+=2;
    else if (b>=1) a++;
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
Y = []
b = 0
for i in range(N):

    for k in range(N):

        a = 0
        if i < k:
            for j in range(D):
                a = a+(X[i][j]-X[k][j])**2

            Y.append(a)
for l in range(len(Y)):
    if math.sqrt(Y[l])-int(math.sqrt(Y[l])) == 0:
        b = b+1
print(b)

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

int calc(int x)
{
    int ret = 0;
    while (x > 0)
    {
        ret += x % 10;
        x /= 10;
    }
    return ret;
}
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int sum = calc(i);
        if (sum >= a && sum <= b)
            ans += i;
    }
    cout << ans << endl;
}

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


int main()
{
  int n, x;
  cin >> n;
  vector<int> dp(n), a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  dp[0] = 0;
  for (int i = 1; i < n; ++i) {
    dp[i] = dp[i-1] + abs(a[i] - a[i-1]);
    if (i > 1)
      dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]));
  }
  cout << dp[n-1] << '\n';

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
#define int long long 
#define pi pair<int,int>
#define vpi vector<pi>
#define vvi vector<vpi>
#define For(i,n) for(int i=0;i<n;i++)
#define pie =3.14159265358979323846264338327950;
const int mod= 1e9+7;


int32_t main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;i++) cin>>ar[i];
    sort(ar,ar+n);
    int ans=ar[n-1];
    int j=n-2;
    int cnt=1;
    while(cnt<n-1){
		cnt++;
		ans+=ar[j];
		if(cnt==n-1){
			break;
		}
		cnt++;
		ans+=ar[j];
		j--;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5224
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string s;
    cin>>s;
    //最終状態はs.length()==2 もしくは隣り合う形になる
    //両端は消せないので両端の形は決まっている
    //xyxyxy
    //xyxyxyx
    if(s[0] == s.back()){
        if(s.size()&1) cout<<"Second"<<endl;
        else puts("First");
    }else{
        if(s.size()&1) puts("First");
        else puts("Second");
    }
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
int main(void) {
    int num,id,i,tempid;
    double height,weight,BMI,best;
    while (scanf("%d",&num)!=EOF&&num!=0) {
        for (i=0; i<num; i++) {
            scanf("%d%lf%lf",&tempid,&height,&weight);
            height/=100.0;
            BMI=weight/(height*height);
            if (i==0) {
                id = tempid;
                best = BMI;
            } else {
                if (fabs(BMI-22.0)<fabs(best-22.0)) {
                    best=BMI;
                    id = tempid;
                } else if ((abs(BMI-22.0)==abs(best-22.0))&&tempid<id) {
                    id = tempid;
                }
            }
        }
        printf("%d\n",id);
    }
    return 0;
}

Measured memory_bytes: 628
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m==-1 && f==-1 && r==-1)
            break;
            if(m==-1 || f==-1){
                System.out.println("F");
            }else if(m+f >= 80){
                System.out.println("A");
            }else if(m+f >= 65){
                System.out.println("B");
            }else if(m+f >= 50){
                System.out.println("C");
            }else if(m+f >= 30){
                if(r >= 50){
                    System.out.println("C");
                }else{
                System.out.println("D");
                }
            }else{
                System.out.println("F");
            }

        }
}
}


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

int main(){
    int n;
    cin >> n;
    vector<string> v(n);

    int num = 0;
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        v[i] = s;
        for(int i=0; i<s.size()-1; i++){
            if(s[i] == 'A' && s[i+1] == 'B') num++;
        }

        if(s[0] == 'B' && s[s.size()-1] == 'A') c3++;
        else if(s[0] == 'B') c2++;
        else if(s[s.size()-1] == 'A') c1++;
    }

    int ans = 0;

    if(c1 == 0 || c2 == 0 || c3 == 0){
        //どれかがない場合を特別視

        if(c1 == 0 && c2 != 0 && c3 != 0){
            ans = min(c2, c3);
            if(c3 > c2) ans += c3 - c2;
        }

        if(c2 == 0 && c1 != 0 && c3 != 0){
            ans = min(c1, c3);
            if(c3 > c1) ans += c3 - c1;
        }

        if(c1 != 0 && c2 != 0 && c3 == 0){
            ans = min(c1, c2);
        }

        if(c1 == 0 && c2 == 0 && c3 != 0){
            ans = c3 - 1;
        }

        ans += num;
        cout << ans << endl;
        return 0;
    }

    else {
        //c3について計算
        if(c3 > 0) ans += c3 - 1;
        //c3に繋げられるか
        if(c1 >= 1 && c2 >= 1 && c3 >= 1){
            ans += 2;
            c1--;
            c2--;
        }
        //あまったc1, c2について計算
        ans += min(c1, c2);

        ans += num;
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main() {


	int nofp,h,w,ans=0,arr[1002],arr1[1002];
	cin>>nofp>>h>>w;
	for(int i=1;i<=nofp;++i)
	{
		cin>>arr[i]>>arr1[i];

	}for(int j=1;j<=nofp;++j)
	{
		if(arr[j]>=h&&arr1[j]>=w)
			ans++;

	}cout<<ans<<endl;









    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli x, y, z;
    x = 0;
    y = 0;
    z = 0;
    lli n,a,b;
    cin >> n >> a >> b;
    rep(i, n) {
        lli p;
        cin >> p;
        if(a>=p)
        {
            x++;
        }
        else if(b<p)
        {
            z++;
        }
        else
        {
            y++;
        }
    }
    out(min(x, min(y, z)));
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    
    int score = 0;
    int g_count = 0;
    int p_count = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (g_count == p_count)
        {
            g_count += 1;
            
            if (s[i] == 'p') { score -= 1; }
        } else {
            p_count += 1;
            
            if (s[i] == 'g') { score += 1; }
        }
    }
    
    cout << score << endl;
    
    return 0;
}

Measured memory_bytes: 512
n=gets.to_i
a=gets.split.map &:to_i
b=a.sort
b=[0]+b
c=0
n.times do |i|
  if a[i]>c
    g=b.find_index{|e|e>=a[i]}
    r=b[0..g-1]
    p (b.length-g)*(a[i]-c)+r.inject(:+)-c*g
    b=b[g..-1]
    c=a[i]
  else
    p 0
  end
end

Measured memory_bytes: 17528
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void){
   char input[4];
   int a=0;
   scanf("%s",input);
   a += (strcmp("abc",input)==0)?1:0;
   a += (strcmp("acb",input)==0)?1:0;
   a += (strcmp("bac",input)==0)?1:0;
   a += (strcmp("bca",input)==0)?1:0;
   a += (strcmp("cab",input)==0)?1:0;
   a += (strcmp("cba",input)==0)?1:0;
   if (a==1){printf("Yes\n");}else{printf("No\n");}
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
struct Bitset{
	uint a[64];
	Bitset(){
		memset(a,0,sizeof(a));
	}
	void set(int x){
		a[x>>5]|=1u<<(x&31);
	}
	bool operator [](int x)const{
		return (a[x>>5]>>(x&31))&1;
	}
	Bitset operator &(const Bitset &b)const{
		Bitset c;
		For(i,0,63) c.a[i]=a[i]&b.a[i];
		return c;
	}
	Bitset operator ^(const Bitset &b)const{
		Bitset c;
		For(i,0,63) c.a[i]=a[i]^b.a[i];
		return c;
	}
	Bitset operator |(const Bitset &b)const{
		Bitset c;
		For(i,0,63) c.a[i]=a[i]|b.a[i];
		return c;
	}
};
const int N=2005;
vector<int> e[N];
int n,m,t,T;
int dfn[N],ed[N],fa[N],dep[N];
Bitset par[N],son[N],nson[N],g[N],all;
int L[N][N],top[N][N];
pii q[N*N/2];
void dfs(int x,int f){
	dfn[x]=++T; fa[x]=f;
	if (f!=-1){
		dep[x]=dep[f];
		par[x]=par[f];
	}
	++dep[x];
	par[x].set(x);
	for (auto i:e[x])
		if (i!=f){
			dfs(i,x);
			son[x]=son[x]^son[i];
		}
	son[x].set(x);
	nson[x]=all^son[x];
	ed[x]=T;
}
int LCA(int x,int y){
	if (L[x][y]!=-1) return L[x][y];
	if (x==y) return L[x][y]=x;
	if (dep[x]<dep[y]) swap(x,y);
	return L[x][y]=L[y][x]=LCA(fa[x],y);
}
int find_top(int x,int y){
	if (top[x][y]!=-1) return top[x][y];
	return top[x][y]=(fa[x]==y?x:find_top(fa[x],y));
}
void add(int x,int y){
	if (g[x][y]) return;
	g[x].set(y); g[y].set(x);
	q[++t]=pii(x,y);
}
void work(int id,const Bitset &a){
	For(i,0,63) if (a.a[i])
		For(j,0,31) if (a[(i<<5)|j])
			add(id,(i<<5)|j);
}
int main(){
	scanf("%d%d",&n,&m);
	For(i,0,n-1) all.set(i);
	For(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		e[--x].PB(--y);
		e[y].PB(x);
	}
	dfs(0,-1);
	For(i,0,n-1) g[i].set(i);
	For(i,1,m){
		int x,y;
		scanf("%d%d",&x,&y);
		q[++t]=pii(--x,--y);
		g[x].set(y);
		g[y].set(x);
	}
	memset(L,-1,sizeof(L));
	memset(top,-1,sizeof(top));
	For(i,1,t){
		int x=q[i].fi,y=q[i].se;
		if (dep[x]>dep[y]) swap(x,y);
		int L=LCA(x,y);
		Bitset sta=par[x]^par[y];
		sta.set(L); sta=sta|son[y];
		if (dfn[x]<=dfn[y]&&ed[y]<=ed[x])
			sta=sta|nson[find_top(y,x)];
		else sta=sta|son[x];
		work(x,sta&g[y]&(all^g[x]));
		work(y,sta&g[x]&(all^g[y]));
	}
	printf("%d\n",t);		
}


Measured memory_bytes: 50688
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    string s;
    cin >> s;
    lint n = s.size();

    vector<pair<char, lint>> v;
    v.emplace_back(s[0], 1);
    for(lint i=1; i<n; i++) {
        if(v.back().first == s[i])  v.back().second++;
        else  v.emplace_back(s[i], 1);
    }

    lint ans = 0;
    lint pre = 0;
    for(lint i=0; i<v.size(); i++) {
        if(v[i].first == '>') {
            ans += max(pre, v[i].second);
            ans += (v[i].second-1) * (v[i].second) / 2;
        } else {
            pre = v[i].second;
            ans += (v[i].second-1) * (v[i].second) / 2;
        }
    }
    if(v.back().first == '<')  ans += pre;

    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define mp make_pair

const int INF = INT_MAX;

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n, k;
	cin >> n >> k;

	vi fruit(n);
	for(int i = 0; i < n; i++){
		cin >> fruit[i];
	}
	sort(fruit.begin(), fruit.end());

	int ans = 0;
	for(int i = 0; i < k; i++){
		ans += fruit[i];
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3664
#coding:utf-8
s = int(input())
ls = [s]
while(1):
    n = ls[-1]
    if  n % 2 == 0:
        new = n / 2
    else:
        new = 3*n + 1
    if new in ls:
        print (len(ls)+1)
        break
    else:
        ls.append(new)

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1000000007;

int a[maxN];
vector<pii> v[maxN];

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].push_back({a[y],y});
		v[y].push_back({a[x],x});
	}
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		sort(v[i].begin(),v[i].end());
		int k = v[i].size();
		if(k == 0)
		{
			ans++;
		}
		else if(a[i] > a[v[i][k-1].second])
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12172
#include <stdio.h>

int main(void)
{
    int i, n, tmp;
    long long int sum = 0;
    int max_num = -1000001;
    int min_num = 1000001;

    scanf("%d", &n);  

    for(i = 0; i < n; i++)
    {
        scanf("%d", &tmp);

        sum += tmp;

        if(max_num < tmp)
        max_num = tmp;

        if(min_num > tmp)
        min_num = tmp;
    }

    printf("%d %d %ld\n", min_num, max_num ,sum);

    return 0;
}


Measured memory_bytes: 2760
<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
$t=explode(' ',$t);
if($t[0]<10)
{
    echo (100*(10-$t[0]))+$t[1];
}else
{
    echo $t[1];
}

Measured memory_bytes: 4604
n = int(input())
a = list(map(int, input().split()))
x1 = 0
pm = 1
for i in a:
    x1 += i*pm
    pm *= -1

print(x1, end=' ')
px = x1//2
for i in range(n-1):
    px = a[i]-px
    print(px*2, end=' ')

Measured memory_bytes: 14028
object Main extends App {
var get1 = readLine.split(" ")
var loop = get1(1).toInt
var word = readLine.split("")
var count : Array[Int] = new Array(word.size)
	for(i <- word.indexOf("A") to word.size - 1) {
    	if(word(i-1)=="A" && word(i)=="C")
      		count(i) = count(i - 1) + 1
        else
          count(i) = count(i - 1)
    }
  	for(i <- 0 to loop - 1) {
      var position = readLine.split(" ")
    	println(count(position(1).toInt) - count(position(0).toInt))
    }
}

Measured memory_bytes: 56688
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    int c1=0;
    int c2=0;
    for(int i=0;i<s.length();i++){
        if(i&1){
            if(s[i]!='0')c1++;

        }
        else{
            if(s[i]!='1')c1++;
        }
    }
    for(int i=0;i<s.length();i++){
        if(i&1){
            if(s[i]!='1')c2++;

        }
        else{
            if(s[i]!='0')c2++;
        }
    }
    cout<<min(c1,c2);
}


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

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



Measured memory_bytes: 3092
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int abprice = A * X + B * Y;

		int target1 = 0;
		int target1_2 = 0;
		int target2 = 0;
		int dif = 0;
		if (X < Y) {
			target1 = X;
			target1_2 = Y;
			target2 = B;
			dif = Y - X;
		} else {
			target1 = Y;
			target1_2 = X;
			target2 = A;
			dif = X - Y;
		}

		int cprice1 = C * target1 * 2 + dif * target2;
		int cprice2 = C * target1_2 * 2;
		int cprice = cprice1 > cprice2 ? cprice2 : cprice1;

		if (abprice > cprice) {
			System.out.println(cprice);
		} else {
			System.out.println(abprice);
		}

	}
}

Measured memory_bytes: 21844
n,m = [int(i) for i in input().split()]
ab = []
for i in range(n):
	array = list(map(int,input().split()))
	ab.append(array)
cd = []
for i in range(m):
	arra = list(map(int,input().split()))
	cd.append(arra)
chk = []
for i in range(n):
	for j in range(m):
		chk.append(abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1]))
for i in range(n):
	ans = chk[:m]
	#print(ans)
	print(ans.index(min(ans))+1)
	chk = chk[m:]

Measured memory_bytes: 3064
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int a, b, c, i;
   
      
    scanf("%d %d %d", &a, &b, &c );
   

    for( i = 1 ; a * i <= a * b ; i = i + 1 ){

        if( ( a * i ) % b == c ){

            printf("YES\n");

            return 0;

            }

        }
   

    printf("NO\n");


    return 0;
                                                          
}


Measured memory_bytes: 128
#!/usr/bin/env ruby

n = gets.chomp.to_i

money = 0
n.times do
  (x, y) = gets.chomp.split(/ /)
  if (y == 'JPY')
    money += x.to_i
  else
    jpy = x.to_f * 380000.0
    money += jpy
  end
end

puts money

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<double, double> P;
constexpr int IINF = INT_MAX;


int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> d(m), id(n, -1), dist(1<<m);
    vector<vector<int> > v(n, vector<int>(k)), graph(1<<m);
    for(int i=0;i<m;i++){
        cin >> d[i];
        d[i]--;
        id[d[i]] = i;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<k;j++){
            cin >> v[i][j];
            v[i][j]--;
        }
    }
    // i番目の暗い部屋にいるかをbitで持った状態を頂点、指示による遷移を辺とする
    for(int S=1;S<(1<<m);S++){
        for(int j=0;j<k;j++){
            int T = 0;
            for(int i=0;i<m;i++){
                if(((S>>i)&1) && id[v[d[i]][j]] >= 0){
                    T |= 1<<id[v[d[i]][j]];
                }
            }
            graph[S].push_back(T);
        }
    }
    // BFS
    fill(dist.begin(), dist.end(), IINF);
    dist[(1<<m)-1] = 0;
    queue<int> que;
    que.push((1<<m)-1);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(auto u : graph[v]){
            if(dist[u] == IINF){
                dist[u] = dist[v] + 1;
                que.push(u);
            }
        }
    }
    cout << dist[0] << endl;
    return 0;
}



Measured memory_bytes: 38788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int getTimesDivideBy2(int a) {
            int times = 0;
            while (a % 2 == 0) {
                a /= 2;
                times++;
            }
            return times;
        }
        void solve(InputReader in, PrintWriter out) {
            // write your code here
            int N = in.nextInt();
            int ans = 0;
            for (int i = 0; i < N; i++) {
                int a = in.nextInt();
                ans += getTimesDivideBy2(a);
            }
            out.println(ans);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

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

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 25300
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;

namespace AtCoderSolve
{
    class Solve
    {

        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;


        static int N, K;
        static int[] h;
        
        //static long[] A, B;


        public static void Input()
        {
            var cin = new Scanner();
            var input = cin.SplitReader();
            N = input[0];
            K = input[1];
            h = cin.SplitReader();
        }


        static void Main(string[] args)
        {
            Input();
            
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            long[] dp = new long[N];
            for(var i = 0; i < N; i++)
            {
                dp[i] = INF;
            }

            dp[0] = 0;
            for(var i = 1; i < N; i++)
            {
                for(var j = 1; j <= K; j++)
                {
                    if (i - j < 0)
                    {
                        continue;
                    }
                    dp[i] = Min(dp[i], dp[i - j] + Abs(h[i] - h[i - j]));
                }
            }

            Console.WriteLine(dp[N - 1]);

            //Console.Out.Flush();
        }
    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }
}






Measured memory_bytes: 20576
#Fukushimaken: 
from heapq import heappop, heappush
def P(i):
    return 31 if i % 5 == 1 else 3

def M(i):
    return 17 * (i % 2) + 3 * (i % 3) + 19

def check(c, n):
    for i in xrange(16):
        if (c >> i) & n == 0:
            return i
    return None

ans = [-1] * 100 + [0]
eq = map(lambda i: (i * 5, i, None, P(i)), xrange(100))
c = 1 << 17
while len(eq) != 0:    
    m, n, i, p = heappop(eq)
    if i is None:        
        i = check(c, p)
        if ans[n-1] != -1 and i is not None:
            c = c | (p << i)
            ans[n] = m - n * 5
            heappush(eq, (m + M(n), n, i, p))
        else:
            heappush(eq, (m + 1, n, None, p)) #
    else:        
        c = c ^ (p << i)

while True:
    try:
        print ans[input()]
    except:
        break

Measured memory_bytes: 4512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei,
	      P p=[](E a,size_t b){b++;return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.assign(2*n-1,ti);
    laz.assign(2*n-1,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
  void update(int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<Int,Int> ch(n,
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  0,0,
			  [](Int a,Int b){return a*b;});
  ch.build(n,vector<Int>(n,0));
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>s>>t;
      cout<<ch.query(s-1,t)<<endl;
    }else{
      cin>>s>>t>>x;
      ch.update(s-1,t,x);
    }
  }
}

/*
  verified on 2018/03/04
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G&lang=jp
*/



Measured memory_bytes: 7604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int N, M;

void solve() {
    cin >> N >> M;
    ll A[N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A, A + N);
    priority_queue<P> O;
    for (int i = 0; i < M; ++i) {
        int b, c;
        cin >> b >> c;
        O.push(P(c, b));
    }
    int i = 0;
    while(!O.empty()) {
        P t = O.top(); O.pop();
        int count = 0;
        while(A[i] < t.first && count < t.second) {
            A[i] = t.first;
            count++;
            i++;
        }
        if (count == 0) break;
    }
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += A[i];
    }
    cout << ans << endl;
}

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


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

int main() {
  long long int a,b,c,d;
  long long int x,y;
  long long int ans;


  cin >> a >> b >> c >> d;
  cout << max({a*c,a*d,b*c,b*d}) << endl;
}

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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

int main()
{
  int N, F[100][10], P[100][11];

  cin >> N;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 10; j++) {
      cin >> F[i][j];
    }
  }

  for(int i = 0; i < N; i++) {
    for(int j = 0; j <= 10; j++) {
      cin >> P[i][j];
    }
  }

  int ret = -INF;
  for(int i = 0; i < (1 << 10); i++) {
    if(i == 0) continue;
    vector< int > sum(N, 0);
    for(int j = 0; j < N; j++) {
      for(int k = 0; k < 10; k++) {
        if((i >> k) & 1) {
          if(F[j][k] == 1) {
            ++sum[j];
          }
        }
      }
    }
    int cost = 0;
    for(int j = 0; j < N; j++) {
      cost += P[j][sum[j]];
    }
    ret = max(ret, cost);

  }

  cout << ret << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    VI a(n);
    VI b(m);
    REP(i,n)cin>>a[i];
    REP(i,m)cin>>b[i];
    a.PB(x);
    b.PB(y);
    SORT(a);
    SORT(b);
    string ans = "War";
    if(a.back() < b.front())ans = "No War";
    PUTS(ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n,x;
int A[SIZE];

int main()
{
	scanf("%d %d",&n,&x);
	ll ans=0;
	for(int i=0;i<n;i++)scanf("%d",&A[i]);
	for(int i=0;i<n-1;i++){
		if(A[i]+A[i+1]<=x)continue;
		else if(A[i] <= x){
			ans += (ll)A[i]+A[i+1]-x;
			A[i+1] = x-A[i];
		}else{
			ans += (ll)A[i]+A[i+1]-x;
			A[i+1]=0;
		}
	}
	printf("%lld\n",ans);

	return 0;
}


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

using namespace std;
const int N = 2e5+100;
const double  eps  = (1e-10);
//点
struct Point{
    double x,y;
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    Point operator + (Point p){return Point(x+p.x,y+p.y);}
    Point operator - (Point p){return Point(x-p.x,y-p.y);}
    Point operator * (double a){return Point(a*x,a*y);}
    Point operator / (double a){return Point(x/a,y/a);}
    double norm(){return x*x+y*y;}//模的平方
    double ABS() {return sqrt(norm());}//模
};
//线段
struct Segment{
    Point p1,p2;
};
double dot(Point a,Point b){
    return a.x*b.x+a.y*b.y;
}
double cross(Point a,Point b){
    return a.x*b.y-a.y*b.x;
}
vector<Point> G;
//旋转卡壳计算凸包直径
double Diameter(vector<Point> G){
    double ans=0;
    int n=G.size();
    for(int i=0,k=0;i<n;i++){
        while((G[i]-G[k]).norm()<(G[i]-G[(k+1)%n]).norm()) k=(k+1)%n;
        ans=max(ans,(G[i]-G[k]).ABS());
    }
    return ans;
}
int main(){
    int n;scanf("%d",&n);
    double x,y;
    for(int i=1;i<=n;i++){
        scanf("%lf %lf",&x,&y);
        G.push_back({x,y});
    }
    double ans=Diameter(G);
    printf("%.10lf\n",ans);
    return 0;
}


Measured memory_bytes: 5408
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
int n , A , B , C , D , k;

inline bool check(int len)
{
	int a = A - len / (k + 1) * k - len % (k + 1) , b = B - len / (k + 1);
	return b <= (LL)a * k;
}

int main()
{
	scanf("%d" , &n);
	while(n--)
	{
		scanf("%d%d%d%d" , &A , &B , &C , &D);
		int l = 0 , r = A + B + 1 , mid , ans = 1; k = max(ceil(1.0 * A / (B + 1)) , ceil(1.0 * B / (A + 1)));
		while(l < r)
		{
			mid = (l + r) >> 1;
			if(check(mid)) l = mid + 1; else r = mid;
		}
		// l = ans;
		int a = A - l / (k + 1) * k - l % (k + 1) , b = B - l / (k + 1);
		r = l + b - a * k + 1;
		for(int i = C ; i <= min(l , D) ; ++i) if(i % (k + 1)) putchar('A'); else putchar('B');
		for(int i = max(C , l + 1) ; i <= D ; ++i) if((i - r) % (k + 1)) putchar('B'); else putchar('A');
		putchar('\n');
	}
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    string s;cin>>s;
    string t="CODEFESTIVAL2016";
    int cnt=0;

    rep(i,s.size()){
        if(s[i]!=t[i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

int main() {
	ll X;
	cin >> X;

	for(int i = 0; i < 1001; i++) {
		for(int j = -1000; j < i; j++) {
			long double x1 = i * i * i * i * i;
			long double x2 = j * j * j * j * j;
			double x3 = pow(i, 5);
			double x4 = pow(j, 5);

			// cout << i << ", " << j << " " << x1 << " : " << x2 << " = " << (x1 - x2) << endl;
			// cout << i << ", " << j << " " << x3 << " : " << x4 << " = " << (x3 - x4)  << endl;
			if ((x3 - x4) == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
  return 0;
}


Measured memory_bytes: 4108