akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int x, y;
    cin >> x >> y;
    if (2 * x <= y && y <= 4 * x && y % 2 == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 3124
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

import copy
MAX_SCORE = -float('inf')
MAX_ANS = -1
for K in range(26):
    v = 0
    ans = [0]*D
    L = [0]*26
    for i in range(1, D+1):
        max_score = -float('inf')
        max_idx = 0
        for j in range(26):
            temp = v
            temp += S[i-1][j]
            L_ = copy.copy(L)
            L_[j] = i
            for k in range(26):
                for l in range(i, min(i+K, D+1)):
                    temp -= C[k]*(i-L_[k])
            if temp >= max_score:
                max_score = temp
                max_idx = j
        v = max_score
        L[max_idx] = i
        ans[i-1] = max_idx+1
    if v >= MAX_SCORE:
        MAX_SCORE = v
        MAX_ANS = ans
print(*MAX_ANS, sep='\n')


Measured memory_bytes: 76292
#include<iostream>

using namespace std;

int main(){
 int a,b,c;
  cin >> a >> b >> c;
  
  if((a==5 && b==5 && c==7)||(a==7 && b==5 && c==5)||(a==5 && b==7 && c==5)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll N;
ll A[55];

int main()
{
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    sort(A, A + N, [](ll a, ll b) { return a > b; });

    ll ans = 0;
    vector<ll> v(N, 0);
    while (true)
    {
        ll s = 0;
        REP(i, N)
        {
            //! N-1以下にするのに何回の操作が必要？
            ll a = A[i] + ans - v[i] - (N - 1);
            ll t = (a + N - 1) / N;
            v[i] = t;
            s += t;
        }

        ans = s;
        bool check = true;
        REP(i, N)
        {
            ll b = A[i] + s - v[i] - v[i] * N;
            if (b < 0)
            {
                check = true;
                break;
            }
            if (b >= N)
                check = false;
        }
        if (check)
            break;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MAX 5000005
#define P ((ll)1e9+7)
using namespace std;

ll qpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n&1) res = res*a%P;
        a = a*a%P, n >>= 1;
    }
    return res;
}

int n, m;
ll f[MAX];

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

    ll ans = 0;
    for(int i = m; i >= 1; i--){
        f[i] = qpow(m/i, n);
        ans = (ans + f[i]*i%P)%P;
        for(int j = 2; i*j <= m; j++){
            ans = (ans-f[i*j]*i%P+P)%P;
            f[i] -= f[i*j];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;

const int N = 1e5;
const int INF = 1e9;
typedef long long int ll;
typedef pair<int,int> ii;

string a,b,total;
int n;

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

	cin>>n;
	cin>>total;

	for(int i=0;i<n/2;++i)
		a+=total[i];

	for(int i=n/2;i<n;++i)
		b+=total[i];
	if(a == b)
		cout<<"Yes\n";
	else
		cout<<"No\n";

}

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

int main() {
	string s;
	cin >> s;
	if (s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]) {
		cout << "Yes" << endl;
	}else if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]){
		cout << "Yes" << endl;
	}
	else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main() {
    int N, ans, m = 0;
    cin >> N;
    for (int i = 0; ; ++i) {
        if (N < m) {
            ans = i - 1;
            break;
        }
        m += pow(2,i);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3288
#include <iostream>
using namespace std;
string a;
int n, mx, c[130];
bool f(int p) {
	for(int i=0; i<p; i++) if(a[i] != a[p+i]) return 0;
	return 1;
}

int main() {
	cin>>a;
	for(int i=0; i<a.size()-1; i++) {
		c[a[i]]++;
		c[a[i]]%2 ? n++ : n--;
		if(n==0 && f(i/2+1)) mx = i+1;
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
#define fi first
#define se second
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

void Main()
{
  i64 n,m;
  cin >> n >> m;

  string ans = "1";
  while(sz(ans)<n) ans += "0";

  if(n==1) ans = "0";

  i64 s;
  char c;
  v(bool) b(n,false);
  rep(i,m){
    cin >> s >> c;
    if(b[s-1] && ans[s-1]!=c){
      cout << "-1\n";
      return;
    }else if(s==1 && c=='0' && n!=1){
      cout << "-1\n";
      return;
    }
    ans[s-1] = c;
    b[s-1] = true;
  }
  cout << ans << endl;

}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    long double A, B, H, M, D, P;
    cin >> A >> B >> H >> M;

    P = 3.141592653589793;

    D = abs(30 * H - 5.5 * M);

    cout << fixed << setprecision(15) << sqrt(A * A + B * B - 2 * A * B * cos(D*P/180)) << endl;
}

Measured memory_bytes: 4164
import java.util.Scanner;

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

		int X = n.nextInt();
		int Y = n.nextInt();

		if(Y % 2 != 0 || (X*4) < Y || (X*2) > Y) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 35580
// ABC079_B
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define vl vector<ll>
#define pll pair<ll, ll>
#define F first
#define S second

int main() {
    // input
    ll N;
    cin >> N;
    vl vec(N+1);
    // calculation
    vec[0] = 2;
    vec[1] = 1;
    
    if (N == 1) {
        cout << vec[N] << "\n";
    } else {
        for (ll i = 2; i <= N; ++i) {
            vec[i] = vec[i-1] + vec[i-2];
        }
        cout << vec[N] << "\n";
    }
    
    return 0;
}

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

using namespace std;

int main()
{
set<string> S;
int n;
cin>>n;
for(int i =0;i<n;i++)
{
 string a;
 cin>>a;
 S.insert(a);
}

cout<<S.size()<<endl;
return 0;
}


Measured memory_bytes: 19060
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm>
using namespace std;

int p[10], c[10];
bool S[10];
signed main() {
	int ans = INT_MAX;
	int d, g; cin >> d >> g;
	for (int i = 0; i < d; i++) {
		cin >> p[i] >> c[i];
	}
	for (int i = 0; i < (1 << d); i++) {
		int m = 0, score = 0;
		for (int j = 0; j < d; j++) {
			if ((1 << j)&i) {
				S[j] = true;
				m += p[j];
				score += (100 * (j + 1)*p[j]) + c[j];
			}
			else S[j] = false;
		}
		if (score >= g){ans = min(ans, m); continue; }
		for (int j = d - 1; j >= 0; j--) {
			if (score + (p[j] - 1) * 100 * (j + 1) >= g&&!S[j]) {
				int k = (g - score) / (100 * (j + 1));
				if ((g - score) % (100 * (j + 1)))k++;
				ans = min(ans, m + k);
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int ans=1;
	while(ans<=n)
	{
		ans*=2;
	}
	if(n==1)
		cout<<1<<endl;
	else
	cout<<ans/2<<endl;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << 6 - a - b << endl;
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int arr[100005];
int str[100005];
int main()
{
    int n;
    cin>>n;
    int counter=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(str[arr[i]]==0){
            str[arr[i]]=1;
            counter++;
        }
    }
    if(counter%2==0)
        counter--;

    cout<<counter<<endl;


    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

struct coord {
  int x;
  int y;
};
int H,W;
char map[55][55];
int length[55][55];
bool use[55][55];

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
coord start = (coord){0, 0};
coord end;

int bfs(){
  std::queue<coord> queue;
  queue.push(start);
  length[start.x][start.y] = 0;
  while(queue.size()){
    coord thiscoord = queue.front();
    queue.pop();
    if (thiscoord.x == end.x && thiscoord.y == end.y){
      return 0;
    } else {
      for (int i=0; i<4; i++){
        if (thiscoord.x+dx[i]>=0 && thiscoord.x+dx[i]<H &&
            thiscoord.y+dy[i]>=0 && thiscoord.y+dy[i]<W &&
            map[thiscoord.x+dx[i]][thiscoord.y+dy[i]]!='#' && 
            length[thiscoord.x+dx[i]][thiscoord.y+dy[i]]==-1){
          queue.push((coord){thiscoord.x+dx[i], thiscoord.y+dy[i]});
          length[thiscoord.x+dx[i]][thiscoord.y+dy[i]] = length[thiscoord.x][thiscoord.y]+1;
          //printf("length[%d][%d]=%d\n",thiscoord.x+dx[i],thiscoord.y+dy[i],length[thiscoord.x][thiscoord.y]+1);
        }
      }
    }
  }
  return -1;
}

int main(){

  scanf("%d",&H);
  scanf("%d",&W);
  end = (coord){H-1, W-1};  
  std::string S;
  int whitecount = 0;
  for (int i=0; i<H; i++){
    std::cin >> S;
    for (int j=0; j<W; j++){
      map[i][j]=S[j];
      length[i][j] = -1;
      use[i][j] = false;
      if (S[j]=='.'){
        whitecount++;
      }
    }
  }
  if (bfs()){
    printf("-1\n");
  } else {
  /*  thiscoord = (coord){end.x, end.y};
  thislength = length[end.x][end.y];
  use[end.x][end.y]=true;
  while (thislength>=0){
    for (int i=0; i<4; i++){
      if (length[thiscoord.x+dx[i]][thiscoord.y+dy[i]]==thislength-1){
        thislength--;
        thiscoord = (coord){thiscoord.x+dx[i], thiscoord.y+dy[i]};
        use[thiscoord.x+dx[i]][thiscoord.y+dy[i]] = true;
        break;
      }
    }
    }*/
    int endlength = length[end.x][end.y];
    //printf("endlength=%d\n",endlength);
    printf("%d\n",whitecount-endlength-1);
  }
  return 0;
}


Measured memory_bytes: 256
i=list(map(int, input().split()))
a=i[0]
b=i[1]
k=1001
for j in range (1000,0,-1):
    if int(j*0.08)==a and int(j*0.1)==b:
        k=j
if k==1001:
    print(-1)
else:
    print(k)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

// https://leetcode.com/problems/count-complete-tree-nodes/
#include <bits/stdc++.h>
using namespace std;


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

	int a, b, c;
	cin >> a >> b >> c;

	int m = min(a+b, a+c);
	m = min(m, b+c);
	cout << m;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define INF -2147483647
#define mod 1000000007
signed main(){
  int a,b,c;
  int d,e=0,r=0,f=0;
  cin>>a>>b>>c;
  for(int i=0;i<a;i++){
    cin>>d;
    if(d<=b) e++;
    if(b+1<=d&&d<=c) f++;
    if(d>=c+1) r++;
  }
  //cout<<e<<f<<r<<"\n";
  cout<<min(e,min(f,r))<<"\n";
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);i++)
using namespace std;
int main(){
    int64_t a,b,c,k,sum=0,cnt=0;
    cin>>a>>b>>c>>k;
    while(cnt<=k){
        if(a>k){
            sum+=k;
            break;
        }else if(a>0&&a<=k){
            sum+=a;
            cnt+=a;
            a=0;
            continue;
        }else if(b>k){
            break;
        }else if(b>0&&b<=k){
            cnt+=b;
            if(cnt>=k)break;
            b=0;
            continue;
        }else{
            for(;cnt<k;cnt++){
            sum-=1;
            }
            break;
        }
    }
    cout<<sum;
    }

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const double DINF=1e10;

double ans=DINF;
int n,m;
vector<vector<int>> g;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(10);

    cin>>n>>m;
    g.resize(n);
    rep(i,m){
        int s,t;cin>>s>>t;s--,t--;
        g[s].push_back(t);
    }
    
    for(int block=0;block<n;block++){
        vector<double> dp(n,0);
        for(int i=n-2;i>=0;i--){
            double sum=0.0;
            double M=0.0;
            int num=g[i].size();
            for(auto x:g[i]){
                chmax(M,dp[x]);
                sum+=dp[x];
            }
            if(g[i].size()>1&&i==block){
                sum-=M;
                num--;
            }
            double tmp=sum/num+1;
            dp[i]=tmp;
        }
        chmin(ans,dp[0]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
N = int( input() )
S = [ input() for i in range(N) ]

initial = ['M', 'A', 'R', 'C', 'H']
sum_initials = [0]*5
for Si in S:
    for i in range(5):
        if Si[0] == initial[i]:
            sum_initials[i] += 1

ans = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += sum_initials[i]*sum_initials[j]*sum_initials[k]
print( ans )

Measured memory_bytes: 9752
#include<bits/stdc++.h>
using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
  char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
  vector<char*> v({token});
  while(token = strtok(NULL,", ")) v.push_back(token);
  return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
  debug() << " [" << args.back() << ": " << H << "] ";
  args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main() {
    IOS;
    int n,i;
    ll c;
    cin>>n>>c;
    ll x[n],v[n],pre[n],ans=0,sum=0;
    REP(i,0,n-1) cin>>x[i]>>v[i];
    REP(i,0,n-1){
    	sum+=v[i];
    	ans=max(ans,sum-x[i]);
    	pre[i]=max(1ll*0,sum-2*x[i]);
    	if(i>0) pre[i]=max(pre[i],pre[i-1]);
    }
    sum=0;
    ll suf[n];
    RAP(i,n-1,0){
    	sum+=v[i];
    	if(i==0) ans=max(ans,sum-c+x[i]);
    	else ans=max(ans,sum-c+x[i]+pre[i-1]);
    	suf[i]=max(1ll*0,sum-2*(c-x[i]));
    	if(i<n-1) suf[i]=max(suf[i],suf[i+1]);
    }
    sum=0;
    REP(i,0,n-2){
    	sum+=v[i];
   		ans=max(ans,sum-x[i]+suf[i+1]);
    }
    cout<<ans;
    return 0;   
} 

Measured memory_bytes: 6752
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll A,B,C;
	cin >>A>>B>>C;
 
	// 解法
	ll ans = min(C, B/A);
	
	//出力
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n;
vector<ll> s[310000], t(310000);
int main(){
    cin >> n;
    REP(i, n){
        cin >> t[i];
        REP(j, t[i]){
            ll a;
            cin >> a;
            s[i].push_back(a);
        }
        sort(ALL(s[i]), greater<ll>());
    }
    priority_queue<ll, vector<ll>, greater<ll>> q;
    ll ans = 0;
    REP(i, n){
        ll ma = min(i + 1, t[i]);
        REP(j, ma){
            if(q.size() < i + 1){
                q.push(s[i][j]);
                ans += s[i][j];
            }
            else{
                if(q.top() < s[i][j]){
                    ans -= q.top();
                    q.pop();
                    q.push(s[i][j]);
                    ans += s[i][j];
                }
            }
        }
       // cout << ans << endl;
    }
    cout << ans << endl;
}




Measured memory_bytes: 26012
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
//DP用
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;
}
const long long INF = 1LL << 60;

int count(int i,int c) {
    if(i % c == 0) {
        return i/c;
    }else {
        return i/c+1;
    }
}

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    int ans;
    if(a*n > b) {
        ans = b;
    }else {
        ans = a*n;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

sum = 0
for a in range(1,N+1):
    for b in range(1,N+1):
        for c in range(1,N+1):
            sum += gcd(a, b, c)
print(sum)

Measured memory_bytes: 74812
object Main extends App {
  val n = io.StdIn.readLine().toInt
  
  def readData(i: Int, acc: Map[Int, Set[(Int, Int)]]): Map[Int, Set[(Int, Int)]] = if (i > n)
  	acc
  else {
    val a = io.StdIn.readLine().toInt
    val testimony = Iterator.continually(io.StdIn.readLine()).take(a).map(_.split(' ').map(_.toInt)).map {
      case Array(x, y) => (x, y)
    }.toSet
    readData(i + 1, acc + (i -> testimony))
  }
  
  val testimonies = readData(1, Map.empty)
  
  val all = 1 to n
  
  def checkConsistent(unkinds: Set[Int]): Boolean = {
    val honests = all.toSet -- unkinds
    honests.forall { i =>
      	testimonies.getOrElse(i, Set.empty).forall {
          case (x, 0) => unkinds.contains(x)
          case (x, 1) => honests.contains(x)
          case z => throw new Exception(s"予想しない値です: ${z}")
        }
    }
  }
  
  def findUnkinds(unkinds: Int): Int = if (unkinds == n)
  	n
  else {
  	val consistent = all.combinations(unkinds).exists { candidates =>
      checkConsistent(candidates.toSet)
    }
    if (consistent)
    	unkinds
    else
    	findUnkinds(unkinds + 1)
  }
  
  val answer = findUnkinds(0)
  
  println(n - answer)
}

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

using namespace std;

int main(int argc, char const *argv[]) {
	int a,b,c;
	std::cin >> a >> b >> c;
	if (a <= c && c <= b) {
		std::cout << "Yes" << '\n';
	}
	else {
		std::cout << "No" << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007

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

  int N; cin>>N;
  string S; cin>>S;

  // 累積和
  vector<int> e(N+1), w(N+1);
  rep(i,N) {
    e[i+1] = e[i] + (S[i]=='E');
    w[i+1] = w[i] + (S[i]=='W');
  }

  int res = 300000;
  rep(i, N) {
    int cnt = w[i] + (e[N]-e[i+1]);
    res = min(res, cnt);
  }

  cout << res << endl;


  return 0;
}


Measured memory_bytes: 2964
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  private static class Change {

    int times;
    int toValue;

  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int m = sc.nextInt();

    List<Integer> values = new ArrayList<>(n);
    List<Change> changes = new ArrayList<>(m);

    for (int i = 0; i < n; i++) {
      values.add(sc.nextInt());
    }

    for (int i = 0; i < m; i++) {
      Change change = new Change();
      change.times = sc.nextInt();
      change.toValue = sc.nextInt();
      changes.add(change);
    }

    // logic

    values.sort(Integer::compareTo);
    changes.sort(Comparator.comparingInt(c -> c.toValue));
    Collections.reverse(changes);

    int i = 0;
    for (Change change : changes) {
      for (int j = 0; j < change.times; j++) {
        if (i == n) break;
        if (values.get(i) < change.toValue) {
          values.set(i, change.toValue);
        } else {
          break;
        }
        i++;
      }
    }

    long sum = 0;
    for (int value : values) {
      sum += value;
    }
    os.println(sum);
  }
}

Measured memory_bytes: 101456
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

vector<int> getParent(int node, int N) {
    vector<int> res;
    while (node > 0) {
        res.push_back(node);
        node = (node - 1) / N;
    }
    reverse(all(res));
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vector<int> U(Q), V(Q);
    rep(i, 0, Q) {
        cin >> U[i] >> V[i];
        --U[i], --V[i];
    }
    if (N == 1) {
        rep(i, 0, Q) {
            cout << min(U[i], V[i]) + 1 << endl;
        }
        return 0;
    }
    rep(i, 0, Q) {
        vector<int> parent_u = getParent(U[i], N);
        vector<int> parent_v = getParent(V[i], N);
        int lca = 0;
        rep(i, 0, min(parent_u.size(), parent_v.size())) {
            if (parent_u[i] == parent_v[i]) {
                lca = parent_u[i];
            }
            else {
                break;
            }
        }
        cout << lca + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> A(100);
  for(int i = 1;i < 101 ;i++){
    if(a%i == 0 && b%i == 0){
      A[i-1] = i;
    }
   }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
  cout << A[k-1] << endl;
}


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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  cout << min(min(a+b, b+c), min(b+c, c+a)) << endl;
}

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

int main() {
    int n,i=1,ans=0;
    cin>>n;
    while(n--){
        int t;
        cin>>t;
        if(i%2&&t%2)
            ans++;
        i++;
    }
    cout<<ans<<endl;
}


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

using namespace std;

string N;

int main(void)
{
    cin >> N;

    int sum = 0;
    for (int i = 0; i < N.length(); i++)
    {
        sum += (int)N[i] - 48;
        sum %= 9;
    }

    if (sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3740
using System;
using System.Linq;
using System.Collections.Generic;

class Mondai
{
    static void Main()
    {
        var hw = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var H = hw[0];
        var W = hw[1];

        var min1 = GetMin(H, W);
        var min2 = GetMin(W,H);

        var ans = Math.Min(min1,min2);

        Console.WriteLine(ans);
    }

    static long GetMin(long H, long W)
    {
        var min = long.MaxValue;

        for (int i = 1; i < H; ++i)
        {
            var A = W * i;

            var half = (H - i) / 2;
            var B1 = half * W;
            var C1 = (H - i - half) * W;
            var min1 = Math.Min(A, Math.Min(B1, C1));
            var max1 = Math.Max(A, Math.Max(B1, C1));
            var sa = Math.Abs(max1 - min1);

            half = W / 2;
            var B2 = half * (H - i);
            var C2 = (W - half) * (H - i);
            var min2 = Math.Min(A, Math.Min(B2, C2));
            var max2 = Math.Max(A, Math.Max(B2, C2));
            var sa2 = Math.Abs(max2 - min2);

            sa = sa < sa2 ? sa : sa2;
            if (sa < min) min = sa;
        }
        return min;
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    ll cnt = 0;
    for (ll i = N-1; i >= 0; i--) {
        A[i] += cnt;
        if(A[i] == 0){
            cnt += 0;
        }
        else{
            cnt += B[i] - 1 - ((A[i] - 1) % B[i]);
        }
    }
    printf("%lld\n", cnt);
}

Measured memory_bytes: 4832
//Program.cpp
//Author : Aaryan Srivastava 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define pb push_back
#define popb pop_back
#define ull unsigned long long  
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii,int>
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second 
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 2*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace std;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#define AaryanS 0 
#endif

int dx[] = {0,0,1,-1} ;
int dy[] = {1,-1,0,0} ;
int ar[1005][1005] ;
bool vis[1005][1005] ;
int n,m ;
int isvalid(int x, int y){
    return(x >= 0 && x < n && y >= 0 && y <m && ar[x][y] == 0) ;
}

void solve()
{
    queue<pii> q ;
    cin >> n >> m ;
    string s[n] ;
    // int ar[n][m] = {} ;    
    rep(i,n)
        cin >> s[i] ;
    rep(i,n)
        rep(j,m){
            ar[i][j] = (s[i][j] == '#' ? inf : 0) ;
            if(s[i][j] == '#') {
                q.push({i,j}) ;
            }

        }
    while(!q.empty()){
        auto u = q.front() ;
        // cout << u.ff << " " << u.ss << endl ;
        q.pop() ;
        if(vis[u.ff][u.ss] == true)
            continue ;
        vis[u.ff][u.ss]= true ;
        rep(i,4){
            if(isvalid(u.ff+dx[i], u.ss + dy[i])){
                // cout << dx[i] << " -- "<< dy[i] << endl ;
                if(ar[u.ff][u.ss] == inf)
                    ar[u.ff + dx[i]][u.ss + dy[i]] = 1 ;
                else
                    ar[u.ff + dx[i]][u.ss + dy[i]] = ar[u.ff][u.ss] + 1 ;
                q.push({u.ff+dx[i], u.ss + dy[i]}) ;
            }
        }
   }
   int ans = 0 ;
   rep(i,n){
    rep(j,m)
        if(ar[i][j] != inf) ans = max(ar[i][j], ans) ;
    }
    if(ans == inf)
        cout << 0 << endl ;
    else
        cout << ans ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case " << t << ":\n" ;
        solve();
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

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

int n, x, y, g[100005];
vector<int> v[100005];

void sgd(int dg, int op) {
	for(int i = 0; i < v[dg].size(); ++i) {
		if(v[dg][i] != op) {
			sgd(v[dg][i], dg);
			g[dg] ^= g[v[dg][i]] + 1;
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i < n; ++i) {
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	sgd(1, 0);
	if(g[1]) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	return 0;
}

Measured memory_bytes: 12416
#include <iostream>
#include <string>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
void init(int *a, int b){
  for(int i=1;i<=b;i++){
    a[i]=b-i+1;
  }
}

int main(int argc, char *argv[])
{
  int n, r;
  int p, c;
  int hanafuda[51];
  int tmp[51];
  while(1){
    cin >> n >> r;
    if(n+r==0){
      return 0;
    }
    init(hanafuda, n);
    for(int i=0;i<r;i++){
      cin >> p >> c;

      for(int k=1;k<p;k++){
        tmp[c+k]=hanafuda[k];
      }

      for(int k=p;k<p+c;k++){
        tmp[k-p+1]=hanafuda[k];
      }

      for(int l=1;l<c+p;l++){
        hanafuda[l]=tmp[l];
      }
    }

    cout << hanafuda[1] << endl;
  }
  return 0;
}



Measured memory_bytes: 3080
i = int(input()) 
s = input()
if i >= 1 and 100 >= i and i % 2 == 0 and i == len(s) and s.isalpha() and s.islower():
  n = (int)(i/2)
  t_0 = s[0]
  t_1 = s[n]
  for j in range(1, n):
    t_0 += s[j]
  for k in range(n + 1, i):
    t_1 += s[k]
  if t_0 == t_1:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>

#define INF 1050000000
#define MOD 1000000007

using namespace std;



int main() {
	int n, m; cin >> n >> m;
	int p[m], y[m];
	vector<int> id[n + 1];
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> y[i];
		id[p[i]].push_back(y[i]);
	}

	for (int i = 0; i < n; i++) {
		sort(id[i + 1].begin(), id[i + 1].end());
	}
	for (int i = 0; i < m; i++) {
		cout << setfill('0') << right << setw(12)<< (long long int) p[i] * 1000000 + int(lower_bound((id[p[i]]).begin(), id[p[i]].end(), y[i]) - id[p[i]].begin()) + 1 << endl;
	}





}

Measured memory_bytes: 7808
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m, X, Y;
		n = sc.nextInt();
		m = sc.nextInt();
		X = sc.nextInt();
		Y = sc.nextInt();
		ArrayList<Integer> x = new ArrayList<Integer>();
		ArrayList<Integer> y = new ArrayList<Integer>();

		for (int i = 0; i < n; i++) {
			x.add(sc.nextInt());
		}

		for (int i = 0; i < m; i++) {
			y.add(sc.nextInt());
		}

		Collections.sort(x);
		Collections.sort(y);

		boolean ok = false;
		for (int z = X + 1; z <= Y; z++) {
			if (x.get(x.size() - 1) < z && y.get(0) >= z) {
				ok = true;
				break;
			}
		}

		if (ok) {
			System.out.println("No War");
		} else {
			System.out.println("War");
		}

		sc.close();
	}
}

Measured memory_bytes: 21844
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
// Union-Find 木 (Verified: AtCoder Typical Contest 001 B)
struct UnionFind {
private:
    const int n;
    int size_;
    vector<int> uf;
public:
    // 初期化 UnionFind uni(n) のように宣言すれば良い
    UnionFind(int _n) : n(_n), size_(_n), uf(_n, -1) {}
    // find (木の根を求める)
    int find(int x) {return (uf[x] < 0) ? x :  find(uf[x]);}
    // x と y が同じ集合に属するかどうか
    bool same(int x, int y) {return find(x) == find(y);}
    // x が属する集合の要素数
    int size(int x) {return -uf[find(x)];}
    // 集合はいくつあるか
    int size()      {return size_;}
    // x と y の属する集合を併合
    void demo(){
        for(int i=0; i<n; i++)
      cout<<uf[i]<<" ";
    cout<<endl;}

    bool unite(int x, int y) {
    	
        x = find(x); y = find(y);
        if(x == y) return false;
        size_--;
        if(-uf[x] < -uf[y]) swap(x, y);
        uf[x] += uf[y]; uf[y] = x;
        
  //  for(int i=0; i<n; i++)
      //cout<<uf[i]<<" ";
    //cout<<endl;

        return true;
        
    }
    };
 
 
int main() {
    int N, M, K; cin >> N >> M >> K;
    UnionFind uf(N);
    vector<int> ans(N);
    for(int i=0; i<M; i++) {
        int u, v; cin >> u >> v; u--; v--;
        uf.unite(u, v);
        ans[u]--;
        ans[v]--;
    }
 
    vector< vector<int> > G(N);
    for(int i=0; i<K; i++) {
        int u, v; cin >> u >> v; u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
 
    for(int i=0; i<N; i++) {
        ans[i] += uf.size(i) - 1;
        
      //  uf.demo();
        for(auto j : G[i]) {
            if(uf.same(i, j)) ans[i]--;
        }
        cout << ans[i] << " \n"[i + 1 == N];
    }
    return 0;
}

Measured memory_bytes: 6784
# 2019-11-13 21:06:16(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n = int(sys.stdin.readline().rstrip())
    
    order = []
    cities = []
    for i in range(1, n+1):
        city, score = sys.stdin.readline().split()
        order.append([city, int(score), i])
        cities.append(city)

    res = dict((c, list()) for c in set(cities))
    for i in range(n):
        res[order[i][0]].append(order[i][1:])

    for city, score in sorted(res.items()):
        for s in sorted(score, reverse=True):
            print(s[1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};


#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int field[10][10];
int H, W, C;
int ans = 0;
vector<int> v;
int dh[4] = {1, -1, 0, 0};
int dw[4] = {0, 0, 1, -1};

void check() {
    if(v.back() != C) return;
    UnionFind uni(100);
    for(int h = 1; h <= H; h++) {
        for(int w = 1; w <= W; w++) {
            if(h < H) {
                if(field[h][w] == field[h+1][w]) uni.merge(h+w*H, h+1+w*H);
            }
            if(w < W) {
                if(field[h][w] == field[h][w+1]) uni.merge(h+w*H, h+(w+1)*H);
            }
        }
    }
    for(int time = 0; time < v.size(); time++) {
        for(int h = 1; h <= H; h++) {
            for(int w = 1; w <= W; w++) {
                if(!uni.issame(h+w*H, 1+1*H)) continue;
                for(int k = 0; k < 4; k++) {
                    int newh = h + dh[k];
                    int neww = w + dw[k];
                    if(newh < 1 || newh > H || neww < 1 || neww > W) continue;
                    if(field[newh][neww] == v[time]) uni.merge(h+w*H, newh+neww*H);
                }
            }
        }
    }
    ans = max(ans, (int)uni.size(1+1*H));
}

void f() {
    if(v.size() == 5) {
        check();
        return;
    }
    for(int i = 1; i <= 6; i++) {
        v.push_back(i);
        f();
        v.pop_back();
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> H >> W >> C;
        if(H == 0) break;
        for(int h = 1; h <= H; h++) {
            for(int w = 1; w <= W; w++) {
                cin >> field[h][w];
            }
        }
        ans = 0;
        f();
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

ll f[400000];

void calc() {
    f[0] = 1;
    rep(i, 1, 400001) {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
    }
}

ll pow_mod(ll a, ll b, ll m){
    ll ret = 1;
    while (b > 0) {
        if (b & 1) {
            ret = ret * a % m;
        }
        a = a * a % m;
        b >>= 1;
    }
    return ret;
}

ll inv_mod(ll a, ll m){
    return pow_mod(a, m - 2, m);
}

ll comb(ll n, ll r) {
    ll ret = f[n];
    ret *= inv_mod(f[r], mod);
    ret %= mod;
    ret *= inv_mod(f[n - r], mod);
    ret %= mod;
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N, B;
    cin >> N >> B;
    ll R = N - B;
    calc();
    for(ll k = 1; k <= B; k++) {
        if(R + 1 < k) {
            output(0);
            continue;
        }
        ll c = comb(B - 1, k - 1);
        ll d = comb(R + 1, k);
//        cout << k<< "," <<R + 1 << endl;
        output(c * d % mod);
    }
    
    return 0;
}


Measured memory_bytes: 3456