akhauriyash/Code-Regression huggingface dataset:
from collections import deque


H, W = map(int, input().split())
S = [list(map(str, input())) for i in range(H)]
numWhite = -2  # [1,1], [H,W]を除く
for h in range(H):
    numWhite += S[h].count(".")


dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def bfs():
    que = deque([])
    que.append([0, 0])
    D = []
    for h in range(H):
        D.append([float('inf') for _ in range(W)])
    D[0][0] = 0
    while len(que) > 0:
        p = que.popleft()
        if p == [H-1, W-1]:
            break
        else:
            for i in range(4):
                nx = p[0] + dx[i]
                ny = p[1] + dy[i]
                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != '#' and D[nx][ny] == float('inf'):
                    que.append([nx, ny])
                    D[nx][ny] = D[p[0]][p[1]] + 1
    return D[H-1][W-1]


ans = numWhite - bfs() + 1
if isinstance(ans, int):
    print(ans)
else:
    print(-1)

Measured memory_bytes: 3436
import sys
from collections import deque


mod = 10**9 + 7
n = int(input())
a = deque(sorted(list(map(int, (input().split())))))
if n % 2 == 0:
    for i in range(n//2):
        b = a.popleft()
        c = a.popleft()
        if b != i*2+1 or c != i*2+1:
            print(0)
            sys.exit()
    print(pow(2, n//2, mod))

if n % 2 == 1:
    if a.popleft() != 0:
        print(0)
        sys.exit()
    for i in range(n//2):
        b = a.popleft()
        c = a.popleft()
        if b != (i+1)*2 or c != (i+1)*2:
            print(0)
            sys.exit()
    print(pow(2, n//2, mod))

Measured memory_bytes: 14196
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

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

//隣接リストを用いた場合　O(|E|log|V|)
 const int MAX_V=100010;  //変える
 const ll INF=10000000000000000;  //変える
 struct edge {int to, cost1, cost2; }; //cost1は円
 int V;

 vector <edge> G[MAX_V];
 ll d1[MAX_V];
 ll d2[MAX_V];
 
 void dijkstra1 (int s){
     //小さい順に取り出す firstは最短距離、secondは頂点の番号
     priority_queue<P, vector<P>, greater<P>> que;
     fill(d1,d1+V,INF);
     d1[s]=0;
     que.push(P(0,s));
     
     while (!que.empty()) {
         P p=que.top();  que.pop();
         int v=p.second;
         if (d1[v]<p.first) continue;
         rep(i,0,G[v].size()){
             edge e=G[v][i];
             if (d1[e.to]>d1[v]+e.cost1){
                 d1[e.to]=d1[v]+e.cost1;
                 que.push(P(d1[e.to], e.to));
             }
         }
     }
 }

void dijkstra2 (int s){
    //小さい順に取り出す firstは最短距離、secondは頂点の番号
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d2,d2+V,INF);
    d2[s]=0;
    que.push(P(0,s));
    
    while (!que.empty()) {
        P p=que.top();  que.pop();
        int v=p.second;
        if (d2[v]<p.first) continue;
        rep(i,0,G[v].size()){
            edge e=G[v][i];
            if (d2[e.to]>d2[v]+e.cost2){
                d2[e.to]=d2[v]+e.cost2;
                que.push(P(d2[e.to], e.to));
            }
        }
    }
    
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m,s,t;
    cin >> V >> m >> s >> t;
    s--; t--;
    rep(i,0,m){
        int u, v, a, b;
        cin >>u>>v>>a>>b;
        u--; v--;
        G[u].push_back(edge {v,a,b}); G[v].push_back(edge {u,a,b});
    }
    dijkstra1(s);
    dijkstra2(t);
    set<P> st;
    rep(i,0,V){
        st.insert(P(d1[i]+d2[i], i));
    }
    ll inf=1e15;
    rep(i,0,V){
        cout << inf-(*(st.begin())).first << "\n";
        st.erase(P(d1[i]+d2[i],i));
    }
}


Measured memory_bytes: 15996
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  int n, m;
  readf("%d %d\n", &n, &m);
  auto ac = new bool[n];
  auto wa = new int[n];
  for(int i=0; i<m; i++) {
    auto pS = readln.chomp.split;
    auto pi = pS[0].to!int-1;
    auto Si = pS[1];
    if(Si=="AC") ac[pi] = true;
    else {
      if(!ac[pi]) wa[pi]++;
    }
  }
  int ac_count = 0, wa_count = 0;
  for(int i=0; i<n; i++) {
    if(ac[i]) {
      ac_count++;
      wa_count += wa[i];
    }
  }
  writef("%d %d\n", ac_count, wa_count);
}


Measured memory_bytes: 3708
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] T = new int[n + 1];

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

        for(int i = 1; i <= n ; i ++){
            System.out.print("node " + i + ": key = " + T[i] + ", ");
            if(i/2 > 0){
                System.out.print("parent key = " + T[i/2] + ", ");
            }

            if(2*i <= n){
                System.out.print("left key = " + T[2*i] + ", ");
            }

            if((2*i + 1) <= n){
                System.out.print("right key = " + T[2*i + 1] + ", ");
            }
            System.out.println();
        }

    }


}



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

def solve(N,A):
    ans = 0
    cnts = [0]*10**5
    for a in A:
        cnts[a] += 1
    ans = 0
    for i in range(10**5-2):
        ans = max(ans,sum(cnts[i:i+3]))
    return ans
print(solve(N,A))

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

using namespace std;

struct Dice {
  int top;
  int bottom;
  int front;
  int back;
  int left;
  int right;
  Dice() : top(1), bottom(6), front(2), back(5), left(4), right(3) {}
  void E() {
    int tmp = right;
    right = top; top = left; left = bottom; bottom = tmp;
  }
  void N() {
    int tmp = back;
    back = top; top = front; front = bottom; bottom = tmp;
  }
  void S() {
    int tmp = front;
    front = top; top = back; back = bottom; bottom = tmp;
  }
  void W() {
    int tmp = left;
    left = top; top = right; right = bottom; bottom = tmp;
  }
};

int main() {
  Dice d;
  cin >> d.top;
  cin >> d.front;
  cin >> d.right;
  cin >> d.left;
  cin >> d.back;
  cin >> d.bottom;
  string command;
  cin >> command;
  for (size_t i = 0; i < command.length(); ++i) {
    switch (command[i]) {
    case 'E': d.E(); break;
    case 'N': d.N(); break;
    case 'S': d.S(); break;
    case 'W': d.W(); break;
    default: break;
    }
  }
  cout << d.top << endl;
  return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
using namespace std;

int main() {
	int n,count_n=0,a[100010]; cin >> n;
	map<int, int> mp;
	REP(i, n) {
		cin >> a[i]; 
		if (mp.find(a[i])==mp.end()) {
			mp[a[i]] = 1;
		}
		else {
			mp[a[i]]++;
		}
	}

	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if (itr->second % 2)count_n++;
	}
	cout << count_n << endl;

	return 0;
}

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

int main() {
    int count[5]={};
    for(int i=0;i<3;i++){
        for(int j=0;j<2;j++){
            int s;
            cin >> s;
            count[s]++;
        }
    }
    int ans = 0;
    for(int i=1;i<5;i++){
        if(count[i]%2==0)ans++;
    }
    if(ans==2) cout << "YES" << endl;
    else cout << "NO" << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
  
Node root;
Node find(Node root,int key){
  if(root==NIL||root->key==key)
    return root;
  if(root->key > key)
    return find(root->left,key);
  else
    return find(root->right,key);
} 
Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;
}
Node treeSuccessor(Node x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node y = x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return 0;
}
Node treeDelete(Node z){
  Node y;
  Node x;
 
  if(z->left==NIL || z->right==NIL) y=z;
  else y = treeSuccessor(z);
   
  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }else{
    if(y==y->parent->left){
      y->parent->left=x;
    }else{
      y->parent->right=x;
    }
  }
  if(y!=z) z->key=y->key;
  free(y);
  return 0;
}
   
 
void insert(int key){
   Node y = NIL;
   Node x = root;
   Node z;
     
   z =malloc(sizeof(struct node));
   z->key = key;
   z->left = NIL;
   z->right = NIL;
   while(x!=NIL){
     y=x;
     if(z->key < x->key)x=x->left;
     else x=x->right;
   }
   z->parent=y;
   if(y==NIL)root=z;
   else if(z->key <y->key)
   y->left=z;
   else
     y->right=z;
}
  
void inorder(Node root){
  if(root->left!=NIL)
    inorder(root->left);
  printf(" %d",root->key);
  if(root->right!=NIL)
    inorder(root->right);
} 
void preorder(Node root){
  if(root!=NIL)
    printf(" %d",root->key);
  if(root->left!=NIL)
    preorder(root->left);
  if(root->right!=NIL)
    preorder(root->right);
}
int main(){
  int n, i, x;
  char s[10];
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", s);
    if ( s[0] == 'f' ){
      scanf("%d", &x);
     Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    if ( s[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( s[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if(s[0] == 'd'){
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }
  return 0;
}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  
  //年が2019より大きい場合：
  if(s.compare(0,4,"2019")>0)
    cout << "TBD";
   //年が2019より小さい場合：
  if(s.compare(0,4,"2019")<0)
    cout << "Heisei";
   //年が2019の場合：
  if(s.compare(0,4,"2019")==0){
    //月が4より大きい場合：
    if(s.compare(5,2,"04")>0)
      cout << "TBD";
    //月が4より小さい場合：
    if(s.compare(5,2,"04")<0)
      cout << "Heisei";
    //月が4の場合：
    if(s.compare(5,2,"04")==0){
      //日が30より大きい場合：
      if(s.compare(8,2,"30")>0)
        cout << "TBD";
      //日が30より小さい、もしくは同じ場合：
      if(s.compare(8,2,"30")<=0)
        cout << "Heisei";
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  ll a,b,c; cin >>a >>b >>c;
  ll k; cin >>k;
  ll res = 0;
  if (k <= a){
    res += k; cout <<res <<endl; return 0;
  }
  res += a;
  k -= a;
  if (k <= b){
    cout <<res <<endl; return 0;
  }
  k -= b;
  res -= k;
  cout <<res <<endl;
}

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

int main() {
  int n,m,maxi = 0,p,x,ans;
  cin >> n;
  vector<int> t(n);
  for(int i = 0; i< n; i++){
    cin >> t.at(i);
    maxi += t.at(i);
  }
  cin >> m;
  for(int i = 0; i < m; i++){
    cin >> p >> x;
    ans = maxi - t.at(p - 1) + x;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <numeric>
#include <algorithm>
#include <set>
#include <deque>
using namespace std;
using ll = long long;
constexpr double INF{ 1e9 };
constexpr int MAGIC_PRIME{ 1000000000 + 7 };
constexpr array<int, 4> dy{ -1, 1, 0, 0 };
constexpr array<int, 4> dx{ 0, 0, -1, 1 };
constexpr int div_ru(int a, int b)
{
    return (a - b + 1) / b;
}
ll pow_mod(ll b, ll e, ll m)
{ // https://atcoder.jp/contests/atc002/tasks/atc002_b
    ll r = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            r = (r * b) % m;
        b = (b * b) % m;
    }
    return r;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int p, q, r;
    cin >> p >> q >> r;

    cout << p + q + r - max(max(p, q), r) << endl;

}
// vector<vector<int>> mm(h, vector<int>(w, -1));


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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 ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,k;cin >> h >> w >> k;
    vector<vector<char>> c(h,vector<char>(w));
    vector<vector<int>> a(h,vector<int>(w));
    int cnt=1;
    REP(i,h){
        REP(j,w){
            cin >> c[i][j];
            if(c[i][j]=='#'){
                a[i][j]=cnt;
                cnt++;
            }
        }
    }
    REP(i,h){
        REP(j,w-1){
            if(!a[i][j+1]){
                a[i][j+1]=a[i][j];
            }
        }
        REPR(j,w-1){
            if(!a[i][j]){
                a[i][j]=a[i][j+1];
            }
        }
    }
    REP(j,w){
        REP(i,h-1){
            if(!a[i+1][j]){
                a[i+1][j]=a[i][j];
            }
        }
        REPR(i,h-1){
            if(!a[i][j]){
                a[i][j]=a[i+1][j];
            }
        }
    }
    REP(i,h){
        REP(j,w){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 3808
# ARC064C - Boxes and Candies (ABC048C)
def main():
    n, x = list(map(int, input().rstrip().split()))
    A = list(map(int, input().rstrip().split()))
    ans = 0
    if A[0] > x:
        ans += A[0] - x
        A[0] = x
    for i in range(n - 1):
        dif = A[i] + A[i + 1] - x
        if dif > 0:
            A[i + 1] -= dif
            ans += dif
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;


int main (void) 
{

  /* Variable_Proclamation */
  int N;    // input  (棒の数)
  int K;    // input  (選択する数)
  int sum;  // output

  int i;    // subscript


  /* Input, Array_Proclamation */
  cin >> N >> K;
  vector<int> l(N);


  for(i=0; i<N; i++)
  {
    cin >> l.at(i);
  }


  /* Initialize */
  sum = 0;


  /* Calculation */
  sort( l.begin(), l.end() );
  reverse( l.begin(), l.end() );
  for(i=0; i<K; i++)
  {
    sum += l.at(i);
  }
  

  /* Output */
  cout << sum << endl;


  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;
#define INF 1000000007
#define MOD 1000000007

int		main(void)
{
	ld a, b, x;
	cin >> a >> b >> x;
	ld s = x / a;
	ld h, rad;
	if (s < a * b / 2)
	{
		h = 2 * s / b;
		rad = atan(b / h);
	}
	else
	{
		s = a * b - s;
		h = 2 * s / a;
		rad = atan(h / a);
	}
	/*
	if (s > a * b / 2)
	{
		s = a * b - s;
		h = 2 * s / b;
		rad = atan(h / b);
	}
	else
	{
		h = 2 * s / b;
		rad = atan(b / h);
	}
	*/
	ld ans = rad * 180 / M_PI;
	cout << setprecision(10) << ans << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

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

    cout << (a<=8&&b<=8?"Yay!":":(") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        String str = scn.nextLine();
        int ans;

        while(!str.equals("0")){
            String[] num = str.split("");
            ans = 0;
            for(int i=0;i<str.length();i++){
                int a = Integer.valueOf(num[i]);
                ans += a;
            }
            System.out.println(ans);
            str=scn.nextLine();

        }



        scn.close();


    }


}


Measured memory_bytes: 27648
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner scn = new Scanner(System.in);
		PrintWriter pr = new PrintWriter(System.out);
		while (true) {
			int n = scn.nextInt();
			if(n==0) break;
			int firstm = scn.nextInt();
			int[] firstlinex = new int[firstm];
			int[] firstliney = new int[firstm];
			for(int k=0;k<firstm;k++){
				firstlinex[k] = scn.nextInt();
				firstliney[k] = scn.nextInt();
			}
			for(int k=1;k<=n;k++){
				int m = scn.nextInt();
				int[] x = new int[m];
				int[] y = new int[m];
				for(int s=0;s<m;s++){
					x[s] = scn.nextInt();
					y[s] = scn.nextInt();
				}
				if(m!=firstm) continue;
				for(int l=0;l<4;l++){
					for(int s=0;s<m;s++){
						double tmpx=-firstliney[s];
						double tmpy=firstlinex[s];
						firstlinex[s]=(int)tmpx;
						firstliney[s]=(int)tmpy;
					}
					boolean b1 = true;
					boolean b2 = true;
					int dx1 = firstlinex[0]-x[0];
					int dy1 = firstliney[0]-y[0];
					int dx2 = firstlinex[0]-x[m-1];
					int dy2 = firstliney[0]-y[m-1];
					for(int s=0;s<m;s++){
						if(firstlinex[s]!=x[s]+dx1||firstliney[s]!=y[s]+dy1){
							b1 = false;
						}
						if(firstlinex[s]!=x[m-s-1]+dx2||firstliney[s]!=y[m-s-1]+dy2){
							b2 = false;
						}
					}
					if(b1||b2){
						pr.println(k);
						break;
					}
				}
			}
			pr.println("+++++");
		}
		pr.flush();
		scn.close();
	}



}

Measured memory_bytes: 37764
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

memo = sum(a)



q=a[0]
b=memo-a[0]

ans = abs(q-b)
for i in range(1,n-1):
    q += a[i]
    b -= a[i]

    ans = min(ans,abs(q-b))
    
print(ans)

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

int main(void){
	char s[10];
	char t[10];
	int a;
	int b;
	char u[10];

	scanf("%s %s", s, t);
	scanf("%d %d", &a, &b);
	scanf("%s", u);

	if(strcmp(s,u)==0){
		a -= 1;
	} else if(strcmp(t,u)==0) {
		b -= 1;
	}


	printf("%d %d\n", a, b);

	return 0;
}


Measured memory_bytes: 128
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

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

int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}

signed main() {
    int n;cin >>n;
    vector<int> a(n);
    rep(i,n-1)cin >>a[i];
    vector<int> cnt(n);
    rep(i,n-1)cnt[a[i]-1]++;
    rep(i,n)cout <<cnt[i]<<endl;
}

















Measured memory_bytes: 6376
N, K = map(int,input().split())
H = []
for i in range(N):
    h = int(input())
    H.append(h)

H.sort()
l = 0
r = K-1
ans = 10**10
while r <= N-1:
    sub = H[r] - H[l]
    ans = min(ans, sub)
    r += 1
    l += 1

print(ans)


Measured memory_bytes: 50936
N = int(input())
T, A = [int(x) for x in input().split()]
HN = [int(x) for x in input().split()]
dT = 10 ** 10
res = 0
for i, h in enumerate(HN):
  tdT = abs(A - (T - h * 0.006))
  if tdT < dT:
    res = i
    dT = tdT
    
print(res + 1)

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

int main(void){
    int a, b, c;
    double s, l, h;
    
    scanf("%d %d %d",&a,&b,&c);
    
    s = sin(c*M_PI / 180.0)*a*b/2;
    l = a + b + sqrt(a*a + b*b - 2*a*b * cos(c*M_PI / 180.0));
    h = s / a*2;
    
    printf("%lf %lf %lf\n", s, l, h);
    
    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;


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

	int N;
	cin >> N;

	vector<ll> p(N+1);
	repk(i,1,N+1) {
		cin >> p[i];
	}

	int  right = 1;
	int left = 1;
	for(int i = 1; i <= N; i++) {
		if (p[i] == i) {
			swap(p[i], p[i + 1]);
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
	ll n,k;
	cin>>n>>k;
	ll h[n];
	ll dp[n]={0};
	for(ll i=0;i<n;i++){
		cin>>h[i];
		dp[i]=10000000000000000;
	}
	dp[0]=0;
	for(ll i=1;i<n;i++){
		for(ll j=i-1;j>=max((ll)0,i-k);j--){
			dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}

	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
def main():
    import numpy as np

    H, W = map(int, input().split())
    A = np.array([[int(x) for x in input().split()] for _ in range(H)])
    B = np.array([[int(x) for x in input().split()] for _ in range(H)])
    D = np.abs(A - B)

    MAX_BIAS_PER_CELL = 80
    UPPER_BOUND_TOTAL_BIAS = MAX_BIAS_PER_CELL * (H + W - 1) + 1

    dp = np.zeros(shape=(H, W, UPPER_BOUND_TOTAL_BIAS * 2 + 1), dtype=np.bool_)
    d = D[0][0]
    dp[0, 0, UPPER_BOUND_TOTAL_BIAS - d] = 1
    dp[0, 0, UPPER_BOUND_TOTAL_BIAS + d] = 1

    for r in range(H):
        for c in range(W):
            d = D[r][c]
            if r > 0:
                dp[r, c, d:] |= dp[r - 1, c, :UPPER_BOUND_TOTAL_BIAS * 2 + 1 - d]
                dp[r, c, :UPPER_BOUND_TOTAL_BIAS * 2 + 1 - d] |= dp[r - 1, c, d:]
            if c > 0:
                dp[r, c, d:] |= dp[r, c - 1, :UPPER_BOUND_TOTAL_BIAS * 2 + 1 - d]
                dp[r, c, :UPPER_BOUND_TOTAL_BIAS * 2 + 1 - d] |= dp[r, c - 1, d:]

    t = dp[H - 1, W - 1, :]
    indices = np.where(t == 1)[0]  # 一次元
    ret = np.abs(indices - UPPER_BOUND_TOTAL_BIAS)
    print(np.min(ret))


if __name__ == '__main__':
    main()


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

int binarySearch(int A[], int n, int key){
   size_t left = 0;
   size_t right = n;
   size_t mid = (left + right) / 2;
   while(left < right){
      mid = (left + right) / 2;
      if(A[mid] == key) return 1;
      if(A[mid] < key) left = mid + 1;
      else if(A[mid] > key) right = mid;
   }
   return 0;
}

int main()
{
   int n, q;
   int S[100'000];
   cin >> n;
   for(int i=0; i<n; i++) cin >> S[i];
   cin >> q;
   int key;
   int count = 0;
   for(int i=0; i<q; i++){
      cin >> key;
      if(binarySearch(S, n, key)) count++;
   }

   cout << count << endl;
}


Measured memory_bytes: 3488
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 20/08/2017 13:01:11
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define POB pop_back
#define dist(a, b) sqrt(a*a + b*b)
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vipi;
bool compare(pi p1, pi p2){
	 if(1) return true;
	 return false;
}

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	int x, a, b;
	cin>>x>>a>>b;
	if(abs(x - a) <= abs(x - b)) cout<<"A"<<endl;
	else cout<<"B"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <algorithm>
#include <functional>
#include <utility>
#include <string>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define ceil(x,m) ((x)+(m)-1)/(m)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

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

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   int len = v.size();
   s << "[";
   for (int i = 0; i < len; i++) { s << v[i]; if (i < len - 1) s << " "; }
   s << "]";
   return s;
}

class BIT
{
   private:
      vector<int> bit;
      int len;
   public:
      BIT(int n) {
         len = n+1;
         bit = vector<int>(len);
      }
      void add(int i, int x) {
         i += 1;
         while (i < len) {
            bit[i] += x;
            i += i & -i;
         }
      }
      int sum(int i) {
         i += 1;
         int s = 0;
         while (i > 0) {
            s += bit[i];
            i -= i & -i;
         }
         return s;
      }
};

int count(vec<int>& a, int x)
{
   // return the count of m_lr >= x
   int N = SZ(a);
   BIT bit(2*N+1);
   int s = 0, cnt = 0;
   bit.add(0 +N, 1);
   rep(r, 0, N) {
      s += (a[r] >= x) ? 1 : -1;
      cnt += bit.sum(s +N);
      bit.add(s +N, 1);
   }
   return cnt;
}

int binary_search(vector<int>& a)
{
   int N = SZ(a);
   int m, l = -1, r = N;
   vec<int> b(N);
   COPY(a, b);
   SORT(b);
   while (r - l > 1) {
      m = (l + r) / 2;
      if ((N+1)*N/2 - count(a, b[m]) > (N+1)*N/2 / 2) {
         r = m;
      } else {
         l = m;
      }
   }
   return b[l];
}

signed main()
{
   int N; cin >> N;
   vec<int> a(N);
   rep(i, 0, N) {
      cin >> a[i];
   }

   cout << binary_search(a) << endl;

   return 0;
}


Measured memory_bytes: 3428
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから

void solve(){
  int n;
  cin>>n;
  cout<<n*n*n;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define rep(i,N) For(i,0,N)
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

int main(){
  ll i,N,ans=0,mar=0,mil=1LL<<60;
  cin>>N;
  vector<pair<ll,ll>> v(N);
  multiset<ll> se;
  rep(i,N){
    cin>>v[i].first>>v[i].second;
    v[i].first--;
    chmax(mar,v[i].first);
    chmin(mil,v[i].second);
    chmax(ans,v[i].second-v[i].first);
    se.insert(v[i].second);
    v[i].second*=-1;
  }
  ans+=max(mil-mar,0LL);
  sort(v.begin(),v.end());
  se.erase(se.find(-v[0].second));
  mil=-v[0].second;
  for(i=1;i<N;i++){
    chmax(ans,max(0LL,*se.begin()-v[N-1].first)+max(0LL,mil-v[i-1].first));
    se.erase(se.find(-v[i].second));
    chmin(mil,-v[i].second);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6528
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, M = MAP()
LRD = [LIST() for _ in range(M)]

graph = [[] for _ in range(N)]
for L, R, D in LRD:
	graph[L-1].append((R-1, D))
	graph[R-1].append((L-1, -D))

check = [1]*N
i = 0
while 1:
	while check[i] == 0:
		i += 1
		if i == N:
			print("Yes")
			exit()

	check[i] = 0
	dis = defaultdict(int)
	dis[i] = 0
	q = deque([i])
	while q:
		p = q.popleft()
		for v, dist in graph[p]:
			if check[v] == 1:
				check[v] = 0
				dis[v] = dis[p] + dist
				q.append(v)
			if check[v] == 0 and dis[v] != dis[p] + dist:
				print("No")
				exit()


Measured memory_bytes: 113664
<?php
function main($input)
{
  $weather_records = str_split($input);
  $output = 0;

  foreach($weather_records as $key => $record)
  {
      $weather_records[$key] = $record == 'S' ? 0 : 1;
  }

  extract($weather_records, EXTR_PREFIX_ALL, 'day');

  if(!isset($day_0) || !isset($day_1) || !isset($day_2))
  {
    exit();
  }
  
  if($day_0 && $day_1 && $day_2)
  {
      $output = 3;
  } 
  elseif (($day_0 && $day_1) || ($day_1 && $day_2))
  {
      $output = 2;
  }
  elseif($day_0 || $day_1 || $day_2)
  {
      $output = 1;
  }

  fwrite(STDOUT, $output);  
}

$input = trim(fgets(STDIN));
main($input);

// $tests = [
//   	'RRR',
//	 	'RRS',
//  	'SSS',
//  	'RSR'
// ];

// foreach($tests as $test)
// {
//	main($test);
// }

Measured memory_bytes: 16036
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[list(map(int,input().split())) for _ in range(m)]

ans=min(a)+min(b)
for i in range(m):
  ans=min(ans,(a[x[i][0]-1]+b[x[i][1]-1]-x[i][2]))

print(ans)


Measured memory_bytes: 38848
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<pair<int,int> > z;
    int i;
    for(i=0; i<n; i++) {
        int a;
        scanf("%d", &a);
        z.push_back(make_pair(a,1));
    }
    for(i=0; i<n; i++) {
        int b;
        scanf("%d", &b);
        z.push_back(make_pair(b,0));
    }
    sort(z.begin(), z.end());

    ll ans=1;
    int cnt=0;
    for(i=0; i<(int)z.size(); i++) {
        if(z[i].second) {
            if(cnt<0) {
                ans=ans*abs(cnt)%MOD;
            }
            cnt++;
        }
        else {
            if(cnt>0) {
                ans=ans*abs(cnt)%MOD;
            }
            cnt--;
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 2420
using System;
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    int result = c - (a - b);
    Console.WriteLine(0 < result ? result : 0);
  }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=1LL;
	cin >>n;
	map<int,ll>dis;
	int bef=0;
	int tmp=n;
	int count=0;
	bool prime=true;
	for(int t=2;t<=n;t++){
		prime=true;
		for(int i=2;i<=sqrt(t) and prime;i++){
			prime&=((t%i)!=0);
			//if(prime==false){
			//	cout<<t<<" ! "<<i<<endl;
			//}
		}
		
		if(prime){
			count=n;
			dis[t]+=0;
			while(count!=0){
				dis[t]+=(count/t);
				(count/=t);
			}
		}
	}
	
	
	repi(itr,dis){
	//	clog<<(itr->F)<<" "<<(itr->S)<<endl;
		ans*=((itr->S)+1LL);
		ans %=1000000007;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
n,q = map(int,input().split())
s = input()
cumulative_sum = [0]*n
for i in range(1,n,1):
    if s[i-1:i+1]=="AC":
        cumulative_sum[i] = cumulative_sum[i-1]+1
    else:
        cumulative_sum[i] = cumulative_sum[i-1]
for i in range(q):
    li,ri = map(int,input().split())
    print(cumulative_sum[ri-1]-cumulative_sum[li-1])

Measured memory_bytes: 50776
N,A,B = map(int,input().split())
S = input()
pas = 0
num = A + B
kaigai = 0
for i in range(len(S)):
    if S[i] == "a":
        if pas < num:
            pas += 1
            print("Yes")
        else:
            print("No")
    elif S[i] == "b":
        kaigai += 1
        if pas < num and kaigai <= B:
            pas += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")



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


int main() { 
    string s,t;
    cin >> s >> t;
    int n=s.size();
    int f[26][26]={{0}};
    bool flag=true;
    for (int i=0;i<n;i++) {
        int si=s[i]-'a',ti=t[i]-'a';
        if (f[si][ti]!=1) {
            for (int j=0;j<26;j++) {
                if (f[si][j]==1 || f[j][ti]==1) {
                    flag=false;
                }
            }
            f[si][ti]=1;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main () {
  int A, B;
  cin >> A >> B;
  
  int x, y, z;
  
  x=A+B;
  y=A-B;
  z=A*B;
  
  int answer = max(max(x, y),z);
  
  cout << answer << endl;
}
  
  
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define fi first
#define sc second
#define mp make_pair
#define pb push_back
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000013
int n,m;
vector<P>edge[100005],redge[100005];
ll dist[100005]; ll way[100005];
ll rdist[100005]; ll rway[100005];
int x[100005],y[100005],z[100005];
int main(){
	cin>>n>>m;
	rep(i,m){
		int a,b,c; scanf("%d%d%d",&a,&b,&c);
		edge[a].pb(mp(b,c));
		redge[b].pb(mp(a,c));
		x[i] = a;y[i] = b;z[i] = c;
	}
	for(int i=1;i<=n;i++) dist[i] = rdist[i] = 1e18;
	priority_queue<pair<ll,int>,vector<pair<ll,int> >, greater<pair<ll,int> > >que;
	que.push(mp(0,1)); dist[1] = 0; way[1] = 1;
	while(!que.empty()){
		pair<ll,int>p = que.top(); que.pop();
		if(p.fi != dist[p.sc]) continue;
		rep(i,edge[p.sc].size()){
			int x = edge[p.sc][i].fi;
			int add = edge[p.sc][i].sc;
			if(dist[x] > dist[p.sc]+add){
				dist[x] = dist[p.sc]+add;
				way[x] = way[p.sc];
				que.push(mp(dist[x],x));
			}
			else if(dist[x] == dist[p.sc]+add){
				way[x] = (way[x]+way[p.sc])%mod;
			}
		}
	}
	que.push(mp(0,2)); rdist[2] = 0; rway[2] = 1;
	while(!que.empty()){
		pair<ll,int>p = que.top(); que.pop();
		if(p.fi != rdist[p.sc]) continue;
		rep(i,redge[p.sc].size()){
			int x = redge[p.sc][i].fi;
			int add = redge[p.sc][i].sc;
			if(rdist[x] > rdist[p.sc]+add){
				rdist[x] = rdist[p.sc]+add;
				rway[x] = rway[p.sc];
				que.push(mp(rdist[x],x));
			}
			else if(rdist[x] == rdist[p.sc]+add){
				rway[x] = (rway[x]+rway[p.sc])%mod;
			}
		}
	}
	assert(dist[2] == rdist[1]);
	//cout << way[2] << dist[2] << endl;
	rep(i,m){
		ll a = dist[y[i]];
		ll b = rdist[x[i]];
		ll c = way[x[i]];
		ll d = rway[y[i]];
		if(a+b+z[i] < dist[2]) puts("HAPPY");
		else if(a+b+z[i] == dist[2]) puts("SOSO");
		else{
			if(dist[x[i]]+rdist[y[i]]+z[i]==dist[2] && c*d%mod == way[2]) puts("SAD");
			else puts("SOSO");
		}
	}
}

	



Measured memory_bytes: 18344
import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner cin=new Scanner(System.in);
        int group;
        long result=0;
        ArrayList<Integer> power = new ArrayList<Integer>();
        group = cin.nextInt();
        for(int i =0;i<3*group;i++){
            power.add(cin.nextInt());
        }
            Collections.sort(power, Comparator.reverseOrder());
            for(int j=1;j<=group;j++){
	        result = result+power.get(2*j-1);
            }   
            System.out.println(result);
    }
}


Measured memory_bytes: 97400
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    ll x;
    cin>>x;
    cout<<(x&1?2*x:x);
    return 0;
}


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

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

    sort(a.begin(), a.end(), greater<int>());

    int A = 0;
    int B = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            A += a[i];
        } else {
            B += a[i];
        }
    }
    cout << A - B << endl;
    return 0;
}

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

int n;
int a[400000];
int dp[400000];

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i + 1];
    dp[1] = 0;
    dp[2] = abs(a[2] - a[1]);
    for (int i = 3; i <= n; ++i)
        dp[i] = min(dp[i-2]+abs(a[i]-a[i-2]), dp[i-1]+abs(a[i]-a[i-1]));
    cout << dp[n] << endl;
    return 0;
}

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

int main()
{
	int a, b;

	cin >> a >> b;

	if (a < b) {
		cout << "a < b" << endl;
	} else if (a > b) {
		cout << "a > b" << endl;
	} else {
		cout << "a == b" << endl;
	}

	return 0;
}

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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

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

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    int N;
    cin >> N;
    int i;
    vector <string> a(N);
    rep(i, N) { cin >> a[i]; }
//    vector<int> f(26, 0);
    vector < vector<int> > f(N, vector<int>(26, 0));
    vector < vector<int> > b(N, vector<int>(26, 0));
    vector<int> c(26, 0);

    for (int i = 0; i < N; ++i) {
        string s = a[i];
        for (int j = 0; j < s.length(); ++j) {

            b[i][s[j] - 'a']++;
            if (f[i][s[j] - 'a'] == 0) {
                f[i][s[j] - 'a'] = 1;
            }
        }

    }

    for (int j = 0; j < 26; ++j) {
        int maxTemp = -1;
        for (int i = 0; i < N; ++i) {
            int temp = b[i][j];

            if (maxTemp == -1) {
                maxTemp = temp;
            }
            if (temp < maxTemp) {
                maxTemp = temp;
            }
        }
        if (maxTemp > 0) {
            c[j] = maxTemp;
        }
    }

    for (int i = 0; i < 26; ++i) {
        if (c[i] > 0) {
            for (int j = 0; j < c[i]; ++j) {
                char temp = i + 'a';
                cout << temp;
            }
        }
    }
    cout << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,k;
    cin >> n >> k;
    cout << (n%k?1:0) << endl;;
    return 0;
}

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

typedef long long				ll;
typedef unsigned long long		ull;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll a, b;
	string s, s1;
	cin >> a >> b;
	ll k = a, k1 = b;
	while (k1--) 
		s += a + '0';
	while (k--) 
		s1 += b + '0';
	cout << (s >= s1? s1: s) << endl;
	return 0;
}


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

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; }

using ll = long long;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];
  ll ans = 0;
  rep(i,N){
    if((K|A[i])==K) ans += B[i];
  }
  for(int i = 31; i>=0; i--){
    ll t = 0;
    if(K&(1LL<<i)){
      ll p = (K|((1LL<<i)-1))-(1LL<<i);
      rep(i,N) {
        if((p|A[i])==p) t+=B[i]; 
      }
    }
    chmax(ans,t);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4856
from itertools import groupby, accumulate

N, K = [int(i) for i in input().split()]
S = input()

A = [(k, len(tuple(v))) for k, v in groupby(S)]
M = len(A)

ans, count = 0, 0
l, r = 0, 0
while l < M:
    bound = 2 * K
    if A[l][0] == '1':
        bound += 1
    while r < M and r - l < bound:
        count += A[r][1]
        r += 1
    ans = max(ans, count)
    count -= A[l][1]
    l += 1

print(ans)

Measured memory_bytes: 10484